Skip to content

Commit

Permalink
work arounds for 'JPEG' compression with YCbCr reported as 'YCbCr JPE…
Browse files Browse the repository at this point in the history
…G' in gdal 3.10
  • Loading branch information
dugalh committed Dec 9, 2024
1 parent a907518 commit 316e2ac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,9 @@ def exif_image_file(odm_image_file: Path, tmp_path_factory: pytest.TempPathFacto
dst_filename = tmp_path_factory.mktemp('data').joinpath('exif.tif')
with rio.open(odm_image_file, 'r') as src_im:
dst_profile = src_im.profile.copy()
# work around GDAL / rasterio issue that reads YCbCr JPEG compression as 'YCbCr JPEG' in
# profile['compress'], but does not allow it to be written that way
dst_profile['compress'] = 'jpeg'
with rio.open(dst_filename, 'w', **dst_profile) as dst_im:
dst_tags = src_im.tags()
dst_tags.update(
Expand All @@ -998,6 +1001,9 @@ def exif_no_focal_image_file(
dst_filename = tmp_path_factory.mktemp('data').joinpath('exif.tif')
with rio.open(exif_image_file, 'r') as src_im:
dst_profile = src_im.profile.copy()
# work around GDAL / rasterio issue that reads YCbCr JPEG compression as 'YCbCr JPEG' in
# profile['compress'], but does not allow it to be written that way
dst_profile['compress'] = 'jpeg'
with rio.open(dst_filename, 'w', **dst_profile) as dst_im:
dst_tags = src_im.tags()
dst_tags.pop('EXIF_FocalLength')
Expand All @@ -1014,6 +1020,9 @@ def xmp_no_dewarp_image_file(
dst_filename = tmp_path_factory.mktemp('data').joinpath('exif.tif')
with rio.open(odm_image_file, 'r') as src_im:
dst_profile = src_im.profile.copy()
# work around GDAL / rasterio issue that reads YCbCr JPEG compression as 'YCbCr JPEG' in
# profile['compress'], but does not allow it to be written that way
dst_profile['compress'] = 'jpeg'
with rio.open(dst_filename, 'w', **dst_profile) as dst_im:
dst_im.update_tags(**src_im.tags())
for namespace in src_im.tag_namespaces():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def test_create_profile_image(

# dtype and compression
assert im.dtypes[0] == dtype
assert im.compression.value.lower() == compress
assert compress.value in im.profile['compress'].lower()

# photometric
if shape[0] == 3 and compress is Compress.jpeg:
Expand Down Expand Up @@ -609,7 +609,7 @@ def test_create_profile_image_creation_options(
assert im.profile['blockxsize'] == im.profile['blockysize'] == 256

# compression
assert im.compression.value.lower() == 'jpeg'
assert 'jpeg' in im.profile['compress'].lower()
assert im.photometric is PhotometricInterp.ycbcr
assert im_struct['JPEG_QUALITY'] == '90'

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ortho.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ def test_process_compress(
compress = Compress.jpeg if dtype == 'uint8' else Compress.deflate

with rio.open(ortho_file, 'r') as ortho_im:
assert ortho_im.profile['compress'] == compress
assert compress.value in ortho_im.profile['compress'].lower()


@pytest.mark.parametrize('build_ovw, driver', [*product([True, False], Driver)])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pan_sharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def test_process_compress(pan_sharpen: PanSharpen, tmp_path: Path, compress: Com
compress = Compress.jpeg if dtype == 'uint8' else Compress.deflate

with rio.open(out_file, 'r') as out_im:
assert out_im.profile['compress'] == compress
assert compress.value in out_im.profile['compress'].lower()


@pytest.mark.parametrize('build_ovw, driver', [*product([True, False], Driver)])
Expand Down

0 comments on commit 316e2ac

Please sign in to comment.