OLD | NEW |
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/include/fxge/fx_dib.h" | 7 #include "core/include/fxge/fx_dib.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
11 #include "core/fxge/dib/dib_int.h" | 11 #include "core/fxge/dib/dib_int.h" |
12 #include "core/include/fxcodec/fx_codec.h" | 12 #include "core/include/fxcodec/fx_codec.h" |
13 #include "core/include/fxge/fx_ge.h" | 13 #include "core/include/fxge/fx_ge.h" |
14 | 14 |
15 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, | 15 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, |
16 uint8_t* dest_buf, | 16 uint8_t* dest_buf, |
17 int dest_pitch, | 17 int dest_pitch, |
18 int width, | 18 int width, |
19 int height, | 19 int height, |
20 const CFX_DIBSource* pSrcBitmap, | 20 const CFX_DIBSource* pSrcBitmap, |
21 int src_left, | 21 int src_left, |
22 int src_top, | 22 int src_top, |
23 FX_DWORD*& pal, | 23 uint32_t*& pal, |
24 void* pIccTransform); | 24 void* pIccTransform); |
25 void CmykDecode(FX_DWORD cmyk, int& c, int& m, int& y, int& k) { | 25 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { |
26 c = FXSYS_GetCValue(cmyk); | 26 c = FXSYS_GetCValue(cmyk); |
27 m = FXSYS_GetMValue(cmyk); | 27 m = FXSYS_GetMValue(cmyk); |
28 y = FXSYS_GetYValue(cmyk); | 28 y = FXSYS_GetYValue(cmyk); |
29 k = FXSYS_GetKValue(cmyk); | 29 k = FXSYS_GetKValue(cmyk); |
30 } | 30 } |
31 void ArgbDecode(FX_DWORD argb, int& a, int& r, int& g, int& b) { | 31 void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) { |
32 a = FXARGB_A(argb); | 32 a = FXARGB_A(argb); |
33 r = FXARGB_R(argb); | 33 r = FXARGB_R(argb); |
34 g = FXARGB_G(argb); | 34 g = FXARGB_G(argb); |
35 b = FXARGB_B(argb); | 35 b = FXARGB_B(argb); |
36 } | 36 } |
37 void ArgbDecode(FX_DWORD argb, int& a, FX_COLORREF& rgb) { | 37 void ArgbDecode(uint32_t argb, int& a, FX_COLORREF& rgb) { |
38 a = FXARGB_A(argb); | 38 a = FXARGB_A(argb); |
39 rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); | 39 rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); |
40 } | 40 } |
41 FX_DWORD ArgbEncode(int a, FX_COLORREF rgb) { | 41 uint32_t ArgbEncode(int a, FX_COLORREF rgb) { |
42 return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb), | 42 return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb), |
43 FXSYS_GetBValue(rgb)); | 43 FXSYS_GetBValue(rgb)); |
44 } | 44 } |
45 | 45 |
46 CFX_DIBSource::CFX_DIBSource() { | 46 CFX_DIBSource::CFX_DIBSource() { |
47 m_bpp = 0; | 47 m_bpp = 0; |
48 m_AlphaFlag = 0; | 48 m_AlphaFlag = 0; |
49 m_Width = m_Height = 0; | 49 m_Width = m_Height = 0; |
50 m_Pitch = 0; | 50 m_Pitch = 0; |
51 m_pPalette = NULL; | 51 m_pPalette = NULL; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 delete pNewBitmap; | 189 delete pNewBitmap; |
190 return NULL; | 190 return NULL; |
191 } | 191 } |
192 pNewBitmap->CopyPalette(m_pPalette); | 192 pNewBitmap->CopyPalette(m_pPalette); |
193 pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip); | 193 pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip); |
194 if (GetBPP() == 1 && rect.left % 8 != 0) { | 194 if (GetBPP() == 1 && rect.left % 8 != 0) { |
195 int left_shift = rect.left % 32; | 195 int left_shift = rect.left % 32; |
196 int right_shift = 32 - left_shift; | 196 int right_shift = 32 - left_shift; |
197 int dword_count = pNewBitmap->m_Pitch / 4; | 197 int dword_count = pNewBitmap->m_Pitch / 4; |
198 for (int row = rect.top; row < rect.bottom; row++) { | 198 for (int row = rect.top; row < rect.bottom; row++) { |
199 FX_DWORD* src_scan = (FX_DWORD*)GetScanline(row) + rect.left / 32; | 199 uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32; |
200 FX_DWORD* dest_scan = (FX_DWORD*)pNewBitmap->GetScanline(row - rect.top); | 200 uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top); |
201 for (int i = 0; i < dword_count; i++) { | 201 for (int i = 0; i < dword_count; i++) { |
202 dest_scan[i] = | 202 dest_scan[i] = |
203 (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift); | 203 (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift); |
204 } | 204 } |
205 } | 205 } |
206 } else { | 206 } else { |
207 int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8; | 207 int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8; |
208 if (m_Pitch < (FX_DWORD)copy_len) { | 208 if (m_Pitch < (uint32_t)copy_len) { |
209 copy_len = m_Pitch; | 209 copy_len = m_Pitch; |
210 } | 210 } |
211 for (int row = rect.top; row < rect.bottom; row++) { | 211 for (int row = rect.top; row < rect.bottom; row++) { |
212 const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8; | 212 const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8; |
213 uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top); | 213 uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top); |
214 FXSYS_memcpy(dest_scan, src_scan, copy_len); | 214 FXSYS_memcpy(dest_scan, src_scan, copy_len); |
215 } | 215 } |
216 } | 216 } |
217 return pNewBitmap; | 217 return pNewBitmap; |
218 } | 218 } |
219 void CFX_DIBSource::BuildPalette() { | 219 void CFX_DIBSource::BuildPalette() { |
220 if (m_pPalette) { | 220 if (m_pPalette) { |
221 return; | 221 return; |
222 } | 222 } |
223 if (GetBPP() == 1) { | 223 if (GetBPP() == 1) { |
224 m_pPalette = FX_Alloc(FX_DWORD, 2); | 224 m_pPalette = FX_Alloc(uint32_t, 2); |
225 if (IsCmykImage()) { | 225 if (IsCmykImage()) { |
226 m_pPalette[0] = 0xff; | 226 m_pPalette[0] = 0xff; |
227 m_pPalette[1] = 0; | 227 m_pPalette[1] = 0; |
228 } else { | 228 } else { |
229 m_pPalette[0] = 0xff000000; | 229 m_pPalette[0] = 0xff000000; |
230 m_pPalette[1] = 0xffffffff; | 230 m_pPalette[1] = 0xffffffff; |
231 } | 231 } |
232 } else if (GetBPP() == 8) { | 232 } else if (GetBPP() == 8) { |
233 m_pPalette = FX_Alloc(FX_DWORD, 256); | 233 m_pPalette = FX_Alloc(uint32_t, 256); |
234 if (IsCmykImage()) { | 234 if (IsCmykImage()) { |
235 for (int i = 0; i < 256; i++) { | 235 for (int i = 0; i < 256; i++) { |
236 m_pPalette[i] = 0xff - i; | 236 m_pPalette[i] = 0xff - i; |
237 } | 237 } |
238 } else { | 238 } else { |
239 for (int i = 0; i < 256; i++) { | 239 for (int i = 0; i < 256; i++) { |
240 m_pPalette[i] = 0xff000000 | (i * 0x10101); | 240 m_pPalette[i] = 0xff000000 | (i * 0x10101); |
241 } | 241 } |
242 } | 242 } |
243 } | 243 } |
244 } | 244 } |
245 FX_BOOL CFX_DIBSource::BuildAlphaMask() { | 245 FX_BOOL CFX_DIBSource::BuildAlphaMask() { |
246 if (m_pAlphaMask) { | 246 if (m_pAlphaMask) { |
247 return TRUE; | 247 return TRUE; |
248 } | 248 } |
249 m_pAlphaMask = new CFX_DIBitmap; | 249 m_pAlphaMask = new CFX_DIBitmap; |
250 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { | 250 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { |
251 delete m_pAlphaMask; | 251 delete m_pAlphaMask; |
252 m_pAlphaMask = NULL; | 252 m_pAlphaMask = NULL; |
253 return FALSE; | 253 return FALSE; |
254 } | 254 } |
255 FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff, | 255 FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff, |
256 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch()); | 256 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch()); |
257 return TRUE; | 257 return TRUE; |
258 } | 258 } |
259 FX_DWORD CFX_DIBSource::GetPaletteEntry(int index) const { | 259 uint32_t CFX_DIBSource::GetPaletteEntry(int index) const { |
260 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); | 260 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); |
261 if (m_pPalette) { | 261 if (m_pPalette) { |
262 return m_pPalette[index]; | 262 return m_pPalette[index]; |
263 } | 263 } |
264 if (IsCmykImage()) { | 264 if (IsCmykImage()) { |
265 if (GetBPP() == 1) { | 265 if (GetBPP() == 1) { |
266 return index ? 0 : 0xff; | 266 return index ? 0 : 0xff; |
267 } | 267 } |
268 return 0xff - index; | 268 return 0xff - index; |
269 } | 269 } |
270 if (GetBPP() == 1) { | 270 if (GetBPP() == 1) { |
271 return index ? 0xffffffff : 0xff000000; | 271 return index ? 0xffffffff : 0xff000000; |
272 } | 272 } |
273 return index * 0x10101 | 0xff000000; | 273 return index * 0x10101 | 0xff000000; |
274 } | 274 } |
275 void CFX_DIBSource::SetPaletteEntry(int index, FX_DWORD color) { | 275 void CFX_DIBSource::SetPaletteEntry(int index, uint32_t color) { |
276 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); | 276 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); |
277 if (!m_pPalette) { | 277 if (!m_pPalette) { |
278 BuildPalette(); | 278 BuildPalette(); |
279 } | 279 } |
280 m_pPalette[index] = color; | 280 m_pPalette[index] = color; |
281 } | 281 } |
282 int CFX_DIBSource::FindPalette(FX_DWORD color) const { | 282 int CFX_DIBSource::FindPalette(uint32_t color) const { |
283 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); | 283 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); |
284 if (!m_pPalette) { | 284 if (!m_pPalette) { |
285 if (IsCmykImage()) { | 285 if (IsCmykImage()) { |
286 if (GetBPP() == 1) { | 286 if (GetBPP() == 1) { |
287 return ((uint8_t)color == 0xff) ? 0 : 1; | 287 return ((uint8_t)color == 0xff) ? 0 : 1; |
288 } | 288 } |
289 return 0xff - (uint8_t)color; | 289 return 0xff - (uint8_t)color; |
290 } | 290 } |
291 if (GetBPP() == 1) { | 291 if (GetBPP() == 1) { |
292 return ((uint8_t)color == 0xff) ? 1 : 0; | 292 return ((uint8_t)color == 0xff) ? 1 : 0; |
293 } | 293 } |
294 return (uint8_t)color; | 294 return (uint8_t)color; |
295 } | 295 } |
296 int palsize = (1 << GetBPP()); | 296 int palsize = (1 << GetBPP()); |
297 for (int i = 0; i < palsize; i++) | 297 for (int i = 0; i < palsize; i++) |
298 if (m_pPalette[i] == color) { | 298 if (m_pPalette[i] == color) { |
299 return i; | 299 return i; |
300 } | 300 } |
301 return -1; | 301 return -1; |
302 } | 302 } |
303 void CFX_DIBitmap::Clear(FX_DWORD color) { | 303 void CFX_DIBitmap::Clear(uint32_t color) { |
304 if (!m_pBuffer) { | 304 if (!m_pBuffer) { |
305 return; | 305 return; |
306 } | 306 } |
307 switch (GetFormat()) { | 307 switch (GetFormat()) { |
308 case FXDIB_1bppMask: | 308 case FXDIB_1bppMask: |
309 FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0, | 309 FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0, |
310 m_Pitch * m_Height); | 310 m_Pitch * m_Height); |
311 break; | 311 break; |
312 case FXDIB_1bppRgb: { | 312 case FXDIB_1bppRgb: { |
313 int index = FindPalette(color); | 313 int index = FindPalette(color); |
(...skipping 24 matching lines...) Expand all Loading... |
338 for (int row = 1; row < m_Height; row++) { | 338 for (int row = 1; row < m_Height; row++) { |
339 FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch); | 339 FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch); |
340 } | 340 } |
341 } | 341 } |
342 break; | 342 break; |
343 } | 343 } |
344 case FXDIB_Rgb32: | 344 case FXDIB_Rgb32: |
345 case FXDIB_Argb: { | 345 case FXDIB_Argb: { |
346 color = IsCmykImage() ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); | 346 color = IsCmykImage() ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
347 for (int i = 0; i < m_Width; i++) { | 347 for (int i = 0; i < m_Width; i++) { |
348 ((FX_DWORD*)m_pBuffer)[i] = color; | 348 ((uint32_t*)m_pBuffer)[i] = color; |
349 } | 349 } |
350 for (int row = 1; row < m_Height; row++) { | 350 for (int row = 1; row < m_Height; row++) { |
351 FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch); | 351 FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch); |
352 } | 352 } |
353 break; | 353 break; |
354 } | 354 } |
355 default: | 355 default: |
356 break; | 356 break; |
357 } | 357 } |
358 } | 358 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 439 } |
440 } else { | 440 } else { |
441 if (m_pPalette) { | 441 if (m_pPalette) { |
442 return FALSE; | 442 return FALSE; |
443 } | 443 } |
444 if (m_bpp == 8) { | 444 if (m_bpp == 8) { |
445 dest_format = FXDIB_8bppMask; | 445 dest_format = FXDIB_8bppMask; |
446 } | 446 } |
447 uint8_t* dest_buf = | 447 uint8_t* dest_buf = |
448 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8; | 448 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8; |
449 FX_DWORD* d_plt = NULL; | 449 uint32_t* d_plt = NULL; |
450 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height, | 450 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height, |
451 pSrcBitmap, src_left, src_top, d_plt, pIccTransform)) { | 451 pSrcBitmap, src_left, src_top, d_plt, pIccTransform)) { |
452 return FALSE; | 452 return FALSE; |
453 } | 453 } |
454 } | 454 } |
455 return TRUE; | 455 return TRUE; |
456 } | 456 } |
457 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, | 457 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, |
458 int dest_top, | 458 int dest_top, |
459 int width, | 459 int width, |
460 int height, | 460 int height, |
461 const CFX_DIBSource* pMask, | 461 const CFX_DIBSource* pMask, |
462 FX_DWORD color, | 462 uint32_t color, |
463 int src_left, | 463 int src_left, |
464 int src_top, | 464 int src_top, |
465 int alpha_flag, | 465 int alpha_flag, |
466 void* pIccTransform) { | 466 void* pIccTransform) { |
467 if (!m_pBuffer) { | 467 if (!m_pBuffer) { |
468 return FALSE; | 468 return FALSE; |
469 } | 469 } |
470 ASSERT(HasAlpha() && (m_bpp >= 24)); | 470 ASSERT(HasAlpha() && (m_bpp >= 24)); |
471 ASSERT(pMask->IsAlphaMask()); | 471 ASSERT(pMask->IsAlphaMask()); |
472 if (!HasAlpha() || !pMask->IsAlphaMask() || m_bpp < 24) { | 472 if (!HasAlpha() || !pMask->IsAlphaMask() || m_bpp < 24) { |
473 return FALSE; | 473 return FALSE; |
474 } | 474 } |
475 GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(), | 475 GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(), |
476 pMask->GetHeight(), src_left, src_top, NULL); | 476 pMask->GetHeight(), src_left, src_top, NULL); |
477 if (width == 0 || height == 0) { | 477 if (width == 0 || height == 0) { |
478 return TRUE; | 478 return TRUE; |
479 } | 479 } |
480 int src_bpp = pMask->GetBPP(); | 480 int src_bpp = pMask->GetBPP(); |
481 int alpha; | 481 int alpha; |
482 FX_DWORD dst_color; | 482 uint32_t dst_color; |
483 if (alpha_flag >> 8) { | 483 if (alpha_flag >> 8) { |
484 alpha = alpha_flag & 0xff; | 484 alpha = alpha_flag & 0xff; |
485 dst_color = FXCMYK_TODIB(color); | 485 dst_color = FXCMYK_TODIB(color); |
486 } else { | 486 } else { |
487 alpha = FXARGB_A(color); | 487 alpha = FXARGB_A(color); |
488 dst_color = FXARGB_TODIB(color); | 488 dst_color = FXARGB_TODIB(color); |
489 } | 489 } |
490 uint8_t* color_p = (uint8_t*)&dst_color; | 490 uint8_t* color_p = (uint8_t*)&dst_color; |
491 if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() && | 491 if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() && |
492 CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { | 492 CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { |
493 ICodec_IccModule* pIccModule = | 493 ICodec_IccModule* pIccModule = |
494 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); | 494 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
495 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1); | 495 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1); |
496 } else { | 496 } else { |
497 if (alpha_flag >> 8 && !IsCmykImage()) { | 497 if (alpha_flag >> 8 && !IsCmykImage()) { |
498 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), | 498 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), |
499 FXSYS_GetYValue(color), FXSYS_GetKValue(color), | 499 FXSYS_GetYValue(color), FXSYS_GetKValue(color), |
500 color_p[2], color_p[1], color_p[0]); | 500 color_p[2], color_p[1], color_p[0]); |
501 } else if (!(alpha_flag >> 8) && IsCmykImage()) { | 501 } else if (!(alpha_flag >> 8) && IsCmykImage()) { |
502 return FALSE; | 502 return FALSE; |
503 } | 503 } |
504 } | 504 } |
505 if (!IsCmykImage()) { | 505 if (!IsCmykImage()) { |
506 color_p[3] = (uint8_t)alpha; | 506 color_p[3] = (uint8_t)alpha; |
507 } | 507 } |
508 if (GetFormat() == FXDIB_Argb) { | 508 if (GetFormat() == FXDIB_Argb) { |
509 for (int row = 0; row < height; row++) { | 509 for (int row = 0; row < height; row++) { |
510 FX_DWORD* dest_pos = | 510 uint32_t* dest_pos = |
511 (FX_DWORD*)(m_pBuffer + (dest_top + row) * m_Pitch + dest_left * 4); | 511 (uint32_t*)(m_pBuffer + (dest_top + row) * m_Pitch + dest_left * 4); |
512 const uint8_t* src_scan = pMask->GetScanline(src_top + row); | 512 const uint8_t* src_scan = pMask->GetScanline(src_top + row); |
513 if (src_bpp == 1) { | 513 if (src_bpp == 1) { |
514 for (int col = 0; col < width; col++) { | 514 for (int col = 0; col < width; col++) { |
515 int src_bitpos = src_left + col; | 515 int src_bitpos = src_left + col; |
516 if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8))) { | 516 if (src_scan[src_bitpos / 8] & (1 << (7 - src_bitpos % 8))) { |
517 *dest_pos = dst_color; | 517 *dest_pos = dst_color; |
518 } else { | 518 } else { |
519 *dest_pos = 0; | 519 *dest_pos = 0; |
520 } | 520 } |
521 dest_pos++; | 521 dest_pos++; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 for (int col = 0; col < width; col++) { | 556 for (int col = 0; col < width; col++) { |
557 FXSYS_memcpy(dest_color_pos, color_p, comps); | 557 FXSYS_memcpy(dest_color_pos, color_p, comps); |
558 dest_color_pos += comps; | 558 dest_color_pos += comps; |
559 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255); | 559 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255); |
560 } | 560 } |
561 } | 561 } |
562 } | 562 } |
563 } | 563 } |
564 return TRUE; | 564 return TRUE; |
565 } | 565 } |
566 void CFX_DIBSource::CopyPalette(const FX_DWORD* pSrc, FX_DWORD size) { | 566 void CFX_DIBSource::CopyPalette(const uint32_t* pSrc, uint32_t size) { |
567 if (!pSrc || GetBPP() > 8) { | 567 if (!pSrc || GetBPP() > 8) { |
568 FX_Free(m_pPalette); | 568 FX_Free(m_pPalette); |
569 m_pPalette = NULL; | 569 m_pPalette = NULL; |
570 } else { | 570 } else { |
571 FX_DWORD pal_size = 1 << GetBPP(); | 571 uint32_t pal_size = 1 << GetBPP(); |
572 if (!m_pPalette) { | 572 if (!m_pPalette) { |
573 m_pPalette = FX_Alloc(FX_DWORD, pal_size); | 573 m_pPalette = FX_Alloc(uint32_t, pal_size); |
574 } | 574 } |
575 if (pal_size > size) { | 575 if (pal_size > size) { |
576 pal_size = size; | 576 pal_size = size; |
577 } | 577 } |
578 FXSYS_memcpy(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD)); | 578 FXSYS_memcpy(m_pPalette, pSrc, pal_size * sizeof(uint32_t)); |
579 } | 579 } |
580 } | 580 } |
581 void CFX_DIBSource::GetPalette(FX_DWORD* pal, int alpha) const { | 581 void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const { |
582 ASSERT(GetBPP() <= 8 && !IsCmykImage()); | 582 ASSERT(GetBPP() <= 8 && !IsCmykImage()); |
583 if (GetBPP() == 1) { | 583 if (GetBPP() == 1) { |
584 pal[0] = | 584 pal[0] = |
585 ((m_pPalette ? m_pPalette[0] : 0xff000000) & 0xffffff) | (alpha << 24); | 585 ((m_pPalette ? m_pPalette[0] : 0xff000000) & 0xffffff) | (alpha << 24); |
586 pal[1] = | 586 pal[1] = |
587 ((m_pPalette ? m_pPalette[1] : 0xffffffff) & 0xffffff) | (alpha << 24); | 587 ((m_pPalette ? m_pPalette[1] : 0xffffffff) & 0xffffff) | (alpha << 24); |
588 return; | 588 return; |
589 } | 589 } |
590 if (m_pPalette) { | 590 if (m_pPalette) { |
591 for (int i = 0; i < 256; i++) { | 591 for (int i = 0; i < 256; i++) { |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 } else { | 1061 } else { |
1062 if (!ConvertFormat(FXDIB_Argb)) { | 1062 if (!ConvertFormat(FXDIB_Argb)) { |
1063 return FALSE; | 1063 return FALSE; |
1064 } | 1064 } |
1065 MultiplyAlpha(alpha); | 1065 MultiplyAlpha(alpha); |
1066 } | 1066 } |
1067 break; | 1067 break; |
1068 } | 1068 } |
1069 return TRUE; | 1069 return TRUE; |
1070 } | 1070 } |
1071 FX_DWORD CFX_DIBitmap::GetPixel(int x, int y) const { | 1071 uint32_t CFX_DIBitmap::GetPixel(int x, int y) const { |
1072 if (!m_pBuffer) { | 1072 if (!m_pBuffer) { |
1073 return 0; | 1073 return 0; |
1074 } | 1074 } |
1075 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; | 1075 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; |
1076 switch (GetFormat()) { | 1076 switch (GetFormat()) { |
1077 case FXDIB_1bppMask: { | 1077 case FXDIB_1bppMask: { |
1078 if ((*pos) & (1 << (7 - x % 8))) { | 1078 if ((*pos) & (1 << (7 - x % 8))) { |
1079 return 0xff000000; | 1079 return 0xff000000; |
1080 } | 1080 } |
1081 return 0; | 1081 return 0; |
(...skipping 12 matching lines...) Expand all Loading... |
1094 case FXDIB_Rgba: | 1094 case FXDIB_Rgba: |
1095 case FXDIB_Rgb32: | 1095 case FXDIB_Rgb32: |
1096 return FXARGB_GETDIB(pos) | 0xff000000; | 1096 return FXARGB_GETDIB(pos) | 0xff000000; |
1097 case FXDIB_Argb: | 1097 case FXDIB_Argb: |
1098 return FXARGB_GETDIB(pos); | 1098 return FXARGB_GETDIB(pos); |
1099 default: | 1099 default: |
1100 break; | 1100 break; |
1101 } | 1101 } |
1102 return 0; | 1102 return 0; |
1103 } | 1103 } |
1104 void CFX_DIBitmap::SetPixel(int x, int y, FX_DWORD color) { | 1104 void CFX_DIBitmap::SetPixel(int x, int y, uint32_t color) { |
1105 if (!m_pBuffer) { | 1105 if (!m_pBuffer) { |
1106 return; | 1106 return; |
1107 } | 1107 } |
1108 if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) { | 1108 if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) { |
1109 return; | 1109 return; |
1110 } | 1110 } |
1111 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; | 1111 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; |
1112 switch (GetFormat()) { | 1112 switch (GetFormat()) { |
1113 case FXDIB_1bppMask: | 1113 case FXDIB_1bppMask: |
1114 if (color >> 24) { | 1114 if (color >> 24) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 FX_BOOL bFlipX, | 1177 FX_BOOL bFlipX, |
1178 int clip_left, | 1178 int clip_left, |
1179 int clip_width) const { | 1179 int clip_width) const { |
1180 if (!m_pBuffer) { | 1180 if (!m_pBuffer) { |
1181 return; | 1181 return; |
1182 } | 1182 } |
1183 int src_Bpp = m_bpp / 8; | 1183 int src_Bpp = m_bpp / 8; |
1184 uint8_t* scanline = m_pBuffer + line * m_Pitch; | 1184 uint8_t* scanline = m_pBuffer + line * m_Pitch; |
1185 if (src_Bpp == 0) { | 1185 if (src_Bpp == 0) { |
1186 for (int i = 0; i < clip_width; i++) { | 1186 for (int i = 0; i < clip_width; i++) { |
1187 FX_DWORD dest_x = clip_left + i; | 1187 uint32_t dest_x = clip_left + i; |
1188 FX_DWORD src_x = dest_x * m_Width / dest_width; | 1188 uint32_t src_x = dest_x * m_Width / dest_width; |
1189 if (bFlipX) { | 1189 if (bFlipX) { |
1190 src_x = m_Width - src_x - 1; | 1190 src_x = m_Width - src_x - 1; |
1191 } | 1191 } |
1192 src_x %= m_Width; | 1192 src_x %= m_Width; |
1193 dest_scan[i] = (scanline[src_x / 8] & (1 << (7 - src_x % 8))) ? 255 : 0; | 1193 dest_scan[i] = (scanline[src_x / 8] & (1 << (7 - src_x % 8))) ? 255 : 0; |
1194 } | 1194 } |
1195 } else if (src_Bpp == 1) { | 1195 } else if (src_Bpp == 1) { |
1196 for (int i = 0; i < clip_width; i++) { | 1196 for (int i = 0; i < clip_width; i++) { |
1197 FX_DWORD dest_x = clip_left + i; | 1197 uint32_t dest_x = clip_left + i; |
1198 FX_DWORD src_x = dest_x * m_Width / dest_width; | 1198 uint32_t src_x = dest_x * m_Width / dest_width; |
1199 if (bFlipX) { | 1199 if (bFlipX) { |
1200 src_x = m_Width - src_x - 1; | 1200 src_x = m_Width - src_x - 1; |
1201 } | 1201 } |
1202 src_x %= m_Width; | 1202 src_x %= m_Width; |
1203 int dest_pos = i; | 1203 int dest_pos = i; |
1204 if (m_pPalette) { | 1204 if (m_pPalette) { |
1205 if (!IsCmykImage()) { | 1205 if (!IsCmykImage()) { |
1206 dest_pos *= 3; | 1206 dest_pos *= 3; |
1207 FX_ARGB argb = m_pPalette[scanline[src_x]]; | 1207 FX_ARGB argb = m_pPalette[scanline[src_x]]; |
1208 dest_scan[dest_pos] = FXARGB_B(argb); | 1208 dest_scan[dest_pos] = FXARGB_B(argb); |
1209 dest_scan[dest_pos + 1] = FXARGB_G(argb); | 1209 dest_scan[dest_pos + 1] = FXARGB_G(argb); |
1210 dest_scan[dest_pos + 2] = FXARGB_R(argb); | 1210 dest_scan[dest_pos + 2] = FXARGB_R(argb); |
1211 } else { | 1211 } else { |
1212 dest_pos *= 4; | 1212 dest_pos *= 4; |
1213 FX_CMYK cmyk = m_pPalette[scanline[src_x]]; | 1213 FX_CMYK cmyk = m_pPalette[scanline[src_x]]; |
1214 dest_scan[dest_pos] = FXSYS_GetCValue(cmyk); | 1214 dest_scan[dest_pos] = FXSYS_GetCValue(cmyk); |
1215 dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk); | 1215 dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk); |
1216 dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk); | 1216 dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk); |
1217 dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk); | 1217 dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk); |
1218 } | 1218 } |
1219 } else { | 1219 } else { |
1220 dest_scan[dest_pos] = scanline[src_x]; | 1220 dest_scan[dest_pos] = scanline[src_x]; |
1221 } | 1221 } |
1222 } | 1222 } |
1223 } else { | 1223 } else { |
1224 for (int i = 0; i < clip_width; i++) { | 1224 for (int i = 0; i < clip_width; i++) { |
1225 FX_DWORD dest_x = clip_left + i; | 1225 uint32_t dest_x = clip_left + i; |
1226 FX_DWORD src_x = | 1226 uint32_t src_x = |
1227 bFlipX ? (m_Width - dest_x * m_Width / dest_width - 1) * src_Bpp | 1227 bFlipX ? (m_Width - dest_x * m_Width / dest_width - 1) * src_Bpp |
1228 : (dest_x * m_Width / dest_width) * src_Bpp; | 1228 : (dest_x * m_Width / dest_width) * src_Bpp; |
1229 src_x %= m_Width * src_Bpp; | 1229 src_x %= m_Width * src_Bpp; |
1230 int dest_pos = i * src_Bpp; | 1230 int dest_pos = i * src_Bpp; |
1231 for (int b = 0; b < src_Bpp; b++) { | 1231 for (int b = 0; b < src_Bpp; b++) { |
1232 dest_scan[dest_pos + b] = scanline[src_x + b]; | 1232 dest_scan[dest_pos + b] = scanline[src_x + b]; |
1233 } | 1233 } |
1234 } | 1234 } |
1235 } | 1235 } |
1236 } | 1236 } |
1237 | 1237 |
1238 // TODO(weili): Split this function into two for handling CMYK and RGB | 1238 // TODO(weili): Split this function into two for handling CMYK and RGB |
1239 // colors separately. | 1239 // colors separately. |
1240 FX_BOOL CFX_DIBitmap::ConvertColorScale(FX_DWORD forecolor, | 1240 FX_BOOL CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, |
1241 FX_DWORD backcolor) { | 1241 uint32_t backcolor) { |
1242 ASSERT(!IsAlphaMask()); | 1242 ASSERT(!IsAlphaMask()); |
1243 if (!m_pBuffer || IsAlphaMask()) { | 1243 if (!m_pBuffer || IsAlphaMask()) { |
1244 return FALSE; | 1244 return FALSE; |
1245 } | 1245 } |
1246 // Values used for CMYK colors. | 1246 // Values used for CMYK colors. |
1247 int fc = 0; | 1247 int fc = 0; |
1248 int fm = 0; | 1248 int fm = 0; |
1249 int fy = 0; | 1249 int fy = 0; |
1250 int fk = 0; | 1250 int fk = 0; |
1251 int bc = 0; | 1251 int bc = 0; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); | 1364 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); |
1365 *scanline++ = bb + (fb - bb) * gray / 255; | 1365 *scanline++ = bb + (fb - bb) * gray / 255; |
1366 *scanline++ = bg + (fg - bg) * gray / 255; | 1366 *scanline++ = bg + (fg - bg) * gray / 255; |
1367 *scanline = br + (fr - br) * gray / 255; | 1367 *scanline = br + (fr - br) * gray / 255; |
1368 scanline += gap; | 1368 scanline += gap; |
1369 } | 1369 } |
1370 } | 1370 } |
1371 } | 1371 } |
1372 return TRUE; | 1372 return TRUE; |
1373 } | 1373 } |
1374 FX_BOOL CFX_DIBitmap::DitherFS(const FX_DWORD* pPalette, | 1374 FX_BOOL CFX_DIBitmap::DitherFS(const uint32_t* pPalette, |
1375 int pal_size, | 1375 int pal_size, |
1376 const FX_RECT* pRect) { | 1376 const FX_RECT* pRect) { |
1377 if (!m_pBuffer) { | 1377 if (!m_pBuffer) { |
1378 return FALSE; | 1378 return FALSE; |
1379 } | 1379 } |
1380 if (m_bpp != 8 && m_pPalette && m_AlphaFlag != 0) { | 1380 if (m_bpp != 8 && m_pPalette && m_AlphaFlag != 0) { |
1381 return FALSE; | 1381 return FALSE; |
1382 } | 1382 } |
1383 if (m_Width < 4 && m_Height < 4) { | 1383 if (m_Width < 4 && m_Height < 4) { |
1384 return FALSE; | 1384 return FALSE; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 for (int col = 0; col < m_Width; col++) { | 1491 for (int col = 0; col < m_Width; col++) { |
1492 dest_scan[0] = src_scan[0]; | 1492 dest_scan[0] = src_scan[0]; |
1493 dest_scan[1] = src_scan[1]; | 1493 dest_scan[1] = src_scan[1]; |
1494 dest_scan[2] = src_scan[2]; | 1494 dest_scan[2] = src_scan[2]; |
1495 dest_scan -= 3; | 1495 dest_scan -= 3; |
1496 src_scan += 3; | 1496 src_scan += 3; |
1497 } | 1497 } |
1498 } else { | 1498 } else { |
1499 ASSERT(Bpp == 4); | 1499 ASSERT(Bpp == 4); |
1500 for (int col = 0; col < m_Width; col++) { | 1500 for (int col = 0; col < m_Width; col++) { |
1501 *(FX_DWORD*)dest_scan = *(FX_DWORD*)src_scan; | 1501 *(uint32_t*)dest_scan = *(uint32_t*)src_scan; |
1502 dest_scan -= 4; | 1502 dest_scan -= 4; |
1503 src_scan += 4; | 1503 src_scan += 4; |
1504 } | 1504 } |
1505 } | 1505 } |
1506 } | 1506 } |
1507 } | 1507 } |
1508 if (m_pAlphaMask) { | 1508 if (m_pAlphaMask) { |
1509 pDestBuffer = pFlipped->m_pAlphaMask->GetBuffer(); | 1509 pDestBuffer = pFlipped->m_pAlphaMask->GetBuffer(); |
1510 FX_DWORD dest_pitch = pFlipped->m_pAlphaMask->GetPitch(); | 1510 uint32_t dest_pitch = pFlipped->m_pAlphaMask->GetPitch(); |
1511 for (int row = 0; row < m_Height; row++) { | 1511 for (int row = 0; row < m_Height; row++) { |
1512 const uint8_t* src_scan = m_pAlphaMask->GetScanline(row); | 1512 const uint8_t* src_scan = m_pAlphaMask->GetScanline(row); |
1513 uint8_t* dest_scan = | 1513 uint8_t* dest_scan = |
1514 pDestBuffer + dest_pitch * (bYFlip ? (m_Height - row - 1) : row); | 1514 pDestBuffer + dest_pitch * (bYFlip ? (m_Height - row - 1) : row); |
1515 if (!bXFlip) { | 1515 if (!bXFlip) { |
1516 FXSYS_memcpy(dest_scan, src_scan, dest_pitch); | 1516 FXSYS_memcpy(dest_scan, src_scan, dest_pitch); |
1517 continue; | 1517 continue; |
1518 } | 1518 } |
1519 dest_scan += (m_Width - 1); | 1519 dest_scan += (m_Width - 1); |
1520 for (int col = 0; col < m_Width; col++) { | 1520 for (int col = 0; col < m_Width; col++) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 m_bRgbByteOrder = FALSE; | 1588 m_bRgbByteOrder = FALSE; |
1589 m_BlendType = FXDIB_BLEND_NORMAL; | 1589 m_BlendType = FXDIB_BLEND_NORMAL; |
1590 } | 1590 } |
1591 CFX_ImageRenderer::~CFX_ImageRenderer() { | 1591 CFX_ImageRenderer::~CFX_ImageRenderer() { |
1592 delete m_pTransformer; | 1592 delete m_pTransformer; |
1593 } | 1593 } |
1594 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, | 1594 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, |
1595 const CFX_ClipRgn* pClipRgn, | 1595 const CFX_ClipRgn* pClipRgn, |
1596 const CFX_DIBSource* pSource, | 1596 const CFX_DIBSource* pSource, |
1597 int bitmap_alpha, | 1597 int bitmap_alpha, |
1598 FX_DWORD mask_color, | 1598 uint32_t mask_color, |
1599 const CFX_Matrix* pMatrix, | 1599 const CFX_Matrix* pMatrix, |
1600 FX_DWORD dib_flags, | 1600 uint32_t dib_flags, |
1601 FX_BOOL bRgbByteOrder, | 1601 FX_BOOL bRgbByteOrder, |
1602 int alpha_flag, | 1602 int alpha_flag, |
1603 void* pIccTransform, | 1603 void* pIccTransform, |
1604 int blend_type) { | 1604 int blend_type) { |
1605 m_Matrix = *pMatrix; | 1605 m_Matrix = *pMatrix; |
1606 CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect(); | 1606 CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect(); |
1607 FX_RECT image_rect = image_rect_f.GetOutterRect(); | 1607 FX_RECT image_rect = image_rect_f.GetOutterRect(); |
1608 m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(), | 1608 m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(), |
1609 pDevice->GetHeight()); | 1609 pDevice->GetHeight()); |
1610 m_ClipBox.Intersect(image_rect); | 1610 m_ClipBox.Intersect(image_rect); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch()); | 1741 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch()); |
1742 } | 1742 } |
1743 if (dest_alpha_buf) { | 1743 if (dest_alpha_buf) { |
1744 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha, | 1744 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha, |
1745 m_pBitmap->m_pAlphaMask->GetPitch()); | 1745 m_pBitmap->m_pAlphaMask->GetPitch()); |
1746 } | 1746 } |
1747 } | 1747 } |
1748 FX_BOOL CFX_BitmapStorer::SetInfo(int width, | 1748 FX_BOOL CFX_BitmapStorer::SetInfo(int width, |
1749 int height, | 1749 int height, |
1750 FXDIB_Format src_format, | 1750 FXDIB_Format src_format, |
1751 FX_DWORD* pSrcPalette) { | 1751 uint32_t* pSrcPalette) { |
1752 m_pBitmap = new CFX_DIBitmap; | 1752 m_pBitmap = new CFX_DIBitmap; |
1753 if (!m_pBitmap->Create(width, height, src_format)) { | 1753 if (!m_pBitmap->Create(width, height, src_format)) { |
1754 delete m_pBitmap; | 1754 delete m_pBitmap; |
1755 m_pBitmap = NULL; | 1755 m_pBitmap = NULL; |
1756 return FALSE; | 1756 return FALSE; |
1757 } | 1757 } |
1758 if (pSrcPalette) { | 1758 if (pSrcPalette) { |
1759 m_pBitmap->CopyPalette(pSrcPalette); | 1759 m_pBitmap->CopyPalette(pSrcPalette); |
1760 } | 1760 } |
1761 return TRUE; | 1761 return TRUE; |
1762 } | 1762 } |
OLD | NEW |