Skip to content

Commit

Permalink
JP2OpenJPEG: correctly set coordinates to opj_set_decode_area() on ov…
Browse files Browse the repository at this point in the history
…erviews (linked to previous fix)
  • Loading branch information
rouault committed Sep 26, 2019
1 parent 5e26b46 commit 9f1c8b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Binary file not shown.
6 changes: 6 additions & 0 deletions autotest/gdrivers/jp2openjpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3109,6 +3109,12 @@ def test_jp2openjpeg_odd_dimensions():

assert cs == 29642

# Check that we don't request outside of the full resolution coordinates
ds = gdal.Open('data/single_block_32769_16385.jp2')
assert ds.ReadRaster(0,0,ds.RasterXSize,ds.RasterYSize,2049,1025)
assert gdal.GetLastErrorMsg() == ''
ds = None

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


Expand Down
14 changes: 10 additions & 4 deletions gdal/frmts/openjpeg/openjpegdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class JP2OpenJPEGDataset final: public GDALJP2AbstractDataset

int bIs420 = FALSE;

int nParentXSize = 0;
int nParentYSize = 0;
int iLevel = 0;
int nOverviewCount = 0;
JP2OpenJPEGDataset** papoOverviewDS = nullptr;
Expand Down Expand Up @@ -927,10 +929,10 @@ CPLErr JP2OpenJPEGDataset::ReadBlock( int nBand, VSILFILE* fpIn,
/* The decode area must be expressed in grid reference, ie at full*/
/* scale */
if (!opj_set_decode_area(pCodec,psImage,
(nBlockXOff*nBlockXSize) << iLevel,
(nBlockYOff*nBlockYSize) << iLevel,
(nBlockXOff*nBlockXSize+nWidthToRead) << iLevel,
(nBlockYOff*nBlockYSize+nHeightToRead) << iLevel))
static_cast<int>(static_cast<GIntBig>(nBlockXOff*nBlockXSize) * nParentXSize / nRasterXSize),
static_cast<int>(static_cast<GIntBig>(nBlockYOff*nBlockYSize) * nParentYSize / nRasterYSize),
static_cast<int>(static_cast<GIntBig>(nBlockXOff*nBlockXSize+nWidthToRead) * nParentXSize / nRasterXSize),
static_cast<int>(static_cast<GIntBig>(nBlockYOff*nBlockYSize+nHeightToRead) * nParentYSize / nRasterYSize)))
{
CPLError(CE_Failure, CPLE_AppDefined, "opj_set_decode_area() failed");
eErr = CE_Failure;
Expand Down Expand Up @@ -2142,6 +2144,8 @@ GDALDataset *JP2OpenJPEGDataset::Open( GDALOpenInfo * poOpenInfo )
/* -------------------------------------------------------------------- */
int nW = poDS->nRasterXSize;
int nH = poDS->nRasterYSize;
poDS->nParentXSize = poDS->nRasterXSize;
poDS->nParentYSize = poDS->nRasterYSize;

/* Lower resolutions are not compatible with a color-table */
if( poCT != nullptr )
Expand Down Expand Up @@ -2170,6 +2174,8 @@ GDALDataset *JP2OpenJPEGDataset::Open( GDALOpenInfo * poOpenInfo )
poDS->papoOverviewDS,
(poDS->nOverviewCount + 1) * sizeof(JP2OpenJPEGDataset*));
JP2OpenJPEGDataset* poODS = new JP2OpenJPEGDataset();
poODS->nParentXSize = poDS->nRasterXSize;
poODS->nParentYSize = poDS->nRasterYSize;
poODS->SetDescription( poOpenInfo->pszFilename );
poODS->iLevel = poDS->nOverviewCount + 1;
poODS->bSingleTiled = poDS->bSingleTiled;
Expand Down

0 comments on commit 9f1c8b8

Please sign in to comment.