Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: core/fxcodec/codec/fx_codec_progress.cpp

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix a bad merge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxcodec/codec/fx_codec_png.cpp ('k') | core/fxcodec/codec/fx_codec_tiff.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/codec/include/ccodec_progressivedecoder.h" 7 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h"
8 8
9 #include "core/fxcodec/include/fx_codec.h" 9 #include "core/fxcodec/include/fx_codec.h"
10 #include "core/fxge/include/fx_dib.h" 10 #include "core/fxge/include/fx_dib.h"
(...skipping 21 matching lines...) Expand all
32 if (dest_len < 0) { 32 if (dest_len < 0) {
33 base = (FX_FLOAT)(src_len); 33 base = (FX_FLOAT)(src_len);
34 } else { 34 } else {
35 base = 0.0f; 35 base = 0.0f;
36 } 36 }
37 m_ItemSize = 37 m_ItemSize =
38 (int)(sizeof(int) * 2 + 38 (int)(sizeof(int) * 2 +
39 sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1)); 39 sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1));
40 m_DestMin = dest_min; 40 m_DestMin = dest_min;
41 m_pWeightTables = FX_Alloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4); 41 m_pWeightTables = FX_Alloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4);
42 if (m_pWeightTables == NULL) {
43 return;
44 }
45 if (FXSYS_fabs((FX_FLOAT)scale) < 1.0f) { 42 if (FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
46 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) { 43 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) {
47 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel); 44 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
48 double src_pos = dest_pixel * scale + scale / 2 + base; 45 double src_pos = dest_pixel * scale + scale / 2 + base;
49 if (bInterpol) { 46 if (bInterpol) {
50 pixel_weights.m_SrcStart = 47 pixel_weights.m_SrcStart =
51 (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2); 48 (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2);
52 pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2); 49 pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2);
53 if (pixel_weights.m_SrcStart < src_min) { 50 if (pixel_weights.m_SrcStart < src_min) {
54 pixel_weights.m_SrcStart = src_min; 51 pixel_weights.m_SrcStart = src_min;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len, 121 void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len,
125 int src_len, 122 int src_len,
126 FX_BOOL bInterpol) { 123 FX_BOOL bInterpol) {
127 if (m_pWeightTables) { 124 if (m_pWeightTables) {
128 FX_Free(m_pWeightTables); 125 FX_Free(m_pWeightTables);
129 } 126 }
130 double scale = (double)dest_len / (double)src_len; 127 double scale = (double)dest_len / (double)src_len;
131 m_ItemSize = sizeof(int) * 4; 128 m_ItemSize = sizeof(int) * 4;
132 int size = dest_len * m_ItemSize + 4; 129 int size = dest_len * m_ItemSize + 4;
133 m_pWeightTables = FX_Alloc(uint8_t, size); 130 m_pWeightTables = FX_Alloc(uint8_t, size);
134 if (m_pWeightTables == NULL) {
135 return;
136 }
137 FXSYS_memset(m_pWeightTables, 0, size); 131 FXSYS_memset(m_pWeightTables, 0, size);
138 if (scale > 1) { 132 if (scale > 1) {
139 int pre_des_col = 0; 133 int pre_des_col = 0;
140 for (int src_col = 0; src_col < src_len; src_col++) { 134 for (int src_col = 0; src_col < src_len; src_col++) {
141 double des_col_f = src_col * scale; 135 double des_col_f = src_col * scale;
142 int des_col = FXSYS_round((FX_FLOAT)des_col_f); 136 int des_col = FXSYS_round((FX_FLOAT)des_col_f);
143 PixelWeight* pWeight = 137 PixelWeight* pWeight =
144 (PixelWeight*)(m_pWeightTables + des_col * m_ItemSize); 138 (PixelWeight*)(m_pWeightTables + des_col * m_ItemSize);
145 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col; 139 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col;
146 pWeight->m_Weights[0] = 65536; 140 pWeight->m_Weights[0] = 65536;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 179 }
186 void CCodec_ProgressiveDecoder::CFXCODEC_VertTable::Calc(int dest_len, 180 void CCodec_ProgressiveDecoder::CFXCODEC_VertTable::Calc(int dest_len,
187 int src_len) { 181 int src_len) {
188 if (m_pWeightTables) { 182 if (m_pWeightTables) {
189 FX_Free(m_pWeightTables); 183 FX_Free(m_pWeightTables);
190 } 184 }
191 double scale = (double)dest_len / (double)src_len; 185 double scale = (double)dest_len / (double)src_len;
192 m_ItemSize = sizeof(int) * 4; 186 m_ItemSize = sizeof(int) * 4;
193 int size = dest_len * m_ItemSize + 4; 187 int size = dest_len * m_ItemSize + 4;
194 m_pWeightTables = FX_Alloc(uint8_t, size); 188 m_pWeightTables = FX_Alloc(uint8_t, size);
195 if (m_pWeightTables == NULL) {
196 return;
197 }
198 FXSYS_memset(m_pWeightTables, 0, size); 189 FXSYS_memset(m_pWeightTables, 0, size);
199 if (scale > 1) { 190 if (scale > 1) {
200 double step = 0.0; 191 double step = 0.0;
201 int src_row = 0; 192 int src_row = 0;
202 while (step < (double)dest_len) { 193 while (step < (double)dest_len) {
203 int start_step = (int)step; 194 int start_step = (int)step;
204 step = scale * (++src_row); 195 step = scale * (++src_row);
205 int end_step = (int)step; 196 int end_step = (int)step;
206 if (end_step >= dest_len) { 197 if (end_step >= dest_len) {
207 end_step = dest_len; 198 end_step = dest_len;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize); 231 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
241 pWeight->m_SrcStart = des_row; 232 pWeight->m_SrcStart = des_row;
242 pWeight->m_SrcEnd = des_row; 233 pWeight->m_SrcEnd = des_row;
243 pWeight->m_Weights[0] = 65536; 234 pWeight->m_Weights[0] = 65536;
244 pWeight->m_Weights[1] = 0; 235 pWeight->m_Weights[1] = 0;
245 } 236 }
246 } 237 }
247 } 238 }
248 CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder( 239 CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder(
249 CCodec_ModuleMgr* pCodecMgr) { 240 CCodec_ModuleMgr* pCodecMgr) {
250 m_pFile = NULL; 241 m_pFile = nullptr;
251 m_pJpegContext = NULL; 242 m_pJpegContext = nullptr;
252 m_pPngContext = NULL; 243 m_pPngContext = nullptr;
253 m_pGifContext = NULL; 244 m_pGifContext = nullptr;
254 m_pBmpContext = NULL; 245 m_pBmpContext = nullptr;
255 m_pTiffContext = NULL; 246 m_pTiffContext = nullptr;
256 m_pCodecMgr = NULL; 247 m_pCodecMgr = nullptr;
257 m_pSrcBuf = NULL; 248 m_pSrcBuf = nullptr;
258 m_pDecodeBuf = NULL; 249 m_pDecodeBuf = nullptr;
259 m_pDeviceBitmap = NULL; 250 m_pDeviceBitmap = nullptr;
260 m_pSrcPalette = NULL; 251 m_pSrcPalette = nullptr;
261 m_pCodecMgr = pCodecMgr; 252 m_pCodecMgr = pCodecMgr;
262 m_offSet = 0; 253 m_offSet = 0;
263 m_SrcSize = 0; 254 m_SrcSize = 0;
264 m_ScanlineSize = 0; 255 m_ScanlineSize = 0;
265 m_SrcWidth = m_SrcHeight = 0; 256 m_SrcWidth = m_SrcHeight = 0;
266 m_SrcComponents = 0; 257 m_SrcComponents = 0;
267 m_SrcBPC = 0; 258 m_SrcBPC = 0;
268 m_SrcPassNumber = 0; 259 m_SrcPassNumber = 0;
269 m_clipBox = FX_RECT(0, 0, 0, 0); 260 m_clipBox = FX_RECT(0, 0, 0, 0);
270 m_imagType = FXCODEC_IMAGE_UNKNOWN; 261 m_imagType = FXCODEC_IMAGE_UNKNOWN;
271 m_status = FXCODEC_STATUS_DECODE_FINISH; 262 m_status = FXCODEC_STATUS_DECODE_FINISH;
272 m_TransMethod = -1; 263 m_TransMethod = -1;
273 m_SrcRow = 0; 264 m_SrcRow = 0;
274 m_SrcFormat = FXCodec_Invalid; 265 m_SrcFormat = FXCodec_Invalid;
275 m_bInterpol = TRUE; 266 m_bInterpol = TRUE;
276 m_FrameNumber = 0; 267 m_FrameNumber = 0;
277 m_FrameCur = 0; 268 m_FrameCur = 0;
278 m_SrcPaletteNumber = 0; 269 m_SrcPaletteNumber = 0;
279 m_GifPltNumber = 0; 270 m_GifPltNumber = 0;
280 m_GifBgIndex = 0; 271 m_GifBgIndex = 0;
281 m_pGifPalette = NULL; 272 m_pGifPalette = nullptr;
282 m_GifTransIndex = -1; 273 m_GifTransIndex = -1;
283 m_GifFrameRect = FX_RECT(0, 0, 0, 0); 274 m_GifFrameRect = FX_RECT(0, 0, 0, 0);
284 m_BmpIsTopBottom = FALSE; 275 m_BmpIsTopBottom = FALSE;
285 } 276 }
286 CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() { 277 CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() {
287 m_pFile = NULL; 278 m_pFile = nullptr;
288 if (m_pJpegContext) { 279 if (m_pJpegContext) {
289 m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext); 280 m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext);
290 } 281 }
291 if (m_pPngContext) { 282 if (m_pPngContext) {
292 m_pCodecMgr->GetPngModule()->Finish(m_pPngContext); 283 m_pCodecMgr->GetPngModule()->Finish(m_pPngContext);
293 } 284 }
294 if (m_pGifContext) { 285 if (m_pGifContext) {
295 m_pCodecMgr->GetGifModule()->Finish(m_pGifContext); 286 m_pCodecMgr->GetGifModule()->Finish(m_pGifContext);
296 } 287 }
297 if (m_pBmpContext) { 288 if (m_pBmpContext) {
298 m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext); 289 m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext);
299 } 290 }
300 if (m_pTiffContext) { 291 if (m_pTiffContext) {
301 m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext); 292 m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext);
302 } 293 }
303 FX_Free(m_pSrcBuf); 294 FX_Free(m_pSrcBuf);
304 FX_Free(m_pDecodeBuf); 295 FX_Free(m_pDecodeBuf);
305 FX_Free(m_pSrcPalette); 296 FX_Free(m_pSrcPalette);
306 } 297 }
307 FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData( 298 FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData(
308 CCodec_JpegModule* pJpegModule, 299 CCodec_JpegModule* pJpegModule,
309 FXCODEC_STATUS& err_status) { 300 FXCODEC_STATUS& err_status) {
310 uint32_t dwSize = (uint32_t)m_pFile->GetSize(); 301 uint32_t dwSize = (uint32_t)m_pFile->GetSize();
311 if (dwSize <= m_offSet) { 302 if (dwSize <= m_offSet) {
312 return FALSE; 303 return FALSE;
313 } 304 }
314 dwSize = dwSize - m_offSet; 305 dwSize = dwSize - m_offSet;
315 uint32_t dwAvail = pJpegModule->GetAvailInput(m_pJpegContext, NULL); 306 uint32_t dwAvail = pJpegModule->GetAvailInput(m_pJpegContext, nullptr);
316 if (dwAvail == m_SrcSize) { 307 if (dwAvail == m_SrcSize) {
317 if (dwSize > FXCODEC_BLOCK_SIZE) { 308 if (dwSize > FXCODEC_BLOCK_SIZE) {
318 dwSize = FXCODEC_BLOCK_SIZE; 309 dwSize = FXCODEC_BLOCK_SIZE;
319 } 310 }
320 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) / 311 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) /
321 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE; 312 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE;
322 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize); 313 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize);
323 if (!m_pSrcBuf) { 314 if (!m_pSrcBuf) {
324 err_status = FXCODEC_STATUS_ERR_MEMORY; 315 err_status = FXCODEC_STATUS_ERR_MEMORY;
325 return FALSE; 316 return FALSE;
(...skipping 16 matching lines...) Expand all
342 return TRUE; 333 return TRUE;
343 } 334 }
344 FX_BOOL CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule, 335 FX_BOOL CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule,
345 int width, 336 int width,
346 int height, 337 int height,
347 int bpc, 338 int bpc,
348 int pass, 339 int pass,
349 int* color_type, 340 int* color_type,
350 double* gamma) { 341 double* gamma) {
351 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 342 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
352 if (pCodec->m_pDeviceBitmap == NULL) { 343 if (!pCodec->m_pDeviceBitmap) {
353 pCodec->m_SrcWidth = width; 344 pCodec->m_SrcWidth = width;
354 pCodec->m_SrcHeight = height; 345 pCodec->m_SrcHeight = height;
355 pCodec->m_SrcBPC = bpc; 346 pCodec->m_SrcBPC = bpc;
356 pCodec->m_SrcPassNumber = pass; 347 pCodec->m_SrcPassNumber = pass;
357 pCodec->m_SrcComponents = 348 pCodec->m_SrcComponents =
358 *color_type == 0 ? 1 : *color_type == 2 349 *color_type == 0 ? 1 : *color_type == 2
359 ? 3 350 ? 3
360 : *color_type == 3 351 : *color_type == 3
361 ? 4 352 ? 4
362 : *color_type == 4 353 : *color_type == 4
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } 554 }
564 } 555 }
565 } 556 }
566 FX_BOOL CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule, 557 FX_BOOL CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
567 FXCODEC_STATUS& err_status) { 558 FXCODEC_STATUS& err_status) {
568 uint32_t dwSize = (uint32_t)m_pFile->GetSize(); 559 uint32_t dwSize = (uint32_t)m_pFile->GetSize();
569 if (dwSize <= m_offSet) { 560 if (dwSize <= m_offSet) {
570 return FALSE; 561 return FALSE;
571 } 562 }
572 dwSize = dwSize - m_offSet; 563 dwSize = dwSize - m_offSet;
573 uint32_t dwAvail = pGifModule->GetAvailInput(m_pGifContext, NULL); 564 uint32_t dwAvail = pGifModule->GetAvailInput(m_pGifContext, nullptr);
574 if (dwAvail == m_SrcSize) { 565 if (dwAvail == m_SrcSize) {
575 if (dwSize > FXCODEC_BLOCK_SIZE) { 566 if (dwSize > FXCODEC_BLOCK_SIZE) {
576 dwSize = FXCODEC_BLOCK_SIZE; 567 dwSize = FXCODEC_BLOCK_SIZE;
577 } 568 }
578 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) / 569 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) /
579 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE; 570 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE;
580 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize); 571 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize);
581 if (!m_pSrcBuf) { 572 if (!m_pSrcBuf) {
582 err_status = FXCODEC_STATUS_ERR_MEMORY; 573 err_status = FXCODEC_STATUS_ERR_MEMORY;
583 return FALSE; 574 return FALSE;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 int32_t trans_index, 615 int32_t trans_index,
625 int32_t disposal_method, 616 int32_t disposal_method,
626 FX_BOOL interlace) { 617 FX_BOOL interlace) {
627 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 618 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
628 pCodec->m_offSet = rcd_pos; 619 pCodec->m_offSet = rcd_pos;
629 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; 620 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR;
630 if (!pCodec->GifReadMoreData(pCodec->m_pCodecMgr->GetGifModule(), 621 if (!pCodec->GifReadMoreData(pCodec->m_pCodecMgr->GetGifModule(),
631 error_status)) { 622 error_status)) {
632 return FALSE; 623 return FALSE;
633 } 624 }
634 uint8_t* pPalette = NULL; 625 uint8_t* pPalette = nullptr;
635 if (pal_num != 0 && pal_ptr) { 626 if (pal_num != 0 && pal_ptr) {
636 pPalette = (uint8_t*)pal_ptr; 627 pPalette = (uint8_t*)pal_ptr;
637 } else { 628 } else {
638 pal_num = pCodec->m_GifPltNumber; 629 pal_num = pCodec->m_GifPltNumber;
639 pPalette = pCodec->m_pGifPalette; 630 pPalette = pCodec->m_pGifPalette;
640 } 631 }
641 if (pCodec->m_pSrcPalette == NULL) { 632 if (!pCodec->m_pSrcPalette) {
642 pCodec->m_pSrcPalette = FX_Alloc(FX_ARGB, pal_num); 633 pCodec->m_pSrcPalette = FX_Alloc(FX_ARGB, pal_num);
643 } else if (pal_num > pCodec->m_SrcPaletteNumber) { 634 } else if (pal_num > pCodec->m_SrcPaletteNumber) {
644 pCodec->m_pSrcPalette = FX_Realloc(FX_ARGB, pCodec->m_pSrcPalette, pal_num); 635 pCodec->m_pSrcPalette = FX_Realloc(FX_ARGB, pCodec->m_pSrcPalette, pal_num);
645 } 636 }
646 if (pCodec->m_pSrcPalette == NULL) { 637 if (!pCodec->m_pSrcPalette)
647 return FALSE; 638 return FALSE;
648 } 639
649 pCodec->m_SrcPaletteNumber = pal_num; 640 pCodec->m_SrcPaletteNumber = pal_num;
650 for (int i = 0; i < pal_num; i++) { 641 for (int i = 0; i < pal_num; i++) {
651 uint32_t j = i * 3; 642 uint32_t j = i * 3;
652 pCodec->m_pSrcPalette[i] = 643 pCodec->m_pSrcPalette[i] =
653 ArgbEncode(0xff, pPalette[j], pPalette[j + 1], pPalette[j + 2]); 644 ArgbEncode(0xff, pPalette[j], pPalette[j + 1], pPalette[j + 2]);
654 } 645 }
655 pCodec->m_GifTransIndex = trans_index; 646 pCodec->m_GifTransIndex = trans_index;
656 pCodec->m_GifFrameRect = img_rc; 647 pCodec->m_GifFrameRect = img_rc;
657 pCodec->m_SrcPassNumber = interlace ? 4 : 1; 648 pCodec->m_SrcPassNumber = interlace ? 4 : 1;
658 int32_t pal_index = pCodec->m_GifBgIndex; 649 int32_t pal_index = pCodec->m_GifBgIndex;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 GifDoubleLineResampleVert(pDeviceBitmap, scale_y, des_row + (int)scale_y); 836 GifDoubleLineResampleVert(pDeviceBitmap, scale_y, des_row + (int)scale_y);
846 } 837 }
847 } 838 }
848 FX_BOOL CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule, 839 FX_BOOL CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule,
849 FXCODEC_STATUS& err_status) { 840 FXCODEC_STATUS& err_status) {
850 uint32_t dwSize = (uint32_t)m_pFile->GetSize(); 841 uint32_t dwSize = (uint32_t)m_pFile->GetSize();
851 if (dwSize <= m_offSet) { 842 if (dwSize <= m_offSet) {
852 return FALSE; 843 return FALSE;
853 } 844 }
854 dwSize = dwSize - m_offSet; 845 dwSize = dwSize - m_offSet;
855 uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext, NULL); 846 uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext, nullptr);
856 if (dwAvail == m_SrcSize) { 847 if (dwAvail == m_SrcSize) {
857 if (dwSize > FXCODEC_BLOCK_SIZE) { 848 if (dwSize > FXCODEC_BLOCK_SIZE) {
858 dwSize = FXCODEC_BLOCK_SIZE; 849 dwSize = FXCODEC_BLOCK_SIZE;
859 } 850 }
860 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) / 851 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) /
861 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE; 852 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE;
862 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize); 853 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize);
863 if (!m_pSrcBuf) { 854 if (!m_pSrcBuf) {
864 err_status = FXCODEC_STATUS_ERR_MEMORY; 855 err_status = FXCODEC_STATUS_ERR_MEMORY;
865 return FALSE; 856 return FALSE;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 if (size > FXCODEC_BLOCK_SIZE) { 1004 if (size > FXCODEC_BLOCK_SIZE) {
1014 size = FXCODEC_BLOCK_SIZE; 1005 size = FXCODEC_BLOCK_SIZE;
1015 } 1006 }
1016 FX_Free(m_pSrcBuf); 1007 FX_Free(m_pSrcBuf);
1017 m_pSrcBuf = FX_Alloc(uint8_t, size); 1008 m_pSrcBuf = FX_Alloc(uint8_t, size);
1018 FXSYS_memset(m_pSrcBuf, 0, size); 1009 FXSYS_memset(m_pSrcBuf, 0, size);
1019 m_SrcSize = size; 1010 m_SrcSize = size;
1020 switch (imageType) { 1011 switch (imageType) {
1021 case FXCODEC_IMAGE_BMP: { 1012 case FXCODEC_IMAGE_BMP: {
1022 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); 1013 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
1023 if (pBmpModule == NULL) { 1014 if (!pBmpModule) {
1024 m_status = FXCODEC_STATUS_ERR_MEMORY; 1015 m_status = FXCODEC_STATUS_ERR_MEMORY;
1025 return FALSE; 1016 return FALSE;
1026 } 1017 }
1027 pBmpModule->InputImagePositionBufCallback = 1018 pBmpModule->InputImagePositionBufCallback =
1028 BmpInputImagePositionBufCallback; 1019 BmpInputImagePositionBufCallback;
1029 pBmpModule->ReadScanlineCallback = BmpReadScanlineCallback; 1020 pBmpModule->ReadScanlineCallback = BmpReadScanlineCallback;
1030 m_pBmpContext = pBmpModule->Start((void*)this); 1021 m_pBmpContext = pBmpModule->Start((void*)this);
1031 if (m_pBmpContext == NULL) { 1022 if (!m_pBmpContext) {
1032 m_status = FXCODEC_STATUS_ERR_MEMORY; 1023 m_status = FXCODEC_STATUS_ERR_MEMORY;
1033 return FALSE; 1024 return FALSE;
1034 } 1025 }
1035 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size); 1026 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size);
1036 if (!bResult) { 1027 if (!bResult) {
1037 m_status = FXCODEC_STATUS_ERR_READ; 1028 m_status = FXCODEC_STATUS_ERR_READ;
1038 return FALSE; 1029 return FALSE;
1039 } 1030 }
1040 m_offSet += size; 1031 m_offSet += size;
1041 pBmpModule->Input(m_pBmpContext, m_pSrcBuf, size); 1032 pBmpModule->Input(m_pBmpContext, m_pSrcBuf, size);
1042 uint32_t* pPalette = NULL; 1033 uint32_t* pPalette = nullptr;
1043 int32_t readResult = pBmpModule->ReadHeader( 1034 int32_t readResult = pBmpModule->ReadHeader(
1044 m_pBmpContext, &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom, 1035 m_pBmpContext, &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom,
1045 &m_SrcComponents, &m_SrcPaletteNumber, &pPalette, pAttribute); 1036 &m_SrcComponents, &m_SrcPaletteNumber, &pPalette, pAttribute);
1046 while (readResult == 2) { 1037 while (readResult == 2) {
1047 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_FORMAT; 1038 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_FORMAT;
1048 if (!BmpReadMoreData(pBmpModule, error_status)) { 1039 if (!BmpReadMoreData(pBmpModule, error_status)) {
1049 m_status = error_status; 1040 m_status = error_status;
1050 return FALSE; 1041 return FALSE;
1051 } 1042 }
1052 readResult = pBmpModule->ReadHeader( 1043 readResult = pBmpModule->ReadHeader(
1053 m_pBmpContext, &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom, 1044 m_pBmpContext, &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom,
1054 &m_SrcComponents, &m_SrcPaletteNumber, &pPalette, pAttribute); 1045 &m_SrcComponents, &m_SrcPaletteNumber, &pPalette, pAttribute);
1055 } 1046 }
1056 if (readResult == 1) { 1047 if (readResult == 1) {
1057 m_SrcBPC = 8; 1048 m_SrcBPC = 8;
1058 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1049 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1059 FX_Free(m_pSrcPalette); 1050 FX_Free(m_pSrcPalette);
1060 if (m_SrcPaletteNumber) { 1051 if (m_SrcPaletteNumber) {
1061 m_pSrcPalette = FX_Alloc(FX_ARGB, m_SrcPaletteNumber); 1052 m_pSrcPalette = FX_Alloc(FX_ARGB, m_SrcPaletteNumber);
1062 FXSYS_memcpy(m_pSrcPalette, pPalette, 1053 FXSYS_memcpy(m_pSrcPalette, pPalette,
1063 m_SrcPaletteNumber * sizeof(uint32_t)); 1054 m_SrcPaletteNumber * sizeof(uint32_t));
1064 } else { 1055 } else {
1065 m_pSrcPalette = nullptr; 1056 m_pSrcPalette = nullptr;
1066 } 1057 }
1067 return TRUE; 1058 return TRUE;
1068 } 1059 }
1069 if (m_pBmpContext) { 1060 if (m_pBmpContext) {
1070 pBmpModule->Finish(m_pBmpContext); 1061 pBmpModule->Finish(m_pBmpContext);
1071 m_pBmpContext = NULL; 1062 m_pBmpContext = nullptr;
1072 } 1063 }
1073 m_status = FXCODEC_STATUS_ERR_FORMAT; 1064 m_status = FXCODEC_STATUS_ERR_FORMAT;
1074 return FALSE; 1065 return FALSE;
1075 } break; 1066 } break;
1076 case FXCODEC_IMAGE_JPG: { 1067 case FXCODEC_IMAGE_JPG: {
1077 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 1068 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
1078 if (pJpegModule == NULL) { 1069 if (!pJpegModule) {
1079 m_status = FXCODEC_STATUS_ERR_MEMORY; 1070 m_status = FXCODEC_STATUS_ERR_MEMORY;
1080 return FALSE; 1071 return FALSE;
1081 } 1072 }
1082 m_pJpegContext = pJpegModule->Start(); 1073 m_pJpegContext = pJpegModule->Start();
1083 if (m_pJpegContext == NULL) { 1074 if (!m_pJpegContext) {
1084 m_status = FXCODEC_STATUS_ERR_MEMORY; 1075 m_status = FXCODEC_STATUS_ERR_MEMORY;
1085 return FALSE; 1076 return FALSE;
1086 } 1077 }
1087 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size); 1078 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size);
1088 if (!bResult) { 1079 if (!bResult) {
1089 m_status = FXCODEC_STATUS_ERR_READ; 1080 m_status = FXCODEC_STATUS_ERR_READ;
1090 return FALSE; 1081 return FALSE;
1091 } 1082 }
1092 m_offSet += size; 1083 m_offSet += size;
1093 pJpegModule->Input(m_pJpegContext, m_pSrcBuf, size); 1084 pJpegModule->Input(m_pJpegContext, m_pSrcBuf, size);
(...skipping 10 matching lines...) Expand all
1104 pJpegModule->ReadHeader(m_pJpegContext, &m_SrcWidth, &m_SrcHeight, 1095 pJpegModule->ReadHeader(m_pJpegContext, &m_SrcWidth, &m_SrcHeight,
1105 &m_SrcComponents, pAttribute); 1096 &m_SrcComponents, pAttribute);
1106 } 1097 }
1107 if (!readResult) { 1098 if (!readResult) {
1108 m_SrcBPC = 8; 1099 m_SrcBPC = 8;
1109 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1100 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1110 return TRUE; 1101 return TRUE;
1111 } 1102 }
1112 if (m_pJpegContext) { 1103 if (m_pJpegContext) {
1113 pJpegModule->Finish(m_pJpegContext); 1104 pJpegModule->Finish(m_pJpegContext);
1114 m_pJpegContext = NULL; 1105 m_pJpegContext = nullptr;
1115 } 1106 }
1116 m_status = FXCODEC_STATUS_ERR_FORMAT; 1107 m_status = FXCODEC_STATUS_ERR_FORMAT;
1117 return FALSE; 1108 return FALSE;
1118 } break; 1109 } break;
1119 case FXCODEC_IMAGE_PNG: { 1110 case FXCODEC_IMAGE_PNG: {
1120 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 1111 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
1121 if (pPngModule == NULL) { 1112 if (!pPngModule) {
1122 m_status = FXCODEC_STATUS_ERR_MEMORY; 1113 m_status = FXCODEC_STATUS_ERR_MEMORY;
1123 return FALSE; 1114 return FALSE;
1124 } 1115 }
1125 pPngModule->ReadHeaderCallback = 1116 pPngModule->ReadHeaderCallback =
1126 CCodec_ProgressiveDecoder::PngReadHeaderFunc; 1117 CCodec_ProgressiveDecoder::PngReadHeaderFunc;
1127 pPngModule->AskScanlineBufCallback = 1118 pPngModule->AskScanlineBufCallback =
1128 CCodec_ProgressiveDecoder::PngAskScanlineBufFunc; 1119 CCodec_ProgressiveDecoder::PngAskScanlineBufFunc;
1129 pPngModule->FillScanlineBufCompletedCallback = 1120 pPngModule->FillScanlineBufCompletedCallback =
1130 CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc; 1121 CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc;
1131 m_pPngContext = pPngModule->Start((void*)this); 1122 m_pPngContext = pPngModule->Start((void*)this);
1132 if (m_pPngContext == NULL) { 1123 if (!m_pPngContext) {
1133 m_status = FXCODEC_STATUS_ERR_MEMORY; 1124 m_status = FXCODEC_STATUS_ERR_MEMORY;
1134 return FALSE; 1125 return FALSE;
1135 } 1126 }
1136 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size); 1127 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size);
1137 if (!bResult) { 1128 if (!bResult) {
1138 m_status = FXCODEC_STATUS_ERR_READ; 1129 m_status = FXCODEC_STATUS_ERR_READ;
1139 return FALSE; 1130 return FALSE;
1140 } 1131 }
1141 m_offSet += size; 1132 m_offSet += size;
1142 bResult = pPngModule->Input(m_pPngContext, m_pSrcBuf, size, pAttribute); 1133 bResult = pPngModule->Input(m_pPngContext, m_pSrcBuf, size, pAttribute);
1143 while (bResult) { 1134 while (bResult) {
1144 uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet; 1135 uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet;
1145 uint32_t input_size = 1136 uint32_t input_size =
1146 remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size; 1137 remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size;
1147 if (input_size == 0) { 1138 if (input_size == 0) {
1148 if (m_pPngContext) { 1139 if (m_pPngContext) {
1149 pPngModule->Finish(m_pPngContext); 1140 pPngModule->Finish(m_pPngContext);
1150 } 1141 }
1151 m_pPngContext = NULL; 1142 m_pPngContext = nullptr;
1152 m_status = FXCODEC_STATUS_ERR_FORMAT; 1143 m_status = FXCODEC_STATUS_ERR_FORMAT;
1153 return FALSE; 1144 return FALSE;
1154 } 1145 }
1155 if (m_pSrcBuf && input_size > m_SrcSize) { 1146 if (m_pSrcBuf && input_size > m_SrcSize) {
1156 FX_Free(m_pSrcBuf); 1147 FX_Free(m_pSrcBuf);
1157 m_pSrcBuf = FX_Alloc(uint8_t, input_size); 1148 m_pSrcBuf = FX_Alloc(uint8_t, input_size);
1158 FXSYS_memset(m_pSrcBuf, 0, input_size); 1149 FXSYS_memset(m_pSrcBuf, 0, input_size);
1159 m_SrcSize = input_size; 1150 m_SrcSize = input_size;
1160 } 1151 }
1161 bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size); 1152 bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size);
1162 if (!bResult) { 1153 if (!bResult) {
1163 m_status = FXCODEC_STATUS_ERR_READ; 1154 m_status = FXCODEC_STATUS_ERR_READ;
1164 return FALSE; 1155 return FALSE;
1165 } 1156 }
1166 m_offSet += input_size; 1157 m_offSet += input_size;
1167 bResult = 1158 bResult =
1168 pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, pAttribute); 1159 pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, pAttribute);
1169 } 1160 }
1170 ASSERT(!bResult); 1161 ASSERT(!bResult);
1171 if (m_pPngContext) { 1162 if (m_pPngContext) {
1172 pPngModule->Finish(m_pPngContext); 1163 pPngModule->Finish(m_pPngContext);
1173 m_pPngContext = NULL; 1164 m_pPngContext = nullptr;
1174 } 1165 }
1175 if (m_SrcPassNumber == 0) { 1166 if (m_SrcPassNumber == 0) {
1176 m_status = FXCODEC_STATUS_ERR_FORMAT; 1167 m_status = FXCODEC_STATUS_ERR_FORMAT;
1177 return FALSE; 1168 return FALSE;
1178 } 1169 }
1179 } break; 1170 } break;
1180 case FXCODEC_IMAGE_GIF: { 1171 case FXCODEC_IMAGE_GIF: {
1181 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 1172 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
1182 if (pGifModule == NULL) { 1173 if (!pGifModule) {
1183 m_status = FXCODEC_STATUS_ERR_MEMORY; 1174 m_status = FXCODEC_STATUS_ERR_MEMORY;
1184 return FALSE; 1175 return FALSE;
1185 } 1176 }
1186 pGifModule->RecordCurrentPositionCallback = 1177 pGifModule->RecordCurrentPositionCallback =
1187 CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback; 1178 CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback;
1188 pGifModule->AskLocalPaletteBufCallback = 1179 pGifModule->AskLocalPaletteBufCallback =
1189 CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback; 1180 CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback;
1190 pGifModule->InputRecordPositionBufCallback = 1181 pGifModule->InputRecordPositionBufCallback =
1191 CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback; 1182 CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback;
1192 pGifModule->ReadScanlineCallback = 1183 pGifModule->ReadScanlineCallback =
1193 CCodec_ProgressiveDecoder::GifReadScanlineCallback; 1184 CCodec_ProgressiveDecoder::GifReadScanlineCallback;
1194 m_pGifContext = pGifModule->Start((void*)this); 1185 m_pGifContext = pGifModule->Start((void*)this);
1195 if (m_pGifContext == NULL) { 1186 if (!m_pGifContext) {
1196 m_status = FXCODEC_STATUS_ERR_MEMORY; 1187 m_status = FXCODEC_STATUS_ERR_MEMORY;
1197 return FALSE; 1188 return FALSE;
1198 } 1189 }
1199 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size); 1190 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, 0, size);
1200 if (!bResult) { 1191 if (!bResult) {
1201 m_status = FXCODEC_STATUS_ERR_READ; 1192 m_status = FXCODEC_STATUS_ERR_READ;
1202 return FALSE; 1193 return FALSE;
1203 } 1194 }
1204 m_offSet += size; 1195 m_offSet += size;
1205 pGifModule->Input(m_pGifContext, m_pSrcBuf, size); 1196 pGifModule->Input(m_pGifContext, m_pSrcBuf, size);
(...skipping 11 matching lines...) Expand all
1217 m_pGifContext, &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber, 1208 m_pGifContext, &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
1218 (void**)&m_pGifPalette, &m_GifBgIndex, nullptr); 1209 (void**)&m_pGifPalette, &m_GifBgIndex, nullptr);
1219 } 1210 }
1220 if (readResult == 1) { 1211 if (readResult == 1) {
1221 m_SrcBPC = 8; 1212 m_SrcBPC = 8;
1222 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1213 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1223 return TRUE; 1214 return TRUE;
1224 } 1215 }
1225 if (m_pGifContext) { 1216 if (m_pGifContext) {
1226 pGifModule->Finish(m_pGifContext); 1217 pGifModule->Finish(m_pGifContext);
1227 m_pGifContext = NULL; 1218 m_pGifContext = nullptr;
1228 } 1219 }
1229 m_status = FXCODEC_STATUS_ERR_FORMAT; 1220 m_status = FXCODEC_STATUS_ERR_FORMAT;
1230 return FALSE; 1221 return FALSE;
1231 } break; 1222 } break;
1232 case FXCODEC_IMAGE_TIF: { 1223 case FXCODEC_IMAGE_TIF: {
1233 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); 1224 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
1234 if (pTiffModule == NULL) { 1225 if (!pTiffModule) {
1235 m_status = FXCODEC_STATUS_ERR_FORMAT; 1226 m_status = FXCODEC_STATUS_ERR_FORMAT;
1236 return FALSE; 1227 return FALSE;
1237 } 1228 }
1238 m_pTiffContext = pTiffModule->CreateDecoder(m_pFile); 1229 m_pTiffContext = pTiffModule->CreateDecoder(m_pFile);
1239 if (m_pTiffContext == NULL) { 1230 if (!m_pTiffContext) {
1240 m_status = FXCODEC_STATUS_ERR_FORMAT; 1231 m_status = FXCODEC_STATUS_ERR_FORMAT;
1241 return FALSE; 1232 return FALSE;
1242 } 1233 }
1243 int32_t frames = 0; 1234 int32_t frames = 0;
1244 pTiffModule->GetFrames(m_pTiffContext, frames); 1235 pTiffModule->GetFrames(m_pTiffContext, frames);
1245 uint32_t bpc; 1236 uint32_t bpc;
1246 FX_BOOL ret = pTiffModule->LoadFrameInfo( 1237 FX_BOOL ret = pTiffModule->LoadFrameInfo(
1247 m_pTiffContext, 0, (uint32_t&)m_SrcWidth, (uint32_t&)m_SrcHeight, 1238 m_pTiffContext, 0, (uint32_t&)m_SrcWidth, (uint32_t&)m_SrcHeight,
1248 (uint32_t&)m_SrcComponents, bpc, pAttribute); 1239 (uint32_t&)m_SrcComponents, bpc, pAttribute);
1249 m_SrcComponents = 4; 1240 m_SrcComponents = 4;
1250 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1241 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1251 if (!ret) { 1242 if (!ret) {
1252 pTiffModule->DestroyDecoder(m_pTiffContext); 1243 pTiffModule->DestroyDecoder(m_pTiffContext);
1253 (m_pTiffContext = NULL); 1244 (m_pTiffContext = nullptr);
1254 (m_status = FXCODEC_STATUS_ERR_FORMAT); 1245 (m_status = FXCODEC_STATUS_ERR_FORMAT);
1255 return FALSE; 1246 return FALSE;
1256 } 1247 }
1257 } break; 1248 } break;
1258 default: 1249 default:
1259 m_status = FXCODEC_STATUS_ERR_FORMAT; 1250 m_status = FXCODEC_STATUS_ERR_FORMAT;
1260 return FALSE; 1251 return FALSE;
1261 } 1252 }
1262 return TRUE; 1253 return TRUE;
1263 } 1254 }
1264 FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo( 1255 FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
1265 IFX_FileRead* pFile, 1256 IFX_FileRead* pFile,
1266 FXCODEC_IMAGE_TYPE imageType, 1257 FXCODEC_IMAGE_TYPE imageType,
1267 CFX_DIBAttribute* pAttribute) { 1258 CFX_DIBAttribute* pAttribute) {
1268 switch (m_status) { 1259 switch (m_status) {
1269 case FXCODEC_STATUS_FRAME_READY: 1260 case FXCODEC_STATUS_FRAME_READY:
1270 case FXCODEC_STATUS_FRAME_TOBECONTINUE: 1261 case FXCODEC_STATUS_FRAME_TOBECONTINUE:
1271 case FXCODEC_STATUS_DECODE_READY: 1262 case FXCODEC_STATUS_DECODE_READY:
1272 case FXCODEC_STATUS_DECODE_TOBECONTINUE: 1263 case FXCODEC_STATUS_DECODE_TOBECONTINUE:
1273 return FXCODEC_STATUS_ERROR; 1264 return FXCODEC_STATUS_ERROR;
1274 default: 1265 default:
1275 break; 1266 break;
1276 } 1267 }
1277 if (pFile == NULL) { 1268 if (!pFile) {
1278 m_status = FXCODEC_STATUS_ERR_PARAMS; 1269 m_status = FXCODEC_STATUS_ERR_PARAMS;
1279 m_pFile = NULL; 1270 m_pFile = nullptr;
1280 return m_status; 1271 return m_status;
1281 } 1272 }
1282 m_pFile = pFile; 1273 m_pFile = pFile;
1283 m_offSet = 0; 1274 m_offSet = 0;
1284 m_SrcWidth = m_SrcHeight = 0; 1275 m_SrcWidth = m_SrcHeight = 0;
1285 m_SrcComponents = m_SrcBPC = 0; 1276 m_SrcComponents = m_SrcBPC = 0;
1286 m_clipBox = FX_RECT(0, 0, 0, 0); 1277 m_clipBox = FX_RECT(0, 0, 0, 0);
1287 m_startX = m_startY = 0; 1278 m_startX = m_startY = 0;
1288 m_sizeX = m_sizeY = 0; 1279 m_sizeX = m_sizeY = 0;
1289 m_SrcPassNumber = 0; 1280 m_SrcPassNumber = 0;
1290 if (imageType != FXCODEC_IMAGE_UNKNOWN && 1281 if (imageType != FXCODEC_IMAGE_UNKNOWN &&
1291 DetectImageType(imageType, pAttribute)) { 1282 DetectImageType(imageType, pAttribute)) {
1292 m_imagType = imageType; 1283 m_imagType = imageType;
1293 m_status = FXCODEC_STATUS_FRAME_READY; 1284 m_status = FXCODEC_STATUS_FRAME_READY;
1294 return m_status; 1285 return m_status;
1295 } 1286 }
1296 for (int type = FXCODEC_IMAGE_BMP; type < FXCODEC_IMAGE_MAX; type++) { 1287 for (int type = FXCODEC_IMAGE_BMP; type < FXCODEC_IMAGE_MAX; type++) {
1297 if (DetectImageType((FXCODEC_IMAGE_TYPE)type, pAttribute)) { 1288 if (DetectImageType((FXCODEC_IMAGE_TYPE)type, pAttribute)) {
1298 m_imagType = (FXCODEC_IMAGE_TYPE)type; 1289 m_imagType = (FXCODEC_IMAGE_TYPE)type;
1299 m_status = FXCODEC_STATUS_FRAME_READY; 1290 m_status = FXCODEC_STATUS_FRAME_READY;
1300 return m_status; 1291 return m_status;
1301 } 1292 }
1302 } 1293 }
1303 m_status = FXCODEC_STATUS_ERR_FORMAT; 1294 m_status = FXCODEC_STATUS_ERR_FORMAT;
1304 m_pFile = NULL; 1295 m_pFile = nullptr;
1305 return m_status; 1296 return m_status;
1306 } 1297 }
1307 void CCodec_ProgressiveDecoder::SetClipBox(FX_RECT* clip) { 1298 void CCodec_ProgressiveDecoder::SetClipBox(FX_RECT* clip) {
1308 if (m_status != FXCODEC_STATUS_FRAME_READY) { 1299 if (m_status != FXCODEC_STATUS_FRAME_READY) {
1309 return; 1300 return;
1310 } 1301 }
1311 if (clip->IsEmpty()) { 1302 if (clip->IsEmpty()) {
1312 m_clipBox = FX_RECT(0, 0, 0, 0); 1303 m_clipBox = FX_RECT(0, 0, 0, 0);
1313 return; 1304 return;
1314 } 1305 }
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 return m_status = FXCODEC_STATUS_FRAME_TOBECONTINUE; 1814 return m_status = FXCODEC_STATUS_FRAME_TOBECONTINUE;
1824 } 1815 }
1825 readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber); 1816 readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
1826 } 1817 }
1827 if (readResult == 1) { 1818 if (readResult == 1) {
1828 frames = m_FrameNumber; 1819 frames = m_FrameNumber;
1829 return m_status = FXCODEC_STATUS_DECODE_READY; 1820 return m_status = FXCODEC_STATUS_DECODE_READY;
1830 } 1821 }
1831 if (m_pGifContext) { 1822 if (m_pGifContext) {
1832 pGifModule->Finish(m_pGifContext); 1823 pGifModule->Finish(m_pGifContext);
1833 m_pGifContext = NULL; 1824 m_pGifContext = nullptr;
1834 } 1825 }
1835 return m_status = FXCODEC_STATUS_ERROR; 1826 return m_status = FXCODEC_STATUS_ERROR;
1836 } 1827 }
1837 } break; 1828 } break;
1838 default: 1829 default:
1839 break; 1830 break;
1840 } 1831 }
1841 return FXCODEC_STATUS_ERROR; 1832 return FXCODEC_STATUS_ERROR;
1842 } 1833 }
1843 FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, 1834 FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
1844 int start_x, 1835 int start_x,
1845 int start_y, 1836 int start_y,
1846 int size_x, 1837 int size_x,
1847 int size_y, 1838 int size_y,
1848 int32_t frames, 1839 int32_t frames,
1849 FX_BOOL bInterpol) { 1840 FX_BOOL bInterpol) {
1850 if (m_status != FXCODEC_STATUS_DECODE_READY) { 1841 if (m_status != FXCODEC_STATUS_DECODE_READY)
1851 return FXCODEC_STATUS_ERROR; 1842 return FXCODEC_STATUS_ERROR;
1852 } 1843
1853 if (pDIBitmap == NULL || pDIBitmap->GetBPP() < 8 || frames < 0 || 1844 if (!pDIBitmap || pDIBitmap->GetBPP() < 8 || frames < 0 ||
1854 frames >= m_FrameNumber) { 1845 frames >= m_FrameNumber) {
1855 return FXCODEC_STATUS_ERR_PARAMS; 1846 return FXCODEC_STATUS_ERR_PARAMS;
1856 } 1847 }
1857 m_pDeviceBitmap = pDIBitmap; 1848 m_pDeviceBitmap = pDIBitmap;
1858 if (m_clipBox.IsEmpty()) { 1849 if (m_clipBox.IsEmpty()) {
1859 return FXCODEC_STATUS_ERR_PARAMS; 1850 return FXCODEC_STATUS_ERR_PARAMS;
1860 } 1851 }
1861 if (size_x <= 0 || size_x > 65535 || size_y <= 0 || size_y > 65535) { 1852 if (size_x <= 0 || size_x > 65535 || size_y <= 0 || size_y > 65535) {
1862 return FXCODEC_STATUS_ERR_PARAMS; 1853 return FXCODEC_STATUS_ERR_PARAMS;
1863 } 1854 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 } 1890 }
1900 switch (m_imagType) { 1891 switch (m_imagType) {
1901 case FXCODEC_IMAGE_JPG: { 1892 case FXCODEC_IMAGE_JPG: {
1902 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 1893 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
1903 int down_scale = 1; 1894 int down_scale = 1;
1904 GetDownScale(down_scale); 1895 GetDownScale(down_scale);
1905 FX_BOOL bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); 1896 FX_BOOL bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale);
1906 while (!bStart) { 1897 while (!bStart) {
1907 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; 1898 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR;
1908 if (!JpegReadMoreData(pJpegModule, error_status)) { 1899 if (!JpegReadMoreData(pJpegModule, error_status)) {
1909 m_pDeviceBitmap = NULL; 1900 m_pDeviceBitmap = nullptr;
1910 m_pFile = NULL; 1901 m_pFile = nullptr;
1911 return m_status = error_status; 1902 return m_status = error_status;
1912 } 1903 }
1913 bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); 1904 bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale);
1914 } 1905 }
1915 int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale; 1906 int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale;
1916 scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4; 1907 scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4;
1917 FX_Free(m_pDecodeBuf); 1908 FX_Free(m_pDecodeBuf);
1918 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 1909 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1919 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 1910 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1920 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, 1911 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
1921 m_clipBox.Width(), m_bInterpol); 1912 m_clipBox.Width(), m_bInterpol);
1922 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 1913 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
1923 switch (m_SrcComponents) { 1914 switch (m_SrcComponents) {
1924 case 1: 1915 case 1:
1925 m_SrcFormat = FXCodec_8bppGray; 1916 m_SrcFormat = FXCodec_8bppGray;
1926 break; 1917 break;
1927 case 3: 1918 case 3:
1928 m_SrcFormat = FXCodec_Rgb; 1919 m_SrcFormat = FXCodec_Rgb;
1929 break; 1920 break;
1930 case 4: 1921 case 4:
1931 m_SrcFormat = FXCodec_Cmyk; 1922 m_SrcFormat = FXCodec_Cmyk;
1932 break; 1923 break;
1933 } 1924 }
1934 GetTransMethod(pDIBitmap->GetFormat(), m_SrcFormat); 1925 GetTransMethod(pDIBitmap->GetFormat(), m_SrcFormat);
1935 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 1926 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
1936 } break; 1927 } break;
1937 case FXCODEC_IMAGE_PNG: { 1928 case FXCODEC_IMAGE_PNG: {
1938 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 1929 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
1939 if (pPngModule == NULL) { 1930 if (!pPngModule) {
1940 m_pDeviceBitmap = NULL; 1931 m_pDeviceBitmap = nullptr;
1941 m_pFile = NULL; 1932 m_pFile = nullptr;
1942 return m_status = FXCODEC_STATUS_ERR_MEMORY; 1933 return m_status = FXCODEC_STATUS_ERR_MEMORY;
1943 } 1934 }
1944 if (m_pPngContext) { 1935 if (m_pPngContext) {
1945 pPngModule->Finish(m_pPngContext); 1936 pPngModule->Finish(m_pPngContext);
1946 m_pPngContext = NULL; 1937 m_pPngContext = nullptr;
1947 } 1938 }
1948 m_pPngContext = pPngModule->Start((void*)this); 1939 m_pPngContext = pPngModule->Start((void*)this);
1949 if (m_pPngContext == NULL) { 1940 if (!m_pPngContext) {
1950 m_pDeviceBitmap = NULL; 1941 m_pDeviceBitmap = nullptr;
1951 m_pFile = NULL; 1942 m_pFile = nullptr;
1952 return m_status = FXCODEC_STATUS_ERR_MEMORY; 1943 return m_status = FXCODEC_STATUS_ERR_MEMORY;
1953 } 1944 }
1954 m_offSet = 0; 1945 m_offSet = 0;
1955 switch (m_pDeviceBitmap->GetFormat()) { 1946 switch (m_pDeviceBitmap->GetFormat()) {
1956 case FXDIB_8bppMask: 1947 case FXDIB_8bppMask:
1957 case FXDIB_8bppRgb: 1948 case FXDIB_8bppRgb:
1958 m_SrcComponents = 1; 1949 m_SrcComponents = 1;
1959 m_SrcFormat = FXCodec_8bppGray; 1950 m_SrcFormat = FXCodec_8bppGray;
1960 break; 1951 break;
1961 case FXDIB_Rgb: 1952 case FXDIB_Rgb:
1962 m_SrcComponents = 3; 1953 m_SrcComponents = 3;
1963 m_SrcFormat = FXCodec_Rgb; 1954 m_SrcFormat = FXCodec_Rgb;
1964 break; 1955 break;
1965 case FXDIB_Rgb32: 1956 case FXDIB_Rgb32:
1966 case FXDIB_Argb: 1957 case FXDIB_Argb:
1967 m_SrcComponents = 4; 1958 m_SrcComponents = 4;
1968 m_SrcFormat = FXCodec_Argb; 1959 m_SrcFormat = FXCodec_Argb;
1969 break; 1960 break;
1970 default: { 1961 default: {
1971 m_pDeviceBitmap = NULL; 1962 m_pDeviceBitmap = nullptr;
1972 m_pFile = NULL; 1963 m_pFile = nullptr;
1973 return m_status = FXCODEC_STATUS_ERR_PARAMS; 1964 return m_status = FXCODEC_STATUS_ERR_PARAMS;
1974 } 1965 }
1975 } 1966 }
1976 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); 1967 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
1977 int scanline_size = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; 1968 int scanline_size = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4;
1978 FX_Free(m_pDecodeBuf); 1969 FX_Free(m_pDecodeBuf);
1979 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 1970 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1980 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 1971 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1981 m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol); 1972 m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol);
1982 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 1973 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
1983 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 1974 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
1984 } break; 1975 } break;
1985 case FXCODEC_IMAGE_GIF: { 1976 case FXCODEC_IMAGE_GIF: {
1986 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 1977 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
1987 if (pGifModule == NULL) { 1978 if (!pGifModule) {
1988 m_pDeviceBitmap = NULL; 1979 m_pDeviceBitmap = nullptr;
1989 m_pFile = NULL; 1980 m_pFile = nullptr;
1990 return m_status = FXCODEC_STATUS_ERR_MEMORY; 1981 return m_status = FXCODEC_STATUS_ERR_MEMORY;
1991 } 1982 }
1992 m_SrcFormat = FXCodec_8bppRgb; 1983 m_SrcFormat = FXCodec_8bppRgb;
1993 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); 1984 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
1994 int scanline_size = (m_SrcWidth + 3) / 4 * 4; 1985 int scanline_size = (m_SrcWidth + 3) / 4 * 4;
1995 FX_Free(m_pDecodeBuf); 1986 FX_Free(m_pDecodeBuf);
1996 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 1987 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1997 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 1988 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1998 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, 1989 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
1999 m_clipBox.Width(), m_bInterpol); 1990 m_clipBox.Width(), m_bInterpol);
2000 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 1991 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
2001 m_FrameCur = frames; 1992 m_FrameCur = frames;
2002 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 1993 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2003 } break; 1994 } break;
2004 case FXCODEC_IMAGE_BMP: { 1995 case FXCODEC_IMAGE_BMP: {
2005 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); 1996 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
2006 if (pBmpModule == NULL) { 1997 if (!pBmpModule) {
2007 m_pDeviceBitmap = NULL; 1998 m_pDeviceBitmap = nullptr;
2008 m_pFile = NULL; 1999 m_pFile = nullptr;
2009 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2000 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2010 } 2001 }
2011 switch (m_SrcComponents) { 2002 switch (m_SrcComponents) {
2012 case 1: 2003 case 1:
2013 m_SrcFormat = FXCodec_8bppRgb; 2004 m_SrcFormat = FXCodec_8bppRgb;
2014 break; 2005 break;
2015 case 3: 2006 case 3:
2016 m_SrcFormat = FXCodec_Rgb; 2007 m_SrcFormat = FXCodec_Rgb;
2017 break; 2008 break;
2018 case 4: 2009 case 4:
(...skipping 23 matching lines...) Expand all
2042 } 2033 }
2043 switch (m_imagType) { 2034 switch (m_imagType) {
2044 case FXCODEC_IMAGE_JPG: { 2035 case FXCODEC_IMAGE_JPG: {
2045 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 2036 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
2046 while (TRUE) { 2037 while (TRUE) {
2047 FX_BOOL readRes = 2038 FX_BOOL readRes =
2048 pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf); 2039 pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf);
2049 while (!readRes) { 2040 while (!readRes) {
2050 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2041 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2051 if (!JpegReadMoreData(pJpegModule, error_status)) { 2042 if (!JpegReadMoreData(pJpegModule, error_status)) {
2052 m_pDeviceBitmap = NULL; 2043 m_pDeviceBitmap = nullptr;
2053 m_pFile = NULL; 2044 m_pFile = nullptr;
2054 return m_status = error_status; 2045 return m_status = error_status;
2055 } 2046 }
2056 readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf); 2047 readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf);
2057 } 2048 }
2058 if (m_SrcFormat == FXCodec_Rgb) { 2049 if (m_SrcFormat == FXCodec_Rgb) {
2059 int src_Bpp = (m_SrcFormat & 0xff) >> 3; 2050 int src_Bpp = (m_SrcFormat & 0xff) >> 3;
2060 _RGB2BGR(m_pDecodeBuf + m_clipBox.left * src_Bpp, m_clipBox.Width()); 2051 _RGB2BGR(m_pDecodeBuf + m_clipBox.left * src_Bpp, m_clipBox.Width());
2061 } 2052 }
2062 if (m_SrcRow >= m_clipBox.bottom) { 2053 if (m_SrcRow >= m_clipBox.bottom) {
2063 m_pDeviceBitmap = NULL; 2054 m_pDeviceBitmap = nullptr;
2064 m_pFile = NULL; 2055 m_pFile = nullptr;
2065 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2056 return m_status = FXCODEC_STATUS_DECODE_FINISH;
2066 } 2057 }
2067 Resample(m_pDeviceBitmap, m_SrcRow, m_pDecodeBuf, m_SrcFormat); 2058 Resample(m_pDeviceBitmap, m_SrcRow, m_pDecodeBuf, m_SrcFormat);
2068 m_SrcRow++; 2059 m_SrcRow++;
2069 if (pPause && pPause->NeedToPauseNow()) { 2060 if (pPause && pPause->NeedToPauseNow()) {
2070 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2061 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2071 } 2062 }
2072 } 2063 }
2073 } break; 2064 } break;
2074 case FXCODEC_IMAGE_PNG: { 2065 case FXCODEC_IMAGE_PNG: {
2075 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 2066 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
2076 while (TRUE) { 2067 while (TRUE) {
2077 uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet; 2068 uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet;
2078 uint32_t input_size = 2069 uint32_t input_size =
2079 remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size; 2070 remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size;
2080 if (input_size == 0) { 2071 if (input_size == 0) {
2081 if (m_pPngContext) { 2072 if (m_pPngContext) {
2082 pPngModule->Finish(m_pPngContext); 2073 pPngModule->Finish(m_pPngContext);
2083 } 2074 }
2084 m_pPngContext = NULL; 2075 m_pPngContext = nullptr;
2085 m_pDeviceBitmap = NULL; 2076 m_pDeviceBitmap = nullptr;
2086 m_pFile = NULL; 2077 m_pFile = nullptr;
2087 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2078 return m_status = FXCODEC_STATUS_DECODE_FINISH;
2088 } 2079 }
2089 if (m_pSrcBuf && input_size > m_SrcSize) { 2080 if (m_pSrcBuf && input_size > m_SrcSize) {
2090 FX_Free(m_pSrcBuf); 2081 FX_Free(m_pSrcBuf);
2091 m_pSrcBuf = FX_Alloc(uint8_t, input_size); 2082 m_pSrcBuf = FX_Alloc(uint8_t, input_size);
2092 FXSYS_memset(m_pSrcBuf, 0, input_size); 2083 FXSYS_memset(m_pSrcBuf, 0, input_size);
2093 m_SrcSize = input_size; 2084 m_SrcSize = input_size;
2094 } 2085 }
2095 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size); 2086 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size);
2096 if (!bResult) { 2087 if (!bResult) {
2097 m_pDeviceBitmap = NULL; 2088 m_pDeviceBitmap = nullptr;
2098 m_pFile = NULL; 2089 m_pFile = nullptr;
2099 return m_status = FXCODEC_STATUS_ERR_READ; 2090 return m_status = FXCODEC_STATUS_ERR_READ;
2100 } 2091 }
2101 m_offSet += input_size; 2092 m_offSet += input_size;
2102 bResult = 2093 bResult =
2103 pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, nullptr); 2094 pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, nullptr);
2104 if (!bResult) { 2095 if (!bResult) {
2105 m_pDeviceBitmap = NULL; 2096 m_pDeviceBitmap = nullptr;
2106 m_pFile = NULL; 2097 m_pFile = nullptr;
2107 return m_status = FXCODEC_STATUS_ERROR; 2098 return m_status = FXCODEC_STATUS_ERROR;
2108 } 2099 }
2109 if (pPause && pPause->NeedToPauseNow()) { 2100 if (pPause && pPause->NeedToPauseNow()) {
2110 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2101 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2111 } 2102 }
2112 } 2103 }
2113 } break; 2104 } break;
2114 case FXCODEC_IMAGE_GIF: { 2105 case FXCODEC_IMAGE_GIF: {
2115 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 2106 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
2116 while (TRUE) { 2107 while (TRUE) {
2117 int32_t readRes = 2108 int32_t readRes =
2118 pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr); 2109 pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
2119 while (readRes == 2) { 2110 while (readRes == 2) {
2120 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2111 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2121 if (!GifReadMoreData(pGifModule, error_status)) { 2112 if (!GifReadMoreData(pGifModule, error_status)) {
2122 m_pDeviceBitmap = NULL; 2113 m_pDeviceBitmap = nullptr;
2123 m_pFile = NULL; 2114 m_pFile = nullptr;
2124 return m_status = error_status; 2115 return m_status = error_status;
2125 } 2116 }
2126 if (pPause && pPause->NeedToPauseNow()) { 2117 if (pPause && pPause->NeedToPauseNow()) {
2127 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2118 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2128 } 2119 }
2129 readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr); 2120 readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
2130 } 2121 }
2131 if (readRes == 1) { 2122 if (readRes == 1) {
2132 m_pDeviceBitmap = NULL; 2123 m_pDeviceBitmap = nullptr;
2133 m_pFile = NULL; 2124 m_pFile = nullptr;
2134 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2125 return m_status = FXCODEC_STATUS_DECODE_FINISH;
2135 } 2126 }
2136 m_pDeviceBitmap = NULL; 2127 m_pDeviceBitmap = nullptr;
2137 m_pFile = NULL; 2128 m_pFile = nullptr;
2138 return m_status = FXCODEC_STATUS_ERROR; 2129 return m_status = FXCODEC_STATUS_ERROR;
2139 } 2130 }
2140 } break; 2131 } break;
2141 case FXCODEC_IMAGE_BMP: { 2132 case FXCODEC_IMAGE_BMP: {
2142 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); 2133 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
2143 while (TRUE) { 2134 while (TRUE) {
2144 int32_t readRes = pBmpModule->LoadImage(m_pBmpContext); 2135 int32_t readRes = pBmpModule->LoadImage(m_pBmpContext);
2145 while (readRes == 2) { 2136 while (readRes == 2) {
2146 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2137 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2147 if (!BmpReadMoreData(pBmpModule, error_status)) { 2138 if (!BmpReadMoreData(pBmpModule, error_status)) {
2148 m_pDeviceBitmap = NULL; 2139 m_pDeviceBitmap = nullptr;
2149 m_pFile = NULL; 2140 m_pFile = nullptr;
2150 return m_status = error_status; 2141 return m_status = error_status;
2151 } 2142 }
2152 if (pPause && pPause->NeedToPauseNow()) { 2143 if (pPause && pPause->NeedToPauseNow()) {
2153 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2144 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2154 } 2145 }
2155 readRes = pBmpModule->LoadImage(m_pBmpContext); 2146 readRes = pBmpModule->LoadImage(m_pBmpContext);
2156 } 2147 }
2157 if (readRes == 1) { 2148 if (readRes == 1) {
2158 m_pDeviceBitmap = NULL; 2149 m_pDeviceBitmap = nullptr;
2159 m_pFile = NULL; 2150 m_pFile = nullptr;
2160 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2151 return m_status = FXCODEC_STATUS_DECODE_FINISH;
2161 } 2152 }
2162 m_pDeviceBitmap = NULL; 2153 m_pDeviceBitmap = nullptr;
2163 m_pFile = NULL; 2154 m_pFile = nullptr;
2164 return m_status = FXCODEC_STATUS_ERROR; 2155 return m_status = FXCODEC_STATUS_ERROR;
2165 } 2156 }
2166 } break; 2157 } break;
2167 case FXCODEC_IMAGE_TIF: { 2158 case FXCODEC_IMAGE_TIF: {
2168 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); 2159 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
2169 FX_BOOL ret = FALSE; 2160 FX_BOOL ret = FALSE;
2170 if (m_pDeviceBitmap->GetBPP() == 32 && 2161 if (m_pDeviceBitmap->GetBPP() == 32 &&
2171 m_pDeviceBitmap->GetWidth() == m_SrcWidth && m_SrcWidth == m_sizeX && 2162 m_pDeviceBitmap->GetWidth() == m_SrcWidth && m_SrcWidth == m_sizeX &&
2172 m_pDeviceBitmap->GetHeight() == m_SrcHeight && 2163 m_pDeviceBitmap->GetHeight() == m_SrcHeight &&
2173 m_SrcHeight == m_sizeY && m_startX == 0 && m_startY == 0 && 2164 m_SrcHeight == m_sizeY && m_startX == 0 && m_startY == 0 &&
2174 m_clipBox.left == 0 && m_clipBox.top == 0 && 2165 m_clipBox.left == 0 && m_clipBox.top == 0 &&
2175 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) { 2166 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) {
2176 ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap); 2167 ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap);
2177 m_pDeviceBitmap = NULL; 2168 m_pDeviceBitmap = nullptr;
2178 m_pFile = NULL; 2169 m_pFile = nullptr;
2179 if (!ret) { 2170 if (!ret) {
2180 return m_status = FXCODEC_STATUS_ERROR; 2171 return m_status = FXCODEC_STATUS_ERROR;
2181 } 2172 }
2182 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2173 return m_status = FXCODEC_STATUS_DECODE_FINISH;
2183 } else { 2174 } else {
2184 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; 2175 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
2185 pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb); 2176 pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb);
2186 if (pDIBitmap->GetBuffer() == NULL) { 2177 if (!pDIBitmap->GetBuffer()) {
2187 delete pDIBitmap; 2178 delete pDIBitmap;
2188 m_pDeviceBitmap = NULL; 2179 m_pDeviceBitmap = nullptr;
2189 m_pFile = NULL; 2180 m_pFile = nullptr;
2190 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2181 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2191 } 2182 }
2192 ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap); 2183 ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap);
2193 if (!ret) { 2184 if (!ret) {
2194 delete pDIBitmap; 2185 delete pDIBitmap;
2195 m_pDeviceBitmap = NULL; 2186 m_pDeviceBitmap = nullptr;
2196 m_pFile = NULL; 2187 m_pFile = nullptr;
2197 return m_status = FXCODEC_STATUS_ERROR; 2188 return m_status = FXCODEC_STATUS_ERROR;
2198 } 2189 }
2199 CFX_DIBitmap* pClipBitmap = 2190 CFX_DIBitmap* pClipBitmap =
2200 (m_clipBox.left == 0 && m_clipBox.top == 0 && 2191 (m_clipBox.left == 0 && m_clipBox.top == 0 &&
2201 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) 2192 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight)
2202 ? pDIBitmap 2193 ? pDIBitmap
2203 : pDIBitmap->Clone(&m_clipBox); 2194 : pDIBitmap->Clone(&m_clipBox);
2204 if (pDIBitmap != pClipBitmap) { 2195 if (pDIBitmap != pClipBitmap) {
2205 delete pDIBitmap; 2196 delete pDIBitmap;
2206 } 2197 }
2207 if (pClipBitmap == NULL) { 2198 if (!pClipBitmap) {
2208 m_pDeviceBitmap = NULL; 2199 m_pDeviceBitmap = nullptr;
2209 m_pFile = NULL; 2200 m_pFile = nullptr;
2210 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2201 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2211 } 2202 }
2212 CFX_DIBitmap* pFormatBitmap = NULL; 2203 CFX_DIBitmap* pFormatBitmap = nullptr;
2213 switch (m_pDeviceBitmap->GetFormat()) { 2204 switch (m_pDeviceBitmap->GetFormat()) {
2214 case FXDIB_8bppRgb: 2205 case FXDIB_8bppRgb:
2215 pFormatBitmap = new CFX_DIBitmap; 2206 pFormatBitmap = new CFX_DIBitmap;
2216 pFormatBitmap->Create(pClipBitmap->GetWidth(), 2207 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2217 pClipBitmap->GetHeight(), FXDIB_8bppRgb); 2208 pClipBitmap->GetHeight(), FXDIB_8bppRgb);
2218 break; 2209 break;
2219 case FXDIB_8bppMask: 2210 case FXDIB_8bppMask:
2220 pFormatBitmap = new CFX_DIBitmap; 2211 pFormatBitmap = new CFX_DIBitmap;
2221 pFormatBitmap->Create(pClipBitmap->GetWidth(), 2212 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2222 pClipBitmap->GetHeight(), FXDIB_8bppMask); 2213 pClipBitmap->GetHeight(), FXDIB_8bppMask);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 src_line += 4; 2263 src_line += 4;
2273 } 2264 }
2274 } 2265 }
2275 } break; 2266 } break;
2276 default: 2267 default:
2277 break; 2268 break;
2278 } 2269 }
2279 if (pClipBitmap != pFormatBitmap) { 2270 if (pClipBitmap != pFormatBitmap) {
2280 delete pClipBitmap; 2271 delete pClipBitmap;
2281 } 2272 }
2282 if (pFormatBitmap == NULL) { 2273 if (!pFormatBitmap) {
2283 m_pDeviceBitmap = NULL; 2274 m_pDeviceBitmap = nullptr;
2284 m_pFile = NULL; 2275 m_pFile = nullptr;
2285 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2276 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2286 } 2277 }
2287 CFX_DIBitmap* pStrechBitmap = pFormatBitmap->StretchTo( 2278 CFX_DIBitmap* pStrechBitmap = pFormatBitmap->StretchTo(
2288 m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE); 2279 m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
2289 delete pFormatBitmap; 2280 delete pFormatBitmap;
2290 pFormatBitmap = NULL; 2281 pFormatBitmap = nullptr;
2291 if (pStrechBitmap == NULL) { 2282 if (!pStrechBitmap) {
2292 m_pDeviceBitmap = NULL; 2283 m_pDeviceBitmap = nullptr;
2293 m_pFile = NULL; 2284 m_pFile = nullptr;
2294 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2285 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2295 } 2286 }
2296 m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY, 2287 m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
2297 pStrechBitmap, 0, 0); 2288 pStrechBitmap, 0, 0);
2298 delete pStrechBitmap; 2289 delete pStrechBitmap;
2299 pStrechBitmap = NULL; 2290 pStrechBitmap = nullptr;
2300 m_pDeviceBitmap = NULL; 2291 m_pDeviceBitmap = nullptr;
2301 m_pFile = NULL; 2292 m_pFile = nullptr;
2302 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2293 return m_status = FXCODEC_STATUS_DECODE_FINISH;
2303 } 2294 }
2304 } break; 2295 } break;
2305 default: 2296 default:
2306 break; 2297 break;
2307 } 2298 }
2308 return FXCODEC_STATUS_ERROR; 2299 return FXCODEC_STATUS_ERROR;
2309 } 2300 }
2310 CCodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() { 2301 CCodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() {
2311 return new CCodec_ProgressiveDecoder(this); 2302 return new CCodec_ProgressiveDecoder(this);
2312 } 2303 }
OLDNEW
« no previous file with comments | « core/fxcodec/codec/fx_codec_png.cpp ('k') | core/fxcodec/codec/fx_codec_tiff.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698