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_dibitmap.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_DIBITMAP_H_
8#define CORE_FXGE_DIB_CFX_DIBITMAP_H_
9
10#include "core/fxcrt/fx_memory_wrappers.h"
11#include "core/fxcrt/maybe_owned.h"
12#include "core/fxcrt/retain_ptr.h"
13#include "core/fxge/dib/cfx_dibbase.h"
14#include "core/fxge/dib/fx_dib.h"
15#include "third_party/abseil-cpp/absl/types/optional.h"
16#include "third_party/base/containers/span.h"
17
18class CFX_DIBitmap final : public CFX_DIBBase {
19 public:
20 struct PitchAndSize {
21 uint32_t pitch;
23 };
24
26
27 bool Create(int width, int height, FXDIB_Format format);
28 bool Create(int width,
29 int height,
30 FXDIB_Format format,
31 uint8_t* pBuffer,
32 uint32_t pitch);
33
34 bool Copy(RetainPtr<const CFX_DIBBase> source);
35
36 // CFX_DIBBase
37 pdfium::span<const uint8_t> GetScanline(int line) const override;
39#if BUILDFLAG(IS_WIN) || defined(PDF_USE_SKIA)
40 RetainPtr<const CFX_DIBitmap> RealizeIfNeeded() const override;
41#endif
42
43 pdfium::span<const uint8_t> GetBuffer() const;
44 pdfium::span<uint8_t> GetWritableBuffer() {
45 pdfium::span<const uint8_t> src = GetBuffer();
46 return {const_cast<uint8_t*>(src.data()), src.size()};
47 }
48
49 pdfium::span<uint8_t> GetWritableScanline(int line) {
50 pdfium::span<const uint8_t> src = GetScanline(line);
51 return {const_cast<uint8_t*>(src.data()), src.size()};
52 }
53
54 void TakeOver(RetainPtr<CFX_DIBitmap>&& pSrcBitmap);
55 bool ConvertFormat(FXDIB_Format format);
56 void Clear(uint32_t color);
57
58#if defined(PDF_USE_SKIA)
59 uint32_t GetPixelForTesting(int x, int y) const;
60#endif // defined(PDF_USE_SKIA)
61
62 bool SetRedFromBitmap(RetainPtr<const CFX_DIBBase> source);
63 bool SetAlphaFromBitmap(RetainPtr<const CFX_DIBBase> source);
65
66 // TODO(crbug.com/pdfium/2007): Migrate callers to `CFX_RenderDevice`.
67 bool MultiplyAlpha(float alpha);
68 bool MultiplyAlphaMask(RetainPtr<const CFX_DIBBase> source);
69
70 bool TransferBitmap(int dest_left,
71 int dest_top,
72 int width,
73 int height,
74 RetainPtr<const CFX_DIBBase> source,
75 int src_left,
76 int src_top);
77
78 bool CompositeBitmap(int dest_left,
79 int dest_top,
80 int width,
81 int height,
82 RetainPtr<const CFX_DIBBase> source,
83 int src_left,
84 int src_top,
85 BlendMode blend_type,
86 const CFX_ClipRgn* pClipRgn,
87 bool bRgbByteOrder);
88
89 bool CompositeMask(int dest_left,
90 int dest_top,
91 int width,
92 int height,
93 const RetainPtr<const CFX_DIBBase>& pMask,
94 uint32_t color,
95 int src_left,
96 int src_top,
97 BlendMode blend_type,
98 const CFX_ClipRgn* pClipRgn,
99 bool bRgbByteOrder);
100
101 void CompositeOneBPPMask(int dest_left,
102 int dest_top,
103 int width,
104 int height,
105 RetainPtr<const CFX_DIBBase> source,
106 int src_left,
107 int src_top);
108
109 bool CompositeRect(int dest_left,
110 int dest_top,
111 int width,
112 int height,
113 uint32_t color);
114
115 bool ConvertColorScale(uint32_t forecolor, uint32_t backcolor);
116
117 // |width| and |height| must be greater than 0.
118 // |format| must have a valid bits per pixel count.
119 // If |pitch| is zero, then the actual pitch will be calculated based on
120 // |width| and |format|.
121 // If |pitch| is non-zero, then that be used as the actual pitch.
122 // The actual pitch will be used to calculate the size.
123 // Returns the calculated pitch and size on success, or nullopt on failure.
125 int height,
126 FXDIB_Format format,
127 uint32_t pitch);
128
129#if defined(PDF_USE_SKIA)
130 // Converts to un-pre-multiplied alpha if necessary.
131 void UnPreMultiply();
132
133 // Forces pre-multiplied alpha without conversion.
134 // TODO(crbug.com/pdfium/2011): Remove the need for this.
135 void ForcePreMultiply();
136#endif
137
138 protected:
139#if defined(PDF_USE_SKIA)
140 bool IsPremultiplied() const override;
141#endif // defined(PDF_USE_SKIA)
142
143 private:
144 enum class Channel : uint8_t { kRed, kAlpha };
145
146#if defined(PDF_USE_SKIA)
147 enum class Format { kCleared, kPreMultiplied, kUnPreMultiplied };
148#endif
149
150 CFX_DIBitmap();
151 CFX_DIBitmap(const CFX_DIBitmap& src);
152 ~CFX_DIBitmap() override;
153
154 bool SetChannelFromBitmap(Channel dest_channel,
155 RetainPtr<const CFX_DIBBase> source);
156 void ConvertBGRColorScale(uint32_t forecolor, uint32_t backcolor);
157 bool TransferWithUnequalFormats(FXDIB_Format dest_format,
158 int dest_left,
159 int dest_top,
160 int width,
161 int height,
162 RetainPtr<const CFX_DIBBase> source,
163 int src_left,
164 int src_top);
165 void TransferWithMultipleBPP(int dest_left,
166 int dest_top,
167 int width,
168 int height,
169 RetainPtr<const CFX_DIBBase> source,
170 int src_left,
171 int src_top);
172 void TransferEqualFormatsOneBPP(int dest_left,
173 int dest_top,
174 int width,
175 int height,
176 RetainPtr<const CFX_DIBBase> source,
177 int src_left,
178 int src_top);
179
180 MaybeOwned<uint8_t, FxFreeDeleter> m_pBuffer;
181#if defined(PDF_USE_SKIA)
182 Format m_nFormat = Format::kCleared;
183#endif
184};
185
186#endif // CORE_FXGE_DIB_CFX_DIBITMAP_H_
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
BlendMode
Definition fx_dib.h:49
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