Skip to content

Commit

Permalink
Merge pull request OSGeo#6356 from rouault/fix_6344
Browse files Browse the repository at this point in the history
GTiff: honour COMPRESS_OVERVIEW and INTERLEAVE_OVERVIEW for internal overviews
  • Loading branch information
rouault authored Sep 14, 2022
2 parents 602f0d9 + 5aa5b76 commit 4288bbd
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 111 deletions.
110 changes: 110 additions & 0 deletions autotest/gcore/tiff_ovr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,116 @@ def test_tiff_ovr_uint64():
gdal.GetDriverByName("GTiff").Delete(temp_path)


###############################################################################


def test_tiff_ovr_internal_overview_different_method():

temp_path = "/vsimem/test.tif"
gdal.GetDriverByName("GTiff").Create(
temp_path, 2, 1, 1, gdal.GDT_Byte, options=["COMPRESS=LZW"]
)
ds = gdal.OpenEx(temp_path, gdal.GA_Update)
with gdaltest.config_options(
{"COMPRESS_OVERVIEW": "DEFLATE", "PREDICTOR_OVERVIEW": "2"}
):
assert ds.BuildOverviews("nearest", overviewlist=[2]) == 0
del ds
ds = gdal.Open(temp_path)
assert ds.GetMetadataItem("COMPRESSION", "IMAGE_STRUCTURE") == "LZW"
ovr_ds = ds.GetRasterBand(1).GetOverview(0).GetDataset()
assert ovr_ds.GetMetadataItem("COMPRESSION", "IMAGE_STRUCTURE") == "DEFLATE"
assert ovr_ds.GetMetadataItem("PREDICTOR", "IMAGE_STRUCTURE") == "2"
del ds
gdal.GetDriverByName("GTiff").Delete(temp_path)


###############################################################################


def test_tiff_ovr_internal_overview_different_method_propagate_predictor():

temp_path = "/vsimem/test.tif"
gdal.GetDriverByName("GTiff").Create(
temp_path, 2, 1, 1, gdal.GDT_Byte, options=["COMPRESS=LZW", "PREDICTOR=2"]
)
ds = gdal.OpenEx(temp_path, gdal.GA_Update)
with gdaltest.config_options({"COMPRESS_OVERVIEW": "DEFLATE"}):
assert ds.BuildOverviews("nearest", overviewlist=[2]) == 0
del ds
ds = gdal.Open(temp_path)
assert ds.GetMetadataItem("COMPRESSION", "IMAGE_STRUCTURE") == "LZW"
ovr_ds = ds.GetRasterBand(1).GetOverview(0).GetDataset()
assert ovr_ds.GetMetadataItem("COMPRESSION", "IMAGE_STRUCTURE") == "DEFLATE"
assert ovr_ds.GetMetadataItem("PREDICTOR", "IMAGE_STRUCTURE") == "2"
del ds
gdal.GetDriverByName("GTiff").Delete(temp_path)


###############################################################################


def test_tiff_ovr_internal_overview_different_method_do_not_propagate_predictor():

temp_path = "/vsimem/test.tif"
gdal.GetDriverByName("GTiff").Create(
temp_path, 2, 1, 1, gdal.GDT_Byte, options=["COMPRESS=LZW", "PREDICTOR=2"]
)
ds = gdal.OpenEx(temp_path, gdal.GA_Update)
with gdaltest.config_options({"COMPRESS_OVERVIEW": "PACKBITS"}):
assert ds.BuildOverviews("nearest", overviewlist=[2]) == 0
del ds
ds = gdal.Open(temp_path)
assert ds.GetMetadataItem("COMPRESSION", "IMAGE_STRUCTURE") == "LZW"
ovr_ds = ds.GetRasterBand(1).GetOverview(0).GetDataset()
assert ovr_ds.GetMetadataItem("COMPRESSION", "IMAGE_STRUCTURE") == "PACKBITS"
assert ovr_ds.GetMetadataItem("PREDICTOR", "IMAGE_STRUCTURE") is None
del ds
gdal.GetDriverByName("GTiff").Delete(temp_path)


###############################################################################


def test_tiff_ovr_internal_overview_different_planar_config_to_pixel():

temp_path = "/vsimem/test.tif"
gdal.GetDriverByName("GTiff").Create(
temp_path, 2, 1, 3, gdal.GDT_Byte, options=["INTERLEAVE=BAND"]
)
ds = gdal.OpenEx(temp_path, gdal.GA_Update)
with gdaltest.config_options({"INTERLEAVE_OVERVIEW": "PIXEL"}):
assert ds.BuildOverviews("nearest", overviewlist=[2]) == 0
del ds
ds = gdal.Open(temp_path)
assert ds.GetMetadataItem("INTERLEAVE", "IMAGE_STRUCTURE") == "BAND"
ovr_ds = ds.GetRasterBand(1).GetOverview(0).GetDataset()
assert ovr_ds.GetMetadataItem("INTERLEAVE", "IMAGE_STRUCTURE") == "PIXEL"
del ds
gdal.GetDriverByName("GTiff").Delete(temp_path)


###############################################################################


def test_tiff_ovr_internal_overview_different_planar_config_to_band():

temp_path = "/vsimem/test.tif"
gdal.GetDriverByName("GTiff").Create(
temp_path, 2, 1, 3, gdal.GDT_Byte, options=["INTERLEAVE=PIXEL"]
)
ds = gdal.OpenEx(temp_path, gdal.GA_Update)
with gdaltest.config_options({"INTERLEAVE_OVERVIEW": "BAND"}):
assert ds.BuildOverviews("nearest", overviewlist=[2]) == 0
del ds
ds = gdal.Open(temp_path)
assert ds.GetMetadataItem("INTERLEAVE", "IMAGE_STRUCTURE") == "PIXEL"
ovr_ds = ds.GetRasterBand(1).GetOverview(0).GetDataset()
assert ovr_ds.GetMetadataItem("INTERLEAVE", "IMAGE_STRUCTURE") == "BAND"
del ds
gdal.GetDriverByName("GTiff").Delete(temp_path)


###############################################################################
# Cleanup

Expand Down
2 changes: 1 addition & 1 deletion doc/source/drivers/raster/gtiff.rst
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ the default behavior of the GTiff driver.
- :decl_configoption:`ESRI_XML_PAM` : Can be set to TRUE to force metadata in the xml:ESRI
domain to be written to PAM.
- :decl_configoption:`COMPRESS_OVERVIEW` : See `Creation Options COMPRESS <#creation-options>`__ section.
Set the compression type to use for overviews
Set the compression type to use for overviews. For internal overviews, only honoured since GDAL 3.6
- :decl_configoption:`PHOTOMETRIC_OVERVIEW` : YCBCR
Set the photometric color space for overview creation
- :decl_configoption:`PREDICTOR_OVERVIEW` : Integer 1,2 or 3.
Expand Down
3 changes: 3 additions & 0 deletions doc/source/programs/gdaladdo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ The photometric interpretation can be set with the :decl_configoption:`PHOTOMETR
=RGB/YCBCR/... configuration option,
and the interleaving with the :decl_configoption:`INTERLEAVE_OVERVIEW` =PIXEL/BAND configuration option.

Since GDAL 3.6, :decl_configoption:`COMPRESS_OVERVIEW` and decl_configoption:`INTERLEAVE_OVERVIEW`
are honoured when creating internal overviews of TIFF files.

For JPEG compressed external and internal overviews, the JPEG quality can be set with
``--config JPEG_QUALITY_OVERVIEW value``.

Expand Down
Loading

0 comments on commit 4288bbd

Please sign in to comment.