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
fx_dib.h
Go to the documentation of this file.
1// Copyright 2014 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_FX_DIB_H_
8#define CORE_FXGE_DIB_FX_DIB_H_
9
10#include <stdint.h>
11
12#include <utility>
13
14#include "core/fxcrt/compiler_specific.h"
15
16// Encoding:
17// - Bits-per-pixel: value & 0xFF
18// - Is mask: value & 0x100
19// - Has alpha: value & 0x200
20// - Is premultiplied-alpha: value & 0x400
21enum class FXDIB_Format : uint16_t {
23 k1bppRgb = 0x001,
24 k8bppRgb = 0x008,
25 kBgr = 0x018,
26 kBgrx = 0x020,
27 k1bppMask = 0x101,
28 k8bppMask = 0x108,
29 kBgra = 0x220,
30#if defined(PDF_USE_SKIA)
31 kBgraPremul = 0x620,
32#endif
33};
34
35// Endian-dependent (in theory).
36using FX_ARGB = uint32_t; // A in high bits, ..., B in low bits.
37using FX_CMYK = uint32_t; // C in high bits, ..., K in low bits.
38
39// FX_COLORREF, like win32 COLORREF, is BGR. i.e. 0x00BBGGRR.
40// Note that while the non-existent alpha component should be set to 0, some
41// parts of the codebase use 0xFFFFFFFF as a sentinel value to indicate error.
42using FX_COLORREF = uint32_t;
43
44// Endian-independent, name-ordered by increasing address.
45template <typename T>
47 T red = 0;
48 T green = 0;
49 T blue = 0;
50};
51
52template <typename T>
54 T blue = 0;
55 T green = 0;
56 T red = 0;
57};
58
59template <typename T>
61 T alpha = 0;
62 T red = 0;
63 T green = 0;
64 T blue = 0;
65};
66
67template <typename T>
69 T alpha = 0;
70 T blue = 0;
71 T green = 0;
72 T red = 0;
73};
74
75template <typename T>
77 T red = 0;
78 T green = 0;
79 T blue = 0;
80 T alpha = 0;
81};
82
83template <typename T>
85 T blue = 0;
86 T green = 0;
87 T red = 0;
88 T alpha = 0;
89};
90
91template <typename T>
93 T cyan = 0;
94 T magenta = 0;
95 T yellow = 0;
96 T key = 0;
97};
98
99template <typename T>
102 T a_star = 0;
103 T b_star = 0;
104};
105
108
109 bool HasAnyOptions() const;
110
112 bool bHalftone = false;
113 bool bNoSmoothing = false;
114 bool bLossy = false;
115};
116
117// See PDF 1.7 spec, table 7.2 and 7.3. The enum values need to be in the same
118// order as listed in the spec.
138
139constexpr uint32_t FXSYS_BGR(uint8_t b, uint8_t g, uint8_t r) {
140 return (b << 16) | (g << 8) | r;
141}
142
143constexpr uint8_t FXSYS_GetRValue(uint32_t bgr) {
144 return bgr & 0xff;
145}
146
147constexpr uint8_t FXSYS_GetGValue(uint32_t bgr) {
148 return (bgr >> 8) & 0xff;
149}
150
151constexpr uint8_t FXSYS_GetBValue(uint32_t bgr) {
152 return (bgr >> 16) & 0xff;
153}
154
155constexpr unsigned int FXSYS_GetUnsignedAlpha(float alpha) {
156 return static_cast<unsigned int>(alpha * 255.f + 0.5f);
157}
158
159// Bits per pixel, not bytes.
160inline int GetBppFromFormat(FXDIB_Format format) {
161 return static_cast<uint16_t>(format) & 0xff;
162}
163
164// AKA bytes per pixel, assuming 8-bits per component.
166 return (static_cast<uint16_t>(format) & 0xff) / 8;
167}
168
170 return !!(static_cast<uint16_t>(format) & 0x100);
171}
172
174 return !!(static_cast<uint16_t>(format) & 0x200);
175}
176
178
179// Ignores alpha.
181
182// Returns (a, FX_COLORREF)
183std::pair<uint8_t, FX_COLORREF> ArgbToAlphaAndColorRef(FX_ARGB argb);
184
187
188constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b) {
189 return (a << 24) | (r << 16) | (g << 8) | b;
190}
191
192constexpr FX_CMYK CmykEncode(uint32_t c, uint32_t m, uint32_t y, uint32_t k) {
193 return (c << 24) | (m << 16) | (y << 8) | k;
194}
195
196#define FXARGB_A(argb) ((uint8_t)((argb) >> 24))
197#define FXARGB_R(argb) ((uint8_t)((argb) >> 16))
198#define FXARGB_G(argb) ((uint8_t)((argb) >> 8))
199#define FXARGB_B(argb) ((uint8_t)(argb))
200#define FXARGB_MUL_ALPHA(argb, alpha)
201 (((((argb) >> 24) * (alpha) / 255) << 24) | ((argb)&0xffffff))
202
203#define FXRGB2GRAY(r, g, b) (((b)*11 + (g)*59 + (r)*30) / 100)
204#define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha)
205 (((backdrop) * (255 - (source_alpha)) + (source) * (source_alpha)) / 255)
206
207#define FXCMYK_TODIB(cmyk)
208 ((uint8_t)((cmyk) >> 24) | ((uint8_t)((cmyk) >> 16)) << 8 |
209 ((uint8_t)((cmyk) >> 8)) << 16 | ((uint8_t)(cmyk) << 24))
210#define FXARGB_TOBGRORDERDIB(argb)
211 ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 |
212 ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24))
213
214// SAFETY: Caller must ensure 4 valid bytes at `p`.
219
220// SAFETY: Caller must ensure 4 valid bytes at `p`.
221UNSAFE_BUFFER_USAGE inline void FXARGB_SetDIB(uint8_t* p, uint32_t argb) {
222 UNSAFE_BUFFERS(p[0]) = FXARGB_B(argb);
223 UNSAFE_BUFFERS(p[1]) = FXARGB_G(argb);
224 UNSAFE_BUFFERS(p[2]) = FXARGB_R(argb);
225 UNSAFE_BUFFERS(p[3]) = FXARGB_A(argb);
226}
227
228// SAFETY: Caller must ensure 4 valid bytes at `p`.
230 uint32_t argb) {
231 UNSAFE_BUFFERS(p[0]) = FXARGB_R(argb);
232 UNSAFE_BUFFERS(p[1]) = FXARGB_G(argb);
233 UNSAFE_BUFFERS(p[2]) = FXARGB_B(argb);
234 UNSAFE_BUFFERS(p[3]) = FXARGB_A(argb);
235}
236
237// SAFETY: Caller must ensure 3 valid bytes at `dest` and `src`.
238UNSAFE_BUFFER_USAGE inline void ReverseCopy3Bytes(uint8_t* dest,
239 const uint8_t* src) {
240 UNSAFE_BUFFERS(dest[2] = src[0]);
241 UNSAFE_BUFFERS(dest[1] = src[1]);
242 UNSAFE_BUFFERS(dest[0] = src[2]);
243}
244
245#if defined(PDF_USE_SKIA)
246template <typename T>
247T PreMultiplyColor(const T& input) {
248 if (input.alpha == 255) {
249 return input;
250 }
251
252 T output;
253 output.alpha = input.alpha;
254 output.blue = static_cast<float>(input.blue) * input.alpha / 255.0f;
255 output.green = static_cast<float>(input.green) * input.alpha / 255.0f;
256 output.red = static_cast<float>(input.red) * input.alpha / 255.0f;
257 return output;
258}
259
260template <typename T>
261T UnPreMultiplyColor(const T& input) {
262 if (input.alpha == 255) {
263 return input;
264 }
265
266 T output;
267 output.alpha = input.alpha;
268 if (input.alpha == 0) {
269 output.blue = 0;
270 output.green = 0;
271 output.red = 0;
272 } else {
273 output.blue = static_cast<float>(input.blue) * 255.0f / input.alpha;
274 output.green = static_cast<float>(input.green) * 255.0f / input.alpha;
275 output.red = static_cast<float>(input.red) * 255.0f / input.alpha;
276 }
277 return output;
278}
279#endif // defined(PDF_USE_SKIA)
280
281#endif // CORE_FXGE_DIB_FX_DIB_H_
fxcrt::ByteString ByteString
Definition bytestring.h:180
#define DCHECK
Definition check.h:33
void Scale(float sx, float sy)
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
Definition cpdf_array.h:29
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
bool ExportNPagesToOne(pdfium::span< const uint32_t > page_indices, const CFX_SizeF &dest_page_size, size_t pages_on_x_axis, size_t pages_on_y_axis)
static ByteString GenerateSubPageContentStreamForTesting(const ByteString &xobject_name, const NupPageSettings &settings)
CPDF_NPageToOneExporter(CPDF_Document *dest_doc, CPDF_Document *src_doc)
std::unique_ptr< XObjectContext > CreateXObjectContextFromPage(int src_page_index)
virtual CPDF_Stream * AsMutableStream()
const CPDF_Stream * AsStream() const
void SetBackgroundAlphaNeeded(bool needed)
void StartParse(std::unique_ptr< CPDF_ContentParser > pParser)
RetainPtr< const CPDF_Dictionary > GetDict() const
std::map< FontData, ByteString > m_FontsMap
RetainPtr< CPDF_Dictionary > m_pPageResources
RetainPtr< const CPDF_Dictionary > GetResources() const
virtual bool IsPage() const
void SetResources(RetainPtr< CPDF_Dictionary > pDict)
const_iterator end() const
std::optional< ByteString > GraphicsMapSearch(const GraphicsData &gd)
virtual ~CPDF_PageObjectHolder()
const_iterator begin() const
const std::vector< CFX_FloatRect > & GetMaskBoundingBoxes() const
void GraphicsMapInsert(const GraphicsData &gd, const ByteString &str)
void AddImageMaskBoundingBox(const CFX_FloatRect &box)
CPDF_Document * GetDocument() const
std::map< GraphicsData, ByteString > m_GraphicsMap
void AppendPageObject(std::unique_ptr< CPDF_PageObject > pPageObj)
void FontsMapInsert(const FontData &fd, const ByteString &str)
bool ErasePageObjectAtIndex(size_t index)
CPDF_PageObjectHolder(CPDF_Document *pDoc, RetainPtr< CPDF_Dictionary > pDict, RetainPtr< CPDF_Dictionary > pPageResources, RetainPtr< CPDF_Dictionary > pResources)
ParseState GetParseState() const
RetainPtr< CPDF_Dictionary > GetMutableDict()
void ContinueParse(PauseIndicatorIface *pPause)
RetainPtr< CPDF_Dictionary > m_pResources
CPDF_PageObject * GetPageObjectByIndex(size_t index) const
std::unique_ptr< CPDF_PageObject > RemovePageObject(CPDF_PageObject *pPageObj)
const CPDF_Transparency & GetTransparency() const
RetainPtr< CPDF_Dictionary > GetMutableResources()
RetainPtr< const CPDF_Dictionary > GetPageResources() const
CFX_Matrix GetCTMAtBeginningOfStream(int32_t stream)
RetainPtr< CPDF_Dictionary > GetMutablePageResources()
CPDF_Transparency m_Transparency
const CFX_FloatRect & GetBBox() const
CFX_Matrix GetCTMAtEndOfStream(int32_t stream)
std::optional< ByteString > FontsMapSearch(const FontData &fd)
std::set< int32_t > TakeDirtyStreams()
static bool CopyInheritable(RetainPtr< CPDF_Dictionary > dest_page_dict, RetainPtr< const CPDF_Dictionary > src_page_dict, const ByteString &key)
CPDF_Document * dest()
const CPDF_Document * dest() const
static RetainPtr< const CPDF_Object > PageDictGetInheritableTag(RetainPtr< const CPDF_Dictionary > dict, const ByteString &src_tag)
CPDF_PageOrganizer(CPDF_Document *dest_doc, CPDF_Document *src_doc)
const CPDF_Document * src() const
CPDF_Document * src()
bool UpdateReference(RetainPtr< CPDF_Object > obj)
void AddObjectMapping(uint32_t old_page_obj_num, uint32_t new_page_obj_num)
RenderContextClearer(CPDF_Page *pPage)
virtual ~RenderContextIface()=default
virtual void ClearPage(CPDF_Page *pPage)=0
RetainPtr< const CPDF_Array > GetAnnotsArray() const
RetainPtr< CPDF_Array > GetOrCreateAnnotsArray()
CPDF_Document * GetDocument() const override
Definition cpdf_page.cpp:51
float GetPageHeight() const override
Definition cpdf_page.cpp:59
void UpdateDimensions()
std::optional< CFX_PointF > DeviceToPage(const FX_RECT &rect, int rotate, const CFX_PointF &device_point) const override
~CPDF_Page() override
bool IsPage() const override
Definition cpdf_page.cpp:63
float GetPageWidth() const override
Definition cpdf_page.cpp:55
CPDFXFA_Page * AsXFAPage() override
Definition cpdf_page.cpp:47
const CFX_Matrix & GetPageMatrix() const
Definition cpdf_page.h:75
RenderContextIface * GetRenderContext()
Definition cpdf_page.h:84
void ParseContent()
Definition cpdf_page.cpp:67
const CFX_SizeF & GetPageSize() const
Definition cpdf_page.h:74
void SetView(View *pView)
Definition cpdf_page.h:92
RetainPtr< CPDF_Array > GetMutableAnnotsArray()
void ClearView()
void SetRenderContext(std::unique_ptr< RenderContextIface > pContext)
CPDF_Page * AsPDFPage() override
Definition cpdf_page.cpp:43
void AddPageImageCache()
std::optional< CFX_PointF > PageToDevice(const FX_RECT &rect, int rotate, const CFX_PointF &page_point) const override
CFX_Matrix GetDisplayMatrix(const FX_RECT &rect, int iRotate) const override
int GetPageRotation() const
CPDF_PageImageCache * GetPageImageCache()
Definition cpdf_page.h:83
void ClearRenderContext()
bool HasFilter() const
static constexpr int kFileBufSize
Definition cpdf_stream.h:25
bool IsMemoryBased() const
Definition cpdf_stream.h:62
void TakeData(DataVector< uint8_t > data)
RetainPtr< CPDF_Object > Clone() const override
~CPDF_Stream() override
size_t GetRawSize() const
CPDF_Stream * AsMutableStream() override
bool WriteTo(IFX_ArchiveStream *archive, const CPDF_Encryptor *encryptor) const override
bool IsFileBased() const
Definition cpdf_stream.h:59
void SetDataFromStringstreamAndRemoveFilter(fxcrt::ostringstream *stream)
Type GetType() const override
void SetDataAndRemoveFilter(pdfium::span< const uint8_t > pData)
void SetDataFromStringstream(fxcrt::ostringstream *stream)
DataVector< uint8_t > ReadAllRawData() const
void SetData(pdfium::span< const uint8_t > pData)
pdfium::span< const uint8_t > GetInMemoryRawData() const
RetainPtr< CPDF_Object > CloneNonCyclic(bool bDirect, std::set< const CPDF_Object * > *pVisited) const override
WideString GetUnicodeText() const override
const CPDF_Dictionary * GetDictInternal() const override
void InitStreamFromFile(RetainPtr< IFX_SeekableReadStream > file)
bool IsIsolated() const
CPDF_Transparency(const CPDF_Transparency &other)
CPDF_Transparency & operator=(const CPDF_Transparency &other)
static ByteString Format(const char *pFormat,...)
ByteString & operator+=(const char *str)
#define UNSAFE_BUFFERS(...)
#define UNSAFE_BUFFER_USAGE
const CPDF_Stream * ToStream(const CPDF_Object *obj)
RetainPtr< CPDF_Stream > ToStream(RetainPtr< CPDF_Object > obj)
CPDF_Stream * ToStream(CPDF_Object *obj)
CFX_PTemplate< float > CFX_PointF
CFX_STemplate< float > CFX_SizeF
UNSAFE_BUFFER_USAGE void FXARGB_SetDIB(uint8_t *p, uint32_t argb)
Definition fx_dib.h:221
bool GetIsMaskFromFormat(FXDIB_Format format)
Definition fx_dib.h:169
uint32_t FX_ARGB
Definition fx_dib.h:36
FX_BGRA_STRUCT< uint8_t > ArgbToBGRAStruct(FX_ARGB argb)
Definition fx_dib.cpp:48
UNSAFE_BUFFER_USAGE FX_ARGB FXARGB_GetDIB(const uint8_t *p)
Definition fx_dib.h:215
UNSAFE_BUFFER_USAGE void ReverseCopy3Bytes(uint8_t *dest, const uint8_t *src)
Definition fx_dib.h:238
BlendMode
Definition fx_dib.h:119
@ kExclusion
Definition fx_dib.h:131
@ kNormal
Definition fx_dib.h:120
@ kSaturation
Definition fx_dib.h:133
@ kColorBurn
Definition fx_dib.h:127
@ kLighten
Definition fx_dib.h:125
@ kMultiply
Definition fx_dib.h:121
@ kColorDodge
Definition fx_dib.h:126
@ kScreen
Definition fx_dib.h:122
@ kLuminosity
Definition fx_dib.h:135
@ kSoftLight
Definition fx_dib.h:129
@ kDifference
Definition fx_dib.h:130
@ kOverlay
Definition fx_dib.h:123
@ kHardLight
Definition fx_dib.h:128
@ kDarken
Definition fx_dib.h:124
#define FXARGB_B(argb)
Definition fx_dib.h:199
constexpr FX_CMYK CmykEncode(uint32_t c, uint32_t m, uint32_t y, uint32_t k)
Definition fx_dib.h:192
#define FXARGB_G(argb)
Definition fx_dib.h:198
constexpr uint32_t FXSYS_BGR(uint8_t b, uint8_t g, uint8_t r)
Definition fx_dib.h:139
std::pair< uint8_t, FX_COLORREF > ArgbToAlphaAndColorRef(FX_ARGB argb)
Definition fx_dib.cpp:56
FX_BGR_STRUCT< uint8_t > ArgbToBGRStruct(FX_ARGB argb)
Definition fx_dib.cpp:52
#define FXARGB_A(argb)
Definition fx_dib.h:196
FX_ARGB AlphaAndColorRefToArgb(int a, FX_COLORREF colorref)
Definition fx_dib.cpp:64
uint32_t FX_COLORREF
Definition fx_dib.h:42
UNSAFE_BUFFER_USAGE void FXARGB_SetRGBOrderDIB(uint8_t *p, uint32_t argb)
Definition fx_dib.h:229
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition fx_dib.h:188
bool GetIsAlphaFromFormat(FXDIB_Format format)
Definition fx_dib.h:173
int GetBppFromFormat(FXDIB_Format format)
Definition fx_dib.h:160
#define FXARGB_R(argb)
Definition fx_dib.h:197
int GetCompsFromFormat(FXDIB_Format format)
Definition fx_dib.h:165
constexpr uint8_t FXSYS_GetRValue(uint32_t bgr)
Definition fx_dib.h:143
FX_COLORREF ArgbToColorRef(FX_ARGB argb)
Definition fx_dib.cpp:60
constexpr unsigned int FXSYS_GetUnsignedAlpha(float alpha)
Definition fx_dib.h:155
FXDIB_Format
Definition fx_dib.h:21
constexpr uint8_t FXSYS_GetGValue(uint32_t bgr)
Definition fx_dib.h:147
constexpr uint8_t FXSYS_GetBValue(uint32_t bgr)
Definition fx_dib.h:151
uint32_t FX_CMYK
Definition fx_dib.h:37
pdfium::CheckedNumeric< int32_t > FX_SAFE_INT32
const char kMediaBox[]
const char kContents[]
#define CONSTRUCT_VIA_MAKE_RETAIN
Definition retain_ptr.h:222
fxcrt::ByteStringView ByteStringView
bool HasAnyOptions() const
Definition fx_dib.cpp:44
bool operator<(const FontData &other) const
ByteString baseFont
bool operator<(const GraphicsData &other) const
UnownedPtr< CPDF_Document > dest_doc
RetainPtr< CPDF_Stream > xobject
fxcrt::WideString WideString
Definition widestring.h:207