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

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: CCodec_ProgressiveDecoder cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxcodec/codec/ccodec_tiffmodule.h ('k') | core/fxcodec/codec/fx_codec_tiff.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h" 7 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h"
8 8
9 #include "core/fxcodec/include/fx_codec.h" 9 #include "core/fxcodec/include/fx_codec.h"
10 #include "core/fxge/include/fx_dib.h" 10 #include "core/fxge/include/fx_dib.h"
11 11
12 #define FXCODEC_BLOCK_SIZE 4096 12 #define FXCODEC_BLOCK_SIZE 4096
13 #define FXCODEC_PNG_GAMMA 2.2 13 #define FXCODEC_PNG_GAMMA 2.2
14 14
15 #if _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_ 15 #if _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_
16 #undef FXCODEC_PNG_GAMMA 16 #undef FXCODEC_PNG_GAMMA
Tom Sepez 2016/06/09 17:53:16 nit: can we do this with a #else instead of a def/
Lei Zhang 2016/06/09 22:00:40 Done.
17 #define FXCODEC_PNG_GAMMA 1.7 17 #define FXCODEC_PNG_GAMMA 1.7
18 #endif 18 #endif
19 19
20 namespace {
21
22 void RGB2BGR(uint8_t* buffer, int width = 1) {
23 if (buffer && width > 0) {
24 uint8_t temp;
25 int i = 0;
26 int j = 0;
27 for (; i < width; i++, j += 3) {
28 temp = buffer[j];
29 buffer[j] = buffer[j + 2];
30 buffer[j + 2] = temp;
31 }
32 }
33 }
34
35 } // namespace
36
20 void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len, 37 void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len,
21 int dest_min, 38 int dest_min,
22 int dest_max, 39 int dest_max,
23 int src_len, 40 int src_len,
24 int src_min, 41 int src_min,
25 int src_max, 42 int src_max,
26 FX_BOOL bInterpol) { 43 FX_BOOL bInterpol) {
27 if (m_pWeightTables) {
28 FX_Free(m_pWeightTables);
29 }
30 double scale, base; 44 double scale, base;
31 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; 45 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len;
32 if (dest_len < 0) { 46 if (dest_len < 0) {
33 base = (FX_FLOAT)(src_len); 47 base = (FX_FLOAT)(src_len);
34 } else { 48 } else {
35 base = 0.0f; 49 base = 0.0f;
36 } 50 }
37 m_ItemSize = 51 m_ItemSize =
38 (int)(sizeof(int) * 2 + 52 (int)(sizeof(int) * 2 +
39 sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1)); 53 sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1));
40 m_DestMin = dest_min; 54 m_DestMin = dest_min;
55 FX_Free(m_pWeightTables);
41 m_pWeightTables = FX_Alloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4); 56 m_pWeightTables = FX_Alloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4);
42 if (FXSYS_fabs((FX_FLOAT)scale) < 1.0f) { 57 if (FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
43 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) { 58 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) {
44 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel); 59 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
45 double src_pos = dest_pixel * scale + scale / 2 + base; 60 double src_pos = dest_pixel * scale + scale / 2 + base;
46 if (bInterpol) { 61 if (bInterpol) {
47 pixel_weights.m_SrcStart = 62 pixel_weights.m_SrcStart =
48 (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2); 63 (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); 64 pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2);
50 if (pixel_weights.m_SrcStart < src_min) { 65 if (pixel_weights.m_SrcStart < src_min) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 double weight = area_start >= area_end ? 0.0f : area_end - area_start; 126 double weight = area_start >= area_end ? 0.0f : area_end - area_start;
112 if (weight == 0 && j == end_i) { 127 if (weight == 0 && j == end_i) {
113 pixel_weights.m_SrcEnd--; 128 pixel_weights.m_SrcEnd--;
114 break; 129 break;
115 } 130 }
116 pixel_weights.m_Weights[j - start_i] = 131 pixel_weights.m_Weights[j - start_i] =
117 FXSYS_round((FX_FLOAT)(weight * 65536)); 132 FXSYS_round((FX_FLOAT)(weight * 65536));
118 } 133 }
119 } 134 }
120 } 135 }
136
121 void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len, 137 void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len,
122 int src_len, 138 int src_len,
123 FX_BOOL bInterpol) { 139 FX_BOOL bInterpol) {
124 if (m_pWeightTables) {
125 FX_Free(m_pWeightTables);
126 }
127 double scale = (double)dest_len / (double)src_len; 140 double scale = (double)dest_len / (double)src_len;
128 m_ItemSize = sizeof(int) * 4; 141 m_ItemSize = sizeof(int) * 4;
129 int size = dest_len * m_ItemSize + 4; 142 int size = dest_len * m_ItemSize + 4;
143 FX_Free(m_pWeightTables);
130 m_pWeightTables = FX_Alloc(uint8_t, size); 144 m_pWeightTables = FX_Alloc(uint8_t, size);
131 FXSYS_memset(m_pWeightTables, 0, size); 145 FXSYS_memset(m_pWeightTables, 0, size);
132 if (scale > 1) { 146 if (scale > 1) {
133 int pre_des_col = 0; 147 int pre_des_col = 0;
134 for (int src_col = 0; src_col < src_len; src_col++) { 148 for (int src_col = 0; src_col < src_len; src_col++) {
135 double des_col_f = src_col * scale; 149 double des_col_f = src_col * scale;
136 int des_col = FXSYS_round((FX_FLOAT)des_col_f); 150 int des_col = FXSYS_round((FX_FLOAT)des_col_f);
137 PixelWeight* pWeight = 151 PixelWeight* pWeight =
138 (PixelWeight*)(m_pWeightTables + des_col * m_ItemSize); 152 (PixelWeight*)(m_pWeightTables + des_col * m_ItemSize);
139 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col; 153 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col;
(...skipping 30 matching lines...) Expand all
170 for (int des_col = 0; des_col < dest_len; des_col++) { 184 for (int des_col = 0; des_col < dest_len; des_col++) {
171 double src_col_f = des_col / scale; 185 double src_col_f = des_col / scale;
172 int src_col = FXSYS_round((FX_FLOAT)src_col_f); 186 int src_col = FXSYS_round((FX_FLOAT)src_col_f);
173 PixelWeight* pWeight = 187 PixelWeight* pWeight =
174 (PixelWeight*)(m_pWeightTables + des_col * m_ItemSize); 188 (PixelWeight*)(m_pWeightTables + des_col * m_ItemSize);
175 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col; 189 pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col;
176 pWeight->m_Weights[0] = 65536; 190 pWeight->m_Weights[0] = 65536;
177 pWeight->m_Weights[1] = 0; 191 pWeight->m_Weights[1] = 0;
178 } 192 }
179 } 193 }
194
180 void CCodec_ProgressiveDecoder::CFXCODEC_VertTable::Calc(int dest_len, 195 void CCodec_ProgressiveDecoder::CFXCODEC_VertTable::Calc(int dest_len,
181 int src_len) { 196 int src_len) {
182 if (m_pWeightTables) {
183 FX_Free(m_pWeightTables);
184 }
185 double scale = (double)dest_len / (double)src_len; 197 double scale = (double)dest_len / (double)src_len;
186 m_ItemSize = sizeof(int) * 4; 198 m_ItemSize = sizeof(int) * 4;
187 int size = dest_len * m_ItemSize + 4; 199 int size = dest_len * m_ItemSize + 4;
200 FX_Free(m_pWeightTables);
188 m_pWeightTables = FX_Alloc(uint8_t, size); 201 m_pWeightTables = FX_Alloc(uint8_t, size);
189 FXSYS_memset(m_pWeightTables, 0, size); 202 FXSYS_memset(m_pWeightTables, 0, size);
190 if (scale > 1) { 203 if (scale <= 1) {
191 double step = 0.0;
192 int src_row = 0;
193 while (step < (double)dest_len) {
194 int start_step = (int)step;
195 step = scale * (++src_row);
196 int end_step = (int)step;
197 if (end_step >= dest_len) {
198 end_step = dest_len;
199 for (int des_row = start_step; des_row < end_step; des_row++) {
200 PixelWeight* pWeight =
201 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
202 pWeight->m_SrcStart = start_step;
203 pWeight->m_SrcEnd = start_step;
204 pWeight->m_Weights[0] = 65536;
205 pWeight->m_Weights[1] = 0;
206 }
207 return;
208 }
209 int length = end_step - start_step;
210 {
211 PixelWeight* pWeight =
212 (PixelWeight*)(m_pWeightTables + start_step * m_ItemSize);
213 pWeight->m_SrcStart = start_step;
214 pWeight->m_SrcEnd = start_step;
215 pWeight->m_Weights[0] = 65536;
216 pWeight->m_Weights[1] = 0;
217 }
218 for (int des_row = start_step + 1; des_row < end_step; des_row++) {
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 }
228 } else {
229 for (int des_row = 0; des_row < dest_len; des_row++) { 204 for (int des_row = 0; des_row < dest_len; des_row++) {
230 PixelWeight* pWeight = 205 PixelWeight* pWeight =
231 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize); 206 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
232 pWeight->m_SrcStart = des_row; 207 pWeight->m_SrcStart = des_row;
233 pWeight->m_SrcEnd = des_row; 208 pWeight->m_SrcEnd = des_row;
234 pWeight->m_Weights[0] = 65536; 209 pWeight->m_Weights[0] = 65536;
235 pWeight->m_Weights[1] = 0; 210 pWeight->m_Weights[1] = 0;
236 } 211 }
212 return;
213 }
214
215 double step = 0.0;
216 int src_row = 0;
217 while (step < (double)dest_len) {
218 int start_step = (int)step;
219 step = scale * (++src_row);
220 int end_step = (int)step;
221 if (end_step >= dest_len) {
222 end_step = dest_len;
223 for (int des_row = start_step; des_row < end_step; des_row++) {
224 PixelWeight* pWeight =
225 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
226 pWeight->m_SrcStart = start_step;
227 pWeight->m_SrcEnd = start_step;
228 pWeight->m_Weights[0] = 65536;
229 pWeight->m_Weights[1] = 0;
230 }
231 return;
232 }
233 int length = end_step - start_step;
234 {
235 PixelWeight* pWeight =
236 (PixelWeight*)(m_pWeightTables + start_step * m_ItemSize);
237 pWeight->m_SrcStart = start_step;
238 pWeight->m_SrcEnd = start_step;
239 pWeight->m_Weights[0] = 65536;
240 pWeight->m_Weights[1] = 0;
241 }
242 for (int des_row = start_step + 1; des_row < end_step; des_row++) {
243 PixelWeight* pWeight =
244 (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
245 pWeight->m_SrcStart = start_step;
246 pWeight->m_SrcEnd = end_step;
247 pWeight->m_Weights[0] = FXSYS_round((FX_FLOAT)(end_step - des_row) /
248 (FX_FLOAT)length * 65536);
249 pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0];
250 }
237 } 251 }
238 } 252 }
253
239 CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder( 254 CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder(
240 CCodec_ModuleMgr* pCodecMgr) { 255 CCodec_ModuleMgr* pCodecMgr) {
241 m_pFile = nullptr; 256 m_pFile = nullptr;
242 m_pJpegContext = nullptr; 257 m_pJpegContext = nullptr;
243 m_pPngContext = nullptr; 258 m_pPngContext = nullptr;
244 m_pGifContext = nullptr; 259 m_pGifContext = nullptr;
245 m_pBmpContext = nullptr; 260 m_pBmpContext = nullptr;
246 m_pTiffContext = nullptr; 261 m_pTiffContext = nullptr;
247 m_pCodecMgr = nullptr; 262 m_pCodecMgr = nullptr;
248 m_pSrcBuf = nullptr; 263 m_pSrcBuf = nullptr;
249 m_pDecodeBuf = nullptr; 264 m_pDecodeBuf = nullptr;
250 m_pDeviceBitmap = nullptr; 265 m_pDeviceBitmap = nullptr;
251 m_pSrcPalette = nullptr; 266 m_pSrcPalette = nullptr;
252 m_pCodecMgr = pCodecMgr; 267 m_pCodecMgr = pCodecMgr;
253 m_offSet = 0; 268 m_offSet = 0;
254 m_SrcSize = 0; 269 m_SrcSize = 0;
255 m_ScanlineSize = 0; 270 m_ScanlineSize = 0;
256 m_SrcWidth = m_SrcHeight = 0; 271 m_SrcWidth = 0;
272 m_SrcHeight = 0;
257 m_SrcComponents = 0; 273 m_SrcComponents = 0;
258 m_SrcBPC = 0; 274 m_SrcBPC = 0;
259 m_SrcPassNumber = 0; 275 m_SrcPassNumber = 0;
260 m_clipBox = FX_RECT(0, 0, 0, 0); 276 m_clipBox = FX_RECT(0, 0, 0, 0);
261 m_imagType = FXCODEC_IMAGE_UNKNOWN; 277 m_imagType = FXCODEC_IMAGE_UNKNOWN;
262 m_status = FXCODEC_STATUS_DECODE_FINISH; 278 m_status = FXCODEC_STATUS_DECODE_FINISH;
263 m_TransMethod = -1; 279 m_TransMethod = -1;
264 m_SrcRow = 0; 280 m_SrcRow = 0;
265 m_SrcFormat = FXCodec_Invalid; 281 m_SrcFormat = FXCodec_Invalid;
266 m_bInterpol = TRUE; 282 m_bInterpol = TRUE;
267 m_FrameNumber = 0; 283 m_FrameNumber = 0;
268 m_FrameCur = 0; 284 m_FrameCur = 0;
269 m_SrcPaletteNumber = 0; 285 m_SrcPaletteNumber = 0;
270 m_GifPltNumber = 0; 286 m_GifPltNumber = 0;
271 m_GifBgIndex = 0; 287 m_GifBgIndex = 0;
272 m_pGifPalette = nullptr; 288 m_pGifPalette = nullptr;
273 m_GifTransIndex = -1; 289 m_GifTransIndex = -1;
274 m_GifFrameRect = FX_RECT(0, 0, 0, 0); 290 m_GifFrameRect = FX_RECT(0, 0, 0, 0);
275 m_BmpIsTopBottom = FALSE; 291 m_BmpIsTopBottom = FALSE;
276 } 292 }
293
277 CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() { 294 CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() {
278 m_pFile = nullptr; 295 m_pFile = nullptr;
279 if (m_pJpegContext) { 296 if (m_pJpegContext)
280 m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext); 297 m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext);
281 } 298 if (m_pPngContext)
282 if (m_pPngContext) {
283 m_pCodecMgr->GetPngModule()->Finish(m_pPngContext); 299 m_pCodecMgr->GetPngModule()->Finish(m_pPngContext);
284 } 300 if (m_pGifContext)
285 if (m_pGifContext) {
286 m_pCodecMgr->GetGifModule()->Finish(m_pGifContext); 301 m_pCodecMgr->GetGifModule()->Finish(m_pGifContext);
287 } 302 if (m_pBmpContext)
288 if (m_pBmpContext) {
289 m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext); 303 m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext);
290 } 304 if (m_pTiffContext)
291 if (m_pTiffContext) {
292 m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext); 305 m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext);
293 }
294 FX_Free(m_pSrcBuf); 306 FX_Free(m_pSrcBuf);
295 FX_Free(m_pDecodeBuf); 307 FX_Free(m_pDecodeBuf);
296 FX_Free(m_pSrcPalette); 308 FX_Free(m_pSrcPalette);
297 } 309 }
310
298 FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData( 311 FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData(
299 CCodec_JpegModule* pJpegModule, 312 CCodec_JpegModule* pJpegModule,
300 FXCODEC_STATUS& err_status) { 313 FXCODEC_STATUS& err_status) {
301 uint32_t dwSize = (uint32_t)m_pFile->GetSize(); 314 uint32_t dwSize = (uint32_t)m_pFile->GetSize();
302 if (dwSize <= m_offSet) { 315 if (dwSize <= m_offSet) {
303 return FALSE; 316 return FALSE;
304 } 317 }
305 dwSize = dwSize - m_offSet; 318 dwSize = dwSize - m_offSet;
306 uint32_t dwAvail = pJpegModule->GetAvailInput(m_pJpegContext, nullptr); 319 uint32_t dwAvail = pJpegModule->GetAvailInput(m_pJpegContext, nullptr);
307 if (dwAvail == m_SrcSize) { 320 if (dwAvail == m_SrcSize) {
(...skipping 17 matching lines...) Expand all
325 } 338 }
326 } 339 }
327 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) { 340 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) {
328 err_status = FXCODEC_STATUS_ERR_READ; 341 err_status = FXCODEC_STATUS_ERR_READ;
329 return FALSE; 342 return FALSE;
330 } 343 }
331 m_offSet += dwSize; 344 m_offSet += dwSize;
332 pJpegModule->Input(m_pJpegContext, m_pSrcBuf, dwSize + dwAvail); 345 pJpegModule->Input(m_pJpegContext, m_pSrcBuf, dwSize + dwAvail);
333 return TRUE; 346 return TRUE;
334 } 347 }
348
335 FX_BOOL CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule, 349 FX_BOOL CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule,
336 int width, 350 int width,
337 int height, 351 int height,
338 int bpc, 352 int bpc,
339 int pass, 353 int pass,
340 int* color_type, 354 int* color_type,
341 double* gamma) { 355 double* gamma) {
342 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 356 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
343 if (!pCodec->m_pDeviceBitmap) { 357 if (!pCodec->m_pDeviceBitmap) {
344 pCodec->m_SrcWidth = width; 358 pCodec->m_SrcWidth = width;
(...skipping 28 matching lines...) Expand all
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 - int(2 * scale_y);
769 if (des_row_1 < des_top) { 792 if (des_row_1 < des_top) {
770 des_row_1 = des_top; 793 des_row_1 = des_top;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 return; 852 return;
830 } 853 }
831 } 854 }
832 } 855 }
833 int des_bottom = des_top + m_sizeY - 1; 856 int des_bottom = des_top + m_sizeY - 1;
834 if (des_row + (int)(2 * scale_y) >= des_bottom && 857 if (des_row + (int)(2 * scale_y) >= des_bottom &&
835 des_row + (int)scale_y < des_bottom) { 858 des_row + (int)scale_y < des_bottom) {
836 GifDoubleLineResampleVert(pDeviceBitmap, scale_y, des_row + (int)scale_y); 859 GifDoubleLineResampleVert(pDeviceBitmap, scale_y, des_row + (int)scale_y);
837 } 860 }
838 } 861 }
862
839 FX_BOOL CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule, 863 FX_BOOL CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule,
840 FXCODEC_STATUS& err_status) { 864 FXCODEC_STATUS& err_status) {
841 uint32_t dwSize = (uint32_t)m_pFile->GetSize(); 865 uint32_t dwSize = (uint32_t)m_pFile->GetSize();
842 if (dwSize <= m_offSet) { 866 if (dwSize <= m_offSet)
843 return FALSE; 867 return FALSE;
844 } 868
845 dwSize = dwSize - m_offSet; 869 dwSize = dwSize - m_offSet;
846 uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext, nullptr); 870 uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext, nullptr);
847 if (dwAvail == m_SrcSize) { 871 if (dwAvail == m_SrcSize) {
848 if (dwSize > FXCODEC_BLOCK_SIZE) { 872 if (dwSize > FXCODEC_BLOCK_SIZE) {
849 dwSize = FXCODEC_BLOCK_SIZE; 873 dwSize = FXCODEC_BLOCK_SIZE;
850 } 874 }
851 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) / 875 m_SrcSize = (dwSize + dwAvail + FXCODEC_BLOCK_SIZE - 1) /
852 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE; 876 FXCODEC_BLOCK_SIZE * FXCODEC_BLOCK_SIZE;
853 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize); 877 m_pSrcBuf = FX_Realloc(uint8_t, m_pSrcBuf, m_SrcSize);
854 if (!m_pSrcBuf) { 878 if (!m_pSrcBuf) {
(...skipping 10 matching lines...) Expand all
865 } 889 }
866 } 890 }
867 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) { 891 if (!m_pFile->ReadBlock(m_pSrcBuf + dwAvail, m_offSet, dwSize)) {
868 err_status = FXCODEC_STATUS_ERR_READ; 892 err_status = FXCODEC_STATUS_ERR_READ;
869 return FALSE; 893 return FALSE;
870 } 894 }
871 m_offSet += dwSize; 895 m_offSet += dwSize;
872 pBmpModule->Input(m_pBmpContext, m_pSrcBuf, dwSize + dwAvail); 896 pBmpModule->Input(m_pBmpContext, m_pSrcBuf, dwSize + dwAvail);
873 return TRUE; 897 return TRUE;
874 } 898 }
899
875 FX_BOOL CCodec_ProgressiveDecoder::BmpInputImagePositionBufCallback( 900 FX_BOOL CCodec_ProgressiveDecoder::BmpInputImagePositionBufCallback(
876 void* pModule, 901 void* pModule,
877 uint32_t rcd_pos) { 902 uint32_t rcd_pos) {
878 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 903 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
879 pCodec->m_offSet = rcd_pos; 904 pCodec->m_offSet = rcd_pos;
880 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; 905 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR;
881 if (!pCodec->BmpReadMoreData(pCodec->m_pCodecMgr->GetBmpModule(), 906 return pCodec->BmpReadMoreData(pCodec->m_pCodecMgr->GetBmpModule(),
882 error_status)) { 907 error_status);
883 return FALSE;
884 }
885 return TRUE;
886 } 908 }
909
887 void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule, 910 void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule,
888 int32_t row_num, 911 int32_t row_num,
889 uint8_t* row_buf) { 912 uint8_t* row_buf) {
890 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule; 913 CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
891 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap; 914 CFX_DIBitmap* pDIBitmap = pCodec->m_pDeviceBitmap;
892 ASSERT(pDIBitmap); 915 ASSERT(pDIBitmap);
893 FXSYS_memcpy(pCodec->m_pDecodeBuf, row_buf, pCodec->m_ScanlineSize); 916 FXSYS_memcpy(pCodec->m_pDecodeBuf, row_buf, pCodec->m_ScanlineSize);
894 int src_top = pCodec->m_clipBox.top; 917 int src_top = pCodec->m_clipBox.top;
895 int src_bottom = pCodec->m_clipBox.bottom; 918 int src_bottom = pCodec->m_clipBox.bottom;
896 int des_top = pCodec->m_startY; 919 int des_top = pCodec->m_startY;
897 int src_hei = pCodec->m_clipBox.Height(); 920 int src_hei = pCodec->m_clipBox.Height();
898 int des_hei = pCodec->m_sizeY; 921 int des_hei = pCodec->m_sizeY;
899 if (row_num >= src_top && row_num < src_bottom) { 922 if (row_num < src_top || row_num >= src_bottom)
900 double scale_y = (double)des_hei / (double)src_hei; 923 return;
901 int src_row = row_num - src_top; 924
902 int des_row = (int)(src_row * scale_y) + des_top; 925 double scale_y = (double)des_hei / (double)src_hei;
903 if (des_row >= des_top + des_hei) { 926 int src_row = row_num - src_top;
904 return; 927 int des_row = (int)(src_row * scale_y) + des_top;
905 } 928 if (des_row >= des_top + des_hei)
906 pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf, 929 return;
907 pCodec->m_SrcFormat); 930
908 if (scale_y > 1.0) { 931 pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf,
909 if (pCodec->m_BmpIsTopBottom || !pCodec->m_bInterpol) { 932 pCodec->m_SrcFormat);
910 pCodec->ResampleVert(pDIBitmap, scale_y, des_row); 933 if (scale_y <= 1.0)
911 return; 934 return;
912 } else { 935
913 pCodec->ResampleVertBT(pDIBitmap, scale_y, des_row); 936 if (pCodec->m_BmpIsTopBottom || !pCodec->m_bInterpol) {
914 } 937 pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
915 } 938 return;
916 } 939 }
940 pCodec->ResampleVertBT(pDIBitmap, scale_y, des_row);
917 } 941 }
942
918 void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, 943 void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap,
919 double scale_y, 944 double scale_y,
920 int des_row) { 945 int des_row) {
921 int des_Bpp = pDeviceBitmap->GetBPP() >> 3; 946 int des_Bpp = pDeviceBitmap->GetBPP() >> 3;
922 uint32_t des_ScanOffet = m_startX * des_Bpp; 947 uint32_t des_ScanOffet = m_startX * des_Bpp;
923 int des_top = m_startY; 948 int des_top = m_startY;
924 int des_bottom = m_startY + m_sizeY; 949 int des_bottom = m_startY + m_sizeY;
925 int des_row_1 = des_row + int(scale_y); 950 int des_row_1 = des_row + int(scale_y);
926 if (des_row_1 >= des_bottom - 1) { 951 if (des_row_1 >= des_bottom - 1) {
927 uint8_t* scan_src = 952 uint8_t* scan_src =
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 *scan_des++ = (uint8_t)((des_g) >> 16); 1014 *scan_des++ = (uint8_t)((des_g) >> 16);
990 *scan_des++ = (uint8_t)((des_r) >> 16); 1015 *scan_des++ = (uint8_t)((des_r) >> 16);
991 *scan_des++ = (uint8_t)((des_a) >> 16); 1016 *scan_des++ = (uint8_t)((des_a) >> 16);
992 } break; 1017 } break;
993 default: 1018 default:
994 return; 1019 return;
995 } 1020 }
996 } 1021 }
997 } 1022 }
998 } 1023 }
1024
999 FX_BOOL CCodec_ProgressiveDecoder::DetectImageType( 1025 FX_BOOL CCodec_ProgressiveDecoder::DetectImageType(
1000 FXCODEC_IMAGE_TYPE imageType, 1026 FXCODEC_IMAGE_TYPE imageType,
1001 CFX_DIBAttribute* pAttribute) { 1027 CFX_DIBAttribute* pAttribute) {
1002 m_offSet = 0; 1028 m_offSet = 0;
1003 uint32_t size = (uint32_t)m_pFile->GetSize(); 1029 uint32_t size = (uint32_t)m_pFile->GetSize();
1004 if (size > FXCODEC_BLOCK_SIZE) { 1030 if (size > FXCODEC_BLOCK_SIZE) {
1005 size = FXCODEC_BLOCK_SIZE; 1031 size = FXCODEC_BLOCK_SIZE;
1006 } 1032 }
1007 FX_Free(m_pSrcBuf); 1033 FX_Free(m_pSrcBuf);
1008 m_pSrcBuf = FX_Alloc(uint8_t, size); 1034 m_pSrcBuf = FX_Alloc(uint8_t, size);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 m_pSrcPalette = nullptr; 1082 m_pSrcPalette = nullptr;
1057 } 1083 }
1058 return TRUE; 1084 return TRUE;
1059 } 1085 }
1060 if (m_pBmpContext) { 1086 if (m_pBmpContext) {
1061 pBmpModule->Finish(m_pBmpContext); 1087 pBmpModule->Finish(m_pBmpContext);
1062 m_pBmpContext = nullptr; 1088 m_pBmpContext = nullptr;
1063 } 1089 }
1064 m_status = FXCODEC_STATUS_ERR_FORMAT; 1090 m_status = FXCODEC_STATUS_ERR_FORMAT;
1065 return FALSE; 1091 return FALSE;
1066 } break; 1092 }
1067 case FXCODEC_IMAGE_JPG: { 1093 case FXCODEC_IMAGE_JPG: {
1068 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 1094 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
1069 if (!pJpegModule) { 1095 if (!pJpegModule) {
1070 m_status = FXCODEC_STATUS_ERR_MEMORY; 1096 m_status = FXCODEC_STATUS_ERR_MEMORY;
1071 return FALSE; 1097 return FALSE;
1072 } 1098 }
1073 m_pJpegContext = pJpegModule->Start(); 1099 m_pJpegContext = pJpegModule->Start();
1074 if (!m_pJpegContext) { 1100 if (!m_pJpegContext) {
1075 m_status = FXCODEC_STATUS_ERR_MEMORY; 1101 m_status = FXCODEC_STATUS_ERR_MEMORY;
1076 return FALSE; 1102 return FALSE;
(...skipping 22 matching lines...) Expand all
1099 m_SrcBPC = 8; 1125 m_SrcBPC = 8;
1100 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1126 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1101 return TRUE; 1127 return TRUE;
1102 } 1128 }
1103 if (m_pJpegContext) { 1129 if (m_pJpegContext) {
1104 pJpegModule->Finish(m_pJpegContext); 1130 pJpegModule->Finish(m_pJpegContext);
1105 m_pJpegContext = nullptr; 1131 m_pJpegContext = nullptr;
1106 } 1132 }
1107 m_status = FXCODEC_STATUS_ERR_FORMAT; 1133 m_status = FXCODEC_STATUS_ERR_FORMAT;
1108 return FALSE; 1134 return FALSE;
1109 } break; 1135 }
1110 case FXCODEC_IMAGE_PNG: { 1136 case FXCODEC_IMAGE_PNG: {
1111 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 1137 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
1112 if (!pPngModule) { 1138 if (!pPngModule) {
1113 m_status = FXCODEC_STATUS_ERR_MEMORY; 1139 m_status = FXCODEC_STATUS_ERR_MEMORY;
1114 return FALSE; 1140 return FALSE;
1115 } 1141 }
1116 pPngModule->ReadHeaderCallback = 1142 pPngModule->ReadHeaderCallback =
1117 CCodec_ProgressiveDecoder::PngReadHeaderFunc; 1143 CCodec_ProgressiveDecoder::PngReadHeaderFunc;
1118 pPngModule->AskScanlineBufCallback = 1144 pPngModule->AskScanlineBufCallback =
1119 CCodec_ProgressiveDecoder::PngAskScanlineBufFunc; 1145 CCodec_ProgressiveDecoder::PngAskScanlineBufFunc;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 } 1186 }
1161 ASSERT(!bResult); 1187 ASSERT(!bResult);
1162 if (m_pPngContext) { 1188 if (m_pPngContext) {
1163 pPngModule->Finish(m_pPngContext); 1189 pPngModule->Finish(m_pPngContext);
1164 m_pPngContext = nullptr; 1190 m_pPngContext = nullptr;
1165 } 1191 }
1166 if (m_SrcPassNumber == 0) { 1192 if (m_SrcPassNumber == 0) {
1167 m_status = FXCODEC_STATUS_ERR_FORMAT; 1193 m_status = FXCODEC_STATUS_ERR_FORMAT;
1168 return FALSE; 1194 return FALSE;
1169 } 1195 }
1170 } break; 1196 }
Tom Sepez 2016/06/09 17:53:16 still need a break here, the return above is condi
Lei Zhang 2016/06/09 22:00:40 Whoops.
1171 case FXCODEC_IMAGE_GIF: { 1197 case FXCODEC_IMAGE_GIF: {
1172 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 1198 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
1173 if (!pGifModule) { 1199 if (!pGifModule) {
1174 m_status = FXCODEC_STATUS_ERR_MEMORY; 1200 m_status = FXCODEC_STATUS_ERR_MEMORY;
1175 return FALSE; 1201 return FALSE;
1176 } 1202 }
1177 pGifModule->RecordCurrentPositionCallback = 1203 pGifModule->RecordCurrentPositionCallback =
1178 CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback; 1204 CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback;
1179 pGifModule->AskLocalPaletteBufCallback = 1205 pGifModule->AskLocalPaletteBufCallback =
1180 CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback; 1206 CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 m_SrcBPC = 8; 1238 m_SrcBPC = 8;
1213 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1239 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1214 return TRUE; 1240 return TRUE;
1215 } 1241 }
1216 if (m_pGifContext) { 1242 if (m_pGifContext) {
1217 pGifModule->Finish(m_pGifContext); 1243 pGifModule->Finish(m_pGifContext);
1218 m_pGifContext = nullptr; 1244 m_pGifContext = nullptr;
1219 } 1245 }
1220 m_status = FXCODEC_STATUS_ERR_FORMAT; 1246 m_status = FXCODEC_STATUS_ERR_FORMAT;
1221 return FALSE; 1247 return FALSE;
1222 } break; 1248 }
1223 case FXCODEC_IMAGE_TIF: { 1249 case FXCODEC_IMAGE_TIF: {
1224 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); 1250 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
1225 if (!pTiffModule) { 1251 if (!pTiffModule) {
1226 m_status = FXCODEC_STATUS_ERR_FORMAT; 1252 m_status = FXCODEC_STATUS_ERR_FORMAT;
1227 return FALSE; 1253 return FALSE;
1228 } 1254 }
1229 m_pTiffContext = pTiffModule->CreateDecoder(m_pFile); 1255 m_pTiffContext = pTiffModule->CreateDecoder(m_pFile);
1230 if (!m_pTiffContext) { 1256 if (!m_pTiffContext) {
1231 m_status = FXCODEC_STATUS_ERR_FORMAT; 1257 m_status = FXCODEC_STATUS_ERR_FORMAT;
1232 return FALSE; 1258 return FALSE;
1233 } 1259 }
1234 int32_t frames = 0; 1260 int32_t dummy_bpc;
1235 pTiffModule->GetFrames(m_pTiffContext, frames); 1261 FX_BOOL ret = pTiffModule->LoadFrameInfo(m_pTiffContext, 0, &m_SrcWidth,
1236 uint32_t bpc; 1262 &m_SrcHeight, &m_SrcComponents,
1237 FX_BOOL ret = pTiffModule->LoadFrameInfo( 1263 &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; 1264 m_SrcComponents = 4;
1241 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight); 1265 m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
1242 if (!ret) { 1266 if (!ret) {
1243 pTiffModule->DestroyDecoder(m_pTiffContext); 1267 pTiffModule->DestroyDecoder(m_pTiffContext);
1244 (m_pTiffContext = nullptr); 1268 m_pTiffContext = nullptr;
1245 (m_status = FXCODEC_STATUS_ERR_FORMAT); 1269 m_status = FXCODEC_STATUS_ERR_FORMAT;
1246 return FALSE; 1270 return FALSE;
1247 } 1271 }
1248 } break; 1272 return TRUE;
1273 }
1249 default: 1274 default:
1250 m_status = FXCODEC_STATUS_ERR_FORMAT; 1275 m_status = FXCODEC_STATUS_ERR_FORMAT;
1251 return FALSE; 1276 return FALSE;
1252 } 1277 }
1253 return TRUE;
1254 } 1278 }
1279
1255 FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo( 1280 FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
1256 IFX_FileRead* pFile, 1281 IFX_FileRead* pFile,
1257 FXCODEC_IMAGE_TYPE imageType, 1282 FXCODEC_IMAGE_TYPE imageType,
1258 CFX_DIBAttribute* pAttribute) { 1283 CFX_DIBAttribute* pAttribute) {
1259 switch (m_status) { 1284 switch (m_status) {
1260 case FXCODEC_STATUS_FRAME_READY: 1285 case FXCODEC_STATUS_FRAME_READY:
1261 case FXCODEC_STATUS_FRAME_TOBECONTINUE: 1286 case FXCODEC_STATUS_FRAME_TOBECONTINUE:
1262 case FXCODEC_STATUS_DECODE_READY: 1287 case FXCODEC_STATUS_DECODE_READY:
1263 case FXCODEC_STATUS_DECODE_TOBECONTINUE: 1288 case FXCODEC_STATUS_DECODE_TOBECONTINUE:
1264 return FXCODEC_STATUS_ERROR; 1289 return FXCODEC_STATUS_ERROR;
(...skipping 23 matching lines...) Expand all
1288 if (DetectImageType((FXCODEC_IMAGE_TYPE)type, pAttribute)) { 1313 if (DetectImageType((FXCODEC_IMAGE_TYPE)type, pAttribute)) {
1289 m_imagType = (FXCODEC_IMAGE_TYPE)type; 1314 m_imagType = (FXCODEC_IMAGE_TYPE)type;
1290 m_status = FXCODEC_STATUS_FRAME_READY; 1315 m_status = FXCODEC_STATUS_FRAME_READY;
1291 return m_status; 1316 return m_status;
1292 } 1317 }
1293 } 1318 }
1294 m_status = FXCODEC_STATUS_ERR_FORMAT; 1319 m_status = FXCODEC_STATUS_ERR_FORMAT;
1295 m_pFile = nullptr; 1320 m_pFile = nullptr;
1296 return m_status; 1321 return m_status;
1297 } 1322 }
1323
1298 void CCodec_ProgressiveDecoder::SetClipBox(FX_RECT* clip) { 1324 void CCodec_ProgressiveDecoder::SetClipBox(FX_RECT* clip) {
1299 if (m_status != FXCODEC_STATUS_FRAME_READY) { 1325 if (m_status != FXCODEC_STATUS_FRAME_READY)
1300 return; 1326 return;
1301 } 1327
1302 if (clip->IsEmpty()) { 1328 if (clip->IsEmpty()) {
1303 m_clipBox = FX_RECT(0, 0, 0, 0); 1329 m_clipBox = FX_RECT(0, 0, 0, 0);
1304 return; 1330 return;
1305 } 1331 }
1306 if (clip->left < 0) { 1332 clip->left = std::max(clip->left, 0);
1307 clip->left = 0; 1333 clip->right = std::min(clip->right, m_SrcWidth);
1308 } 1334 clip->top = std::max(clip->top, 0);
1309 if (clip->right > m_SrcWidth) { 1335 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()) { 1336 if (clip->IsEmpty()) {
1319 m_clipBox = FX_RECT(0, 0, 0, 0); 1337 m_clipBox = FX_RECT(0, 0, 0, 0);
1320 return; 1338 return;
1321 } 1339 }
1322 m_clipBox = *clip; 1340 m_clipBox = *clip;
1323 } 1341 }
1342
1324 void CCodec_ProgressiveDecoder::GetDownScale(int& down_scale) { 1343 void CCodec_ProgressiveDecoder::GetDownScale(int& down_scale) {
1325 down_scale = 1; 1344 down_scale = 1;
1326 int ratio_w = m_clipBox.Width() / m_sizeX; 1345 int ratio_w = m_clipBox.Width() / m_sizeX;
1327 int ratio_h = m_clipBox.Height() / m_sizeY; 1346 int ratio_h = m_clipBox.Height() / m_sizeY;
1328 int ratio = (ratio_w > ratio_h) ? ratio_h : ratio_w; 1347 int ratio = (ratio_w > ratio_h) ? ratio_h : ratio_w;
1329 if (ratio >= 8) { 1348 if (ratio >= 8) {
1330 down_scale = 8; 1349 down_scale = 8;
1331 } else if (ratio >= 4) { 1350 } else if (ratio >= 4) {
1332 down_scale = 4; 1351 down_scale = 4;
1333 } else if (ratio >= 2) { 1352 } else if (ratio >= 2) {
1334 down_scale = 2; 1353 down_scale = 2;
1335 } 1354 }
1336 m_clipBox.left /= down_scale; 1355 m_clipBox.left /= down_scale;
1337 m_clipBox.right /= down_scale; 1356 m_clipBox.right /= down_scale;
1338 m_clipBox.top /= down_scale; 1357 m_clipBox.top /= down_scale;
1339 m_clipBox.bottom /= down_scale; 1358 m_clipBox.bottom /= down_scale;
1340 if (m_clipBox.right == m_clipBox.left) { 1359 if (m_clipBox.right == m_clipBox.left) {
1341 m_clipBox.right = m_clipBox.left + 1; 1360 m_clipBox.right = m_clipBox.left + 1;
1342 } 1361 }
1343 if (m_clipBox.bottom == m_clipBox.top) { 1362 if (m_clipBox.bottom == m_clipBox.top) {
1344 m_clipBox.bottom = m_clipBox.top + 1; 1363 m_clipBox.bottom = m_clipBox.top + 1;
1345 } 1364 }
1346 } 1365 }
1366
1347 void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format, 1367 void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format,
1348 FXCodec_Format src_format) { 1368 FXCodec_Format src_format) {
1349 switch (des_format) { 1369 switch (des_format) {
1350 case FXDIB_1bppMask: 1370 case FXDIB_1bppMask:
1351 case FXDIB_1bppRgb: { 1371 case FXDIB_1bppRgb: {
1352 switch (src_format) { 1372 switch (src_format) {
1353 case FXCodec_1bppGray: 1373 case FXCodec_1bppGray:
1354 m_TransMethod = 0; 1374 m_TransMethod = 0;
1355 break; 1375 break;
1356 default: 1376 default:
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 m_TransMethod = 11; 1454 m_TransMethod = 11;
1435 break; 1455 break;
1436 default: 1456 default:
1437 m_TransMethod = -1; 1457 m_TransMethod = -1;
1438 } 1458 }
1439 } break; 1459 } break;
1440 default: 1460 default:
1441 m_TransMethod = -1; 1461 m_TransMethod = -1;
1442 } 1462 }
1443 } 1463 }
1444 void _RGB2BGR(uint8_t* buffer, int width = 1) { 1464
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, 1465 void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap,
1457 int des_line, 1466 int des_line,
1458 uint8_t* src_scan, 1467 uint8_t* src_scan,
1459 FXCodec_Format src_format) { 1468 FXCodec_Format src_format) {
1460 int src_left = m_clipBox.left; 1469 int src_left = m_clipBox.left;
1461 int des_left = m_startX; 1470 int des_left = m_startX;
1462 uint8_t* des_scan = 1471 uint8_t* des_scan =
1463 pDeviceBitmap->GetBuffer() + des_line * pDeviceBitmap->GetPitch(); 1472 pDeviceBitmap->GetBuffer() + des_line * pDeviceBitmap->GetPitch();
1464 int src_bpp = src_format & 0xff; 1473 int src_bpp = src_format & 0xff;
1465 int des_bpp = pDeviceBitmap->GetBPP(); 1474 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); 1656 *des_scan++ = (uint8_t)((des_b) >> 16);
1648 *des_scan++ = (uint8_t)((des_g) >> 16); 1657 *des_scan++ = (uint8_t)((des_g) >> 16);
1649 *des_scan++ = (uint8_t)((des_r) >> 16); 1658 *des_scan++ = (uint8_t)((des_r) >> 16);
1650 *des_scan++ = (uint8_t)((des_alpha * 255) >> 16); 1659 *des_scan++ = (uint8_t)((des_alpha * 255) >> 16);
1651 } break; 1660 } break;
1652 default: 1661 default:
1653 return; 1662 return;
1654 } 1663 }
1655 } 1664 }
1656 } 1665 }
1666
1657 void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap, 1667 void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap,
1658 double scale_y, 1668 double scale_y,
1659 int des_row) { 1669 int des_row) {
1660 int des_Bpp = pDeviceBitmap->GetBPP() >> 3; 1670 int des_Bpp = pDeviceBitmap->GetBPP() >> 3;
1661 uint32_t des_ScanOffet = m_startX * des_Bpp; 1671 uint32_t des_ScanOffet = m_startX * des_Bpp;
1662 if (m_bInterpol) { 1672 if (m_bInterpol) {
1663 int des_top = m_startY; 1673 int des_top = m_startY;
1664 int des_row_1 = des_row - int(scale_y); 1674 int des_row_1 = des_row - int(scale_y);
1665 if (des_row_1 < des_top) { 1675 if (des_row_1 < des_top) {
1666 int des_bottom = des_top + m_sizeY; 1676 int des_bottom = des_top + m_sizeY;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 if (des_row + i >= m_startY + m_sizeY) { 1769 if (des_row + i >= m_startY + m_sizeY) {
1760 return; 1770 return;
1761 } 1771 }
1762 uint8_t* scan_des = 1772 uint8_t* scan_des =
1763 (uint8_t*)pDeviceBitmap->GetScanline(des_row + i) + des_ScanOffet; 1773 (uint8_t*)pDeviceBitmap->GetScanline(des_row + i) + des_ScanOffet;
1764 uint32_t size = m_sizeX * des_Bpp; 1774 uint32_t size = m_sizeX * des_Bpp;
1765 FXSYS_memcpy(scan_des, scan_src, size); 1775 FXSYS_memcpy(scan_des, scan_src, size);
1766 } 1776 }
1767 } 1777 }
1768 } 1778 }
1779
1769 void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap, 1780 void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap,
1770 int32_t src_line, 1781 int32_t src_line,
1771 uint8_t* src_scan, 1782 uint8_t* src_scan,
1772 FXCodec_Format src_format) { 1783 FXCodec_Format src_format) {
1773 int src_top = m_clipBox.top; 1784 int src_top = m_clipBox.top;
1774 int des_top = m_startY; 1785 int des_top = m_startY;
1775 int src_hei = m_clipBox.Height(); 1786 int src_hei = m_clipBox.Height();
1776 int des_hei = m_sizeY; 1787 int des_hei = m_sizeY;
1777 if (src_line >= src_top) { 1788 if (src_line >= src_top) {
1778 double scale_y = (double)des_hei / (double)src_hei; 1789 double scale_y = (double)des_hei / (double)src_hei;
1779 int src_row = src_line - src_top; 1790 int src_row = src_line - src_top;
1780 int des_row = (int)(src_row * scale_y) + des_top; 1791 int des_row = (int)(src_row * scale_y) + des_top;
1781 if (des_row >= des_top + des_hei) { 1792 if (des_row >= des_top + des_hei) {
1782 return; 1793 return;
1783 } 1794 }
1784 ReSampleScanline(pDeviceBitmap, des_row, m_pDecodeBuf, src_format); 1795 ReSampleScanline(pDeviceBitmap, des_row, m_pDecodeBuf, src_format);
1785 if (scale_y > 1.0) { 1796 if (scale_y > 1.0) {
1786 ResampleVert(pDeviceBitmap, scale_y, des_row); 1797 ResampleVert(pDeviceBitmap, scale_y, des_row);
1787 } 1798 }
1788 } 1799 }
1789 } 1800 }
1801
1790 FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames, 1802 FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames,
1791 IFX_Pause* pPause) { 1803 IFX_Pause* pPause) {
1792 if (!(m_status == FXCODEC_STATUS_FRAME_READY || 1804 if (!(m_status == FXCODEC_STATUS_FRAME_READY ||
1793 m_status == FXCODEC_STATUS_FRAME_TOBECONTINUE)) { 1805 m_status == FXCODEC_STATUS_FRAME_TOBECONTINUE)) {
1794 return FXCODEC_STATUS_ERROR; 1806 return FXCODEC_STATUS_ERROR;
1795 } 1807 }
1796 switch (m_imagType) { 1808 switch (m_imagType) {
1797 case FXCODEC_IMAGE_BMP: 1809 case FXCODEC_IMAGE_BMP:
1798 case FXCODEC_IMAGE_JPG: 1810 case FXCODEC_IMAGE_JPG:
1799 case FXCODEC_IMAGE_PNG: 1811 case FXCODEC_IMAGE_PNG:
1800 case FXCODEC_IMAGE_TIF: 1812 case FXCODEC_IMAGE_TIF:
1801 frames = m_FrameNumber = 1; 1813 frames = m_FrameNumber = 1;
1802 return m_status = FXCODEC_STATUS_DECODE_READY; 1814 m_status = FXCODEC_STATUS_DECODE_READY;
1815 return m_status;
1803 case FXCODEC_IMAGE_GIF: { 1816 case FXCODEC_IMAGE_GIF: {
1804 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 1817 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
1805 while (TRUE) { 1818 while (true) {
1806 int32_t readResult = 1819 int32_t readResult =
1807 pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber); 1820 pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
1808 while (readResult == 2) { 1821 while (readResult == 2) {
1809 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_READ; 1822 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_READ;
1810 if (!GifReadMoreData(pGifModule, error_status)) { 1823 if (!GifReadMoreData(pGifModule, error_status)) {
1811 return error_status; 1824 return error_status;
1812 } 1825 }
1813 if (pPause && pPause->NeedToPauseNow()) { 1826 if (pPause && pPause->NeedToPauseNow()) {
1814 return m_status = FXCODEC_STATUS_FRAME_TOBECONTINUE; 1827 m_status = FXCODEC_STATUS_FRAME_TOBECONTINUE;
1828 return m_status;
1815 } 1829 }
1816 readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber); 1830 readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
1817 } 1831 }
1818 if (readResult == 1) { 1832 if (readResult == 1) {
1819 frames = m_FrameNumber; 1833 frames = m_FrameNumber;
1820 return m_status = FXCODEC_STATUS_DECODE_READY; 1834 m_status = FXCODEC_STATUS_DECODE_READY;
1835 return m_status;
1821 } 1836 }
1822 if (m_pGifContext) { 1837 if (m_pGifContext) {
1823 pGifModule->Finish(m_pGifContext); 1838 pGifModule->Finish(m_pGifContext);
1824 m_pGifContext = nullptr; 1839 m_pGifContext = nullptr;
1825 } 1840 }
1826 return m_status = FXCODEC_STATUS_ERROR; 1841 m_status = FXCODEC_STATUS_ERROR;
1842 return m_status;
1827 } 1843 }
1828 } break; 1844 }
1829 default: 1845 default:
1830 break; 1846 return FXCODEC_STATUS_ERROR;
1831 } 1847 }
1832 return FXCODEC_STATUS_ERROR;
1833 } 1848 }
1849
1834 FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, 1850 FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
1835 int start_x, 1851 int start_x,
1836 int start_y, 1852 int start_y,
1837 int size_x, 1853 int size_x,
1838 int size_y, 1854 int size_y,
1839 int32_t frames, 1855 int32_t frames,
1840 FX_BOOL bInterpol) { 1856 FX_BOOL bInterpol) {
1841 if (m_status != FXCODEC_STATUS_DECODE_READY) 1857 if (m_status != FXCODEC_STATUS_DECODE_READY)
1842 return FXCODEC_STATUS_ERROR; 1858 return FXCODEC_STATUS_ERROR;
1843 1859
1844 if (!pDIBitmap || pDIBitmap->GetBPP() < 8 || frames < 0 || 1860 if (!pDIBitmap || pDIBitmap->GetBPP() < 8 || frames < 0 ||
1845 frames >= m_FrameNumber) { 1861 frames >= m_FrameNumber) {
1846 return FXCODEC_STATUS_ERR_PARAMS; 1862 return FXCODEC_STATUS_ERR_PARAMS;
1847 } 1863 }
1848 m_pDeviceBitmap = pDIBitmap; 1864 m_pDeviceBitmap = pDIBitmap;
1849 if (m_clipBox.IsEmpty()) { 1865 if (m_clipBox.IsEmpty())
1850 return FXCODEC_STATUS_ERR_PARAMS; 1866 return FXCODEC_STATUS_ERR_PARAMS;
1851 } 1867 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; 1868 return FXCODEC_STATUS_ERR_PARAMS;
1854 } 1869
1855 FX_RECT device_rc = 1870 FX_RECT device_rc =
1856 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y); 1871 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(); 1872 int32_t out_range_x = device_rc.right - pDIBitmap->GetWidth();
1858 int32_t out_range_y = device_rc.bottom - pDIBitmap->GetHeight(); 1873 int32_t out_range_y = device_rc.bottom - pDIBitmap->GetHeight();
1859 device_rc.Intersect( 1874 device_rc.Intersect(
1860 FX_RECT(0, 0, pDIBitmap->GetWidth(), pDIBitmap->GetHeight())); 1875 FX_RECT(0, 0, pDIBitmap->GetWidth(), pDIBitmap->GetHeight()));
1861 if (device_rc.IsEmpty()) { 1876 if (device_rc.IsEmpty())
1862 return FXCODEC_STATUS_ERR_PARAMS; 1877 return FXCODEC_STATUS_ERR_PARAMS;
1863 } 1878
1864 m_startX = device_rc.left; 1879 m_startX = device_rc.left;
1865 m_startY = device_rc.top; 1880 m_startY = device_rc.top;
1866 m_sizeX = device_rc.Width(); 1881 m_sizeX = device_rc.Width();
1867 m_sizeY = device_rc.Height(); 1882 m_sizeY = device_rc.Height();
1868 m_bInterpol = bInterpol; 1883 m_bInterpol = bInterpol;
1869 m_FrameCur = 0; 1884 m_FrameCur = 0;
1870 if (start_x < 0 || out_range_x > 0) { 1885 if (start_x < 0 || out_range_x > 0) {
1871 FX_FLOAT scaleX = (FX_FLOAT)m_clipBox.Width() / (FX_FLOAT)size_x; 1886 FX_FLOAT scaleX = (FX_FLOAT)m_clipBox.Width() / (FX_FLOAT)size_x;
1872 if (start_x < 0) { 1887 if (start_x < 0) {
1873 m_clipBox.left -= (int32_t)FXSYS_ceil((FX_FLOAT)start_x * scaleX); 1888 m_clipBox.left -= (int32_t)FXSYS_ceil((FX_FLOAT)start_x * scaleX);
(...skipping 18 matching lines...) Expand all
1892 case FXCODEC_IMAGE_JPG: { 1907 case FXCODEC_IMAGE_JPG: {
1893 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 1908 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
1894 int down_scale = 1; 1909 int down_scale = 1;
1895 GetDownScale(down_scale); 1910 GetDownScale(down_scale);
1896 FX_BOOL bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); 1911 FX_BOOL bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale);
1897 while (!bStart) { 1912 while (!bStart) {
1898 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; 1913 FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR;
1899 if (!JpegReadMoreData(pJpegModule, error_status)) { 1914 if (!JpegReadMoreData(pJpegModule, error_status)) {
1900 m_pDeviceBitmap = nullptr; 1915 m_pDeviceBitmap = nullptr;
1901 m_pFile = nullptr; 1916 m_pFile = nullptr;
1902 return m_status = error_status; 1917 m_status = error_status;
1918 return m_status;
1903 } 1919 }
1904 bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); 1920 bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale);
1905 } 1921 }
1906 int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale; 1922 int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale;
1907 scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4; 1923 scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4;
1908 FX_Free(m_pDecodeBuf); 1924 FX_Free(m_pDecodeBuf);
1909 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 1925 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1910 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 1926 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1911 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, 1927 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
1912 m_clipBox.Width(), m_bInterpol); 1928 m_clipBox.Width(), m_bInterpol);
1913 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 1929 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
1914 switch (m_SrcComponents) { 1930 switch (m_SrcComponents) {
1915 case 1: 1931 case 1:
1916 m_SrcFormat = FXCodec_8bppGray; 1932 m_SrcFormat = FXCodec_8bppGray;
1917 break; 1933 break;
1918 case 3: 1934 case 3:
1919 m_SrcFormat = FXCodec_Rgb; 1935 m_SrcFormat = FXCodec_Rgb;
1920 break; 1936 break;
1921 case 4: 1937 case 4:
1922 m_SrcFormat = FXCodec_Cmyk; 1938 m_SrcFormat = FXCodec_Cmyk;
1923 break; 1939 break;
1924 } 1940 }
1925 GetTransMethod(pDIBitmap->GetFormat(), m_SrcFormat); 1941 GetTransMethod(pDIBitmap->GetFormat(), m_SrcFormat);
1926 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 1942 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
1927 } break; 1943 return m_status;
1944 }
1928 case FXCODEC_IMAGE_PNG: { 1945 case FXCODEC_IMAGE_PNG: {
1929 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 1946 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
1930 if (!pPngModule) { 1947 if (!pPngModule) {
1931 m_pDeviceBitmap = nullptr; 1948 m_pDeviceBitmap = nullptr;
1932 m_pFile = nullptr; 1949 m_pFile = nullptr;
1933 return m_status = FXCODEC_STATUS_ERR_MEMORY; 1950 m_status = FXCODEC_STATUS_ERR_MEMORY;
1951 return m_status;
1934 } 1952 }
1935 if (m_pPngContext) { 1953 if (m_pPngContext) {
1936 pPngModule->Finish(m_pPngContext); 1954 pPngModule->Finish(m_pPngContext);
1937 m_pPngContext = nullptr; 1955 m_pPngContext = nullptr;
1938 } 1956 }
1939 m_pPngContext = pPngModule->Start((void*)this); 1957 m_pPngContext = pPngModule->Start((void*)this);
1940 if (!m_pPngContext) { 1958 if (!m_pPngContext) {
1941 m_pDeviceBitmap = nullptr; 1959 m_pDeviceBitmap = nullptr;
1942 m_pFile = nullptr; 1960 m_pFile = nullptr;
1943 return m_status = FXCODEC_STATUS_ERR_MEMORY; 1961 m_status = FXCODEC_STATUS_ERR_MEMORY;
1962 return m_status;
1944 } 1963 }
1945 m_offSet = 0; 1964 m_offSet = 0;
1946 switch (m_pDeviceBitmap->GetFormat()) { 1965 switch (m_pDeviceBitmap->GetFormat()) {
1947 case FXDIB_8bppMask: 1966 case FXDIB_8bppMask:
1948 case FXDIB_8bppRgb: 1967 case FXDIB_8bppRgb:
1949 m_SrcComponents = 1; 1968 m_SrcComponents = 1;
1950 m_SrcFormat = FXCodec_8bppGray; 1969 m_SrcFormat = FXCodec_8bppGray;
1951 break; 1970 break;
1952 case FXDIB_Rgb: 1971 case FXDIB_Rgb:
1953 m_SrcComponents = 3; 1972 m_SrcComponents = 3;
1954 m_SrcFormat = FXCodec_Rgb; 1973 m_SrcFormat = FXCodec_Rgb;
1955 break; 1974 break;
1956 case FXDIB_Rgb32: 1975 case FXDIB_Rgb32:
1957 case FXDIB_Argb: 1976 case FXDIB_Argb:
1958 m_SrcComponents = 4; 1977 m_SrcComponents = 4;
1959 m_SrcFormat = FXCodec_Argb; 1978 m_SrcFormat = FXCodec_Argb;
1960 break; 1979 break;
1961 default: { 1980 default: {
1962 m_pDeviceBitmap = nullptr; 1981 m_pDeviceBitmap = nullptr;
1963 m_pFile = nullptr; 1982 m_pFile = nullptr;
1964 return m_status = FXCODEC_STATUS_ERR_PARAMS; 1983 m_status = FXCODEC_STATUS_ERR_PARAMS;
1984 return m_status;
1965 } 1985 }
1966 } 1986 }
1967 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); 1987 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
1968 int scanline_size = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; 1988 int scanline_size = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4;
1969 FX_Free(m_pDecodeBuf); 1989 FX_Free(m_pDecodeBuf);
1970 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 1990 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1971 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 1991 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1972 m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol); 1992 m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol);
1973 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 1993 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
1974 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 1994 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
1975 } break; 1995 return m_status;
1996 }
1976 case FXCODEC_IMAGE_GIF: { 1997 case FXCODEC_IMAGE_GIF: {
1977 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 1998 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
1978 if (!pGifModule) { 1999 if (!pGifModule) {
1979 m_pDeviceBitmap = nullptr; 2000 m_pDeviceBitmap = nullptr;
1980 m_pFile = nullptr; 2001 m_pFile = nullptr;
1981 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2002 m_status = FXCODEC_STATUS_ERR_MEMORY;
2003 return m_status;
1982 } 2004 }
1983 m_SrcFormat = FXCodec_8bppRgb; 2005 m_SrcFormat = FXCodec_8bppRgb;
1984 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); 2006 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
1985 int scanline_size = (m_SrcWidth + 3) / 4 * 4; 2007 int scanline_size = (m_SrcWidth + 3) / 4 * 4;
1986 FX_Free(m_pDecodeBuf); 2008 FX_Free(m_pDecodeBuf);
1987 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); 2009 m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size);
1988 FXSYS_memset(m_pDecodeBuf, 0, scanline_size); 2010 FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
1989 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, 2011 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
1990 m_clipBox.Width(), m_bInterpol); 2012 m_clipBox.Width(), m_bInterpol);
1991 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 2013 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
1992 m_FrameCur = frames; 2014 m_FrameCur = frames;
1993 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2015 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
1994 } break; 2016 return m_status;
2017 }
1995 case FXCODEC_IMAGE_BMP: { 2018 case FXCODEC_IMAGE_BMP: {
1996 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); 2019 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
1997 if (!pBmpModule) { 2020 if (!pBmpModule) {
1998 m_pDeviceBitmap = nullptr; 2021 m_pDeviceBitmap = nullptr;
1999 m_pFile = nullptr; 2022 m_pFile = nullptr;
2000 return m_status = FXCODEC_STATUS_ERR_MEMORY; 2023 m_status = FXCODEC_STATUS_ERR_MEMORY;
2024 return m_status;
2001 } 2025 }
2002 switch (m_SrcComponents) { 2026 switch (m_SrcComponents) {
2003 case 1: 2027 case 1:
2004 m_SrcFormat = FXCodec_8bppRgb; 2028 m_SrcFormat = FXCodec_8bppRgb;
2005 break; 2029 break;
2006 case 3: 2030 case 3:
2007 m_SrcFormat = FXCodec_Rgb; 2031 m_SrcFormat = FXCodec_Rgb;
2008 break; 2032 break;
2009 case 4: 2033 case 4:
2010 m_SrcFormat = FXCodec_Rgb32; 2034 m_SrcFormat = FXCodec_Rgb32;
2011 break; 2035 break;
2012 } 2036 }
2013 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat); 2037 GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
2014 m_ScanlineSize = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; 2038 m_ScanlineSize = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4;
2015 FX_Free(m_pDecodeBuf); 2039 FX_Free(m_pDecodeBuf);
2016 m_pDecodeBuf = FX_Alloc(uint8_t, m_ScanlineSize); 2040 m_pDecodeBuf = FX_Alloc(uint8_t, m_ScanlineSize);
2017 FXSYS_memset(m_pDecodeBuf, 0, m_ScanlineSize); 2041 FXSYS_memset(m_pDecodeBuf, 0, m_ScanlineSize);
2018 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0, 2042 m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
2019 m_clipBox.Width(), m_bInterpol); 2043 m_clipBox.Width(), m_bInterpol);
2020 m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); 2044 m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
2021 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2045 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2022 } break; 2046 return m_status;
2047 }
2023 case FXCODEC_IMAGE_TIF: 2048 case FXCODEC_IMAGE_TIF:
2024 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2049 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2050 return m_status;
2025 default: 2051 default:
2026 break; 2052 return FXCODEC_STATUS_ERROR;
2027 } 2053 }
2028 return FXCODEC_STATUS_ERROR;
2029 } 2054 }
2055
2030 FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { 2056 FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
2031 if (m_status != FXCODEC_STATUS_DECODE_TOBECONTINUE) { 2057 if (m_status != FXCODEC_STATUS_DECODE_TOBECONTINUE)
2032 return FXCODEC_STATUS_ERROR; 2058 return FXCODEC_STATUS_ERROR;
2033 } 2059
2034 switch (m_imagType) { 2060 switch (m_imagType) {
2035 case FXCODEC_IMAGE_JPG: { 2061 case FXCODEC_IMAGE_JPG: {
2036 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); 2062 CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
2037 while (TRUE) { 2063 while (true) {
2038 FX_BOOL readRes = 2064 FX_BOOL readRes =
2039 pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf); 2065 pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf);
2040 while (!readRes) { 2066 while (!readRes) {
2041 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2067 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2042 if (!JpegReadMoreData(pJpegModule, error_status)) { 2068 if (!JpegReadMoreData(pJpegModule, error_status)) {
2043 m_pDeviceBitmap = nullptr; 2069 m_pDeviceBitmap = nullptr;
2044 m_pFile = nullptr; 2070 m_pFile = nullptr;
2045 return m_status = error_status; 2071 m_status = error_status;
2072 return m_status;
2046 } 2073 }
2047 readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf); 2074 readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf);
2048 } 2075 }
2049 if (m_SrcFormat == FXCodec_Rgb) { 2076 if (m_SrcFormat == FXCodec_Rgb) {
2050 int src_Bpp = (m_SrcFormat & 0xff) >> 3; 2077 int src_Bpp = (m_SrcFormat & 0xff) >> 3;
2051 _RGB2BGR(m_pDecodeBuf + m_clipBox.left * src_Bpp, m_clipBox.Width()); 2078 RGB2BGR(m_pDecodeBuf + m_clipBox.left * src_Bpp, m_clipBox.Width());
2052 } 2079 }
2053 if (m_SrcRow >= m_clipBox.bottom) { 2080 if (m_SrcRow >= m_clipBox.bottom) {
2054 m_pDeviceBitmap = nullptr; 2081 m_pDeviceBitmap = nullptr;
2055 m_pFile = nullptr; 2082 m_pFile = nullptr;
2056 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2083 m_status = FXCODEC_STATUS_DECODE_FINISH;
2084 return m_status;
2057 } 2085 }
2058 Resample(m_pDeviceBitmap, m_SrcRow, m_pDecodeBuf, m_SrcFormat); 2086 Resample(m_pDeviceBitmap, m_SrcRow, m_pDecodeBuf, m_SrcFormat);
2059 m_SrcRow++; 2087 m_SrcRow++;
2060 if (pPause && pPause->NeedToPauseNow()) { 2088 if (pPause && pPause->NeedToPauseNow()) {
2061 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2089 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2090 return m_status;
2062 } 2091 }
2063 } 2092 }
2064 } break; 2093 }
2065 case FXCODEC_IMAGE_PNG: { 2094 case FXCODEC_IMAGE_PNG: {
2066 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule(); 2095 CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
2067 while (TRUE) { 2096 while (true) {
2068 uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet; 2097 uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet;
2069 uint32_t input_size = 2098 uint32_t input_size =
2070 remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size; 2099 remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size;
2071 if (input_size == 0) { 2100 if (input_size == 0) {
2072 if (m_pPngContext) { 2101 if (m_pPngContext) {
2073 pPngModule->Finish(m_pPngContext); 2102 pPngModule->Finish(m_pPngContext);
2074 } 2103 }
2075 m_pPngContext = nullptr; 2104 m_pPngContext = nullptr;
2076 m_pDeviceBitmap = nullptr; 2105 m_pDeviceBitmap = nullptr;
2077 m_pFile = nullptr; 2106 m_pFile = nullptr;
2078 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2107 m_status = FXCODEC_STATUS_DECODE_FINISH;
2108 return m_status;
2079 } 2109 }
2080 if (m_pSrcBuf && input_size > m_SrcSize) { 2110 if (m_pSrcBuf && input_size > m_SrcSize) {
2081 FX_Free(m_pSrcBuf); 2111 FX_Free(m_pSrcBuf);
2082 m_pSrcBuf = FX_Alloc(uint8_t, input_size); 2112 m_pSrcBuf = FX_Alloc(uint8_t, input_size);
2083 FXSYS_memset(m_pSrcBuf, 0, input_size); 2113 FXSYS_memset(m_pSrcBuf, 0, input_size);
2084 m_SrcSize = input_size; 2114 m_SrcSize = input_size;
2085 } 2115 }
2086 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size); 2116 FX_BOOL bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size);
2087 if (!bResult) { 2117 if (!bResult) {
2088 m_pDeviceBitmap = nullptr; 2118 m_pDeviceBitmap = nullptr;
2089 m_pFile = nullptr; 2119 m_pFile = nullptr;
2090 return m_status = FXCODEC_STATUS_ERR_READ; 2120 m_status = FXCODEC_STATUS_ERR_READ;
2121 return m_status;
2091 } 2122 }
2092 m_offSet += input_size; 2123 m_offSet += input_size;
2093 bResult = 2124 bResult =
2094 pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, nullptr); 2125 pPngModule->Input(m_pPngContext, m_pSrcBuf, input_size, nullptr);
2095 if (!bResult) { 2126 if (!bResult) {
2096 m_pDeviceBitmap = nullptr; 2127 m_pDeviceBitmap = nullptr;
2097 m_pFile = nullptr; 2128 m_pFile = nullptr;
2098 return m_status = FXCODEC_STATUS_ERROR; 2129 m_status = FXCODEC_STATUS_ERROR;
2130 return m_status;
2099 } 2131 }
2100 if (pPause && pPause->NeedToPauseNow()) { 2132 if (pPause && pPause->NeedToPauseNow()) {
2101 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2133 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2134 return m_status;
2102 } 2135 }
2103 } 2136 }
2104 } break; 2137 }
2105 case FXCODEC_IMAGE_GIF: { 2138 case FXCODEC_IMAGE_GIF: {
2106 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule(); 2139 CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
2107 while (TRUE) { 2140 while (true) {
2108 int32_t readRes = 2141 int32_t readRes =
2109 pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr); 2142 pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
2110 while (readRes == 2) { 2143 while (readRes == 2) {
2111 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2144 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2112 if (!GifReadMoreData(pGifModule, error_status)) { 2145 if (!GifReadMoreData(pGifModule, error_status)) {
2113 m_pDeviceBitmap = nullptr; 2146 m_pDeviceBitmap = nullptr;
2114 m_pFile = nullptr; 2147 m_pFile = nullptr;
2115 return m_status = error_status; 2148 m_status = error_status;
2149 return m_status;
2116 } 2150 }
2117 if (pPause && pPause->NeedToPauseNow()) { 2151 if (pPause && pPause->NeedToPauseNow()) {
2118 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2152 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2153 return m_status;
2119 } 2154 }
2120 readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr); 2155 readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
2121 } 2156 }
2122 if (readRes == 1) { 2157 if (readRes == 1) {
2123 m_pDeviceBitmap = nullptr; 2158 m_pDeviceBitmap = nullptr;
2124 m_pFile = nullptr; 2159 m_pFile = nullptr;
2125 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2160 m_status = FXCODEC_STATUS_DECODE_FINISH;
2161 return m_status;
2126 } 2162 }
2127 m_pDeviceBitmap = nullptr; 2163 m_pDeviceBitmap = nullptr;
2128 m_pFile = nullptr; 2164 m_pFile = nullptr;
2129 return m_status = FXCODEC_STATUS_ERROR; 2165 m_status = FXCODEC_STATUS_ERROR;
2166 return m_status;
2130 } 2167 }
2131 } break; 2168 }
2132 case FXCODEC_IMAGE_BMP: { 2169 case FXCODEC_IMAGE_BMP: {
2133 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule(); 2170 CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
2134 while (TRUE) { 2171 while (true) {
2135 int32_t readRes = pBmpModule->LoadImage(m_pBmpContext); 2172 int32_t readRes = pBmpModule->LoadImage(m_pBmpContext);
2136 while (readRes == 2) { 2173 while (readRes == 2) {
2137 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH; 2174 FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
2138 if (!BmpReadMoreData(pBmpModule, error_status)) { 2175 if (!BmpReadMoreData(pBmpModule, error_status)) {
2139 m_pDeviceBitmap = nullptr; 2176 m_pDeviceBitmap = nullptr;
2140 m_pFile = nullptr; 2177 m_pFile = nullptr;
2141 return m_status = error_status; 2178 m_status = error_status;
2179 return m_status;
2142 } 2180 }
2143 if (pPause && pPause->NeedToPauseNow()) { 2181 if (pPause && pPause->NeedToPauseNow()) {
2144 return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; 2182 m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
2183 return m_status;
2145 } 2184 }
2146 readRes = pBmpModule->LoadImage(m_pBmpContext); 2185 readRes = pBmpModule->LoadImage(m_pBmpContext);
2147 } 2186 }
2148 if (readRes == 1) { 2187 if (readRes == 1) {
2149 m_pDeviceBitmap = nullptr; 2188 m_pDeviceBitmap = nullptr;
2150 m_pFile = nullptr; 2189 m_pFile = nullptr;
2151 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2190 m_status = FXCODEC_STATUS_DECODE_FINISH;
2191 return m_status;
2152 } 2192 }
2153 m_pDeviceBitmap = nullptr; 2193 m_pDeviceBitmap = nullptr;
2154 m_pFile = nullptr; 2194 m_pFile = nullptr;
2155 return m_status = FXCODEC_STATUS_ERROR; 2195 m_status = FXCODEC_STATUS_ERROR;
2196 return m_status;
2156 } 2197 }
2157 } break; 2198 };
2158 case FXCODEC_IMAGE_TIF: { 2199 case FXCODEC_IMAGE_TIF: {
2159 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule(); 2200 CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
2160 FX_BOOL ret = FALSE; 2201 FX_BOOL ret = FALSE;
2161 if (m_pDeviceBitmap->GetBPP() == 32 && 2202 if (m_pDeviceBitmap->GetBPP() == 32 &&
2162 m_pDeviceBitmap->GetWidth() == m_SrcWidth && m_SrcWidth == m_sizeX && 2203 m_pDeviceBitmap->GetWidth() == m_SrcWidth && m_SrcWidth == m_sizeX &&
2163 m_pDeviceBitmap->GetHeight() == m_SrcHeight && 2204 m_pDeviceBitmap->GetHeight() == m_SrcHeight &&
2164 m_SrcHeight == m_sizeY && m_startX == 0 && m_startY == 0 && 2205 m_SrcHeight == m_sizeY && m_startX == 0 && m_startY == 0 &&
2165 m_clipBox.left == 0 && m_clipBox.top == 0 && 2206 m_clipBox.left == 0 && m_clipBox.top == 0 &&
2166 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) { 2207 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight) {
2167 ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap); 2208 ret = pTiffModule->Decode(m_pTiffContext, m_pDeviceBitmap);
2168 m_pDeviceBitmap = nullptr; 2209 m_pDeviceBitmap = nullptr;
2169 m_pFile = nullptr; 2210 m_pFile = nullptr;
2170 if (!ret) { 2211 if (!ret) {
2171 return m_status = FXCODEC_STATUS_ERROR; 2212 m_status = FXCODEC_STATUS_ERROR;
2213 return m_status;
2172 } 2214 }
2173 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2215 m_status = FXCODEC_STATUS_DECODE_FINISH;
2174 } else { 2216 return m_status;
2175 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; 2217 }
2176 pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb); 2218
2177 if (!pDIBitmap->GetBuffer()) { 2219 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
2178 delete pDIBitmap; 2220 pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb);
2179 m_pDeviceBitmap = nullptr; 2221 if (!pDIBitmap->GetBuffer()) {
2180 m_pFile = nullptr; 2222 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; 2223 m_pDeviceBitmap = nullptr;
2292 m_pFile = nullptr; 2224 m_pFile = nullptr;
2293 return m_status = FXCODEC_STATUS_DECODE_FINISH; 2225 m_status = FXCODEC_STATUS_ERR_MEMORY;
2226 return m_status;
2294 } 2227 }
2295 } break; 2228 ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap);
2229 if (!ret) {
2230 delete pDIBitmap;
2231 m_pDeviceBitmap = nullptr;
2232 m_pFile = nullptr;
2233 m_status = FXCODEC_STATUS_ERROR;
2234 return m_status;
2235 }
2236 CFX_DIBitmap* pClipBitmap =
2237 (m_clipBox.left == 0 && m_clipBox.top == 0 &&
2238 m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight)
2239 ? pDIBitmap
2240 : pDIBitmap->Clone(&m_clipBox);
2241 if (pDIBitmap != pClipBitmap) {
2242 delete pDIBitmap;
2243 }
2244 if (!pClipBitmap) {
2245 m_pDeviceBitmap = nullptr;
2246 m_pFile = nullptr;
2247 m_status = FXCODEC_STATUS_ERR_MEMORY;
2248 return m_status;
2249 }
2250 CFX_DIBitmap* pFormatBitmap = nullptr;
2251 switch (m_pDeviceBitmap->GetFormat()) {
2252 case FXDIB_8bppRgb:
2253 pFormatBitmap = new CFX_DIBitmap;
2254 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2255 pClipBitmap->GetHeight(), FXDIB_8bppRgb);
2256 break;
2257 case FXDIB_8bppMask:
2258 pFormatBitmap = new CFX_DIBitmap;
2259 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2260 pClipBitmap->GetHeight(), FXDIB_8bppMask);
2261 break;
2262 case FXDIB_Rgb:
2263 pFormatBitmap = new CFX_DIBitmap;
2264 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2265 pClipBitmap->GetHeight(), FXDIB_Rgb);
2266 break;
2267 case FXDIB_Rgb32:
2268 pFormatBitmap = new CFX_DIBitmap;
2269 pFormatBitmap->Create(pClipBitmap->GetWidth(),
2270 pClipBitmap->GetHeight(), FXDIB_Rgb32);
2271 break;
2272 case FXDIB_Argb:
2273 pFormatBitmap = pClipBitmap;
2274 break;
2275 default:
2276 break;
2277 }
2278 switch (m_pDeviceBitmap->GetFormat()) {
2279 case FXDIB_8bppRgb:
2280 case FXDIB_8bppMask: {
2281 for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
2282 uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
2283 uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
2284 for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
2285 uint8_t _a = 255 - src_line[3];
2286 uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
2287 uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
2288 uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
2289 *des_line++ = FXRGB2GRAY(r, g, b);
2290 src_line += 4;
2291 }
2292 }
2293 } break;
2294 case FXDIB_Rgb:
2295 case FXDIB_Rgb32: {
2296 int32_t desBpp = (m_pDeviceBitmap->GetFormat() == FXDIB_Rgb) ? 3 : 4;
2297 for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
2298 uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
2299 uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
2300 for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
2301 uint8_t _a = 255 - src_line[3];
2302 uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
2303 uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
2304 uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
2305 *des_line++ = b;
2306 *des_line++ = g;
2307 *des_line++ = r;
2308 des_line += desBpp - 3;
2309 src_line += 4;
2310 }
2311 }
2312 } break;
2313 default:
2314 break;
2315 }
2316 if (pClipBitmap != pFormatBitmap) {
2317 delete pClipBitmap;
2318 }
2319 if (!pFormatBitmap) {
2320 m_pDeviceBitmap = nullptr;
2321 m_pFile = nullptr;
2322 m_status = FXCODEC_STATUS_ERR_MEMORY;
2323 return m_status;
2324 }
2325 CFX_DIBitmap* pStrechBitmap = pFormatBitmap->StretchTo(
2326 m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
2327 delete pFormatBitmap;
2328 pFormatBitmap = nullptr;
2329 if (!pStrechBitmap) {
2330 m_pDeviceBitmap = nullptr;
2331 m_pFile = nullptr;
2332 m_status = FXCODEC_STATUS_ERR_MEMORY;
2333 return m_status;
2334 }
2335 m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
2336 pStrechBitmap, 0, 0);
2337 delete pStrechBitmap;
2338 pStrechBitmap = nullptr;
2339 m_pDeviceBitmap = nullptr;
2340 m_pFile = nullptr;
2341 m_status = FXCODEC_STATUS_DECODE_FINISH;
2342 return m_status;
2343 }
2296 default: 2344 default:
2297 break; 2345 return FXCODEC_STATUS_ERROR;
2298 } 2346 }
2299 return FXCODEC_STATUS_ERROR;
2300 } 2347 }
2348
2301 CCodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() { 2349 CCodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() {
2302 return new CCodec_ProgressiveDecoder(this); 2350 return new CCodec_ProgressiveDecoder(this);
2303 } 2351 }
OLDNEW
« no previous file with comments | « core/fxcodec/codec/ccodec_tiffmodule.h ('k') | core/fxcodec/codec/fx_codec_tiff.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698