diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fxcodec/codec/codec_int.h | 6 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GrdProc.cpp | 759 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GrdProc.h | 2 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_GrrdProc.cpp | 275 | ||||
-rw-r--r-- | core/fxcodec/lgif/fx_gif.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_coords.cpp | 14 | ||||
-rw-r--r-- | core/fxcrt/include/fx_coordinates.h | 121 |
7 files changed, 544 insertions, 637 deletions
diff --git a/core/fxcodec/codec/codec_int.h b/core/fxcodec/codec/codec_int.h index e0d2ff494f..566bbc3c9b 100644 --- a/core/fxcodec/codec/codec_int.h +++ b/core/fxcodec/codec/codec_int.h @@ -22,9 +22,9 @@ class CPDF_ColorSpace; struct DecodeData { public: - DecodeData(unsigned char* src_data, OPJ_SIZE_T src_size) - : src_data(src_data), src_size(src_size), offset(0) {} - unsigned char* src_data; + DecodeData(uint8_t* data, OPJ_SIZE_T size) + : src_data(data), src_size(size), offset(0) {} + uint8_t* src_data; OPJ_SIZE_T src_size; OPJ_SIZE_T offset; }; diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp index 2391fb2b07..9527c1eaf8 100644 --- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp @@ -18,7 +18,7 @@ CJBig2_GRDProc::CJBig2_GRDProc() m_pLine(nullptr), m_pPause(nullptr), m_DecodeType(0), - LTP(0) { + m_LTP(FALSE) { m_ReplaceRect.left = 0; m_ReplaceRect.bottom = 0; m_ReplaceRect.top = 0; @@ -65,43 +65,35 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2; - uint8_t *pLine, *pLine1, *pLine2, cVal; - int32_t nStride, nStride2, k; - int32_t nLineBytes, nBitsLeft, cc; - LTP = 0; std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); if (!GBREG->m_pData) return nullptr; - pLine = GBREG->m_pData; - nStride = GBREG->m_nStride; - nStride2 = nStride << 1; - nLineBytes = ((GBW + 7) >> 3) - 1; - nBitsLeft = GBW - (nLineBytes << 3); + FX_BOOL LTP = FALSE; + uint8_t* pLine = GBREG->m_pData; + int32_t nStride = GBREG->m_nStride; + int32_t nStride2 = nStride << 1; + int32_t nLineBytes = ((GBW + 7) >> 3) - 1; + int32_t nBitsLeft = GBW - (nLineBytes << 3); uint32_t height = GBH & 0x7fffffff; for (uint32_t h = 0; h < height; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]); + if (LTP) { GBREG->copyLine(h, h - 1); } else { if (h > 1) { - pLine1 = pLine - nStride2; - pLine2 = pLine - nStride; - line1 = (*pLine1++) << 6; - line2 = *pLine2++; - CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0)); - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine1 = pLine - nStride2; + uint8_t* pLine2 = pLine - nStride; + uint32_t line1 = (*pLine1++) << 6; + uint32_t line2 = *pLine2++; + uint32_t CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0)); + for (int32_t cc = 0; cc < nLineBytes; cc++) { line1 = (line1 << 8) | ((*pLine1++) << 6); line2 = (line2 << 8) | (*pLine2++); - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | ((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010)); @@ -110,26 +102,26 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( } line1 <<= 8; line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | ((line1 >> (7 - k)) & 0x0800) | ((line2 >> (7 - k)) & 0x0010)); } - pLine[nLineBytes] = cVal; + pLine[nLineBytes] = cVal1; } else { - pLine2 = pLine - nStride; - line2 = (h & 1) ? (*pLine2++) : 0; - CONTEXT = (line2 & 0x07f0); - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine2 = pLine - nStride; + uint32_t line2 = (h & 1) ? (*pLine2++) : 0; + uint32_t CONTEXT = (line2 & 0x07f0); + for (int32_t cc = 0; cc < nLineBytes; cc++) { if (h & 1) { line2 = (line2 << 8) | (*pLine2++); } - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010)); @@ -137,14 +129,14 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( pLine[cc] = cVal; } line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | (((line2 >> (7 - k))) & 0x0010)); } - pLine[nLineBytes] = cVal; + pLine[nLineBytes] = cVal1; } } pLine += nStride; @@ -155,31 +147,27 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2, line3; - LTP = 0; + FX_BOOL LTP = FALSE; std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]); + if (LTP) { GBREG->copyLine(h, h - 1); } else { - line1 = GBREG->getPixel(1, h - 2); + uint32_t line1 = GBREG->getPixel(1, h - 2); line1 |= GBREG->getPixel(0, h - 2) << 1; - line2 = GBREG->getPixel(2, h - 1); + uint32_t line2 = GBREG->getPixel(2, h - 1); line2 |= GBREG->getPixel(1, h - 1) << 1; line2 |= GBREG->getPixel(0, h - 1) << 2; - line3 = 0; + uint32_t line3 = 0; for (uint32_t w = 0; w < GBW; w++) { + FX_BOOL bVal; if (USESKIP && SKIP->getPixel(w, h)) { bVal = 0; } else { - CONTEXT = line3; + uint32_t CONTEXT = line3; CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4; CONTEXT |= line2 << 5; CONTEXT |= GBREG->getPixel(w + GBAT[2], h + GBAT[3]) << 10; @@ -203,42 +191,34 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2; - uint8_t *pLine, *pLine1, *pLine2, cVal; - int32_t nStride, nStride2, k; - int32_t nLineBytes, nBitsLeft, cc; - LTP = 0; std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); if (!GBREG->m_pData) return nullptr; - pLine = GBREG->m_pData; - nStride = GBREG->m_nStride; - nStride2 = nStride << 1; - nLineBytes = ((GBW + 7) >> 3) - 1; - nBitsLeft = GBW - (nLineBytes << 3); + FX_BOOL LTP = FALSE; + uint8_t* pLine = GBREG->m_pData; + int32_t nStride = GBREG->m_nStride; + int32_t nStride2 = nStride << 1; + int32_t nLineBytes = ((GBW + 7) >> 3) - 1; + int32_t nBitsLeft = GBW - (nLineBytes << 3); for (uint32_t h = 0; h < GBH; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]); + if (LTP) { GBREG->copyLine(h, h - 1); } else { if (h > 1) { - pLine1 = pLine - nStride2; - pLine2 = pLine - nStride; - line1 = (*pLine1++) << 4; - line2 = *pLine2++; - CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine1 = pLine - nStride2; + uint8_t* pLine2 = pLine - nStride; + uint32_t line1 = (*pLine1++) << 4; + uint32_t line2 = *pLine2++; + uint32_t CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); + for (int32_t cc = 0; cc < nLineBytes; cc++) { line1 = (line1 << 8) | ((*pLine1++) << 4); line2 = (line2 << 8) | (*pLine2++); - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | ((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008); @@ -247,26 +227,26 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( } line1 <<= 8; line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | ((line1 >> (7 - k)) & 0x0200) | ((line2 >> (8 - k)) & 0x0008); } - pLine[nLineBytes] = cVal; + pLine[nLineBytes] = cVal1; } else { - pLine2 = pLine - nStride; - line2 = (h & 1) ? (*pLine2++) : 0; - CONTEXT = (line2 >> 1) & 0x01f8; - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine2 = pLine - nStride; + uint32_t line2 = (h & 1) ? (*pLine2++) : 0; + uint32_t CONTEXT = (line2 >> 1) & 0x01f8; + for (int32_t cc = 0; cc < nLineBytes; cc++) { if (h & 1) { line2 = (line2 << 8) | (*pLine2++); } - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (k + 1)) & 0x0008); @@ -274,14 +254,14 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( pLine[cc] = cVal; } line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008); } - pLine[nLineBytes] = cVal; + pLine[nLineBytes] = cVal1; } } pLine += nStride; @@ -292,32 +272,28 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2, line3; - LTP = 0; + FX_BOOL LTP = FALSE; std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]); + if (LTP) { GBREG->copyLine(h, h - 1); } else { - line1 = GBREG->getPixel(2, h - 2); + uint32_t line1 = GBREG->getPixel(2, h - 2); line1 |= GBREG->getPixel(1, h - 2) << 1; line1 |= GBREG->getPixel(0, h - 2) << 2; - line2 = GBREG->getPixel(2, h - 1); + uint32_t line2 = GBREG->getPixel(2, h - 1); line2 |= GBREG->getPixel(1, h - 1) << 1; line2 |= GBREG->getPixel(0, h - 1) << 2; - line3 = 0; + uint32_t line3 = 0; for (uint32_t w = 0; w < GBW; w++) { + FX_BOOL bVal; if (USESKIP && SKIP->getPixel(w, h)) { bVal = 0; } else { - CONTEXT = line3; + uint32_t CONTEXT = line3; CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 3; CONTEXT |= line2 << 4; CONTEXT |= line1 << 9; @@ -334,45 +310,38 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( } return GBREG.release(); } + CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2; - uint8_t *pLine, *pLine1, *pLine2, cVal; - int32_t nStride, nStride2, k; - int32_t nLineBytes, nBitsLeft, cc; - LTP = 0; std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); if (!GBREG->m_pData) return nullptr; - pLine = GBREG->m_pData; - nStride = GBREG->m_nStride; - nStride2 = nStride << 1; - nLineBytes = ((GBW + 7) >> 3) - 1; - nBitsLeft = GBW - (nLineBytes << 3); + FX_BOOL LTP = FALSE; + uint8_t* pLine = GBREG->m_pData; + int32_t nStride = GBREG->m_nStride; + int32_t nStride2 = nStride << 1; + int32_t nLineBytes = ((GBW + 7) >> 3) - 1; + int32_t nBitsLeft = GBW - (nLineBytes << 3); for (uint32_t h = 0; h < GBH; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]); + if (LTP) { GBREG->copyLine(h, h - 1); } else { if (h > 1) { - pLine1 = pLine - nStride2; - pLine2 = pLine - nStride; - line1 = (*pLine1++) << 1; - line2 = *pLine2++; - CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine1 = pLine - nStride2; + uint8_t* pLine2 = pLine - nStride; + uint32_t line1 = (*pLine1++) << 1; + uint32_t line2 = *pLine2++; + uint32_t CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); + for (int32_t cc = 0; cc < nLineBytes; cc++) { line1 = (line1 << 8) | ((*pLine1++) << 1); line2 = (line2 << 8) | (*pLine2++); - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | ((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004); @@ -381,26 +350,26 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( } line1 <<= 8; line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | ((line1 >> (7 - k)) & 0x0080) | ((line2 >> (10 - k)) & 0x0004); } - pLine[nLineBytes] = cVal; + pLine[nLineBytes] = cVal1; } else { - pLine2 = pLine - nStride; - line2 = (h & 1) ? (*pLine2++) : 0; - CONTEXT = (line2 >> 3) & 0x007c; - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine2 = pLine - nStride; + uint32_t line2 = (h & 1) ? (*pLine2++) : 0; + uint32_t CONTEXT = (line2 >> 3) & 0x007c; + for (int32_t cc = 0; cc < nLineBytes; cc++) { if (h & 1) { line2 = (line2 << 8) | (*pLine2++); } - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | ((line2 >> (k + 3)) & 0x0004); @@ -408,14 +377,14 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( pLine[cc] = cVal; } line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | (((line2 >> (10 - k))) & 0x0004); } - pLine[nLineBytes] = cVal; + pLine[nLineBytes] = cVal1; } } pLine += nStride; @@ -426,30 +395,26 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2, line3; - LTP = 0; + FX_BOOL LTP = FALSE; std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]); + if (LTP) { GBREG->copyLine(h, h - 1); } else { - line1 = GBREG->getPixel(1, h - 2); + uint32_t line1 = GBREG->getPixel(1, h - 2); line1 |= GBREG->getPixel(0, h - 2) << 1; - line2 = GBREG->getPixel(1, h - 1); + uint32_t line2 = GBREG->getPixel(1, h - 1); line2 |= GBREG->getPixel(0, h - 1) << 1; - line3 = 0; + uint32_t line3 = 0; for (uint32_t w = 0; w < GBW; w++) { + FX_BOOL bVal; if (USESKIP && SKIP->getPixel(w, h)) { bVal = 0; } else { - CONTEXT = line3; + uint32_t CONTEXT = line3; CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 2; CONTEXT |= line2 << 3; CONTEXT |= line1 << 7; @@ -470,38 +435,30 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1; - uint8_t *pLine, *pLine1, cVal; - int32_t nStride, k; - int32_t nLineBytes, nBitsLeft, cc; - LTP = 0; std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); if (!GBREG->m_pData) return nullptr; - pLine = GBREG->m_pData; - nStride = GBREG->m_nStride; - nLineBytes = ((GBW + 7) >> 3) - 1; - nBitsLeft = GBW - (nLineBytes << 3); + FX_BOOL LTP = FALSE; + uint8_t* pLine = GBREG->m_pData; + int32_t nStride = GBREG->m_nStride; + int32_t nLineBytes = ((GBW + 7) >> 3) - 1; + int32_t nBitsLeft = GBW - (nLineBytes << 3); for (uint32_t h = 0; h < GBH; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]); + if (LTP) { GBREG->copyLine(h, h - 1); } else { if (h > 0) { - pLine1 = pLine - nStride; - line1 = *pLine1++; - CONTEXT = (line1 >> 1) & 0x03f0; - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine1 = pLine - nStride; + uint32_t line1 = *pLine1++; + uint32_t CONTEXT = (line1 >> 1) & 0x03f0; + for (int32_t cc = 0; cc < nLineBytes; cc++) { line1 = (line1 << 8) | (*pLine1++); - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (k + 1)) & 0x0010); @@ -509,32 +466,32 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( pLine[cc] = cVal; } line1 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010); } - pLine[nLineBytes] = cVal; + pLine[nLineBytes] = cVal1; } else { - CONTEXT = 0; - for (cc = 0; cc < nLineBytes; cc++) { - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint32_t CONTEXT = 0; + for (int32_t cc = 0; cc < nLineBytes; cc++) { + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; } pLine[cc] = cVal; } - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; } - pLine[nLineBytes] = cVal; + pLine[nLineBytes] = cVal1; } } pLine += nStride; @@ -545,28 +502,24 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2; - LTP = 0; + FX_BOOL LTP = FALSE; std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); - LTP = LTP ^ SLTP; - } + if (TPGDON) + LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]); if (LTP == 1) { GBREG->copyLine(h, h - 1); } else { - line1 = GBREG->getPixel(1, h - 1); + uint32_t line1 = GBREG->getPixel(1, h - 1); line1 |= GBREG->getPixel(0, h - 1) << 1; - line2 = 0; + uint32_t line2 = 0; for (uint32_t w = 0; w < GBW; w++) { + FX_BOOL bVal; if (USESKIP && SKIP->getPixel(w, h)) { bVal = 0; } else { - CONTEXT = line2; + uint32_t CONTEXT = line2; CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4; CONTEXT |= line1 << 5; bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); @@ -606,7 +559,7 @@ FXCODEC_STATUS CJBig2_GRDProc::Start_decode_Arith( (*m_pImage)->fill(0); m_pArithDecoder = pArithDecoder; m_gbContext = gbContext; - LTP = 0; + m_LTP = FALSE; m_pLine = nullptr; m_loopIndex = 0; return decode_Arith(pPause); @@ -697,40 +650,32 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - FX_BOOL SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2; - uint8_t *pLine1, *pLine2, cVal; - int32_t nStride, nStride2, k; - int32_t nLineBytes, nBitsLeft, cc; if (!m_pLine) { m_pLine = pImage->m_pData; } - nStride = pImage->m_nStride; - nStride2 = nStride << 1; - nLineBytes = ((GBW + 7) >> 3) - 1; - nBitsLeft = GBW - (nLineBytes << 3); + int32_t nStride = pImage->m_nStride; + int32_t nStride2 = nStride << 1; + int32_t nLineBytes = ((GBW + 7) >> 3) - 1; + int32_t nBitsLeft = GBW - (nLineBytes << 3); uint32_t height = GBH & 0x7fffffff; for (; m_loopIndex < height; m_loopIndex++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]); + if (m_LTP) { pImage->copyLine(m_loopIndex, m_loopIndex - 1); } else { if (m_loopIndex > 1) { - pLine1 = m_pLine - nStride2; - pLine2 = m_pLine - nStride; - line1 = (*pLine1++) << 6; - line2 = *pLine2++; - CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0)); - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine1 = m_pLine - nStride2; + uint8_t* pLine2 = m_pLine - nStride; + uint32_t line1 = (*pLine1++) << 6; + uint32_t line2 = *pLine2++; + uint32_t CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0)); + for (int32_t cc = 0; cc < nLineBytes; cc++) { line1 = (line1 << 8) | ((*pLine1++) << 6); line2 = (line2 << 8) | (*pLine2++); - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | ((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010)); @@ -739,26 +684,26 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3( } line1 <<= 8; line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | ((line1 >> (7 - k)) & 0x0800) | ((line2 >> (7 - k)) & 0x0010)); } - m_pLine[nLineBytes] = cVal; + m_pLine[nLineBytes] = cVal1; } else { - pLine2 = m_pLine - nStride; - line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; - CONTEXT = (line2 & 0x07f0); - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine2 = m_pLine - nStride; + uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; + uint32_t CONTEXT = (line2 & 0x07f0); + for (int32_t cc = 0; cc < nLineBytes; cc++) { if (m_loopIndex & 1) { line2 = (line2 << 8) | (*pLine2++); } - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010)); @@ -766,14 +711,14 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3( m_pLine[cc] = cVal; } line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> (7 - k)) & 0x0010)); } - m_pLine[nLineBytes] = cVal; + m_pLine[nLineBytes] = cVal1; } } m_pLine += nStride; @@ -792,28 +737,24 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - FX_BOOL SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2, line3; for (; m_loopIndex < GBH; m_loopIndex++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]); + if (m_LTP) { pImage->copyLine(m_loopIndex, m_loopIndex - 1); } else { - line1 = pImage->getPixel(1, m_loopIndex - 2); + uint32_t line1 = pImage->getPixel(1, m_loopIndex - 2); line1 |= pImage->getPixel(0, m_loopIndex - 2) << 1; - line2 = pImage->getPixel(2, m_loopIndex - 1); + uint32_t line2 = pImage->getPixel(2, m_loopIndex - 1); line2 |= pImage->getPixel(1, m_loopIndex - 1) << 1; line2 |= pImage->getPixel(0, m_loopIndex - 1) << 2; - line3 = 0; + uint32_t line3 = 0; for (uint32_t w = 0; w < GBW; w++) { + FX_BOOL bVal; if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { bVal = 0; } else { - CONTEXT = line3; + uint32_t CONTEXT = line3; CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4; CONTEXT |= line2 << 5; CONTEXT |= pImage->getPixel(w + GBAT[2], m_loopIndex + GBAT[3]) << 10; @@ -847,39 +788,31 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - FX_BOOL SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2; - uint8_t *pLine1, *pLine2, cVal; - int32_t nStride, nStride2, k; - int32_t nLineBytes, nBitsLeft, cc; if (!m_pLine) { m_pLine = pImage->m_pData; } - nStride = pImage->m_nStride; - nStride2 = nStride << 1; - nLineBytes = ((GBW + 7) >> 3) - 1; - nBitsLeft = GBW - (nLineBytes << 3); + int32_t nStride = pImage->m_nStride; + int32_t nStride2 = nStride << 1; + int32_t nLineBytes = ((GBW + 7) >> 3) - 1; + int32_t nBitsLeft = GBW - (nLineBytes << 3); for (; m_loopIndex < GBH; m_loopIndex++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]); + if (m_LTP) { pImage->copyLine(m_loopIndex, m_loopIndex - 1); } else { if (m_loopIndex > 1) { - pLine1 = m_pLine - nStride2; - pLine2 = m_pLine - nStride; - line1 = (*pLine1++) << 4; - line2 = *pLine2++; - CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine1 = m_pLine - nStride2; + uint8_t* pLine2 = m_pLine - nStride; + uint32_t line1 = (*pLine1++) << 4; + uint32_t line2 = *pLine2++; + uint32_t CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); + for (int32_t cc = 0; cc < nLineBytes; cc++) { line1 = (line1 << 8) | ((*pLine1++) << 4); line2 = (line2 << 8) | (*pLine2++); - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | ((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008); @@ -888,26 +821,26 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3( } line1 <<= 8; line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | ((line1 >> (7 - k)) & 0x0200) | ((line2 >> (8 - k)) & 0x0008); } - m_pLine[nLineBytes] = cVal; + m_pLine[nLineBytes] = cVal1; } else { - pLine2 = m_pLine - nStride; - line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; - CONTEXT = (line2 >> 1) & 0x01f8; - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine2 = m_pLine - nStride; + uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; + uint32_t CONTEXT = (line2 >> 1) & 0x01f8; + for (int32_t cc = 0; cc < nLineBytes; cc++) { if (m_loopIndex & 1) { line2 = (line2 << 8) | (*pLine2++); } - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (k + 1)) & 0x0008); @@ -915,14 +848,14 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3( m_pLine[cc] = cVal; } line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008); } - m_pLine[nLineBytes] = cVal; + m_pLine[nLineBytes] = cVal1; } } m_pLine += nStride; @@ -941,29 +874,25 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - FX_BOOL SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2, line3; for (uint32_t h = 0; h < GBH; h++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]); + if (m_LTP) { pImage->copyLine(h, h - 1); } else { - line1 = pImage->getPixel(2, h - 2); + uint32_t line1 = pImage->getPixel(2, h - 2); line1 |= pImage->getPixel(1, h - 2) << 1; line1 |= pImage->getPixel(0, h - 2) << 2; - line2 = pImage->getPixel(2, h - 1); + uint32_t line2 = pImage->getPixel(2, h - 1); line2 |= pImage->getPixel(1, h - 1) << 1; line2 |= pImage->getPixel(0, h - 1) << 2; - line3 = 0; + uint32_t line3 = 0; for (uint32_t w = 0; w < GBW; w++) { + FX_BOOL bVal; if (USESKIP && SKIP->getPixel(w, h)) { bVal = 0; } else { - CONTEXT = line3; + uint32_t CONTEXT = line3; CONTEXT |= pImage->getPixel(w + GBAT[0], h + GBAT[1]) << 3; CONTEXT |= line2 << 4; CONTEXT |= line1 << 9; @@ -992,39 +921,31 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - FX_BOOL SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2; - uint8_t *pLine1, *pLine2, cVal; - int32_t nStride, nStride2, k; - int32_t nLineBytes, nBitsLeft, cc; if (!m_pLine) { m_pLine = pImage->m_pData; } - nStride = pImage->m_nStride; - nStride2 = nStride << 1; - nLineBytes = ((GBW + 7) >> 3) - 1; - nBitsLeft = GBW - (nLineBytes << 3); + int32_t nStride = pImage->m_nStride; + int32_t nStride2 = nStride << 1; + int32_t nLineBytes = ((GBW + 7) >> 3) - 1; + int32_t nBitsLeft = GBW - (nLineBytes << 3); for (; m_loopIndex < GBH; m_loopIndex++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]); + if (m_LTP) { pImage->copyLine(m_loopIndex, m_loopIndex - 1); } else { if (m_loopIndex > 1) { - pLine1 = m_pLine - nStride2; - pLine2 = m_pLine - nStride; - line1 = (*pLine1++) << 1; - line2 = *pLine2++; - CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine1 = m_pLine - nStride2; + uint8_t* pLine2 = m_pLine - nStride; + uint32_t line1 = (*pLine1++) << 1; + uint32_t line2 = *pLine2++; + uint32_t CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); + for (int32_t cc = 0; cc < nLineBytes; cc++) { line1 = (line1 << 8) | ((*pLine1++) << 1); line2 = (line2 << 8) | (*pLine2++); - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | ((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004); @@ -1033,26 +954,26 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3( } line1 <<= 8; line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | ((line1 >> (7 - k)) & 0x0080) | ((line2 >> (10 - k)) & 0x0004); } - m_pLine[nLineBytes] = cVal; + m_pLine[nLineBytes] = cVal1; } else { - pLine2 = m_pLine - nStride; - line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; - CONTEXT = (line2 >> 3) & 0x007c; - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine2 = m_pLine - nStride; + uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; + uint32_t CONTEXT = (line2 >> 3) & 0x007c; + for (int32_t cc = 0; cc < nLineBytes; cc++) { if (m_loopIndex & 1) { line2 = (line2 << 8) | (*pLine2++); } - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | ((line2 >> (k + 3)) & 0x0004); @@ -1060,14 +981,14 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3( m_pLine[cc] = cVal; } line2 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | (((line2 >> (10 - k))) & 0x0004); } - m_pLine[nLineBytes] = cVal; + m_pLine[nLineBytes] = cVal1; } } m_pLine += nStride; @@ -1086,27 +1007,23 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - FX_BOOL SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2, line3; for (; m_loopIndex < GBH; m_loopIndex++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]); + if (m_LTP) { pImage->copyLine(m_loopIndex, m_loopIndex - 1); } else { - line1 = pImage->getPixel(1, m_loopIndex - 2); + uint32_t line1 = pImage->getPixel(1, m_loopIndex - 2); line1 |= pImage->getPixel(0, m_loopIndex - 2) << 1; - line2 = pImage->getPixel(1, m_loopIndex - 1); + uint32_t line2 = pImage->getPixel(1, m_loopIndex - 1); line2 |= pImage->getPixel(0, m_loopIndex - 1) << 1; - line3 = 0; + uint32_t line3 = 0; for (uint32_t w = 0; w < GBW; w++) { + FX_BOOL bVal; if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { bVal = 0; } else { - CONTEXT = line3; + uint32_t CONTEXT = line3; CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 2; CONTEXT |= line2 << 3; CONTEXT |= line1 << 7; @@ -1137,35 +1054,27 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - FX_BOOL SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1; - uint8_t *pLine1, cVal; - int32_t nStride, k; - int32_t nLineBytes, nBitsLeft, cc; - if (!m_pLine) { + if (!m_pLine) m_pLine = pImage->m_pData; - } - nStride = pImage->m_nStride; - nLineBytes = ((GBW + 7) >> 3) - 1; - nBitsLeft = GBW - (nLineBytes << 3); + + int32_t nStride = pImage->m_nStride; + int32_t nLineBytes = ((GBW + 7) >> 3) - 1; + int32_t nBitsLeft = GBW - (nLineBytes << 3); for (; m_loopIndex < GBH; m_loopIndex++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]); + if (m_LTP) { pImage->copyLine(m_loopIndex, m_loopIndex - 1); } else { if (m_loopIndex > 0) { - pLine1 = m_pLine - nStride; - line1 = *pLine1++; - CONTEXT = (line1 >> 1) & 0x03f0; - for (cc = 0; cc < nLineBytes; cc++) { + uint8_t* pLine1 = m_pLine - nStride; + uint32_t line1 = *pLine1++; + uint32_t CONTEXT = (line1 >> 1) & 0x03f0; + for (int32_t cc = 0; cc < nLineBytes; cc++) { line1 = (line1 << 8) | (*pLine1++); - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (k + 1)) & 0x0010); @@ -1173,32 +1082,32 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3( m_pLine[cc] = cVal; } line1 <<= 8; - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010); } - m_pLine[nLineBytes] = cVal; + m_pLine[nLineBytes] = cVal1; } else { - CONTEXT = 0; - for (cc = 0; cc < nLineBytes; cc++) { - cVal = 0; - for (k = 7; k >= 0; k--) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + uint32_t CONTEXT = 0; + for (int32_t cc = 0; cc < nLineBytes; cc++) { + uint8_t cVal = 0; + for (int32_t k = 7; k >= 0; k--) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); cVal |= bVal << k; CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; } m_pLine[cc] = cVal; } - cVal = 0; - for (k = 0; k < nBitsLeft; k++) { - bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); - cVal |= bVal << (7 - k); + uint8_t cVal1 = 0; + for (int32_t k = 0; k < nBitsLeft; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); + cVal1 |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; } - m_pLine[nLineBytes] = cVal; + m_pLine[nLineBytes] = cVal1; } } m_pLine += nStride; @@ -1217,25 +1126,21 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - FX_BOOL SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2; for (; m_loopIndex < GBH; m_loopIndex++) { - if (TPGDON) { - SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); - LTP = LTP ^ SLTP; - } - if (LTP == 1) { + if (TPGDON) + m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]); + if (m_LTP) { pImage->copyLine(m_loopIndex, m_loopIndex - 1); } else { - line1 = pImage->getPixel(1, m_loopIndex - 1); + uint32_t line1 = pImage->getPixel(1, m_loopIndex - 1); line1 |= pImage->getPixel(0, m_loopIndex - 1) << 1; - line2 = 0; + uint32_t line2 = 0; for (uint32_t w = 0; w < GBW; w++) { + FX_BOOL bVal; if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { bVal = 0; } else { - CONTEXT = line2; + uint32_t CONTEXT = line2; CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4; CONTEXT |= line1 << 5; bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.h b/core/fxcodec/jbig2/JBig2_GrdProc.h index b24e2f36fa..6026798aad 100644 --- a/core/fxcodec/jbig2/JBig2_GrdProc.h +++ b/core/fxcodec/jbig2/JBig2_GrdProc.h @@ -117,7 +117,7 @@ class CJBig2_GRDProc { CJBig2_ArithDecoder* m_pArithDecoder; JBig2ArithCtx* m_gbContext; uint16_t m_DecodeType; - FX_BOOL LTP; + FX_BOOL m_LTP; FX_RECT m_ReplaceRect; }; diff --git a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp index 17d17d558e..25c9ea2d8a 100644 --- a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp @@ -34,35 +34,33 @@ CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2, line3, line4, line5; - LTP = 0; + FX_BOOL LTP = FALSE; std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); GRREG->fill(0); for (uint32_t h = 0; h < GRH; h++) { - if (TPGRON) { - SLTP = pArithDecoder->DECODE(&grContext[0x0010]); - LTP = LTP ^ SLTP; - } - if (LTP == 0) { - line1 = GRREG->getPixel(1, h - 1); + if (TPGRON) + LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0010]); + if (!LTP) { + uint32_t line1 = GRREG->getPixel(1, h - 1); line1 |= GRREG->getPixel(0, h - 1) << 1; - line2 = 0; - line3 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); + uint32_t line2 = 0; + uint32_t line3 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); line3 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) << 1; - line4 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); + uint32_t line4 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) << 2; - line5 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); + uint32_t line5 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) << 1; line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) << 2; for (uint32_t w = 0; w < GRW; w++) { - CONTEXT = line5; + uint32_t CONTEXT = line5; CONTEXT |= line4 << 3; CONTEXT |= line3 << 6; CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], @@ -71,7 +69,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( CONTEXT |= line2 << 9; CONTEXT |= line1 << 10; CONTEXT |= GRREG->getPixel(w + GRAT[0], h + GRAT[1]) << 12; - bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); + FX_BOOL bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); GRREG->setPixel(w, h, bVal); line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x03; line2 = ((line2 << 1) | bVal) & 0x01; @@ -89,23 +87,26 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( 0x07; } } else { - line1 = GRREG->getPixel(1, h - 1); + uint32_t line1 = GRREG->getPixel(1, h - 1); line1 |= GRREG->getPixel(0, h - 1) << 1; - line2 = 0; - line3 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); + uint32_t line2 = 0; + uint32_t line3 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY - 1); line3 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1) << 1; - line4 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); + uint32_t line4 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) << 2; - line5 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); + uint32_t line5 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) << 1; line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY + 1) << 2; for (uint32_t w = 0; w < GRW; w++) { - bVal = GRREFERENCE->getPixel(w, h); + FX_BOOL bVal = GRREFERENCE->getPixel(w, h); if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w - 1, h - 1)) && (bVal == GRREFERENCE->getPixel(w, h - 1)) && (bVal == GRREFERENCE->getPixel(w + 1, h - 1)) && @@ -114,7 +115,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( (bVal == GRREFERENCE->getPixel(w - 1, h + 1)) && (bVal == GRREFERENCE->getPixel(w, h + 1)) && (bVal == GRREFERENCE->getPixel(w + 1, h + 1)))) { - CONTEXT = line5; + uint32_t CONTEXT = line5; CONTEXT |= line4 << 3; CONTEXT |= line3 << 6; CONTEXT |= GRREFERENCE->getPixel(w - GRREFERENCEDX + GRAT[2], @@ -152,64 +153,56 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( if (!GRREFERENCE->m_pData) return nullptr; - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line1_r, line2_r, line3_r; - uint8_t *pLine, *pLineR, cVal; - intptr_t nStride, nStrideR, nOffset; - int32_t k, nBits; - int32_t GRWR, GRHR; - int32_t GRW, GRH; - GRW = (int32_t)CJBig2_GRRDProc::GRW; - GRH = (int32_t)CJBig2_GRRDProc::GRH; - LTP = 0; - std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); + int32_t iGRW = static_cast<int32_t>(GRW); + int32_t iGRH = static_cast<int32_t>(GRH); + std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); if (!GRREG->m_pData) return nullptr; - pLine = GRREG->m_pData; - pLineR = GRREFERENCE->m_pData; - nStride = GRREG->m_nStride; - nStrideR = GRREFERENCE->m_nStride; - GRWR = (int32_t)GRREFERENCE->m_nWidth; - GRHR = (int32_t)GRREFERENCE->m_nHeight; - if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { + FX_BOOL LTP = FALSE; + uint8_t* pLine = GRREG->m_pData; + uint8_t* pLineR = GRREFERENCE->m_pData; + intptr_t nStride = GRREG->m_nStride; + intptr_t nStrideR = GRREFERENCE->m_nStride; + int32_t GRWR = GRREFERENCE->m_nWidth; + int32_t GRHR = GRREFERENCE->m_nHeight; + if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) GRREFERENCEDY = 0; - } - nOffset = -GRREFERENCEDY * nStrideR; - for (int32_t h = 0; h < GRH; h++) { - if (TPGRON) { - SLTP = pArithDecoder->DECODE(&grContext[0x0010]); - LTP = LTP ^ SLTP; - } - line1 = (h > 0) ? pLine[-nStride] << 4 : 0; + intptr_t nOffset = -GRREFERENCEDY * nStrideR; + for (int32_t h = 0; h < iGRH; h++) { + if (TPGRON) + LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0010]); + uint32_t line1 = (h > 0) ? pLine[-nStride] << 4 : 0; int32_t reference_h = h - GRREFERENCEDY; FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); - line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; - line2_r = line2_r_ok ? pLineR[nOffset] : 0; - line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; - if (LTP == 0) { - CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | - ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); - for (int32_t w = 0; w < GRW; w += 8) { - nBits = GRW - w > 8 ? 8 : GRW - w; - if (h > 0) + uint32_t line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; + uint32_t line2_r = line2_r_ok ? pLineR[nOffset] : 0; + uint32_t line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; + if (!LTP) { + uint32_t CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | + ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); + for (int32_t w = 0; w < iGRW; w += 8) { + int32_t nBits = iGRW - w > 8 ? 8 : iGRW - w; + if (h > 0) { line1 = (line1 << 8) | - (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); + (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); + } if (h > GRHR + GRREFERENCEDY + 1) { line1_r = 0; line2_r = 0; line3_r = 0; } else { - if (line1_r_ok) + if (line1_r_ok) { line1_r = (line1_r << 8) | (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); - if (line2_r_ok) + } + if (line2_r_ok) { line2_r = (line2_r << 8) | (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); + } if (line3_r_ok) { line3_r = (line3_r << 8) | @@ -218,9 +211,9 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( line3_r = 0; } } - cVal = 0; - for (k = 0; k < nBits; k++) { - bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 0; k < nBits; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); cVal |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x0cdb) << 1) | (bVal << 9) | ((line1 >> (7 - k)) & 0x0400) | @@ -231,20 +224,23 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( pLine[w >> 3] = cVal; } } else { - CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | - ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); - for (int32_t w = 0; w < GRW; w += 8) { - nBits = GRW - w > 8 ? 8 : GRW - w; - if (h > 0) + uint32_t CONTEXT = (line1 & 0x1c00) | (line1_r & 0x01c0) | + ((line2_r >> 3) & 0x0038) | ((line3_r >> 6) & 0x0007); + for (int32_t w = 0; w < iGRW; w += 8) { + int32_t nBits = iGRW - w > 8 ? 8 : iGRW - w; + if (h > 0) { line1 = (line1 << 8) | - (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); - if (line1_r_ok) + (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); + } + if (line1_r_ok) { line1_r = (line1_r << 8) | (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); - if (line2_r_ok) + } + if (line2_r_ok) { line2_r = (line2_r << 8) | (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); + } if (line3_r_ok) { line3_r = (line3_r << 8) | @@ -252,9 +248,9 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( } else { line3_r = 0; } - cVal = 0; - for (k = 0; k < nBits; k++) { - bVal = GRREFERENCE->getPixel(w + k, h); + uint8_t cVal = 0; + for (int32_t k = 0; k < nBits; k++) { + FX_BOOL bVal = GRREFERENCE->getPixel(w + k, h); if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && @@ -286,37 +282,35 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line2, line3, line4, line5; - LTP = 0; + FX_BOOL LTP = FALSE; std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); GRREG->fill(0); for (uint32_t h = 0; h < GRH; h++) { - if (TPGRON) { - SLTP = pArithDecoder->DECODE(&grContext[0x0008]); - LTP = LTP ^ SLTP; - } - if (LTP == 0) { - line1 = GRREG->getPixel(1, h - 1); + if (TPGRON) + LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0008]); + if (!LTP) { + uint32_t line1 = GRREG->getPixel(1, h - 1); line1 |= GRREG->getPixel(0, h - 1) << 1; line1 |= GRREG->getPixel(-1, h - 1) << 2; - line2 = 0; - line3 = GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1); - line4 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); + uint32_t line2 = 0; + uint32_t line3 = + GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1); + uint32_t line4 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) << 2; - line5 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); + uint32_t line5 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) << 1; for (uint32_t w = 0; w < GRW; w++) { - CONTEXT = line5; + uint32_t CONTEXT = line5; CONTEXT |= line4 << 2; CONTEXT |= line3 << 5; CONTEXT |= line2 << 6; CONTEXT |= line1 << 7; - bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); + FX_BOOL bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); GRREG->setPixel(w, h, bVal); line1 = ((line1 << 1) | GRREG->getPixel(w + 2, h - 1)) & 0x07; line2 = ((line2 << 1) | bVal) & 0x01; @@ -334,20 +328,23 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( 0x03; } } else { - line1 = GRREG->getPixel(1, h - 1); + uint32_t line1 = GRREG->getPixel(1, h - 1); line1 |= GRREG->getPixel(0, h - 1) << 1; line1 |= GRREG->getPixel(-1, h - 1) << 2; - line2 = 0; - line3 = GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1); - line4 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); + uint32_t line2 = 0; + uint32_t line3 = + GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY - 1); + uint32_t line4 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY); line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY) << 1; line4 |= GRREFERENCE->getPixel(-GRREFERENCEDX - 1, h - GRREFERENCEDY) << 2; - line5 = GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); + uint32_t line5 = + GRREFERENCE->getPixel(-GRREFERENCEDX + 1, h - GRREFERENCEDY + 1); line5 |= GRREFERENCE->getPixel(-GRREFERENCEDX, h - GRREFERENCEDY + 1) << 1; for (uint32_t w = 0; w < GRW; w++) { - bVal = GRREFERENCE->getPixel(w, h); + FX_BOOL bVal = GRREFERENCE->getPixel(w, h); if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w - 1, h - 1)) && (bVal == GRREFERENCE->getPixel(w, h - 1)) && (bVal == GRREFERENCE->getPixel(w + 1, h - 1)) && @@ -356,7 +353,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( (bVal == GRREFERENCE->getPixel(w - 1, h + 1)) && (bVal == GRREFERENCE->getPixel(w, h + 1)) && (bVal == GRREFERENCE->getPixel(w + 1, h + 1)))) { - CONTEXT = line5; + uint32_t CONTEXT = line5; CONTEXT |= line4 << 2; CONTEXT |= line3 << 5; CONTEXT |= line2 << 6; @@ -390,52 +387,42 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( if (!GRREFERENCE->m_pData) return nullptr; - FX_BOOL LTP, SLTP, bVal; - uint32_t CONTEXT; - uint32_t line1, line1_r, line2_r, line3_r; - uint8_t *pLine, *pLineR, cVal; - intptr_t nStride, nStrideR, nOffset; - int32_t k, nBits; - int32_t GRWR, GRHR; - int32_t GRW, GRH; - GRW = (int32_t)CJBig2_GRRDProc::GRW; - GRH = (int32_t)CJBig2_GRRDProc::GRH; - LTP = 0; - std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); + int32_t iGRW = static_cast<int32_t>(GRW); + int32_t iGRH = static_cast<int32_t>(GRH); + std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); if (!GRREG->m_pData) return nullptr; - pLine = GRREG->m_pData; - pLineR = GRREFERENCE->m_pData; - nStride = GRREG->m_nStride; - nStrideR = GRREFERENCE->m_nStride; - GRWR = (int32_t)GRREFERENCE->m_nWidth; - GRHR = (int32_t)GRREFERENCE->m_nHeight; + FX_BOOL LTP = FALSE; + uint8_t* pLine = GRREG->m_pData; + uint8_t* pLineR = GRREFERENCE->m_pData; + intptr_t nStride = GRREG->m_nStride; + intptr_t nStrideR = GRREFERENCE->m_nStride; + int32_t GRWR = GRREFERENCE->m_nWidth; + int32_t GRHR = GRREFERENCE->m_nHeight; if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { GRREFERENCEDY = 0; } - nOffset = -GRREFERENCEDY * nStrideR; - for (int32_t h = 0; h < GRH; h++) { - if (TPGRON) { - SLTP = pArithDecoder->DECODE(&grContext[0x0008]); - LTP = LTP ^ SLTP; - } - line1 = (h > 0) ? pLine[-nStride] << 1 : 0; + intptr_t nOffset = -GRREFERENCEDY * nStrideR; + for (int32_t h = 0; h < iGRH; h++) { + if (TPGRON) + LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0008]); + uint32_t line1 = (h > 0) ? pLine[-nStride] << 1 : 0; int32_t reference_h = h - GRREFERENCEDY; FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); FX_BOOL line3_r_ok = (reference_h > -2 && reference_h < GRHR - 1); - line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; - line2_r = line2_r_ok ? pLineR[nOffset] : 0; - line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; - if (LTP == 0) { - CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | - ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); - for (int32_t w = 0; w < GRW; w += 8) { - nBits = GRW - w > 8 ? 8 : GRW - w; + uint32_t line1_r = line1_r_ok ? pLineR[nOffset - nStrideR] : 0; + uint32_t line2_r = line2_r_ok ? pLineR[nOffset] : 0; + uint32_t line3_r = line3_r_ok ? pLineR[nOffset + nStrideR] : 0; + if (!LTP) { + uint32_t CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | + ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); + for (int32_t w = 0; w < iGRW; w += 8) { + int32_t nBits = iGRW - w > 8 ? 8 : iGRW - w; if (h > 0) line1 = (line1 << 8) | - (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); + (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); if (line1_r_ok) line1_r = (line1_r << 8) | @@ -450,9 +437,9 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( } else { line3_r = 0; } - cVal = 0; - for (k = 0; k < nBits; k++) { - bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); + uint8_t cVal = 0; + for (int32_t k = 0; k < nBits; k++) { + FX_BOOL bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); cVal |= bVal << (7 - k); CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | ((line1 >> (7 - k)) & 0x0080) | @@ -463,13 +450,13 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( pLine[w >> 3] = cVal; } } else { - CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | - ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); - for (int32_t w = 0; w < GRW; w += 8) { - nBits = GRW - w > 8 ? 8 : GRW - w; + uint32_t CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | + ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); + for (int32_t w = 0; w < iGRW; w += 8) { + int32_t nBits = iGRW - w > 8 ? 8 : iGRW - w; if (h > 0) line1 = (line1 << 8) | - (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); + (w + 8 < iGRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); if (line1_r_ok) line1_r = (line1_r << 8) | @@ -484,9 +471,9 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( } else { line3_r = 0; } - cVal = 0; - for (k = 0; k < nBits; k++) { - bVal = GRREFERENCE->getPixel(w + k, h); + uint8_t cVal = 0; + for (int32_t k = 0; k < nBits; k++) { + FX_BOOL bVal = GRREFERENCE->getPixel(w + k, h); if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && diff --git a/core/fxcodec/lgif/fx_gif.cpp b/core/fxcodec/lgif/fx_gif.cpp index e22bbc7774..b9ea090853 100644 --- a/core/fxcodec/lgif/fx_gif.cpp +++ b/core/fxcodec/lgif/fx_gif.cpp @@ -332,13 +332,13 @@ FX_BOOL CGifLZWEncoder::Encode(const uint8_t* src_buf, } FX_BOOL CGifLZWEncoder::LookUpInTable(const uint8_t* buf, uint32_t& offset, - uint8_t& bit_offset) { + uint8_t& out_bit_offset) { for (uint16_t i = table_cur; i < index_num; i++) { if (code_table[i].prefix == code_table[index_num].prefix && code_table[i].suffix == code_table[index_num].suffix) { code_table[index_num].prefix = i; code_table[index_num].suffix = - gif_cut_buf(buf, offset, src_bit_cut, bit_offset, src_bit_num); + gif_cut_buf(buf, offset, src_bit_cut, out_bit_offset, src_bit_num); table_cur = i; return TRUE; } diff --git a/core/fxcrt/fx_basic_coords.cpp b/core/fxcrt/fx_basic_coords.cpp index 4625bfd666..4c5dc55733 100644 --- a/core/fxcrt/fx_basic_coords.cpp +++ b/core/fxcrt/fx_basic_coords.cpp @@ -284,15 +284,15 @@ static void FXCRT_Matrix_Concat(CFX_Matrix& m, FX_FLOAT ff = m1.e * m2.b + m1.f * m2.d + m2.f; m.a = aa, m.b = bb, m.c = cc, m.d = dd, m.e = ee, m.f = ff; } -void CFX_Matrix::Concat(FX_FLOAT a, - FX_FLOAT b, - FX_FLOAT c, - FX_FLOAT d, - FX_FLOAT e, - FX_FLOAT f, +void CFX_Matrix::Concat(FX_FLOAT a_in, + FX_FLOAT b_in, + FX_FLOAT c_in, + FX_FLOAT d_in, + FX_FLOAT e_in, + FX_FLOAT f_in, FX_BOOL bPrepended) { CFX_Matrix m; - m.Set(a, b, c, d, e, f); + m.Set(a_in, b_in, c_in, d_in, e_in, f_in); Concat(m, bPrepended); } void CFX_Matrix::Concat(const CFX_Matrix& m, FX_BOOL bPrepended) { diff --git a/core/fxcrt/include/fx_coordinates.h b/core/fxcrt/include/fx_coordinates.h index ec6b41c869..eff2a7258a 100644 --- a/core/fxcrt/include/fx_coordinates.h +++ b/core/fxcrt/include/fx_coordinates.h @@ -319,33 +319,51 @@ class CFX_RTemplate { typedef CFX_PSTemplate<baseType> FXT_SIZE; typedef CFX_VTemplate<baseType> FXT_VECTOR; typedef CFX_RTemplate<baseType> FXT_RECT; - void Set(baseType left, baseType top, baseType width, baseType height) { - FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, - FXT_RECT::height = height; - } - void Set(baseType left, baseType top, const FXT_SIZE& size) { - FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::Size(size); - } - void Set(const FXT_POINT& p, baseType width, baseType height) { - TopLeft(p), FXT_RECT::width = width, FXT_RECT::height = height; + void Set(baseType dst_left, + baseType dst_top, + baseType dst_width, + baseType dst_height) { + left = dst_left; + top = dst_top; + width = dst_width; + height = dst_height; + } + void Set(baseType dst_left, baseType dst_top, const FXT_SIZE& dst_size) { + left = dst_left; + top = dst_top; + Size(dst_size); + } + void Set(const FXT_POINT& p, baseType dst_width, baseType dst_height) { + TopLeft(p); + width = dst_width; + height = dst_height; } void Set(const FXT_POINT& p1, const FXT_POINT& p2) { - TopLeft(p1), FXT_RECT::width = p2.x - p1.x, FXT_RECT::height = p2.y - p1.y, - FXT_RECT::Normalize(); + TopLeft(p1); + width = p2.x - p1.x; + height = p2.y - p1.y; + Normalize(); } void Set(const FXT_POINT& p, const FXT_VECTOR& v) { - TopLeft(p), FXT_RECT::width = v.x, FXT_RECT::height = v.y, - FXT_RECT::Normalize(); + TopLeft(p); + width = v.x; + height = v.y; + Normalize(); } void Reset() { - FXT_RECT::left = FXT_RECT::top = FXT_RECT::width = FXT_RECT::height = 0; + left = 0; + top = 0; + width = 0; + height = 0; } FXT_RECT& operator+=(const FXT_POINT& p) { - left += p.x, top += p.y; + left += p.x; + top += p.y; return *this; } FXT_RECT& operator-=(const FXT_POINT& p) { - left -= p.x, top -= p.y; + left -= p.x; + top -= p.y; return *this; } baseType right() const { return left + width; } @@ -371,11 +389,14 @@ class CFX_RTemplate { height += y * 2; } void Inflate(const FXT_POINT& p) { Inflate(p.x, p.y); } - void Inflate(baseType left, baseType top, baseType right, baseType bottom) { - FXT_RECT::left -= left; - FXT_RECT::top -= top; - FXT_RECT::width += left + right; - FXT_RECT::height += top + bottom; + void Inflate(baseType off_left, + baseType off_top, + baseType off_right, + baseType off_bottom) { + left -= off_left; + top -= off_top; + width += off_left + off_right; + height += off_top + off_bottom; } void Inflate(const FXT_RECT& rt) { Inflate(rt.left, rt.top, rt.left + rt.width, rt.top + rt.height); @@ -387,11 +408,14 @@ class CFX_RTemplate { height -= y * 2; } void Deflate(const FXT_POINT& p) { Deflate(p.x, p.y); } - void Deflate(baseType left, baseType top, baseType right, baseType bottom) { - FXT_RECT::left += left; - FXT_RECT::top += top; - FXT_RECT::width -= left + right; - FXT_RECT::height -= top + bottom; + void Deflate(baseType off_left, + baseType off_top, + baseType off_right, + baseType off_bottom) { + left += off_left; + top += off_top; + width -= off_left + off_right; + height -= off_top + off_bottom; } void Deflate(const FXT_RECT& rt) { Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); @@ -464,54 +488,45 @@ class CFX_RTemplate { return p; } void Union(baseType x, baseType y) { - baseType r = right(), b = bottom(); - if (left > x) { + baseType r = right(); + baseType b = bottom(); + if (left > x) left = x; - } - if (r < x) { + if (r < x) r = x; - } - if (top > y) { + if (top > y) top = y; - } - if (b < y) { + if (b < y) b = y; - } width = r - left; height = b - top; } void Union(const FXT_POINT& p) { Union(p.x, p.y); } void Union(const FXT_RECT& rt) { - baseType r = right(), b = bottom(); - if (left > rt.left) { + baseType r = right(); + baseType b = bottom(); + if (left > rt.left) left = rt.left; - } - if (r < rt.right()) { + if (r < rt.right()) r = rt.right(); - } - if (top > rt.top) { + if (top > rt.top) top = rt.top; - } - if (b < rt.bottom()) { + if (b < rt.bottom()) b = rt.bottom(); - } width = r - left; height = b - top; } void Intersect(const FXT_RECT& rt) { - baseType r = right(), b = bottom(); - if (left < rt.left) { + baseType r = right(); + baseType b = bottom(); + if (left < rt.left) left = rt.left; - } - if (r > rt.right()) { + if (r > rt.right()) r = rt.right(); - } - if (top < rt.top) { + if (top < rt.top) top = rt.top; - } - if (b > rt.bottom()) { + if (b > rt.bottom()) b = rt.bottom(); - } width = r - left; height = b - top; } |