| OLD | NEW | 
|    1 // Copyright 2015 PDFium Authors. All rights reserved. |    1 // Copyright 2015 PDFium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |    5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 
|    6  |    6  | 
|    7 #include "core/fxcodec/jbig2/JBig2_GrrdProc.h" |    7 #include "core/fxcodec/jbig2/JBig2_GrrdProc.h" | 
|    8  |    8  | 
|    9 #include <memory> |    9 #include <memory> | 
|   10  |   10  | 
|   11 #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" |   11 #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" | 
|   12 #include "core/fxcodec/jbig2/JBig2_BitStream.h" |   12 #include "core/fxcodec/jbig2/JBig2_BitStream.h" | 
|   13 #include "core/fxcodec/jbig2/JBig2_Image.h" |   13 #include "core/fxcodec/jbig2/JBig2_Image.h" | 
|   14  |   14  | 
|   15 CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, |   15 CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, | 
|   16                                       JBig2ArithCtx* grContext) { |   16                                       JBig2ArithCtx* grContext) { | 
|   17   if (GRW == 0 || GRH == 0) |   17   if (GRW == 0 || GRH == 0) | 
|   18     return new CJBig2_Image(GRW, GRH); |   18     return new CJBig2_Image(GRW, GRH); | 
|   19  |   19  | 
|   20   if (GRTEMPLATE == 0) { |   20   if (GRTEMPLATE == 0) { | 
|   21     if ((GRAT[0] == -1) && (GRAT[1] == -1) && (GRAT[2] == -1) && |   21     if ((GRAT[0] == -1) && (GRAT[1] == -1) && (GRAT[2] == -1) && | 
|   22         (GRAT[3] == -1) && (GRREFERENCEDX == 0) && |   22         (GRAT[3] == -1) && (GRREFERENCEDX == 0) && | 
|   23         (GRW == (uint32_t)GRREFERENCE->m_nWidth)) { |   23         (GRW == (uint32_t)GRREFERENCE->width())) { | 
|   24       return decode_Template0_opt(pArithDecoder, grContext); |   24       return decode_Template0_opt(pArithDecoder, grContext); | 
|   25     } |   25     } | 
|   26     return decode_Template0_unopt(pArithDecoder, grContext); |   26     return decode_Template0_unopt(pArithDecoder, grContext); | 
|   27   } |   27   } | 
|   28  |   28  | 
|   29   if ((GRREFERENCEDX == 0) && (GRW == (uint32_t)GRREFERENCE->m_nWidth)) |   29   if ((GRREFERENCEDX == 0) && (GRW == (uint32_t)GRREFERENCE->width())) | 
|   30     return decode_Template1_opt(pArithDecoder, grContext); |   30     return decode_Template1_opt(pArithDecoder, grContext); | 
|   31   return decode_Template1_unopt(pArithDecoder, grContext); |   31   return decode_Template1_unopt(pArithDecoder, grContext); | 
|   32 } |   32 } | 
|   33  |   33  | 
|   34 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( |   34 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( | 
|   35     CJBig2_ArithDecoder* pArithDecoder, |   35     CJBig2_ArithDecoder* pArithDecoder, | 
|   36     JBig2ArithCtx* grContext) { |   36     JBig2ArithCtx* grContext) { | 
|   37   FX_BOOL LTP = FALSE; |   37   FX_BOOL LTP = FALSE; | 
|   38   std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); |   38   std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); | 
|   39   GRREG->fill(0); |   39   GRREG->fill(0); | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  155  |  155  | 
|  156   int32_t iGRW = static_cast<int32_t>(GRW); |  156   int32_t iGRW = static_cast<int32_t>(GRW); | 
|  157   int32_t iGRH = static_cast<int32_t>(GRH); |  157   int32_t iGRH = static_cast<int32_t>(GRH); | 
|  158   std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); |  158   std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); | 
|  159   if (!GRREG->m_pData) |  159   if (!GRREG->m_pData) | 
|  160     return nullptr; |  160     return nullptr; | 
|  161  |  161  | 
|  162   FX_BOOL LTP = FALSE; |  162   FX_BOOL LTP = FALSE; | 
|  163   uint8_t* pLine = GRREG->m_pData; |  163   uint8_t* pLine = GRREG->m_pData; | 
|  164   uint8_t* pLineR = GRREFERENCE->m_pData; |  164   uint8_t* pLineR = GRREFERENCE->m_pData; | 
|  165   intptr_t nStride = GRREG->m_nStride; |  165   intptr_t nStride = GRREG->stride(); | 
|  166   intptr_t nStrideR = GRREFERENCE->m_nStride; |  166   intptr_t nStrideR = GRREFERENCE->stride(); | 
|  167   int32_t GRWR = GRREFERENCE->m_nWidth; |  167   int32_t GRWR = GRREFERENCE->width(); | 
|  168   int32_t GRHR = GRREFERENCE->m_nHeight; |  168   int32_t GRHR = GRREFERENCE->height(); | 
|  169   if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) |  169   if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) | 
|  170     GRREFERENCEDY = 0; |  170     GRREFERENCEDY = 0; | 
|  171   intptr_t nOffset = -GRREFERENCEDY * nStrideR; |  171   intptr_t nOffset = -GRREFERENCEDY * nStrideR; | 
|  172   for (int32_t h = 0; h < iGRH; h++) { |  172   for (int32_t h = 0; h < iGRH; h++) { | 
|  173     if (TPGRON) |  173     if (TPGRON) | 
|  174       LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0010]); |  174       LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0010]); | 
|  175     uint32_t line1 = (h > 0) ? pLine[-nStride] << 4 : 0; |  175     uint32_t line1 = (h > 0) ? pLine[-nStride] << 4 : 0; | 
|  176     int32_t reference_h = h - GRREFERENCEDY; |  176     int32_t reference_h = h - GRREFERENCEDY; | 
|  177     FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); |  177     FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); | 
|  178     FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); |  178     FX_BOOL line2_r_ok = (reference_h > -1 && reference_h < GRHR); | 
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  389  |  389  | 
|  390   int32_t iGRW = static_cast<int32_t>(GRW); |  390   int32_t iGRW = static_cast<int32_t>(GRW); | 
|  391   int32_t iGRH = static_cast<int32_t>(GRH); |  391   int32_t iGRH = static_cast<int32_t>(GRH); | 
|  392   std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); |  392   std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH)); | 
|  393   if (!GRREG->m_pData) |  393   if (!GRREG->m_pData) | 
|  394     return nullptr; |  394     return nullptr; | 
|  395  |  395  | 
|  396   FX_BOOL LTP = FALSE; |  396   FX_BOOL LTP = FALSE; | 
|  397   uint8_t* pLine = GRREG->m_pData; |  397   uint8_t* pLine = GRREG->m_pData; | 
|  398   uint8_t* pLineR = GRREFERENCE->m_pData; |  398   uint8_t* pLineR = GRREFERENCE->m_pData; | 
|  399   intptr_t nStride = GRREG->m_nStride; |  399   intptr_t nStride = GRREG->stride(); | 
|  400   intptr_t nStrideR = GRREFERENCE->m_nStride; |  400   intptr_t nStrideR = GRREFERENCE->stride(); | 
|  401   int32_t GRWR = GRREFERENCE->m_nWidth; |  401   int32_t GRWR = GRREFERENCE->width(); | 
|  402   int32_t GRHR = GRREFERENCE->m_nHeight; |  402   int32_t GRHR = GRREFERENCE->height(); | 
|  403   if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { |  403   if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { | 
|  404     GRREFERENCEDY = 0; |  404     GRREFERENCEDY = 0; | 
|  405   } |  405   } | 
|  406   intptr_t nOffset = -GRREFERENCEDY * nStrideR; |  406   intptr_t nOffset = -GRREFERENCEDY * nStrideR; | 
|  407   for (int32_t h = 0; h < iGRH; h++) { |  407   for (int32_t h = 0; h < iGRH; h++) { | 
|  408     if (TPGRON) |  408     if (TPGRON) | 
|  409       LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0008]); |  409       LTP = LTP ^ pArithDecoder->DECODE(&grContext[0x0008]); | 
|  410     uint32_t line1 = (h > 0) ? pLine[-nStride] << 1 : 0; |  410     uint32_t line1 = (h > 0) ? pLine[-nStride] << 1 : 0; | 
|  411     int32_t reference_h = h - GRREFERENCEDY; |  411     int32_t reference_h = h - GRREFERENCEDY; | 
|  412     FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); |  412     FX_BOOL line1_r_ok = (reference_h > 0 && reference_h < GRHR + 1); | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  494         pLine[w >> 3] = cVal; |  494         pLine[w >> 3] = cVal; | 
|  495       } |  495       } | 
|  496     } |  496     } | 
|  497     pLine += nStride; |  497     pLine += nStride; | 
|  498     if (h < GRHR + GRREFERENCEDY) { |  498     if (h < GRHR + GRREFERENCEDY) { | 
|  499       pLineR += nStrideR; |  499       pLineR += nStrideR; | 
|  500     } |  500     } | 
|  501   } |  501   } | 
|  502   return GRREG.release(); |  502   return GRREG.release(); | 
|  503 } |  503 } | 
| OLD | NEW |