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

Side by Side Diff: core/fxge/dib/fx_dib_main.cpp

Issue 2477443002: Remove FX_BOOL from core (Closed)
Patch Set: Created 4 years, 1 month 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/fxge/dib/fx_dib_engine.cpp ('k') | core/fxge/dib/fx_dib_transform.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/fxge/fx_dib.h" 7 #include "core/fxge/fx_dib.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 m_Pitch(0) {} 48 m_Pitch(0) {}
49 49
50 CFX_DIBSource::~CFX_DIBSource() { 50 CFX_DIBSource::~CFX_DIBSource() {
51 delete m_pAlphaMask; 51 delete m_pAlphaMask;
52 } 52 }
53 53
54 uint8_t* CFX_DIBSource::GetBuffer() const { 54 uint8_t* CFX_DIBSource::GetBuffer() const {
55 return nullptr; 55 return nullptr;
56 } 56 }
57 57
58 FX_BOOL CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const { 58 bool CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const {
59 return FALSE; 59 return false;
60 } 60 }
61 61
62 CFX_DIBitmap::CFX_DIBitmap() { 62 CFX_DIBitmap::CFX_DIBitmap() {
63 m_bExtBuf = FALSE; 63 m_bExtBuf = false;
64 m_pBuffer = nullptr; 64 m_pBuffer = nullptr;
65 m_pPalette = nullptr; 65 m_pPalette = nullptr;
66 } 66 }
67 67
68 #define _MAX_OOM_LIMIT_ 12000000 68 #define _MAX_OOM_LIMIT_ 12000000
69 FX_BOOL CFX_DIBitmap::Create(int width, 69 bool CFX_DIBitmap::Create(int width,
70 int height, 70 int height,
71 FXDIB_Format format, 71 FXDIB_Format format,
72 uint8_t* pBuffer, 72 uint8_t* pBuffer,
73 int pitch) { 73 int pitch) {
74 m_pBuffer = nullptr; 74 m_pBuffer = nullptr;
75 m_bpp = (uint8_t)format; 75 m_bpp = (uint8_t)format;
76 m_AlphaFlag = (uint8_t)(format >> 8); 76 m_AlphaFlag = (uint8_t)(format >> 8);
77 m_Width = m_Height = m_Pitch = 0; 77 m_Width = m_Height = m_Pitch = 0;
78 if (width <= 0 || height <= 0 || pitch < 0) { 78 if (width <= 0 || height <= 0 || pitch < 0) {
79 return FALSE; 79 return false;
80 } 80 }
81 if ((INT_MAX - 31) / width < (format & 0xff)) { 81 if ((INT_MAX - 31) / width < (format & 0xff)) {
82 return FALSE; 82 return false;
83 } 83 }
84 if (!pitch) { 84 if (!pitch) {
85 pitch = (width * (format & 0xff) + 31) / 32 * 4; 85 pitch = (width * (format & 0xff) + 31) / 32 * 4;
86 } 86 }
87 if ((1 << 30) / pitch < height) { 87 if ((1 << 30) / pitch < height) {
88 return FALSE; 88 return false;
89 } 89 }
90 if (pBuffer) { 90 if (pBuffer) {
91 m_pBuffer = pBuffer; 91 m_pBuffer = pBuffer;
92 m_bExtBuf = TRUE; 92 m_bExtBuf = true;
93 } else { 93 } else {
94 int size = pitch * height + 4; 94 int size = pitch * height + 4;
95 int oomlimit = _MAX_OOM_LIMIT_; 95 int oomlimit = _MAX_OOM_LIMIT_;
96 if (oomlimit >= 0 && size >= oomlimit) { 96 if (oomlimit >= 0 && size >= oomlimit) {
97 m_pBuffer = FX_TryAlloc(uint8_t, size); 97 m_pBuffer = FX_TryAlloc(uint8_t, size);
98 if (!m_pBuffer) { 98 if (!m_pBuffer) {
99 return FALSE; 99 return false;
100 } 100 }
101 } else { 101 } else {
102 m_pBuffer = FX_Alloc(uint8_t, size); 102 m_pBuffer = FX_Alloc(uint8_t, size);
103 } 103 }
104 } 104 }
105 m_Width = width; 105 m_Width = width;
106 m_Height = height; 106 m_Height = height;
107 m_Pitch = pitch; 107 m_Pitch = pitch;
108 if (HasAlpha() && format != FXDIB_Argb) { 108 if (HasAlpha() && format != FXDIB_Argb) {
109 FX_BOOL ret = TRUE; 109 bool ret = true;
110 ret = BuildAlphaMask(); 110 ret = BuildAlphaMask();
111 if (!ret) { 111 if (!ret) {
112 if (!m_bExtBuf) { 112 if (!m_bExtBuf) {
113 FX_Free(m_pBuffer); 113 FX_Free(m_pBuffer);
114 m_pBuffer = nullptr; 114 m_pBuffer = nullptr;
115 m_Width = m_Height = m_Pitch = 0; 115 m_Width = m_Height = m_Pitch = 0;
116 return FALSE; 116 return false;
117 } 117 }
118 } 118 }
119 } 119 }
120 return TRUE; 120 return true;
121 } 121 }
122 122
123 FX_BOOL CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) { 123 bool CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) {
124 if (m_pBuffer) { 124 if (m_pBuffer) {
125 return FALSE; 125 return false;
126 } 126 }
127 if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat())) { 127 if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat())) {
128 return FALSE; 128 return false;
129 } 129 }
130 CopyPalette(pSrc->GetPalette()); 130 CopyPalette(pSrc->GetPalette());
131 CopyAlphaMask(pSrc->m_pAlphaMask); 131 CopyAlphaMask(pSrc->m_pAlphaMask);
132 for (int row = 0; row < pSrc->GetHeight(); row++) { 132 for (int row = 0; row < pSrc->GetHeight(); row++) {
133 FXSYS_memcpy(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch); 133 FXSYS_memcpy(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch);
134 } 134 }
135 return TRUE; 135 return true;
136 } 136 }
137 137
138 CFX_DIBitmap::~CFX_DIBitmap() { 138 CFX_DIBitmap::~CFX_DIBitmap() {
139 if (!m_bExtBuf) 139 if (!m_bExtBuf)
140 FX_Free(m_pBuffer); 140 FX_Free(m_pBuffer);
141 141
142 m_pBuffer = nullptr; 142 m_pBuffer = nullptr;
143 } 143 }
144 144
145 uint8_t* CFX_DIBitmap::GetBuffer() const { 145 uint8_t* CFX_DIBitmap::GetBuffer() const {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 m_pPalette.get()[i] = 0xff - i; 228 m_pPalette.get()[i] = 0xff - i;
229 } 229 }
230 } else { 230 } else {
231 for (int i = 0; i < 256; i++) { 231 for (int i = 0; i < 256; i++) {
232 m_pPalette.get()[i] = 0xff000000 | (i * 0x10101); 232 m_pPalette.get()[i] = 0xff000000 | (i * 0x10101);
233 } 233 }
234 } 234 }
235 } 235 }
236 } 236 }
237 237
238 FX_BOOL CFX_DIBSource::BuildAlphaMask() { 238 bool CFX_DIBSource::BuildAlphaMask() {
239 if (m_pAlphaMask) { 239 if (m_pAlphaMask) {
240 return TRUE; 240 return true;
241 } 241 }
242 m_pAlphaMask = new CFX_DIBitmap; 242 m_pAlphaMask = new CFX_DIBitmap;
243 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 243 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
244 delete m_pAlphaMask; 244 delete m_pAlphaMask;
245 m_pAlphaMask = nullptr; 245 m_pAlphaMask = nullptr;
246 return FALSE; 246 return false;
247 } 247 }
248 FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff, 248 FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff,
249 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch()); 249 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
250 return TRUE; 250 return true;
251 } 251 }
252 252
253 uint32_t CFX_DIBSource::GetPaletteEntry(int index) const { 253 uint32_t CFX_DIBSource::GetPaletteEntry(int index) const {
254 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 254 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
255 if (m_pPalette) { 255 if (m_pPalette) {
256 return m_pPalette.get()[index]; 256 return m_pPalette.get()[index];
257 } 257 }
258 if (IsCmykImage()) { 258 if (IsCmykImage()) {
259 if (GetBPP() == 1) { 259 if (GetBPP() == 1) {
260 return index ? 0 : 0xff; 260 return index ? 0 : 0xff;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 dest_rect.Intersect(pClipRgn->GetBox()); 390 dest_rect.Intersect(pClipRgn->GetBox());
391 } 391 }
392 dest_left = dest_rect.left; 392 dest_left = dest_rect.left;
393 dest_top = dest_rect.top; 393 dest_top = dest_rect.top;
394 src_left = dest_left - x_offset; 394 src_left = dest_left - x_offset;
395 src_top = dest_top - y_offset; 395 src_top = dest_top - y_offset;
396 width = dest_rect.right - dest_rect.left; 396 width = dest_rect.right - dest_rect.left;
397 height = dest_rect.bottom - dest_rect.top; 397 height = dest_rect.bottom - dest_rect.top;
398 } 398 }
399 399
400 FX_BOOL CFX_DIBitmap::TransferBitmap(int dest_left, 400 bool CFX_DIBitmap::TransferBitmap(int dest_left,
401 int dest_top, 401 int dest_top,
402 int width, 402 int width,
403 int height, 403 int height,
404 const CFX_DIBSource* pSrcBitmap, 404 const CFX_DIBSource* pSrcBitmap,
405 int src_left, 405 int src_left,
406 int src_top) { 406 int src_top) {
407 if (!m_pBuffer) 407 if (!m_pBuffer)
408 return FALSE; 408 return false;
409 409
410 GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(), 410 GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(),
411 pSrcBitmap->GetHeight(), src_left, src_top, nullptr); 411 pSrcBitmap->GetHeight(), src_left, src_top, nullptr);
412 if (width == 0 || height == 0) 412 if (width == 0 || height == 0)
413 return TRUE; 413 return true;
414 414
415 FXDIB_Format dest_format = GetFormat(); 415 FXDIB_Format dest_format = GetFormat();
416 FXDIB_Format src_format = pSrcBitmap->GetFormat(); 416 FXDIB_Format src_format = pSrcBitmap->GetFormat();
417 if (dest_format == src_format) { 417 if (dest_format == src_format) {
418 if (GetBPP() == 1) { 418 if (GetBPP() == 1) {
419 for (int row = 0; row < height; row++) { 419 for (int row = 0; row < height; row++) {
420 uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch; 420 uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch;
421 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); 421 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
422 for (int col = 0; col < width; col++) { 422 for (int col = 0; col < width; col++) {
423 if (src_scan[(src_left + col) / 8] & 423 if (src_scan[(src_left + col) / 8] &
(...skipping 11 matching lines...) Expand all
435 for (int row = 0; row < height; row++) { 435 for (int row = 0; row < height; row++) {
436 uint8_t* dest_scan = 436 uint8_t* dest_scan =
437 m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp; 437 m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp;
438 const uint8_t* src_scan = 438 const uint8_t* src_scan =
439 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; 439 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
440 FXSYS_memcpy(dest_scan, src_scan, width * Bpp); 440 FXSYS_memcpy(dest_scan, src_scan, width * Bpp);
441 } 441 }
442 } 442 }
443 } else { 443 } else {
444 if (m_pPalette) 444 if (m_pPalette)
445 return FALSE; 445 return false;
446 446
447 if (m_bpp == 8) 447 if (m_bpp == 8)
448 dest_format = FXDIB_8bppMask; 448 dest_format = FXDIB_8bppMask;
449 449
450 uint8_t* dest_buf = 450 uint8_t* dest_buf =
451 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8; 451 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8;
452 std::unique_ptr<uint32_t, FxFreeDeleter> d_plt; 452 std::unique_ptr<uint32_t, FxFreeDeleter> d_plt;
453 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height, 453 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height,
454 pSrcBitmap, src_left, src_top, &d_plt)) { 454 pSrcBitmap, src_left, src_top, &d_plt)) {
455 return FALSE; 455 return false;
456 } 456 }
457 } 457 }
458 return TRUE; 458 return true;
459 } 459 }
460 460
461 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, 461 bool CFX_DIBitmap::TransferMask(int dest_left,
462 int dest_top, 462 int dest_top,
463 int width, 463 int width,
464 int height, 464 int height,
465 const CFX_DIBSource* pMask, 465 const CFX_DIBSource* pMask,
466 uint32_t color, 466 uint32_t color,
467 int src_left, 467 int src_left,
468 int src_top, 468 int src_top,
469 int alpha_flag, 469 int alpha_flag,
470 void* pIccTransform) { 470 void* pIccTransform) {
471 if (!m_pBuffer) { 471 if (!m_pBuffer) {
472 return FALSE; 472 return false;
473 } 473 }
474 ASSERT(HasAlpha() && (m_bpp >= 24)); 474 ASSERT(HasAlpha() && (m_bpp >= 24));
475 ASSERT(pMask->IsAlphaMask()); 475 ASSERT(pMask->IsAlphaMask());
476 if (!HasAlpha() || !pMask->IsAlphaMask() || m_bpp < 24) { 476 if (!HasAlpha() || !pMask->IsAlphaMask() || m_bpp < 24) {
477 return FALSE; 477 return false;
478 } 478 }
479 GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(), 479 GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(),
480 pMask->GetHeight(), src_left, src_top, nullptr); 480 pMask->GetHeight(), src_left, src_top, nullptr);
481 if (width == 0 || height == 0) { 481 if (width == 0 || height == 0) {
482 return TRUE; 482 return true;
483 } 483 }
484 int src_bpp = pMask->GetBPP(); 484 int src_bpp = pMask->GetBPP();
485 int alpha; 485 int alpha;
486 uint32_t dst_color; 486 uint32_t dst_color;
487 if (alpha_flag >> 8) { 487 if (alpha_flag >> 8) {
488 alpha = alpha_flag & 0xff; 488 alpha = alpha_flag & 0xff;
489 dst_color = FXCMYK_TODIB(color); 489 dst_color = FXCMYK_TODIB(color);
490 } else { 490 } else {
491 alpha = FXARGB_A(color); 491 alpha = FXARGB_A(color);
492 dst_color = FXARGB_TODIB(color); 492 dst_color = FXARGB_TODIB(color);
493 } 493 }
494 uint8_t* color_p = (uint8_t*)&dst_color; 494 uint8_t* color_p = (uint8_t*)&dst_color;
495 if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() && 495 if (pIccTransform && CFX_GEModule::Get()->GetCodecModule() &&
496 CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { 496 CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
497 CCodec_IccModule* pIccModule = 497 CCodec_IccModule* pIccModule =
498 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); 498 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
499 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1); 499 pIccModule->TranslateScanline(pIccTransform, color_p, color_p, 1);
500 } else { 500 } else {
501 if (alpha_flag >> 8 && !IsCmykImage()) { 501 if (alpha_flag >> 8 && !IsCmykImage()) {
502 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), 502 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
503 FXSYS_GetYValue(color), FXSYS_GetKValue(color), 503 FXSYS_GetYValue(color), FXSYS_GetKValue(color),
504 color_p[2], color_p[1], color_p[0]); 504 color_p[2], color_p[1], color_p[0]);
505 } else if (!(alpha_flag >> 8) && IsCmykImage()) { 505 } else if (!(alpha_flag >> 8) && IsCmykImage()) {
506 return FALSE; 506 return false;
507 } 507 }
508 } 508 }
509 if (!IsCmykImage()) { 509 if (!IsCmykImage()) {
510 color_p[3] = (uint8_t)alpha; 510 color_p[3] = (uint8_t)alpha;
511 } 511 }
512 if (GetFormat() == FXDIB_Argb) { 512 if (GetFormat() == FXDIB_Argb) {
513 for (int row = 0; row < height; row++) { 513 for (int row = 0; row < height; row++) {
514 uint32_t* dest_pos = 514 uint32_t* dest_pos =
515 (uint32_t*)(m_pBuffer + (dest_top + row) * m_Pitch + dest_left * 4); 515 (uint32_t*)(m_pBuffer + (dest_top + row) * m_Pitch + dest_left * 4);
516 const uint8_t* src_scan = pMask->GetScanline(src_top + row); 516 const uint8_t* src_scan = pMask->GetScanline(src_top + row);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } else { 558 } else {
559 src_scan += src_left; 559 src_scan += src_left;
560 for (int col = 0; col < width; col++) { 560 for (int col = 0; col < width; col++) {
561 FXSYS_memcpy(dest_color_pos, color_p, comps); 561 FXSYS_memcpy(dest_color_pos, color_p, comps);
562 dest_color_pos += comps; 562 dest_color_pos += comps;
563 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255); 563 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255);
564 } 564 }
565 } 565 }
566 } 566 }
567 } 567 }
568 return TRUE; 568 return true;
569 } 569 }
570 570
571 void CFX_DIBSource::CopyPalette(const uint32_t* pSrc) { 571 void CFX_DIBSource::CopyPalette(const uint32_t* pSrc) {
572 static const uint32_t kPaletteSize = 256; 572 static const uint32_t kPaletteSize = 256;
573 573
574 if (!pSrc || GetBPP() > 8) { 574 if (!pSrc || GetBPP() > 8) {
575 m_pPalette.reset(); 575 m_pPalette.reset();
576 } else { 576 } else {
577 uint32_t pal_size = 1 << GetBPP(); 577 uint32_t pal_size = 1 << GetBPP();
578 if (!m_pPalette) 578 if (!m_pPalette)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 const uint8_t* src_scan = GetScanline(row) + rect.left * 4 + 3; 620 const uint8_t* src_scan = GetScanline(row) + rect.left * 4 + 3;
621 uint8_t* dest_scan = (uint8_t*)pMask->GetScanline(row - rect.top); 621 uint8_t* dest_scan = (uint8_t*)pMask->GetScanline(row - rect.top);
622 for (int col = rect.left; col < rect.right; col++) { 622 for (int col = rect.left; col < rect.right; col++) {
623 *dest_scan++ = *src_scan; 623 *dest_scan++ = *src_scan;
624 src_scan += 4; 624 src_scan += 4;
625 } 625 }
626 } 626 }
627 return pMask; 627 return pMask;
628 } 628 }
629 629
630 FX_BOOL CFX_DIBSource::CopyAlphaMask(const CFX_DIBSource* pAlphaMask, 630 bool CFX_DIBSource::CopyAlphaMask(const CFX_DIBSource* pAlphaMask,
631 const FX_RECT* pClip) { 631 const FX_RECT* pClip) {
632 if (!HasAlpha() || GetFormat() == FXDIB_Argb) { 632 if (!HasAlpha() || GetFormat() == FXDIB_Argb) {
633 return FALSE; 633 return false;
634 } 634 }
635 if (pAlphaMask) { 635 if (pAlphaMask) {
636 FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height); 636 FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height);
637 if (pClip) { 637 if (pClip) {
638 rect.Intersect(*pClip); 638 rect.Intersect(*pClip);
639 if (rect.IsEmpty() || rect.Width() != m_Width || 639 if (rect.IsEmpty() || rect.Width() != m_Width ||
640 rect.Height() != m_Height) { 640 rect.Height() != m_Height) {
641 return FALSE; 641 return false;
642 } 642 }
643 } else { 643 } else {
644 if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height) { 644 if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height) {
645 return FALSE; 645 return false;
646 } 646 }
647 } 647 }
648 for (int row = 0; row < m_Height; row++) 648 for (int row = 0; row < m_Height; row++)
649 FXSYS_memcpy((void*)m_pAlphaMask->GetScanline(row), 649 FXSYS_memcpy((void*)m_pAlphaMask->GetScanline(row),
650 pAlphaMask->GetScanline(row + rect.top) + rect.left, 650 pAlphaMask->GetScanline(row + rect.top) + rect.left,
651 m_pAlphaMask->m_Pitch); 651 m_pAlphaMask->m_Pitch);
652 } else { 652 } else {
653 m_pAlphaMask->Clear(0xff000000); 653 m_pAlphaMask->Clear(0xff000000);
654 } 654 }
655 return TRUE; 655 return true;
656 } 656 }
657 657
658 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3}; 658 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
659 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, 659 bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
660 const CFX_DIBSource* pSrcBitmap, 660 const CFX_DIBSource* pSrcBitmap,
661 FXDIB_Channel srcChannel) { 661 FXDIB_Channel srcChannel) {
662 if (!m_pBuffer) { 662 if (!m_pBuffer) {
663 return FALSE; 663 return false;
664 } 664 }
665 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap; 665 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap;
666 CFX_DIBitmap* pDst = this; 666 CFX_DIBitmap* pDst = this;
667 int destOffset, srcOffset; 667 int destOffset, srcOffset;
668 if (srcChannel == FXDIB_Alpha) { 668 if (srcChannel == FXDIB_Alpha) {
669 if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) { 669 if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) {
670 return FALSE; 670 return false;
671 } 671 }
672 if (pSrcBitmap->GetBPP() == 1) { 672 if (pSrcBitmap->GetBPP() == 1) {
673 pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask); 673 pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask);
674 if (!pSrcClone) { 674 if (!pSrcClone) {
675 return FALSE; 675 return false;
676 } 676 }
677 } 677 }
678 if (pSrcBitmap->GetFormat() == FXDIB_Argb) { 678 if (pSrcBitmap->GetFormat() == FXDIB_Argb) {
679 srcOffset = 3; 679 srcOffset = 3;
680 } else { 680 } else {
681 srcOffset = 0; 681 srcOffset = 0;
682 } 682 }
683 } else { 683 } else {
684 if (pSrcBitmap->IsAlphaMask()) { 684 if (pSrcBitmap->IsAlphaMask()) {
685 return FALSE; 685 return false;
686 } 686 }
687 if (pSrcBitmap->GetBPP() < 24) { 687 if (pSrcBitmap->GetBPP() < 24) {
688 if (pSrcBitmap->IsCmykImage()) { 688 if (pSrcBitmap->IsCmykImage()) {
689 pSrcClone = pSrcBitmap->CloneConvert( 689 pSrcClone = pSrcBitmap->CloneConvert(
690 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20)); 690 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20));
691 } else { 691 } else {
692 pSrcClone = pSrcBitmap->CloneConvert( 692 pSrcClone = pSrcBitmap->CloneConvert(
693 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18)); 693 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18));
694 } 694 }
695 if (!pSrcClone) { 695 if (!pSrcClone) {
696 return FALSE; 696 return false;
697 } 697 }
698 } 698 }
699 srcOffset = g_ChannelOffset[srcChannel]; 699 srcOffset = g_ChannelOffset[srcChannel];
700 } 700 }
701 if (destChannel == FXDIB_Alpha) { 701 if (destChannel == FXDIB_Alpha) {
702 if (IsAlphaMask()) { 702 if (IsAlphaMask()) {
703 if (!ConvertFormat(FXDIB_8bppMask)) { 703 if (!ConvertFormat(FXDIB_8bppMask)) {
704 if (pSrcClone != pSrcBitmap) { 704 if (pSrcClone != pSrcBitmap) {
705 delete pSrcClone; 705 delete pSrcClone;
706 } 706 }
707 return FALSE; 707 return false;
708 } 708 }
709 destOffset = 0; 709 destOffset = 0;
710 } else { 710 } else {
711 destOffset = 0; 711 destOffset = 0;
712 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) { 712 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
713 if (pSrcClone != pSrcBitmap) { 713 if (pSrcClone != pSrcBitmap) {
714 delete pSrcClone; 714 delete pSrcClone;
715 } 715 }
716 return FALSE; 716 return false;
717 } 717 }
718 if (GetFormat() == FXDIB_Argb) { 718 if (GetFormat() == FXDIB_Argb) {
719 destOffset = 3; 719 destOffset = 3;
720 } 720 }
721 } 721 }
722 } else { 722 } else {
723 if (IsAlphaMask()) { 723 if (IsAlphaMask()) {
724 if (pSrcClone != pSrcBitmap) { 724 if (pSrcClone != pSrcBitmap) {
725 delete pSrcClone; 725 delete pSrcClone;
726 } 726 }
727 return FALSE; 727 return false;
728 } 728 }
729 if (GetBPP() < 24) { 729 if (GetBPP() < 24) {
730 if (HasAlpha()) { 730 if (HasAlpha()) {
731 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) { 731 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
732 if (pSrcClone != pSrcBitmap) { 732 if (pSrcClone != pSrcBitmap) {
733 delete pSrcClone; 733 delete pSrcClone;
734 } 734 }
735 return FALSE; 735 return false;
736 } 736 }
737 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 737 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
738 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) { 738 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
739 #else 739 #else
740 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) { 740 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
741 #endif 741 #endif
742 if (pSrcClone != pSrcBitmap) { 742 if (pSrcClone != pSrcBitmap) {
743 delete pSrcClone; 743 delete pSrcClone;
744 } 744 }
745 return FALSE; 745 return false;
746 } 746 }
747 } 747 }
748 destOffset = g_ChannelOffset[destChannel]; 748 destOffset = g_ChannelOffset[destChannel];
749 } 749 }
750 if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) { 750 if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
751 CFX_DIBitmap* pAlphaMask = pSrcClone->m_pAlphaMask; 751 CFX_DIBitmap* pAlphaMask = pSrcClone->m_pAlphaMask;
752 if (pSrcClone->GetWidth() != m_Width || 752 if (pSrcClone->GetWidth() != m_Width ||
753 pSrcClone->GetHeight() != m_Height) { 753 pSrcClone->GetHeight() != m_Height) {
754 if (pAlphaMask) { 754 if (pAlphaMask) {
755 pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height); 755 pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height);
756 if (!pAlphaMask) { 756 if (!pAlphaMask) {
757 if (pSrcClone != pSrcBitmap) { 757 if (pSrcClone != pSrcBitmap) {
758 delete pSrcClone; 758 delete pSrcClone;
759 } 759 }
760 return FALSE; 760 return false;
761 } 761 }
762 } 762 }
763 } 763 }
764 if (pSrcClone != pSrcBitmap) { 764 if (pSrcClone != pSrcBitmap) {
765 pSrcClone->m_pAlphaMask = nullptr; 765 pSrcClone->m_pAlphaMask = nullptr;
766 delete pSrcClone; 766 delete pSrcClone;
767 } 767 }
768 pSrcClone = pAlphaMask; 768 pSrcClone = pAlphaMask;
769 srcOffset = 0; 769 srcOffset = 0;
770 } else if (pSrcClone->GetWidth() != m_Width || 770 } else if (pSrcClone->GetWidth() != m_Width ||
771 pSrcClone->GetHeight() != m_Height) { 771 pSrcClone->GetHeight() != m_Height) {
772 CFX_DIBitmap* pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height); 772 CFX_DIBitmap* pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height);
773 if (pSrcClone != pSrcBitmap) { 773 if (pSrcClone != pSrcBitmap) {
774 delete pSrcClone; 774 delete pSrcClone;
775 } 775 }
776 if (!pSrcMatched) { 776 if (!pSrcMatched) {
777 return FALSE; 777 return false;
778 } 778 }
779 pSrcClone = pSrcMatched; 779 pSrcClone = pSrcMatched;
780 } 780 }
781 if (destChannel == FXDIB_Alpha && m_pAlphaMask) { 781 if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
782 pDst = m_pAlphaMask; 782 pDst = m_pAlphaMask;
783 destOffset = 0; 783 destOffset = 0;
784 } 784 }
785 int srcBytes = pSrcClone->GetBPP() / 8; 785 int srcBytes = pSrcClone->GetBPP() / 8;
786 int destBytes = pDst->GetBPP() / 8; 786 int destBytes = pDst->GetBPP() / 8;
787 for (int row = 0; row < m_Height; row++) { 787 for (int row = 0; row < m_Height; row++) {
788 uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset; 788 uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset;
789 const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset; 789 const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset;
790 for (int col = 0; col < m_Width; col++) { 790 for (int col = 0; col < m_Width; col++) {
791 *dest_pos = *src_pos; 791 *dest_pos = *src_pos;
792 dest_pos += destBytes; 792 dest_pos += destBytes;
793 src_pos += srcBytes; 793 src_pos += srcBytes;
794 } 794 }
795 } 795 }
796 if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) { 796 if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) {
797 delete pSrcClone; 797 delete pSrcClone;
798 } 798 }
799 return TRUE; 799 return true;
800 } 800 }
801 801
802 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) { 802 bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
803 if (!m_pBuffer) { 803 if (!m_pBuffer) {
804 return FALSE; 804 return false;
805 } 805 }
806 int destOffset; 806 int destOffset;
807 if (destChannel == FXDIB_Alpha) { 807 if (destChannel == FXDIB_Alpha) {
808 if (IsAlphaMask()) { 808 if (IsAlphaMask()) {
809 if (!ConvertFormat(FXDIB_8bppMask)) { 809 if (!ConvertFormat(FXDIB_8bppMask)) {
810 return FALSE; 810 return false;
811 } 811 }
812 destOffset = 0; 812 destOffset = 0;
813 } else { 813 } else {
814 destOffset = 0; 814 destOffset = 0;
815 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) { 815 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
816 return FALSE; 816 return false;
817 } 817 }
818 if (GetFormat() == FXDIB_Argb) { 818 if (GetFormat() == FXDIB_Argb) {
819 destOffset = 3; 819 destOffset = 3;
820 } 820 }
821 } 821 }
822 } else { 822 } else {
823 if (IsAlphaMask()) { 823 if (IsAlphaMask()) {
824 return FALSE; 824 return false;
825 } 825 }
826 if (GetBPP() < 24) { 826 if (GetBPP() < 24) {
827 if (HasAlpha()) { 827 if (HasAlpha()) {
828 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) { 828 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
829 return FALSE; 829 return false;
830 } 830 }
831 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 831 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
832 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) { 832 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
833 #else 833 #else
834 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) { 834 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
835 #endif 835 #endif
836 return FALSE; 836 return false;
837 } 837 }
838 } 838 }
839 destOffset = g_ChannelOffset[destChannel]; 839 destOffset = g_ChannelOffset[destChannel];
840 } 840 }
841 int Bpp = GetBPP() / 8; 841 int Bpp = GetBPP() / 8;
842 if (Bpp == 1) { 842 if (Bpp == 1) {
843 FXSYS_memset(m_pBuffer, value, m_Height * m_Pitch); 843 FXSYS_memset(m_pBuffer, value, m_Height * m_Pitch);
844 return TRUE; 844 return true;
845 } 845 }
846 if (destChannel == FXDIB_Alpha && m_pAlphaMask) { 846 if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
847 FXSYS_memset(m_pAlphaMask->GetBuffer(), value, 847 FXSYS_memset(m_pAlphaMask->GetBuffer(), value,
848 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch()); 848 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
849 return TRUE; 849 return true;
850 } 850 }
851 for (int row = 0; row < m_Height; row++) { 851 for (int row = 0; row < m_Height; row++) {
852 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset; 852 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset;
853 for (int col = 0; col < m_Width; col++) { 853 for (int col = 0; col < m_Width; col++) {
854 *scan_line = value; 854 *scan_line = value;
855 scan_line += Bpp; 855 scan_line += Bpp;
856 } 856 }
857 } 857 }
858 return TRUE; 858 return true;
859 } 859 }
860 860
861 FX_BOOL CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) { 861 bool CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) {
862 if (!m_pBuffer) { 862 if (!m_pBuffer) {
863 return FALSE; 863 return false;
864 } 864 }
865 ASSERT(pSrcBitmap->IsAlphaMask()); 865 ASSERT(pSrcBitmap->IsAlphaMask());
866 if (!pSrcBitmap->IsAlphaMask()) { 866 if (!pSrcBitmap->IsAlphaMask()) {
867 return FALSE; 867 return false;
868 } 868 }
869 if (!IsAlphaMask() && !HasAlpha()) { 869 if (!IsAlphaMask() && !HasAlpha()) {
870 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha); 870 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
871 } 871 }
872 CFX_DIBitmap* pSrcClone = (CFX_DIBitmap*)pSrcBitmap; 872 CFX_DIBitmap* pSrcClone = (CFX_DIBitmap*)pSrcBitmap;
873 if (pSrcBitmap->GetWidth() != m_Width || 873 if (pSrcBitmap->GetWidth() != m_Width ||
874 pSrcBitmap->GetHeight() != m_Height) { 874 pSrcBitmap->GetHeight() != m_Height) {
875 pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height); 875 pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
876 if (!pSrcClone) { 876 if (!pSrcClone) {
877 return FALSE; 877 return false;
878 } 878 }
879 } 879 }
880 if (IsAlphaMask()) { 880 if (IsAlphaMask()) {
881 if (!ConvertFormat(FXDIB_8bppMask)) { 881 if (!ConvertFormat(FXDIB_8bppMask)) {
882 if (pSrcClone != pSrcBitmap) { 882 if (pSrcClone != pSrcBitmap) {
883 delete pSrcClone; 883 delete pSrcClone;
884 } 884 }
885 return FALSE; 885 return false;
886 } 886 }
887 for (int row = 0; row < m_Height; row++) { 887 for (int row = 0; row < m_Height; row++) {
888 uint8_t* dest_scan = m_pBuffer + m_Pitch * row; 888 uint8_t* dest_scan = m_pBuffer + m_Pitch * row;
889 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row; 889 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
890 if (pSrcClone->GetBPP() == 1) { 890 if (pSrcClone->GetBPP() == 1) {
891 for (int col = 0; col < m_Width; col++) { 891 for (int col = 0; col < m_Width; col++) {
892 if (!((1 << (7 - col % 8)) & src_scan[col / 8])) { 892 if (!((1 << (7 - col % 8)) & src_scan[col / 8])) {
893 dest_scan[col] = 0; 893 dest_scan[col] = 0;
894 } 894 }
895 } 895 }
896 } else { 896 } else {
897 for (int col = 0; col < m_Width; col++) { 897 for (int col = 0; col < m_Width; col++) {
898 *dest_scan = (*dest_scan) * src_scan[col] / 255; 898 *dest_scan = (*dest_scan) * src_scan[col] / 255;
899 dest_scan++; 899 dest_scan++;
900 } 900 }
901 } 901 }
902 } 902 }
903 } else { 903 } else {
904 if (GetFormat() == FXDIB_Argb) { 904 if (GetFormat() == FXDIB_Argb) {
905 if (pSrcClone->GetBPP() == 1) { 905 if (pSrcClone->GetBPP() == 1) {
906 if (pSrcClone != pSrcBitmap) { 906 if (pSrcClone != pSrcBitmap) {
907 delete pSrcClone; 907 delete pSrcClone;
908 } 908 }
909 return FALSE; 909 return false;
910 } 910 }
911 for (int row = 0; row < m_Height; row++) { 911 for (int row = 0; row < m_Height; row++) {
912 uint8_t* dest_scan = m_pBuffer + m_Pitch * row + 3; 912 uint8_t* dest_scan = m_pBuffer + m_Pitch * row + 3;
913 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row; 913 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
914 for (int col = 0; col < m_Width; col++) { 914 for (int col = 0; col < m_Width; col++) {
915 *dest_scan = (*dest_scan) * src_scan[col] / 255; 915 *dest_scan = (*dest_scan) * src_scan[col] / 255;
916 dest_scan += 4; 916 dest_scan += 4;
917 } 917 }
918 } 918 }
919 } else { 919 } else {
920 m_pAlphaMask->MultiplyAlpha(pSrcClone); 920 m_pAlphaMask->MultiplyAlpha(pSrcClone);
921 } 921 }
922 } 922 }
923 if (pSrcClone != pSrcBitmap) { 923 if (pSrcClone != pSrcBitmap) {
924 delete pSrcClone; 924 delete pSrcClone;
925 } 925 }
926 return TRUE; 926 return true;
927 } 927 }
928 928
929 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) { 929 bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
930 if (!m_pBuffer) { 930 if (!m_pBuffer) {
931 return FALSE; 931 return false;
932 } 932 }
933 switch (GetFormat()) { 933 switch (GetFormat()) {
934 case FXDIB_1bppRgb: { 934 case FXDIB_1bppRgb: {
935 if (!m_pPalette) { 935 if (!m_pPalette) {
936 return FALSE; 936 return false;
937 } 937 }
938 uint8_t gray[2]; 938 uint8_t gray[2];
939 for (int i = 0; i < 2; i++) { 939 for (int i = 0; i < 2; i++) {
940 int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16); 940 int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
941 int g = static_cast<uint8_t>(m_pPalette.get()[i] >> 8); 941 int g = static_cast<uint8_t>(m_pPalette.get()[i] >> 8);
942 int b = static_cast<uint8_t>(m_pPalette.get()[i]); 942 int b = static_cast<uint8_t>(m_pPalette.get()[i]);
943 gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b)); 943 gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
944 } 944 }
945 CFX_DIBitmap* pMask = new CFX_DIBitmap; 945 CFX_DIBitmap* pMask = new CFX_DIBitmap;
946 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 946 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
947 delete pMask; 947 delete pMask;
948 return FALSE; 948 return false;
949 } 949 }
950 FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height); 950 FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height);
951 for (int row = 0; row < m_Height; row++) { 951 for (int row = 0; row < m_Height; row++) {
952 uint8_t* src_pos = m_pBuffer + row * m_Pitch; 952 uint8_t* src_pos = m_pBuffer + row * m_Pitch;
953 uint8_t* dest_pos = (uint8_t*)pMask->GetScanline(row); 953 uint8_t* dest_pos = (uint8_t*)pMask->GetScanline(row);
954 for (int col = 0; col < m_Width; col++) { 954 for (int col = 0; col < m_Width; col++) {
955 if (src_pos[col / 8] & (1 << (7 - col % 8))) { 955 if (src_pos[col / 8] & (1 << (7 - col % 8))) {
956 *dest_pos = gray[1]; 956 *dest_pos = gray[1];
957 } 957 }
958 dest_pos++; 958 dest_pos++;
959 } 959 }
960 } 960 }
961 TakeOver(pMask); 961 TakeOver(pMask);
962 delete pMask; 962 delete pMask;
963 break; 963 break;
964 } 964 }
965 case FXDIB_8bppRgb: { 965 case FXDIB_8bppRgb: {
966 if (!m_pPalette) { 966 if (!m_pPalette) {
967 return FALSE; 967 return false;
968 } 968 }
969 uint8_t gray[256]; 969 uint8_t gray[256];
970 for (int i = 0; i < 256; i++) { 970 for (int i = 0; i < 256; i++) {
971 int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16); 971 int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
972 int g = static_cast<uint8_t>(m_pPalette.get()[i] >> 8); 972 int g = static_cast<uint8_t>(m_pPalette.get()[i] >> 8);
973 int b = static_cast<uint8_t>(m_pPalette.get()[i]); 973 int b = static_cast<uint8_t>(m_pPalette.get()[i]);
974 gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b)); 974 gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
975 } 975 }
976 CFX_DIBitmap* pMask = new CFX_DIBitmap; 976 CFX_DIBitmap* pMask = new CFX_DIBitmap;
977 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 977 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
978 delete pMask; 978 delete pMask;
979 return FALSE; 979 return false;
980 } 980 }
981 for (int row = 0; row < m_Height; row++) { 981 for (int row = 0; row < m_Height; row++) {
982 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch(); 982 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
983 uint8_t* src_pos = m_pBuffer + row * m_Pitch; 983 uint8_t* src_pos = m_pBuffer + row * m_Pitch;
984 for (int col = 0; col < m_Width; col++) { 984 for (int col = 0; col < m_Width; col++) {
985 *dest_pos++ = gray[*src_pos++]; 985 *dest_pos++ = gray[*src_pos++];
986 } 986 }
987 } 987 }
988 TakeOver(pMask); 988 TakeOver(pMask);
989 delete pMask; 989 delete pMask;
990 break; 990 break;
991 } 991 }
992 case FXDIB_Rgb: { 992 case FXDIB_Rgb: {
993 CFX_DIBitmap* pMask = new CFX_DIBitmap; 993 CFX_DIBitmap* pMask = new CFX_DIBitmap;
994 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 994 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
995 delete pMask; 995 delete pMask;
996 return FALSE; 996 return false;
997 } 997 }
998 for (int row = 0; row < m_Height; row++) { 998 for (int row = 0; row < m_Height; row++) {
999 uint8_t* src_pos = m_pBuffer + row * m_Pitch; 999 uint8_t* src_pos = m_pBuffer + row * m_Pitch;
1000 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch(); 1000 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
1001 for (int col = 0; col < m_Width; col++) { 1001 for (int col = 0; col < m_Width; col++) {
1002 *dest_pos++ = FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos); 1002 *dest_pos++ = FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos);
1003 src_pos += 3; 1003 src_pos += 3;
1004 } 1004 }
1005 } 1005 }
1006 TakeOver(pMask); 1006 TakeOver(pMask);
1007 delete pMask; 1007 delete pMask;
1008 break; 1008 break;
1009 } 1009 }
1010 case FXDIB_Rgb32: { 1010 case FXDIB_Rgb32: {
1011 CFX_DIBitmap* pMask = new CFX_DIBitmap; 1011 CFX_DIBitmap* pMask = new CFX_DIBitmap;
1012 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 1012 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
1013 delete pMask; 1013 delete pMask;
1014 return FALSE; 1014 return false;
1015 } 1015 }
1016 for (int row = 0; row < m_Height; row++) { 1016 for (int row = 0; row < m_Height; row++) {
1017 uint8_t* src_pos = m_pBuffer + row * m_Pitch; 1017 uint8_t* src_pos = m_pBuffer + row * m_Pitch;
1018 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch(); 1018 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
1019 for (int col = 0; col < m_Width; col++) { 1019 for (int col = 0; col < m_Width; col++) {
1020 *dest_pos++ = FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos); 1020 *dest_pos++ = FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos);
1021 src_pos += 4; 1021 src_pos += 4;
1022 } 1022 }
1023 } 1023 }
1024 TakeOver(pMask); 1024 TakeOver(pMask);
1025 delete pMask; 1025 delete pMask;
1026 break; 1026 break;
1027 } 1027 }
1028 default: 1028 default:
1029 return FALSE; 1029 return false;
1030 } 1030 }
1031 return TRUE; 1031 return true;
1032 } 1032 }
1033 1033
1034 FX_BOOL CFX_DIBitmap::MultiplyAlpha(int alpha) { 1034 bool CFX_DIBitmap::MultiplyAlpha(int alpha) {
1035 if (!m_pBuffer) { 1035 if (!m_pBuffer) {
1036 return FALSE; 1036 return false;
1037 } 1037 }
1038 switch (GetFormat()) { 1038 switch (GetFormat()) {
1039 case FXDIB_1bppMask: 1039 case FXDIB_1bppMask:
1040 if (!ConvertFormat(FXDIB_8bppMask)) { 1040 if (!ConvertFormat(FXDIB_8bppMask)) {
1041 return FALSE; 1041 return false;
1042 } 1042 }
1043 MultiplyAlpha(alpha); 1043 MultiplyAlpha(alpha);
1044 break; 1044 break;
1045 case FXDIB_8bppMask: { 1045 case FXDIB_8bppMask: {
1046 for (int row = 0; row < m_Height; row++) { 1046 for (int row = 0; row < m_Height; row++) {
1047 uint8_t* scan_line = m_pBuffer + row * m_Pitch; 1047 uint8_t* scan_line = m_pBuffer + row * m_Pitch;
1048 for (int col = 0; col < m_Width; col++) { 1048 for (int col = 0; col < m_Width; col++) {
1049 scan_line[col] = scan_line[col] * alpha / 255; 1049 scan_line[col] = scan_line[col] * alpha / 255;
1050 } 1050 }
1051 } 1051 }
1052 break; 1052 break;
1053 } 1053 }
1054 case FXDIB_Argb: { 1054 case FXDIB_Argb: {
1055 for (int row = 0; row < m_Height; row++) { 1055 for (int row = 0; row < m_Height; row++) {
1056 uint8_t* scan_line = m_pBuffer + row * m_Pitch + 3; 1056 uint8_t* scan_line = m_pBuffer + row * m_Pitch + 3;
1057 for (int col = 0; col < m_Width; col++) { 1057 for (int col = 0; col < m_Width; col++) {
1058 *scan_line = (*scan_line) * alpha / 255; 1058 *scan_line = (*scan_line) * alpha / 255;
1059 scan_line += 4; 1059 scan_line += 4;
1060 } 1060 }
1061 } 1061 }
1062 break; 1062 break;
1063 } 1063 }
1064 default: 1064 default:
1065 if (HasAlpha()) { 1065 if (HasAlpha()) {
1066 m_pAlphaMask->MultiplyAlpha(alpha); 1066 m_pAlphaMask->MultiplyAlpha(alpha);
1067 } else if (IsCmykImage()) { 1067 } else if (IsCmykImage()) {
1068 if (!ConvertFormat((FXDIB_Format)(GetFormat() | 0x0200))) { 1068 if (!ConvertFormat((FXDIB_Format)(GetFormat() | 0x0200))) {
1069 return FALSE; 1069 return false;
1070 } 1070 }
1071 m_pAlphaMask->MultiplyAlpha(alpha); 1071 m_pAlphaMask->MultiplyAlpha(alpha);
1072 } else { 1072 } else {
1073 if (!ConvertFormat(FXDIB_Argb)) { 1073 if (!ConvertFormat(FXDIB_Argb)) {
1074 return FALSE; 1074 return false;
1075 } 1075 }
1076 MultiplyAlpha(alpha); 1076 MultiplyAlpha(alpha);
1077 } 1077 }
1078 break; 1078 break;
1079 } 1079 }
1080 return TRUE; 1080 return true;
1081 } 1081 }
1082 1082
1083 uint32_t CFX_DIBitmap::GetPixel(int x, int y) const { 1083 uint32_t CFX_DIBitmap::GetPixel(int x, int y) const {
1084 if (!m_pBuffer) { 1084 if (!m_pBuffer) {
1085 return 0; 1085 return 0;
1086 } 1086 }
1087 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; 1087 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
1088 switch (GetFormat()) { 1088 switch (GetFormat()) {
1089 case FXDIB_1bppMask: { 1089 case FXDIB_1bppMask: {
1090 if ((*pos) & (1 << (7 - x % 8))) { 1090 if ((*pos) & (1 << (7 - x % 8))) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 break; 1182 break;
1183 default: 1183 default:
1184 break; 1184 break;
1185 } 1185 }
1186 } 1186 }
1187 1187
1188 void CFX_DIBitmap::DownSampleScanline(int line, 1188 void CFX_DIBitmap::DownSampleScanline(int line,
1189 uint8_t* dest_scan, 1189 uint8_t* dest_scan,
1190 int dest_bpp, 1190 int dest_bpp,
1191 int dest_width, 1191 int dest_width,
1192 FX_BOOL bFlipX, 1192 bool bFlipX,
1193 int clip_left, 1193 int clip_left,
1194 int clip_width) const { 1194 int clip_width) const {
1195 if (!m_pBuffer) { 1195 if (!m_pBuffer) {
1196 return; 1196 return;
1197 } 1197 }
1198 int src_Bpp = m_bpp / 8; 1198 int src_Bpp = m_bpp / 8;
1199 uint8_t* scanline = m_pBuffer + line * m_Pitch; 1199 uint8_t* scanline = m_pBuffer + line * m_Pitch;
1200 if (src_Bpp == 0) { 1200 if (src_Bpp == 0) {
1201 for (int i = 0; i < clip_width; i++) { 1201 for (int i = 0; i < clip_width; i++) {
1202 uint32_t dest_x = clip_left + i; 1202 uint32_t dest_x = clip_left + i;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 int dest_pos = i * src_Bpp; 1245 int dest_pos = i * src_Bpp;
1246 for (int b = 0; b < src_Bpp; b++) { 1246 for (int b = 0; b < src_Bpp; b++) {
1247 dest_scan[dest_pos + b] = scanline[src_x + b]; 1247 dest_scan[dest_pos + b] = scanline[src_x + b];
1248 } 1248 }
1249 } 1249 }
1250 } 1250 }
1251 } 1251 }
1252 1252
1253 // TODO(weili): Split this function into two for handling CMYK and RGB 1253 // TODO(weili): Split this function into two for handling CMYK and RGB
1254 // colors separately. 1254 // colors separately.
1255 FX_BOOL CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, 1255 bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) {
1256 uint32_t backcolor) {
1257 ASSERT(!IsAlphaMask()); 1256 ASSERT(!IsAlphaMask());
1258 if (!m_pBuffer || IsAlphaMask()) { 1257 if (!m_pBuffer || IsAlphaMask()) {
1259 return FALSE; 1258 return false;
1260 } 1259 }
1261 // Values used for CMYK colors. 1260 // Values used for CMYK colors.
1262 int fc = 0; 1261 int fc = 0;
1263 int fm = 0; 1262 int fm = 0;
1264 int fy = 0; 1263 int fy = 0;
1265 int fk = 0; 1264 int fk = 0;
1266 int bc = 0; 1265 int bc = 0;
1267 int bm = 0; 1266 int bm = 0;
1268 int by = 0; 1267 int by = 0;
1269 int bk = 0; 1268 int bk = 0;
1270 // Values used for RGB colors. 1269 // Values used for RGB colors.
1271 int fr = 0; 1270 int fr = 0;
1272 int fg = 0; 1271 int fg = 0;
1273 int fb = 0; 1272 int fb = 0;
1274 int br = 0; 1273 int br = 0;
1275 int bg = 0; 1274 int bg = 0;
1276 int bb = 0; 1275 int bb = 0;
1277 FX_BOOL isCmykImage = IsCmykImage(); 1276 bool isCmykImage = IsCmykImage();
1278 if (isCmykImage) { 1277 if (isCmykImage) {
1279 fc = FXSYS_GetCValue(forecolor); 1278 fc = FXSYS_GetCValue(forecolor);
1280 fm = FXSYS_GetMValue(forecolor); 1279 fm = FXSYS_GetMValue(forecolor);
1281 fy = FXSYS_GetYValue(forecolor); 1280 fy = FXSYS_GetYValue(forecolor);
1282 fk = FXSYS_GetKValue(forecolor); 1281 fk = FXSYS_GetKValue(forecolor);
1283 bc = FXSYS_GetCValue(backcolor); 1282 bc = FXSYS_GetCValue(backcolor);
1284 bm = FXSYS_GetMValue(backcolor); 1283 bm = FXSYS_GetMValue(backcolor);
1285 by = FXSYS_GetYValue(backcolor); 1284 by = FXSYS_GetYValue(backcolor);
1286 bk = FXSYS_GetKValue(backcolor); 1285 bk = FXSYS_GetKValue(backcolor);
1287 } else { 1286 } else {
1288 fr = FXSYS_GetRValue(forecolor); 1287 fr = FXSYS_GetRValue(forecolor);
1289 fg = FXSYS_GetGValue(forecolor); 1288 fg = FXSYS_GetGValue(forecolor);
1290 fb = FXSYS_GetBValue(forecolor); 1289 fb = FXSYS_GetBValue(forecolor);
1291 br = FXSYS_GetRValue(backcolor); 1290 br = FXSYS_GetRValue(backcolor);
1292 bg = FXSYS_GetGValue(backcolor); 1291 bg = FXSYS_GetGValue(backcolor);
1293 bb = FXSYS_GetBValue(backcolor); 1292 bb = FXSYS_GetBValue(backcolor);
1294 } 1293 }
1295 if (m_bpp <= 8) { 1294 if (m_bpp <= 8) {
1296 if (isCmykImage) { 1295 if (isCmykImage) {
1297 if (forecolor == 0xff && backcolor == 0 && !m_pPalette) { 1296 if (forecolor == 0xff && backcolor == 0 && !m_pPalette) {
1298 return TRUE; 1297 return true;
1299 } 1298 }
1300 } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) { 1299 } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) {
1301 return TRUE; 1300 return true;
1302 } 1301 }
1303 if (!m_pPalette) { 1302 if (!m_pPalette) {
1304 BuildPalette(); 1303 BuildPalette();
1305 } 1304 }
1306 int size = 1 << m_bpp; 1305 int size = 1 << m_bpp;
1307 if (isCmykImage) { 1306 if (isCmykImage) {
1308 for (int i = 0; i < size; i++) { 1307 for (int i = 0; i < size; i++) {
1309 uint8_t b, g, r; 1308 uint8_t b, g, r;
1310 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]), 1309 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]),
1311 FXSYS_GetMValue(m_pPalette.get()[i]), 1310 FXSYS_GetMValue(m_pPalette.get()[i]),
1312 FXSYS_GetYValue(m_pPalette.get()[i]), 1311 FXSYS_GetYValue(m_pPalette.get()[i]),
1313 FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b); 1312 FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b);
1314 int gray = 255 - FXRGB2GRAY(r, g, b); 1313 int gray = 255 - FXRGB2GRAY(r, g, b);
1315 m_pPalette.get()[i] = CmykEncode( 1314 m_pPalette.get()[i] = CmykEncode(
1316 bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255, 1315 bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255,
1317 by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255); 1316 by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255);
1318 } 1317 }
1319 } else { 1318 } else {
1320 for (int i = 0; i < size; i++) { 1319 for (int i = 0; i < size; i++) {
1321 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]), 1320 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]),
1322 FXARGB_G(m_pPalette.get()[i]), 1321 FXARGB_G(m_pPalette.get()[i]),
1323 FXARGB_B(m_pPalette.get()[i])); 1322 FXARGB_B(m_pPalette.get()[i]));
1324 m_pPalette.get()[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, 1323 m_pPalette.get()[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255,
1325 bg + (fg - bg) * gray / 255, 1324 bg + (fg - bg) * gray / 255,
1326 bb + (fb - bb) * gray / 255); 1325 bb + (fb - bb) * gray / 255);
1327 } 1326 }
1328 } 1327 }
1329 return TRUE; 1328 return true;
1330 } 1329 }
1331 if (isCmykImage) { 1330 if (isCmykImage) {
1332 if (forecolor == 0xff && backcolor == 0x00) { 1331 if (forecolor == 0xff && backcolor == 0x00) {
1333 for (int row = 0; row < m_Height; row++) { 1332 for (int row = 0; row < m_Height; row++) {
1334 uint8_t* scanline = m_pBuffer + row * m_Pitch; 1333 uint8_t* scanline = m_pBuffer + row * m_Pitch;
1335 for (int col = 0; col < m_Width; col++) { 1334 for (int col = 0; col < m_Width; col++) {
1336 uint8_t b, g, r; 1335 uint8_t b, g, r;
1337 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3], 1336 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3],
1338 r, g, b); 1337 r, g, b);
1339 *scanline++ = 0; 1338 *scanline++ = 0;
1340 *scanline++ = 0; 1339 *scanline++ = 0;
1341 *scanline++ = 0; 1340 *scanline++ = 0;
1342 *scanline++ = 255 - FXRGB2GRAY(r, g, b); 1341 *scanline++ = 255 - FXRGB2GRAY(r, g, b);
1343 } 1342 }
1344 } 1343 }
1345 return TRUE; 1344 return true;
1346 } 1345 }
1347 } else if (forecolor == 0 && backcolor == 0xffffff) { 1346 } else if (forecolor == 0 && backcolor == 0xffffff) {
1348 for (int row = 0; row < m_Height; row++) { 1347 for (int row = 0; row < m_Height; row++) {
1349 uint8_t* scanline = m_pBuffer + row * m_Pitch; 1348 uint8_t* scanline = m_pBuffer + row * m_Pitch;
1350 int gap = m_bpp / 8 - 2; 1349 int gap = m_bpp / 8 - 2;
1351 for (int col = 0; col < m_Width; col++) { 1350 for (int col = 0; col < m_Width; col++) {
1352 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); 1351 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
1353 *scanline++ = gray; 1352 *scanline++ = gray;
1354 *scanline++ = gray; 1353 *scanline++ = gray;
1355 *scanline = gray; 1354 *scanline = gray;
1356 scanline += gap; 1355 scanline += gap;
1357 } 1356 }
1358 } 1357 }
1359 return TRUE; 1358 return true;
1360 } 1359 }
1361 if (isCmykImage) { 1360 if (isCmykImage) {
1362 for (int row = 0; row < m_Height; row++) { 1361 for (int row = 0; row < m_Height; row++) {
1363 uint8_t* scanline = m_pBuffer + row * m_Pitch; 1362 uint8_t* scanline = m_pBuffer + row * m_Pitch;
1364 for (int col = 0; col < m_Width; col++) { 1363 for (int col = 0; col < m_Width; col++) {
1365 uint8_t b, g, r; 1364 uint8_t b, g, r;
1366 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3], 1365 AdobeCMYK_to_sRGB1(scanline[0], scanline[1], scanline[2], scanline[3],
1367 r, g, b); 1366 r, g, b);
1368 int gray = 255 - FXRGB2GRAY(r, g, b); 1367 int gray = 255 - FXRGB2GRAY(r, g, b);
1369 *scanline++ = bc + (fc - bc) * gray / 255; 1368 *scanline++ = bc + (fc - bc) * gray / 255;
1370 *scanline++ = bm + (fm - bm) * gray / 255; 1369 *scanline++ = bm + (fm - bm) * gray / 255;
1371 *scanline++ = by + (fy - by) * gray / 255; 1370 *scanline++ = by + (fy - by) * gray / 255;
1372 *scanline++ = bk + (fk - bk) * gray / 255; 1371 *scanline++ = bk + (fk - bk) * gray / 255;
1373 } 1372 }
1374 } 1373 }
1375 } else { 1374 } else {
1376 for (int row = 0; row < m_Height; row++) { 1375 for (int row = 0; row < m_Height; row++) {
1377 uint8_t* scanline = m_pBuffer + row * m_Pitch; 1376 uint8_t* scanline = m_pBuffer + row * m_Pitch;
1378 int gap = m_bpp / 8 - 2; 1377 int gap = m_bpp / 8 - 2;
1379 for (int col = 0; col < m_Width; col++) { 1378 for (int col = 0; col < m_Width; col++) {
1380 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]); 1379 int gray = FXRGB2GRAY(scanline[2], scanline[1], scanline[0]);
1381 *scanline++ = bb + (fb - bb) * gray / 255; 1380 *scanline++ = bb + (fb - bb) * gray / 255;
1382 *scanline++ = bg + (fg - bg) * gray / 255; 1381 *scanline++ = bg + (fg - bg) * gray / 255;
1383 *scanline = br + (fr - br) * gray / 255; 1382 *scanline = br + (fr - br) * gray / 255;
1384 scanline += gap; 1383 scanline += gap;
1385 } 1384 }
1386 } 1385 }
1387 } 1386 }
1388 return TRUE; 1387 return true;
1389 } 1388 }
1390 1389
1391 CFX_DIBitmap* CFX_DIBSource::FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const { 1390 CFX_DIBitmap* CFX_DIBSource::FlipImage(bool bXFlip, bool bYFlip) const {
1392 CFX_DIBitmap* pFlipped = new CFX_DIBitmap; 1391 CFX_DIBitmap* pFlipped = new CFX_DIBitmap;
1393 if (!pFlipped->Create(m_Width, m_Height, GetFormat())) { 1392 if (!pFlipped->Create(m_Width, m_Height, GetFormat())) {
1394 delete pFlipped; 1393 delete pFlipped;
1395 return nullptr; 1394 return nullptr;
1396 } 1395 }
1397 pFlipped->CopyPalette(m_pPalette.get()); 1396 pFlipped->CopyPalette(m_pPalette.get());
1398 uint8_t* pDestBuffer = pFlipped->GetBuffer(); 1397 uint8_t* pDestBuffer = pFlipped->GetBuffer();
1399 int Bpp = m_bpp / 8; 1398 int Bpp = m_bpp / 8;
1400 for (int row = 0; row < m_Height; row++) { 1399 for (int row = 0; row < m_Height; row++) {
1401 const uint8_t* src_scan = GetScanline(row); 1400 const uint8_t* src_scan = GetScanline(row);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 CFX_DIBExtractor::~CFX_DIBExtractor() {} 1477 CFX_DIBExtractor::~CFX_DIBExtractor() {}
1479 1478
1480 CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {} 1479 CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {}
1481 1480
1482 CFX_FilteredDIB::~CFX_FilteredDIB() { 1481 CFX_FilteredDIB::~CFX_FilteredDIB() {
1483 if (m_bAutoDropSrc) { 1482 if (m_bAutoDropSrc) {
1484 delete m_pSrc; 1483 delete m_pSrc;
1485 } 1484 }
1486 } 1485 }
1487 1486
1488 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) { 1487 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc) {
1489 m_pSrc = pSrc; 1488 m_pSrc = pSrc;
1490 m_bAutoDropSrc = bAutoDropSrc; 1489 m_bAutoDropSrc = bAutoDropSrc;
1491 m_Width = pSrc->GetWidth(); 1490 m_Width = pSrc->GetWidth();
1492 m_Height = pSrc->GetHeight(); 1491 m_Height = pSrc->GetHeight();
1493 FXDIB_Format format = GetDestFormat(); 1492 FXDIB_Format format = GetDestFormat();
1494 m_bpp = (uint8_t)format; 1493 m_bpp = (uint8_t)format;
1495 m_AlphaFlag = (uint8_t)(format >> 8); 1494 m_AlphaFlag = (uint8_t)(format >> 8);
1496 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; 1495 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4;
1497 m_pPalette.reset(GetDestPalette()); 1496 m_pPalette.reset(GetDestPalette());
1498 m_Scanline.resize(m_Pitch); 1497 m_Scanline.resize(m_Pitch);
1499 } 1498 }
1500 1499
1501 const uint8_t* CFX_FilteredDIB::GetScanline(int line) const { 1500 const uint8_t* CFX_FilteredDIB::GetScanline(int line) const {
1502 TranslateScanline(m_pSrc->GetScanline(line), &m_Scanline); 1501 TranslateScanline(m_pSrc->GetScanline(line), &m_Scanline);
1503 return m_Scanline.data(); 1502 return m_Scanline.data();
1504 } 1503 }
1505 1504
1506 void CFX_FilteredDIB::DownSampleScanline(int line, 1505 void CFX_FilteredDIB::DownSampleScanline(int line,
1507 uint8_t* dest_scan, 1506 uint8_t* dest_scan,
1508 int dest_bpp, 1507 int dest_bpp,
1509 int dest_width, 1508 int dest_width,
1510 FX_BOOL bFlipX, 1509 bool bFlipX,
1511 int clip_left, 1510 int clip_left,
1512 int clip_width) const { 1511 int clip_width) const {
1513 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, 1512 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX,
1514 clip_left, clip_width); 1513 clip_left, clip_width);
1515 TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp); 1514 TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp);
1516 } 1515 }
1517 1516
1518 CFX_ImageRenderer::CFX_ImageRenderer() { 1517 CFX_ImageRenderer::CFX_ImageRenderer() {
1519 m_Status = 0; 1518 m_Status = 0;
1520 m_bRgbByteOrder = FALSE; 1519 m_bRgbByteOrder = false;
1521 m_BlendType = FXDIB_BLEND_NORMAL; 1520 m_BlendType = FXDIB_BLEND_NORMAL;
1522 } 1521 }
1523 1522
1524 CFX_ImageRenderer::~CFX_ImageRenderer() {} 1523 CFX_ImageRenderer::~CFX_ImageRenderer() {}
1525 1524
1526 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, 1525 bool CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice,
1527 const CFX_ClipRgn* pClipRgn, 1526 const CFX_ClipRgn* pClipRgn,
1528 const CFX_DIBSource* pSource, 1527 const CFX_DIBSource* pSource,
1529 int bitmap_alpha, 1528 int bitmap_alpha,
1530 uint32_t mask_color, 1529 uint32_t mask_color,
1531 const CFX_Matrix* pMatrix, 1530 const CFX_Matrix* pMatrix,
1532 uint32_t dib_flags, 1531 uint32_t dib_flags,
1533 FX_BOOL bRgbByteOrder, 1532 bool bRgbByteOrder,
1534 int alpha_flag, 1533 int alpha_flag,
1535 void* pIccTransform, 1534 void* pIccTransform,
1536 int blend_type) { 1535 int blend_type) {
1537 m_Matrix = *pMatrix; 1536 m_Matrix = *pMatrix;
1538 CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect(); 1537 CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect();
1539 FX_RECT image_rect = image_rect_f.GetOuterRect(); 1538 FX_RECT image_rect = image_rect_f.GetOuterRect();
1540 m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(), 1539 m_ClipBox = pClipRgn ? pClipRgn->GetBox() : FX_RECT(0, 0, pDevice->GetWidth(),
1541 pDevice->GetHeight()); 1540 pDevice->GetHeight());
1542 m_ClipBox.Intersect(image_rect); 1541 m_ClipBox.Intersect(image_rect);
1543 if (m_ClipBox.IsEmpty()) 1542 if (m_ClipBox.IsEmpty())
1544 return FALSE; 1543 return false;
1545 1544
1546 m_pDevice = pDevice; 1545 m_pDevice = pDevice;
1547 m_pClipRgn = pClipRgn; 1546 m_pClipRgn = pClipRgn;
1548 m_MaskColor = mask_color; 1547 m_MaskColor = mask_color;
1549 m_BitmapAlpha = bitmap_alpha; 1548 m_BitmapAlpha = bitmap_alpha;
1550 m_Matrix = *pMatrix; 1549 m_Matrix = *pMatrix;
1551 m_Flags = dib_flags; 1550 m_Flags = dib_flags;
1552 m_AlphaFlag = alpha_flag; 1551 m_AlphaFlag = alpha_flag;
1553 m_pIccTransform = pIccTransform; 1552 m_pIccTransform = pIccTransform;
1554 m_bRgbByteOrder = bRgbByteOrder; 1553 m_bRgbByteOrder = bRgbByteOrder;
1555 m_BlendType = blend_type; 1554 m_BlendType = blend_type;
1556 1555
1557 if ((FXSYS_fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) || 1556 if ((FXSYS_fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) ||
1558 (FXSYS_fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0)) { 1557 (FXSYS_fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0)) {
1559 if (FXSYS_fabs(m_Matrix.a) < FXSYS_fabs(m_Matrix.b) / 20 && 1558 if (FXSYS_fabs(m_Matrix.a) < FXSYS_fabs(m_Matrix.b) / 20 &&
1560 FXSYS_fabs(m_Matrix.d) < FXSYS_fabs(m_Matrix.c) / 20 && 1559 FXSYS_fabs(m_Matrix.d) < FXSYS_fabs(m_Matrix.c) / 20 &&
1561 FXSYS_fabs(m_Matrix.a) < 0.5f && FXSYS_fabs(m_Matrix.d) < 0.5f) { 1560 FXSYS_fabs(m_Matrix.a) < 0.5f && FXSYS_fabs(m_Matrix.d) < 0.5f) {
1562 int dest_width = image_rect.Width(); 1561 int dest_width = image_rect.Width();
1563 int dest_height = image_rect.Height(); 1562 int dest_height = image_rect.Height();
1564 FX_RECT bitmap_clip = m_ClipBox; 1563 FX_RECT bitmap_clip = m_ClipBox;
1565 bitmap_clip.Offset(-image_rect.left, -image_rect.top); 1564 bitmap_clip.Offset(-image_rect.left, -image_rect.top);
1566 bitmap_clip = FXDIB_SwapClipBox(bitmap_clip, dest_width, dest_height, 1565 bitmap_clip = FXDIB_SwapClipBox(bitmap_clip, dest_width, dest_height,
1567 m_Matrix.c > 0, m_Matrix.b < 0); 1566 m_Matrix.c > 0, m_Matrix.b < 0);
1568 m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox, 1567 m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox,
1569 TRUE, m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder, 1568 true, m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder,
1570 alpha_flag, pIccTransform, m_BlendType); 1569 alpha_flag, pIccTransform, m_BlendType);
1571 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( 1570 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>(
1572 &m_Composer, pSource, dest_height, dest_width, bitmap_clip, 1571 &m_Composer, pSource, dest_height, dest_width, bitmap_clip,
1573 dib_flags); 1572 dib_flags);
1574 if (!m_Stretcher->Start()) 1573 if (!m_Stretcher->Start())
1575 return FALSE; 1574 return false;
1576 1575
1577 m_Status = 1; 1576 m_Status = 1;
1578 return TRUE; 1577 return true;
1579 } 1578 }
1580 m_Status = 2; 1579 m_Status = 2;
1581 m_pTransformer.reset( 1580 m_pTransformer.reset(
1582 new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox)); 1581 new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox));
1583 m_pTransformer->Start(); 1582 m_pTransformer->Start();
1584 return TRUE; 1583 return true;
1585 } 1584 }
1586 1585
1587 int dest_width = image_rect.Width(); 1586 int dest_width = image_rect.Width();
1588 if (m_Matrix.a < 0) 1587 if (m_Matrix.a < 0)
1589 dest_width = -dest_width; 1588 dest_width = -dest_width;
1590 1589
1591 int dest_height = image_rect.Height(); 1590 int dest_height = image_rect.Height();
1592 if (m_Matrix.d > 0) 1591 if (m_Matrix.d > 0)
1593 dest_height = -dest_height; 1592 dest_height = -dest_height;
1594 1593
1595 if (dest_width == 0 || dest_height == 0) 1594 if (dest_width == 0 || dest_height == 0)
1596 return FALSE; 1595 return false;
1597 1596
1598 FX_RECT bitmap_clip = m_ClipBox; 1597 FX_RECT bitmap_clip = m_ClipBox;
1599 bitmap_clip.Offset(-image_rect.left, -image_rect.top); 1598 bitmap_clip.Offset(-image_rect.left, -image_rect.top);
1600 m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox, 1599 m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox,
1601 FALSE, FALSE, FALSE, m_bRgbByteOrder, alpha_flag, 1600 false, false, false, m_bRgbByteOrder, alpha_flag,
1602 pIccTransform, m_BlendType); 1601 pIccTransform, m_BlendType);
1603 m_Status = 1; 1602 m_Status = 1;
1604 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( 1603 m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>(
1605 &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags); 1604 &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags);
1606 return m_Stretcher->Start(); 1605 return m_Stretcher->Start();
1607 } 1606 }
1608 1607
1609 FX_BOOL CFX_ImageRenderer::Continue(IFX_Pause* pPause) { 1608 bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
1610 if (m_Status == 1) 1609 if (m_Status == 1)
1611 return m_Stretcher->Continue(pPause); 1610 return m_Stretcher->Continue(pPause);
1612 1611
1613 if (m_Status == 2) { 1612 if (m_Status == 2) {
1614 if (m_pTransformer->Continue(pPause)) 1613 if (m_pTransformer->Continue(pPause))
1615 return TRUE; 1614 return true;
1616 1615
1617 std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); 1616 std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
1618 if (!pBitmap || !pBitmap->GetBuffer()) 1617 if (!pBitmap || !pBitmap->GetBuffer())
1619 return FALSE; 1618 return false;
1620 1619
1621 if (pBitmap->IsAlphaMask()) { 1620 if (pBitmap->IsAlphaMask()) {
1622 if (m_BitmapAlpha != 255) { 1621 if (m_BitmapAlpha != 255) {
1623 if (m_AlphaFlag >> 8) { 1622 if (m_AlphaFlag >> 8) {
1624 m_AlphaFlag = 1623 m_AlphaFlag =
1625 (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) | 1624 (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) |
1626 ((m_AlphaFlag >> 8) << 8)); 1625 ((m_AlphaFlag >> 8) << 8));
1627 } else { 1626 } else {
1628 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); 1627 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha);
1629 } 1628 }
1630 } 1629 }
1631 m_pDevice->CompositeMask( 1630 m_pDevice->CompositeMask(
1632 m_pTransformer->result().left, m_pTransformer->result().top, 1631 m_pTransformer->result().left, m_pTransformer->result().top,
1633 pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), m_MaskColor, 1632 pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), m_MaskColor,
1634 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag, 1633 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag,
1635 m_pIccTransform); 1634 m_pIccTransform);
1636 } else { 1635 } else {
1637 if (m_BitmapAlpha != 255) 1636 if (m_BitmapAlpha != 255)
1638 pBitmap->MultiplyAlpha(m_BitmapAlpha); 1637 pBitmap->MultiplyAlpha(m_BitmapAlpha);
1639 m_pDevice->CompositeBitmap( 1638 m_pDevice->CompositeBitmap(
1640 m_pTransformer->result().left, m_pTransformer->result().top, 1639 m_pTransformer->result().left, m_pTransformer->result().top,
1641 pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), 0, 0, 1640 pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), 0, 0,
1642 m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform); 1641 m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
1643 } 1642 }
1644 return FALSE; 1643 return false;
1645 } 1644 }
1646 return FALSE; 1645 return false;
1647 } 1646 }
1648 1647
1649 CFX_BitmapStorer::CFX_BitmapStorer() { 1648 CFX_BitmapStorer::CFX_BitmapStorer() {
1650 } 1649 }
1651 1650
1652 CFX_BitmapStorer::~CFX_BitmapStorer() { 1651 CFX_BitmapStorer::~CFX_BitmapStorer() {
1653 } 1652 }
1654 1653
1655 std::unique_ptr<CFX_DIBitmap> CFX_BitmapStorer::Detach() { 1654 std::unique_ptr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
1656 return std::move(m_pBitmap); 1655 return std::move(m_pBitmap);
(...skipping 13 matching lines...) Expand all
1670 : nullptr; 1669 : nullptr;
1671 if (dest_buf) 1670 if (dest_buf)
1672 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch()); 1671 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch());
1673 1672
1674 if (dest_alpha_buf) { 1673 if (dest_alpha_buf) {
1675 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha, 1674 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha,
1676 m_pBitmap->m_pAlphaMask->GetPitch()); 1675 m_pBitmap->m_pAlphaMask->GetPitch());
1677 } 1676 }
1678 } 1677 }
1679 1678
1680 FX_BOOL CFX_BitmapStorer::SetInfo(int width, 1679 bool CFX_BitmapStorer::SetInfo(int width,
1681 int height, 1680 int height,
1682 FXDIB_Format src_format, 1681 FXDIB_Format src_format,
1683 uint32_t* pSrcPalette) { 1682 uint32_t* pSrcPalette) {
1684 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); 1683 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
1685 if (!m_pBitmap->Create(width, height, src_format)) { 1684 if (!m_pBitmap->Create(width, height, src_format)) {
1686 m_pBitmap.reset(); 1685 m_pBitmap.reset();
1687 return FALSE; 1686 return false;
1688 } 1687 }
1689 if (pSrcPalette) 1688 if (pSrcPalette)
1690 m_pBitmap->CopyPalette(pSrcPalette); 1689 m_pBitmap->CopyPalette(pSrcPalette);
1691 return TRUE; 1690 return true;
1692 } 1691 }
OLDNEW
« no previous file with comments | « core/fxge/dib/fx_dib_engine.cpp ('k') | core/fxge/dib/fx_dib_transform.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698