Skip to content

Commit 3c73342

Browse files
mscuttergithub-actions[bot]
authored andcommitted
GTiff: accept Float16 with PREDICTOR=3
1 parent 2df6c93 commit 3c73342

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

autotest/gcore/tiff_write.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12173,6 +12173,31 @@ def test_tiff_write_multi_band_interleaved_predictor_3(tmp_vsimem):
1217312173
#
1217412174

1217512175

12176+
def test_tiff_write_float16_predictor_3(tmp_vsimem):
12177+
12178+
ref_values = (1.5, -3.5, 4.5, -2.5)
12179+
ref_content = struct.pack("e" * len(ref_values), *ref_values)
12180+
with gdal.GetDriverByName("GTiff").Create(
12181+
tmp_vsimem / "test.tif",
12182+
len(ref_values),
12183+
1,
12184+
1,
12185+
gdal.GDT_Float16,
12186+
options=["PREDICTOR=3", "COMPRESS=LZW"],
12187+
) as ds:
12188+
ds.WriteRaster(0, 0, len(ref_values), 1, ref_content, buf_type=gdal.GDT_Float16)
12189+
with gdal.Open(tmp_vsimem / "test.tif") as ds:
12190+
assert ds.GetMetadataItem("PREDICTOR", "IMAGE_STRUCTURE") == "3"
12191+
content = struct.unpack(
12192+
"e" * len(ref_values), ds.ReadRaster(buf_type=gdal.GDT_Float16)
12193+
)
12194+
assert content == pytest.approx(ref_values, abs=1e-6)
12195+
12196+
12197+
###############################################################################
12198+
#
12199+
12200+
1217612201
def test_tiff_write_5_bands_interleaved_predictor_2(tmp_vsimem):
1217712202

1217812203
ref_content = struct.pack("B" * 10, 1, 5, 3, 2, 4, 9, 6, 8, 0, 7)

frmts/gtiff/gtiffdataset_write.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5769,11 +5769,12 @@ TIFF *GTiffDataset::CreateLL(const char *pszFilename, int nXSize, int nYSize,
57695769
}
57705770
else if (nPredictor == 3)
57715771
{
5772-
if (eType != GDT_Float32 && eType != GDT_Float64)
5772+
if (eType != GDT_Float16 && eType != GDT_Float32 &&
5773+
eType != GDT_Float64)
57735774
{
5774-
ReportError(
5775-
pszFilename, CE_Failure, CPLE_AppDefined,
5776-
"PREDICTOR=3 is only supported with Float32 or Float64.");
5775+
ReportError(pszFilename, CE_Failure, CPLE_AppDefined,
5776+
"PREDICTOR=3 is only supported with Float16, "
5777+
"Float32 or Float64.");
57775778
return nullptr;
57785779
}
57795780
}

0 commit comments

Comments
 (0)