PNG: fix reading 16-bit interlaced images (on little-endian machines)
Fixes https://lists.osgeo.org/pipermail/gdal-dev/2024-December/059989.html
This commit is contained in:
parent
8d5ca35da0
commit
73839c499a
Binary file not shown.
After Width: | Height: | Size: 775 B |
|
@ -471,3 +471,13 @@ def test_png_copy_mdd():
|
|||
ds = None
|
||||
|
||||
gdal.Unlink(filename)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Read test of 16-bit interlaced
|
||||
|
||||
|
||||
def test_png_read_interlace_16_bit():
|
||||
|
||||
ds = gdal.Open("data/png/uint16_interlaced.png")
|
||||
assert ds.GetRasterBand(1).Checksum() == 4672
|
||||
|
|
|
@ -1405,6 +1405,21 @@ CPLErr PNGDataset::LoadInterlacedChunk(int iLine)
|
|||
|
||||
bool bRet = safe_png_read_image(hPNG, png_rows, sSetJmpContext);
|
||||
|
||||
// Do swap on LSB machines. 16-bit PNG data is stored in MSB format.
|
||||
#ifdef CPL_LSB
|
||||
if (bRet && nBitDepth == 16)
|
||||
{
|
||||
for (int i = 0; i < GetRasterYSize(); i++)
|
||||
{
|
||||
if (i >= nBufferStartLine && i < nBufferStartLine + nBufferLines)
|
||||
{
|
||||
GDALSwapWords(png_rows[i], 2,
|
||||
GetRasterXSize() * GetRasterCount(), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
CPLFree(png_rows);
|
||||
CPLFree(dummy_row);
|
||||
if (!bRet)
|
||||
|
|
Loading…
Reference in New Issue