| 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_INCLUDE_FXGE_FX_DIB_H_ | 7 #ifndef CORE_INCLUDE_FXGE_FX_DIB_H_ |
| 8 #define CORE_INCLUDE_FXGE_FX_DIB_H_ | 8 #define CORE_INCLUDE_FXGE_FX_DIB_H_ |
| 9 | 9 |
| 10 #include "core/include/fxcrt/fx_basic.h" | 10 #include "core/include/fxcrt/fx_basic.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 | \ | 153 ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 | \ |
| 154 ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24)) | 154 ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24)) |
| 155 #define FXGETFLAG_COLORTYPE(flag) (uint8_t)((flag) >> 8) | 155 #define FXGETFLAG_COLORTYPE(flag) (uint8_t)((flag) >> 8) |
| 156 #define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag) | 156 #define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag) |
| 157 #define FXGETFLAG_ALPHA_STROKE(flag) (uint8_t)((flag) >> 16) | 157 #define FXGETFLAG_ALPHA_STROKE(flag) (uint8_t)((flag) >> 16) |
| 158 #define FXSETFLAG_COLORTYPE(flag, val) \ | 158 #define FXSETFLAG_COLORTYPE(flag, val) \ |
| 159 flag = (((val) << 8) | (flag & 0xffff00ff)) | 159 flag = (((val) << 8) | (flag & 0xffff00ff)) |
| 160 #define FXSETFLAG_ALPHA_FILL(flag, val) flag = ((val) | (flag & 0xffffff00)) | 160 #define FXSETFLAG_ALPHA_FILL(flag, val) flag = ((val) | (flag & 0xffffff00)) |
| 161 #define FXSETFLAG_ALPHA_STROKE(flag, val) \ | 161 #define FXSETFLAG_ALPHA_STROKE(flag, val) \ |
| 162 flag = (((val) << 16) | (flag & 0xff00ffff)) | 162 flag = (((val) << 16) | (flag & 0xff00ffff)) |
| 163 |
| 163 class CFX_DIBSource { | 164 class CFX_DIBSource { |
| 164 public: | 165 public: |
| 165 virtual ~CFX_DIBSource(); | 166 virtual ~CFX_DIBSource(); |
| 166 | 167 |
| 167 int GetWidth() const { return m_Width; } | 168 int GetWidth() const { return m_Width; } |
| 168 | |
| 169 int GetHeight() const { return m_Height; } | 169 int GetHeight() const { return m_Height; } |
| 170 | 170 |
| 171 FXDIB_Format GetFormat() const { | 171 FXDIB_Format GetFormat() const { |
| 172 return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp); | 172 return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp); |
| 173 } | 173 } |
| 174 | |
| 175 FX_DWORD GetPitch() const { return m_Pitch; } | 174 FX_DWORD GetPitch() const { return m_Pitch; } |
| 176 | |
| 177 FX_DWORD* GetPalette() const { return m_pPalette; } | 175 FX_DWORD* GetPalette() const { return m_pPalette; } |
| 178 | 176 |
| 179 virtual uint8_t* GetBuffer() const { return NULL; } | 177 virtual uint8_t* GetBuffer() const; |
| 180 | |
| 181 virtual const uint8_t* GetScanline(int line) const = 0; | 178 virtual const uint8_t* GetScanline(int line) const = 0; |
| 182 | 179 virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const; |
| 183 virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const { | |
| 184 return FALSE; | |
| 185 } | |
| 186 | |
| 187 virtual void DownSampleScanline(int line, | 180 virtual void DownSampleScanline(int line, |
| 188 uint8_t* dest_scan, | 181 uint8_t* dest_scan, |
| 189 int dest_bpp, | 182 int dest_bpp, |
| 190 int dest_width, | 183 int dest_width, |
| 191 FX_BOOL bFlipX, | 184 FX_BOOL bFlipX, |
| 192 int clip_left, | 185 int clip_left, |
| 193 int clip_width) const = 0; | 186 int clip_width) const = 0; |
| 194 | |
| 195 virtual void SetDownSampleSize(int width, int height) {} | 187 virtual void SetDownSampleSize(int width, int height) {} |
| 196 | 188 |
| 197 int GetBPP() const { return m_bpp; } | 189 int GetBPP() const { return m_bpp; } |
| 198 | 190 |
| 199 // TODO(thestig): Investigate this. Given the possible values of FXDIB_Format, | 191 // TODO(thestig): Investigate this. Given the possible values of FXDIB_Format, |
| 200 // it feels as though this should be implemented as !!(m_AlphaFlag & 1) and | 192 // it feels as though this should be implemented as !!(m_AlphaFlag & 1) and |
| 201 // IsOpaqueImage() below should never be able to return TRUE. | 193 // IsOpaqueImage() below should never be able to return TRUE. |
| 202 bool IsAlphaMask() const { return m_AlphaFlag == 1; } | 194 bool IsAlphaMask() const { return m_AlphaFlag == 1; } |
| 203 bool HasAlpha() const { return !!(m_AlphaFlag & 2); } | 195 bool HasAlpha() const { return !!(m_AlphaFlag & 2); } |
| 204 bool IsOpaqueImage() const { return !(m_AlphaFlag & 3); } | 196 bool IsOpaqueImage() const { return !(m_AlphaFlag & 3); } |
| 205 bool IsCmykImage() const { return !!(m_AlphaFlag & 4); } | 197 bool IsCmykImage() const { return !!(m_AlphaFlag & 4); } |
| 206 | 198 |
| 207 int GetPaletteSize() const { | 199 int GetPaletteSize() const { |
| 208 return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); | 200 return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); |
| 209 } | 201 } |
| 210 | 202 |
| 211 FX_DWORD GetPaletteEntry(int index) const; | 203 FX_DWORD GetPaletteEntry(int index) const; |
| 212 | 204 |
| 213 void SetPaletteEntry(int index, FX_DWORD color); | 205 void SetPaletteEntry(int index, FX_DWORD color); |
| 214 FX_DWORD GetPaletteArgb(int index) const { return GetPaletteEntry(index); } | 206 FX_DWORD GetPaletteArgb(int index) const { return GetPaletteEntry(index); } |
| 215 void SetPaletteArgb(int index, FX_DWORD color) { | 207 void SetPaletteArgb(int index, FX_DWORD color) { |
| 216 SetPaletteEntry(index, color); | 208 SetPaletteEntry(index, color); |
| 217 } | 209 } |
| 218 | 210 |
| 219 void CopyPalette(const FX_DWORD* pSrcPal, FX_DWORD size = 256); | 211 void CopyPalette(const FX_DWORD* pSrcPal, FX_DWORD size = 256); |
| 220 | 212 |
| 221 CFX_DIBitmap* Clone(const FX_RECT* pClip = NULL) const; | 213 CFX_DIBitmap* Clone(const FX_RECT* pClip = NULL) const; |
| 222 | |
| 223 CFX_DIBitmap* CloneConvert(FXDIB_Format format, | 214 CFX_DIBitmap* CloneConvert(FXDIB_Format format, |
| 224 const FX_RECT* pClip = NULL, | 215 const FX_RECT* pClip = NULL, |
| 225 void* pIccTransform = NULL) const; | 216 void* pIccTransform = NULL) const; |
| 226 | 217 |
| 227 CFX_DIBitmap* StretchTo(int dest_width, | 218 CFX_DIBitmap* StretchTo(int dest_width, |
| 228 int dest_height, | 219 int dest_height, |
| 229 FX_DWORD flags = 0, | 220 FX_DWORD flags = 0, |
| 230 const FX_RECT* pClip = NULL) const; | 221 const FX_RECT* pClip = NULL) const; |
| 231 | |
| 232 CFX_DIBitmap* TransformTo(const CFX_Matrix* pMatrix, | 222 CFX_DIBitmap* TransformTo(const CFX_Matrix* pMatrix, |
| 233 int& left, | 223 int& left, |
| 234 int& top, | 224 int& top, |
| 235 FX_DWORD flags = 0, | 225 FX_DWORD flags = 0, |
| 236 const FX_RECT* pClip = NULL) const; | 226 const FX_RECT* pClip = NULL) const; |
| 237 | 227 |
| 238 CFX_DIBitmap* GetAlphaMask(const FX_RECT* pClip = NULL) const; | 228 CFX_DIBitmap* GetAlphaMask(const FX_RECT* pClip = NULL) const; |
| 239 | |
| 240 FX_BOOL CopyAlphaMask(const CFX_DIBSource* pAlphaMask, | 229 FX_BOOL CopyAlphaMask(const CFX_DIBSource* pAlphaMask, |
| 241 const FX_RECT* pClip = NULL); | 230 const FX_RECT* pClip = NULL); |
| 242 | 231 |
| 243 CFX_DIBitmap* SwapXY(FX_BOOL bXFlip, | 232 CFX_DIBitmap* SwapXY(FX_BOOL bXFlip, |
| 244 FX_BOOL bYFlip, | 233 FX_BOOL bYFlip, |
| 245 const FX_RECT* pClip = NULL) const; | 234 const FX_RECT* pClip = NULL) const; |
| 246 | 235 |
| 247 CFX_DIBitmap* FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const; | 236 CFX_DIBitmap* FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const; |
| 248 | 237 |
| 249 void GetOverlapRect(int& dest_left, | 238 void GetOverlapRect(int& dest_left, |
| 250 int& dest_top, | 239 int& dest_top, |
| 251 int& width, | 240 int& width, |
| 252 int& height, | 241 int& height, |
| 253 int src_width, | 242 int src_width, |
| 254 int src_height, | 243 int src_height, |
| 255 int& src_left, | 244 int& src_left, |
| 256 int& src_top, | 245 int& src_top, |
| 257 const CFX_ClipRgn* pClipRgn); | 246 const CFX_ClipRgn* pClipRgn); |
| 258 | 247 |
| 259 CFX_DIBitmap* m_pAlphaMask; | 248 CFX_DIBitmap* m_pAlphaMask; |
| 260 | 249 |
| 261 protected: | 250 protected: |
| 262 CFX_DIBSource(); | 251 CFX_DIBSource(); |
| 263 | 252 |
| 264 int m_Width; | 253 int m_Width; |
| 265 | |
| 266 int m_Height; | 254 int m_Height; |
| 267 | |
| 268 int m_bpp; | 255 int m_bpp; |
| 269 | |
| 270 FX_DWORD m_AlphaFlag; | 256 FX_DWORD m_AlphaFlag; |
| 271 | |
| 272 FX_DWORD m_Pitch; | 257 FX_DWORD m_Pitch; |
| 273 | |
| 274 FX_DWORD* m_pPalette; | 258 FX_DWORD* m_pPalette; |
| 275 | 259 |
| 276 void BuildPalette(); | 260 void BuildPalette(); |
| 277 | |
| 278 FX_BOOL BuildAlphaMask(); | 261 FX_BOOL BuildAlphaMask(); |
| 279 | |
| 280 int FindPalette(FX_DWORD color) const; | 262 int FindPalette(FX_DWORD color) const; |
| 281 | |
| 282 void GetPalette(FX_DWORD* pal, int alpha) const; | 263 void GetPalette(FX_DWORD* pal, int alpha) const; |
| 283 }; | 264 }; |
| 284 class CFX_DIBitmap : public CFX_DIBSource { | 265 class CFX_DIBitmap : public CFX_DIBSource { |
| 285 public: | 266 public: |
| 286 CFX_DIBitmap(); | 267 CFX_DIBitmap(); |
| 287 explicit CFX_DIBitmap(const CFX_DIBitmap& src); | 268 explicit CFX_DIBitmap(const CFX_DIBitmap& src); |
| 288 ~CFX_DIBitmap() override; | 269 ~CFX_DIBitmap() override; |
| 289 | 270 |
| 290 FX_BOOL Create(int width, | 271 FX_BOOL Create(int width, |
| 291 int height, | 272 int height, |
| 292 FXDIB_Format format, | 273 FXDIB_Format format, |
| 293 uint8_t* pBuffer = NULL, | 274 uint8_t* pBuffer = NULL, |
| 294 int pitch = 0); | 275 int pitch = 0); |
| 295 | 276 |
| 296 FX_BOOL Copy(const CFX_DIBSource* pSrc); | 277 FX_BOOL Copy(const CFX_DIBSource* pSrc); |
| 297 | 278 |
| 298 // CFX_DIBSource | 279 // CFX_DIBSource |
| 299 uint8_t* GetBuffer() const override { return m_pBuffer; } | 280 uint8_t* GetBuffer() const override; |
| 300 const uint8_t* GetScanline(int line) const override { | 281 const uint8_t* GetScanline(int line) const override; |
| 301 return m_pBuffer ? m_pBuffer + line * m_Pitch : NULL; | |
| 302 } | |
| 303 void DownSampleScanline(int line, | 282 void DownSampleScanline(int line, |
| 304 uint8_t* dest_scan, | 283 uint8_t* dest_scan, |
| 305 int dest_bpp, | 284 int dest_bpp, |
| 306 int dest_width, | 285 int dest_width, |
| 307 FX_BOOL bFlipX, | 286 FX_BOOL bFlipX, |
| 308 int clip_left, | 287 int clip_left, |
| 309 int clip_width) const override; | 288 int clip_width) const override; |
| 310 | 289 |
| 311 void TakeOver(CFX_DIBitmap* pSrcBitmap); | 290 void TakeOver(CFX_DIBitmap* pSrcBitmap); |
| 312 | 291 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 int m_Status; | 664 int m_Status; |
| 686 FX_RECT m_ClipBox; | 665 FX_RECT m_ClipBox; |
| 687 FX_DWORD m_Flags; | 666 FX_DWORD m_Flags; |
| 688 int m_AlphaFlag; | 667 int m_AlphaFlag; |
| 689 void* m_pIccTransform; | 668 void* m_pIccTransform; |
| 690 FX_BOOL m_bRgbByteOrder; | 669 FX_BOOL m_bRgbByteOrder; |
| 691 int m_BlendType; | 670 int m_BlendType; |
| 692 }; | 671 }; |
| 693 | 672 |
| 694 #endif // CORE_INCLUDE_FXGE_FX_DIB_H_ | 673 #endif // CORE_INCLUDE_FXGE_FX_DIB_H_ |
| OLD | NEW |