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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "core/fxcodec/fx_codec.h" | 10 #include "core/fxcodec/fx_codec.h" |
| 11 #include "core/fxcrt/cfx_maybe_owned.h" |
11 #include "core/fxge/fx_dib.h" | 12 #include "core/fxge/fx_dib.h" |
12 #include "third_party/base/ptr_util.h" | 13 #include "third_party/base/ptr_util.h" |
13 | 14 |
14 class CFX_Palette { | 15 class CFX_Palette { |
15 public: | 16 public: |
16 CFX_Palette(); | 17 CFX_Palette(); |
17 ~CFX_Palette(); | 18 ~CFX_Palette(); |
18 | 19 |
19 bool BuildPalette(const CFX_DIBSource* pBitmap); | 20 bool BuildPalette(const CFX_DIBSource* pBitmap); |
20 uint32_t* GetPalette() const { return m_pPalette; } | 21 uint32_t* GetPalette() const { return m_pPalette; } |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 | 785 |
785 std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert( | 786 std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert( |
786 FXDIB_Format dest_format) const { | 787 FXDIB_Format dest_format) const { |
787 if (dest_format == GetFormat()) | 788 if (dest_format == GetFormat()) |
788 return Clone(nullptr); | 789 return Clone(nullptr); |
789 | 790 |
790 std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>(); | 791 std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>(); |
791 if (!pClone->Create(m_Width, m_Height, dest_format)) | 792 if (!pClone->Create(m_Width, m_Height, dest_format)) |
792 return nullptr; | 793 return nullptr; |
793 | 794 |
794 CFX_DIBitmap* pSrcAlpha = nullptr; | 795 CFX_MaybeOwned<CFX_DIBitmap> pSrcAlpha; |
795 if (HasAlpha()) { | 796 if (HasAlpha()) { |
796 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; | 797 if (GetFormat() == FXDIB_Argb) |
| 798 pSrcAlpha = CloneAlphaMask(); |
| 799 else |
| 800 pSrcAlpha = m_pAlphaMask; |
| 801 |
797 if (!pSrcAlpha) | 802 if (!pSrcAlpha) |
798 return nullptr; | 803 return nullptr; |
799 } | 804 } |
800 | |
801 bool ret = true; | 805 bool ret = true; |
802 if (dest_format & 0x0200) { | 806 if (dest_format & 0x0200) { |
803 if (dest_format == FXDIB_Argb) { | 807 if (dest_format == FXDIB_Argb) { |
804 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) | 808 ret = pSrcAlpha |
805 : pClone->LoadChannel(FXDIB_Alpha, 0xff); | 809 ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha.Get(), FXDIB_Alpha) |
| 810 : pClone->LoadChannel(FXDIB_Alpha, 0xff); |
806 } else { | 811 } else { |
807 ret = pClone->CopyAlphaMask(pSrcAlpha); | 812 ret = pClone->SetAlphaMask(pSrcAlpha.Get()); |
808 } | 813 } |
809 } | 814 } |
810 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { | |
811 delete pSrcAlpha; | |
812 pSrcAlpha = nullptr; | |
813 } | |
814 if (!ret) | 815 if (!ret) |
815 return nullptr; | 816 return nullptr; |
816 | 817 |
817 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp; | 818 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp; |
818 if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), | 819 if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), |
819 m_Width, m_Height, this, 0, 0, &pal_8bpp)) { | 820 m_Width, m_Height, this, 0, 0, &pal_8bpp)) { |
820 return nullptr; | 821 return nullptr; |
821 } | 822 } |
822 if (pal_8bpp) | 823 if (pal_8bpp) |
823 pClone->CopyPalette(pal_8bpp.get()); | 824 pClone->SetPalette(pal_8bpp.get()); |
824 | 825 |
825 return pClone; | 826 return pClone; |
826 } | 827 } |
827 | 828 |
828 bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { | 829 bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { |
829 FXDIB_Format src_format = GetFormat(); | 830 FXDIB_Format src_format = GetFormat(); |
830 if (dest_format == src_format) | 831 if (dest_format == src_format) |
831 return true; | 832 return true; |
832 | 833 |
833 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && | 834 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && |
(...skipping 26 matching lines...) Expand all Loading... |
860 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; | 861 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; |
861 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); | 862 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); |
862 for (int col = 0; col < m_Width; col++) { | 863 for (int col = 0; col < m_Width; col++) { |
863 *pDstScanline = *pSrcScanline++; | 864 *pDstScanline = *pSrcScanline++; |
864 pDstScanline += 4; | 865 pDstScanline += 4; |
865 } | 866 } |
866 } | 867 } |
867 } | 868 } |
868 } else if (dest_format & 0x0200) { | 869 } else if (dest_format & 0x0200) { |
869 if (src_format == FXDIB_Argb) { | 870 if (src_format == FXDIB_Argb) { |
870 pAlphaMask = GetAlphaMask(); | 871 pAlphaMask = CloneAlphaMask().release(); |
871 if (!pAlphaMask) { | 872 if (!pAlphaMask) { |
872 FX_Free(dest_buf); | 873 FX_Free(dest_buf); |
873 return false; | 874 return false; |
874 } | 875 } |
875 } else { | 876 } else { |
876 if (!m_pAlphaMask) { | 877 if (!m_pAlphaMask) { |
877 if (!BuildAlphaMask()) { | 878 if (!BuildAlphaMask()) { |
878 FX_Free(dest_buf); | 879 FX_Free(dest_buf); |
879 return false; | 880 return false; |
880 } | 881 } |
(...skipping 20 matching lines...) Expand all Loading... |
901 m_pPalette = std::move(pal_8bpp); | 902 m_pPalette = std::move(pal_8bpp); |
902 if (!m_bExtBuf) | 903 if (!m_bExtBuf) |
903 FX_Free(m_pBuffer); | 904 FX_Free(m_pBuffer); |
904 m_bExtBuf = false; | 905 m_bExtBuf = false; |
905 m_pBuffer = dest_buf; | 906 m_pBuffer = dest_buf; |
906 m_bpp = (uint8_t)dest_format; | 907 m_bpp = (uint8_t)dest_format; |
907 m_AlphaFlag = (uint8_t)(dest_format >> 8); | 908 m_AlphaFlag = (uint8_t)(dest_format >> 8); |
908 m_Pitch = dest_pitch; | 909 m_Pitch = dest_pitch; |
909 return true; | 910 return true; |
910 } | 911 } |
OLD | NEW |