| 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 #ifndef CORE_FXGE_INCLUDE_FX_DIB_H_ | 7 #ifndef CORE_FXGE_INCLUDE_FX_DIB_H_ |
| 8 #define CORE_FXGE_INCLUDE_FX_DIB_H_ | 8 #define CORE_FXGE_INCLUDE_FX_DIB_H_ |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 #define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag) | 157 #define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag) |
| 158 | 158 |
| 159 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, | 159 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, |
| 160 uint8_t* dest_buf, | 160 uint8_t* dest_buf, |
| 161 int dest_pitch, | 161 int dest_pitch, |
| 162 int width, | 162 int width, |
| 163 int height, | 163 int height, |
| 164 const CFX_DIBSource* pSrcBitmap, | 164 const CFX_DIBSource* pSrcBitmap, |
| 165 int src_left, | 165 int src_left, |
| 166 int src_top, | 166 int src_top, |
| 167 uint32_t*& pal); | 167 std::unique_ptr<uint32_t, FxFreeDeleter>* pal); |
| 168 | 168 |
| 169 class CFX_DIBSource { | 169 class CFX_DIBSource { |
| 170 public: | 170 public: |
| 171 virtual ~CFX_DIBSource(); | 171 virtual ~CFX_DIBSource(); |
| 172 | 172 |
| 173 int GetWidth() const { return m_Width; } | |
| 174 int GetHeight() const { return m_Height; } | |
| 175 | |
| 176 FXDIB_Format GetFormat() const { | |
| 177 return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp); | |
| 178 } | |
| 179 uint32_t GetPitch() const { return m_Pitch; } | |
| 180 uint32_t* GetPalette() const { return m_pPalette; } | |
| 181 | |
| 182 virtual uint8_t* GetBuffer() const; | 173 virtual uint8_t* GetBuffer() const; |
| 183 virtual const uint8_t* GetScanline(int line) const = 0; | 174 virtual const uint8_t* GetScanline(int line) const = 0; |
| 184 virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const; | 175 virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const; |
| 185 virtual void DownSampleScanline(int line, | 176 virtual void DownSampleScanline(int line, |
| 186 uint8_t* dest_scan, | 177 uint8_t* dest_scan, |
| 187 int dest_bpp, | 178 int dest_bpp, |
| 188 int dest_width, | 179 int dest_width, |
| 189 FX_BOOL bFlipX, | 180 FX_BOOL bFlipX, |
| 190 int clip_left, | 181 int clip_left, |
| 191 int clip_width) const = 0; | 182 int clip_width) const = 0; |
| 192 | 183 |
| 184 int GetWidth() const { return m_Width; } |
| 185 int GetHeight() const { return m_Height; } |
| 186 |
| 187 FXDIB_Format GetFormat() const { |
| 188 return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp); |
| 189 } |
| 190 uint32_t GetPitch() const { return m_Pitch; } |
| 191 uint32_t* GetPalette() const { return m_pPalette.get(); } |
| 193 int GetBPP() const { return m_bpp; } | 192 int GetBPP() const { return m_bpp; } |
| 194 | 193 |
| 195 // TODO(thestig): Investigate this. Given the possible values of FXDIB_Format, | 194 // TODO(thestig): Investigate this. Given the possible values of FXDIB_Format, |
| 196 // it feels as though this should be implemented as !!(m_AlphaFlag & 1) and | 195 // it feels as though this should be implemented as !!(m_AlphaFlag & 1) and |
| 197 // IsOpaqueImage() below should never be able to return TRUE. | 196 // IsOpaqueImage() below should never be able to return TRUE. |
| 198 bool IsAlphaMask() const { return m_AlphaFlag == 1; } | 197 bool IsAlphaMask() const { return m_AlphaFlag == 1; } |
| 199 bool HasAlpha() const { return !!(m_AlphaFlag & 2); } | 198 bool HasAlpha() const { return !!(m_AlphaFlag & 2); } |
| 200 bool IsOpaqueImage() const { return !(m_AlphaFlag & 3); } | 199 bool IsOpaqueImage() const { return !(m_AlphaFlag & 3); } |
| 201 bool IsCmykImage() const { return !!(m_AlphaFlag & 4); } | 200 bool IsCmykImage() const { return !!(m_AlphaFlag & 4); } |
| 202 | 201 |
| 203 int GetPaletteSize() const { | 202 int GetPaletteSize() const { |
| 204 return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); | 203 return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); |
| 205 } | 204 } |
| 206 | 205 |
| 207 uint32_t GetPaletteEntry(int index) const; | 206 uint32_t GetPaletteEntry(int index) const; |
| 208 | 207 |
| 209 void SetPaletteEntry(int index, uint32_t color); | 208 void SetPaletteEntry(int index, uint32_t color); |
| 210 uint32_t GetPaletteArgb(int index) const { return GetPaletteEntry(index); } | 209 uint32_t GetPaletteArgb(int index) const { return GetPaletteEntry(index); } |
| 211 void SetPaletteArgb(int index, uint32_t color) { | 210 void SetPaletteArgb(int index, uint32_t color) { |
| 212 SetPaletteEntry(index, color); | 211 SetPaletteEntry(index, color); |
| 213 } | 212 } |
| 214 | 213 |
| 215 void CopyPalette(const uint32_t* pSrcPal, uint32_t size = 256); | 214 void CopyPalette(const uint32_t* pSrcPal); |
| 216 | 215 |
| 217 CFX_DIBitmap* Clone(const FX_RECT* pClip = nullptr) const; | 216 CFX_DIBitmap* Clone(const FX_RECT* pClip = nullptr) const; |
| 218 CFX_DIBitmap* CloneConvert(FXDIB_Format format) const; | 217 CFX_DIBitmap* CloneConvert(FXDIB_Format format) const; |
| 219 | 218 |
| 220 CFX_DIBitmap* StretchTo(int dest_width, | 219 CFX_DIBitmap* StretchTo(int dest_width, |
| 221 int dest_height, | 220 int dest_height, |
| 222 uint32_t flags = 0, | 221 uint32_t flags = 0, |
| 223 const FX_RECT* pClip = nullptr) const; | 222 const FX_RECT* pClip = nullptr) const; |
| 224 CFX_DIBitmap* TransformTo(const CFX_Matrix* pMatrix, | 223 CFX_DIBitmap* TransformTo(const CFX_Matrix* pMatrix, |
| 225 int& left, | 224 int& left, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 249 | 248 |
| 250 #if defined _SKIA_SUPPORT_ | 249 #if defined _SKIA_SUPPORT_ |
| 251 void DebugVerifyBitmapIsPreMultiplied(void* buffer = nullptr) const; | 250 void DebugVerifyBitmapIsPreMultiplied(void* buffer = nullptr) const; |
| 252 #endif | 251 #endif |
| 253 | 252 |
| 254 CFX_DIBitmap* m_pAlphaMask; | 253 CFX_DIBitmap* m_pAlphaMask; |
| 255 | 254 |
| 256 protected: | 255 protected: |
| 257 CFX_DIBSource(); | 256 CFX_DIBSource(); |
| 258 | 257 |
| 258 void BuildPalette(); |
| 259 FX_BOOL BuildAlphaMask(); |
| 260 int FindPalette(uint32_t color) const; |
| 261 void GetPalette(uint32_t* pal, int alpha) const; |
| 262 |
| 259 int m_Width; | 263 int m_Width; |
| 260 int m_Height; | 264 int m_Height; |
| 261 int m_bpp; | 265 int m_bpp; |
| 262 uint32_t m_AlphaFlag; | 266 uint32_t m_AlphaFlag; |
| 263 uint32_t m_Pitch; | 267 uint32_t m_Pitch; |
| 264 uint32_t* m_pPalette; | 268 // TODO(weili): Use std::vector for this. |
| 265 | 269 std::unique_ptr<uint32_t, FxFreeDeleter> m_pPalette; |
| 266 void BuildPalette(); | |
| 267 FX_BOOL BuildAlphaMask(); | |
| 268 int FindPalette(uint32_t color) const; | |
| 269 void GetPalette(uint32_t* pal, int alpha) const; | |
| 270 }; | 270 }; |
| 271 | 271 |
| 272 class CFX_DIBitmap : public CFX_DIBSource { | 272 class CFX_DIBitmap : public CFX_DIBSource { |
| 273 public: | 273 public: |
| 274 CFX_DIBitmap(); | 274 CFX_DIBitmap(); |
| 275 explicit CFX_DIBitmap(const CFX_DIBitmap& src); | 275 explicit CFX_DIBitmap(const CFX_DIBitmap& src); |
| 276 ~CFX_DIBitmap() override; | 276 ~CFX_DIBitmap() override; |
| 277 | 277 |
| 278 FX_BOOL Create(int width, | 278 FX_BOOL Create(int width, |
| 279 int height, | 279 int height, |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 int m_Status; | 669 int m_Status; |
| 670 FX_RECT m_ClipBox; | 670 FX_RECT m_ClipBox; |
| 671 uint32_t m_Flags; | 671 uint32_t m_Flags; |
| 672 int m_AlphaFlag; | 672 int m_AlphaFlag; |
| 673 void* m_pIccTransform; | 673 void* m_pIccTransform; |
| 674 FX_BOOL m_bRgbByteOrder; | 674 FX_BOOL m_bRgbByteOrder; |
| 675 int m_BlendType; | 675 int m_BlendType; |
| 676 }; | 676 }; |
| 677 | 677 |
| 678 #endif // CORE_FXGE_INCLUDE_FX_DIB_H_ | 678 #endif // CORE_FXGE_INCLUDE_FX_DIB_H_ |
| OLD | NEW |