Skip to content

Commit

Permalink
JP2OpenJPEG: fix reading overviews, when tiled API is used, and the d…
Browse files Browse the repository at this point in the history
…imensions of the full resolution image are not a multiple of 2^numresolutions (fixes #1860)
  • Loading branch information
rouault committed Sep 19, 2019
1 parent dd7abfb commit 44fcc1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions autotest/gdrivers/jp2openjpeg.py
Expand Up @@ -3094,6 +3094,22 @@ def test_jp2openjpeg_external_overviews_multiple_band():
assert cs == [6233, 7706, 26085]

###############################################################################
# Test accessing overview levels when the dimensions of the full resolution
# image are not a multiple of 2^numresolutions


def test_jp2openjpeg_odd_dimensions():

if gdaltest.jp2openjpeg_drv is None:
pytest.skip()

ds = gdal.Open('data/513x513.jp2')
cs = ds.GetRasterBand(1).GetOverview(0).Checksum()
ds = None

assert cs == 29642

###############################################################################


def test_jp2openjpeg_cleanup():
Expand Down
5 changes: 3 additions & 2 deletions gdal/frmts/openjpeg/openjpegdataset.cpp
Expand Up @@ -2162,8 +2162,9 @@ GDALDataset *JP2OpenJPEGDataset::Open( GDALOpenInfo * poOpenInfo )
(nW > 128 || nH > 128) &&
(poDS->bUseSetDecodeArea || ((nTileW % 2) == 0 && (nTileH % 2) == 0)))
{
nW /= 2;
nH /= 2;
// This must be this exact formula per the JPEG2000 standard
nW = (nW + 1) / 2;
nH = (nH + 1) / 2;

poDS->papoOverviewDS = (JP2OpenJPEGDataset**) CPLRealloc(
poDS->papoOverviewDS,
Expand Down

0 comments on commit 44fcc1b

Please sign in to comment.