OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/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 Loading... |
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) |
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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 pAlphaMask->GetScanline(row + rect.top) + rect.left, | 654 pAlphaMask->GetScanline(row + rect.top) + rect.left, |
657 m_pAlphaMask->m_Pitch); | 655 m_pAlphaMask->m_Pitch); |
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 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(pSrcBitmap); |
672 CFX_DIBitmap* pDst = this; | 670 int srcOffset; |
673 int destOffset, srcOffset; | |
674 if (srcChannel == FXDIB_Alpha) { | 671 if (srcChannel == FXDIB_Alpha) { |
675 if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) { | 672 if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) |
676 return false; | 673 return false; |
677 } | 674 |
678 if (pSrcBitmap->GetBPP() == 1) { | 675 if (pSrcBitmap->GetBPP() == 1) { |
679 pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask); | 676 pSrcClone = pSrcBitmap->CloneConvert(FXDIB_8bppMask); |
680 if (!pSrcClone) { | 677 if (!pSrcClone) |
681 return false; | 678 return false; |
682 } | |
683 } | 679 } |
684 if (pSrcBitmap->GetFormat() == FXDIB_Argb) { | 680 srcOffset = pSrcBitmap->GetFormat() == FXDIB_Argb ? 3 : 0; |
685 srcOffset = 3; | |
686 } else { | |
687 srcOffset = 0; | |
688 } | |
689 } else { | 681 } else { |
690 if (pSrcBitmap->IsAlphaMask()) { | 682 if (pSrcBitmap->IsAlphaMask()) |
691 return false; | 683 return false; |
692 } | 684 |
693 if (pSrcBitmap->GetBPP() < 24) { | 685 if (pSrcBitmap->GetBPP() < 24) { |
694 if (pSrcBitmap->IsCmykImage()) { | 686 if (pSrcBitmap->IsCmykImage()) { |
695 pSrcClone = pSrcBitmap->CloneConvert( | 687 pSrcClone = pSrcBitmap->CloneConvert(static_cast<FXDIB_Format>( |
696 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x20)); | 688 (pSrcBitmap->GetFormat() & 0xff00) | 0x20)); |
697 } else { | 689 } else { |
698 pSrcClone = pSrcBitmap->CloneConvert( | 690 pSrcClone = pSrcBitmap->CloneConvert(static_cast<FXDIB_Format>( |
699 (FXDIB_Format)((pSrcBitmap->GetFormat() & 0xff00) | 0x18)); | 691 (pSrcBitmap->GetFormat() & 0xff00) | 0x18)); |
700 } | 692 } |
701 if (!pSrcClone) { | 693 if (!pSrcClone) |
702 return false; | 694 return false; |
703 } | |
704 } | 695 } |
705 srcOffset = g_ChannelOffset[srcChannel]; | 696 srcOffset = g_ChannelOffset[srcChannel]; |
706 } | 697 } |
| 698 int destOffset = 0; |
707 if (destChannel == FXDIB_Alpha) { | 699 if (destChannel == FXDIB_Alpha) { |
708 if (IsAlphaMask()) { | 700 if (IsAlphaMask()) { |
709 if (!ConvertFormat(FXDIB_8bppMask)) { | 701 if (!ConvertFormat(FXDIB_8bppMask)) |
710 if (pSrcClone != pSrcBitmap) { | |
711 delete pSrcClone; | |
712 } | |
713 return false; | 702 return false; |
714 } | |
715 destOffset = 0; | |
716 } else { | 703 } else { |
717 destOffset = 0; | 704 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; | 705 return false; |
723 } | 706 |
724 if (GetFormat() == FXDIB_Argb) { | 707 if (GetFormat() == FXDIB_Argb) |
725 destOffset = 3; | 708 destOffset = 3; |
726 } | |
727 } | 709 } |
728 } else { | 710 } else { |
729 if (IsAlphaMask()) { | 711 if (IsAlphaMask()) |
730 if (pSrcClone != pSrcBitmap) { | |
731 delete pSrcClone; | |
732 } | |
733 return false; | 712 return false; |
734 } | 713 |
735 if (GetBPP() < 24) { | 714 if (GetBPP() < 24) { |
736 if (HasAlpha()) { | 715 if (HasAlpha()) { |
737 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) { | 716 if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyka : FXDIB_Argb)) |
738 if (pSrcClone != pSrcBitmap) { | |
739 delete pSrcClone; | |
740 } | |
741 return false; | 717 return false; |
742 } | |
743 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 718 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
744 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) { | 719 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb32)) { |
745 #else | 720 #else |
746 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) { | 721 } else if (!ConvertFormat(IsCmykImage() ? FXDIB_Cmyk : FXDIB_Rgb)) { |
747 #endif | 722 #endif |
748 if (pSrcClone != pSrcBitmap) { | |
749 delete pSrcClone; | |
750 } | |
751 return false; | 723 return false; |
752 } | 724 } |
753 } | 725 } |
754 destOffset = g_ChannelOffset[destChannel]; | 726 destOffset = g_ChannelOffset[destChannel]; |
755 } | 727 } |
756 if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) { | 728 if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) { |
757 CFX_DIBitmap* pAlphaMask = pSrcClone->m_pAlphaMask; | 729 CFX_MaybeOwned<CFX_DIBSource> pAlphaMask(pSrcClone->m_pAlphaMask); |
758 if (pSrcClone->GetWidth() != m_Width || | 730 if (pSrcClone->GetWidth() != m_Width || |
759 pSrcClone->GetHeight() != m_Height) { | 731 pSrcClone->GetHeight() != m_Height) { |
760 if (pAlphaMask) { | 732 if (pAlphaMask) { |
761 pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height); | 733 pAlphaMask = pAlphaMask->StretchTo(m_Width, m_Height); |
762 if (!pAlphaMask) { | 734 if (!pAlphaMask) |
763 if (pSrcClone != pSrcBitmap) { | |
764 delete pSrcClone; | |
765 } | |
766 return false; | 735 return false; |
767 } | |
768 } | 736 } |
769 } | 737 } |
770 if (pSrcClone != pSrcBitmap) { | 738 pSrcClone = std::move(pAlphaMask); |
771 pSrcClone->m_pAlphaMask = nullptr; | |
772 delete pSrcClone; | |
773 } | |
774 pSrcClone = pAlphaMask; | |
775 srcOffset = 0; | 739 srcOffset = 0; |
776 } else if (pSrcClone->GetWidth() != m_Width || | 740 } else if (pSrcClone->GetWidth() != m_Width || |
777 pSrcClone->GetHeight() != m_Height) { | 741 pSrcClone->GetHeight() != m_Height) { |
778 CFX_DIBitmap* pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height); | 742 std::unique_ptr<CFX_DIBitmap> pSrcMatched = |
779 if (pSrcClone != pSrcBitmap) { | 743 pSrcClone->StretchTo(m_Width, m_Height); |
780 delete pSrcClone; | 744 if (!pSrcMatched) |
781 } | |
782 if (!pSrcMatched) { | |
783 return false; | 745 return false; |
784 } | 746 |
785 pSrcClone = pSrcMatched; | 747 pSrcClone = std::move(pSrcMatched); |
786 } | 748 } |
| 749 CFX_DIBitmap* pDst = this; |
787 if (destChannel == FXDIB_Alpha && m_pAlphaMask) { | 750 if (destChannel == FXDIB_Alpha && m_pAlphaMask) { |
788 pDst = m_pAlphaMask; | 751 pDst = m_pAlphaMask; |
789 destOffset = 0; | 752 destOffset = 0; |
790 } | 753 } |
791 int srcBytes = pSrcClone->GetBPP() / 8; | 754 int srcBytes = pSrcClone->GetBPP() / 8; |
792 int destBytes = pDst->GetBPP() / 8; | 755 int destBytes = pDst->GetBPP() / 8; |
793 for (int row = 0; row < m_Height; row++) { | 756 for (int row = 0; row < m_Height; row++) { |
794 uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset; | 757 uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset; |
795 const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset; | 758 const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset; |
796 for (int col = 0; col < m_Width; col++) { | 759 for (int col = 0; col < m_Width; col++) { |
797 *dest_pos = *src_pos; | 760 *dest_pos = *src_pos; |
798 dest_pos += destBytes; | 761 dest_pos += destBytes; |
799 src_pos += srcBytes; | 762 src_pos += srcBytes; |
800 } | 763 } |
801 } | 764 } |
802 if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) { | |
803 delete pSrcClone; | |
804 } | |
805 return true; | 765 return true; |
806 } | 766 } |
807 | 767 |
808 bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) { | 768 bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) { |
809 if (!m_pBuffer) { | 769 if (!m_pBuffer) { |
810 return false; | 770 return false; |
811 } | 771 } |
812 int destOffset; | 772 int destOffset; |
813 if (destChannel == FXDIB_Alpha) { | 773 if (destChannel == FXDIB_Alpha) { |
814 if (IsAlphaMask()) { | 774 if (IsAlphaMask()) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 for (int row = 0; row < m_Height; row++) { | 817 for (int row = 0; row < m_Height; row++) { |
858 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset; | 818 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset; |
859 for (int col = 0; col < m_Width; col++) { | 819 for (int col = 0; col < m_Width; col++) { |
860 *scan_line = value; | 820 *scan_line = value; |
861 scan_line += Bpp; | 821 scan_line += Bpp; |
862 } | 822 } |
863 } | 823 } |
864 return true; | 824 return true; |
865 } | 825 } |
866 | 826 |
867 bool CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) { | 827 bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) { |
868 if (!m_pBuffer) { | 828 if (!m_pBuffer) |
869 return false; | 829 return false; |
870 } | 830 |
871 ASSERT(pSrcBitmap->IsAlphaMask()); | 831 ASSERT(pSrcBitmap->IsAlphaMask()); |
872 if (!pSrcBitmap->IsAlphaMask()) { | 832 if (!pSrcBitmap->IsAlphaMask()) |
873 return false; | 833 return false; |
874 } | 834 |
875 if (!IsAlphaMask() && !HasAlpha()) { | 835 if (!IsAlphaMask() && !HasAlpha()) |
876 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha); | 836 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha); |
877 } | 837 |
878 CFX_DIBitmap* pSrcClone = (CFX_DIBitmap*)pSrcBitmap; | 838 CFX_MaybeOwned<CFX_DIBitmap> pSrcClone( |
| 839 static_cast<CFX_DIBitmap*>(pSrcBitmap)); |
879 if (pSrcBitmap->GetWidth() != m_Width || | 840 if (pSrcBitmap->GetWidth() != m_Width || |
880 pSrcBitmap->GetHeight() != m_Height) { | 841 pSrcBitmap->GetHeight() != m_Height) { |
881 pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height); | 842 pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height); |
882 if (!pSrcClone) { | 843 if (!pSrcClone) |
883 return false; | 844 return false; |
884 } | |
885 } | 845 } |
886 if (IsAlphaMask()) { | 846 if (IsAlphaMask()) { |
887 if (!ConvertFormat(FXDIB_8bppMask)) { | 847 if (!ConvertFormat(FXDIB_8bppMask)) |
888 if (pSrcClone != pSrcBitmap) { | |
889 delete pSrcClone; | |
890 } | |
891 return false; | 848 return false; |
892 } | 849 |
893 for (int row = 0; row < m_Height; row++) { | 850 for (int row = 0; row < m_Height; row++) { |
894 uint8_t* dest_scan = m_pBuffer + m_Pitch * row; | 851 uint8_t* dest_scan = m_pBuffer + m_Pitch * row; |
895 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row; | 852 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row; |
896 if (pSrcClone->GetBPP() == 1) { | 853 if (pSrcClone->GetBPP() == 1) { |
897 for (int col = 0; col < m_Width; col++) { | 854 for (int col = 0; col < m_Width; col++) { |
898 if (!((1 << (7 - col % 8)) & src_scan[col / 8])) { | 855 if (!((1 << (7 - col % 8)) & src_scan[col / 8])) |
899 dest_scan[col] = 0; | 856 dest_scan[col] = 0; |
900 } | |
901 } | 857 } |
902 } else { | 858 } else { |
903 for (int col = 0; col < m_Width; col++) { | 859 for (int col = 0; col < m_Width; col++) { |
904 *dest_scan = (*dest_scan) * src_scan[col] / 255; | 860 *dest_scan = (*dest_scan) * src_scan[col] / 255; |
905 dest_scan++; | 861 dest_scan++; |
906 } | 862 } |
907 } | 863 } |
908 } | 864 } |
909 } else { | 865 } else { |
910 if (GetFormat() == FXDIB_Argb) { | 866 if (GetFormat() == FXDIB_Argb) { |
911 if (pSrcClone->GetBPP() == 1) { | 867 if (pSrcClone->GetBPP() == 1) |
912 if (pSrcClone != pSrcBitmap) { | |
913 delete pSrcClone; | |
914 } | |
915 return false; | 868 return false; |
916 } | 869 |
917 for (int row = 0; row < m_Height; row++) { | 870 for (int row = 0; row < m_Height; row++) { |
918 uint8_t* dest_scan = m_pBuffer + m_Pitch * row + 3; | 871 uint8_t* dest_scan = m_pBuffer + m_Pitch * row + 3; |
919 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row; | 872 uint8_t* src_scan = pSrcClone->m_pBuffer + pSrcClone->m_Pitch * row; |
920 for (int col = 0; col < m_Width; col++) { | 873 for (int col = 0; col < m_Width; col++) { |
921 *dest_scan = (*dest_scan) * src_scan[col] / 255; | 874 *dest_scan = (*dest_scan) * src_scan[col] / 255; |
922 dest_scan += 4; | 875 dest_scan += 4; |
923 } | 876 } |
924 } | 877 } |
925 } else { | 878 } else { |
926 m_pAlphaMask->MultiplyAlpha(pSrcClone); | 879 m_pAlphaMask->MultiplyAlpha(pSrcClone.Get()); |
927 } | 880 } |
928 } | 881 } |
929 if (pSrcClone != pSrcBitmap) { | |
930 delete pSrcClone; | |
931 } | |
932 return true; | 882 return true; |
933 } | 883 } |
934 | 884 |
935 bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { | 885 bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { |
936 if (!m_pBuffer) { | 886 if (!m_pBuffer) { |
937 return false; | 887 return false; |
938 } | 888 } |
939 switch (GetFormat()) { | 889 switch (GetFormat()) { |
940 case FXDIB_1bppRgb: { | 890 case FXDIB_1bppRgb: { |
941 if (!m_pPalette) { | 891 if (!m_pPalette) { |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 if (pSrc->GetBuffer()) { | 1419 if (pSrc->GetBuffer()) { |
1470 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); | 1420 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); |
1471 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), | 1421 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), |
1472 pSrc->GetFormat(), pSrc->GetBuffer())) { | 1422 pSrc->GetFormat(), pSrc->GetBuffer())) { |
1473 m_pBitmap.reset(); | 1423 m_pBitmap.reset(); |
1474 return; | 1424 return; |
1475 } | 1425 } |
1476 m_pBitmap->CopyPalette(pSrc->GetPalette()); | 1426 m_pBitmap->CopyPalette(pSrc->GetPalette()); |
1477 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); | 1427 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); |
1478 } else { | 1428 } else { |
1479 m_pBitmap.reset(pSrc->Clone()); | 1429 m_pBitmap = pSrc->Clone(); |
1480 } | 1430 } |
1481 } | 1431 } |
1482 | 1432 |
1483 CFX_DIBExtractor::~CFX_DIBExtractor() {} | 1433 CFX_DIBExtractor::~CFX_DIBExtractor() {} |
1484 | 1434 |
1485 CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {} | 1435 CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {} |
1486 | 1436 |
1487 CFX_FilteredDIB::~CFX_FilteredDIB() { | 1437 CFX_FilteredDIB::~CFX_FilteredDIB() { |
1488 if (m_bAutoDropSrc) { | 1438 if (m_bAutoDropSrc) { |
1489 delete m_pSrc; | 1439 delete m_pSrc; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1688 uint32_t* pSrcPalette) { | 1638 uint32_t* pSrcPalette) { |
1689 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); | 1639 m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); |
1690 if (!m_pBitmap->Create(width, height, src_format)) { | 1640 if (!m_pBitmap->Create(width, height, src_format)) { |
1691 m_pBitmap.reset(); | 1641 m_pBitmap.reset(); |
1692 return false; | 1642 return false; |
1693 } | 1643 } |
1694 if (pSrcPalette) | 1644 if (pSrcPalette) |
1695 m_pBitmap->CopyPalette(pSrcPalette); | 1645 m_pBitmap->CopyPalette(pSrcPalette); |
1696 return true; | 1646 return true; |
1697 } | 1647 } |
OLD | NEW |