diff options
Diffstat (limited to 'core/fxcodec')
-rw-r--r-- | core/fxcodec/codec/codec_int.h | 1 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_flate.cpp | 6 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jpx_opj.cpp | 16 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_tiff.cpp | 6 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Context.cpp | 18 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Image.cpp | 195 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_TrdProc.cpp | 69 |
7 files changed, 146 insertions, 165 deletions
diff --git a/core/fxcodec/codec/codec_int.h b/core/fxcodec/codec/codec_int.h index d2f44dd674..d19a694222 100644 --- a/core/fxcodec/codec/codec_int.h +++ b/core/fxcodec/codec/codec_int.h @@ -47,7 +47,6 @@ class CCodec_ScanlineDecoder : public ICodec_ScanlineDecoder { ~CCodec_ScanlineDecoder() override; // ICodec_ScanlineDecoder - FX_DWORD GetSrcOffset() override { return -1; } void DownScale(int dest_width, int dest_height) override; const uint8_t* GetScanline(int line) override; FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) override; diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp index 49a4f34166..27416f1c67 100644 --- a/core/fxcodec/codec/fx_codec_flate.cpp +++ b/core/fxcodec/codec/fx_codec_flate.cpp @@ -147,7 +147,7 @@ int CLZWDecoder::Decode(uint8_t* dest_buf, m_Early = bEarlyChange ? 1 : 0; m_nCodes = 0; FX_DWORD old_code = (FX_DWORD)-1; - uint8_t last_char; + uint8_t last_char = 0; while (1) { if (m_InPos + m_CodeLen > src_size * 8) { break; @@ -942,7 +942,7 @@ FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, offset = src_size; int err = decoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChange); if (err || dest_size == 0 || dest_size + 1 < dest_size) { - return -1; + return static_cast<FX_DWORD>(-1); } } { @@ -965,7 +965,7 @@ FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); } - return ret ? offset : -1; + return ret ? offset : static_cast<FX_DWORD>(-1); } FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size, diff --git a/core/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/fxcodec/codec/fx_codec_jpx_opj.cpp index aaa89388b8..a57b93df22 100644 --- a/core/fxcodec/codec/fx_codec_jpx_opj.cpp +++ b/core/fxcodec/codec/fx_codec_jpx_opj.cpp @@ -24,16 +24,17 @@ static void fx_warning_callback(const char* msg, void* client_data) { static void fx_info_callback(const char* msg, void* client_data) { (void)client_data; } + OPJ_SIZE_T opj_read_from_memory(void* p_buffer, OPJ_SIZE_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast<OPJ_SIZE_T>(-1); } // Reads at EOF return an error code. if (srcData->offset >= srcData->src_size) { - return -1; + return static_cast<OPJ_SIZE_T>(-1); } OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; OPJ_SIZE_T readlength = nb_bytes < bufferLength ? nb_bytes : bufferLength; @@ -41,16 +42,17 @@ OPJ_SIZE_T opj_read_from_memory(void* p_buffer, srcData->offset += readlength; return readlength; } + OPJ_SIZE_T opj_write_from_memory(void* p_buffer, OPJ_SIZE_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast<OPJ_SIZE_T>(-1); } // Writes at EOF return an error code. if (srcData->offset >= srcData->src_size) { - return -1; + return static_cast<OPJ_SIZE_T>(-1); } OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; OPJ_SIZE_T writeLength = nb_bytes < bufferLength ? nb_bytes : bufferLength; @@ -58,17 +60,18 @@ OPJ_SIZE_T opj_write_from_memory(void* p_buffer, srcData->offset += writeLength; return writeLength; } + OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast<OPJ_OFF_T>(-1); } // Offsets are signed and may indicate a negative skip. Do not support this // because of the strange return convention where either bytes skipped or // -1 is returned. Following that convention, a successful relative seek of // -1 bytes would be required to to give the same result as the error case. if (nb_bytes < 0) { - return -1; + return static_cast<OPJ_OFF_T>(-1); } // FIXME: use std::make_unsigned<OPJ_OFF_T>::type once c++11 lib is OK'd. uint64_t unsignedNbBytes = static_cast<uint64_t>(nb_bytes); @@ -89,6 +92,7 @@ OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { } return nb_bytes; } + OPJ_BOOL opj_seek_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { diff --git a/core/fxcodec/codec/fx_codec_tiff.cpp b/core/fxcodec/codec/fx_codec_tiff.cpp index 2af92f2f12..0312622fb4 100644 --- a/core/fxcodec/codec/fx_codec_tiff.cpp +++ b/core/fxcodec/codec/fx_codec_tiff.cpp @@ -122,20 +122,20 @@ static toff_t _tiff_seek(thandle_t context, toff_t offset, int whence) { case 2: if (pTiffContext->isDecoder) { if (pTiffContext->io.in->GetSize() < (FX_FILESIZE)offset) { - return -1; + return static_cast<toff_t>(-1); } pTiffContext->offset = (FX_DWORD)(pTiffContext->io.in->GetSize() - offset); } else { if (pTiffContext->io.out->GetSize() < (FX_FILESIZE)offset) { - return -1; + return static_cast<toff_t>(-1); } pTiffContext->offset = (FX_DWORD)(pTiffContext->io.out->GetSize() - offset); } break; default: - return -1; + return static_cast<toff_t>(-1); } ASSERT(pTiffContext->isDecoder ? (pTiffContext->offset <= (FX_DWORD)pTiffContext->io.in->GetSize()) diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 89157b9bf1..805a102c74 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -201,7 +201,7 @@ int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, } int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; - int32_t nRet; + int32_t nRet = 0; if (m_PauseStep <= 1) { nRet = decode_EmbedOrgnazation(pPause); } else if (m_PauseStep == 2) { @@ -683,14 +683,14 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { } pTRD->SBRTEMPLATE = (wFlags >> 15) & 0x0001; - uint8_t cSBHUFFFS; - uint8_t cSBHUFFDS; - uint8_t cSBHUFFDT; - uint8_t cSBHUFFRDW; - uint8_t cSBHUFFRDH; - uint8_t cSBHUFFRDX; - uint8_t cSBHUFFRDY; - uint8_t cSBHUFFRSIZE; + uint8_t cSBHUFFFS = 0; + uint8_t cSBHUFFDS = 0; + uint8_t cSBHUFFDT = 0; + uint8_t cSBHUFFRDW = 0; + uint8_t cSBHUFFRDH = 0; + uint8_t cSBHUFFRDX = 0; + uint8_t cSBHUFFRDY = 0; + uint8_t cSBHUFFRSIZE = 0; if (pTRD->SBHUFF == 1) { if (m_pStream->readShortInteger(&wFlags) != 0) return JBIG2_ERROR_TOO_SHORT; diff --git a/core/fxcodec/jbig2/JBig2_Image.cpp b/core/fxcodec/jbig2/JBig2_Image.cpp index 311c38270e..dddc1d29d0 100644 --- a/core/fxcodec/jbig2/JBig2_Image.cpp +++ b/core/fxcodec/jbig2/JBig2_Image.cpp @@ -665,74 +665,46 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, int32_t y, JBig2ComposeOp op, const FX_RECT* pSrcRect) { - int32_t xs0, ys0, xs1, ys1, xd0, yd0, xd1, yd1, xx, yy, w, h, middleDwords, - lineLeft; - FX_DWORD s1, d1, d2, shift, shift1, shift2, tmp, tmp1, tmp2, maskL, maskR, - maskM; - uint8_t *lineSrc, *lineDst, *sp, *dp; - int32_t sw, sh; if (!m_pData) { return FALSE; } + // TODO(weili): Check whether the range check is correct. Should x>=1048576? if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { return FALSE; } - sw = pSrcRect->Width(); - sh = pSrcRect->Height(); - if (y < 0) { - ys0 = -y; - } else { - ys0 = 0; - } - if (y + sh > pDst->m_nHeight) { - ys1 = pDst->m_nHeight - y; - } else { - ys1 = sh; - } - if (x < 0) { - xs0 = -x; - } else { - xs0 = 0; - } - if (x + sw > pDst->m_nWidth) { - xs1 = pDst->m_nWidth - x; - } else { - xs1 = sw; - } + int32_t sw = pSrcRect->Width(); + int32_t sh = pSrcRect->Height(); + int32_t ys0 = y < 0 ? -y : 0; + int32_t ys1 = y + sh > pDst->m_nHeight ? pDst->m_nHeight - y : sh; + int32_t xs0 = x < 0 ? -x : 0; + int32_t xs1 = x + sw > pDst->m_nWidth ? pDst->m_nWidth - x : sw; if ((ys0 >= ys1) || (xs0 >= xs1)) { return 0; } - w = xs1 - xs0; - h = ys1 - ys0; - if (y < 0) { - yd0 = 0; - } else { - yd0 = y; - } - if (x < 0) { - xd0 = 0; - } else { - xd0 = x; - } - xd1 = xd0 + w; - yd1 = yd0 + h; - d1 = xd0 & 31; - d2 = xd1 & 31; - s1 = xs0 & 31; - maskL = 0xffffffff >> d1; - maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32); - maskM = maskL & maskR; - lineSrc = m_pData + (pSrcRect->top + ys0) * m_nStride + - (((xs0 + pSrcRect->left) >> 5) << 2); - lineLeft = m_nStride - ((xs0 >> 5) << 2); - lineDst = pDst->m_pData + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2); + int32_t w = xs1 - xs0; + int32_t h = ys1 - ys0; + int32_t yd0 = y < 0 ? 0 : y; + int32_t xd0 = x < 0 ? 0 : x; + int32_t xd1 = xd0 + w; + int32_t yd1 = yd0 + h; + int32_t d1 = xd0 & 31; + int32_t d2 = xd1 & 31; + int32_t s1 = xs0 & 31; + int32_t maskL = 0xffffffff >> d1; + int32_t maskR = 0xffffffff << ((32 - (xd1 & 31)) % 32); + int32_t maskM = maskL & maskR; + uint8_t* lineSrc = m_pData + (pSrcRect->top + ys0) * m_nStride + + (((xs0 + pSrcRect->left) >> 5) << 2); + int32_t lineLeft = m_nStride - ((xs0 >> 5) << 2); + uint8_t* lineDst = pDst->m_pData + yd0 * pDst->m_nStride + ((xd0 >> 5) << 2); if ((xd0 & ~31) == ((xd1 - 1) & ~31)) { if ((xs0 & ~31) == ((xs1 - 1) & ~31)) { if (s1 > d1) { - shift = s1 - d1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = JBIG2_GETDWORD(lineSrc) << shift; - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift = s1 - d1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(lineSrc) << shift; + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -758,10 +730,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else { - shift = d1 - s1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = JBIG2_GETDWORD(lineSrc) >> shift; - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift = d1 - s1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(lineSrc) >> shift; + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -788,12 +761,13 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, } } } else { - shift1 = s1 - d1; - shift2 = 32 - shift1; - for (yy = yd0; yy < yd1; yy++) { - tmp1 = (JBIG2_GETDWORD(lineSrc) << shift1) | - (JBIG2_GETDWORD(lineSrc + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD shift1 = s1 - d1; + FX_DWORD shift2 = 32 - shift1; + for (int32_t yy = yd0; yy < yd1; yy++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(lineSrc) << shift1) | + (JBIG2_GETDWORD(lineSrc + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(lineDst); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskM) | ((tmp1 | tmp2) & maskM); @@ -821,16 +795,17 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, } } else { if (s1 > d1) { - shift1 = s1 - d1; - shift2 = 32 - shift1; - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + FX_DWORD shift1 = s1 - d1; + FX_DWORD shift2 = 32 - shift1; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = (JBIG2_GETDWORD(sp) << shift1) | - (JBIG2_GETDWORD(sp + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | + (JBIG2_GETDWORD(sp + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -855,10 +830,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, sp += 4; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = (JBIG2_GETDWORD(sp) << shift1) | - (JBIG2_GETDWORD(sp + 4) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | + (JBIG2_GETDWORD(sp + 4) >> shift2); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -884,11 +860,12 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift1) | (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> shift2); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); @@ -915,13 +892,14 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else if (s1 == d1) { - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -946,9 +924,10 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, sp += 4; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -974,8 +953,9 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = JBIG2_GETDWORD(sp); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); @@ -1002,15 +982,16 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, lineDst += pDst->m_nStride; } } else { - shift1 = d1 - s1; - shift2 = 32 - shift1; - middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); - for (yy = yd0; yy < yd1; yy++) { - sp = lineSrc; - dp = lineDst; + FX_DWORD shift1 = d1 - s1; + FX_DWORD shift2 = 32 - shift1; + int32_t middleDwords = (xd1 >> 5) - ((xd0 + 31) >> 5); + for (int32_t yy = yd0; yy < yd1; yy++) { + uint8_t* sp = lineSrc; + uint8_t* dp = lineDst; if (d1 != 0) { - tmp1 = JBIG2_GETDWORD(sp) >> shift1; - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp1 = JBIG2_GETDWORD(sp) >> shift1; + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskL) | ((tmp1 | tmp2) & maskL); @@ -1034,10 +1015,11 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp[3] = (uint8_t)tmp; dp += 4; } - for (xx = 0; xx < middleDwords; xx++) { - tmp1 = (JBIG2_GETDWORD(sp) << shift2) | - ((JBIG2_GETDWORD(sp + 4)) >> shift1); - tmp2 = JBIG2_GETDWORD(dp); + for (int32_t xx = 0; xx < middleDwords; xx++) { + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift2) | + ((JBIG2_GETDWORD(sp + 4)) >> shift1); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = tmp1 | tmp2; @@ -1063,11 +1045,12 @@ FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, dp += 4; } if (d2 != 0) { - tmp1 = + FX_DWORD tmp1 = (JBIG2_GETDWORD(sp) << shift2) | (((sp + 4) < lineSrc + lineLeft ? JBIG2_GETDWORD(sp + 4) : 0) >> shift1); - tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp2 = JBIG2_GETDWORD(dp); + FX_DWORD tmp = 0; switch (op) { case JBIG2_COMPOSE_OR: tmp = (tmp2 & ~maskR) | ((tmp1 | tmp2) & maskR); diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp index 401249e3f2..1a078a1592 100644 --- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp @@ -15,48 +15,39 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, JBig2ArithCtx* grContext) { - int32_t STRIPT, FIRSTS; - FX_DWORD NINSTANCES; - int32_t DT, DFS, CURS; - int32_t SI, TI; - CJBig2_Image* IBI; - FX_DWORD WI, HI; - int32_t IDS; - FX_BOOL RI; - int32_t RDWI, RDHI, RDXI, RDYI; - CJBig2_Image* IBOI; - FX_DWORD WOI, HOI; - FX_BOOL bFirst; - FX_DWORD nTmp; - int32_t nVal, nBits; std::unique_ptr<CJBig2_HuffmanDecoder> pHuffmanDecoder( new CJBig2_HuffmanDecoder(pStream)); std::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); SBREG->fill(SBDEFPIXEL); + int32_t STRIPT; if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) return nullptr; STRIPT *= SBSTRIPS; STRIPT = -STRIPT; - FIRSTS = 0; - NINSTANCES = 0; + FX_DWORD NINSTANCES = 0; while (NINSTANCES < SBNUMINSTANCES) { + int32_t DT; if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &DT) != 0) return nullptr; DT *= SBSTRIPS; STRIPT = STRIPT + DT; - bFirst = TRUE; + bool bFirst = true; + int32_t FIRSTS = 0; + int32_t CURS = 0; for (;;) { if (bFirst) { + int32_t DFS; if (pHuffmanDecoder->decodeAValue(SBHUFFFS, &DFS) != 0) return nullptr; FIRSTS = FIRSTS + DFS; CURS = FIRSTS; - bFirst = FALSE; + bFirst = false; } else { - nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); + int32_t IDS; + int32_t nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); if (nVal == JBIG2_OOB) { break; } else if (nVal != 0) { @@ -67,20 +58,22 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, } uint8_t CURT = 0; if (SBSTRIPS != 1) { - nTmp = 1; + FX_DWORD nTmp = 1; while ((FX_DWORD)(1 << nTmp) < SBSTRIPS) { nTmp++; } + int32_t nVal; if (pStream->readNBits(nTmp, &nVal) != 0) return nullptr; CURT = nVal; } - TI = STRIPT + CURT; - nVal = 0; - nBits = 0; + int32_t TI = STRIPT + CURT; + int32_t nVal = 0; + int32_t nBits = 0; FX_DWORD IDI; for (;;) { + FX_DWORD nTmp; if (pStream->read1Bit(&nTmp) != 0) return nullptr; @@ -96,16 +89,18 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, break; } } - if (SBREFINE == 0) { - RI = 0; - } else { - if (pStream->read1Bit(&RI) != 0) { - return nullptr; - } + FX_BOOL RI = 0; + if (SBREFINE != 0 && pStream->read1Bit(&RI) != 0) { + return nullptr; } + CJBig2_Image* IBI = nullptr; if (RI == 0) { IBI = SBSYMS[IDI]; } else { + int32_t RDWI; + int32_t RDHI; + int32_t RDXI; + int32_t RDYI; if ((pHuffmanDecoder->decodeAValue(SBHUFFRDW, &RDWI) != 0) || (pHuffmanDecoder->decodeAValue(SBHUFFRDH, &RDHI) != 0) || (pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDXI) != 0) || @@ -114,13 +109,13 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, return nullptr; } pStream->alignByte(); - nTmp = pStream->getOffset(); - IBOI = SBSYMS[IDI]; + FX_DWORD nTmp = pStream->getOffset(); + CJBig2_Image* IBOI = SBSYMS[IDI]; if (!IBOI) return nullptr; - WOI = IBOI->m_nWidth; - HOI = IBOI->m_nHeight; + FX_DWORD WOI = IBOI->m_nWidth; + FX_DWORD HOI = IBOI->m_nHeight; if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) return nullptr; @@ -155,8 +150,8 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, if (!IBI) { continue; } - WI = IBI->m_nWidth; - HI = IBI->m_nHeight; + FX_DWORD WI = IBI->m_nWidth; + FX_DWORD HI = IBI->m_nHeight; if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) || (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { CURS = CURS + WI - 1; @@ -164,7 +159,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { CURS = CURS + HI - 1; } - SI = CURS; + int32_t SI = CURS; if (TRANSPOSED == 0) { switch (REFCORNER) { case JBIG2_CORNER_TOPLEFT: @@ -277,7 +272,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, int32_t FIRSTS = 0; FX_DWORD NINSTANCES = 0; while (NINSTANCES < SBNUMINSTANCES) { - int32_t CURS; + int32_t CURS = 0; int32_t DT; pIADT->decode(pArithDecoder, &DT); DT *= SBSTRIPS; |