| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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_Context.h" | 7 #include "core/fxcodec/jbig2/JBig2_Context.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 pSegment->m_Result.im = | 917 pSegment->m_Result.im = |
| 918 pTRD->decode_Huffman(m_pStream.get(), grContext.get()); | 918 pTRD->decode_Huffman(m_pStream.get(), grContext.get()); |
| 919 if (!pSegment->m_Result.im) | 919 if (!pSegment->m_Result.im) |
| 920 return JBIG2_ERROR_FATAL; | 920 return JBIG2_ERROR_FATAL; |
| 921 m_pStream->alignByte(); | 921 m_pStream->alignByte(); |
| 922 } | 922 } |
| 923 if (pSegment->m_cFlags.s.type != 4) { | 923 if (pSegment->m_cFlags.s.type != 4) { |
| 924 if (!m_bBufSpecified) { | 924 if (!m_bBufSpecified) { |
| 925 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 925 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 926 if ((pPageInfo->m_bIsStriped == 1) && | 926 if ((pPageInfo->m_bIsStriped == 1) && |
| 927 (ri.y + ri.height > m_pPage->m_nHeight)) { | 927 (ri.y + ri.height > m_pPage->height())) { |
| 928 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 928 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 929 } | 929 } |
| 930 } | 930 } |
| 931 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 931 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
| 932 (JBig2ComposeOp)(ri.flags & 0x03)); | 932 (JBig2ComposeOp)(ri.flags & 0x03)); |
| 933 delete pSegment->m_Result.im; | 933 delete pSegment->m_Result.im; |
| 934 pSegment->m_Result.im = nullptr; | 934 pSegment->m_Result.im = nullptr; |
| 935 } | 935 } |
| 936 return JBIG2_SUCCESS; | 936 return JBIG2_SUCCESS; |
| 937 } | 937 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[0]); | 1008 findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[0]); |
| 1009 if (!pSeg || (pSeg->m_cFlags.s.type != 16)) | 1009 if (!pSeg || (pSeg->m_cFlags.s.type != 16)) |
| 1010 return JBIG2_ERROR_FATAL; | 1010 return JBIG2_ERROR_FATAL; |
| 1011 | 1011 |
| 1012 CJBig2_PatternDict* pPatternDict = pSeg->m_Result.pd; | 1012 CJBig2_PatternDict* pPatternDict = pSeg->m_Result.pd; |
| 1013 if (!pPatternDict || (pPatternDict->NUMPATS == 0)) | 1013 if (!pPatternDict || (pPatternDict->NUMPATS == 0)) |
| 1014 return JBIG2_ERROR_FATAL; | 1014 return JBIG2_ERROR_FATAL; |
| 1015 | 1015 |
| 1016 pHRD->HNUMPATS = pPatternDict->NUMPATS; | 1016 pHRD->HNUMPATS = pPatternDict->NUMPATS; |
| 1017 pHRD->HPATS = pPatternDict->HDPATS; | 1017 pHRD->HPATS = pPatternDict->HDPATS; |
| 1018 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; | 1018 pHRD->HPW = pPatternDict->HDPATS[0]->width(); |
| 1019 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; | 1019 pHRD->HPH = pPatternDict->HDPATS[0]->height(); |
| 1020 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1020 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
| 1021 if (pHRD->HMMR == 0) { | 1021 if (pHRD->HMMR == 0) { |
| 1022 const size_t size = GetHuffContextSize(pHRD->HTEMPLATE); | 1022 const size_t size = GetHuffContextSize(pHRD->HTEMPLATE); |
| 1023 std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( | 1023 std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext( |
| 1024 FX_Alloc(JBig2ArithCtx, size)); | 1024 FX_Alloc(JBig2ArithCtx, size)); |
| 1025 JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); | 1025 JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); |
| 1026 std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( | 1026 std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
| 1027 new CJBig2_ArithDecoder(m_pStream.get())); | 1027 new CJBig2_ArithDecoder(m_pStream.get())); |
| 1028 pSegment->m_Result.im = | 1028 pSegment->m_Result.im = |
| 1029 pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); | 1029 pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); |
| 1030 if (!pSegment->m_Result.im) | 1030 if (!pSegment->m_Result.im) |
| 1031 return JBIG2_ERROR_FATAL; | 1031 return JBIG2_ERROR_FATAL; |
| 1032 | 1032 |
| 1033 m_pStream->alignByte(); | 1033 m_pStream->alignByte(); |
| 1034 m_pStream->offset(2); | 1034 m_pStream->offset(2); |
| 1035 } else { | 1035 } else { |
| 1036 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream.get(), pPause); | 1036 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream.get(), pPause); |
| 1037 if (!pSegment->m_Result.im) | 1037 if (!pSegment->m_Result.im) |
| 1038 return JBIG2_ERROR_FATAL; | 1038 return JBIG2_ERROR_FATAL; |
| 1039 m_pStream->alignByte(); | 1039 m_pStream->alignByte(); |
| 1040 } | 1040 } |
| 1041 if (pSegment->m_cFlags.s.type != 20) { | 1041 if (pSegment->m_cFlags.s.type != 20) { |
| 1042 if (!m_bBufSpecified) { | 1042 if (!m_bBufSpecified) { |
| 1043 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1043 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 1044 if (pPageInfo->m_bIsStriped == 1 && | 1044 if (pPageInfo->m_bIsStriped == 1 && |
| 1045 ri.y + ri.height > m_pPage->m_nHeight) { | 1045 ri.y + ri.height > m_pPage->height()) { |
| 1046 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1046 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1047 } | 1047 } |
| 1048 } | 1048 } |
| 1049 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1049 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
| 1050 (JBig2ComposeOp)(ri.flags & 0x03)); | 1050 (JBig2ComposeOp)(ri.flags & 0x03)); |
| 1051 delete pSegment->m_Result.im; | 1051 delete pSegment->m_Result.im; |
| 1052 pSegment->m_Result.im = nullptr; | 1052 pSegment->m_Result.im = nullptr; |
| 1053 } | 1053 } |
| 1054 return JBIG2_SUCCESS; | 1054 return JBIG2_SUCCESS; |
| 1055 } | 1055 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 m_pArithDecoder.get(), | 1101 m_pArithDecoder.get(), |
| 1102 &m_gbContext[0], pPause); | 1102 &m_gbContext[0], pPause); |
| 1103 } else { | 1103 } else { |
| 1104 m_ProcessingStatus = m_pGRD->Continue_decode(pPause); | 1104 m_ProcessingStatus = m_pGRD->Continue_decode(pPause); |
| 1105 } | 1105 } |
| 1106 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1106 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 1107 if (pSegment->m_cFlags.s.type != 36) { | 1107 if (pSegment->m_cFlags.s.type != 36) { |
| 1108 if (!m_bBufSpecified) { | 1108 if (!m_bBufSpecified) { |
| 1109 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1109 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 1110 if ((pPageInfo->m_bIsStriped == 1) && | 1110 if ((pPageInfo->m_bIsStriped == 1) && |
| 1111 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1111 (m_ri.y + m_ri.height > m_pPage->height())) { |
| 1112 m_pPage->expand(m_ri.y + m_ri.height, | 1112 m_pPage->expand(m_ri.y + m_ri.height, |
| 1113 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1113 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1114 } | 1114 } |
| 1115 } | 1115 } |
| 1116 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1116 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
| 1117 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1117 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
| 1118 pSegment->m_Result.im, | 1118 pSegment->m_Result.im, |
| 1119 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1119 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
| 1120 } | 1120 } |
| 1121 return JBIG2_SUCCESS; | 1121 return JBIG2_SUCCESS; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1135 if (!pSegment->m_Result.im) { | 1135 if (!pSegment->m_Result.im) { |
| 1136 m_pGRD.reset(); | 1136 m_pGRD.reset(); |
| 1137 return JBIG2_ERROR_FATAL; | 1137 return JBIG2_ERROR_FATAL; |
| 1138 } | 1138 } |
| 1139 m_pStream->alignByte(); | 1139 m_pStream->alignByte(); |
| 1140 } | 1140 } |
| 1141 if (pSegment->m_cFlags.s.type != 36) { | 1141 if (pSegment->m_cFlags.s.type != 36) { |
| 1142 if (!m_bBufSpecified) { | 1142 if (!m_bBufSpecified) { |
| 1143 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1143 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 1144 if ((pPageInfo->m_bIsStriped == 1) && | 1144 if ((pPageInfo->m_bIsStriped == 1) && |
| 1145 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1145 (m_ri.y + m_ri.height > m_pPage->height())) { |
| 1146 m_pPage->expand(m_ri.y + m_ri.height, | 1146 m_pPage->expand(m_ri.y + m_ri.height, |
| 1147 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1147 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1148 } | 1148 } |
| 1149 } | 1149 } |
| 1150 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1150 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
| 1151 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1151 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
| 1152 pSegment->m_Result.im, | 1152 pSegment->m_Result.im, |
| 1153 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1153 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
| 1154 delete pSegment->m_Result.im; | 1154 delete pSegment->m_Result.im; |
| 1155 pSegment->m_Result.im = nullptr; | 1155 pSegment->m_Result.im = nullptr; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get()); | 1208 pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get()); |
| 1209 if (!pSegment->m_Result.im) | 1209 if (!pSegment->m_Result.im) |
| 1210 return JBIG2_ERROR_FATAL; | 1210 return JBIG2_ERROR_FATAL; |
| 1211 | 1211 |
| 1212 m_pStream->alignByte(); | 1212 m_pStream->alignByte(); |
| 1213 m_pStream->offset(2); | 1213 m_pStream->offset(2); |
| 1214 if (pSegment->m_cFlags.s.type != 40) { | 1214 if (pSegment->m_cFlags.s.type != 40) { |
| 1215 if (!m_bBufSpecified) { | 1215 if (!m_bBufSpecified) { |
| 1216 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1216 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 1217 if ((pPageInfo->m_bIsStriped == 1) && | 1217 if ((pPageInfo->m_bIsStriped == 1) && |
| 1218 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1218 (ri.y + ri.height > m_pPage->height())) { |
| 1219 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1219 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1220 } | 1220 } |
| 1221 } | 1221 } |
| 1222 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1222 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
| 1223 (JBig2ComposeOp)(ri.flags & 0x03)); | 1223 (JBig2ComposeOp)(ri.flags & 0x03)); |
| 1224 delete pSegment->m_Result.im; | 1224 delete pSegment->m_Result.im; |
| 1225 pSegment->m_Result.im = nullptr; | 1225 pSegment->m_Result.im = nullptr; |
| 1226 } | 1226 } |
| 1227 return JBIG2_SUCCESS; | 1227 return JBIG2_SUCCESS; |
| 1228 } | 1228 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 SBSYMCODES[CURTEMP].code = CURCODE; | 1387 SBSYMCODES[CURTEMP].code = CURCODE; |
| 1388 CURCODE = CURCODE + 1; | 1388 CURCODE = CURCODE + 1; |
| 1389 } | 1389 } |
| 1390 CURTEMP = CURTEMP + 1; | 1390 CURTEMP = CURTEMP + 1; |
| 1391 } | 1391 } |
| 1392 CURLEN = CURLEN + 1; | 1392 CURLEN = CURLEN + 1; |
| 1393 } | 1393 } |
| 1394 FX_Free(LENCOUNT); | 1394 FX_Free(LENCOUNT); |
| 1395 FX_Free(FIRSTCODE); | 1395 FX_Free(FIRSTCODE); |
| 1396 } | 1396 } |
| OLD | NEW |