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

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: Git rid of comparisons against NULL 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
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 error_status)) { 622 error_status)) {
632 return FALSE; 623 return FALSE;
633 } 624 }
634 uint8_t* pPalette = NULL; 625 uint8_t* pPalette = NULL;
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 354 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);
(...skipping 26 matching lines...) Expand all
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 = NULL;
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 17 matching lines...) Expand all
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 = NULL;
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);
(...skipping 29 matching lines...) Expand all
1172 pPngModule->Finish(m_pPngContext); 1163 pPngModule->Finish(m_pPngContext);
1173 m_pPngContext = NULL; 1164 m_pPngContext = NULL;
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 18 matching lines...) Expand all
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 = NULL;
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;
(...skipping 17 matching lines...) Expand all
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 = NULL;
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;
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = NULL;
1941 m_pFile = NULL; 1932 m_pFile = NULL;
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 = NULL;
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 = NULL;
1951 m_pFile = NULL; 1942 m_pFile = NULL;
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;
(...skipping 17 matching lines...) Expand all
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 = NULL;
1989 m_pFile = NULL; 1980 m_pFile = NULL;
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 = NULL;
2008 m_pFile = NULL; 1999 m_pFile = NULL;
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;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap); 2167 ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap);
2177 m_pDeviceBitmap = NULL; 2168 m_pDeviceBitmap = NULL;
2178 m_pFile = NULL; 2169 m_pFile = NULL;
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 = NULL;
2189 m_pFile = NULL; 2180 m_pFile = NULL;
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 = NULL;
2196 m_pFile = NULL; 2187 m_pFile = NULL;
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 = NULL;
2209 m_pFile = NULL; 2200 m_pFile = NULL;
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 = NULL;
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);
(...skipping 54 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 = NULL;
2284 m_pFile = NULL; 2275 m_pFile = NULL;
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 = NULL;
2291 if (pStrechBitmap == NULL) { 2282 if (!pStrechBitmap) {
2292 m_pDeviceBitmap = NULL; 2283 m_pDeviceBitmap = NULL;
2293 m_pFile = NULL; 2284 m_pFile = NULL;
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 = NULL;
2300 m_pDeviceBitmap = NULL; 2291 m_pDeviceBitmap = NULL;
2301 m_pFile = NULL; 2292 m_pFile = NULL;
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

Powered by Google App Engine
This is Rietveld 408576698