Skip to content

Commit

Permalink
Merge pull request #11132 from rouault/jpegxl_read_float16
Browse files Browse the repository at this point in the history
JPEGXL: add support for reading Float16 (as Float32)
  • Loading branch information
rouault authored Nov 4, 2024
2 parents af82417 + e845e53 commit 38151bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Binary file added autotest/gdrivers/data/jpegxl/float16.jxl
Binary file not shown.
14 changes: 14 additions & 0 deletions autotest/gdrivers/jpegxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,3 +847,17 @@ def test_jpegxl_identify_raw_codestream():
f"{gdalmanage_path} identify data/jpegxl/test.jxl.bin"
)
assert "JPEGXL" in out


###############################################################################
def test_jpegxl_read_float16():

# Image produced with:
# gdal_translate autotest/gcore/data/rgbsmall.tif float.exr -co PIXEL_TYPE=FLOAT -co TILED=NO -co COMPRESS=PIZ
# cjxl -d 0 float.exr float16.jxl
ds = gdal.Open("data/jpegxl/float16.jxl")
assert [ds.GetRasterBand(i + 1).Checksum() for i in range(3)] == [
21212,
21053,
21349,
]
6 changes: 6 additions & 0 deletions frmts/jpegxl/jpegxl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ bool JPEGXLDataset::Open(GDALOpenInfo *poOpenInfo)
else if (info.bits_per_sample <= 16)
eDT = GDT_UInt16;
}
else if (info.exponent_bits_per_sample == 5)
{
// Float16
CPLDebug("JXL", "16-bit floating point data");
eDT = GDT_Float32;
}
else if (info.exponent_bits_per_sample == 8)
{
eDT = GDT_Float32;
Expand Down

0 comments on commit 38151bc

Please sign in to comment.