diff --git a/autotest/gcore/data/gtiff/byte_jxl_deprecated_50002.tif b/autotest/gcore/data/gtiff/byte_jxl_deprecated_50002.tif new file mode 100644 index 000000000000..ff444755fc22 Binary files /dev/null and b/autotest/gcore/data/gtiff/byte_jxl_deprecated_50002.tif differ diff --git a/autotest/gcore/data/gtiff/byte_jxl_dng_1_7_52546.tif b/autotest/gcore/data/gtiff/byte_jxl_dng_1_7_52546.tif new file mode 100644 index 000000000000..704677ac10a8 Binary files /dev/null and b/autotest/gcore/data/gtiff/byte_jxl_dng_1_7_52546.tif differ diff --git a/autotest/gcore/gcps2geotransform.py b/autotest/gcore/gcps2geotransform.py index 917c42df8d5e..db803924d632 100755 --- a/autotest/gcore/gcps2geotransform.py +++ b/autotest/gcore/gcps2geotransform.py @@ -80,7 +80,7 @@ def test_gcps2gt_2(): def test_gcps2gt_3(): - approx_ok = 0 + approx_ok = False gt = gdal.GCPsToGeoTransform( _list2gcps( [ diff --git a/autotest/gcore/tiff_read.py b/autotest/gcore/tiff_read.py index a6f9352aaa59..500d05398930 100755 --- a/autotest/gcore/tiff_read.py +++ b/autotest/gcore/tiff_read.py @@ -4681,6 +4681,28 @@ def test_tiff_jxl_read_for_files_created_before_6393(): assert gdal.GetLastErrorMsg() == "" +############################################################################### +# Test reading Compression=50002 deprecated value + + +@pytest.mark.require_creation_option("GTiff", "JXL") +def test_tiff_read_jxl_deprecated_50002(): + ds = gdal.Open("data/gtiff/byte_jxl_deprecated_50002.tif") + assert ds.GetMetadataItem("COMPRESSION", "IMAGE_STRUCTURE") == "JXL" + assert ds.GetRasterBand(1).Checksum() == 4672 + + +############################################################################### +# Test reading Compression=52546 value used in DNG 1.7 + + +@pytest.mark.require_creation_option("GTiff", "JXL") +def test_tiff_read_jxl_dng_1_7_52546(): + ds = gdal.Open("data/gtiff/byte_jxl_dng_1_7_52546.tif") + assert ds.GetMetadataItem("COMPRESSION", "IMAGE_STRUCTURE") == "JXL" + assert ds.GetRasterBand(1).Checksum() == 4672 + + ############################################################################### # Test multi-threaded decoding diff --git a/frmts/gtiff/geotiff.cpp b/frmts/gtiff/geotiff.cpp index 91c8b583a051..db72d8d9faf4 100644 --- a/frmts/gtiff/geotiff.cpp +++ b/frmts/gtiff/geotiff.cpp @@ -965,8 +965,10 @@ static const struct {COMPRESSION_LERC, "LERC_DEFLATE", true}, {COMPRESSION_LERC, "LERC_ZSTD", true}, COMPRESSION_ENTRY(WEBP, true), - COMPRESSION_ENTRY(JXL, true), - COMPRESSION_ENTRY(JXL_DNG_1_7, true), + // COMPRESSION_JXL_DNG_1_7 must be *before* COMPRESSION_JXL + {COMPRESSION_JXL_DNG_1_7, "JXL", true}, + {COMPRESSION_JXL, "JXL", + true}, // deprecated. No longer used for writing since GDAL 3.11 // Compression methods in read-only COMPRESSION_ENTRY(OJPEG, false), diff --git a/frmts/gtiff/gt_overview.cpp b/frmts/gtiff/gt_overview.cpp index 2e86afea2a5d..001273ee9614 100644 --- a/frmts/gtiff/gt_overview.cpp +++ b/frmts/gtiff/gt_overview.cpp @@ -521,7 +521,8 @@ CPLErr GTIFFBuildOverviewsEx(const char *pszFilename, int nBands, nPlanarConfig = PLANARCONFIG_CONTIG; } else if (nCompression == COMPRESSION_WEBP || - nCompression == COMPRESSION_JXL) + nCompression == COMPRESSION_JXL || + nCompression == COMPRESSION_JXL_DNG_1_7) { nPlanarConfig = PLANARCONFIG_CONTIG; } @@ -1036,7 +1037,8 @@ CPLErr GTIFFBuildOverviewsEx(const char *pszFilename, int nBands, } #if HAVE_JXL - if (nCompression == COMPRESSION_JXL) + if (nCompression == COMPRESSION_JXL || + nCompression == COMPRESSION_JXL_DNG_1_7) { if (const char *pszJXLLossLess = GetOptionValue("JXL_LOSSLESS", "JXL_LOSSLESS_OVERVIEW")) diff --git a/frmts/gtiff/gtiffdataset.cpp b/frmts/gtiff/gtiffdataset.cpp index ee65ece7df1e..26d1f917d28c 100644 --- a/frmts/gtiff/gtiffdataset.cpp +++ b/frmts/gtiff/gtiffdataset.cpp @@ -949,7 +949,8 @@ void GTiffDataset::RestoreVolatileParameters(TIFF *hTIFF) if (m_bWebPLossless && m_nCompression == COMPRESSION_WEBP) TIFFSetField(hTIFF, TIFFTAG_WEBP_LOSSLESS, 1); #ifdef HAVE_JXL - if (m_nCompression == COMPRESSION_JXL) + if (m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7) { TIFFSetField(hTIFF, TIFFTAG_JXL_LOSSYNESS, m_bJXLLossless ? JXL_LOSSLESS : JXL_LOSSY); diff --git a/frmts/gtiff/gtiffdataset_read.cpp b/frmts/gtiff/gtiffdataset_read.cpp index 07962792ffe3..1ba913fa4e23 100644 --- a/frmts/gtiff/gtiffdataset_read.cpp +++ b/frmts/gtiff/gtiffdataset_read.cpp @@ -212,7 +212,9 @@ CPLErr GTiffDataset::ReadCompressedData(const char *pszFormat, int nXOff, m_nPhotometric != PHOTOMETRIC_SEPARATED)) || (m_nCompression == COMPRESSION_WEBP && EQUAL(aosTokens[0], "WEBP")) || - (m_nCompression == COMPRESSION_JXL && EQUAL(aosTokens[0], "JXL"))) + ((m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7) && + EQUAL(aosTokens[0], "JXL"))) { std::string osDetailedFormat = aosTokens[0]; @@ -989,6 +991,7 @@ bool GTiffDataset::IsMultiThreadedReadCompatible() const m_nCompression == COMPRESSION_ZSTD || m_nCompression == COMPRESSION_LERC || m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7 || m_nCompression == COMPRESSION_WEBP || m_nCompression == COMPRESSION_JPEG); } @@ -5500,7 +5503,8 @@ CPLErr GTiffDataset::OpenOffset(TIFF *hTIFFIn, toff_t nDirOffsetIn, m_dfMaxZErrorOverview = CPLAtof(pszValue); } #if HAVE_JXL - else if (m_nCompression == COMPRESSION_JXL && + else if ((m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7) && EQUAL(pszKey, "COMPRESSION_REVERSIBILITY")) { if (EQUAL(pszValue, "LOSSLESS")) @@ -5508,7 +5512,8 @@ CPLErr GTiffDataset::OpenOffset(TIFF *hTIFFIn, toff_t nDirOffsetIn, else if (EQUAL(pszValue, "LOSSY")) m_bJXLLossless = false; } - else if (m_nCompression == COMPRESSION_JXL && + else if ((m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7) && EQUAL(pszKey, "JXL_DISTANCE")) { const double dfVal = CPLAtof(pszValue); @@ -5521,7 +5526,8 @@ CPLErr GTiffDataset::OpenOffset(TIFF *hTIFFIn, toff_t nDirOffsetIn, m_fJXLDistance = static_cast(dfVal); } } - else if (m_nCompression == COMPRESSION_JXL && + else if ((m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7) && EQUAL(pszKey, "JXL_ALPHA_DISTANCE")) { const double dfVal = CPLAtof(pszValue); @@ -5533,7 +5539,8 @@ CPLErr GTiffDataset::OpenOffset(TIFF *hTIFFIn, toff_t nDirOffsetIn, m_fJXLAlphaDistance = static_cast(dfVal); } } - else if (m_nCompression == COMPRESSION_JXL && + else if ((m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7) && EQUAL(pszKey, "JXL_EFFORT")) { const int nEffort = atoi(pszValue); @@ -5710,7 +5717,8 @@ CPLErr GTiffDataset::OpenOffset(TIFF *hTIFFIn, toff_t nDirOffsetIn, } } #ifdef HAVE_JXL - else if (m_nCompression == COMPRESSION_JXL) + else if (m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7) { const char *pszReversibility = GetMetadataItem("COMPRESSION_REVERSIBILITY", "IMAGE_STRUCTURE"); @@ -6305,7 +6313,8 @@ const char *GTiffDataset::GetMetadataItem(const char *pszName, if (pszDomain != nullptr && EQUAL(pszDomain, "IMAGE_STRUCTURE")) { if ((m_nCompression == COMPRESSION_WEBP || - m_nCompression == COMPRESSION_JXL) && + m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7) && EQUAL(pszName, "COMPRESSION_REVERSIBILITY") && m_oGTiffMDMD.GetMetadataItem("COMPRESSION_REVERSIBILITY", "IMAGE_STRUCTURE") == nullptr) diff --git a/frmts/gtiff/gtiffdataset_write.cpp b/frmts/gtiff/gtiffdataset_write.cpp index de4c48002ed7..aa45e94280fc 100644 --- a/frmts/gtiff/gtiffdataset_write.cpp +++ b/frmts/gtiff/gtiffdataset_write.cpp @@ -1357,6 +1357,7 @@ bool GTiffDataset::SubmitCompressionJob(int nStripOrTile, GByte *pabyData, m_nCompression == COMPRESSION_ZSTD || m_nCompression == COMPRESSION_LERC || m_nCompression == COMPRESSION_JXL || + m_nCompression == COMPRESSION_JXL_DNG_1_7 || m_nCompression == COMPRESSION_WEBP || m_nCompression == COMPRESSION_JPEG)) { @@ -5255,7 +5256,9 @@ TIFF *GTiffDataset::CreateLL(const char *pszFilename, int nXSize, int nYSize, } #ifdef HAVE_JXL - if (l_nCompression == COMPRESSION_JXL && eType != GDT_Float32) + if ((l_nCompression == COMPRESSION_JXL || + l_nCompression == COMPRESSION_JXL_DNG_1_7) && + eType != GDT_Float32) { // Reflects tif_jxl's GetJXLDataType() if (eType != GDT_Byte && eType != GDT_UInt16) @@ -5899,7 +5902,8 @@ TIFF *GTiffDataset::CreateLL(const char *pszFilename, int nXSize, int nYSize, TIFFSetField(l_hTIFF, TIFFTAG_LERC_MAXZERROR, l_dfMaxZError); } #if HAVE_JXL - if (l_nCompression == COMPRESSION_JXL) + if (l_nCompression == COMPRESSION_JXL || + l_nCompression == COMPRESSION_JXL_DNG_1_7) { TIFFSetField(l_hTIFF, TIFFTAG_JXL_LOSSYNESS, l_bJXLLossless ? JXL_LOSSLESS : JXL_LOSSY); @@ -7883,7 +7887,8 @@ GDALDataset *GTiffDataset::CreateCopy(const char *pszFilename, TIFFSetField(l_hTIFF, TIFFTAG_LERC_MAXZERROR, poDS->m_dfMaxZError); } #if HAVE_JXL - if (l_nCompression == COMPRESSION_JXL) + if (l_nCompression == COMPRESSION_JXL || + l_nCompression == COMPRESSION_JXL_DNG_1_7) { TIFFSetField(l_hTIFF, TIFFTAG_JXL_LOSSYNESS, poDS->m_bJXLLossless ? JXL_LOSSLESS : JXL_LOSSY); diff --git a/frmts/gtiff/gtiffrasterband_read.cpp b/frmts/gtiff/gtiffrasterband_read.cpp index c29be2bc98f4..44097ff8fc31 100644 --- a/frmts/gtiff/gtiffrasterband_read.cpp +++ b/frmts/gtiff/gtiffrasterband_read.cpp @@ -1071,7 +1071,7 @@ void *GTiffRasterBand::CacheMultiRange(int nXOff, int nYOff, int nXSize, VSILFILE *fp = VSI_TIFFGetVSILFile(th); - // An error in VSIFReadMultiRangeL() will not be criticial, + // An error in VSIFReadMultiRangeL() will not be critical, // as this method is an optimization, and if it fails, // tile-by-tile data acquisition will be done, so we can // temporary turn failures into warnings. diff --git a/frmts/libertiff/libertiffdataset.cpp b/frmts/libertiff/libertiffdataset.cpp index df1a276877c8..5b496081fac8 100644 --- a/frmts/libertiff/libertiffdataset.cpp +++ b/frmts/libertiff/libertiffdataset.cpp @@ -58,6 +58,7 @@ struct LIBERTIFFDatasetFileReader final : public LIBERTIFF_NS::FileReader uint64_t size() const override { + // coverity[missing_lock,lock_evasion] if (m_nFileSize == 0) { std::lock_guard oLock(m_oMutex); @@ -342,6 +343,7 @@ class LIBERTIFFBand final : public GDALPamRasterBand CPLDebug("LIBERTIFF", "GetLockedBlockRef() called"); } std::lock_guard oLock(m_oMutexBlockCache); + // coverity[sleep] return GDALRasterBand::GetLockedBlockRef(nXBlockOff, nYBlockOff, bJustInitialize); } @@ -1246,7 +1248,7 @@ bool LIBERTIFFDataset::ReadBlock(GByte *pabyBlockData, int nBlockXOff, if constexpr (sizeof(size_t) < sizeof(uint64_t)) { - if (size64 > std::numeric_limits::max()) + if (size64 > std::numeric_limits::max() - 1) { CPLError(CE_Failure, CPLE_NotSupported, "Too large strile"); return false; @@ -2171,6 +2173,13 @@ bool LIBERTIFFDataset::Open(std::unique_ptr image) } const GDALDataType eDT = ComputeGDALDataType(); + if (eDT == GDT_Unknown) + { + CPLDebug("LIBERTIFF", + "BitsPerSample = %u and SampleFormat=%u unhandled", + m_image->bitsPerSample(), m_image->sampleFormat()); + return false; + } // Deal with Predictor tag if (m_image->predictor() == 2) diff --git a/gcore/gdalalgorithm.cpp b/gcore/gdalalgorithm.cpp index 5fbc3ba7b21f..9f138cf5683a 100644 --- a/gcore/gdalalgorithm.cpp +++ b/gcore/gdalalgorithm.cpp @@ -2258,7 +2258,7 @@ GDALAlgorithm::AddOpenOptionsArg(std::vector *pValue) { auto poDM = GetGDALDriverManager(); auto &datasetValue = inputArg->Get(); - const auto osDSName = datasetValue.GetName(); + const auto &osDSName = datasetValue.GetName(); const std::string osExt = CPLGetExtension(osDSName.c_str()); if (!osExt.empty()) { @@ -2575,7 +2575,7 @@ GDALAlgorithm::AddCreationOptionsArg(std::vector *pValue) { auto poDM = GetGDALDriverManager(); auto &datasetValue = outputArg->Get(); - const auto osDSName = datasetValue.GetName(); + const auto &osDSName = datasetValue.GetName(); const std::string osExt = CPLGetExtension(osDSName.c_str()); if (!osExt.empty()) { @@ -2665,7 +2665,7 @@ GDALAlgorithm::AddLayerCreationOptionsArg(std::vector *pValue) { auto poDM = GetGDALDriverManager(); auto &datasetValue = outputArg->Get(); - const auto osDSName = datasetValue.GetName(); + const auto &osDSName = datasetValue.GetName(); const std::string osExt = CPLGetExtension(osDSName.c_str()); if (!osExt.empty()) { @@ -3247,7 +3247,7 @@ std::string GDALAlgorithm::GetUsageAsJSON() const if (subAlg->m_displayInJSONUsage) { CPLJSONDocument oSubDoc; - oSubDoc.LoadMemory(subAlg->GetUsageAsJSON()); + CPL_IGNORE_RET_VAL(oSubDoc.LoadMemory(subAlg->GetUsageAsJSON())); jSubAlgorithms.Add(oSubDoc.GetRoot()); } } diff --git a/gcore/gdalalgorithm.h b/gcore/gdalalgorithm.h index 44d0a9ecbf73..a42024f971d5 100644 --- a/gcore/gdalalgorithm.h +++ b/gcore/gdalalgorithm.h @@ -1627,7 +1627,7 @@ class CPL_DLL GDALInConstructionAlgorithmArg final : public GDALAlgorithmArg GDALInConstructionAlgorithmArg &SetAutoCompleteFunction( std::function(const std::string &)> f) { - m_autoCompleteFunction = f; + m_autoCompleteFunction = std::move(f); return *this; } diff --git a/gcore/gdalmultidim.cpp b/gcore/gdalmultidim.cpp index cda4be4d99f7..c47f215896bf 100644 --- a/gcore/gdalmultidim.cpp +++ b/gcore/gdalmultidim.cpp @@ -9514,12 +9514,12 @@ GDALDatasetFromArray *GDALDatasetFromArray::Create( BandImageryMetadata &item = aoBandImageryMetadata[iExtraDimIdx]; if (oJsonItem.GetName() == "CENTRAL_WAVELENGTH_UM") { - item.poCentralWavelengthArray = poArray; + item.poCentralWavelengthArray = std::move(poArray); item.dfCentralWavelengthToMicrometer = dfConvToUM; } else { - item.poFWHMArray = poArray; + item.poFWHMArray = std::move(poArray); item.dfFWHMToMicrometer = dfConvToUM; } }