From f7480d243356f599357a30a9bb74e7253f0542cf Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Mon, 4 Oct 2010 12:41:48 -0400 Subject: [PATCH] Fixed bug when images is smaller than 64x64. Now we compute the proper number of resolution levels to use when an images has size smaller than 64x64 pixels. Change-Id: I27b4d784c4416b88a8536eff44b285b3b9b2fdd6 --- Code/Review/itkJPEG2000ImageIO.cxx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Code/Review/itkJPEG2000ImageIO.cxx b/Code/Review/itkJPEG2000ImageIO.cxx index 53027b74d3..7e1ba99e4d 100644 --- a/Code/Review/itkJPEG2000ImageIO.cxx +++ b/Code/Review/itkJPEG2000ImageIO.cxx @@ -766,6 +766,30 @@ ::Write(const void *buffer) w = this->m_Dimensions[0]; h = this->m_Dimensions[1]; + + // Compute the proper number of resolutions to use. + // This is mostly done for images smaller than 64 pixels + // along any dimension. + unsigned int numberOfResolutions = 0; + + int tw = w >> 1; + int th = h >> 1; + + while( tw && th ) + { + numberOfResolutions++; + tw >>= 1; + th >>= 1; + } + + // Clamp the number of resolutions to 6. + if( numberOfResolutions > 6 ) + { + numberOfResolutions = 6; + } + + parameters.numresolution = numberOfResolutions; + OPJ_COLOR_SPACE color_space = CLRSPC_GRAY; opj_image_cmptparm_t cmptparm[3];