diff --git a/Code/IO/otbJPEG2000ImageIO.cxx b/Code/IO/otbJPEG2000ImageIO.cxx index c1a66eff5fdf1180e6201925073a888015afcf89..a24bf7264db0876b48a92c8d4c5b41e4a9cac4db 100644 --- a/Code/IO/otbJPEG2000ImageIO.cxx +++ b/Code/IO/otbJPEG2000ImageIO.cxx @@ -711,6 +711,11 @@ void JPEG2000ImageIO::Read(void* buffer) { opj_image_t * currentTile = itTile->second; + if(!currentTile) + { + itkExceptionMacro(<<"Tile "<<itTile->first<<" needed but not loaded."); + } + unsigned int lWidthSrc; // Width of the input pixel in nb of pixel unsigned int lHeightDest; // Height of the area where write in nb of pixel unsigned int lWidthDest; // Width of the area where write in nb of pixel @@ -866,6 +871,22 @@ ITK_THREAD_RETURN_TYPE JPEG2000ImageIO::ThreaderCallback( void *arg ) otbMsgDevMacro(<< " Tile " << tiles->at(i).first << " decoded by thread "<<threadId); } + unsigned int lastTile = threadCount*tilesPerThread + threadId; + + // TODO: check this last part + + if(lastTile < tiles->size()) + { + tiles->at(lastTile).second = readers.at(threadId)->DecodeTile(tiles->at(lastTile).first); + + if(!tiles->at(lastTile).second) + { + readers.at(threadId)->Clean(); + itkGenericExceptionMacro(" otbopenjpeg failed to decode the desired tile "<<tiles->at(lastTile).first << "!"); + } + otbMsgDevMacro(<<" Tile " << tiles->at(lastTile).first << " decoded by thread "<<threadId); + } + return ITK_THREAD_RETURN_VALUE; }