Skip to content

Commit 41ffedc

Browse files
authored
Merge pull request OSGeo#11560 from rouault/tiff_ovr_do_not_propagate_photometric_ycbcr_if_ovr_if_not_jpeg
GTiff: internal overview building: do not set PHOTOMETRIC=YCBCR when …
2 parents 37aa84a + 3a804c2 commit 41ffedc

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

autotest/gcore/tiff_ovr.py

+27
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,33 @@ def test_tiff_ovr_43(tmp_path, both_endian):
16751675
assert cs == 642, "did not get expected checksum"
16761676

16771677

1678+
###############################################################################
1679+
# Test that we do not propagate PHOTOMETRIC=YCBCR on overviews when
1680+
# COMPRESS_OVERVIEW != JPEG
1681+
1682+
1683+
@pytest.mark.require_creation_option("GTiff", "JPEG")
1684+
@gdaltest.enable_exceptions()
1685+
def test_tiff_ovr_do_not_propagate_photometric_ycbcr_if_ovr_if_not_jpeg(tmp_path):
1686+
1687+
tif_fname = str(tmp_path / "test.tif")
1688+
1689+
ds = gdal.GetDriverByName("GTiff").Create(
1690+
tif_fname, 8, 8, 3, options=["COMPRESS=JPEG", "PHOTOMETRIC=YCBCR"]
1691+
)
1692+
ds.GetRasterBand(1).Fill(255)
1693+
ds.GetRasterBand(2).Fill(255)
1694+
ds.GetRasterBand(3).Fill(255)
1695+
ds = None
1696+
1697+
with gdal.Open(tif_fname, gdal.GA_Update) as ds:
1698+
with gdal.config_option("COMPRESS_OVERVIEW", "DEFLATE"):
1699+
ds.BuildOverviews("NEAR", [2])
1700+
1701+
with gdal.Open(tif_fname) as ds:
1702+
assert ds.GetRasterBand(1).GetOverview(0).ComputeRasterMinMax() == (255, 255)
1703+
1704+
16781705
###############################################################################
16791706
# Test that we can change overview block size through GDAL_TIFF_OVR_BLOCKSIZE configuration
16801707
# option

frmts/gtiff/gtiffdataset_write.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,10 @@ bool GTiffDataset::GetOverviewParameters(
27092709
/* -------------------------------------------------------------------- */
27102710
/* Determine photometric tag */
27112711
/* -------------------------------------------------------------------- */
2712-
nPhotometric = m_nPhotometric;
2712+
if (m_nPhotometric == PHOTOMETRIC_YCBCR && nCompression != COMPRESSION_JPEG)
2713+
nPhotometric = PHOTOMETRIC_RGB;
2714+
else
2715+
nPhotometric = m_nPhotometric;
27132716
const char *pszPhotometric =
27142717
GetOptionValue("PHOTOMETRIC", "PHOTOMETRIC_OVERVIEW", &pszOptionKey);
27152718
if (!GTIFFUpdatePhotometric(pszPhotometric, pszOptionKey, nCompression,

0 commit comments

Comments
 (0)