| 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 <list> | 7 #include <list> |
| 8 #include "JBig2_Context.h" | 8 #include "JBig2_Context.h" |
| 9 | 9 |
| 10 // Implement a very small least recently used (LRU) cache. It is very | 10 // Implement a very small least recently used (LRU) cache. It is very |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 m_nState = JBIG2_OUT_OF_PAGE; | 49 m_nState = JBIG2_OUT_OF_PAGE; |
| 50 m_pPage = NULL; | 50 m_pPage = NULL; |
| 51 m_bBufSpecified = FALSE; | 51 m_bBufSpecified = FALSE; |
| 52 m_pPause = pPause; | 52 m_pPause = pPause; |
| 53 m_nSegmentDecoded = 0; | 53 m_nSegmentDecoded = 0; |
| 54 m_PauseStep = 10; | 54 m_PauseStep = 10; |
| 55 m_pArithDecoder = NULL; | 55 m_pArithDecoder = NULL; |
| 56 m_pGRD = NULL; | 56 m_pGRD = NULL; |
| 57 m_gbContext = NULL; | 57 m_gbContext = NULL; |
| 58 m_dwOffset = 0; | 58 m_dwOffset = 0; |
| 59 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; | 59 m_ProcessingStatus = FXCODEC_STATUS_FRAME_READY; |
| 60 m_pSymbolDictCache = pSymbolDictCache; | 60 m_pSymbolDictCache = pSymbolDictCache; |
| 61 } | 61 } |
| 62 CJBig2_Context::~CJBig2_Context() { | 62 CJBig2_Context::~CJBig2_Context() { |
| 63 delete m_pArithDecoder; | 63 delete m_pArithDecoder; |
| 64 m_pArithDecoder = NULL; | 64 m_pArithDecoder = NULL; |
| 65 delete m_pGRD; | 65 delete m_pGRD; |
| 66 m_pGRD = NULL; | 66 m_pGRD = NULL; |
| 67 FX_Free(m_gbContext); | 67 FX_Free(m_gbContext); |
| 68 m_gbContext = NULL; | 68 m_gbContext = NULL; |
| 69 delete m_pGlobalContext; | 69 delete m_pGlobalContext; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (!m_pSegment) { | 119 if (!m_pSegment) { |
| 120 m_pSegment.reset(new CJBig2_Segment); | 120 m_pSegment.reset(new CJBig2_Segment); |
| 121 nRet = parseSegmentHeader(m_pSegment.get()); | 121 nRet = parseSegmentHeader(m_pSegment.get()); |
| 122 if (nRet != JBIG2_SUCCESS) { | 122 if (nRet != JBIG2_SUCCESS) { |
| 123 m_pSegment.reset(); | 123 m_pSegment.reset(); |
| 124 return nRet; | 124 return nRet; |
| 125 } | 125 } |
| 126 m_dwOffset = m_pStream->getOffset(); | 126 m_dwOffset = m_pStream->getOffset(); |
| 127 } | 127 } |
| 128 nRet = parseSegmentData(m_pSegment.get(), pPause); | 128 nRet = parseSegmentData(m_pSegment.get(), pPause); |
| 129 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 129 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 130 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 130 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 131 m_PauseStep = 2; | 131 m_PauseStep = 2; |
| 132 return JBIG2_SUCCESS; | 132 return JBIG2_SUCCESS; |
| 133 } | 133 } |
| 134 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | 134 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { |
| 135 m_pSegment.reset(); | 135 m_pSegment.reset(); |
| 136 return JBIG2_SUCCESS; | 136 return JBIG2_SUCCESS; |
| 137 } | 137 } |
| 138 if (nRet != JBIG2_SUCCESS) { | 138 if (nRet != JBIG2_SUCCESS) { |
| 139 m_pSegment.reset(); | 139 m_pSegment.reset(); |
| 140 return nRet; | 140 return nRet; |
| 141 } | 141 } |
| 142 if (m_pSegment->m_dwData_length != 0xffffffff) { | 142 if (m_pSegment->m_dwData_length != 0xffffffff) { |
| 143 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; | 143 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; |
| 144 m_pStream->setOffset(m_dwOffset); | 144 m_pStream->setOffset(m_dwOffset); |
| 145 } else { | 145 } else { |
| 146 m_pStream->offset(4); | 146 m_pStream->offset(4); |
| 147 } | 147 } |
| 148 m_SegmentList.push_back(m_pSegment.release()); | 148 m_SegmentList.push_back(m_pSegment.release()); |
| 149 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && | 149 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && |
| 150 pPause->NeedToPauseNow()) { | 150 pPause->NeedToPauseNow()) { |
| 151 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 151 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 152 m_PauseStep = 2; | 152 m_PauseStep = 2; |
| 153 return JBIG2_SUCCESS; | 153 return JBIG2_SUCCESS; |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 return JBIG2_SUCCESS; | 156 return JBIG2_SUCCESS; |
| 157 } | 157 } |
| 158 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { | 158 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { |
| 159 return decode_SquentialOrgnazation(pPause); | 159 return decode_SquentialOrgnazation(pPause); |
| 160 } | 160 } |
| 161 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { | 161 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { |
| 162 int32_t nRet; | 162 int32_t nRet; |
| 163 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { | 163 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { |
| 164 nonstd::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); | 164 nonstd::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); |
| 165 nRet = parseSegmentHeader(pSegment.get()); | 165 nRet = parseSegmentHeader(pSegment.get()); |
| 166 if (nRet != JBIG2_SUCCESS) { | 166 if (nRet != JBIG2_SUCCESS) { |
| 167 return nRet; | 167 return nRet; |
| 168 } else if (pSegment->m_cFlags.s.type == 51) { | 168 } else if (pSegment->m_cFlags.s.type == 51) { |
| 169 break; | 169 break; |
| 170 } | 170 } |
| 171 m_SegmentList.push_back(pSegment.release()); | 171 m_SegmentList.push_back(pSegment.release()); |
| 172 if (pPause && m_pPause && pPause->NeedToPauseNow()) { | 172 if (pPause && m_pPause && pPause->NeedToPauseNow()) { |
| 173 m_PauseStep = 3; | 173 m_PauseStep = 3; |
| 174 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 174 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 175 return JBIG2_SUCCESS; | 175 return JBIG2_SUCCESS; |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 m_nSegmentDecoded = 0; | 178 m_nSegmentDecoded = 0; |
| 179 return decode_RandomOrgnazation(pPause); | 179 return decode_RandomOrgnazation(pPause); |
| 180 } | 180 } |
| 181 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { | 181 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { |
| 182 for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) { | 182 for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) { |
| 183 int32_t nRet = | 183 int32_t nRet = |
| 184 parseSegmentData(m_SegmentList.get(m_nSegmentDecoded), pPause); | 184 parseSegmentData(m_SegmentList.get(m_nSegmentDecoded), pPause); |
| 185 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) | 185 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) |
| 186 return JBIG2_SUCCESS; | 186 return JBIG2_SUCCESS; |
| 187 | 187 |
| 188 if (nRet != JBIG2_SUCCESS) | 188 if (nRet != JBIG2_SUCCESS) |
| 189 return nRet; | 189 return nRet; |
| 190 | 190 |
| 191 if (m_pPage && pPause && pPause->NeedToPauseNow()) { | 191 if (m_pPage && pPause && pPause->NeedToPauseNow()) { |
| 192 m_PauseStep = 4; | 192 m_PauseStep = 4; |
| 193 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 193 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 194 return JBIG2_SUCCESS; | 194 return JBIG2_SUCCESS; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 return JBIG2_SUCCESS; | 197 return JBIG2_SUCCESS; |
| 198 } | 198 } |
| 199 int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, | 199 int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, |
| 200 int32_t width, | 200 int32_t width, |
| 201 int32_t height, | 201 int32_t height, |
| 202 int32_t stride, | 202 int32_t stride, |
| 203 IFX_Pause* pPause) { | 203 IFX_Pause* pPause) { |
| 204 int32_t nRet = 0; | 204 int32_t nRet = 0; |
| 205 if (m_pGlobalContext) { | 205 if (m_pGlobalContext) { |
| 206 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 206 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
| 207 if (nRet != JBIG2_SUCCESS) { | 207 if (nRet != JBIG2_SUCCESS) { |
| 208 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 208 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 209 return nRet; | 209 return nRet; |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 m_bFirstPage = TRUE; | 212 m_bFirstPage = TRUE; |
| 213 m_PauseStep = 0; | 213 m_PauseStep = 0; |
| 214 delete m_pPage; | 214 delete m_pPage; |
| 215 m_pPage = new CJBig2_Image(width, height, stride, pBuf); | 215 m_pPage = new CJBig2_Image(width, height, stride, pBuf); |
| 216 m_bBufSpecified = TRUE; | 216 m_bBufSpecified = TRUE; |
| 217 if (m_pPage && pPause && pPause->NeedToPauseNow()) { | 217 if (m_pPage && pPause && pPause->NeedToPauseNow()) { |
| 218 m_PauseStep = 1; | 218 m_PauseStep = 1; |
| 219 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 219 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 220 return nRet; | 220 return nRet; |
| 221 } | 221 } |
| 222 int ret = Continue(pPause); | 222 int ret = Continue(pPause); |
| 223 return ret; | 223 return ret; |
| 224 } | 224 } |
| 225 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { | 225 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { |
| 226 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_READY; | 226 m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; |
| 227 int32_t nRet; | 227 int32_t nRet; |
| 228 if (m_PauseStep <= 1) { | 228 if (m_PauseStep <= 1) { |
| 229 switch (m_nStreamType) { | 229 switch (m_nStreamType) { |
| 230 case JBIG2_FILE_STREAM: | 230 case JBIG2_FILE_STREAM: |
| 231 nRet = decodeFile(pPause); | 231 nRet = decodeFile(pPause); |
| 232 break; | 232 break; |
| 233 case JBIG2_SQUENTIAL_STREAM: | 233 case JBIG2_SQUENTIAL_STREAM: |
| 234 nRet = decode_SquentialOrgnazation(pPause); | 234 nRet = decode_SquentialOrgnazation(pPause); |
| 235 break; | 235 break; |
| 236 case JBIG2_RANDOM_STREAM: | 236 case JBIG2_RANDOM_STREAM: |
| 237 if (m_bFirstPage) { | 237 if (m_bFirstPage) { |
| 238 nRet = decode_RandomOrgnazation_FirstPage(pPause); | 238 nRet = decode_RandomOrgnazation_FirstPage(pPause); |
| 239 } else { | 239 } else { |
| 240 nRet = decode_RandomOrgnazation(pPause); | 240 nRet = decode_RandomOrgnazation(pPause); |
| 241 } | 241 } |
| 242 break; | 242 break; |
| 243 case JBIG2_EMBED_STREAM: | 243 case JBIG2_EMBED_STREAM: |
| 244 nRet = decode_EmbedOrgnazation(pPause); | 244 nRet = decode_EmbedOrgnazation(pPause); |
| 245 break; | 245 break; |
| 246 default: | 246 default: |
| 247 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 247 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 248 return JBIG2_ERROR_STREAM_TYPE; | 248 return JBIG2_ERROR_STREAM_TYPE; |
| 249 } | 249 } |
| 250 } else if (m_PauseStep == 2) { | 250 } else if (m_PauseStep == 2) { |
| 251 nRet = decode_SquentialOrgnazation(pPause); | 251 nRet = decode_SquentialOrgnazation(pPause); |
| 252 } else if (m_PauseStep == 3) { | 252 } else if (m_PauseStep == 3) { |
| 253 nRet = decode_RandomOrgnazation_FirstPage(pPause); | 253 nRet = decode_RandomOrgnazation_FirstPage(pPause); |
| 254 } else if (m_PauseStep == 4) { | 254 } else if (m_PauseStep == 4) { |
| 255 nRet = decode_RandomOrgnazation(pPause); | 255 nRet = decode_RandomOrgnazation(pPause); |
| 256 } else if (m_PauseStep == 5) { | 256 } else if (m_PauseStep == 5) { |
| 257 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 257 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 258 return JBIG2_SUCCESS; | 258 return JBIG2_SUCCESS; |
| 259 } | 259 } |
| 260 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 260 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 261 return nRet; | 261 return nRet; |
| 262 } | 262 } |
| 263 m_PauseStep = 5; | 263 m_PauseStep = 5; |
| 264 if (!m_bBufSpecified && nRet == JBIG2_SUCCESS) { | 264 if (!m_bBufSpecified && nRet == JBIG2_SUCCESS) { |
| 265 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 265 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 266 return JBIG2_SUCCESS; | 266 return JBIG2_SUCCESS; |
| 267 } | 267 } |
| 268 if (nRet == JBIG2_SUCCESS) { | 268 if (nRet == JBIG2_SUCCESS) { |
| 269 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 269 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 270 } else { | 270 } else { |
| 271 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 271 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 272 } | 272 } |
| 273 return nRet; | 273 return nRet; |
| 274 } | 274 } |
| 275 int32_t CJBig2_Context::getFirstPage(CJBig2_Image** image, IFX_Pause* pPause) { | 275 int32_t CJBig2_Context::getFirstPage(CJBig2_Image** image, IFX_Pause* pPause) { |
| 276 int32_t nRet; | 276 int32_t nRet; |
| 277 m_bFirstPage = TRUE; | 277 m_bFirstPage = TRUE; |
| 278 m_PauseStep = 0; | 278 m_PauseStep = 0; |
| 279 if (m_pGlobalContext) { | 279 if (m_pGlobalContext) { |
| 280 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 280 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
| 281 if (nRet != JBIG2_SUCCESS) { | 281 if (nRet != JBIG2_SUCCESS) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 if (m_pStream->readInteger(&pSegment->m_dwData_length) != 0) | 390 if (m_pStream->readInteger(&pSegment->m_dwData_length) != 0) |
| 391 return JBIG2_ERROR_TOO_SHORT; | 391 return JBIG2_ERROR_TOO_SHORT; |
| 392 | 392 |
| 393 pSegment->m_pData = m_pStream->getPointer(); | 393 pSegment->m_pData = m_pStream->getPointer(); |
| 394 pSegment->m_State = JBIG2_SEGMENT_DATA_UNPARSED; | 394 pSegment->m_State = JBIG2_SEGMENT_DATA_UNPARSED; |
| 395 return JBIG2_SUCCESS; | 395 return JBIG2_SUCCESS; |
| 396 } | 396 } |
| 397 | 397 |
| 398 int32_t CJBig2_Context::parseSegmentData(CJBig2_Segment* pSegment, | 398 int32_t CJBig2_Context::parseSegmentData(CJBig2_Segment* pSegment, |
| 399 IFX_Pause* pPause) { | 399 IFX_Pause* pPause) { |
| 400 int32_t ret = ProcessiveParseSegmentData(pSegment, pPause); | 400 int32_t ret = ProcessingParseSegmentData(pSegment, pPause); |
| 401 while (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE && | 401 while (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE && |
| 402 m_pStream->getByteLeft() > 0) { | 402 m_pStream->getByteLeft() > 0) { |
| 403 ret = ProcessiveParseSegmentData(pSegment, pPause); | 403 ret = ProcessingParseSegmentData(pSegment, pPause); |
| 404 } | 404 } |
| 405 return ret; | 405 return ret; |
| 406 } | 406 } |
| 407 | 407 |
| 408 int32_t CJBig2_Context::ProcessiveParseSegmentData(CJBig2_Segment* pSegment, | 408 int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, |
| 409 IFX_Pause* pPause) { | 409 IFX_Pause* pPause) { |
| 410 switch (pSegment->m_cFlags.s.type) { | 410 switch (pSegment->m_cFlags.s.type) { |
| 411 case 0: | 411 case 0: |
| 412 return parseSymbolDict(pSegment, pPause); | 412 return parseSymbolDict(pSegment, pPause); |
| 413 case 4: | 413 case 4: |
| 414 case 6: | 414 case 6: |
| 415 case 7: | 415 case 7: |
| 416 if (m_nState == JBIG2_OUT_OF_PAGE) | 416 if (m_nState == JBIG2_OUT_OF_PAGE) |
| 417 return JBIG2_ERROR_FATAL; | 417 return JBIG2_ERROR_FATAL; |
| 418 return parseTextRegion(pSegment); | 418 return parseTextRegion(pSegment); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 pPageInfo->m_bIsStriped = TRUE; | 454 pPageInfo->m_bIsStriped = TRUE; |
| 455 | 455 |
| 456 if (!m_bBufSpecified) { | 456 if (!m_bBufSpecified) { |
| 457 delete m_pPage; | 457 delete m_pPage; |
| 458 FX_DWORD height = | 458 FX_DWORD height = |
| 459 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; | 459 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; |
| 460 m_pPage = new CJBig2_Image(pPageInfo->m_dwWidth, height); | 460 m_pPage = new CJBig2_Image(pPageInfo->m_dwWidth, height); |
| 461 } | 461 } |
| 462 | 462 |
| 463 if (!m_pPage->m_pData) { | 463 if (!m_pPage->m_pData) { |
| 464 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 464 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 465 return JBIG2_ERROR_TOO_SHORT; | 465 return JBIG2_ERROR_TOO_SHORT; |
| 466 } | 466 } |
| 467 | 467 |
| 468 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); | 468 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 469 m_PageInfoList.push_back(pPageInfo.release()); | 469 m_PageInfoList.push_back(pPageInfo.release()); |
| 470 m_nState = JBIG2_IN_PAGE; | 470 m_nState = JBIG2_IN_PAGE; |
| 471 } break; | 471 } break; |
| 472 case 49: | 472 case 49: |
| 473 m_nState = JBIG2_OUT_OF_PAGE; | 473 m_nState = JBIG2_OUT_OF_PAGE; |
| 474 return JBIG2_END_OF_PAGE; | 474 return JBIG2_END_OF_PAGE; |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1297 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
| 1298 if (m_pGRD->MMR == 0) { | 1298 if (m_pGRD->MMR == 0) { |
| 1299 dwTemp = | 1299 dwTemp = |
| 1300 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; | 1300 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; |
| 1301 if (m_gbContext == NULL) { | 1301 if (m_gbContext == NULL) { |
| 1302 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1302 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 1303 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1303 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 1304 } | 1304 } |
| 1305 if (m_pArithDecoder == NULL) { | 1305 if (m_pArithDecoder == NULL) { |
| 1306 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1306 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
| 1307 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( | 1307 m_ProcessingStatus = m_pGRD->Start_decode_Arith( |
| 1308 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); | 1308 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); |
| 1309 } else { | 1309 } else { |
| 1310 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); | 1310 m_ProcessingStatus = m_pGRD->Continue_decode(pPause); |
| 1311 } | 1311 } |
| 1312 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1312 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 1313 if (pSegment->m_cFlags.s.type != 36) { | 1313 if (pSegment->m_cFlags.s.type != 36) { |
| 1314 if (!m_bBufSpecified) { | 1314 if (!m_bBufSpecified) { |
| 1315 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1315 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 1316 if ((pPageInfo->m_bIsStriped == 1) && | 1316 if ((pPageInfo->m_bIsStriped == 1) && |
| 1317 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1317 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
| 1318 m_pPage->expand(m_ri.y + m_ri.height, | 1318 m_pPage->expand(m_ri.y + m_ri.height, |
| 1319 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1319 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1320 } | 1320 } |
| 1321 } | 1321 } |
| 1322 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1322 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
| 1323 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1323 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
| 1324 pSegment->m_Result.im, | 1324 pSegment->m_Result.im, |
| 1325 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1325 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
| 1326 } | 1326 } |
| 1327 return JBIG2_SUCCESS; | 1327 return JBIG2_SUCCESS; |
| 1328 } else { | 1328 } else { |
| 1329 delete m_pArithDecoder; | 1329 delete m_pArithDecoder; |
| 1330 m_pArithDecoder = NULL; | 1330 m_pArithDecoder = NULL; |
| 1331 if (pSegment->m_Result.im == NULL) { | 1331 if (pSegment->m_Result.im == NULL) { |
| 1332 FX_Free(m_gbContext); | 1332 FX_Free(m_gbContext); |
| 1333 nRet = JBIG2_ERROR_FATAL; | 1333 nRet = JBIG2_ERROR_FATAL; |
| 1334 m_gbContext = NULL; | 1334 m_gbContext = NULL; |
| 1335 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 1335 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 1336 goto failed; | 1336 goto failed; |
| 1337 } | 1337 } |
| 1338 FX_Free(m_gbContext); | 1338 FX_Free(m_gbContext); |
| 1339 m_gbContext = NULL; | 1339 m_gbContext = NULL; |
| 1340 m_pStream->alignByte(); | 1340 m_pStream->alignByte(); |
| 1341 m_pStream->offset(2); | 1341 m_pStream->offset(2); |
| 1342 } | 1342 } |
| 1343 } else { | 1343 } else { |
| 1344 FXCODEC_STATUS status = | 1344 FXCODEC_STATUS status = |
| 1345 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause); | 1345 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 SBSYMCODES[CURTEMP].code = CURCODE; | 1626 SBSYMCODES[CURTEMP].code = CURCODE; |
| 1627 CURCODE = CURCODE + 1; | 1627 CURCODE = CURCODE + 1; |
| 1628 } | 1628 } |
| 1629 CURTEMP = CURTEMP + 1; | 1629 CURTEMP = CURTEMP + 1; |
| 1630 } | 1630 } |
| 1631 CURLEN = CURLEN + 1; | 1631 CURLEN = CURLEN + 1; |
| 1632 } | 1632 } |
| 1633 FX_Free(LENCOUNT); | 1633 FX_Free(LENCOUNT); |
| 1634 FX_Free(FIRSTCODE); | 1634 FX_Free(FIRSTCODE); |
| 1635 } | 1635 } |
| OLD | NEW |