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

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

Issue 2053573003: Clean up fx_codec_tiff.cpp. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: use right variable type with TIFFGetField, add checked_casts 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 <algorithm>
10
9 #include "core/fxcodec/include/fx_codec.h" 11 #include "core/fxcodec/include/fx_codec.h"
10 #include "core/fxge/include/fx_dib.h" 12 #include "core/fxge/include/fx_dib.h"
11 13
12 #define FXCODEC_BLOCK_SIZE 4096 14 #define FXCODEC_BLOCK_SIZE 4096
13 #define FXCODEC_PNG_GAMMA 2.2 15 #define FXCODEC_PNG_GAMMA 2.2
14 16
15 #if _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_ 17 #if _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_
16 #undef FXCODEC_PNG_GAMMA 18 #undef FXCODEC_PNG_GAMMA
17 #define FXCODEC_PNG_GAMMA 1.7 19 #define FXCODEC_PNG_GAMMA 1.7
18 #endif 20 #endif
19 21
22 namespace {
23
24 void RGB2BGR(uint8_t* buffer, int width = 1) {
25 if (buffer && width > 0) {
26 uint8_t temp;
27 int i = 0;
28 int j = 0;
29 for (; i < width; i++, j += 3) {
30 temp = buffer[j];
31 buffer[j] = buffer[j + 2];
32 buffer[j + 2] = temp;
33 }
34 }
35 }
36
37 } // namespace
38
20 void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len, 39 void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len,
21 int dest_min, 40 int dest_min,
22 int dest_max, 41 int dest_max,
23 int src_len, 42 int src_len,
24 int src_min, 43 int src_min,
25 int src_max, 44 int src_max,
26 FX_BOOL bInterpol) { 45 FX_BOOL bInterpol) {
27 if (m_pWeightTables) {
28 FX_Free(m_pWeightTables);
29 }
30 double scale, base; 46 double scale, base;
31 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; 47 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len;
32 if (dest_len < 0) { 48 if (dest_len < 0) {
33 base = (FX_FLOAT)(src_len); 49 base = (FX_FLOAT)(src_len);
34 } else { 50 } else {
35 base = 0.0f; 51 base = 0.0f;
36 } 52 }
37 m_ItemSize = 53 m_ItemSize =
38 (int)(sizeof(int) * 2 + 54 (int)(sizeof(int) * 2 +
39 sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1)); 55 sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1));
40 m_DestMin = dest_min; 56 m_DestMin = dest_min;
41 m_pWeightTables = FX_Alloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4); 57 m_pWeightTables.resize((dest_max - dest_min) * m_ItemSize + 4);
42 if (FXSYS_fabs((FX_FLOAT)scale) < 1.0f) { 58 if (FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
43 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) { 59 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) {
44 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel); 60 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
45 double src_pos = dest_pixel * scale + scale / 2 + base; 61 double src_pos = dest_pixel * scale + scale / 2 + base;
46 if (bInterpol) { 62 if (bInterpol) {
47 pixel_weights.m_SrcStart = 63 pixel_weights.m_SrcStart =
48 (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2); 64 (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); 65 pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2);
50 if (pixel_weights.m_SrcStart < src_min) { 66 if (pixel_weights.m_SrcStart < src_min) {
51 pixel_weights.m_SrcStart = src_min; 67 pixel_weights.m_SrcStart = src_min;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 double weight = area_start >= area_end ? 0.0f : area_end - area_start; 127 double weight = area_start >= area_end ? 0.0f : area_end - area_start;
112 if (weight == 0 && j == end_i) { 128 if (weight == 0 && j == end_i) {
113 pixel_weights.m_SrcEnd--; 129 pixel_weights.m_SrcEnd--;
114 break; 130 break;
115 } 131 }
116 pixel_weights.m_Weights[j - start_i] = 132 pixel_weights.m_Weights[j - start_i] =
117 FXSYS_round((FX_FLOAT)(weight * 65536)); 133 FXSYS_round((FX_FLOAT)(weight * 65536));
118 } 134 }
119 } 135 }
120 } 136 }
137
121 void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len, 138 void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len,
122 int src_len, 139 int src_len,
123 FX_BOOL bInterpol) { 140 FX_BOOL bInterpol) {
124 if (m_pWeightTables) {
125 FX_Free(m_pWeightTables);
126 }
127 double scale = (double)dest_len / (double)src_len; 141 double scale = (double)dest_len / (double)src_len;
128 m_ItemSize = sizeof(int) * 4; 142 m_ItemSize = sizeof(int) * 4;
129 int size = dest_len * m_ItemSize + 4; 143 int size = dest_len * m_ItemSize + 4;
130 m_pWeightTables = FX_Alloc(uint8_t, size); 144 m_pWeightTables.resize(size, 0);
131 FXSYS_memset(m_pWeightTables, 0, size);
132 if (scale > 1) { 145 if (scale > 1) {
133 int pre_des_col = 0; 146 int pre_des_col = 0;
134 for (int src_col = 0; src_col < src_len; src_col++) { 147 for (int src_col = 0; src_col < src_len; src_col++) {
135 double des_col_f = src_col * scale; 148 double des_col_f = src_col * scale;
136 int des_col = FXSYS_round((FX_FLOAT)des_col_f); 149 int des_col = FXSYS_round((FX_FLOAT)des_col_f);
137 PixelWeight* pWeight = 150 PixelWeight* pWeight = GetPixelWeight(des_col);
138 (PixelWeight*)(m_pWeightTables + des_col * m_ItemSize);
139 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col; 151 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col;
140 pWeight->m_Weights[0] = 65536; 152 pWeight->m_Weights[0] = 65536;
141 pWeight->m_Weights[1] = 0; 153 pWeight->m_Weights[1] = 0;
142 if (src_col == src_len - 1 && des_col < dest_len - 1) { 154 if (src_col == src_len - 1 && des_col < dest_len - 1) {
143 for (int des_col_index = pre_des_col + 1; des_col_index < dest_len; 155 for (int des_col_index = pre_des_col + 1; des_col_index < dest_len;
144 des_col_index++) { 156 des_col_index++) {
145 pWeight = 157 pWeight = GetPixelWeight(des_col_index);
146 (PixelWeight*)(m_pWeightTables + des_col_index * m_ItemSize);
147 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col; 158 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col;
148 pWeight->m_Weights[0] = 65536; 159 pWeight->m_Weights[0] = 65536;
149 pWeight->m_Weights[1] = 0; 160 pWeight->m_Weights[1] = 0;
150 } 161 }
151 return; 162 return;
152 } 163 }
153 int des_col_len = des_col - pre_des_col; 164 int des_col_len = des_col - pre_des_col;
154 for (int des_col_index = pre_des_col + 1; des_col_index < des_col; 165 for (int des_col_index = pre_des_col + 1; des_col_index < des_col;
155 des_col_index++) { 166 des_col_index++) {
156 pWeight = (PixelWeight*)(m_pWeightTables + des_col_index * m_ItemSize); 167 pWeight = GetPixelWeight(des_col_index);
157 pWeight->m_SrcStart = src_col - 1; 168 pWeight->m_SrcStart = src_col - 1;
158 pWeight->m_SrcEnd = src_col; 169 pWeight->m_SrcEnd = src_col;
159 pWeight->m_Weights[0] = 170 pWeight->m_Weights[0] =
160 bInterpol ? FXSYS_round((FX_FLOAT)( 171 bInterpol ? FXSYS_round((FX_FLOAT)(
161 ((FX_FLOAT)des_col - (FX_FLOAT)des_col_index) / 172 ((FX_FLOAT)des_col - (FX_FLOAT)des_col_index) /
162 (FX_FLOAT)des_col_len * 65536)) 173 (FX_FLOAT)des_col_len * 65536))
163 : 65536; 174 : 65536;
164 pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0]; 175 pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0];
165 } 176 }
166 pre_des_col = des_col; 177 pre_des_col = des_col;
167 } 178 }
168 return; 179 return;
169 } 180 }
170 for (int des_col = 0; des_col < dest_len; des_col++) { 181 for (int des_col = 0; des_col < dest_len; des_col++) {
171 double src_col_f = des_col / scale; 182 double src_col_f = des_col / scale;
172 int src_col = FXSYS_round((FX_FLOAT)src_col_f); 183 int src_col = FXSYS_round((FX_FLOAT)src_col_f);
173 PixelWeight* pWeight = 184 PixelWeight* pWeight = GetPixelWeight(des_col);
174 (PixelWeight*)(m_pWeightTables + des_col * m_ItemSize);
175 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col; 185 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col;
176 pWeight->m_Weights[0] = 65536; 186 pWeight->m_Weights[0] = 65536;
177 pWeight->m_Weights[1] = 0; 187 pWeight->m_Weights[1] = 0;
178 } 188 }
179 } 189 }
190
180 void CCodec_ProgressiveDecoder::CFXCODEC_VertTable::Calc(int dest_len, 191 void CCodec_ProgressiveDecoder::CFXCODEC_VertTable::Calc(int dest_len,
181 int src_len) { 192 int src_len) {
182 if (m_pWeightTables) {
183 FX_Free(m_pWeightTables);
184 }
185 double scale = (double)dest_len / (double)src_len; 193 double scale = (double)dest_len / (double)src_len;
186 m_ItemSize = sizeof(int) * 4; 194 m_ItemSize = sizeof(int) * 4;
187 int size = dest_len * m_ItemSize + 4; 195 int size = dest_len * m_ItemSize + 4;
188 m_pWeightTables = FX_Alloc(uint8_t, size); 196 m_pWeightTables.resize(size, 0);
189 FXSYS_memset(m_pWeightTables, 0, size); 197 if (scale <= 1) {
190 if (scale > 1) { 198 for (int des_row = 0; des_row < dest_len; des_row++) {
191 double step = 0.0; 199 PixelWeight* pWeight = GetPixelWeight(des_row);
192 int src_row = 0; 200 pWeight->m_SrcStart = des_row;
193 while (step < (double)dest_len) { 201 pWeight->m_SrcEnd = des_row;
194 int start_step = (int)step; 202 pWeight->m_Weights[0] = 65536;
195 step = scale * (++src_row); 203 pWeight->m_Weights[1] = 0;
196 int end_step = (int)step; 204 }
197 if (end_step >= dest_len) { 205 return;
198 end_step = dest_len; 206 }
199 for (int des_row = start_step; des_row < end_step; des_row++) { 207
200 PixelWeight* pWeight = 208 double step = 0.0;
201 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize); 209 int src_row = 0;
202 pWeight->m_SrcStart = start_step; 210 while (step < (double)dest_len) {
203 pWeight->m_SrcEnd = start_step; 211 int start_step = (int)step;
204 pWeight->m_Weights[0] = 65536; 212 step = scale * (++src_row);
205 pWeight->m_Weights[1] = 0; 213 int end_step = (int)step;
206 } 214 if (end_step >= dest_len) {
207 return; 215 end_step = dest_len;
208 } 216 for (int des_row = start_step; des_row < end_step; des_row++) {
209 int length = end_step - start_step; 217 PixelWeight* pWeight = GetPixelWeight(des_row);
210 {
211 PixelWeight* pWeight =
212 (PixelWeight*)(m_pWeightTables + start_step * m_ItemSize);
213 pWeight->m_SrcStart = start_step; 218 pWeight->m_SrcStart = start_step;
214 pWeight->m_SrcEnd = start_step; 219 pWeight->m_SrcEnd = start_step;
215 pWeight->m_Weights[0] = 65536; 220 pWeight->m_Weights[0] = 65536;
216 pWeight->m_Weights[1] = 0; 221 pWeight->m_Weights[1] = 0;
217 } 222 }
218 for (int des_row = start_step + 1; des_row < end_step; des_row++) { 223 return;
219 PixelWeight* pWeight =
220 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
221 pWeight->m_SrcStart = start_step;
222 pWeight->m_SrcEnd = end_step;
223 pWeight->m_Weights[0] = FXSYS_round((FX_FLOAT)(end_step - des_row) /
224 (FX_FLOAT)length * 65536);
225 pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0];
226 }
227 } 224 }
228 } else { 225 int length = end_step - start_step;
229 for (int des_row = 0; des_row < dest_len; des_row++) { 226 {
230 PixelWeight* pWeight = 227 PixelWeight* pWeight = GetPixelWeight(start_step);
231 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize); 228 pWeight->m_SrcStart = start_step;
232 pWeight->m_SrcStart = des_row; 229 pWeight->m_SrcEnd = start_step;
233 pWeight->m_SrcEnd = des_row;
234 pWeight->m_Weights[0] = 65536; 230 pWeight->m_Weights[0] = 65536;
235 pWeight->m_Weights[1] = 0; 231 pWeight->m_Weights[1] = 0;
236 } 232 }
233 for (int des_row = start_step + 1; des_row < end_step; des_row++) {
234 PixelWeight* pWeight = GetPixelWeight(des_row);
235 pWeight->m_SrcStart = start_step;
236 pWeight->m_SrcEnd = end_step;
237 pWeight->m_Weights[0] = FXSYS_round((FX_FLOAT)(end_step - des_row) /
238 (FX_FLOAT)length * 65536);
239 pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0];
240 }
237 } 241 }
238 } 242 }
243
239 CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder( 244 CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder(
240 CCodec_ModuleMgr* pCodecMgr) { 245 CCodec_ModuleMgr* pCodecMgr) {
241 m_pFile = nullptr; 246 m_pFile = nullptr;
242 m_pJpegContext = nullptr; 247 m_pJpegContext = nullptr;
243 m_pPngContext = nullptr; 248 m_pPngContext = nullptr;
244 m_pGifContext = nullptr; 249 m_pGifContext = nullptr;
245 m_pBmpContext = nullptr; 250 m_pBmpContext = nullptr;
246 m_pTiffContext = nullptr; 251 m_pTiffContext = nullptr;
247 m_pCodecMgr = nullptr; 252 m_pCodecMgr = nullptr;
248 m_pSrcBuf = nullptr; 253 m_pSrcBuf = nullptr;
249 m_pDecodeBuf = nullptr; 254 m_pDecodeBuf = nullptr;
250 m_pDeviceBitmap = nullptr; 255 m_pDeviceBitmap = nullptr;
251 m_pSrcPalette = nullptr; 256 m_pSrcPalette = nullptr;
252 m_pCodecMgr = pCodecMgr; 257 m_pCodecMgr = pCodecMgr;
253 m_offSet = 0; 258 m_offSet = 0;
254 m_SrcSize = 0; 259 m_SrcSize = 0;
255 m_ScanlineSize = 0; 260 m_ScanlineSize = 0;
256 m_SrcWidth = m_SrcHeight = 0; 261 m_SrcWidth = 0;
262 m_SrcHeight = 0;
257 m_SrcComponents = 0; 263 m_SrcComponents = 0;
258 m_SrcBPC = 0; 264 m_SrcBPC = 0;
259 m_SrcPassNumber = 0; 265 m_SrcPassNumber = 0;
260 m_clipBox = FX_RECT(0, 0, 0, 0); 266 m_clipBox = FX_RECT(0, 0, 0, 0);
261 m_imagType = FXCODEC_IMAGE_UNKNOWN; 267 m_imagType = FXCODEC_IMAGE_UNKNOWN;
262 m_status = FXCODEC_STATUS_DECODE_FINISH; 268 m_status = FXCODEC_STATUS_DECODE_FINISH;
263 m_TransMethod = -1; 269 m_TransMethod = -1;
264 m_SrcRow = 0; 270 m_SrcRow = 0;
265 m_SrcFormat = FXCodec_Invalid; 271 m_SrcFormat = FXCodec_Invalid;
266 m_bInterpol = TRUE; 272 m_bInterpol = TRUE;
267 m_FrameNumber = 0; 273 m_FrameNumber = 0;
268 m_FrameCur = 0; 274 m_FrameCur = 0;
269 m_SrcPaletteNumber = 0; 275 m_SrcPaletteNumber = 0;
270 m_GifPltNumber = 0; 276 m_GifPltNumber = 0;
271 m_GifBgIndex = 0; 277 m_GifBgIndex = 0;
272 m_pGifPalette = nullptr; 278 m_pGifPalette = nullptr;
273 m_GifTransIndex = -1; 279 m_GifTransIndex = -1;
274 m_GifFrameRect = FX_RECT(0, 0, 0, 0); 280 m_GifFrameRect = FX_RECT(0, 0, 0, 0);
275 m_BmpIsTopBottom = FALSE; 281 m_BmpIsTopBottom = FALSE;
276 } 282 }
283
277 CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() { 284 CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() {
278 m_pFile = nullptr; 285 m_pFile = nullptr;
279 if (m_pJpegContext) { 286 if (m_pJpegContext)
280 m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext); 287 m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext);
281 } 288 if (m_pPngContext)
282 if (m_pPngContext) {
283 m_pCodecMgr->GetPngModule()->Finish(m_pPngContext); 289 m_pCodecMgr->GetPngModule()->Finish(m_pPngContext);
284 } 290 if (m_pGifContext)
285 if (m_pGifContext) {
286 m_pCodecMgr->GetGifModule()->Finish(m_pGifContext); 291 m_pCodecMgr->GetGifModule()->Finish(m_pGifContext);
287 } 292 if (m_pBmpContext)
288 if (m_pBmpContext) {
289 m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext); 293 m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext);
290 } 294 if (m_pTiffContext)
291 if (m_pTiffContext) {
292 m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext); 295 m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext);
293 }
294 FX_Free(m_pSrcBuf); 296 FX_Free(m_pSrcBuf);
295 FX_Free(m_pDecodeBuf); 297 FX_Free(m_pDecodeBuf);
296 FX_Free(m_pSrcPalette); 298 FX_Free(m_pSrcPalette);
297 } 299 }
300
298 FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData( 301 FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData(
299 CCodec_JpegModule* pJpegModule, 302 CCodec_JpegModule* pJpegModule,
300 FXCODEC_STATUS& err_status) { 303 FXCODEC_STATUS& err_status) {
301 uint32_t dwSize = (uint32_t)m_pFile->GetSize(); 304 uint32_t dwSize = (uint32_t)m_pFile->GetSize();
302 if (dwSize <= m_offSet) { 305 if (dwSize <= m_offSet) {
303 return FALSE; 306 return FALSE;
304 } 307 }
305 dwSize = dwSize - m_offSet; 308 dwSize = dwSize - m_offSet;
306 uint32_t dwAvail = pJpegModule->GetAvailInput(m_pJpegContext, nullptr); 309 uint32_t dwAvail = pJpegModule->GetAvailInput(m_pJpegContext, nullptr);
307 if (dwAvail == m_SrcSize) { 310 if (dwAvail == m_SrcSize) {
(...skipping 17 matching lines...) Expand all
325 } 328 }
326 } 329 }
327 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) { 330 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) {
328 err_status = FXCODEC_STATUS_ERR_READ; 331 err_status = FXCODEC_STATUS_ERR_READ;
329 return FALSE; 332 return FALSE;
330 } 333 }
331 m_offSet += dwSize; 334 m_offSet += dwSize;
332 pJpegModule->Input(m_pJpegContext, m_pSrcBuf, dwSize + dwAvail); 335 pJpegModule->Input(m_pJpegContext, m_pSrcBuf, dwSize + dwAvail);
333 return TRUE; 336 return TRUE;
334 } 337 }
338
335 FX_BOOL CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule, 339 FX_BOOL CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule,
336 int width, 340 int width,
337 int height, 341 int height,
338 int bpc, 342 int bpc,
339 int pass, 343 int pass,
340 int* color_type, 344 int* color_type,
341 double* gamma) { 345 double* gamma) {
342 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 346 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
343 if (!pCodec->m_pDeviceBitmap) { 347 if (!pCodec->m_pDeviceBitmap) {
344 pCodec->m_SrcWidth = width; 348 pCodec->m_SrcWidth = width;
345 pCodec->m_SrcHeight = height; 349 pCodec->m_SrcHeight = height;
346 pCodec->m_SrcBPC = bpc; 350 pCodec->m_SrcBPC = bpc;
347 pCodec->m_SrcPassNumber = pass; 351 pCodec->m_SrcPassNumber = pass;
348 pCodec->m_SrcComponents = 352 switch (*color_type) {
349 *color_type == 0 ? 1 : *color_type == 2 353 case 0:
350 ? 3 354 pCodec->m_SrcComponents = 1;
351 : *color_type == 3 355 break;
352 ? 4 356 case 4:
353 : *color_type == 4 357 pCodec->m_SrcComponents = 2;
354 ? 2 358 break;
355 : *color_type == 6 ? 4 : 0; 359 case 2:
360 pCodec->m_SrcComponents = 3;
361 break;
362 case 3:
363 case 6:
364 pCodec->m_SrcComponents = 4;
365 break;
366 default:
367 pCodec->m_SrcComponents = 0;
368 break;
369 }
356 pCodec->m_clipBox = FX_RECT(0, 0, width, height); 370 pCodec->m_clipBox = FX_RECT(0, 0, width, height);
357 return FALSE; 371 return FALSE;
358 } 372 }
359 FXDIB_Format format = pCodec->m_pDeviceBitmap->GetFormat(); 373 FXDIB_Format format = pCodec->m_pDeviceBitmap->GetFormat();
360 switch (format) { 374 switch (format) {
361 case FXDIB_1bppMask: 375 case FXDIB_1bppMask:
362 case FXDIB_1bppRgb: 376 case FXDIB_1bppRgb:
363 ASSERT(FALSE); 377 ASSERT(FALSE);
364 return FALSE; 378 return FALSE;
365 case FXDIB_8bppMask: 379 case FXDIB_8bppMask:
366 case FXDIB_8bppRgb: 380 case FXDIB_8bppRgb:
367 *color_type = 0; 381 *color_type = 0;
368 break; 382 break;
369 case FXDIB_Rgb: 383 case FXDIB_Rgb:
370 *color_type = 2; 384 *color_type = 2;
371 break; 385 break;
372 case FXDIB_Rgb32: 386 case FXDIB_Rgb32:
373 case FXDIB_Argb: 387 case FXDIB_Argb:
374 *color_type = 6; 388 *color_type = 6;
375 break; 389 break;
376 default: 390 default:
377 ASSERT(FALSE); 391 ASSERT(FALSE);
378 return FALSE; 392 return FALSE;
379 } 393 }
380 *gamma = FXCODEC_PNG_GAMMA; 394 *gamma = FXCODEC_PNG_GAMMA;
381 return TRUE; 395 return TRUE;
382 } 396 }
397
383 FX_BOOL CCodec_ProgressiveDecoder::PngAskScanlineBufFunc(void* pModule, 398 FX_BOOL CCodec_ProgressiveDecoder::PngAskScanlineBufFunc(void* pModule,
384 int line, 399 int line,
385 uint8_t*& src_buf) { 400 uint8_t*& src_buf) {
386 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 401 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
387 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; 402 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap;
388 if (!pDIBitmap) { 403 if (!pDIBitmap) {
389 ASSERT(false); 404 ASSERT(false);
390 return FALSE; 405 return FALSE;
391 } 406 }
392 if (line >= pCodec->m_clipBox.top && line < pCodec->m_clipBox.bottom) { 407 if (line >= pCodec->m_clipBox.top && line < pCodec->m_clipBox.bottom) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 *pDes++ = (uint8_t)((des_r) >> 16); 462 *pDes++ = (uint8_t)((des_r) >> 16);
448 *pDes = *p; 463 *pDes = *p;
449 } break; 464 } break;
450 default: 465 default:
451 return FALSE; 466 return FALSE;
452 } 467 }
453 } 468 }
454 } 469 }
455 return TRUE; 470 return TRUE;
456 } 471 }
472
457 void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz( 473 void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz(
458 CFX_DIBitmap* pDeviceBitmap, 474 CFX_DIBitmap* pDeviceBitmap,
459 int32_t des_line, 475 int32_t des_line,
460 uint8_t* src_scan, 476 uint8_t* src_scan,
461 FXCodec_Format src_format) { 477 FXCodec_Format src_format) {
462 uint8_t* des_scan = (uint8_t*)pDeviceBitmap->GetScanline(des_line); 478 uint8_t* des_scan = (uint8_t*)pDeviceBitmap->GetScanline(des_line);
463 int32_t src_Bpp = (m_SrcFormat & 0xff) >> 3; 479 int32_t src_Bpp = (m_SrcFormat & 0xff) >> 3;
464 int32_t des_Bpp = pDeviceBitmap->GetBPP() >> 3; 480 int32_t des_Bpp = pDeviceBitmap->GetBPP() >> 3;
465 int32_t src_left = m_clipBox.left; 481 int32_t src_left = m_clipBox.left;
466 int32_t des_left = m_startX; 482 int32_t des_left = m_startX;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 *des_scan++ = (uint8_t)((des_b) >> 16); 534 *des_scan++ = (uint8_t)((des_b) >> 16);
519 *des_scan++ = (uint8_t)((des_g) >> 16); 535 *des_scan++ = (uint8_t)((des_g) >> 16);
520 *des_scan++ = (uint8_t)((des_r) >> 16); 536 *des_scan++ = (uint8_t)((des_r) >> 16);
521 *des_scan++ = (uint8_t)((des_a) >> 16); 537 *des_scan++ = (uint8_t)((des_a) >> 16);
522 } break; 538 } break;
523 default: 539 default:
524 return; 540 return;
525 } 541 }
526 } 542 }
527 } 543 }
544
528 void CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc(void* pModule, 545 void CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc(void* pModule,
529 int pass, 546 int pass,
530 int line) { 547 int line) {
531 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 548 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
532 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; 549 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap;
533 ASSERT(pDIBitmap); 550 ASSERT(pDIBitmap);
534 int src_top = pCodec->m_clipBox.top; 551 int src_top = pCodec->m_clipBox.top;
535 int src_bottom = pCodec->m_clipBox.bottom; 552 int src_bottom = pCodec->m_clipBox.bottom;
536 int des_top = pCodec->m_startY; 553 int des_top = pCodec->m_startY;
537 int src_hei = pCodec->m_clipBox.Height(); 554 int src_hei = pCodec->m_clipBox.Height();
538 int des_hei = pCodec->m_sizeY; 555 int des_hei = pCodec->m_sizeY;
539 if (line >= src_top && line < src_bottom) { 556 if (line >= src_top && line < src_bottom) {
540 double scale_y = (double)des_hei / (double)src_hei; 557 double scale_y = (double)des_hei / (double)src_hei;
541 int src_row = line - src_top; 558 int src_row = line - src_top;
542 int des_row = (int)(src_row * scale_y) + des_top; 559 int des_row = (int)(src_row * scale_y) + des_top;
543 if (des_row >= des_top + des_hei) { 560 if (des_row >= des_top + des_hei) {
544 return; 561 return;
545 } 562 }
546 pCodec->PngOneOneMapResampleHorz(pDIBitmap, des_row, pCodec->m_pDecodeBuf, 563 pCodec->PngOneOneMapResampleHorz(pDIBitmap, des_row, pCodec->m_pDecodeBuf,
547 pCodec->m_SrcFormat); 564 pCodec->m_SrcFormat);
548 if (pCodec->m_SrcPassNumber == 1 && scale_y > 1.0) { 565 if (pCodec->m_SrcPassNumber == 1 && scale_y > 1.0) {
549 pCodec->ResampleVert(pDIBitmap, scale_y, des_row); 566 pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
550 return; 567 return;
551 } 568 }
552 if (pass == 6 && scale_y > 1.0) { 569 if (pass == 6 && scale_y > 1.0) {
553 pCodec->ResampleVert(pDIBitmap, scale_y, des_row); 570 pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
554 } 571 }
555 } 572 }
556 } 573 }
574
557 FX_BOOL CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule, 575 FX_BOOL CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
558 FXCODEC_STATUS& err_status) { 576 FXCODEC_STATUS& err_status) {
559 uint32_t dwSize = (uint32_t)m_pFile->GetSize(); 577 uint32_t dwSize = (uint32_t)m_pFile->GetSize();
560 if (dwSize <= m_offSet) { 578 if (dwSize <= m_offSet) {
561 return FALSE; 579 return FALSE;
562 } 580 }
563 dwSize = dwSize - m_offSet; 581 dwSize = dwSize - m_offSet;
564 uint32_t dwAvail = pGifModule->GetAvailInput(m_pGifContext, nullptr); 582 uint32_t dwAvail = pGifModule->GetAvailInput(m_pGifContext, nullptr);
565 if (dwAvail == m_SrcSize) { 583 if (dwAvail == m_SrcSize) {
566 if (dwSize > FXCODEC_BLOCK_SIZE) { 584 if (dwSize > FXCODEC_BLOCK_SIZE) {
(...skipping 16 matching lines...) Expand all
583 } 601 }
584 } 602 }
585 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) { 603 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) {
586 err_status = FXCODEC_STATUS_ERR_READ; 604 err_status = FXCODEC_STATUS_ERR_READ;
587 return FALSE; 605 return FALSE;
588 } 606 }
589 m_offSet += dwSize; 607 m_offSet += dwSize;
590 pGifModule->Input(m_pGifContext, m_pSrcBuf, dwSize + dwAvail); 608 pGifModule->Input(m_pGifContext, m_pSrcBuf, dwSize + dwAvail);
591 return TRUE; 609 return TRUE;
592 } 610 }
611
593 void CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback( 612 void CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback(
594 void* pModule, 613 void* pModule,
595 uint32_t& cur_pos) { 614 uint32_t& cur_pos) {
596 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 615 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
597 uint32_t remain_size = 616 uint32_t remain_size =
598 pCodec->m_pCodecMgr->GetGifModule()->GetAvailInput(pCodec->m_pGifContext); 617 pCodec->m_pCodecMgr->GetGifModule()->GetAvailInput(pCodec->m_pGifContext);
599 cur_pos = pCodec->m_offSet - remain_size; 618 cur_pos = pCodec->m_offSet - remain_size;
600 } 619 }
620
601 uint8_t* CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback( 621 uint8_t* CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback(
602 void* pModule, 622 void* pModule,
603 int32_t frame_num, 623 int32_t frame_num,
604 int32_t pal_size) { 624 int32_t pal_size) {
605 return FX_Alloc(uint8_t, pal_size); 625 return FX_Alloc(uint8_t, pal_size);
606 } 626 }
627
607 FX_BOOL CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback( 628 FX_BOOL CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback(
608 void* pModule, 629 void* pModule,
609 uint32_t rcd_pos, 630 uint32_t rcd_pos,
610 const FX_RECT& img_rc, 631 const FX_RECT& img_rc,
611 int32_t pal_num, 632 int32_t pal_num,
612 void* pal_ptr, 633 void* pal_ptr,
613 int32_t delay_time, 634 int32_t delay_time,
614 FX_BOOL user_input, 635 FX_BOOL user_input,
615 int32_t trans_index, 636 int32_t trans_index,
616 int32_t disposal_method, 637 int32_t disposal_method,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 for (int col = 0; col < sizeX; col++) { 707 for (int col = 0; col < sizeX; col++) {
687 FXARGB_SETDIB(pScanline, argb); 708 FXARGB_SETDIB(pScanline, argb);
688 pScanline += 4; 709 pScanline += 4;
689 } 710 }
690 break; 711 break;
691 } 712 }
692 } 713 }
693 } 714 }
694 return TRUE; 715 return TRUE;
695 } 716 }
717
696 void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule, 718 void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule,
697 int32_t row_num, 719 int32_t row_num,
698 uint8_t* row_buf) { 720 uint8_t* row_buf) {
699 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 721 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
700 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; 722 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap;
701 ASSERT(pDIBitmap); 723 ASSERT(pDIBitmap);
702 int32_t img_width = pCodec->m_GifFrameRect.Width(); 724 int32_t img_width = pCodec->m_GifFrameRect.Width();
703 if (!pDIBitmap->HasAlpha()) { 725 if (!pDIBitmap->HasAlpha()) {
704 uint8_t* byte_ptr = row_buf; 726 uint8_t* byte_ptr = row_buf;
705 for (int i = 0; i < img_width; i++) { 727 for (int i = 0; i < img_width; i++) {
(...skipping 10 matching lines...) Expand all
716 FXSYS_memset(pCodec->m_pDecodeBuf, pal_index, pCodec->m_SrcWidth); 738 FXSYS_memset(pCodec->m_pDecodeBuf, pal_index, pCodec->m_SrcWidth);
717 bool bLastPass = (row_num % 2) == 1; 739 bool bLastPass = (row_num % 2) == 1;
718 int32_t line = row_num + pCodec->m_GifFrameRect.top; 740 int32_t line = row_num + pCodec->m_GifFrameRect.top;
719 int32_t left = pCodec->m_GifFrameRect.left; 741 int32_t left = pCodec->m_GifFrameRect.left;
720 FXSYS_memcpy(pCodec->m_pDecodeBuf + left, row_buf, img_width); 742 FXSYS_memcpy(pCodec->m_pDecodeBuf + left, row_buf, img_width);
721 int src_top = pCodec->m_clipBox.top; 743 int src_top = pCodec->m_clipBox.top;
722 int src_bottom = pCodec->m_clipBox.bottom; 744 int src_bottom = pCodec->m_clipBox.bottom;
723 int des_top = pCodec->m_startY; 745 int des_top = pCodec->m_startY;
724 int src_hei = pCodec->m_clipBox.Height(); 746 int src_hei = pCodec->m_clipBox.Height();
725 int des_hei = pCodec->m_sizeY; 747 int des_hei = pCodec->m_sizeY;
726 if (line >= src_top && line < src_bottom) { 748 if (line < src_top || line >= src_bottom)
727 double scale_y = (double)des_hei / (double)src_hei; 749 return;
728 int src_row = line - src_top; 750
729 int des_row = (int)(src_row * scale_y) + des_top; 751 double scale_y = (double)des_hei / (double)src_hei;
730 if (des_row >= des_top + des_hei) { 752 int src_row = line - src_top;
731 return; 753 int des_row = (int)(src_row * scale_y) + des_top;
732 } 754 if (des_row >= des_top + des_hei)
733 pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf, 755 return;
734 pCodec->m_SrcFormat); 756
735 if (scale_y > 1.0 && 757 pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf,
736 (!pCodec->m_bInterpol || pCodec->m_SrcPassNumber == 1)) { 758 pCodec->m_SrcFormat);
737 pCodec->ResampleVert(pDIBitmap, scale_y, des_row); 759 if (scale_y > 1.0 && (!pCodec->m_bInterpol || pCodec->m_SrcPassNumber == 1)) {
738 return; 760 pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
739 } 761 return;
740 if (scale_y > 1.0) { 762 }
741 int des_bottom = des_top + pCodec->m_sizeY; 763 if (scale_y <= 1.0)
742 int des_Bpp = pDIBitmap->GetBPP() >> 3; 764 return;
743 uint32_t des_ScanOffet = pCodec->m_startX * des_Bpp; 765
744 if (des_row + (int)scale_y >= des_bottom - 1) { 766 int des_bottom = des_top + pCodec->m_sizeY;
745 uint8_t* scan_src = 767 int des_Bpp = pDIBitmap->GetBPP() >> 3;
746 (uint8_t*)pDIBitmap->GetScanline(des_row) + des_ScanOffet; 768 uint32_t des_ScanOffet = pCodec->m_startX * des_Bpp;
747 int cur_row = des_row; 769 if (des_row + (int)scale_y >= des_bottom - 1) {
748 while (++cur_row < des_bottom) { 770 uint8_t* scan_src =
749 uint8_t* scan_des = 771 (uint8_t*)pDIBitmap->GetScanline(des_row) + des_ScanOffet;
750 (uint8_t*)pDIBitmap->GetScanline(cur_row) + des_ScanOffet; 772 int cur_row = des_row;
751 uint32_t size = pCodec->m_sizeX * des_Bpp; 773 while (++cur_row < des_bottom) {
752 FXSYS_memcpy(scan_des, scan_src, size); 774 uint8_t* scan_des =
753 } 775 (uint8_t*)pDIBitmap->GetScanline(cur_row) + des_ScanOffet;
754 } 776 uint32_t size = pCodec->m_sizeX * des_Bpp;
755 if (bLastPass) { 777 FXSYS_memcpy(scan_des, scan_src, size);
756 pCodec->GifDoubleLineResampleVert(pDIBitmap, scale_y, des_row);
757 }
758 } 778 }
759 } 779 }
780 if (bLastPass)
781 pCodec->GifDoubleLineResampleVert(pDIBitmap, scale_y, des_row);
760 } 782 }
783
761 void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert( 784 void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert(
762 CFX_DIBitmap* pDeviceBitmap, 785 CFX_DIBitmap* pDeviceBitmap,
763 double scale_y, 786 double scale_y,
764 int des_row) { 787 int des_row) {
765 int des_Bpp = pDeviceBitmap->GetBPP() >> 3; 788 int des_Bpp = pDeviceBitmap->GetBPP() >> 3;
766 uint32_t des_ScanOffet = m_startX * des_Bpp; 789 uint32_t des_ScanOffet = m_startX * des_Bpp;
767 int des_top = m_startY; 790 int des_top = m_startY;
768 int des_row_1 = des_row - int(2 * scale_y); 791 int des_row_1 = des_row - static_cast<int>(2 * scale_y);
769 if (des_row_1 < des_top) { 792 des_row_1 = std::max(des_row_1, des_top);
770 des_row_1 = des_top;
771 }
772 for (; des_row_1 < des_row; des_row_1++) { 793 for (; des_row_1 < des_row; des_row_1++) {
773 uint8_t* scan_des = 794 uint8_t* scan_des =
774 (uint8_t*)pDeviceBitmap->GetScanline(des_row_1) + des_ScanOffet; 795 (uint8_t*)pDeviceBitmap->GetScanline(des_row_1) + des_ScanOffet;
775 PixelWeight* pWeight = m_WeightVert.GetPixelWeight(des_row_1 - des_top); 796 PixelWeight* pWeight = m_WeightVert.GetPixelWeight(des_row_1 - des_top);
776 const uint8_t* scan_src1 = 797 const uint8_t* scan_src1 =
777 pDeviceBitmap->GetScanline(pWeight->m_SrcStart + des_top) + 798 pDeviceBitmap->GetScanline(pWeight->m_SrcStart + des_top) +
778 des_ScanOffet; 799 des_ScanOffet;
779 const uint8_t* scan_src2 = 800 const uint8_t* scan_src2 =
780 pDeviceBitmap->GetScanline(pWeight->m_SrcEnd + des_top) + des_ScanOffet; 801 pDeviceBitmap->GetScanline(pWeight->m_SrcEnd + des_top) + des_ScanOffet;
781 for (int des_col = 0; des_col < m_sizeX; des_col++) { 802 for (int des_col = 0; des_col < m_sizeX; des_col++) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 return; 850 return;
830 } 851 }
831 } 852 }
832 } 853 }
833 int des_bottom = des_top + m_sizeY - 1; 854 int des_bottom = des_top + m_sizeY - 1;
834 if (des_row + (int)(2 * scale_y) >= des_bottom && 855 if (des_row + (int)(2 * scale_y) >= des_bottom &&
835 des_row + (int)scale_y < des_bottom) { 856 des_row + (int)scale_y < des_bottom) {
836 GifDoubleLineResampleVert(pDeviceBitmap, scale_y, des_row + (int)scale_y); 857 GifDoubleLineResampleVert(pDeviceBitmap, scale_y, des_row + (int)scale_y);
837 } 858 }
838 } 859 }
860
839 FX_BOOL CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule, 861 FX_BOOL CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule,
840 FXCODEC_STATUS& err_status) { 862 FXCODEC_STATUS& err_status) {
841 uint32_t dwSize = (uint32_t)m_pFile->GetSize(); 863 uint32_t dwSize = (uint32_t)m_pFile->GetSize();
842 if (dwSize <= m_offSet) { 864 if (dwSize <= m_offSet)
843 return FALSE; 865 return FALSE;
844 } 866
845 dwSize = dwSize - m_offSet; 867 dwSize = dwSize - m_offSet;
846 uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext, nullptr); 868 uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext, nullptr);
847 if (dwAvail == m_SrcSize) { 869 if (dwAvail == m_SrcSize) {
848 if (dwSize > FXCODEC_BLOCK_SIZE) { 870 if (dwSize > FXCODEC_BLOCK_SIZE) {
849 dwSize = FXCODEC_BLOCK_SIZE; 871 dwSize = FXCODEC_BLOCK_SIZE;
850 } 872 }
851 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) / 873 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) /
852 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE; 874 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE;
853 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize); 875 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize);
854 if (!m_pSrcBuf) { 876 if (!m_pSrcBuf) {
(...skipping 10 matching lines...) Expand all
865 } 887 }
866 } 888 }
867 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) { 889 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) {
868 err_status = FXCODEC_STATUS_ERR_READ; 890 err_status = FXCODEC_STATUS_ERR_READ;
869 return FALSE; 891 return FALSE;
870 } 892 }
871 m_offSet += dwSize; 893 m_offSet += dwSize;
872 pBmpModule->Input(m_pBmpContext, m_pSrcBuf, dwSize + dwAvail); 894 pBmpModule->Input(m_pBmpContext, m_pSrcBuf, dwSize + dwAvail);
873 return TRUE; 895 return TRUE;
874 } 896 }
897
875 FX_BOOL CCodec_ProgressiveDecoder::BmpInputImagePositionBufCallback( 898 FX_BOOL CCodec_ProgressiveDecoder::BmpInputImagePositionBufCallback(
876 void* pModule, 899 void* pModule,
877 uint32_t rcd_pos) { 900 uint32_t rcd_pos) {
878 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 901 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
879 pCodec->m_offSet = rcd_pos; 902 pCodec->m_offSet = rcd_pos;
880 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; 903 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR;
881 if (!pCodec->BmpReadMoreData(pCodec->m_pCodecMgr->GetBmpModule(), 904 return pCodec->BmpReadMoreData(pCodec->m_pCodecMgr->GetBmpModule(),
882 error_status)) { 905 error_status);
883 return FALSE;
884 }
885 return TRUE;
886 } 906 }
907
887 void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule, 908 void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule,
888 int32_t row_num, 909 int32_t row_num,
889 uint8_t* row_buf) { 910 uint8_t* row_buf) {
890 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 911 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
891 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; 912 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap;
892 ASSERT(pDIBitmap); 913 ASSERT(pDIBitmap);
893 FXSYS_memcpy(pCodec->m_pDecodeBuf, row_buf, pCodec->m_ScanlineSize); 914 FXSYS_memcpy(pCodec->m_pDecodeBuf, row_buf, pCodec->m_ScanlineSize);
894 int src_top = pCodec->m_clipBox.top; 915 int src_top = pCodec->m_clipBox.top;
895 int src_bottom = pCodec->m_clipBox.bottom; 916 int src_bottom = pCodec->m_clipBox.bottom;
896 int des_top = pCodec->m_startY; 917 int des_top = pCodec->m_startY;
897 int src_hei = pCodec->m_clipBox.Height(); 918 int src_hei = pCodec->m_clipBox.Height();
898 int des_hei = pCodec->m_sizeY; 919 int des_hei = pCodec->m_sizeY;
899 if (row_num >= src_top && row_num < src_bottom) { 920 if (row_num < src_top || row_num >= src_bottom)
900 double scale_y = (double)des_hei / (double)src_hei; 921 return;
901 int src_row = row_num - src_top; 922
902 int des_row = (int)(src_row * scale_y) + des_top; 923 double scale_y = (double)des_hei / (double)src_hei;
903 if (des_row >= des_top + des_hei) { 924 int src_row = row_num - src_top;
904 return; 925 int des_row = (int)(src_row * scale_y) + des_top;
905 } 926 if (des_row >= des_top + des_hei)
906 pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf, 927 return;
907 pCodec->m_SrcFormat); 928
908 if (scale_y > 1.0) { 929 pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf,
909 if (pCodec->m_BmpIsTopBottom || !pCodec->m_bInterpol) { 930 pCodec->m_SrcFormat);
910 pCodec->ResampleVert(pDIBitmap, scale_y, des_row); 931 if (scale_y <= 1.0)
911 return; 932 return;
912 } else { 933
913 pCodec->ResampleVertBT(pDIBitmap, scale_y, des_row); 934 if (pCodec->m_BmpIsTopBottom || !pCodec->m_bInterpol) {
914 } 935 pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
915 } 936 return;
916 } 937 }
938 pCodec->ResampleVertBT(pDIBitmap, scale_y, des_row);
917 } 939 }
940
918 void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, 941 void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap,
919 double scale_y, 942 double scale_y,
920 int des_row) { 943 int des_row) {
921 int des_Bpp = pDeviceBitmap->GetBPP() >> 3; 944 int des_Bpp = pDeviceBitmap->GetBPP() >> 3;
922 uint32_t des_ScanOffet = m_startX * des_Bpp; 945 uint32_t des_ScanOffet = m_startX * des_Bpp;
923 int des_top = m_startY; 946 int des_top = m_startY;
924 int des_bottom = m_startY + m_sizeY; 947 int des_bottom = m_startY + m_sizeY;
925 int des_row_1 = des_row + int(scale_y); 948 int des_row_1 = des_row + static_cast<int>(scale_y);
926 if (des_row_1 >= des_bottom - 1) { 949 if (des_row_1 >= des_bottom - 1) {
927 uint8_t* scan_src = 950 uint8_t* scan_src =
928 (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet; 951 (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet;
929 while (++des_row < des_bottom) { 952 while (++des_row < des_bottom) {
930 uint8_t* scan_des = 953 uint8_t* scan_des =
931 (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet; 954 (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet;
932 uint32_t size = m_sizeX * des_Bpp; 955 uint32_t size = m_sizeX * des_Bpp;
933 FXSYS_memcpy(scan_des, scan_src, size); 956 FXSYS_memcpy(scan_des, scan_src, size);
934 } 957 }
935 return; 958 return;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 *scan_des++ = (uint8_t)((des_g) >> 16); 1012 *scan_des++ = (uint8_t)((des_g) >> 16);
990 *scan_des++ = (uint8_t)((des_r) >> 16); 1013 *scan_des++ = (uint8_t)((des_r) >> 16);
991 *scan_des++ = (uint8_t)((des_a) >> 16); 1014 *scan_des++ = (uint8_t)((des_a) >> 16);
992 } break; 1015 } break;
993 default: 1016 default:
994 return; 1017 return;
995 } 1018 }
996 } 1019 }
997 } 1020 }
998 } 1021 }
1022
999 FX_BOOL CCodec_ProgressiveDecoder::DetectImageType( 1023 FX_BOOL CCodec_ProgressiveDecoder::DetectImageType(
1000 FXCODEC_IMAGE_TYPE imageType, 1024 FXCODEC_IMAGE_TYPE imageType,
1001 CFX_DIBAttribute* pAttribute) { 1025 CFX_DIBAttribute* pAttribute) {
1002 m_offSet = 0; 1026 m_offSet = 0;
1003 uint32_t size = (uint32_t)m_pFile->GetSize(); 1027 uint32_t size = (uint32_t)m_pFile->GetSize();
1004 if (size > FXCODEC_BLOCK_SIZE) { 1028 if (size > FXCODEC_BLOCK_SIZE) {
1005 size = FXCODEC_BLOCK_SIZE; 1029 size = FXCODEC_BLOCK_SIZE;
1006 } 1030 }
1007 FX_Free(m_pSrcBuf); 1031 FX_Free(m_pSrcBuf);
1008 m_pSrcBuf = FX_Alloc(uint8_t, size); 1032 m_pSrcBuf = FX_Alloc(uint8_t, size);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 m_pSrcPalette = nullptr; 1080 m_pSrcPalette = nullptr;
1057 } 1081 }
1058 return TRUE; 1082 return TRUE;
1059 } 1083 }
1060 if (m_pBmpContext) { 1084 if (m_pBmpContext) {
1061 pBmpModule->Finish(m_pBmpContext); 1085 pBmpModule->Finish(m_pBmpContext);
1062 m_pBmpContext = nullptr; 1086 m_pBmpContext = nullptr;
1063 } 1087 }
1064 m_status = FXCODEC_STATUS_ERR_FORMAT; 1088 m_status = FXCODEC_STATUS_ERR_FORMAT;
1065 return FALSE; 1089 return FALSE;
1066 } break; 1090 }
1067 case FXCODEC_IMAGE_JPG: { 1091 case FXCODEC_IMAGE_JPG: {
1068 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 1092 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
1069 if (!pJpegModule) { 1093 if (!pJpegModule) {
1070 m_status = FXCODEC_STATUS_ERR_MEMORY; 1094 m_status = FXCODEC_STATUS_ERR_MEMORY;
1071 return FALSE; 1095 return FALSE;
1072 } 1096 }
1073 m_pJpegContext = pJpegModule->Start(); 1097 m_pJpegContext = pJpegModule->Start();
1074 if (!m_pJpegContext) { 1098 if (!m_pJpegContext) {
1075 m_status = FXCODEC_STATUS_ERR_MEMORY; 1099 m_status = FXCODEC_STATUS_ERR_MEMORY;
1076 return FALSE; 1100 return FALSE;
(...skipping 22 matching lines...) Expand all
1099 m_SrcBPC = 8; 1123 m_SrcBPC = 8;
1100 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1124 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1101 return TRUE; 1125 return TRUE;
1102 } 1126 }
1103 if (m_pJpegContext) { 1127 if (m_pJpegContext) {
1104 pJpegModule->Finish(m_pJpegContext); 1128 pJpegModule->Finish(m_pJpegContext);
1105 m_pJpegContext = nullptr; 1129 m_pJpegContext = nullptr;
1106 } 1130 }
1107 m_status = FXCODEC_STATUS_ERR_FORMAT; 1131 m_status = FXCODEC_STATUS_ERR_FORMAT;
1108 return FALSE; 1132 return FALSE;
1109 } break; 1133 }
1110 case FXCODEC_IMAGE_PNG: { 1134 case FXCODEC_IMAGE_PNG: {
1111 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 1135 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
1112 if (!pPngModule) { 1136 if (!pPngModule) {
1113 m_status = FXCODEC_STATUS_ERR_MEMORY; 1137 m_status = FXCODEC_STATUS_ERR_MEMORY;
1114 return FALSE; 1138 return FALSE;
1115 } 1139 }
1116 pPngModule->ReadHeaderCallback = 1140 pPngModule->ReadHeaderCallback =
1117 CCodec_ProgressiveDecoder::PngReadHeaderFunc; 1141 CCodec_ProgressiveDecoder::PngReadHeaderFunc;
1118 pPngModule->AskScanlineBufCallback = 1142 pPngModule->AskScanlineBufCallback =
1119 CCodec_ProgressiveDecoder::PngAskScanlineBufFunc; 1143 CCodec_ProgressiveDecoder::PngAskScanlineBufFunc;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 } 1184 }
1161 ASSERT(!bResult); 1185 ASSERT(!bResult);
1162 if (m_pPngContext) { 1186 if (m_pPngContext) {
1163 pPngModule->Finish(m_pPngContext); 1187 pPngModule->Finish(m_pPngContext);
1164 m_pPngContext = nullptr; 1188 m_pPngContext = nullptr;
1165 } 1189 }
1166 if (m_SrcPassNumber == 0) { 1190 if (m_SrcPassNumber == 0) {
1167 m_status = FXCODEC_STATUS_ERR_FORMAT; 1191 m_status = FXCODEC_STATUS_ERR_FORMAT;
1168 return FALSE; 1192 return FALSE;
1169 } 1193 }
1170 } break; 1194 }
1171 case FXCODEC_IMAGE_GIF: { 1195 case FXCODEC_IMAGE_GIF: {
1172 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 1196 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
1173 if (!pGifModule) { 1197 if (!pGifModule) {
1174 m_status = FXCODEC_STATUS_ERR_MEMORY; 1198 m_status = FXCODEC_STATUS_ERR_MEMORY;
1175 return FALSE; 1199 return FALSE;
1176 } 1200 }
1177 pGifModule->RecordCurrentPositionCallback = 1201 pGifModule->RecordCurrentPositionCallback =
1178 CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback; 1202 CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback;
1179 pGifModule->AskLocalPaletteBufCallback = 1203 pGifModule->AskLocalPaletteBufCallback =
1180 CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback; 1204 CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 m_SrcBPC = 8; 1236 m_SrcBPC = 8;
1213 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1237 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1214 return TRUE; 1238 return TRUE;
1215 } 1239 }
1216 if (m_pGifContext) { 1240 if (m_pGifContext) {
1217 pGifModule->Finish(m_pGifContext); 1241 pGifModule->Finish(m_pGifContext);
1218 m_pGifContext = nullptr; 1242 m_pGifContext = nullptr;
1219 } 1243 }
1220 m_status = FXCODEC_STATUS_ERR_FORMAT; 1244 m_status = FXCODEC_STATUS_ERR_FORMAT;
1221 return FALSE; 1245 return FALSE;
1222 } break; 1246 }
1223 case FXCODEC_IMAGE_TIF: { 1247 case FXCODEC_IMAGE_TIF: {
1224 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); 1248 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
1225 if (!pTiffModule) { 1249 if (!pTiffModule) {
1226 m_status = FXCODEC_STATUS_ERR_FORMAT; 1250 m_status = FXCODEC_STATUS_ERR_FORMAT;
1227 return FALSE; 1251 return FALSE;
1228 } 1252 }
1229 m_pTiffContext = pTiffModule->CreateDecoder(m_pFile); 1253 m_pTiffContext = pTiffModule->CreateDecoder(m_pFile);
1230 if (!m_pTiffContext) { 1254 if (!m_pTiffContext) {
1231 m_status = FXCODEC_STATUS_ERR_FORMAT; 1255 m_status = FXCODEC_STATUS_ERR_FORMAT;
1232 return FALSE; 1256 return FALSE;
1233 } 1257 }
1234 int32_t frames = 0; 1258 int32_t dummy_bpc;
1235 pTiffModule->GetFrames(m_pTiffContext, frames); 1259 FX_BOOL ret = pTiffModule->LoadFrameInfo(m_pTiffContext, 0, &m_SrcWidth,
1236 uint32_t bpc; 1260 &m_SrcHeight, &m_SrcComponents,
1237 FX_BOOL ret = pTiffModule->LoadFrameInfo( 1261 &dummy_bpc, pAttribute);
1238 m_pTiffContext, 0, (uint32_t&)m_SrcWidth, (uint32_t&)m_SrcHeight,
1239 (uint32_t&)m_SrcComponents, bpc, pAttribute);
1240 m_SrcComponents = 4; 1262 m_SrcComponents = 4;
1241 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1263 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1242 if (!ret) { 1264 if (!ret) {
1243 pTiffModule->DestroyDecoder(m_pTiffContext); 1265 pTiffModule->DestroyDecoder(m_pTiffContext);
1244 (m_pTiffContext = nullptr); 1266 m_pTiffContext = nullptr;
1245 (m_status = FXCODEC_STATUS_ERR_FORMAT); 1267 m_status = FXCODEC_STATUS_ERR_FORMAT;
1246 return FALSE; 1268 return FALSE;
1247 } 1269 }
1248 } break; 1270 return TRUE;
1271 }
1249 default: 1272 default:
1250 m_status = FXCODEC_STATUS_ERR_FORMAT; 1273 m_status = FXCODEC_STATUS_ERR_FORMAT;
1251 return FALSE; 1274 return FALSE;
1252 } 1275 }
1253 return TRUE;
1254 } 1276 }
1277
1255 FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo( 1278 FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
1256 IFX_FileRead* pFile, 1279 IFX_FileRead* pFile,
1257 FXCODEC_IMAGE_TYPE imageType, 1280 FXCODEC_IMAGE_TYPE imageType,
1258 CFX_DIBAttribute* pAttribute) { 1281 CFX_DIBAttribute* pAttribute) {
1259 switch (m_status) { 1282 switch (m_status) {
1260 case FXCODEC_STATUS_FRAME_READY: 1283 case FXCODEC_STATUS_FRAME_READY:
1261 case FXCODEC_STATUS_FRAME_TOBECONTINUE: 1284 case FXCODEC_STATUS_FRAME_TOBECONTINUE:
1262 case FXCODEC_STATUS_DECODE_READY: 1285 case FXCODEC_STATUS_DECODE_READY:
1263 case FXCODEC_STATUS_DECODE_TOBECONTINUE: 1286 case FXCODEC_STATUS_DECODE_TOBECONTINUE:
1264 return FXCODEC_STATUS_ERROR; 1287 return FXCODEC_STATUS_ERROR;
(...skipping 23 matching lines...) Expand all
1288 if (DetectImageType((FXCODEC_IMAGE_TYPE)type, pAttribute)) { 1311 if (DetectImageType((FXCODEC_IMAGE_TYPE)type, pAttribute)) {
1289 m_imagType = (FXCODEC_IMAGE_TYPE)type; 1312 m_imagType = (FXCODEC_IMAGE_TYPE)type;
1290 m_status = FXCODEC_STATUS_FRAME_READY; 1313 m_status = FXCODEC_STATUS_FRAME_READY;
1291 return m_status; 1314 return m_status;
1292 } 1315 }
1293 } 1316 }
1294 m_status = FXCODEC_STATUS_ERR_FORMAT; 1317 m_status = FXCODEC_STATUS_ERR_FORMAT;
1295 m_pFile = nullptr; 1318 m_pFile = nullptr;
1296 return m_status; 1319 return m_status;
1297 } 1320 }
1321
1298 void CCodec_ProgressiveDecoder::SetClipBox(FX_RECT* clip) { 1322 void CCodec_ProgressiveDecoder::SetClipBox(FX_RECT* clip) {
1299 if (m_status != FXCODEC_STATUS_FRAME_READY) { 1323 if (m_status != FXCODEC_STATUS_FRAME_READY)
1300 return; 1324 return;
1301 } 1325
1302 if (clip->IsEmpty()) { 1326 if (clip->IsEmpty()) {
1303 m_clipBox = FX_RECT(0, 0, 0, 0); 1327 m_clipBox = FX_RECT(0, 0, 0, 0);
1304 return; 1328 return;
1305 } 1329 }
1306 if (clip->left < 0) { 1330 clip->left = std::max(clip->left, 0);
1307 clip->left = 0; 1331 clip->right = std::min(clip->right, m_SrcWidth);
1308 } 1332 clip->top = std::max(clip->top, 0);
1309 if (clip->right > m_SrcWidth) { 1333 clip->bottom = std::min(clip->bottom, m_SrcHeight);
1310 clip->right = m_SrcWidth;
1311 }
1312 if (clip->top < 0) {
1313 clip->top = 0;
1314 }
1315 if (clip->bottom > m_SrcHeight) {
1316 clip->bottom = m_SrcHeight;
1317 }
1318 if (clip->IsEmpty()) { 1334 if (clip->IsEmpty()) {
1319 m_clipBox = FX_RECT(0, 0, 0, 0); 1335 m_clipBox = FX_RECT(0, 0, 0, 0);
1320 return; 1336 return;
1321 } 1337 }
1322 m_clipBox = *clip; 1338 m_clipBox = *clip;
1323 } 1339 }
1340
1324 void CCodec_ProgressiveDecoder::GetDownScale(int& down_scale) { 1341 void CCodec_ProgressiveDecoder::GetDownScale(int& down_scale) {
1325 down_scale = 1; 1342 down_scale = 1;
1326 int ratio_w = m_clipBox.Width() / m_sizeX; 1343 int ratio_w = m_clipBox.Width() / m_sizeX;
1327 int ratio_h = m_clipBox.Height() / m_sizeY; 1344 int ratio_h = m_clipBox.Height() / m_sizeY;
1328 int ratio = (ratio_w > ratio_h) ? ratio_h : ratio_w; 1345 int ratio = (ratio_w > ratio_h) ? ratio_h : ratio_w;
1329 if (ratio >= 8) { 1346 if (ratio >= 8) {
1330 down_scale = 8; 1347 down_scale = 8;
1331 } else if (ratio >= 4) { 1348 } else if (ratio >= 4) {
1332 down_scale = 4; 1349 down_scale = 4;
1333 } else if (ratio >= 2) { 1350 } else if (ratio >= 2) {
1334 down_scale = 2; 1351 down_scale = 2;
1335 } 1352 }
1336 m_clipBox.left /= down_scale; 1353 m_clipBox.left /= down_scale;
1337 m_clipBox.right /= down_scale; 1354 m_clipBox.right /= down_scale;
1338 m_clipBox.top /= down_scale; 1355 m_clipBox.top /= down_scale;
1339 m_clipBox.bottom /= down_scale; 1356 m_clipBox.bottom /= down_scale;
1340 if (m_clipBox.right == m_clipBox.left) { 1357 if (m_clipBox.right == m_clipBox.left) {
1341 m_clipBox.right = m_clipBox.left + 1; 1358 m_clipBox.right = m_clipBox.left + 1;
1342 } 1359 }
1343 if (m_clipBox.bottom == m_clipBox.top) { 1360 if (m_clipBox.bottom == m_clipBox.top) {
1344 m_clipBox.bottom = m_clipBox.top + 1; 1361 m_clipBox.bottom = m_clipBox.top + 1;
1345 } 1362 }
1346 } 1363 }
1364
1347 void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format, 1365 void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format,
1348 FXCodec_Format src_format) { 1366 FXCodec_Format src_format) {
1349 switch (des_format) { 1367 switch (des_format) {
1350 case FXDIB_1bppMask: 1368 case FXDIB_1bppMask:
1351 case FXDIB_1bppRgb: { 1369 case FXDIB_1bppRgb: {
1352 switch (src_format) { 1370 switch (src_format) {
1353 case FXCodec_1bppGray: 1371 case FXCodec_1bppGray:
1354 m_TransMethod = 0; 1372 m_TransMethod = 0;
1355 break; 1373 break;
1356 default: 1374 default:
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 m_TransMethod = 11; 1452 m_TransMethod = 11;
1435 break; 1453 break;
1436 default: 1454 default:
1437 m_TransMethod = -1; 1455 m_TransMethod = -1;
1438 } 1456 }
1439 } break; 1457 } break;
1440 default: 1458 default:
1441 m_TransMethod = -1; 1459 m_TransMethod = -1;
1442 } 1460 }
1443 } 1461 }
1444 void _RGB2BGR(uint8_t* buffer, int width = 1) { 1462
1445 if (buffer && width > 0) {
1446 uint8_t temp;
1447 int i = 0;
1448 int j = 0;
1449 for (; i < width; i++, j += 3) {
1450 temp = buffer[j];
1451 buffer[j] = buffer[j + 2];
1452 buffer[j + 2] = temp;
1453 }
1454 }
1455 }
1456 void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap, 1463 void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap,
1457 int des_line, 1464 int des_line,
1458 uint8_t* src_scan, 1465 uint8_t* src_scan,
1459 FXCodec_Format src_format) { 1466 FXCodec_Format src_format) {
1460 int src_left = m_clipBox.left; 1467 int src_left = m_clipBox.left;
1461 int des_left = m_startX; 1468 int des_left = m_startX;
1462 uint8_t* des_scan = 1469 uint8_t* des_scan =
1463 pDeviceBitmap->GetBuffer() + des_line * pDeviceBitmap->GetPitch(); 1470 pDeviceBitmap->GetBuffer() + des_line * pDeviceBitmap->GetPitch();
1464 int src_bpp = src_format & 0xff; 1471 int src_bpp = src_format & 0xff;
1465 int des_bpp = pDeviceBitmap->GetBPP(); 1472 int des_bpp = pDeviceBitmap->GetBPP();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 *des_scan++ = (uint8_t)((des_b) >> 16); 1654 *des_scan++ = (uint8_t)((des_b) >> 16);
1648 *des_scan++ = (uint8_t)((des_g) >> 16); 1655 *des_scan++ = (uint8_t)((des_g) >> 16);
1649 *des_scan++ = (uint8_t)((des_r) >> 16); 1656 *des_scan++ = (uint8_t)((des_r) >> 16);
1650 *des_scan++ = (uint8_t)((des_alpha * 255) >> 16); 1657 *des_scan++ = (uint8_t)((des_alpha * 255) >> 16);
1651 } break; 1658 } break;
1652 default: 1659 default:
1653 return; 1660 return;
1654 } 1661 }
1655 } 1662 }
1656 } 1663 }
1664
1657 void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap, 1665 void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap,
1658 double scale_y, 1666 double scale_y,
1659 int des_row) { 1667 int des_row) {
1660 int des_Bpp = pDeviceBitmap->GetBPP() >> 3; 1668 int des_Bpp = pDeviceBitmap->GetBPP() >> 3;
1661 uint32_t des_ScanOffet = m_startX * des_Bpp; 1669 uint32_t des_ScanOffet = m_startX * des_Bpp;
1662 if (m_bInterpol) { 1670 if (m_bInterpol) {
1663 int des_top = m_startY; 1671 int des_top = m_startY;
1664 int des_row_1 = des_row - int(scale_y); 1672 int des_row_1 = des_row - static_cast<int>(scale_y);
1665 if (des_row_1 < des_top) { 1673 if (des_row_1 < des_top) {
1666 int des_bottom = des_top + m_sizeY; 1674 int des_bottom = des_top + m_sizeY;
1667 if (des_row + (int)scale_y >= des_bottom - 1) { 1675 if (des_row + (int)scale_y >= des_bottom - 1) {
1668 uint8_t* scan_src = 1676 uint8_t* scan_src =
1669 (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet; 1677 (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet;
1670 while (++des_row < des_bottom) { 1678 while (++des_row < des_bottom) {
1671 uint8_t* scan_des = 1679 uint8_t* scan_des =
1672 (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet; 1680 (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet;
1673 uint32_t size = m_sizeX * des_Bpp; 1681 uint32_t size = m_sizeX * des_Bpp;
1674 FXSYS_memcpy(scan_des, scan_src, size); 1682 FXSYS_memcpy(scan_des, scan_src, size);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 if (des_row + i >= m_startY + m_sizeY) { 1767 if (des_row + i >= m_startY + m_sizeY) {
1760 return; 1768 return;
1761 } 1769 }
1762 uint8_t* scan_des = 1770 uint8_t* scan_des =
1763 (uint8_t*)pDeviceBitmap->GetScanline(des_row + i) + des_ScanOffet; 1771 (uint8_t*)pDeviceBitmap->GetScanline(des_row + i) + des_ScanOffet;
1764 uint32_t size = m_sizeX * des_Bpp; 1772 uint32_t size = m_sizeX * des_Bpp;
1765 FXSYS_memcpy(scan_des, scan_src, size); 1773 FXSYS_memcpy(scan_des, scan_src, size);
1766 } 1774 }
1767 } 1775 }
1768 } 1776 }
1777
1769 void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap, 1778 void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap,
1770 int32_t src_line, 1779 int32_t src_line,
1771 uint8_t* src_scan, 1780 uint8_t* src_scan,
1772 FXCodec_Format src_format) { 1781 FXCodec_Format src_format) {
1773 int src_top = m_clipBox.top; 1782 int src_top = m_clipBox.top;
1774 int des_top = m_startY; 1783 int des_top = m_startY;
1775 int src_hei = m_clipBox.Height(); 1784 int src_hei = m_clipBox.Height();
1776 int des_hei = m_sizeY; 1785 int des_hei = m_sizeY;
1777 if (src_line >= src_top) { 1786 if (src_line >= src_top) {
1778 double scale_y = (double)des_hei / (double)src_hei; 1787 double scale_y = (double)des_hei / (double)src_hei;
1779 int src_row = src_line - src_top; 1788 int src_row = src_line - src_top;
1780 int des_row = (int)(src_row * scale_y) + des_top; 1789 int des_row = (int)(src_row * scale_y) + des_top;
1781 if (des_row >= des_top + des_hei) { 1790 if (des_row >= des_top + des_hei) {
1782 return; 1791 return;
1783 } 1792 }
1784 ReSampleScanline(pDeviceBitmap, des_row, m_pDecodeBuf, src_format); 1793 ReSampleScanline(pDeviceBitmap, des_row, m_pDecodeBuf, src_format);
1785 if (scale_y > 1.0) { 1794 if (scale_y > 1.0) {
1786 ResampleVert(pDeviceBitmap, scale_y, des_row); 1795 ResampleVert(pDeviceBitmap, scale_y, des_row);
1787 } 1796 }
1788 } 1797 }
1789 } 1798 }
1799
1790 FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames, 1800 FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames,
1791 IFX_Pause* pPause) { 1801 IFX_Pause* pPause) {
1792 if (!(m_status == FXCODEC_STATUS_FRAME_READY || 1802 if (!(m_status == FXCODEC_STATUS_FRAME_READY ||
1793 m_status == FXCODEC_STATUS_FRAME_TOBECONTINUE)) { 1803 m_status == FXCODEC_STATUS_FRAME_TOBECONTINUE)) {
1794 return FXCODEC_STATUS_ERROR; 1804 return FXCODEC_STATUS_ERROR;
1795 } 1805 }
1796 switch (m_imagType) { 1806 switch (m_imagType) {
1797 case FXCODEC_IMAGE_BMP: 1807 case FXCODEC_IMAGE_BMP:
1798 case FXCODEC_IMAGE_JPG: 1808 case FXCODEC_IMAGE_JPG:
1799 case FXCODEC_IMAGE_PNG: 1809 case FXCODEC_IMAGE_PNG:
1800 case FXCODEC_IMAGE_TIF: 1810 case FXCODEC_IMAGE_TIF:
1801 frames = m_FrameNumber = 1; 1811 frames = m_FrameNumber = 1;
1802 return m_status = FXCODEC_STATUS_DECODE_READY; 1812 m_status = FXCODEC_STATUS_DECODE_READY;
1813 return m_status;
1803 case FXCODEC_IMAGE_GIF: { 1814 case FXCODEC_IMAGE_GIF: {
1804 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 1815 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
1805 while (TRUE) { 1816 while (true) {
1806 int32_t readResult = 1817 int32_t readResult =
1807 pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber); 1818 pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
1808 while (readResult == 2) { 1819 while (readResult == 2) {
1809 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_READ; 1820 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_READ;
1810 if (!GifReadMoreData(pGifModule, error_status)) { 1821 if (!GifReadMoreData(pGifModule, error_status)) {
1811 return error_status; 1822 return error_status;
1812 } 1823 }
1813 if (pPause && pPause->NeedToPauseNow()) { 1824 if (pPause && pPause->NeedToPauseNow()) {
1814 return m_status = FXCODEC_STATUS_FRAME_TOBECONTINUE; 1825 m_status = FXCODEC_STATUS_FRAME_TOBECONTINUE;
1826 return m_status;
1815 } 1827 }
1816 readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber); 1828 readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
1817 } 1829 }
1818 if (readResult == 1) { 1830 if (readResult == 1) {
1819 frames = m_FrameNumber; 1831 frames = m_FrameNumber;
1820 return m_status = FXCODEC_STATUS_DECODE_READY; 1832 m_status = FXCODEC_STATUS_DECODE_READY;
1833 return m_status;
1821 } 1834 }
1822 if (m_pGifContext) { 1835 if (m_pGifContext) {
1823 pGifModule->Finish(m_pGifContext); 1836 pGifModule->Finish(m_pGifContext);
1824 m_pGifContext = nullptr; 1837 m_pGifContext = nullptr;
1825 } 1838 }
1826 return m_status = FXCODEC_STATUS_ERROR; 1839 m_status = FXCODEC_STATUS_ERROR;
1840 return m_status;
1827 } 1841 }
1828 } break; 1842 }
1829 default: 1843 default:
1830 break; 1844 return FXCODEC_STATUS_ERROR;
1831 } 1845 }
1832 return FXCODEC_STATUS_ERROR;
1833 } 1846 }
1847
1834 FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, 1848 FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
1835 int start_x, 1849 int start_x,
1836 int start_y, 1850 int start_y,
1837 int size_x, 1851 int size_x,
1838 int size_y, 1852 int size_y,
1839 int32_t frames, 1853 int32_t frames,
1840 FX_BOOL bInterpol) { 1854 FX_BOOL bInterpol) {
1841 if (m_status != FXCODEC_STATUS_DECODE_READY) 1855 if (m_status != FXCODEC_STATUS_DECODE_READY)
1842 return FXCODEC_STATUS_ERROR; 1856 return FXCODEC_STATUS_ERROR;
1843 1857
1844 if (!pDIBitmap || pDIBitmap->GetBPP() < 8 || frames < 0 || 1858 if (!pDIBitmap || pDIBitmap->GetBPP() < 8 || frames < 0 ||
1845 frames >= m_FrameNumber) { 1859 frames >= m_FrameNumber) {
1846 return FXCODEC_STATUS_ERR_PARAMS; 1860 return FXCODEC_STATUS_ERR_PARAMS;
1847 } 1861 }
1848 m_pDeviceBitmap = pDIBitmap; 1862 m_pDeviceBitmap = pDIBitmap;
1849 if (m_clipBox.IsEmpty()) { 1863 if (m_clipBox.IsEmpty())
1850 return FXCODEC_STATUS_ERR_PARAMS; 1864 return FXCODEC_STATUS_ERR_PARAMS;
1851 } 1865 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) {
1853 return FXCODEC_STATUS_ERR_PARAMS; 1866 return FXCODEC_STATUS_ERR_PARAMS;
1854 } 1867
1855 FX_RECT device_rc = 1868 FX_RECT device_rc =
1856 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y); 1869 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y);
1857 int32_t out_range_x = device_rc.right - pDIBitmap->GetWidth(); 1870 int32_t out_range_x = device_rc.right - pDIBitmap->GetWidth();
1858 int32_t out_range_y = device_rc.bottom - pDIBitmap->GetHeight(); 1871 int32_t out_range_y = device_rc.bottom - pDIBitmap->GetHeight();
1859 device_rc.Intersect( 1872 device_rc.Intersect(
1860 FX_RECT(0, 0, pDIBitmap->GetWidth(), pDIBitmap->GetHeight())); 1873 FX_RECT(0, 0, pDIBitmap->GetWidth(), pDIBitmap->GetHeight()));
1861 if (device_rc.IsEmpty()) { 1874 if (device_rc.IsEmpty())
1862 return FXCODEC_STATUS_ERR_PARAMS; 1875 return FXCODEC_STATUS_ERR_PARAMS;
1863 } 1876
1864 m_startX = device_rc.left; 1877 m_startX = device_rc.left;
1865 m_startY = device_rc.top; 1878 m_startY = device_rc.top;
1866 m_sizeX = device_rc.Width(); 1879 m_sizeX = device_rc.Width();
1867 m_sizeY = device_rc.Height(); 1880 m_sizeY = device_rc.Height();
1868 m_bInterpol = bInterpol; 1881 m_bInterpol = bInterpol;
1869 m_FrameCur = 0; 1882 m_FrameCur = 0;
1870 if (start_x < 0 || out_range_x > 0) { 1883 if (start_x < 0 || out_range_x > 0) {
1871 FX_FLOAT scaleX = (FX_FLOAT)m_clipBox.Width() / (FX_FLOAT)size_x; 1884 FX_FLOAT scaleX = (FX_FLOAT)m_clipBox.Width() / (FX_FLOAT)size_x;
1872 if (start_x < 0) { 1885 if (start_x < 0) {
1873 m_clipBox.left -= (int32_t)FXSYS_ceil((FX_FLOAT)start_x * scaleX); 1886 m_clipBox.left -= (int32_t)FXSYS_ceil((FX_FLOAT)start_x * scaleX);
(...skipping 18 matching lines...) Expand all
1892 case FXCODEC_IMAGE_JPG: { 1905 case FXCODEC_IMAGE_JPG: {
1893 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 1906 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
1894 int down_scale = 1; 1907 int down_scale = 1;
1895 GetDownScale(down_scale); 1908 GetDownScale(down_scale);
1896 FX_BOOL bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); 1909 FX_BOOL bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale);
1897 while (!bStart) { 1910 while (!bStart) {
1898 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; 1911 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR;
1899 if (!JpegReadMoreData(pJpegModule, error_status)) { 1912 if (!JpegReadMoreData(pJpegModule, error_status)) {
1900 m_pDeviceBitmap = nullptr; 1913 m_pDeviceBitmap = nullptr;
1901 m_pFile = nullptr; 1914 m_pFile = nullptr;
1902 return m_status = error_status; 1915 m_status = error_status;
1916 return m_status;
1903 } 1917 }
1904 bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); 1918 bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale);
1905 } 1919 }
1906 int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale; 1920 int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale;
1907 scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4; 1921 scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4;
1908 FX_Free(m_pDecodeBuf); 1922 FX_Free(m_pDecodeBuf);
1909 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 1923 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1910 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 1924 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1911 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, 1925 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
1912 m_clipBox.Width(), m_bInterpol); 1926 m_clipBox.Width(), m_bInterpol);
1913 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 1927 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
1914 switch (m_SrcComponents) { 1928 switch (m_SrcComponents) {
1915 case 1: 1929 case 1:
1916 m_SrcFormat = FXCodec_8bppGray; 1930 m_SrcFormat = FXCodec_8bppGray;
1917 break; 1931 break;
1918 case 3: 1932 case 3:
1919 m_SrcFormat = FXCodec_Rgb; 1933 m_SrcFormat = FXCodec_Rgb;
1920 break; 1934 break;
1921 case 4: 1935 case 4:
1922 m_SrcFormat = FXCodec_Cmyk; 1936 m_SrcFormat = FXCodec_Cmyk;
1923 break; 1937 break;
1924 } 1938 }
1925 GetTransMethod(pDIBitmap->GetFormat(), m_SrcFormat); 1939 GetTransMethod(pDIBitmap->GetFormat(), m_SrcFormat);
1926 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 1940 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
1927 } break; 1941 return m_status;
1942 }
1928 case FXCODEC_IMAGE_PNG: { 1943 case FXCODEC_IMAGE_PNG: {
1929 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 1944 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
1930 if (!pPngModule) { 1945 if (!pPngModule) {
1931 m_pDeviceBitmap = nullptr; 1946 m_pDeviceBitmap = nullptr;
1932 m_pFile = nullptr; 1947 m_pFile = nullptr;
1933 return m_status = FXCODEC_STATUS_ERR_MEMORY; 1948 m_status = FXCODEC_STATUS_ERR_MEMORY;
1949 return m_status;
1934 } 1950 }
1935 if (m_pPngContext) { 1951 if (m_pPngContext) {
1936 pPngModule->Finish(m_pPngContext); 1952 pPngModule->Finish(m_pPngContext);
1937 m_pPngContext = nullptr; 1953 m_pPngContext = nullptr;
1938 } 1954 }
1939 m_pPngContext = pPngModule->Start((void*)this); 1955 m_pPngContext = pPngModule->Start((void*)this);
1940 if (!m_pPngContext) { 1956 if (!m_pPngContext) {
1941 m_pDeviceBitmap = nullptr; 1957 m_pDeviceBitmap = nullptr;
1942 m_pFile = nullptr; 1958 m_pFile = nullptr;
1943 return m_status = FXCODEC_STATUS_ERR_MEMORY; 1959 m_status = FXCODEC_STATUS_ERR_MEMORY;
1960 return m_status;
1944 } 1961 }
1945 m_offSet = 0; 1962 m_offSet = 0;
1946 switch (m_pDeviceBitmap->GetFormat()) { 1963 switch (m_pDeviceBitmap->GetFormat()) {
1947 case FXDIB_8bppMask: 1964 case FXDIB_8bppMask:
1948 case FXDIB_8bppRgb: 1965 case FXDIB_8bppRgb:
1949 m_SrcComponents = 1; 1966 m_SrcComponents = 1;
1950 m_SrcFormat = FXCodec_8bppGray; 1967 m_SrcFormat = FXCodec_8bppGray;
1951 break; 1968 break;
1952 case FXDIB_Rgb: 1969 case FXDIB_Rgb:
1953 m_SrcComponents = 3; 1970 m_SrcComponents = 3;
1954 m_SrcFormat = FXCodec_Rgb; 1971 m_SrcFormat = FXCodec_Rgb;
1955 break; 1972 break;
1956 case FXDIB_Rgb32: 1973 case FXDIB_Rgb32:
1957 case FXDIB_Argb: 1974 case FXDIB_Argb:
1958 m_SrcComponents = 4; 1975 m_SrcComponents = 4;
1959 m_SrcFormat = FXCodec_Argb; 1976 m_SrcFormat = FXCodec_Argb;
1960 break; 1977 break;
1961 default: { 1978 default: {
1962 m_pDeviceBitmap = nullptr; 1979 m_pDeviceBitmap = nullptr;
1963 m_pFile = nullptr; 1980 m_pFile = nullptr;
1964 return m_status = FXCODEC_STATUS_ERR_PARAMS; 1981 m_status = FXCODEC_STATUS_ERR_PARAMS;
1982 return m_status;
1965 } 1983 }
1966 } 1984 }
1967 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); 1985 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
1968 int scanline_size = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; 1986 int scanline_size = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4;
1969 FX_Free(m_pDecodeBuf); 1987 FX_Free(m_pDecodeBuf);
1970 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 1988 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1971 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 1989 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1972 m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol); 1990 m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol);
1973 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 1991 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
1974 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 1992 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
1975 } break; 1993 return m_status;
1994 }
1976 case FXCODEC_IMAGE_GIF: { 1995 case FXCODEC_IMAGE_GIF: {
1977 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 1996 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
1978 if (!pGifModule) { 1997 if (!pGifModule) {
1979 m_pDeviceBitmap = nullptr; 1998 m_pDeviceBitmap = nullptr;
1980 m_pFile = nullptr; 1999 m_pFile = nullptr;
1981 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2000 m_status = FXCODEC_STATUS_ERR_MEMORY;
2001 return m_status;
1982 } 2002 }
1983 m_SrcFormat = FXCodec_8bppRgb; 2003 m_SrcFormat = FXCodec_8bppRgb;
1984 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); 2004 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
1985 int scanline_size = (m_SrcWidth + 3) / 4 * 4; 2005 int scanline_size = (m_SrcWidth + 3) / 4 * 4;
1986 FX_Free(m_pDecodeBuf); 2006 FX_Free(m_pDecodeBuf);
1987 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 2007 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1988 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 2008 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1989 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, 2009 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
1990 m_clipBox.Width(), m_bInterpol); 2010 m_clipBox.Width(), m_bInterpol);
1991 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 2011 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
1992 m_FrameCur = frames; 2012 m_FrameCur = frames;
1993 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2013 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
1994 } break; 2014 return m_status;
2015 }
1995 case FXCODEC_IMAGE_BMP: { 2016 case FXCODEC_IMAGE_BMP: {
1996 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); 2017 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
1997 if (!pBmpModule) { 2018 if (!pBmpModule) {
1998 m_pDeviceBitmap = nullptr; 2019 m_pDeviceBitmap = nullptr;
1999 m_pFile = nullptr; 2020 m_pFile = nullptr;
2000 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2021 m_status = FXCODEC_STATUS_ERR_MEMORY;
2022 return m_status;
2001 } 2023 }
2002 switch (m_SrcComponents) { 2024 switch (m_SrcComponents) {
2003 case 1: 2025 case 1:
2004 m_SrcFormat = FXCodec_8bppRgb; 2026 m_SrcFormat = FXCodec_8bppRgb;
2005 break; 2027 break;
2006 case 3: 2028 case 3:
2007 m_SrcFormat = FXCodec_Rgb; 2029 m_SrcFormat = FXCodec_Rgb;
2008 break; 2030 break;
2009 case 4: 2031 case 4:
2010 m_SrcFormat = FXCodec_Rgb32; 2032 m_SrcFormat = FXCodec_Rgb32;
2011 break; 2033 break;
2012 } 2034 }
2013 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); 2035 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
2014 m_ScanlineSize = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; 2036 m_ScanlineSize = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4;
2015 FX_Free(m_pDecodeBuf); 2037 FX_Free(m_pDecodeBuf);
2016 m_pDecodeBuf = FX_Alloc(uint8_t, m_ScanlineSize); 2038 m_pDecodeBuf = FX_Alloc(uint8_t, m_ScanlineSize);
2017 FXSYS_memset(m_pDecodeBuf, 0, m_ScanlineSize); 2039 FXSYS_memset(m_pDecodeBuf, 0, m_ScanlineSize);
2018 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, 2040 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
2019 m_clipBox.Width(), m_bInterpol); 2041 m_clipBox.Width(), m_bInterpol);
2020 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 2042 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
2021 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2043 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2022 } break; 2044 return m_status;
2045 }
2023 case FXCODEC_IMAGE_TIF: 2046 case FXCODEC_IMAGE_TIF:
2024 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2047 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2048 return m_status;
2025 default: 2049 default:
2026 break; 2050 return FXCODEC_STATUS_ERROR;
2027 } 2051 }
2028 return FXCODEC_STATUS_ERROR;
2029 } 2052 }
2053
2030 FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { 2054 FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
2031 if (m_status != FXCODEC_STATUS_DECODE_TOBECONTINUE) { 2055 if (m_status != FXCODEC_STATUS_DECODE_TOBECONTINUE)
2032 return FXCODEC_STATUS_ERROR; 2056 return FXCODEC_STATUS_ERROR;
2033 } 2057
2034 switch (m_imagType) { 2058 switch (m_imagType) {
2035 case FXCODEC_IMAGE_JPG: { 2059 case FXCODEC_IMAGE_JPG: {
2036 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 2060 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
2037 while (TRUE) { 2061 while (true) {
2038 FX_BOOL readRes = 2062 FX_BOOL readRes =
2039 pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf); 2063 pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf);
2040 while (!readRes) { 2064 while (!readRes) {
2041 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2065 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2042 if (!JpegReadMoreData(pJpegModule, error_status)) { 2066 if (!JpegReadMoreData(pJpegModule, error_status)) {
2043 m_pDeviceBitmap = nullptr; 2067 m_pDeviceBitmap = nullptr;
2044 m_pFile = nullptr; 2068 m_pFile = nullptr;
2045 return m_status = error_status; 2069 m_status = error_status;
2070 return m_status;
2046 } 2071 }
2047 readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf); 2072 readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf);
2048 } 2073 }
2049 if (m_SrcFormat == FXCodec_Rgb) { 2074 if (m_SrcFormat == FXCodec_Rgb) {
2050 int src_Bpp = (m_SrcFormat & 0xff) >> 3; 2075 int src_Bpp = (m_SrcFormat & 0xff) >> 3;
2051 _RGB2BGR(m_pDecodeBuf + m_clipBox.left * src_Bpp, m_clipBox.Width()); 2076 RGB2BGR(m_pDecodeBuf + m_clipBox.left * src_Bpp, m_clipBox.Width());
2052 } 2077 }
2053 if (m_SrcRow >= m_clipBox.bottom) { 2078 if (m_SrcRow >= m_clipBox.bottom) {
2054 m_pDeviceBitmap = nullptr; 2079 m_pDeviceBitmap = nullptr;
2055 m_pFile = nullptr; 2080 m_pFile = nullptr;
2056 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2081 m_status = FXCODEC_STATUS_DECODE_FINISH;
2082 return m_status;
2057 } 2083 }
2058 Resample(m_pDeviceBitmap, m_SrcRow, m_pDecodeBuf, m_SrcFormat); 2084 Resample(m_pDeviceBitmap, m_SrcRow, m_pDecodeBuf, m_SrcFormat);
2059 m_SrcRow++; 2085 m_SrcRow++;
2060 if (pPause && pPause->NeedToPauseNow()) { 2086 if (pPause && pPause->NeedToPauseNow()) {
2061 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2087 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2088 return m_status;
2062 } 2089 }
2063 } 2090 }
2064 } break; 2091 }
2065 case FXCODEC_IMAGE_PNG: { 2092 case FXCODEC_IMAGE_PNG: {
2066 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 2093 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
2067 while (TRUE) { 2094 while (true) {
2068 uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet; 2095 uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet;
2069 uint32_t input_size = 2096 uint32_t input_size =
2070 remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size; 2097 remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size;
2071 if (input_size == 0) { 2098 if (input_size == 0) {
2072 if (m_pPngContext) { 2099 if (m_pPngContext) {
2073 pPngModule->Finish(m_pPngContext); 2100 pPngModule->Finish(m_pPngContext);
2074 } 2101 }
2075 m_pPngContext = nullptr; 2102 m_pPngContext = nullptr;
2076 m_pDeviceBitmap = nullptr; 2103 m_pDeviceBitmap = nullptr;
2077 m_pFile = nullptr; 2104 m_pFile = nullptr;
2078 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2105 m_status = FXCODEC_STATUS_DECODE_FINISH;
2106 return m_status;
2079 } 2107 }
2080 if (m_pSrcBuf && input_size > m_SrcSize) { 2108 if (m_pSrcBuf && input_size > m_SrcSize) {
2081 FX_Free(m_pSrcBuf); 2109 FX_Free(m_pSrcBuf);
2082 m_pSrcBuf = FX_Alloc(uint8_t, input_size); 2110 m_pSrcBuf = FX_Alloc(uint8_t, input_size);
2083 FXSYS_memset(m_pSrcBuf, 0, input_size); 2111 FXSYS_memset(m_pSrcBuf, 0, input_size);
2084 m_SrcSize = input_size; 2112 m_SrcSize = input_size;
2085 } 2113 }
2086 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size); 2114 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size);
2087 if (!bResult) { 2115 if (!bResult) {
2088 m_pDeviceBitmap = nullptr; 2116 m_pDeviceBitmap = nullptr;
2089 m_pFile = nullptr; 2117 m_pFile = nullptr;
2090 return m_status = FXCODEC_STATUS_ERR_READ; 2118 m_status = FXCODEC_STATUS_ERR_READ;
2119 return m_status;
2091 } 2120 }
2092 m_offSet += input_size; 2121 m_offSet += input_size;
2093 bResult = 2122 bResult =
2094 pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, nullptr); 2123 pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, nullptr);
2095 if (!bResult) { 2124 if (!bResult) {
2096 m_pDeviceBitmap = nullptr; 2125 m_pDeviceBitmap = nullptr;
2097 m_pFile = nullptr; 2126 m_pFile = nullptr;
2098 return m_status = FXCODEC_STATUS_ERROR; 2127 m_status = FXCODEC_STATUS_ERROR;
2128 return m_status;
2099 } 2129 }
2100 if (pPause && pPause->NeedToPauseNow()) { 2130 if (pPause && pPause->NeedToPauseNow()) {
2101 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2131 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2132 return m_status;
2102 } 2133 }
2103 } 2134 }
2104 } break; 2135 }
2105 case FXCODEC_IMAGE_GIF: { 2136 case FXCODEC_IMAGE_GIF: {
2106 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 2137 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
2107 while (TRUE) { 2138 while (true) {
2108 int32_t readRes = 2139 int32_t readRes =
2109 pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr); 2140 pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
2110 while (readRes == 2) { 2141 while (readRes == 2) {
2111 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2142 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2112 if (!GifReadMoreData(pGifModule, error_status)) { 2143 if (!GifReadMoreData(pGifModule, error_status)) {
2113 m_pDeviceBitmap = nullptr; 2144 m_pDeviceBitmap = nullptr;
2114 m_pFile = nullptr; 2145 m_pFile = nullptr;
2115 return m_status = error_status; 2146 m_status = error_status;
2147 return m_status;
2116 } 2148 }
2117 if (pPause && pPause->NeedToPauseNow()) { 2149 if (pPause && pPause->NeedToPauseNow()) {
2118 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2150 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2151 return m_status;
2119 } 2152 }
2120 readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr); 2153 readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
2121 } 2154 }
2122 if (readRes == 1) { 2155 if (readRes == 1) {
2123 m_pDeviceBitmap = nullptr; 2156 m_pDeviceBitmap = nullptr;
2124 m_pFile = nullptr; 2157 m_pFile = nullptr;
2125 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2158 m_status = FXCODEC_STATUS_DECODE_FINISH;
2159 return m_status;
2126 } 2160 }
2127 m_pDeviceBitmap = nullptr; 2161 m_pDeviceBitmap = nullptr;
2128 m_pFile = nullptr; 2162 m_pFile = nullptr;
2129 return m_status = FXCODEC_STATUS_ERROR; 2163 m_status = FXCODEC_STATUS_ERROR;
2164 return m_status;
2130 } 2165 }
2131 } break; 2166 }
2132 case FXCODEC_IMAGE_BMP: { 2167 case FXCODEC_IMAGE_BMP: {
2133 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); 2168 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
2134 while (TRUE) { 2169 while (true) {
2135 int32_t readRes = pBmpModule->LoadImage(m_pBmpContext); 2170 int32_t readRes = pBmpModule->LoadImage(m_pBmpContext);
2136 while (readRes == 2) { 2171 while (readRes == 2) {
2137 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2172 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2138 if (!BmpReadMoreData(pBmpModule, error_status)) { 2173 if (!BmpReadMoreData(pBmpModule, error_status)) {
2139 m_pDeviceBitmap = nullptr; 2174 m_pDeviceBitmap = nullptr;
2140 m_pFile = nullptr; 2175 m_pFile = nullptr;
2141 return m_status = error_status; 2176 m_status = error_status;
2177 return m_status;
2142 } 2178 }
2143 if (pPause && pPause->NeedToPauseNow()) { 2179 if (pPause && pPause->NeedToPauseNow()) {
2144 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2180 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2181 return m_status;
2145 } 2182 }
2146 readRes = pBmpModule->LoadImage(m_pBmpContext); 2183 readRes = pBmpModule->LoadImage(m_pBmpContext);
2147 } 2184 }
2148 if (readRes == 1) { 2185 if (readRes == 1) {
2149 m_pDeviceBitmap = nullptr; 2186 m_pDeviceBitmap = nullptr;
2150 m_pFile = nullptr; 2187 m_pFile = nullptr;
2151 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2188 m_status = FXCODEC_STATUS_DECODE_FINISH;
2189 return m_status;
2152 } 2190 }
2153 m_pDeviceBitmap = nullptr; 2191 m_pDeviceBitmap = nullptr;
2154 m_pFile = nullptr; 2192 m_pFile = nullptr;
2155 return m_status = FXCODEC_STATUS_ERROR; 2193 m_status = FXCODEC_STATUS_ERROR;
2194 return m_status;
2156 } 2195 }
2157 } break; 2196 };
2158 case FXCODEC_IMAGE_TIF: { 2197 case FXCODEC_IMAGE_TIF: {
2159 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); 2198 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
2160 FX_BOOL ret = FALSE; 2199 FX_BOOL ret = FALSE;
2161 if (m_pDeviceBitmap->GetBPP() == 32 && 2200 if (m_pDeviceBitmap->GetBPP() == 32 &&
2162 m_pDeviceBitmap->GetWidth() == m_SrcWidth && m_SrcWidth == m_sizeX && 2201 m_pDeviceBitmap->GetWidth() == m_SrcWidth && m_SrcWidth == m_sizeX &&
2163 m_pDeviceBitmap->GetHeight() == m_SrcHeight && 2202 m_pDeviceBitmap->GetHeight() == m_SrcHeight &&
2164 m_SrcHeight == m_sizeY && m_startX == 0 && m_startY == 0 && 2203 m_SrcHeight == m_sizeY && m_startX == 0 && m_startY == 0 &&
2165 m_clipBox.left == 0 && m_clipBox.top == 0 && 2204 m_clipBox.left == 0 && m_clipBox.top == 0 &&
2166 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) { 2205 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) {
2167 ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap); 2206 ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap);
2168 m_pDeviceBitmap = nullptr; 2207 m_pDeviceBitmap = nullptr;
2169 m_pFile = nullptr; 2208 m_pFile = nullptr;
2170 if (!ret) { 2209 if (!ret) {
2171 return m_status = FXCODEC_STATUS_ERROR; 2210 m_status = FXCODEC_STATUS_ERROR;
2211 return m_status;
2172 } 2212 }
2173 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2213 m_status = FXCODEC_STATUS_DECODE_FINISH;
2174 } else { 2214 return m_status;
2175 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; 2215 }
2176 pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb); 2216
2177 if (!pDIBitmap->GetBuffer()) { 2217 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
2178 delete pDIBitmap; 2218 pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb);
2179 m_pDeviceBitmap = nullptr; 2219 if (!pDIBitmap->GetBuffer()) {
2180 m_pFile = nullptr; 2220 delete pDIBitmap;
2181 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2182 }
2183 ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap);
2184 if (!ret) {
2185 delete pDIBitmap;
2186 m_pDeviceBitmap = nullptr;
2187 m_pFile = nullptr;
2188 return m_status = FXCODEC_STATUS_ERROR;
2189 }
2190 CFX_DIBitmap* pClipBitmap =
2191 (m_clipBox.left == 0 && m_clipBox.top == 0 &&
2192 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight)
2193 ? pDIBitmap
2194 : pDIBitmap->Clone(&m_clipBox);
2195 if (pDIBitmap != pClipBitmap) {
2196 delete pDIBitmap;
2197 }
2198 if (!pClipBitmap) {
2199 m_pDeviceBitmap = nullptr;
2200 m_pFile = nullptr;
2201 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2202 }
2203 CFX_DIBitmap* pFormatBitmap = nullptr;
2204 switch (m_pDeviceBitmap->GetFormat()) {
2205 case FXDIB_8bppRgb:
2206 pFormatBitmap = new CFX_DIBitmap;
2207 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2208 pClipBitmap->GetHeight(), FXDIB_8bppRgb);
2209 break;
2210 case FXDIB_8bppMask:
2211 pFormatBitmap = new CFX_DIBitmap;
2212 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2213 pClipBitmap->GetHeight(), FXDIB_8bppMask);
2214 break;
2215 case FXDIB_Rgb:
2216 pFormatBitmap = new CFX_DIBitmap;
2217 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2218 pClipBitmap->GetHeight(), FXDIB_Rgb);
2219 break;
2220 case FXDIB_Rgb32:
2221 pFormatBitmap = new CFX_DIBitmap;
2222 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2223 pClipBitmap->GetHeight(), FXDIB_Rgb32);
2224 break;
2225 case FXDIB_Argb:
2226 pFormatBitmap = pClipBitmap;
2227 break;
2228 default:
2229 break;
2230 }
2231 switch (m_pDeviceBitmap->GetFormat()) {
2232 case FXDIB_8bppRgb:
2233 case FXDIB_8bppMask: {
2234 for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
2235 uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
2236 uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
2237 for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
2238 uint8_t _a = 255 - src_line[3];
2239 uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
2240 uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
2241 uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
2242 *des_line++ = FXRGB2GRAY(r, g, b);
2243 src_line += 4;
2244 }
2245 }
2246 } break;
2247 case FXDIB_Rgb:
2248 case FXDIB_Rgb32: {
2249 int32_t desBpp =
2250 (m_pDeviceBitmap->GetFormat() == FXDIB_Rgb) ? 3 : 4;
2251 for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
2252 uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
2253 uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
2254 for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
2255 uint8_t _a = 255 - src_line[3];
2256 uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
2257 uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
2258 uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
2259 *des_line++ = b;
2260 *des_line++ = g;
2261 *des_line++ = r;
2262 des_line += desBpp - 3;
2263 src_line += 4;
2264 }
2265 }
2266 } break;
2267 default:
2268 break;
2269 }
2270 if (pClipBitmap != pFormatBitmap) {
2271 delete pClipBitmap;
2272 }
2273 if (!pFormatBitmap) {
2274 m_pDeviceBitmap = nullptr;
2275 m_pFile = nullptr;
2276 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2277 }
2278 CFX_DIBitmap* pStrechBitmap = pFormatBitmap->StretchTo(
2279 m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
2280 delete pFormatBitmap;
2281 pFormatBitmap = nullptr;
2282 if (!pStrechBitmap) {
2283 m_pDeviceBitmap = nullptr;
2284 m_pFile = nullptr;
2285 return m_status = FXCODEC_STATUS_ERR_MEMORY;
2286 }
2287 m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
2288 pStrechBitmap, 0, 0);
2289 delete pStrechBitmap;
2290 pStrechBitmap = nullptr;
2291 m_pDeviceBitmap = nullptr; 2221 m_pDeviceBitmap = nullptr;
2292 m_pFile = nullptr; 2222 m_pFile = nullptr;
2293 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2223 m_status = FXCODEC_STATUS_ERR_MEMORY;
2224 return m_status;
2294 } 2225 }
2295 } break; 2226 ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap);
2227 if (!ret) {
2228 delete pDIBitmap;
2229 m_pDeviceBitmap = nullptr;
2230 m_pFile = nullptr;
2231 m_status = FXCODEC_STATUS_ERROR;
2232 return m_status;
2233 }
2234 CFX_DIBitmap* pClipBitmap =
2235 (m_clipBox.left == 0 && m_clipBox.top == 0 &&
2236 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight)
2237 ? pDIBitmap
2238 : pDIBitmap->Clone(&m_clipBox);
2239 if (pDIBitmap != pClipBitmap) {
2240 delete pDIBitmap;
2241 }
2242 if (!pClipBitmap) {
2243 m_pDeviceBitmap = nullptr;
2244 m_pFile = nullptr;
2245 m_status = FXCODEC_STATUS_ERR_MEMORY;
2246 return m_status;
2247 }
2248 CFX_DIBitmap* pFormatBitmap = nullptr;
2249 switch (m_pDeviceBitmap->GetFormat()) {
2250 case FXDIB_8bppRgb:
2251 pFormatBitmap = new CFX_DIBitmap;
2252 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2253 pClipBitmap->GetHeight(), FXDIB_8bppRgb);
2254 break;
2255 case FXDIB_8bppMask:
2256 pFormatBitmap = new CFX_DIBitmap;
2257 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2258 pClipBitmap->GetHeight(), FXDIB_8bppMask);
2259 break;
2260 case FXDIB_Rgb:
2261 pFormatBitmap = new CFX_DIBitmap;
2262 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2263 pClipBitmap->GetHeight(), FXDIB_Rgb);
2264 break;
2265 case FXDIB_Rgb32:
2266 pFormatBitmap = new CFX_DIBitmap;
2267 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2268 pClipBitmap->GetHeight(), FXDIB_Rgb32);
2269 break;
2270 case FXDIB_Argb:
2271 pFormatBitmap = pClipBitmap;
2272 break;
2273 default:
2274 break;
2275 }
2276 switch (m_pDeviceBitmap->GetFormat()) {
2277 case FXDIB_8bppRgb:
2278 case FXDIB_8bppMask: {
2279 for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
2280 uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
2281 uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
2282 for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
2283 uint8_t _a = 255 - src_line[3];
2284 uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
2285 uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
2286 uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
2287 *des_line++ = FXRGB2GRAY(r, g, b);
2288 src_line += 4;
2289 }
2290 }
2291 } break;
2292 case FXDIB_Rgb:
2293 case FXDIB_Rgb32: {
2294 int32_t desBpp = (m_pDeviceBitmap->GetFormat() == FXDIB_Rgb) ? 3 : 4;
2295 for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
2296 uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
2297 uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
2298 for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
2299 uint8_t _a = 255 - src_line[3];
2300 uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
2301 uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
2302 uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
2303 *des_line++ = b;
2304 *des_line++ = g;
2305 *des_line++ = r;
2306 des_line += desBpp - 3;
2307 src_line += 4;
2308 }
2309 }
2310 } break;
2311 default:
2312 break;
2313 }
2314 if (pClipBitmap != pFormatBitmap) {
2315 delete pClipBitmap;
2316 }
2317 if (!pFormatBitmap) {
2318 m_pDeviceBitmap = nullptr;
2319 m_pFile = nullptr;
2320 m_status = FXCODEC_STATUS_ERR_MEMORY;
2321 return m_status;
2322 }
2323 CFX_DIBitmap* pStrechBitmap = pFormatBitmap->StretchTo(
2324 m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
2325 delete pFormatBitmap;
2326 pFormatBitmap = nullptr;
2327 if (!pStrechBitmap) {
2328 m_pDeviceBitmap = nullptr;
2329 m_pFile = nullptr;
2330 m_status = FXCODEC_STATUS_ERR_MEMORY;
2331 return m_status;
2332 }
2333 m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
2334 pStrechBitmap, 0, 0);
2335 delete pStrechBitmap;
2336 pStrechBitmap = nullptr;
2337 m_pDeviceBitmap = nullptr;
2338 m_pFile = nullptr;
2339 m_status = FXCODEC_STATUS_DECODE_FINISH;
2340 return m_status;
2341 }
2296 default: 2342 default:
2297 break; 2343 return FXCODEC_STATUS_ERROR;
2298 } 2344 }
2299 return FXCODEC_STATUS_ERROR;
2300 } 2345 }
2346
2301 CCodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() { 2347 CCodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() {
2302 return new CCodec_ProgressiveDecoder(this); 2348 return new CCodec_ProgressiveDecoder(this);
2303 } 2349 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698