Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from OSGeo:master #137

Merged
merged 9 commits into from
Jan 7, 2025
Binary file not shown.
Binary file added autotest/gcore/data/gtiff/byte_jxl_dng_1_7_52546.tif
Binary file not shown.
2 changes: 1 addition & 1 deletion autotest/gcore/gcps2geotransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_gcps2gt_2():

def test_gcps2gt_3():

approx_ok = 0
approx_ok = False
gt = gdal.GCPsToGeoTransform(
_list2gcps(
[
Expand Down
22 changes: 22 additions & 0 deletions autotest/gcore/tiff_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions frmts/gtiff/geotiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 4 additions & 2 deletions frmts/gtiff/gt_overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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"))
Expand Down
3 changes: 2 additions & 1 deletion frmts/gtiff/gtiffdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 16 additions & 7 deletions frmts/gtiff/gtiffdataset_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -5500,15 +5503,17 @@ 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"))
m_bJXLLossless = true;
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);
Expand All @@ -5521,7 +5526,8 @@ CPLErr GTiffDataset::OpenOffset(TIFF *hTIFFIn, toff_t nDirOffsetIn,
m_fJXLDistance = static_cast<float>(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);
Expand All @@ -5533,7 +5539,8 @@ CPLErr GTiffDataset::OpenOffset(TIFF *hTIFFIn, toff_t nDirOffsetIn,
m_fJXLAlphaDistance = static_cast<float>(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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions frmts/gtiff/gtiffdataset_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion frmts/gtiff/gtiffrasterband_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion frmts/libertiff/libertiffdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1246,7 +1248,7 @@ bool LIBERTIFFDataset::ReadBlock(GByte *pabyBlockData, int nBlockXOff,

if constexpr (sizeof(size_t) < sizeof(uint64_t))
{
if (size64 > std::numeric_limits<size_t>::max())
if (size64 > std::numeric_limits<size_t>::max() - 1)
{
CPLError(CE_Failure, CPLE_NotSupported, "Too large strile");
return false;
Expand Down
8 changes: 4 additions & 4 deletions gcore/gdalalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@ GDALAlgorithm::AddOpenOptionsArg(std::vector<std::string> *pValue)
{
auto poDM = GetGDALDriverManager();
auto &datasetValue = inputArg->Get<GDALArgDatasetValue>();
const auto osDSName = datasetValue.GetName();
const auto &osDSName = datasetValue.GetName();
const std::string osExt = CPLGetExtension(osDSName.c_str());
if (!osExt.empty())
{
Expand Down Expand Up @@ -2575,7 +2575,7 @@ GDALAlgorithm::AddCreationOptionsArg(std::vector<std::string> *pValue)
{
auto poDM = GetGDALDriverManager();
auto &datasetValue = outputArg->Get<GDALArgDatasetValue>();
const auto osDSName = datasetValue.GetName();
const auto &osDSName = datasetValue.GetName();
const std::string osExt = CPLGetExtension(osDSName.c_str());
if (!osExt.empty())
{
Expand Down Expand Up @@ -2665,7 +2665,7 @@ GDALAlgorithm::AddLayerCreationOptionsArg(std::vector<std::string> *pValue)
{
auto poDM = GetGDALDriverManager();
auto &datasetValue = outputArg->Get<GDALArgDatasetValue>();
const auto osDSName = datasetValue.GetName();
const auto &osDSName = datasetValue.GetName();
const std::string osExt = CPLGetExtension(osDSName.c_str());
if (!osExt.empty())
{
Expand Down Expand Up @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion gcore/gdalalgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ class CPL_DLL GDALInConstructionAlgorithmArg final : public GDALAlgorithmArg
GDALInConstructionAlgorithmArg &SetAutoCompleteFunction(
std::function<std::vector<std::string>(const std::string &)> f)
{
m_autoCompleteFunction = f;
m_autoCompleteFunction = std::move(f);
return *this;
}

Expand Down
4 changes: 2 additions & 2 deletions gcore/gdalmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Loading