| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 if (!m_pSegment) { | 122 if (!m_pSegment) { |
| 123 m_pSegment.reset(new CJBig2_Segment); | 123 m_pSegment.reset(new CJBig2_Segment); |
| 124 nRet = parseSegmentHeader(m_pSegment.get()); | 124 nRet = parseSegmentHeader(m_pSegment.get()); |
| 125 if (nRet != JBIG2_SUCCESS) { | 125 if (nRet != JBIG2_SUCCESS) { |
| 126 m_pSegment.reset(); | 126 m_pSegment.reset(); |
| 127 return nRet; | 127 return nRet; |
| 128 } | 128 } |
| 129 m_dwOffset = m_pStream->getOffset(); | 129 m_dwOffset = m_pStream->getOffset(); |
| 130 } | 130 } |
| 131 nRet = parseSegmentData(m_pSegment.get(), pPause); | 131 nRet = parseSegmentData(m_pSegment.get(), pPause); |
| 132 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 132 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 133 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 133 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 134 m_PauseStep = 2; | 134 m_PauseStep = 2; |
| 135 return JBIG2_SUCCESS; | 135 return JBIG2_SUCCESS; |
| 136 } | 136 } |
| 137 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | 137 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { |
| 138 m_pSegment.reset(); | 138 m_pSegment.reset(); |
| 139 return JBIG2_SUCCESS; | 139 return JBIG2_SUCCESS; |
| 140 } | 140 } |
| 141 if (nRet != JBIG2_SUCCESS) { | 141 if (nRet != JBIG2_SUCCESS) { |
| 142 m_pSegment.reset(); | 142 m_pSegment.reset(); |
| 143 return nRet; | 143 return nRet; |
| 144 } | 144 } |
| 145 if (m_pSegment->m_dwData_length != 0xffffffff) { | 145 if (m_pSegment->m_dwData_length != 0xffffffff) { |
| 146 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; | 146 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; |
| 147 m_pStream->setOffset(m_dwOffset); | 147 m_pStream->setOffset(m_dwOffset); |
| 148 } else { | 148 } else { |
| 149 m_pStream->offset(4); | 149 m_pStream->offset(4); |
| 150 } | 150 } |
| 151 m_SegmentList.push_back(m_pSegment.release()); | 151 m_SegmentList.push_back(m_pSegment.release()); |
| 152 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && | 152 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && |
| 153 pPause->NeedToPauseNow()) { | 153 pPause->NeedToPauseNow()) { |
| 154 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 154 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 155 m_PauseStep = 2; | 155 m_PauseStep = 2; |
| 156 return JBIG2_SUCCESS; | 156 return JBIG2_SUCCESS; |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 return JBIG2_SUCCESS; | 159 return JBIG2_SUCCESS; |
| 160 } | 160 } |
| 161 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { | 161 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { |
| 162 return decode_SquentialOrgnazation(pPause); | 162 return decode_SquentialOrgnazation(pPause); |
| 163 } | 163 } |
| 164 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { | 164 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { |
| 165 int32_t nRet; | 165 int32_t nRet; |
| 166 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { | 166 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { |
| 167 nonstd::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); | 167 nonstd::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); |
| 168 nRet = parseSegmentHeader(pSegment.get()); | 168 nRet = parseSegmentHeader(pSegment.get()); |
| 169 if (nRet != JBIG2_SUCCESS) { | 169 if (nRet != JBIG2_SUCCESS) { |
| 170 return nRet; | 170 return nRet; |
| 171 } else if (pSegment->m_cFlags.s.type == 51) { | 171 } else if (pSegment->m_cFlags.s.type == 51) { |
| 172 break; | 172 break; |
| 173 } | 173 } |
| 174 m_SegmentList.push_back(pSegment.release()); | 174 m_SegmentList.push_back(pSegment.release()); |
| 175 if (pPause && m_pPause && pPause->NeedToPauseNow()) { | 175 if (pPause && m_pPause && pPause->NeedToPauseNow()) { |
| 176 m_PauseStep = 3; | 176 m_PauseStep = 3; |
| 177 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 177 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 178 return JBIG2_SUCCESS; | 178 return JBIG2_SUCCESS; |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 m_nSegmentDecoded = 0; | 181 m_nSegmentDecoded = 0; |
| 182 return decode_RandomOrgnazation(pPause); | 182 return decode_RandomOrgnazation(pPause); |
| 183 } | 183 } |
| 184 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { | 184 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { |
| 185 for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) { | 185 for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) { |
| 186 int32_t nRet = | 186 int32_t nRet = |
| 187 parseSegmentData(m_SegmentList.get(m_nSegmentDecoded), pPause); | 187 parseSegmentData(m_SegmentList.get(m_nSegmentDecoded), pPause); |
| 188 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) | 188 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) |
| 189 return JBIG2_SUCCESS; | 189 return JBIG2_SUCCESS; |
| 190 | 190 |
| 191 if (nRet != JBIG2_SUCCESS) | 191 if (nRet != JBIG2_SUCCESS) |
| 192 return nRet; | 192 return nRet; |
| 193 | 193 |
| 194 if (m_pPage && pPause && pPause->NeedToPauseNow()) { | 194 if (m_pPage && pPause && pPause->NeedToPauseNow()) { |
| 195 m_PauseStep = 4; | 195 m_PauseStep = 4; |
| 196 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 196 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 197 return JBIG2_SUCCESS; | 197 return JBIG2_SUCCESS; |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 return JBIG2_SUCCESS; | 200 return JBIG2_SUCCESS; |
| 201 } | 201 } |
| 202 int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, | 202 int32_t CJBig2_Context::getFirstPage(uint8_t* pBuf, |
| 203 int32_t width, | 203 int32_t width, |
| 204 int32_t height, | 204 int32_t height, |
| 205 int32_t stride, | 205 int32_t stride, |
| 206 IFX_Pause* pPause) { | 206 IFX_Pause* pPause) { |
| 207 int32_t nRet = 0; | 207 int32_t nRet = 0; |
| 208 if (m_pGlobalContext) { | 208 if (m_pGlobalContext) { |
| 209 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 209 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
| 210 if (nRet != JBIG2_SUCCESS) { | 210 if (nRet != JBIG2_SUCCESS) { |
| 211 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 211 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 212 return nRet; | 212 return nRet; |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 m_bFirstPage = TRUE; | 215 m_bFirstPage = TRUE; |
| 216 m_PauseStep = 0; | 216 m_PauseStep = 0; |
| 217 delete m_pPage; | 217 delete m_pPage; |
| 218 m_pPage = new CJBig2_Image(width, height, stride, pBuf); | 218 m_pPage = new CJBig2_Image(width, height, stride, pBuf); |
| 219 m_bBufSpecified = TRUE; | 219 m_bBufSpecified = TRUE; |
| 220 if (m_pPage && pPause && pPause->NeedToPauseNow()) { | 220 if (m_pPage && pPause && pPause->NeedToPauseNow()) { |
| 221 m_PauseStep = 1; | 221 m_PauseStep = 1; |
| 222 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 222 m_ProcessingStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 223 return nRet; | 223 return nRet; |
| 224 } | 224 } |
| 225 int ret = Continue(pPause); | 225 int ret = Continue(pPause); |
| 226 return ret; | 226 return ret; |
| 227 } | 227 } |
| 228 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { | 228 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { |
| 229 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_READY; | 229 m_ProcessingStatus = FXCODEC_STATUS_DECODE_READY; |
| 230 int32_t nRet; | 230 int32_t nRet; |
| 231 if (m_PauseStep <= 1) { | 231 if (m_PauseStep <= 1) { |
| 232 switch (m_nStreamType) { | 232 switch (m_nStreamType) { |
| 233 case JBIG2_FILE_STREAM: | 233 case JBIG2_FILE_STREAM: |
| 234 nRet = decodeFile(pPause); | 234 nRet = decodeFile(pPause); |
| 235 break; | 235 break; |
| 236 case JBIG2_SQUENTIAL_STREAM: | 236 case JBIG2_SQUENTIAL_STREAM: |
| 237 nRet = decode_SquentialOrgnazation(pPause); | 237 nRet = decode_SquentialOrgnazation(pPause); |
| 238 break; | 238 break; |
| 239 case JBIG2_RANDOM_STREAM: | 239 case JBIG2_RANDOM_STREAM: |
| 240 if (m_bFirstPage) { | 240 if (m_bFirstPage) { |
| 241 nRet = decode_RandomOrgnazation_FirstPage(pPause); | 241 nRet = decode_RandomOrgnazation_FirstPage(pPause); |
| 242 } else { | 242 } else { |
| 243 nRet = decode_RandomOrgnazation(pPause); | 243 nRet = decode_RandomOrgnazation(pPause); |
| 244 } | 244 } |
| 245 break; | 245 break; |
| 246 case JBIG2_EMBED_STREAM: | 246 case JBIG2_EMBED_STREAM: |
| 247 nRet = decode_EmbedOrgnazation(pPause); | 247 nRet = decode_EmbedOrgnazation(pPause); |
| 248 break; | 248 break; |
| 249 default: | 249 default: |
| 250 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 250 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 251 return JBIG2_ERROR_STREAM_TYPE; | 251 return JBIG2_ERROR_STREAM_TYPE; |
| 252 } | 252 } |
| 253 } else if (m_PauseStep == 2) { | 253 } else if (m_PauseStep == 2) { |
| 254 nRet = decode_SquentialOrgnazation(pPause); | 254 nRet = decode_SquentialOrgnazation(pPause); |
| 255 } else if (m_PauseStep == 3) { | 255 } else if (m_PauseStep == 3) { |
| 256 nRet = decode_RandomOrgnazation_FirstPage(pPause); | 256 nRet = decode_RandomOrgnazation_FirstPage(pPause); |
| 257 } else if (m_PauseStep == 4) { | 257 } else if (m_PauseStep == 4) { |
| 258 nRet = decode_RandomOrgnazation(pPause); | 258 nRet = decode_RandomOrgnazation(pPause); |
| 259 } else if (m_PauseStep == 5) { | 259 } else if (m_PauseStep == 5) { |
| 260 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 260 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 261 return JBIG2_SUCCESS; | 261 return JBIG2_SUCCESS; |
| 262 } | 262 } |
| 263 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 263 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 264 return nRet; | 264 return nRet; |
| 265 } | 265 } |
| 266 m_PauseStep = 5; | 266 m_PauseStep = 5; |
| 267 if (!m_bBufSpecified && nRet == JBIG2_SUCCESS) { | 267 if (!m_bBufSpecified && nRet == JBIG2_SUCCESS) { |
| 268 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 268 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 269 return JBIG2_SUCCESS; | 269 return JBIG2_SUCCESS; |
| 270 } | 270 } |
| 271 if (nRet == JBIG2_SUCCESS) { | 271 if (nRet == JBIG2_SUCCESS) { |
| 272 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 272 m_ProcessingStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 273 } else { | 273 } else { |
| 274 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 274 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 275 } | 275 } |
| 276 return nRet; | 276 return nRet; |
| 277 } | 277 } |
| 278 int32_t CJBig2_Context::getFirstPage(CJBig2_Image** image, IFX_Pause* pPause) { | 278 int32_t CJBig2_Context::getFirstPage(CJBig2_Image** image, IFX_Pause* pPause) { |
| 279 int32_t nRet; | 279 int32_t nRet; |
| 280 m_bFirstPage = TRUE; | 280 m_bFirstPage = TRUE; |
| 281 m_PauseStep = 0; | 281 m_PauseStep = 0; |
| 282 if (m_pGlobalContext) { | 282 if (m_pGlobalContext) { |
| 283 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 283 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
| 284 if (nRet != JBIG2_SUCCESS) { | 284 if (nRet != JBIG2_SUCCESS) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 398 } |
| 399 pSegment->m_pData = m_pStream->getPointer(); | 399 pSegment->m_pData = m_pStream->getPointer(); |
| 400 pSegment->m_State = JBIG2_SEGMENT_DATA_UNPARSED; | 400 pSegment->m_State = JBIG2_SEGMENT_DATA_UNPARSED; |
| 401 return JBIG2_SUCCESS; | 401 return JBIG2_SUCCESS; |
| 402 failed: | 402 failed: |
| 403 return JBIG2_ERROR_TOO_SHORT; | 403 return JBIG2_ERROR_TOO_SHORT; |
| 404 } | 404 } |
| 405 | 405 |
| 406 int32_t CJBig2_Context::parseSegmentData(CJBig2_Segment* pSegment, | 406 int32_t CJBig2_Context::parseSegmentData(CJBig2_Segment* pSegment, |
| 407 IFX_Pause* pPause) { | 407 IFX_Pause* pPause) { |
| 408 int32_t ret = ProcessiveParseSegmentData(pSegment, pPause); | 408 int32_t ret = ProcessingParseSegmentData(pSegment, pPause); |
| 409 while (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE && | 409 while (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE && |
| 410 m_pStream->getByteLeft() > 0) { | 410 m_pStream->getByteLeft() > 0) { |
| 411 ret = ProcessiveParseSegmentData(pSegment, pPause); | 411 ret = ProcessingParseSegmentData(pSegment, pPause); |
| 412 } | 412 } |
| 413 return ret; | 413 return ret; |
| 414 } | 414 } |
| 415 | 415 |
| 416 int32_t CJBig2_Context::ProcessiveParseSegmentData(CJBig2_Segment* pSegment, | 416 int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, |
| 417 IFX_Pause* pPause) { | 417 IFX_Pause* pPause) { |
| 418 switch (pSegment->m_cFlags.s.type) { | 418 switch (pSegment->m_cFlags.s.type) { |
| 419 case 0: | 419 case 0: |
| 420 return parseSymbolDict(pSegment, pPause); | 420 return parseSymbolDict(pSegment, pPause); |
| 421 case 4: | 421 case 4: |
| 422 case 6: | 422 case 6: |
| 423 case 7: | 423 case 7: |
| 424 if (m_nState == JBIG2_OUT_OF_PAGE) | 424 if (m_nState == JBIG2_OUT_OF_PAGE) |
| 425 return JBIG2_ERROR_FATAL; | 425 return JBIG2_ERROR_FATAL; |
| 426 return parseTextRegion(pSegment); | 426 return parseTextRegion(pSegment); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 pPageInfo->m_bIsStriped = TRUE; | 462 pPageInfo->m_bIsStriped = TRUE; |
| 463 | 463 |
| 464 if (!m_bBufSpecified) { | 464 if (!m_bBufSpecified) { |
| 465 delete m_pPage; | 465 delete m_pPage; |
| 466 FX_DWORD height = | 466 FX_DWORD height = |
| 467 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; | 467 bMaxHeight ? pPageInfo->m_wMaxStripeSize : pPageInfo->m_dwHeight; |
| 468 m_pPage = new CJBig2_Image(pPageInfo->m_dwWidth, height); | 468 m_pPage = new CJBig2_Image(pPageInfo->m_dwWidth, height); |
| 469 } | 469 } |
| 470 | 470 |
| 471 if (!m_pPage->m_pData) { | 471 if (!m_pPage->m_pData) { |
| 472 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 472 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 473 return JBIG2_ERROR_TOO_SHORT; | 473 return JBIG2_ERROR_TOO_SHORT; |
| 474 } | 474 } |
| 475 | 475 |
| 476 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); | 476 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 477 m_PageInfoList.push_back(pPageInfo.release()); | 477 m_PageInfoList.push_back(pPageInfo.release()); |
| 478 m_nState = JBIG2_IN_PAGE; | 478 m_nState = JBIG2_IN_PAGE; |
| 479 } break; | 479 } break; |
| 480 case 49: | 480 case 49: |
| 481 m_nState = JBIG2_OUT_OF_PAGE; | 481 m_nState = JBIG2_OUT_OF_PAGE; |
| 482 return JBIG2_END_OF_PAGE; | 482 return JBIG2_END_OF_PAGE; |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1305 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
| 1306 if (m_pGRD->MMR == 0) { | 1306 if (m_pGRD->MMR == 0) { |
| 1307 dwTemp = | 1307 dwTemp = |
| 1308 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; | 1308 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; |
| 1309 if (m_gbContext == NULL) { | 1309 if (m_gbContext == NULL) { |
| 1310 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); | 1310 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 1311 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1311 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 1312 } | 1312 } |
| 1313 if (m_pArithDecoder == NULL) { | 1313 if (m_pArithDecoder == NULL) { |
| 1314 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1314 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
| 1315 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( | 1315 m_ProcessingStatus = m_pGRD->Start_decode_Arith( |
| 1316 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); | 1316 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); |
| 1317 } else { | 1317 } else { |
| 1318 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); | 1318 m_ProcessingStatus = m_pGRD->Continue_decode(pPause); |
| 1319 } | 1319 } |
| 1320 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1320 if (m_ProcessingStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 1321 if (pSegment->m_cFlags.s.type != 36) { | 1321 if (pSegment->m_cFlags.s.type != 36) { |
| 1322 if (!m_bBufSpecified) { | 1322 if (!m_bBufSpecified) { |
| 1323 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1323 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 1324 if ((pPageInfo->m_bIsStriped == 1) && | 1324 if ((pPageInfo->m_bIsStriped == 1) && |
| 1325 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1325 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
| 1326 m_pPage->expand(m_ri.y + m_ri.height, | 1326 m_pPage->expand(m_ri.y + m_ri.height, |
| 1327 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1327 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1328 } | 1328 } |
| 1329 } | 1329 } |
| 1330 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1330 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
| 1331 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1331 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
| 1332 pSegment->m_Result.im, | 1332 pSegment->m_Result.im, |
| 1333 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1333 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
| 1334 } | 1334 } |
| 1335 return JBIG2_SUCCESS; | 1335 return JBIG2_SUCCESS; |
| 1336 } else { | 1336 } else { |
| 1337 delete m_pArithDecoder; | 1337 delete m_pArithDecoder; |
| 1338 m_pArithDecoder = NULL; | 1338 m_pArithDecoder = NULL; |
| 1339 if (pSegment->m_Result.im == NULL) { | 1339 if (pSegment->m_Result.im == NULL) { |
| 1340 FX_Free(m_gbContext); | 1340 FX_Free(m_gbContext); |
| 1341 nRet = JBIG2_ERROR_FATAL; | 1341 nRet = JBIG2_ERROR_FATAL; |
| 1342 m_gbContext = NULL; | 1342 m_gbContext = NULL; |
| 1343 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 1343 m_ProcessingStatus = FXCODEC_STATUS_ERROR; |
| 1344 goto failed; | 1344 goto failed; |
| 1345 } | 1345 } |
| 1346 FX_Free(m_gbContext); | 1346 FX_Free(m_gbContext); |
| 1347 m_gbContext = NULL; | 1347 m_gbContext = NULL; |
| 1348 m_pStream->alignByte(); | 1348 m_pStream->alignByte(); |
| 1349 m_pStream->offset(2); | 1349 m_pStream->offset(2); |
| 1350 } | 1350 } |
| 1351 } else { | 1351 } else { |
| 1352 FXCODEC_STATUS status = | 1352 FXCODEC_STATUS status = |
| 1353 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause); | 1353 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... |
| 1634 SBSYMCODES[CURTEMP].code = CURCODE; | 1634 SBSYMCODES[CURTEMP].code = CURCODE; |
| 1635 CURCODE = CURCODE + 1; | 1635 CURCODE = CURCODE + 1; |
| 1636 } | 1636 } |
| 1637 CURTEMP = CURTEMP + 1; | 1637 CURTEMP = CURTEMP + 1; |
| 1638 } | 1638 } |
| 1639 CURLEN = CURLEN + 1; | 1639 CURLEN = CURLEN + 1; |
| 1640 } | 1640 } |
| 1641 FX_Free(LENCOUNT); | 1641 FX_Free(LENCOUNT); |
| 1642 FX_Free(FIRSTCODE); | 1642 FX_Free(FIRSTCODE); |
| 1643 } | 1643 } |
| OLD | NEW |