Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfx_dibbase.h
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef CORE_FXGE_DIB_CFX_DIBBASE_H_
8#define CORE_FXGE_DIB_CFX_DIBBASE_H_
9
10#include <stdint.h>
11
12#include "build/build_config.h"
13#include "core/fxcrt/data_vector.h"
14#include "core/fxcrt/retain_ptr.h"
15#include "core/fxge/dib/fx_dib.h"
16#include "third_party/base/containers/span.h"
17
18#if defined(PDF_USE_SKIA)
19#include "third_party/skia/include/core/SkRefCnt.h" // nogncheck
20#endif
21
22class CFX_ClipRgn;
23class CFX_DIBitmap;
24class CFX_Matrix;
26struct FX_RECT;
27
28#if defined(PDF_USE_SKIA)
29class SkImage;
30#endif // defined(PDF_USE_SKIA)
31
32// Base class for all Device-Independent Bitmaps.
33class CFX_DIBBase : public Retainable {
34 public:
35#if BUILDFLAG(IS_APPLE)
36 // Matches Apple's kCGBitmapByteOrder32Little in fx_quartz_device.cpp.
38#else // BUILDFLAG(IS_APPLE)
40#endif // BUILDFLAG(IS_APPLE)
41
42 static constexpr uint32_t kPaletteSize = 256;
43
44 virtual pdfium::span<const uint8_t> GetScanline(int line) const = 0;
45 virtual bool SkipToScanline(int line, PauseIndicatorIface* pPause) const;
47#if BUILDFLAG(IS_WIN) || defined(PDF_USE_SKIA)
48 // Calls Realize() if needed. Otherwise, return `this`.
49 virtual RetainPtr<const CFX_DIBitmap> RealizeIfNeeded() const;
50#endif
51
52 int GetWidth() const { return m_Width; }
53 int GetHeight() const { return m_Height; }
54 uint32_t GetPitch() const { return m_Pitch; }
55
56 FXDIB_Format GetFormat() const { return m_Format; }
57 int GetBPP() const { return GetBppFromFormat(m_Format); }
59 bool IsAlphaFormat() const { return m_Format == FXDIB_Format::kArgb; }
60 bool IsOpaqueImage() const { return !IsMaskFormat() && !IsAlphaFormat(); }
61
62 bool HasPalette() const { return !m_palette.empty(); }
63 pdfium::span<const uint32_t> GetPaletteSpan() const { return m_palette; }
65 uint32_t GetPaletteArgb(int index) const;
66 void SetPaletteArgb(int index, uint32_t color);
67
68 // Copies into internally-owned palette.
69 void SetPalette(pdfium::span<const uint32_t> src_palette);
70
71 // Moves palette into internally-owned palette.
72 void TakePalette(DataVector<uint32_t> src_palette);
73
74 RetainPtr<CFX_DIBitmap> Realize() const;
75 RetainPtr<CFX_DIBitmap> ClipTo(const FX_RECT& rect) const;
76 RetainPtr<CFX_DIBitmap> ConvertTo(FXDIB_Format format) const;
77 RetainPtr<CFX_DIBitmap> StretchTo(int dest_width,
78 int dest_height,
79 const FXDIB_ResampleOptions& options,
80 const FX_RECT* pClip) const;
81 RetainPtr<CFX_DIBitmap> TransformTo(const CFX_Matrix& mtDest,
82 int* left,
83 int* top) const;
84 RetainPtr<CFX_DIBitmap> SwapXY(bool bXFlip, bool bYFlip) const;
85 RetainPtr<CFX_DIBitmap> FlipImage(bool bXFlip, bool bYFlip) const;
86
87 RetainPtr<CFX_DIBitmap> CloneAlphaMask() const;
88
89 bool GetOverlapRect(int& dest_left,
90 int& dest_top,
91 int& width,
92 int& height,
93 int src_width,
94 int src_height,
95 int& src_left,
96 int& src_top,
97 const CFX_ClipRgn* pClipRgn) const;
98
99#if defined(PDF_USE_SKIA)
100 // Realizes an `SkImage` from this DIB.
101 //
102 // This may share the underlying pixels, in which case, this DIB should not be
103 // modified during the lifetime of the `SkImage`.
104 virtual sk_sp<SkImage> RealizeSkImage() const;
105#endif // defined(PDF_USE_SKIA)
106
107 protected:
109 ~CFX_DIBBase() override;
110
111 // Returns the color palette, or an empty vector if there is no palette.
113 FXDIB_Format dest_format,
114 pdfium::span<uint8_t> dest_buf,
115 int dest_pitch,
116 int width,
117 int height,
118 const RetainPtr<const CFX_DIBBase>& pSrcBitmap,
119 int src_left,
120 int src_top);
121
122#if defined(PDF_USE_SKIA)
123 // Whether alpha is premultiplied (if `IsAlphaFormat()`).
124 virtual bool IsPremultiplied() const;
125#endif // defined(PDF_USE_SKIA)
126
127 RetainPtr<CFX_DIBitmap> ClipToInternal(const FX_RECT* pClip) const;
128 void BuildPalette();
129 int FindPalette(uint32_t color) const;
130
132 int m_Width = 0;
133 int m_Height = 0;
134 uint32_t m_Pitch = 0;
136};
137
138#endif // CORE_FXGE_DIB_CFX_DIBBASE_H_
int FindPalette(uint32_t color) const
static constexpr FXDIB_Format kPlatformRGBFormat
Definition cfx_dibbase.h:39
virtual size_t GetEstimatedImageMemoryBurden() const
RetainPtr< CFX_DIBitmap > ClipTo(const FX_RECT &rect) const
RetainPtr< CFX_DIBitmap > Realize() const
RetainPtr< CFX_DIBitmap > SwapXY(bool bXFlip, bool bYFlip) const
void TakePalette(DataVector< uint32_t > src_palette)
virtual pdfium::span< const uint8_t > GetScanline(int line) const =0
bool HasPalette() const
Definition cfx_dibbase.h:62
virtual bool SkipToScanline(int line, PauseIndicatorIface *pPause) const
RetainPtr< CFX_DIBitmap > CloneAlphaMask() const
void SetPalette(pdfium::span< const uint32_t > src_palette)
uint32_t m_Pitch
FXDIB_Format GetFormat() const
Definition cfx_dibbase.h:56
int GetBPP() const
Definition cfx_dibbase.h:57
bool GetOverlapRect(int &dest_left, int &dest_top, int &width, int &height, int src_width, int src_height, int &src_left, int &src_top, const CFX_ClipRgn *pClipRgn) const
FXDIB_Format m_Format
void BuildPalette()
bool IsAlphaFormat() const
Definition cfx_dibbase.h:59
~CFX_DIBBase() override
RetainPtr< CFX_DIBitmap > TransformTo(const CFX_Matrix &mtDest, int *left, int *top) const
bool IsOpaqueImage() const
Definition cfx_dibbase.h:60
DataVector< uint32_t > m_palette
void SetPaletteArgb(int index, uint32_t color)
uint32_t GetPitch() const
Definition cfx_dibbase.h:54
int GetHeight() const
Definition cfx_dibbase.h:53
RetainPtr< CFX_DIBitmap > ClipToInternal(const FX_RECT *pClip) const
RetainPtr< CFX_DIBitmap > ConvertTo(FXDIB_Format format) const
int GetWidth() const
Definition cfx_dibbase.h:52
RetainPtr< CFX_DIBitmap > StretchTo(int dest_width, int dest_height, const FXDIB_ResampleOptions &options, const FX_RECT *pClip) const
static constexpr uint32_t kPaletteSize
Definition cfx_dibbase.h:42
size_t GetRequiredPaletteSize() const
bool IsMaskFormat() const
Definition cfx_dibbase.h:58
pdfium::span< const uint32_t > GetPaletteSpan() const
Definition cfx_dibbase.h:63
static DataVector< uint32_t > ConvertBuffer(FXDIB_Format dest_format, pdfium::span< uint8_t > dest_buf, int dest_pitch, int width, int height, const RetainPtr< const CFX_DIBBase > &pSrcBitmap, int src_left, int src_top)
RetainPtr< CFX_DIBitmap > FlipImage(bool bXFlip, bool bYFlip) const
uint32_t GetPaletteArgb(int index) const
bool TransferBitmap(int dest_left, int dest_top, int width, int height, RetainPtr< const CFX_DIBBase > source, int src_left, int src_top)
bool SetAlphaFromBitmap(RetainPtr< const CFX_DIBBase > source)
bool SetUniformOpaqueAlpha()
bool Create(int width, int height, FXDIB_Format format)
pdfium::span< const uint8_t > GetBuffer() const
static absl::optional< PitchAndSize > CalculatePitchAndSize(int width, int height, FXDIB_Format format, uint32_t pitch)
bool CompositeMask(int dest_left, int dest_top, int width, int height, const RetainPtr< const CFX_DIBBase > &pMask, uint32_t color, int src_left, int src_top, BlendMode blend_type, const CFX_ClipRgn *pClipRgn, bool bRgbByteOrder)
bool SetRedFromBitmap(RetainPtr< const CFX_DIBBase > source)
bool MultiplyAlphaMask(RetainPtr< const CFX_DIBBase > source)
pdfium::span< uint8_t > GetWritableScanline(int line)
bool CompositeBitmap(int dest_left, int dest_top, int width, int height, RetainPtr< const CFX_DIBBase > source, int src_left, int src_top, BlendMode blend_type, const CFX_ClipRgn *pClipRgn, bool bRgbByteOrder)
bool ConvertColorScale(uint32_t forecolor, uint32_t backcolor)
bool ConvertFormat(FXDIB_Format format)
bool CompositeRect(int dest_left, int dest_top, int width, int height, uint32_t color)
pdfium::span< const uint8_t > GetScanline(int line) const override
size_t GetEstimatedImageMemoryBurden() const override
bool MultiplyAlpha(float alpha)
pdfium::span< uint8_t > GetWritableBuffer()
bool Create(int width, int height, FXDIB_Format format, uint8_t *pBuffer, uint32_t pitch)
void TakeOver(RetainPtr< CFX_DIBitmap > &&pSrcBitmap)
void Clear(uint32_t color)
bool Copy(RetainPtr< const CFX_DIBBase > source)
void CompositeOneBPPMask(int dest_left, int dest_top, int width, int height, RetainPtr< const CFX_DIBBase > source, int src_left, int src_top)
~CFX_DIBitmap() override
FX_RECT ToRoundedFxRect() const
CFX_FloatRect(const FX_RECT &rect)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
void Scale(float fScale)
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
float GetXUnit() const
virtual CFX_FloatRect CalcBoundingBox() const =0
const CFX_Matrix & matrix() const
static float TextUnitToGlyphUnit(float fTextUnit)
void Transform(CPDF_Font::FormIface *pForm, const CFX_Matrix &matrix)
void InitializeFromStreamData(bool bColored, pdfium::span< const float > pData)
RetainPtr< CFX_DIBitmap > GetBitmap()
static void TextUnitRectToGlyphUnitRect(CFX_FloatRect *pRect)
const FX_RECT & bbox() const
const CPDF_Font::FormIface * form() const
bool LoadBitmapFromSoleImageOfForm()
bool colored() const
void SetForm(std::unique_ptr< CPDF_Font::FormIface > pForm)
int width() const
bool IsOwned() const
Definition maybe_owned.h:42
MaybeOwned(OwnedType ptr)
Definition maybe_owned.h:29
MaybeOwned & operator=(const MaybeOwned &that)=delete
void Reset(T *ptr=nullptr)
Definition maybe_owned.h:39
OwnedType Release()
Definition maybe_owned.h:60
MaybeOwned & operator=(const UnownedType &ptr)
Definition maybe_owned.h:77
operator bool() const
Definition maybe_owned.h:94
bool operator==(const OwnedType &ptr) const
Definition maybe_owned.h:87
MaybeOwned & operator=(MaybeOwned &&that) noexcept=default
T * Get() const &
Definition maybe_owned.h:50
MaybeOwned(const MaybeOwned &that)=delete
bool operator==(const MaybeOwned &that) const
Definition maybe_owned.h:86
bool operator!=(const MaybeOwned &that) const
Definition maybe_owned.h:90
bool operator!=(T *ptr) const
Definition maybe_owned.h:92
MaybeOwned & operator=(T *ptr)
Definition maybe_owned.h:73
bool operator!=(const OwnedType ptr) const
Definition maybe_owned.h:91
OwnedType ReleaseAndClear()
Definition maybe_owned.h:67
MaybeOwned()=default
MaybeOwned & operator=(OwnedType ptr)
Definition maybe_owned.h:81
T & operator*() const
Definition maybe_owned.h:95
MaybeOwned(MaybeOwned &&that) noexcept=default
MaybeOwned(const UnownedType &ptr)
Definition maybe_owned.h:28
void Reset(OwnedType ptr)
Definition maybe_owned.h:40
T * operator->() const
Definition maybe_owned.h:96
bool operator==(T *ptr) const
Definition maybe_owned.h:88
~MaybeOwned()=default
bool GetIsMaskFromFormat(FXDIB_Format format)
Definition fx_dib.h:99
BlendMode
Definition fx_dib.h:49
int GetBppFromFormat(FXDIB_Format format)
Definition fx_dib.h:90
FXDIB_Format
Definition fx_dib.h:19
#define CONSTRUCT_VIA_MAKE_RETAIN
Definition retain_ptr.h:224
FX_RECT & operator=(const FX_RECT &that)=default
int32_t bottom
int32_t right
int32_t top
int32_t left