1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef CORE_FPDFAPI_RENDER_RENDER_INT_H_
#define CORE_FPDFAPI_RENDER_RENDER_INT_H_
#include <map>
#include <memory>
#include <vector>
#include "core/fpdfapi/page/cpdf_clippath.h"
#include "core/fpdfapi/page/cpdf_countedobject.h"
#include "core/fpdfapi/page/cpdf_graphicstates.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/render/cpdf_imageloader.h"
#include "core/fpdfapi/render/cpdf_rendercontext.h"
#include "core/fpdfapi/render/cpdf_renderoptions.h"
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_renderdevice.h"
class CCodec_Jbig2Context;
class CCodec_ScanlineDecoder;
class CFX_GlyphBitmap;
class CFX_ImageTransformer;
class CFX_PathData;
class CPDF_Color;
class CPDF_Dictionary;
class CPDF_Document;
class CPDF_Font;
class CPDF_FormObject;
class CPDF_ImageCacheEntry;
class CPDF_ImageObject;
class CPDF_ImageRenderer;
class CPDF_Object;
class CPDF_PageObject;
class CPDF_PageObjectHolder;
class CPDF_PageRenderCache;
class CPDF_PathObject;
class CPDF_RenderStatus;
class CPDF_ShadingObject;
class CPDF_ShadingPattern;
class CPDF_Stream;
class CPDF_TilingPattern;
class CPDF_TransferFunc;
class CPDF_Type3Cache;
class CPDF_Type3Glyphs;
class CPDF_Type3Char;
class CPDF_Type3Font;
class CPDF_ImageRenderer {
public:
CPDF_ImageRenderer();
~CPDF_ImageRenderer();
bool Start(CPDF_RenderStatus* pStatus,
CPDF_PageObject* pObj,
const CFX_Matrix* pObj2Device,
bool bStdCS,
int blendType = FXDIB_BLEND_NORMAL);
bool Continue(IFX_Pause* pPause);
bool Start(CPDF_RenderStatus* pStatus,
const CFX_DIBSource* pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
uint32_t flags,
bool bStdCS,
int blendType = FXDIB_BLEND_NORMAL);
bool m_Result;
protected:
bool StartBitmapAlpha();
bool StartDIBSource();
bool StartRenderDIBSource();
bool StartLoadDIBSource();
bool DrawMaskedImage();
bool DrawPatternImage(const CFX_Matrix* pObj2Device);
CPDF_RenderStatus* m_pRenderStatus;
CPDF_ImageObject* m_pImageObject;
int m_Status;
const CFX_Matrix* m_pObj2Device;
CFX_Matrix m_ImageMatrix;
CPDF_ImageLoader m_Loader;
const CFX_DIBSource* m_pDIBSource;
std::unique_ptr<CFX_DIBitmap> m_pClone;
int m_BitmapAlpha;
bool m_bPatternColor;
CPDF_Pattern* m_pPattern;
FX_ARGB m_FillArgb;
uint32_t m_Flags;
std::unique_ptr<CFX_ImageTransformer> m_pTransformer;
void* m_DeviceHandle;
bool m_bStdCS;
int m_BlendType;
};
class CPDF_ScaledRenderBuffer {
public:
CPDF_ScaledRenderBuffer();
~CPDF_ScaledRenderBuffer();
bool Initialize(CPDF_RenderContext* pContext,
CFX_RenderDevice* pDevice,
const FX_RECT& pRect,
const CPDF_PageObject* pObj,
const CPDF_RenderOptions* pOptions = nullptr,
int max_dpi = 0);
CFX_RenderDevice* GetDevice() {
return m_pBitmapDevice ? m_pBitmapDevice.get() : m_pDevice;
}
CFX_Matrix* GetMatrix() { return &m_Matrix; }
void OutputToDevice();
private:
CFX_RenderDevice* m_pDevice;
CPDF_RenderContext* m_pContext;
FX_RECT m_Rect;
const CPDF_PageObject* m_pObject;
std::unique_ptr<CFX_FxgeDevice> m_pBitmapDevice;
CFX_Matrix m_Matrix;
};
class CPDF_DeviceBuffer {
public:
CPDF_DeviceBuffer();
~CPDF_DeviceBuffer();
bool Initialize(CPDF_RenderContext* pContext,
CFX_RenderDevice* pDevice,
FX_RECT* pRect,
const CPDF_PageObject* pObj,
int max_dpi = 0);
void OutputToDevice();
CFX_DIBitmap* GetBitmap() const { return m_pBitmap.get(); }
const CFX_Matrix* GetMatrix() const { return &m_Matrix; }
private:
CFX_RenderDevice* m_pDevice;
CPDF_RenderContext* m_pContext;
FX_RECT m_Rect;
const CPDF_PageObject* m_pObject;
std::unique_ptr<CFX_DIBitmap> m_pBitmap;
CFX_Matrix m_Matrix;
};
class CPDF_ImageCacheEntry {
public:
CPDF_ImageCacheEntry(CPDF_Document* pDoc, CPDF_Stream* pStream);
~CPDF_ImageCacheEntry();
void Reset(const CFX_DIBitmap* pBitmap);
bool GetCachedBitmap(CFX_DIBSource*& pBitmap,
CFX_DIBSource*& pMask,
uint32_t& MatteColor,
CPDF_Dictionary* pPageResources,
bool bStdCS = false,
uint32_t GroupFamily = 0,
bool bLoadMask = false,
CPDF_RenderStatus* pRenderStatus = nullptr,
int32_t downsampleWidth = 0,
int32_t downsampleHeight = 0);
uint32_t EstimateSize() const { return m_dwCacheSize; }
uint32_t GetTimeCount() const { return m_dwTimeCount; }
CPDF_Stream* GetStream() const { return m_pStream; }
void SetTimeCount(uint32_t dwTimeCount) { m_dwTimeCount = dwTimeCount; }
int m_dwTimeCount;
public:
int StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
CPDF_Dictionary* pPageResources,
bool bStdCS = false,
uint32_t GroupFamily = 0,
bool bLoadMask = false,
CPDF_RenderStatus* pRenderStatus = nullptr,
int32_t downsampleWidth = 0,
int32_t downsampleHeight = 0);
int Continue(IFX_Pause* pPause);
CFX_DIBSource* DetachBitmap();
CFX_DIBSource* DetachMask();
CFX_DIBSource* m_pCurBitmap;
CFX_DIBSource* m_pCurMask;
uint32_t m_MatteColor;
CPDF_RenderStatus* m_pRenderStatus;
protected:
void ContinueGetCachedBitmap();
CPDF_Document* m_pDocument;
CPDF_Stream* m_pStream;
CFX_DIBSource* m_pCachedBitmap;
CFX_DIBSource* m_pCachedMask;
uint32_t m_dwCacheSize;
void CalcSize();
};
typedef struct {
FX_FLOAT m_DecodeMin;
FX_FLOAT m_DecodeStep;
int m_ColorKeyMin;
int m_ColorKeyMax;
} DIB_COMP_DATA;
class CPDF_DIBSource : public CFX_DIBSource {
public:
CPDF_DIBSource();
~CPDF_DIBSource() override;
bool Load(CPDF_Document* pDoc,
const CPDF_Stream* pStream,
CPDF_DIBSource** ppMask,
uint32_t* pMatteColor,
CPDF_Dictionary* pFormResources,
CPDF_Dictionary* pPageResources,
bool bStdCS = false,
uint32_t GroupFamily = 0,
bool bLoadMask = false);
// CFX_DIBSource
bool SkipToScanline(int line, IFX_Pause* pPause) const override;
uint8_t* GetBuffer() const override;
const uint8_t* GetScanline(int line) const override;
void DownSampleScanline(int line,
uint8_t* dest_scan,
int dest_bpp,
int dest_width,
bool bFlipX,
int clip_left,
int clip_width) const override;
CFX_DIBitmap* GetBitmap() const;
void ReleaseBitmap(CFX_DIBitmap* pBitmap) const;
uint32_t GetMatteColor() const { return m_MatteColor; }
int StartLoadDIBSource(CPDF_Document* pDoc,
const CPDF_Stream* pStream,
bool bHasMask,
CPDF_Dictionary* pFormResources,
CPDF_Dictionary* pPageResources,
bool bStdCS = false,
uint32_t GroupFamily = 0,
bool bLoadMask = false);
int ContinueLoadDIBSource(IFX_Pause* pPause);
int StratLoadMask();
int StartLoadMaskDIB();
int ContinueLoadMaskDIB(IFX_Pause* pPause);
int ContinueToLoadMask();
CPDF_DIBSource* DetachMask();
private:
bool LoadColorInfo(const CPDF_Dictionary* pFormResources,
const CPDF_Dictionary* pPageResources);
DIB_COMP_DATA* GetDecodeAndMaskArray(bool& bDefaultDecode, bool& bColorKey);
CPDF_DIBSource* LoadMask(uint32_t& MatteColor);
CPDF_DIBSource* LoadMaskDIB(CPDF_Stream* pMask);
void LoadJpxBitmap();
void LoadPalette();
int CreateDecoder();
void TranslateScanline24bpp(uint8_t* dest_scan,
const uint8_t* src_scan) const;
void ValidateDictParam();
void DownSampleScanline1Bit(int orig_Bpp,
int dest_Bpp,
uint32_t src_width,
const uint8_t* pSrcLine,
uint8_t* dest_scan,
int dest_width,
bool bFlipX,
int clip_left,
int clip_width) const;
void DownSampleScanline8Bit(int orig_Bpp,
int dest_Bpp,
uint32_t src_width,
const uint8_t* pSrcLine,
uint8_t* dest_scan,
int dest_width,
bool bFlipX,
int clip_left,
int clip_width) const;
void DownSampleScanline32Bit(int orig_Bpp,
int dest_Bpp,
uint32_t src_width,
const uint8_t* pSrcLine,
uint8_t* dest_scan,
int dest_width,
bool bFlipX,
int clip_left,
int clip_width) const;
bool TransMask() const;
CPDF_Document* m_pDocument;
const CPDF_Stream* m_pStream;
std::unique_ptr<CPDF_StreamAcc> m_pStreamAcc;
const CPDF_Dictionary* m_pDict;
CPDF_ColorSpace* m_pColorSpace;
uint32_t m_Family;
uint32_t m_bpc;
uint32_t m_bpc_orig;
uint32_t m_nComponents;
uint32_t m_GroupFamily;
uint32_t m_MatteColor;
bool m_bLoadMask;
bool m_bDefaultDecode;
bool m_bImageMask;
bool m_bDoBpcCheck;
bool m_bColorKey;
bool m_bHasMask;
bool m_bStdCS;
DIB_COMP_DATA* m_pCompData;
uint8_t* m_pLineBuf;
uint8_t* m_pMaskedLine;
std::unique_ptr<CFX_DIBitmap> m_pCachedBitmap;
std::unique_ptr<CCodec_ScanlineDecoder> m_pDecoder;
CPDF_DIBSource* m_pMask;
std::unique_ptr<CPDF_StreamAcc> m_pGlobalStream;
std::unique_ptr<CCodec_Jbig2Context> m_pJbig2Context;
CPDF_Stream* m_pMaskStream;
int m_Status;
};
#define FPDF_HUGE_IMAGE_SIZE 60000000
class CPDF_DIBTransferFunc : public CFX_FilteredDIB {
public:
explicit CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc);
~CPDF_DIBTransferFunc() override;
// CFX_FilteredDIB
FXDIB_Format GetDestFormat() override;
FX_ARGB* GetDestPalette() override;
void TranslateScanline(const uint8_t* src_buf,
std::vector<uint8_t>* dest_buf) const override;
void TranslateDownSamples(uint8_t* dest_buf,
const uint8_t* src_buf,
int pixels,
int Bpp) const override;
const uint8_t* m_RampR;
const uint8_t* m_RampG;
const uint8_t* m_RampB;
};
#endif // CORE_FPDFAPI_RENDER_RENDER_INT_H_
|