Skip to content

Commit c106b96

Browse files
authored
Merge pull request #11554 from OSGeo/backport-11553-to-release/3.10
[Backport release/3.10] PNG: fix reading 16-bit interlaced images (on little-endian machines)
2 parents 2231508 + ff54154 commit c106b96

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed
775 Bytes
Loading

autotest/gdrivers/png.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,13 @@ def test_png_copy_mdd():
472472
ds = None
473473

474474
gdal.Unlink(filename)
475+
476+
477+
###############################################################################
478+
# Read test of 16-bit interlaced
479+
480+
481+
def test_png_read_interlace_16_bit():
482+
483+
ds = gdal.Open("data/png/uint16_interlaced.png")
484+
assert ds.GetRasterBand(1).Checksum() == 4672

frmts/png/pngdataset.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,21 @@ CPLErr PNGDataset::LoadInterlacedChunk(int iLine)
14051405

14061406
bool bRet = safe_png_read_image(hPNG, png_rows, sSetJmpContext);
14071407

1408+
// Do swap on LSB machines. 16-bit PNG data is stored in MSB format.
1409+
#ifdef CPL_LSB
1410+
if (bRet && nBitDepth == 16)
1411+
{
1412+
for (int i = 0; i < GetRasterYSize(); i++)
1413+
{
1414+
if (i >= nBufferStartLine && i < nBufferStartLine + nBufferLines)
1415+
{
1416+
GDALSwapWords(png_rows[i], 2,
1417+
GetRasterXSize() * GetRasterCount(), 2);
1418+
}
1419+
}
1420+
}
1421+
#endif
1422+
14081423
CPLFree(png_rows);
14091424
CPLFree(dummy_row);
14101425
if (!bRet)

0 commit comments

Comments
 (0)