Skip to content

Commit

Permalink
Merge pull request #11510 from rouault/gtiff_warn_ignored_predictor
Browse files Browse the repository at this point in the history
GTiff creation: emit warning when PREDICTOR option is used with an incompatible codec
  • Loading branch information
rouault authored Dec 19, 2024
2 parents 42ca02c + ef68e3d commit fbc0ed6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
14 changes: 14 additions & 0 deletions autotest/gcore/tiff_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -11974,3 +11974,17 @@ def test_tiff_write_float32_predictor_3_endianness(tmp_path):
)
with gdal.Open(out_filename) as ds:
assert ds.GetRasterBand(1).Checksum() == 4672


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


def test_tiff_write_warn_ignore_predictor_option(tmp_vsimem):
out_filename = str(tmp_vsimem / "out.tif")
gdal.ErrorReset()
with gdal.quiet_errors():
gdal.GetDriverByName("GTiff").Create(
out_filename, 1, 1, options=["PREDICTOR=2"]
)
assert "PREDICTOR option is ignored" in gdal.GetLastErrorMsg()
17 changes: 15 additions & 2 deletions frmts/gtiff/gtiffdataset_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5297,9 +5297,22 @@ TIFF *GTiffDataset::CreateLL(const char *pszFilename, int nXSize, int nYSize,
nPredictor = atoi(pszValue);
}

// Do early checks as libtiff will only error out when starting to write.
if (nPredictor != PREDICTOR_NONE &&
CPLTestBool(CPLGetConfigOption("GDAL_GTIFF_PREDICTOR_CHECKS", "YES")))
l_nCompression != COMPRESSION_ADOBE_DEFLATE &&
l_nCompression != COMPRESSION_LZW &&
l_nCompression != COMPRESSION_LZMA &&
l_nCompression != COMPRESSION_ZSTD)
{
ReportError(pszFilename, CE_Warning, CPLE_NotSupported,
"PREDICTOR option is ignored for COMPRESS=%s. "
"Only valid for DEFLATE, LZW, LZMA or ZSTD",
CSLFetchNameValueDef(papszParamList, "COMPRESS", "NONE"));
}

// Do early checks as libtiff will only error out when starting to write.
else if (nPredictor != PREDICTOR_NONE &&
CPLTestBool(
CPLGetConfigOption("GDAL_GTIFF_PREDICTOR_CHECKS", "YES")))
{
#if (TIFFLIB_VERSION > 20210416) || defined(INTERNAL_LIBTIFF)
#define HAVE_PREDICTOR_2_FOR_64BIT
Expand Down

0 comments on commit fbc0ed6

Please sign in to comment.