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

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