Skip to content

Commit

Permalink
Merge pull request #7006 from OSGeo/backport-7004-to-release/3.6
Browse files Browse the repository at this point in the history
[Backport release/3.6] JPEGXL: advertize COMPRESSION_REVERSIBILITY=LOSSY when there is a JPEG reconstruction box
  • Loading branch information
rouault authored Jan 1, 2023
2 parents bf04dde + d0e7049 commit 889129d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
6 changes: 5 additions & 1 deletion autotest/gdrivers/jpegxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ def test_jpegxl_lossless_copy_of_jpeg():
assert set(ds.GetMetadataDomainList()) == set(
["DERIVED_SUBDATASETS", "EXIF", "IMAGE_STRUCTURE"]
)
assert ds.GetMetadataItem("HAS_JPEG_RECONSTRUCTION_DATA", "_DEBUG_") == "YES"
assert (
ds.GetMetadataItem("COMPRESSION_REVERSIBILITY", "IMAGE_STRUCTURE")
== "LOSSY"
)
assert ds.GetMetadataItem("ORIGINAL_COMPRESSION", "IMAGE_STRUCTURE") == "JPEG"

ds = None
gdal.GetDriverByName("JPEGXL").Delete(outfilename)
Expand Down
27 changes: 17 additions & 10 deletions frmts/jpegxl/jpegxl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,6 @@ bool JPEGXLDataset::Open(GDALOpenInfo *poOpenInfo)
return false;
}

GDALDataset::SetMetadataItem(
"COMPRESSION_REVERSIBILITY",
info.uses_original_profile ? "LOSSLESS (possibly)" : "LOSSY",
"IMAGE_STRUCTURE");

nRasterXSize = static_cast<int>(info.xsize);
nRasterYSize = static_cast<int>(info.ysize);

Expand Down Expand Up @@ -770,6 +765,23 @@ bool JPEGXLDataset::Open(GDALOpenInfo *poOpenInfo)
return false;
}

GDALDataset::SetMetadataItem("COMPRESSION_REVERSIBILITY",
info.uses_original_profile
#ifdef HAVE_JXL_BOX_API
&& !m_bHasJPEGReconstructionData
?
#endif
"LOSSLESS (possibly)"
: "LOSSY",
"IMAGE_STRUCTURE");
#ifdef HAVE_JXL_BOX_API
if (m_bHasJPEGReconstructionData)
{
GDALDataset::SetMetadataItem("ORIGINAL_COMPRESSION", "JPEG",
"IMAGE_STRUCTURE");
}
#endif

#ifdef HAVE_JXL_THREADS
const char *pszNumThreads =
CPLGetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS");
Expand Down Expand Up @@ -997,11 +1009,6 @@ const char *JPEGXLDataset::GetMetadataItem(const char *pszName,
{
return m_aosEXIFMetadata.FetchNameValue(pszName);
}
else if (pszDomain != nullptr && EQUAL(pszDomain, "_DEBUG_"))
{
if (EQUAL(pszName, "HAS_JPEG_RECONSTRUCTION_DATA"))
return m_bHasJPEGReconstructionData ? "YES" : "NO";
}
#endif

return GDALPamDataset::GetMetadataItem(pszName, pszDomain);
Expand Down

0 comments on commit 889129d

Please sign in to comment.