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

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

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 years 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/src/fxge/dib/fx_dib_engine.cpp ('k') | core/src/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/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
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return FALSE; 82 return FALSE;
83 } 83 }
84 if (pBuffer) { 84 if (pBuffer) {
85 m_pBuffer = pBuffer; 85 m_pBuffer = pBuffer;
86 m_bExtBuf = TRUE; 86 m_bExtBuf = TRUE;
87 } else { 87 } else {
88 int size = pitch * height + 4; 88 int size = pitch * height + 4;
89 int oomlimit = _MAX_OOM_LIMIT_; 89 int oomlimit = _MAX_OOM_LIMIT_;
90 if (oomlimit >= 0 && size >= oomlimit) { 90 if (oomlimit >= 0 && size >= oomlimit) {
91 m_pBuffer = FX_TryAlloc(uint8_t, size); 91 m_pBuffer = FX_TryAlloc(uint8_t, size);
92 if (m_pBuffer == NULL) { 92 if (!m_pBuffer) {
93 return FALSE; 93 return FALSE;
94 } 94 }
95 } else { 95 } else {
96 m_pBuffer = FX_Alloc(uint8_t, size); 96 m_pBuffer = FX_Alloc(uint8_t, size);
97 } 97 }
98 } 98 }
99 m_Width = width; 99 m_Width = width;
100 m_Height = height; 100 m_Height = height;
101 m_Pitch = pitch; 101 m_Pitch = pitch;
102 if (HasAlpha() && format != FXDIB_Argb) { 102 if (HasAlpha() && format != FXDIB_Argb) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 243 }
244 return 0xff - index; 244 return 0xff - index;
245 } 245 }
246 if (GetBPP() == 1) { 246 if (GetBPP() == 1) {
247 return index ? 0xffffffff : 0xff000000; 247 return index ? 0xffffffff : 0xff000000;
248 } 248 }
249 return index * 0x10101 | 0xff000000; 249 return index * 0x10101 | 0xff000000;
250 } 250 }
251 void CFX_DIBSource::SetPaletteEntry(int index, FX_DWORD color) { 251 void CFX_DIBSource::SetPaletteEntry(int index, FX_DWORD color) {
252 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 252 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
253 if (m_pPalette == NULL) { 253 if (!m_pPalette) {
254 BuildPalette(); 254 BuildPalette();
255 } 255 }
256 m_pPalette[index] = color; 256 m_pPalette[index] = color;
257 } 257 }
258 int CFX_DIBSource::FindPalette(FX_DWORD color) const { 258 int CFX_DIBSource::FindPalette(FX_DWORD color) const {
259 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 259 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
260 if (m_pPalette == NULL) { 260 if (!m_pPalette) {
261 if (IsCmykImage()) { 261 if (IsCmykImage()) {
262 if (GetBPP() == 1) { 262 if (GetBPP() == 1) {
263 return ((uint8_t)color == 0xff) ? 0 : 1; 263 return ((uint8_t)color == 0xff) ? 0 : 1;
264 } 264 }
265 return 0xff - (uint8_t)color; 265 return 0xff - (uint8_t)color;
266 } 266 }
267 if (GetBPP() == 1) { 267 if (GetBPP() == 1) {
268 return ((uint8_t)color == 0xff) ? 1 : 0; 268 return ((uint8_t)color == 0xff) ? 1 : 0;
269 } 269 }
270 return (uint8_t)color; 270 return (uint8_t)color;
271 } 271 }
272 int palsize = (1 << GetBPP()); 272 int palsize = (1 << GetBPP());
273 for (int i = 0; i < palsize; i++) 273 for (int i = 0; i < palsize; i++)
274 if (m_pPalette[i] == color) { 274 if (m_pPalette[i] == color) {
275 return i; 275 return i;
276 } 276 }
277 return -1; 277 return -1;
278 } 278 }
279 void CFX_DIBitmap::Clear(FX_DWORD color) { 279 void CFX_DIBitmap::Clear(FX_DWORD color) {
280 if (m_pBuffer == NULL) { 280 if (!m_pBuffer) {
281 return; 281 return;
282 } 282 }
283 switch (GetFormat()) { 283 switch (GetFormat()) {
284 case FXDIB_1bppMask: 284 case FXDIB_1bppMask:
285 FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0, 285 FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0,
286 m_Pitch * m_Height); 286 m_Pitch * m_Height);
287 break; 287 break;
288 case FXDIB_1bppRgb: { 288 case FXDIB_1bppRgb: {
289 int index = FindPalette(color); 289 int index = FindPalette(color);
290 FXSYS_memset(m_pBuffer, index ? 0xff : 0, m_Pitch * m_Height); 290 FXSYS_memset(m_pBuffer, index ? 0xff : 0, m_Pitch * m_Height);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 height = dest_rect.bottom - dest_rect.top; 370 height = dest_rect.bottom - dest_rect.top;
371 } 371 }
372 FX_BOOL CFX_DIBitmap::TransferBitmap(int dest_left, 372 FX_BOOL CFX_DIBitmap::TransferBitmap(int dest_left,
373 int dest_top, 373 int dest_top,
374 int width, 374 int width,
375 int height, 375 int height,
376 const CFX_DIBSource* pSrcBitmap, 376 const CFX_DIBSource* pSrcBitmap,
377 int src_left, 377 int src_left,
378 int src_top, 378 int src_top,
379 void* pIccTransform) { 379 void* pIccTransform) {
380 if (m_pBuffer == NULL) { 380 if (!m_pBuffer) {
381 return FALSE; 381 return FALSE;
382 } 382 }
383 GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(), 383 GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(),
384 pSrcBitmap->GetHeight(), src_left, src_top, NULL); 384 pSrcBitmap->GetHeight(), src_left, src_top, NULL);
385 if (width == 0 || height == 0) { 385 if (width == 0 || height == 0) {
386 return TRUE; 386 return TRUE;
387 } 387 }
388 FXDIB_Format dest_format = GetFormat(); 388 FXDIB_Format dest_format = GetFormat();
389 FXDIB_Format src_format = pSrcBitmap->GetFormat(); 389 FXDIB_Format src_format = pSrcBitmap->GetFormat();
390 if (dest_format == src_format && pIccTransform == NULL) { 390 if (dest_format == src_format && !pIccTransform) {
391 if (GetBPP() == 1) { 391 if (GetBPP() == 1) {
392 for (int row = 0; row < height; row++) { 392 for (int row = 0; row < height; row++) {
393 uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch; 393 uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch;
394 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); 394 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
395 for (int col = 0; col < width; col++) { 395 for (int col = 0; col < width; col++) {
396 if (src_scan[(src_left + col) / 8] & 396 if (src_scan[(src_left + col) / 8] &
397 (1 << (7 - (src_left + col) % 8))) { 397 (1 << (7 - (src_left + col) % 8))) {
398 dest_scan[(dest_left + col) / 8] |= 1 398 dest_scan[(dest_left + col) / 8] |= 1
399 << (7 - (dest_left + col) % 8); 399 << (7 - (dest_left + col) % 8);
400 } else { 400 } else {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, 433 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left,
434 int dest_top, 434 int dest_top,
435 int width, 435 int width,
436 int height, 436 int height,
437 const CFX_DIBSource* pMask, 437 const CFX_DIBSource* pMask,
438 FX_DWORD color, 438 FX_DWORD color,
439 int src_left, 439 int src_left,
440 int src_top, 440 int src_top,
441 int alpha_flag, 441 int alpha_flag,
442 void* pIccTransform) { 442 void* pIccTransform) {
443 if (m_pBuffer == NULL) { 443 if (!m_pBuffer) {
444 return FALSE; 444 return FALSE;
445 } 445 }
446 ASSERT(HasAlpha() && (m_bpp >= 24)); 446 ASSERT(HasAlpha() && (m_bpp >= 24));
447 ASSERT(pMask->IsAlphaMask()); 447 ASSERT(pMask->IsAlphaMask());
448 if (!HasAlpha() || !pMask->IsAlphaMask() || m_bpp < 24) { 448 if (!HasAlpha() || !pMask->IsAlphaMask() || m_bpp < 24) {
449 return FALSE; 449 return FALSE;
450 } 450 }
451 GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(), 451 GetOverlapRect(dest_left, dest_top, width, height, pMask->GetWidth(),
452 pMask->GetHeight(), src_left, src_top, NULL); 452 pMask->GetHeight(), src_left, src_top, NULL);
453 if (width == 0 || height == 0) { 453 if (width == 0 || height == 0) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 FXSYS_memcpy(dest_color_pos, color_p, comps); 533 FXSYS_memcpy(dest_color_pos, color_p, comps);
534 dest_color_pos += comps; 534 dest_color_pos += comps;
535 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255); 535 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255);
536 } 536 }
537 } 537 }
538 } 538 }
539 } 539 }
540 return TRUE; 540 return TRUE;
541 } 541 }
542 void CFX_DIBSource::CopyPalette(const FX_DWORD* pSrc, FX_DWORD size) { 542 void CFX_DIBSource::CopyPalette(const FX_DWORD* pSrc, FX_DWORD size) {
543 if (pSrc == NULL || GetBPP() > 8) { 543 if (!pSrc || GetBPP() > 8) {
544 FX_Free(m_pPalette); 544 FX_Free(m_pPalette);
545 m_pPalette = NULL; 545 m_pPalette = NULL;
546 } else { 546 } else {
547 FX_DWORD pal_size = 1 << GetBPP(); 547 FX_DWORD pal_size = 1 << GetBPP();
548 if (m_pPalette == NULL) { 548 if (!m_pPalette) {
549 m_pPalette = FX_Alloc(FX_DWORD, pal_size); 549 m_pPalette = FX_Alloc(FX_DWORD, pal_size);
550 } 550 }
551 if (pal_size > size) { 551 if (pal_size > size) {
552 pal_size = size; 552 pal_size = size;
553 } 553 }
554 FXSYS_memcpy(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD)); 554 FXSYS_memcpy(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD));
555 } 555 }
556 } 556 }
557 void CFX_DIBSource::GetPalette(FX_DWORD* pal, int alpha) const { 557 void CFX_DIBSource::GetPalette(FX_DWORD* pal, int alpha) const {
558 ASSERT(GetBPP() <= 8 && !IsCmykImage()); 558 ASSERT(GetBPP() <= 8 && !IsCmykImage());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 m_pAlphaMask->m_Pitch); 621 m_pAlphaMask->m_Pitch);
622 } else { 622 } else {
623 m_pAlphaMask->Clear(0xff000000); 623 m_pAlphaMask->Clear(0xff000000);
624 } 624 }
625 return TRUE; 625 return TRUE;
626 } 626 }
627 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3}; 627 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
628 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, 628 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
629 const CFX_DIBSource* pSrcBitmap, 629 const CFX_DIBSource* pSrcBitmap,
630 FXDIB_Channel srcChannel) { 630 FXDIB_Channel srcChannel) {
631 if (m_pBuffer == NULL) { 631 if (!m_pBuffer) {
632 return FALSE; 632 return FALSE;
633 } 633 }
634 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap; 634 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap;
635 CFX_DIBitmap* pDst = this; 635 CFX_DIBitmap* pDst = this;
636 int destOffset, srcOffset; 636 int destOffset, srcOffset;
637 if (srcChannel == FXDIB_Alpha) { 637 if (srcChannel == FXDIB_Alpha) {
638 if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) { 638 if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) {
639 return FALSE; 639 return FALSE;
640 } 640 }
641 if (pSrcBitmap->GetBPP() == 1) { 641 if (pSrcBitmap->GetBPP() == 1) {
642 pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask); 642 pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask);
643 if (pSrcClone == NULL) { 643 if (!pSrcClone) {
644 return FALSE; 644 return FALSE;
645 } 645 }
646 } 646 }
647 if (pSrcBitmap->GetFormat() == FXDIB_Argb) { 647 if (pSrcBitmap->GetFormat() == FXDIB_Argb) {
648 srcOffset = 3; 648 srcOffset = 3;
649 } else { 649 } else {
650 srcOffset = 0; 650 srcOffset = 0;
651 } 651 }
652 } else { 652 } else {
653 if (pSrcBitmap->IsAlphaMask()) { 653 if (pSrcBitmap->IsAlphaMask()) {
654 return FALSE; 654 return FALSE;
655 } 655 }
656 if (pSrcBitmap->GetBPP() < 24) { 656 if (pSrcBitmap->GetBPP() < 24) {
657 if (pSrcBitmap->IsCmykImage()) { 657 if (pSrcBitmap->IsCmykImage()) {
658 pSrcClone = pSrcBitmap->CloneConvert( 658 pSrcClone = pSrcBitmap->CloneConvert(
659 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20)); 659 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20));
660 } else { 660 } else {
661 pSrcClone = pSrcBitmap->CloneConvert( 661 pSrcClone = pSrcBitmap->CloneConvert(
662 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18)); 662 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18));
663 } 663 }
664 if (pSrcClone == NULL) { 664 if (!pSrcClone) {
665 return FALSE; 665 return FALSE;
666 } 666 }
667 } 667 }
668 srcOffset = g_ChannelOffset[srcChannel]; 668 srcOffset = g_ChannelOffset[srcChannel];
669 } 669 }
670 if (destChannel == FXDIB_Alpha) { 670 if (destChannel == FXDIB_Alpha) {
671 if (IsAlphaMask()) { 671 if (IsAlphaMask()) {
672 if (!ConvertFormat(FXDIB_8bppMask)) { 672 if (!ConvertFormat(FXDIB_8bppMask)) {
673 if (pSrcClone != pSrcBitmap) { 673 if (pSrcClone != pSrcBitmap) {
674 delete pSrcClone; 674 delete pSrcClone;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 } 716 }
717 } 717 }
718 destOffset = g_ChannelOffset[destChannel]; 718 destOffset = g_ChannelOffset[destChannel];
719 } 719 }
720 if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) { 720 if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
721 CFX_DIBitmap* pAlphaMask = pSrcClone->m_pAlphaMask; 721 CFX_DIBitmap* pAlphaMask = pSrcClone->m_pAlphaMask;
722 if (pSrcClone->GetWidth() != m_Width || 722 if (pSrcClone->GetWidth() != m_Width ||
723 pSrcClone->GetHeight() != m_Height) { 723 pSrcClone->GetHeight() != m_Height) {
724 if (pAlphaMask) { 724 if (pAlphaMask) {
725 pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height); 725 pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height);
726 if (pAlphaMask == NULL) { 726 if (!pAlphaMask) {
727 if (pSrcClone != pSrcBitmap) { 727 if (pSrcClone != pSrcBitmap) {
728 delete pSrcClone; 728 delete pSrcClone;
729 } 729 }
730 return FALSE; 730 return FALSE;
731 } 731 }
732 } 732 }
733 } 733 }
734 if (pSrcClone != pSrcBitmap) { 734 if (pSrcClone != pSrcBitmap) {
735 pSrcClone->m_pAlphaMask = NULL; 735 pSrcClone->m_pAlphaMask = NULL;
736 delete pSrcClone; 736 delete pSrcClone;
737 } 737 }
738 pSrcClone = pAlphaMask; 738 pSrcClone = pAlphaMask;
739 srcOffset = 0; 739 srcOffset = 0;
740 } else if (pSrcClone->GetWidth() != m_Width || 740 } else if (pSrcClone->GetWidth() != m_Width ||
741 pSrcClone->GetHeight() != m_Height) { 741 pSrcClone->GetHeight() != m_Height) {
742 CFX_DIBitmap* pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height); 742 CFX_DIBitmap* pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height);
743 if (pSrcClone != pSrcBitmap) { 743 if (pSrcClone != pSrcBitmap) {
744 delete pSrcClone; 744 delete pSrcClone;
745 } 745 }
746 if (pSrcMatched == NULL) { 746 if (!pSrcMatched) {
747 return FALSE; 747 return FALSE;
748 } 748 }
749 pSrcClone = pSrcMatched; 749 pSrcClone = pSrcMatched;
750 } 750 }
751 if (destChannel == FXDIB_Alpha && m_pAlphaMask) { 751 if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
752 pDst = m_pAlphaMask; 752 pDst = m_pAlphaMask;
753 destOffset = 0; 753 destOffset = 0;
754 } 754 }
755 int srcBytes = pSrcClone->GetBPP() / 8; 755 int srcBytes = pSrcClone->GetBPP() / 8;
756 int destBytes = pDst->GetBPP() / 8; 756 int destBytes = pDst->GetBPP() / 8;
757 for (int row = 0; row < m_Height; row++) { 757 for (int row = 0; row < m_Height; row++) {
758 uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset; 758 uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset;
759 const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset; 759 const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset;
760 for (int col = 0; col < m_Width; col++) { 760 for (int col = 0; col < m_Width; col++) {
761 *dest_pos = *src_pos; 761 *dest_pos = *src_pos;
762 dest_pos += destBytes; 762 dest_pos += destBytes;
763 src_pos += srcBytes; 763 src_pos += srcBytes;
764 } 764 }
765 } 765 }
766 if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) { 766 if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) {
767 delete pSrcClone; 767 delete pSrcClone;
768 } 768 }
769 return TRUE; 769 return TRUE;
770 } 770 }
771 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) { 771 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
772 if (m_pBuffer == NULL) { 772 if (!m_pBuffer) {
773 return FALSE; 773 return FALSE;
774 } 774 }
775 int destOffset; 775 int destOffset;
776 if (destChannel == FXDIB_Alpha) { 776 if (destChannel == FXDIB_Alpha) {
777 if (IsAlphaMask()) { 777 if (IsAlphaMask()) {
778 if (!ConvertFormat(FXDIB_8bppMask)) { 778 if (!ConvertFormat(FXDIB_8bppMask)) {
779 return FALSE; 779 return FALSE;
780 } 780 }
781 destOffset = 0; 781 destOffset = 0;
782 } else { 782 } else {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 for (int row = 0; row < m_Height; row++) { 823 for (int row = 0; row < m_Height; row++) {
824 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset; 824 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset;
825 for (int col = 0; col < m_Width; col++) { 825 for (int col = 0; col < m_Width; col++) {
826 *scan_line = value; 826 *scan_line = value;
827 scan_line += Bpp; 827 scan_line += Bpp;
828 } 828 }
829 } 829 }
830 return TRUE; 830 return TRUE;
831 } 831 }
832 FX_BOOL CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) { 832 FX_BOOL CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) {
833 if (m_pBuffer == NULL) { 833 if (!m_pBuffer) {
834 return FALSE; 834 return FALSE;
835 } 835 }
836 ASSERT(pSrcBitmap->IsAlphaMask()); 836 ASSERT(pSrcBitmap->IsAlphaMask());
837 if (!pSrcBitmap->IsAlphaMask()) { 837 if (!pSrcBitmap->IsAlphaMask()) {
838 return FALSE; 838 return FALSE;
839 } 839 }
840 if (!IsAlphaMask() && !HasAlpha()) { 840 if (!IsAlphaMask() && !HasAlpha()) {
841 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha); 841 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
842 } 842 }
843 CFX_DIBitmap* pSrcClone = (CFX_DIBitmap*)pSrcBitmap; 843 CFX_DIBitmap* pSrcClone = (CFX_DIBitmap*)pSrcBitmap;
844 if (pSrcBitmap->GetWidth() != m_Width || 844 if (pSrcBitmap->GetWidth() != m_Width ||
845 pSrcBitmap->GetHeight() != m_Height) { 845 pSrcBitmap->GetHeight() != m_Height) {
846 pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height); 846 pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
847 if (pSrcClone == NULL) { 847 if (!pSrcClone) {
848 return FALSE; 848 return FALSE;
849 } 849 }
850 } 850 }
851 if (IsAlphaMask()) { 851 if (IsAlphaMask()) {
852 if (!ConvertFormat(FXDIB_8bppMask)) { 852 if (!ConvertFormat(FXDIB_8bppMask)) {
853 if (pSrcClone != pSrcBitmap) { 853 if (pSrcClone != pSrcBitmap) {
854 delete pSrcClone; 854 delete pSrcClone;
855 } 855 }
856 return FALSE; 856 return FALSE;
857 } 857 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } else { 890 } else {
891 m_pAlphaMask->MultiplyAlpha(pSrcClone); 891 m_pAlphaMask->MultiplyAlpha(pSrcClone);
892 } 892 }
893 } 893 }
894 if (pSrcClone != pSrcBitmap) { 894 if (pSrcClone != pSrcBitmap) {
895 delete pSrcClone; 895 delete pSrcClone;
896 } 896 }
897 return TRUE; 897 return TRUE;
898 } 898 }
899 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) { 899 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) {
900 if (m_pBuffer == NULL) { 900 if (!m_pBuffer) {
901 return FALSE; 901 return FALSE;
902 } 902 }
903 switch (GetFormat()) { 903 switch (GetFormat()) {
904 case FXDIB_1bppRgb: { 904 case FXDIB_1bppRgb: {
905 if (m_pPalette == NULL) { 905 if (!m_pPalette) {
906 return FALSE; 906 return FALSE;
907 } 907 }
908 uint8_t gray[2]; 908 uint8_t gray[2];
909 for (int i = 0; i < 2; i++) { 909 for (int i = 0; i < 2; i++) {
910 int r = (uint8_t)(m_pPalette[i] >> 16); 910 int r = (uint8_t)(m_pPalette[i] >> 16);
911 int g = (uint8_t)(m_pPalette[i] >> 8); 911 int g = (uint8_t)(m_pPalette[i] >> 8);
912 int b = (uint8_t)m_pPalette[i]; 912 int b = (uint8_t)m_pPalette[i];
913 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); 913 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b);
914 } 914 }
915 CFX_DIBitmap* pMask = new CFX_DIBitmap; 915 CFX_DIBitmap* pMask = new CFX_DIBitmap;
(...skipping 10 matching lines...) Expand all
926 *dest_pos = gray[1]; 926 *dest_pos = gray[1];
927 } 927 }
928 dest_pos++; 928 dest_pos++;
929 } 929 }
930 } 930 }
931 TakeOver(pMask); 931 TakeOver(pMask);
932 delete pMask; 932 delete pMask;
933 break; 933 break;
934 } 934 }
935 case FXDIB_8bppRgb: { 935 case FXDIB_8bppRgb: {
936 if (m_pPalette == NULL) { 936 if (!m_pPalette) {
937 return FALSE; 937 return FALSE;
938 } 938 }
939 uint8_t gray[256]; 939 uint8_t gray[256];
940 for (int i = 0; i < 256; i++) { 940 for (int i = 0; i < 256; i++) {
941 int r = (uint8_t)(m_pPalette[i] >> 16); 941 int r = (uint8_t)(m_pPalette[i] >> 16);
942 int g = (uint8_t)(m_pPalette[i] >> 8); 942 int g = (uint8_t)(m_pPalette[i] >> 8);
943 int b = (uint8_t)m_pPalette[i]; 943 int b = (uint8_t)m_pPalette[i];
944 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); 944 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b);
945 } 945 }
946 CFX_DIBitmap* pMask = new CFX_DIBitmap; 946 CFX_DIBitmap* pMask = new CFX_DIBitmap;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 TakeOver(pMask); 994 TakeOver(pMask);
995 delete pMask; 995 delete pMask;
996 break; 996 break;
997 } 997 }
998 default: 998 default:
999 return FALSE; 999 return FALSE;
1000 } 1000 }
1001 return TRUE; 1001 return TRUE;
1002 } 1002 }
1003 FX_BOOL CFX_DIBitmap::MultiplyAlpha(int alpha) { 1003 FX_BOOL CFX_DIBitmap::MultiplyAlpha(int alpha) {
1004 if (m_pBuffer == NULL) { 1004 if (!m_pBuffer) {
1005 return FALSE; 1005 return FALSE;
1006 } 1006 }
1007 switch (GetFormat()) { 1007 switch (GetFormat()) {
1008 case FXDIB_1bppMask: 1008 case FXDIB_1bppMask:
1009 if (!ConvertFormat(FXDIB_8bppMask)) { 1009 if (!ConvertFormat(FXDIB_8bppMask)) {
1010 return FALSE; 1010 return FALSE;
1011 } 1011 }
1012 MultiplyAlpha(alpha); 1012 MultiplyAlpha(alpha);
1013 break; 1013 break;
1014 case FXDIB_8bppMask: { 1014 case FXDIB_8bppMask: {
(...skipping 27 matching lines...) Expand all
1042 if (!ConvertFormat(FXDIB_Argb)) { 1042 if (!ConvertFormat(FXDIB_Argb)) {
1043 return FALSE; 1043 return FALSE;
1044 } 1044 }
1045 MultiplyAlpha(alpha); 1045 MultiplyAlpha(alpha);
1046 } 1046 }
1047 break; 1047 break;
1048 } 1048 }
1049 return TRUE; 1049 return TRUE;
1050 } 1050 }
1051 FX_DWORD CFX_DIBitmap::GetPixel(int x, int y) const { 1051 FX_DWORD CFX_DIBitmap::GetPixel(int x, int y) const {
1052 if (m_pBuffer == NULL) { 1052 if (!m_pBuffer) {
1053 return 0; 1053 return 0;
1054 } 1054 }
1055 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; 1055 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
1056 switch (GetFormat()) { 1056 switch (GetFormat()) {
1057 case FXDIB_1bppMask: { 1057 case FXDIB_1bppMask: {
1058 if ((*pos) & (1 << (7 - x % 8))) { 1058 if ((*pos) & (1 << (7 - x % 8))) {
1059 return 0xff000000; 1059 return 0xff000000;
1060 } 1060 }
1061 return 0; 1061 return 0;
1062 } 1062 }
(...skipping 12 matching lines...) Expand all
1075 case FXDIB_Rgb32: 1075 case FXDIB_Rgb32:
1076 return FXARGB_GETDIB(pos) | 0xff000000; 1076 return FXARGB_GETDIB(pos) | 0xff000000;
1077 case FXDIB_Argb: 1077 case FXDIB_Argb:
1078 return FXARGB_GETDIB(pos); 1078 return FXARGB_GETDIB(pos);
1079 default: 1079 default:
1080 break; 1080 break;
1081 } 1081 }
1082 return 0; 1082 return 0;
1083 } 1083 }
1084 void CFX_DIBitmap::SetPixel(int x, int y, FX_DWORD color) { 1084 void CFX_DIBitmap::SetPixel(int x, int y, FX_DWORD color) {
1085 if (m_pBuffer == NULL) { 1085 if (!m_pBuffer) {
1086 return; 1086 return;
1087 } 1087 }
1088 if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) { 1088 if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) {
1089 return; 1089 return;
1090 } 1090 }
1091 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; 1091 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
1092 switch (GetFormat()) { 1092 switch (GetFormat()) {
1093 case FXDIB_1bppMask: 1093 case FXDIB_1bppMask:
1094 if (color >> 24) { 1094 if (color >> 24) {
1095 *pos |= 1 << (7 - x % 8); 1095 *pos |= 1 << (7 - x % 8);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 break; 1150 break;
1151 } 1151 }
1152 } 1152 }
1153 void CFX_DIBitmap::DownSampleScanline(int line, 1153 void CFX_DIBitmap::DownSampleScanline(int line,
1154 uint8_t* dest_scan, 1154 uint8_t* dest_scan,
1155 int dest_bpp, 1155 int dest_bpp,
1156 int dest_width, 1156 int dest_width,
1157 FX_BOOL bFlipX, 1157 FX_BOOL bFlipX,
1158 int clip_left, 1158 int clip_left,
1159 int clip_width) const { 1159 int clip_width) const {
1160 if (m_pBuffer == NULL) { 1160 if (!m_pBuffer) {
1161 return; 1161 return;
1162 } 1162 }
1163 int src_Bpp = m_bpp / 8; 1163 int src_Bpp = m_bpp / 8;
1164 uint8_t* scanline = m_pBuffer + line * m_Pitch; 1164 uint8_t* scanline = m_pBuffer + line * m_Pitch;
1165 if (src_Bpp == 0) { 1165 if (src_Bpp == 0) {
1166 for (int i = 0; i < clip_width; i++) { 1166 for (int i = 0; i < clip_width; i++) {
1167 FX_DWORD dest_x = clip_left + i; 1167 FX_DWORD dest_x = clip_left + i;
1168 FX_DWORD src_x = dest_x * m_Width / dest_width; 1168 FX_DWORD src_x = dest_x * m_Width / dest_width;
1169 if (bFlipX) { 1169 if (bFlipX) {
1170 src_x = m_Width - src_x - 1; 1170 src_x = m_Width - src_x - 1;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 int dest_pos = i * src_Bpp; 1210 int dest_pos = i * src_Bpp;
1211 for (int b = 0; b < src_Bpp; b++) { 1211 for (int b = 0; b < src_Bpp; b++) {
1212 dest_scan[dest_pos + b] = scanline[src_x + b]; 1212 dest_scan[dest_pos + b] = scanline[src_x + b];
1213 } 1213 }
1214 } 1214 }
1215 } 1215 }
1216 } 1216 }
1217 FX_BOOL CFX_DIBitmap::ConvertColorScale(FX_DWORD forecolor, 1217 FX_BOOL CFX_DIBitmap::ConvertColorScale(FX_DWORD forecolor,
1218 FX_DWORD backcolor) { 1218 FX_DWORD backcolor) {
1219 ASSERT(!IsAlphaMask()); 1219 ASSERT(!IsAlphaMask());
1220 if (m_pBuffer == NULL || IsAlphaMask()) { 1220 if (!m_pBuffer || IsAlphaMask()) {
1221 return FALSE; 1221 return FALSE;
1222 } 1222 }
1223 int fc, fm, fy, fk, bc, bm, by, bk; 1223 int fc, fm, fy, fk, bc, bm, by, bk;
1224 int fr, fg, fb, br, bg, bb; 1224 int fr, fg, fb, br, bg, bb;
1225 FX_BOOL isCmykImage = IsCmykImage(); 1225 FX_BOOL isCmykImage = IsCmykImage();
1226 if (isCmykImage) { 1226 if (isCmykImage) {
1227 fc = FXSYS_GetCValue(forecolor); 1227 fc = FXSYS_GetCValue(forecolor);
1228 fm = FXSYS_GetMValue(forecolor); 1228 fm = FXSYS_GetMValue(forecolor);
1229 fy = FXSYS_GetYValue(forecolor); 1229 fy = FXSYS_GetYValue(forecolor);
1230 fk = FXSYS_GetKValue(forecolor); 1230 fk = FXSYS_GetKValue(forecolor);
1231 bc = FXSYS_GetCValue(backcolor); 1231 bc = FXSYS_GetCValue(backcolor);
1232 bm = FXSYS_GetMValue(backcolor); 1232 bm = FXSYS_GetMValue(backcolor);
1233 by = FXSYS_GetYValue(backcolor); 1233 by = FXSYS_GetYValue(backcolor);
1234 bk = FXSYS_GetKValue(backcolor); 1234 bk = FXSYS_GetKValue(backcolor);
1235 } else { 1235 } else {
1236 fr = FXSYS_GetRValue(forecolor); 1236 fr = FXSYS_GetRValue(forecolor);
1237 fg = FXSYS_GetGValue(forecolor); 1237 fg = FXSYS_GetGValue(forecolor);
1238 fb = FXSYS_GetBValue(forecolor); 1238 fb = FXSYS_GetBValue(forecolor);
1239 br = FXSYS_GetRValue(backcolor); 1239 br = FXSYS_GetRValue(backcolor);
1240 bg = FXSYS_GetGValue(backcolor); 1240 bg = FXSYS_GetGValue(backcolor);
1241 bb = FXSYS_GetBValue(backcolor); 1241 bb = FXSYS_GetBValue(backcolor);
1242 } 1242 }
1243 if (m_bpp <= 8) { 1243 if (m_bpp <= 8) {
1244 if (isCmykImage) { 1244 if (isCmykImage) {
1245 if (forecolor == 0xff && backcolor == 0 && m_pPalette == NULL) { 1245 if (forecolor == 0xff && backcolor == 0 && !m_pPalette) {
1246 return TRUE; 1246 return TRUE;
1247 } 1247 }
1248 } else if (forecolor == 0 && backcolor == 0xffffff && m_pPalette == NULL) { 1248 } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) {
1249 return TRUE; 1249 return TRUE;
1250 } 1250 }
1251 if (m_pPalette == NULL) { 1251 if (!m_pPalette) {
1252 BuildPalette(); 1252 BuildPalette();
1253 } 1253 }
1254 int size = 1 << m_bpp; 1254 int size = 1 << m_bpp;
1255 if (isCmykImage) { 1255 if (isCmykImage) {
1256 for (int i = 0; i < size; i++) { 1256 for (int i = 0; i < size; i++) {
1257 uint8_t b, g, r; 1257 uint8_t b, g, r;
1258 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]), 1258 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]),
1259 FXSYS_GetMValue(m_pPalette[i]), 1259 FXSYS_GetMValue(m_pPalette[i]),
1260 FXSYS_GetYValue(m_pPalette[i]), 1260 FXSYS_GetYValue(m_pPalette[i]),
1261 FXSYS_GetKValue(m_pPalette[i]), r, g, b); 1261 FXSYS_GetKValue(m_pPalette[i]), r, g, b);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 *scanline = br + (fr - br) * gray / 255; 1329 *scanline = br + (fr - br) * gray / 255;
1330 scanline += gap; 1330 scanline += gap;
1331 } 1331 }
1332 } 1332 }
1333 } 1333 }
1334 return TRUE; 1334 return TRUE;
1335 } 1335 }
1336 FX_BOOL CFX_DIBitmap::DitherFS(const FX_DWORD* pPalette, 1336 FX_BOOL CFX_DIBitmap::DitherFS(const FX_DWORD* pPalette,
1337 int pal_size, 1337 int pal_size,
1338 const FX_RECT* pRect) { 1338 const FX_RECT* pRect) {
1339 if (m_pBuffer == NULL) { 1339 if (!m_pBuffer) {
1340 return FALSE; 1340 return FALSE;
1341 } 1341 }
1342 if (m_bpp != 8 && m_pPalette && m_AlphaFlag != 0) { 1342 if (m_bpp != 8 && m_pPalette && m_AlphaFlag != 0) {
1343 return FALSE; 1343 return FALSE;
1344 } 1344 }
1345 if (m_Width < 4 && m_Height < 4) { 1345 if (m_Width < 4 && m_Height < 4) {
1346 return FALSE; 1346 return FALSE;
1347 } 1347 }
1348 FX_RECT rect(0, 0, m_Width, m_Height); 1348 FX_RECT rect(0, 0, m_Width, m_Height);
1349 if (pRect) { 1349 if (pRect) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 *dest_scan = *src_scan; 1483 *dest_scan = *src_scan;
1484 dest_scan--; 1484 dest_scan--;
1485 src_scan++; 1485 src_scan++;
1486 } 1486 }
1487 } 1487 }
1488 } 1488 }
1489 return pFlipped; 1489 return pFlipped;
1490 } 1490 }
1491 CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) { 1491 CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
1492 m_pBitmap = NULL; 1492 m_pBitmap = NULL;
1493 if (pSrc->GetBuffer() == NULL) { 1493 if (pSrc->GetBuffer()) {
1494 m_pBitmap = pSrc->Clone();
1495 } else {
1496 m_pBitmap = new CFX_DIBitmap; 1494 m_pBitmap = new CFX_DIBitmap;
1497 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), 1495 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(),
1498 pSrc->GetFormat(), pSrc->GetBuffer())) { 1496 pSrc->GetFormat(), pSrc->GetBuffer())) {
1499 delete m_pBitmap; 1497 delete m_pBitmap;
1500 m_pBitmap = NULL; 1498 m_pBitmap = NULL;
1501 return; 1499 return;
1502 } 1500 }
1503 m_pBitmap->CopyPalette(pSrc->GetPalette()); 1501 m_pBitmap->CopyPalette(pSrc->GetPalette());
1504 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); 1502 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask);
1503 } else {
1504 m_pBitmap = pSrc->Clone();
1505 } 1505 }
1506 } 1506 }
1507 CFX_DIBExtractor::~CFX_DIBExtractor() { 1507 CFX_DIBExtractor::~CFX_DIBExtractor() {
1508 delete m_pBitmap; 1508 delete m_pBitmap;
1509 } 1509 }
1510 CFX_FilteredDIB::CFX_FilteredDIB() { 1510 CFX_FilteredDIB::CFX_FilteredDIB() {
1511 m_pScanline = NULL; 1511 m_pScanline = NULL;
1512 m_pSrc = NULL; 1512 m_pSrc = NULL;
1513 } 1513 }
1514 CFX_FilteredDIB::~CFX_FilteredDIB() { 1514 CFX_FilteredDIB::~CFX_FilteredDIB() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 } 1633 }
1634 FX_BOOL CFX_ImageRenderer::Continue(IFX_Pause* pPause) { 1634 FX_BOOL CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
1635 if (m_Status == 1) { 1635 if (m_Status == 1) {
1636 return m_Stretcher.Continue(pPause); 1636 return m_Stretcher.Continue(pPause);
1637 } 1637 }
1638 if (m_Status == 2) { 1638 if (m_Status == 2) {
1639 if (m_pTransformer->Continue(pPause)) { 1639 if (m_pTransformer->Continue(pPause)) {
1640 return TRUE; 1640 return TRUE;
1641 } 1641 }
1642 CFX_DIBitmap* pBitmap = m_pTransformer->m_Storer.Detach(); 1642 CFX_DIBitmap* pBitmap = m_pTransformer->m_Storer.Detach();
1643 if (pBitmap == NULL) { 1643 if (!pBitmap) {
1644 return FALSE; 1644 return FALSE;
1645 } 1645 }
1646 if (pBitmap->GetBuffer() == NULL) { 1646 if (!pBitmap->GetBuffer()) {
1647 delete pBitmap; 1647 delete pBitmap;
1648 return FALSE; 1648 return FALSE;
1649 } 1649 }
1650 if (pBitmap->IsAlphaMask()) { 1650 if (pBitmap->IsAlphaMask()) {
1651 if (m_BitmapAlpha != 255) { 1651 if (m_BitmapAlpha != 255) {
1652 if (m_AlphaFlag >> 8) { 1652 if (m_AlphaFlag >> 8) {
1653 m_AlphaFlag = 1653 m_AlphaFlag =
1654 (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) | 1654 (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) |
1655 ((m_AlphaFlag >> 8) << 8)); 1655 ((m_AlphaFlag >> 8) << 8));
1656 } else { 1656 } else {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 if (!m_pBitmap->Create(width, height, src_format)) { 1715 if (!m_pBitmap->Create(width, height, src_format)) {
1716 delete m_pBitmap; 1716 delete m_pBitmap;
1717 m_pBitmap = NULL; 1717 m_pBitmap = NULL;
1718 return FALSE; 1718 return FALSE;
1719 } 1719 }
1720 if (pSrcPalette) { 1720 if (pSrcPalette) {
1721 m_pBitmap->CopyPalette(pSrcPalette); 1721 m_pBitmap->CopyPalette(pSrcPalette);
1722 } 1722 }
1723 return TRUE; 1723 return TRUE;
1724 } 1724 }
OLDNEW
« no previous file with comments | « core/src/fxge/dib/fx_dib_engine.cpp ('k') | core/src/fxge/dib/fx_dib_transform.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698