| 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/fxge/fx_dib.h" | 11 #include "core/fxge/fx_dib.h" |
| 12 #include "third_party/base/ptr_util.h" |
| 12 | 13 |
| 13 class CFX_Palette { | 14 class CFX_Palette { |
| 14 public: | 15 public: |
| 15 CFX_Palette(); | 16 CFX_Palette(); |
| 16 ~CFX_Palette(); | 17 ~CFX_Palette(); |
| 17 | 18 |
| 18 bool BuildPalette(const CFX_DIBSource* pBitmap); | 19 bool BuildPalette(const CFX_DIBSource* pBitmap); |
| 19 uint32_t* GetPalette() const { return m_pPalette; } | 20 uint32_t* GetPalette() const { return m_pPalette; } |
| 20 uint32_t* GetColorLut() const { return m_cLut; } | 21 uint32_t* GetColorLut() const { return m_cLut; } |
| 21 uint32_t* GetAmountLut() const { return m_aLut; } | 22 uint32_t* GetAmountLut() const { return m_aLut; } |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 return ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height, | 775 return ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height, |
| 775 pSrcBitmap, src_left, src_top); | 776 pSrcBitmap, src_left, src_top); |
| 776 } | 777 } |
| 777 return false; | 778 return false; |
| 778 } | 779 } |
| 779 default: | 780 default: |
| 780 return false; | 781 return false; |
| 781 } | 782 } |
| 782 } | 783 } |
| 783 | 784 |
| 784 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format) const { | 785 std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert( |
| 786 FXDIB_Format dest_format) const { |
| 785 if (dest_format == GetFormat()) | 787 if (dest_format == GetFormat()) |
| 786 return Clone(nullptr); | 788 return Clone(nullptr); |
| 787 | 789 |
| 788 std::unique_ptr<CFX_DIBitmap> pClone(new CFX_DIBitmap); | 790 std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>(); |
| 789 if (!pClone->Create(m_Width, m_Height, dest_format)) | 791 if (!pClone->Create(m_Width, m_Height, dest_format)) |
| 790 return nullptr; | 792 return nullptr; |
| 791 | 793 |
| 792 CFX_DIBitmap* pSrcAlpha = nullptr; | 794 CFX_DIBitmap* pSrcAlpha = nullptr; |
| 793 if (HasAlpha()) { | 795 if (HasAlpha()) { |
| 794 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; | 796 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; |
| 795 if (!pSrcAlpha) | 797 if (!pSrcAlpha) |
| 796 return nullptr; | 798 return nullptr; |
| 797 } | 799 } |
| 798 | 800 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 812 if (!ret) | 814 if (!ret) |
| 813 return nullptr; | 815 return nullptr; |
| 814 | 816 |
| 815 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp; | 817 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp; |
| 816 if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), | 818 if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), |
| 817 m_Width, m_Height, this, 0, 0, &pal_8bpp)) { | 819 m_Width, m_Height, this, 0, 0, &pal_8bpp)) { |
| 818 return nullptr; | 820 return nullptr; |
| 819 } | 821 } |
| 820 if (pal_8bpp) | 822 if (pal_8bpp) |
| 821 pClone->CopyPalette(pal_8bpp.get()); | 823 pClone->CopyPalette(pal_8bpp.get()); |
| 822 return pClone.release(); | 824 |
| 825 return pClone; |
| 823 } | 826 } |
| 824 | 827 |
| 825 bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { | 828 bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { |
| 826 FXDIB_Format src_format = GetFormat(); | 829 FXDIB_Format src_format = GetFormat(); |
| 827 if (dest_format == src_format) | 830 if (dest_format == src_format) |
| 828 return true; | 831 return true; |
| 829 | 832 |
| 830 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && | 833 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && |
| 831 !m_pPalette) { | 834 !m_pPalette) { |
| 832 m_AlphaFlag = 1; | 835 m_AlphaFlag = 1; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 m_pPalette = std::move(pal_8bpp); | 901 m_pPalette = std::move(pal_8bpp); |
| 899 if (!m_bExtBuf) | 902 if (!m_bExtBuf) |
| 900 FX_Free(m_pBuffer); | 903 FX_Free(m_pBuffer); |
| 901 m_bExtBuf = false; | 904 m_bExtBuf = false; |
| 902 m_pBuffer = dest_buf; | 905 m_pBuffer = dest_buf; |
| 903 m_bpp = (uint8_t)dest_format; | 906 m_bpp = (uint8_t)dest_format; |
| 904 m_AlphaFlag = (uint8_t)(dest_format >> 8); | 907 m_AlphaFlag = (uint8_t)(dest_format >> 8); |
| 905 m_Pitch = dest_pitch; | 908 m_Pitch = dest_pitch; |
| 906 return true; | 909 return true; |
| 907 } | 910 } |
| OLD | NEW |