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

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

Issue 2534953004: Return unique_ptrs from CFX_DIBitmap::Clone(). (Closed)
Patch Set: win again Created 4 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
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 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 #include <utility> 13 #include <utility>
14 14
15 #include "core/fxcodec/fx_codec.h" 15 #include "core/fxcodec/fx_codec.h"
16 #include "core/fxcrt/cfx_maybe_owned.h"
16 #include "core/fxge/cfx_gemodule.h" 17 #include "core/fxge/cfx_gemodule.h"
17 #include "core/fxge/dib/dib_int.h" 18 #include "core/fxge/dib/dib_int.h"
18 #include "core/fxge/ge/cfx_cliprgn.h" 19 #include "core/fxge/ge/cfx_cliprgn.h"
19 #include "third_party/base/ptr_util.h" 20 #include "third_party/base/ptr_util.h"
20 21
21 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { 22 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) {
22 c = FXSYS_GetCValue(cmyk); 23 c = FXSYS_GetCValue(cmyk);
23 m = FXSYS_GetMValue(cmyk); 24 m = FXSYS_GetMValue(cmyk);
24 y = FXSYS_GetYValue(cmyk); 25 y = FXSYS_GetYValue(cmyk);
25 k = FXSYS_GetKValue(cmyk); 26 k = FXSYS_GetKValue(cmyk);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 pSrcBitmap->m_pBuffer = nullptr; 168 pSrcBitmap->m_pBuffer = nullptr;
168 pSrcBitmap->m_pAlphaMask = nullptr; 169 pSrcBitmap->m_pAlphaMask = nullptr;
169 m_bpp = pSrcBitmap->m_bpp; 170 m_bpp = pSrcBitmap->m_bpp;
170 m_bExtBuf = pSrcBitmap->m_bExtBuf; 171 m_bExtBuf = pSrcBitmap->m_bExtBuf;
171 m_AlphaFlag = pSrcBitmap->m_AlphaFlag; 172 m_AlphaFlag = pSrcBitmap->m_AlphaFlag;
172 m_Width = pSrcBitmap->m_Width; 173 m_Width = pSrcBitmap->m_Width;
173 m_Height = pSrcBitmap->m_Height; 174 m_Height = pSrcBitmap->m_Height;
174 m_Pitch = pSrcBitmap->m_Pitch; 175 m_Pitch = pSrcBitmap->m_Pitch;
175 } 176 }
176 177
177 CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const { 178 std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
178 FX_RECT rect(0, 0, m_Width, m_Height); 179 FX_RECT rect(0, 0, m_Width, m_Height);
179 if (pClip) { 180 if (pClip) {
180 rect.Intersect(*pClip); 181 rect.Intersect(*pClip);
181 if (rect.IsEmpty()) { 182 if (rect.IsEmpty())
182 return nullptr; 183 return nullptr;
183 }
184 } 184 }
185 std::unique_ptr<CFX_DIBitmap> pNewBitmap(new CFX_DIBitmap); 185 auto pNewBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
186 if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat())) 186 if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
187 return nullptr; 187 return nullptr;
188 188
189 pNewBitmap->CopyPalette(m_pPalette.get()); 189 pNewBitmap->CopyPalette(m_pPalette.get());
190 pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip); 190 pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip);
191 if (GetBPP() == 1 && rect.left % 8 != 0) { 191 if (GetBPP() == 1 && rect.left % 8 != 0) {
192 int left_shift = rect.left % 32; 192 int left_shift = rect.left % 32;
193 int right_shift = 32 - left_shift; 193 int right_shift = 32 - left_shift;
194 int dword_count = pNewBitmap->m_Pitch / 4; 194 int dword_count = pNewBitmap->m_Pitch / 4;
195 for (int row = rect.top; row < rect.bottom; row++) { 195 for (int row = rect.top; row < rect.bottom; row++) {
196 uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32; 196 uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32;
197 uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top); 197 uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top);
198 for (int i = 0; i < dword_count; i++) { 198 for (int i = 0; i < dword_count; i++) {
199 dest_scan[i] = 199 dest_scan[i] =
200 (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift); 200 (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift);
201 } 201 }
202 } 202 }
203 } else { 203 } else {
204 int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8; 204 int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8;
205 if (m_Pitch < (uint32_t)copy_len) { 205 if (m_Pitch < (uint32_t)copy_len) {
npm 2016/12/05 20:37:23 Nit: {}
Tom Sepez 2016/12/05 21:38:13 Done.
206 copy_len = m_Pitch; 206 copy_len = m_Pitch;
207 } 207 }
208 for (int row = rect.top; row < rect.bottom; row++) { 208 for (int row = rect.top; row < rect.bottom; row++) {
209 const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8; 209 const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8;
210 uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top); 210 uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top);
211 FXSYS_memcpy(dest_scan, src_scan, copy_len); 211 FXSYS_memcpy(dest_scan, src_scan, copy_len);
212 } 212 }
213 } 213 }
214 return pNewBitmap.release(); 214 return pNewBitmap;
215 } 215 }
216 216
217 void CFX_DIBSource::BuildPalette() { 217 void CFX_DIBSource::BuildPalette() {
218 if (m_pPalette) { 218 if (m_pPalette)
219 return; 219 return;
220 } 220
221 if (GetBPP() == 1) { 221 if (GetBPP() == 1) {
222 m_pPalette.reset(FX_Alloc(uint32_t, 2)); 222 m_pPalette.reset(FX_Alloc(uint32_t, 2));
223 if (IsCmykImage()) { 223 if (IsCmykImage()) {
224 m_pPalette.get()[0] = 0xff; 224 m_pPalette.get()[0] = 0xff;
225 m_pPalette.get()[1] = 0; 225 m_pPalette.get()[1] = 0;
226 } else { 226 } else {
227 m_pPalette.get()[0] = 0xff000000; 227 m_pPalette.get()[0] = 0xff000000;
228 m_pPalette.get()[1] = 0xffffffff; 228 m_pPalette.get()[1] = 0xffffffff;
229 } 229 }
230 } else if (GetBPP() == 8) { 230 } else if (GetBPP() == 8) {
231 m_pPalette.reset(FX_Alloc(uint32_t, 256)); 231 m_pPalette.reset(FX_Alloc(uint32_t, 256));
232 if (IsCmykImage()) { 232 if (IsCmykImage()) {
233 for (int i = 0; i < 256; i++) { 233 for (int i = 0; i < 256; i++)
234 m_pPalette.get()[i] = 0xff - i; 234 m_pPalette.get()[i] = 0xff - i;
235 }
236 } else { 235 } else {
237 for (int i = 0; i < 256; i++) { 236 for (int i = 0; i < 256; i++)
238 m_pPalette.get()[i] = 0xff000000 | (i * 0x10101); 237 m_pPalette.get()[i] = 0xff000000 | (i * 0x10101);
239 }
240 } 238 }
241 } 239 }
242 } 240 }
243 241
244 bool CFX_DIBSource::BuildAlphaMask() { 242 bool CFX_DIBSource::BuildAlphaMask() {
245 if (m_pAlphaMask) { 243 if (m_pAlphaMask) {
246 return true; 244 return true;
247 } 245 }
248 m_pAlphaMask = new CFX_DIBitmap; 246 m_pAlphaMask = new CFX_DIBitmap;
249 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 247 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } else { 656 } else {
659 m_pAlphaMask->Clear(0xff000000); 657 m_pAlphaMask->Clear(0xff000000);
660 } 658 }
661 return true; 659 return true;
662 } 660 }
663 661
664 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3}; 662 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
665 bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, 663 bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
666 const CFX_DIBSource* pSrcBitmap, 664 const CFX_DIBSource* pSrcBitmap,
667 FXDIB_Channel srcChannel) { 665 FXDIB_Channel srcChannel) {
668 if (!m_pBuffer) { 666 if (!m_pBuffer)
669 return false; 667 return false;
670 } 668
671 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap; 669 CFX_MaybeOwned<CFX_DIBSource> pSrcClone(
672 CFX_DIBitmap* pDst = this; 670 const_cast<CFX_DIBSource*>(pSrcBitmap));
dsinclair 2016/12/05 20:41:26 Should we remove the const from the signature?
Tom Sepez 2016/12/05 21:38:13 Ok. Not too many ripples ...
673 int destOffset, srcOffset; 671 int srcOffset;
674 if (srcChannel == FXDIB_Alpha) { 672 if (srcChannel == FXDIB_Alpha) {
675 if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) { 673 if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask())
676 return false; 674 return false;
677 } 675
678 if (pSrcBitmap->GetBPP() == 1) { 676 if (pSrcBitmap->GetBPP() == 1) {
679 pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask); 677 pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask);
680 if (!pSrcClone) { 678 if (!pSrcClone)
681 return false; 679 return false;
682 }
683 } 680 }
684 if (pSrcBitmap->GetFormat() == FXDIB_Argb) { 681 srcOffset = pSrcBitmap->GetFormat() == FXDIB_Argb ? 3 : 0;
685 srcOffset = 3;
686 } else {
687 srcOffset = 0;
688 }
689 } else { 682 } else {
690 if (pSrcBitmap->IsAlphaMask()) { 683 if (pSrcBitmap->IsAlphaMask())
691 return false; 684 return false;
692 } 685
693 if (pSrcBitmap->GetBPP() < 24) { 686 if (pSrcBitmap->GetBPP() < 24) {
694 if (pSrcBitmap->IsCmykImage()) { 687 if (pSrcBitmap->IsCmykImage()) {
695 pSrcClone = pSrcBitmap->CloneConvert( 688 pSrcClone = pSrcBitmap->CloneConvert(
696 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20)); 689 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20));
dsinclair 2016/12/05 20:41:26 static_cast? and below
Tom Sepez 2016/12/05 21:38:13 Done.
697 } else { 690 } else {
698 pSrcClone = pSrcBitmap->CloneConvert( 691 pSrcClone = pSrcBitmap->CloneConvert(
699 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18)); 692 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18));
700 } 693 }
701 if (!pSrcClone) { 694 if (!pSrcClone)
702 return false; 695 return false;
703 }
704 } 696 }
705 srcOffset = g_ChannelOffset[srcChannel]; 697 srcOffset = g_ChannelOffset[srcChannel];
706 } 698 }
699 int destOffset = 0;
707 if (destChannel == FXDIB_Alpha) { 700 if (destChannel == FXDIB_Alpha) {
708 if (IsAlphaMask()) { 701 if (IsAlphaMask()) {
709 if (!ConvertFormat(FXDIB_8bppMask)) { 702 if (!ConvertFormat(FXDIB_8bppMask))
710 if (pSrcClone != pSrcBitmap) {
711 delete pSrcClone;
712 }
713 return false; 703 return false;
714 }
715 destOffset = 0;
716 } else { 704 } else {
717 destOffset = 0; 705 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb))
718 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) {
719 if (pSrcClone != pSrcBitmap) {
720 delete pSrcClone;
721 }
722 return false; 706 return false;
723 } 707
724 if (GetFormat() == FXDIB_Argb) { 708 if (GetFormat() == FXDIB_Argb)
725 destOffset = 3; 709 destOffset = 3;
726 }
727 } 710 }
728 } else { 711 } else {
729 if (IsAlphaMask()) { 712 if (IsAlphaMask())
730 if (pSrcClone != pSrcBitmap) {
731 delete pSrcClone;
732 }
733 return false; 713 return false;
734 } 714
735 if (GetBPP() < 24) { 715 if (GetBPP() < 24) {
736 if (HasAlpha()) { 716 if (HasAlpha()) {
737 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) { 717 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb))
738 if (pSrcClone != pSrcBitmap) {
739 delete pSrcClone;
740 }
741 return false; 718 return false;
742 }
743 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 719 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
744 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) { 720 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) {
745 #else 721 #else
746 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) { 722 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) {
747 #endif 723 #endif
748 if (pSrcClone != pSrcBitmap) {
749 delete pSrcClone;
750 }
751 return false; 724 return false;
752 } 725 }
753 } 726 }
754 destOffset = g_ChannelOffset[destChannel]; 727 destOffset = g_ChannelOffset[destChannel];
755 } 728 }
756 if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) { 729 if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
757 CFX_DIBitmap* pAlphaMask = pSrcClone->m_pAlphaMask; 730 CFX_MaybeOwned<CFX_DIBSource> pAlphaMask(pSrcClone->m_pAlphaMask);
758 if (pSrcClone->GetWidth() != m_Width || 731 if (pSrcClone->GetWidth() != m_Width ||
759 pSrcClone->GetHeight() != m_Height) { 732 pSrcClone->GetHeight() != m_Height) {
760 if (pAlphaMask) { 733 if (pAlphaMask) {
761 pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height); 734 pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height);
762 if (!pAlphaMask) { 735 if (!pAlphaMask)
763 if (pSrcClone != pSrcBitmap) {
764 delete pSrcClone;
765 }
766 return false; 736 return false;
767 }
768 } 737 }
769 } 738 }
770 if (pSrcClone != pSrcBitmap) { 739 pSrcClone = std::move(pAlphaMask);
771 pSrcClone->m_pAlphaMask = nullptr;
772 delete pSrcClone;
773 }
774 pSrcClone = pAlphaMask;
775 srcOffset = 0; 740 srcOffset = 0;
776 } else if (pSrcClone->GetWidth() != m_Width || 741 } else if (pSrcClone->GetWidth() != m_Width ||
777 pSrcClone->GetHeight() != m_Height) { 742 pSrcClone->GetHeight() != m_Height) {
778 CFX_DIBitmap* pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height); 743 std::unique_ptr<CFX_DIBitmap> pSrcMatched =
779 if (pSrcClone != pSrcBitmap) { 744 pSrcClone->StretchTo(m_Width, m_Height);
780 delete pSrcClone; 745 if (!pSrcMatched)
781 }
782 if (!pSrcMatched) {
783 return false; 746 return false;
784 } 747
785 pSrcClone = pSrcMatched; 748 pSrcClone = std::move(pSrcMatched);
786 } 749 }
750 CFX_DIBitmap* pDst = this;
787 if (destChannel == FXDIB_Alpha && m_pAlphaMask) { 751 if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
788 pDst = m_pAlphaMask; 752 pDst = m_pAlphaMask;
789 destOffset = 0; 753 destOffset = 0;
790 } 754 }
791 int srcBytes = pSrcClone->GetBPP() / 8; 755 int srcBytes = pSrcClone->GetBPP() / 8;
792 int destBytes = pDst->GetBPP() / 8; 756 int destBytes = pDst->GetBPP() / 8;
793 for (int row = 0; row < m_Height; row++) { 757 for (int row = 0; row < m_Height; row++) {
794 uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset; 758 uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset;
795 const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset; 759 const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset;
796 for (int col = 0; col < m_Width; col++) { 760 for (int col = 0; col < m_Width; col++) {
797 *dest_pos = *src_pos; 761 *dest_pos = *src_pos;
798 dest_pos += destBytes; 762 dest_pos += destBytes;
799 src_pos += srcBytes; 763 src_pos += srcBytes;
800 } 764 }
801 } 765 }
802 if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) {
803 delete pSrcClone;
804 }
805 return true; 766 return true;
806 } 767 }
807 768
808 bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) { 769 bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
809 if (!m_pBuffer) { 770 if (!m_pBuffer) {
810 return false; 771 return false;
811 } 772 }
812 int destOffset; 773 int destOffset;
813 if (destChannel == FXDIB_Alpha) { 774 if (destChannel == FXDIB_Alpha) {
814 if (IsAlphaMask()) { 775 if (IsAlphaMask()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset; 819 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset;
859 for (int col = 0; col < m_Width; col++) { 820 for (int col = 0; col < m_Width; col++) {
860 *scan_line = value; 821 *scan_line = value;
861 scan_line += Bpp; 822 scan_line += Bpp;
862 } 823 }
863 } 824 }
864 return true; 825 return true;
865 } 826 }
866 827
867 bool CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) { 828 bool CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) {
868 if (!m_pBuffer) { 829 if (!m_pBuffer)
869 return false; 830 return false;
870 } 831
871 ASSERT(pSrcBitmap->IsAlphaMask()); 832 ASSERT(pSrcBitmap->IsAlphaMask());
872 if (!pSrcBitmap->IsAlphaMask()) { 833 if (!pSrcBitmap->IsAlphaMask())
873 return false; 834 return false;
874 } 835
875 if (!IsAlphaMask() && !HasAlpha()) { 836 if (!IsAlphaMask() && !HasAlpha())
876 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha); 837 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
877 } 838
878 CFX_DIBitmap* pSrcClone = (CFX_DIBitmap*)pSrcBitmap; 839 CFX_MaybeOwned<CFX_DIBitmap> pSrcClone(
840 static_cast<CFX_DIBitmap*>(const_cast<CFX_DIBSource*>(pSrcBitmap)));
npm 2016/12/05 20:37:23 Why 2 casts?
Tom Sepez 2016/12/05 21:38:13 Because a const_cast can't change type, and a stat
879 if (pSrcBitmap->GetWidth() != m_Width || 841 if (pSrcBitmap->GetWidth() != m_Width ||
880 pSrcBitmap->GetHeight() != m_Height) { 842 pSrcBitmap->GetHeight() != m_Height) {
881 pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height); 843 pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
882 if (!pSrcClone) { 844 if (!pSrcClone)
883 return false; 845 return false;
884 }
885 } 846 }
886 if (IsAlphaMask()) { 847 if (IsAlphaMask()) {
887 if (!ConvertFormat(FXDIB_8bppMask)) { 848 if (!ConvertFormat(FXDIB_8bppMask))
888 if (pSrcClone != pSrcBitmap) {
889 delete pSrcClone;
890 }
891 return false; 849 return false;
892 } 850
893 for (int row = 0; row < m_Height; row++) { 851 for (int row = 0; row < m_Height; row++) {
894 uint8_t* dest_scan = m_pBuffer + m_Pitch * row; 852 uint8_t* dest_scan = m_pBuffer + m_Pitch * row;
895 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row; 853 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
896 if (pSrcClone->GetBPP() == 1) { 854 if (pSrcClone->GetBPP() == 1) {
897 for (int col = 0; col < m_Width; col++) { 855 for (int col = 0; col < m_Width; col++) {
898 if (!((1 << (7 - col % 8)) & src_scan[col / 8])) { 856 if (!((1 << (7 - col % 8)) & src_scan[col / 8])) {
npm 2016/12/05 20:37:23 Nit: {}
Tom Sepez 2016/12/05 21:38:13 Done.
899 dest_scan[col] = 0; 857 dest_scan[col] = 0;
900 } 858 }
901 } 859 }
902 } else { 860 } else {
903 for (int col = 0; col < m_Width; col++) { 861 for (int col = 0; col < m_Width; col++) {
904 *dest_scan = (*dest_scan) * src_scan[col] / 255; 862 *dest_scan = (*dest_scan) * src_scan[col] / 255;
905 dest_scan++; 863 dest_scan++;
906 } 864 }
907 } 865 }
908 } 866 }
909 } else { 867 } else {
910 if (GetFormat() == FXDIB_Argb) { 868 if (GetFormat() == FXDIB_Argb) {
911 if (pSrcClone->GetBPP() == 1) { 869 if (pSrcClone->GetBPP() == 1)
912 if (pSrcClone != pSrcBitmap) {
913 delete pSrcClone;
914 }
915 return false; 870 return false;
916 } 871
917 for (int row = 0; row < m_Height; row++) { 872 for (int row = 0; row < m_Height; row++) {
918 uint8_t* dest_scan = m_pBuffer + m_Pitch * row + 3; 873 uint8_t* dest_scan = m_pBuffer + m_Pitch * row + 3;
919 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row; 874 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row;
920 for (int col = 0; col < m_Width; col++) { 875 for (int col = 0; col < m_Width; col++) {
921 *dest_scan = (*dest_scan) * src_scan[col] / 255; 876 *dest_scan = (*dest_scan) * src_scan[col] / 255;
922 dest_scan += 4; 877 dest_scan += 4;
923 } 878 }
924 } 879 }
925 } else { 880 } else {
926 m_pAlphaMask->MultiplyAlpha(pSrcClone); 881 m_pAlphaMask->MultiplyAlpha(pSrcClone.Get());
927 } 882 }
928 } 883 }
929 if (pSrcClone != pSrcBitmap) {
930 delete pSrcClone;
931 }
932 return true; 884 return true;
933 } 885 }
934 886
935 bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { 887 bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
936 if (!m_pBuffer) { 888 if (!m_pBuffer) {
937 return false; 889 return false;
938 } 890 }
939 switch (GetFormat()) { 891 switch (GetFormat()) {
940 case FXDIB_1bppRgb: { 892 case FXDIB_1bppRgb: {
941 if (!m_pPalette) { 893 if (!m_pPalette) {
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 if (pSrc->GetBuffer()) { 1421 if (pSrc->GetBuffer()) {
1470 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); 1422 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
1471 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), 1423 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(),
1472 pSrc->GetFormat(), pSrc->GetBuffer())) { 1424 pSrc->GetFormat(), pSrc->GetBuffer())) {
1473 m_pBitmap.reset(); 1425 m_pBitmap.reset();
1474 return; 1426 return;
1475 } 1427 }
1476 m_pBitmap->CopyPalette(pSrc->GetPalette()); 1428 m_pBitmap->CopyPalette(pSrc->GetPalette());
1477 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); 1429 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask);
1478 } else { 1430 } else {
1479 m_pBitmap.reset(pSrc->Clone()); 1431 m_pBitmap = pSrc->Clone();
1480 } 1432 }
1481 } 1433 }
1482 1434
1483 CFX_DIBExtractor::~CFX_DIBExtractor() {} 1435 CFX_DIBExtractor::~CFX_DIBExtractor() {}
1484 1436
1485 CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {} 1437 CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {}
1486 1438
1487 CFX_FilteredDIB::~CFX_FilteredDIB() { 1439 CFX_FilteredDIB::~CFX_FilteredDIB() {
1488 if (m_bAutoDropSrc) { 1440 if (m_bAutoDropSrc) {
1489 delete m_pSrc; 1441 delete m_pSrc;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 uint32_t* pSrcPalette) { 1640 uint32_t* pSrcPalette) {
1689 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); 1641 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
1690 if (!m_pBitmap->Create(width, height, src_format)) { 1642 if (!m_pBitmap->Create(width, height, src_format)) {
1691 m_pBitmap.reset(); 1643 m_pBitmap.reset();
1692 return false; 1644 return false;
1693 } 1645 }
1694 if (pSrcPalette) 1646 if (pSrcPalette)
1695 m_pBitmap->CopyPalette(pSrcPalette); 1647 m_pBitmap->CopyPalette(pSrcPalette);
1696 return true; 1648 return true;
1697 } 1649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698