Clean up CPDF_AnnotList.
[pdfium.git] / core / src / fpdfapi / fpdf_render / render_int.h
1 // Copyright 2014 PDFium Authors. All rights reserved.
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_SRC_FPDFAPI_FPDF_RENDER_RENDER_INT_H_
8 #define CORE_SRC_FPDFAPI_FPDF_RENDER_RENDER_INT_H_
9
10 #include <map>
11
12 #include "../../../../third_party/base/nonstd_unique_ptr.h"
13 #include "../../../include/fpdfapi/fpdf_pageobj.h"
14
15 class CFX_GlyphBitmap;
16 class CPDF_QuickStretcher;
17
18 #define TYPE3_MAX_BLUES 16
19
20 class CPDF_Type3Glyphs {
21  public:
22   CPDF_Type3Glyphs() {
23     m_GlyphMap.InitHashTable(253);
24     m_TopBlueCount = m_BottomBlueCount = 0;
25   }
26   ~CPDF_Type3Glyphs();
27   CFX_MapPtrToPtr m_GlyphMap;
28   void AdjustBlue(FX_FLOAT top,
29                   FX_FLOAT bottom,
30                   int& top_line,
31                   int& bottom_line);
32
33   int m_TopBlue[TYPE3_MAX_BLUES], m_BottomBlue[TYPE3_MAX_BLUES];
34   int m_TopBlueCount, m_BottomBlueCount;
35 };
36 class CPDF_Type3Cache {
37  public:
38   explicit CPDF_Type3Cache(CPDF_Type3Font* pFont) : m_pFont(pFont) {}
39   ~CPDF_Type3Cache();
40
41   CFX_GlyphBitmap* LoadGlyph(FX_DWORD charcode,
42                              const CFX_AffineMatrix* pMatrix,
43                              FX_FLOAT retinaScaleX = 1.0f,
44                              FX_FLOAT retinaScaleY = 1.0f);
45
46  protected:
47   CFX_GlyphBitmap* RenderGlyph(CPDF_Type3Glyphs* pSize,
48                                FX_DWORD charcode,
49                                const CFX_AffineMatrix* pMatrix,
50                                FX_FLOAT retinaScaleX = 1.0f,
51                                FX_FLOAT retinaScaleY = 1.0f);
52   CPDF_Type3Font* const m_pFont;
53   std::map<CFX_ByteString, CPDF_Type3Glyphs*> m_SizeMap;
54 };
55 class CPDF_TransferFunc {
56  public:
57   CPDF_Document* m_pPDFDoc;
58   uint8_t m_Samples[256 * 3];
59   FX_BOOL m_bIdentity;
60
61   CFX_DIBSource* TranslateImage(const CFX_DIBSource* pSrc,
62                                 FX_BOOL bAutoDropSrc);
63   FX_COLORREF TranslateColor(FX_COLORREF src);
64 };
65
66 class CPDF_DocRenderData {
67  public:
68   CPDF_DocRenderData(CPDF_Document* pPDFDoc = NULL);
69   ~CPDF_DocRenderData();
70   CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont);
71   CPDF_TransferFunc* GetTransferFunc(CPDF_Object* pObj);
72   CFX_FontCache* GetFontCache() { return m_pFontCache; }
73   void Clear(FX_BOOL bRelease = FALSE);
74   void ReleaseCachedType3(CPDF_Type3Font* pFont);
75   void ReleaseTransferFunc(CPDF_Object* pObj);
76
77  private:
78   using CPDF_Type3CacheMap =
79       std::map<CPDF_Font*, CPDF_CountedObject<CPDF_Type3Cache>*>;
80   using CPDF_TransferFuncMap =
81       std::map<CPDF_Object*, CPDF_CountedObject<CPDF_TransferFunc>*>;
82
83   CPDF_Document* m_pPDFDoc;
84   CFX_FontCache* m_pFontCache;
85   CPDF_Type3CacheMap m_Type3FaceMap;
86   CPDF_TransferFuncMap m_TransferFuncMap;
87 };
88 struct _PDF_RenderItem {
89  public:
90   CPDF_PageObjects* m_pObjectList;
91   CFX_AffineMatrix m_Matrix;
92 };
93
94 typedef CFX_ArrayTemplate<_PDF_RenderItem> CPDF_RenderLayer;
95
96 class IPDF_ObjectRenderer {
97  public:
98   static IPDF_ObjectRenderer* Create(int type);
99   virtual ~IPDF_ObjectRenderer() {}
100   virtual FX_BOOL Start(CPDF_RenderStatus* pRenderStatus,
101                         const CPDF_PageObject* pObj,
102                         const CFX_AffineMatrix* pObj2Device,
103                         FX_BOOL bStdCS,
104                         int blendType = FXDIB_BLEND_NORMAL) = 0;
105   virtual FX_BOOL Continue(IFX_Pause* pPause) = 0;
106   FX_BOOL m_Result;
107 };
108
109 class CPDF_RenderStatus {
110  public:
111   CPDF_RenderStatus();
112   ~CPDF_RenderStatus();
113   FX_BOOL Initialize(class CPDF_RenderContext* pContext,
114                      CFX_RenderDevice* pDevice,
115                      const CFX_AffineMatrix* pDeviceMatrix,
116                      const CPDF_PageObject* pStopObj,
117                      const CPDF_RenderStatus* pParentStatus,
118                      const CPDF_GraphicStates* pInitialStates,
119                      const CPDF_RenderOptions* pOptions,
120                      int transparency,
121                      FX_BOOL bDropObjects,
122                      CPDF_Dictionary* pFormResource = NULL,
123                      FX_BOOL bStdCS = FALSE,
124                      CPDF_Type3Char* pType3Char = NULL,
125                      FX_ARGB fill_color = 0,
126                      FX_DWORD GroupFamily = 0,
127                      FX_BOOL bLoadMask = FALSE);
128   void RenderObjectList(const CPDF_PageObjects* pObjs,
129                         const CFX_AffineMatrix* pObj2Device);
130   void RenderSingleObject(const CPDF_PageObject* pObj,
131                           const CFX_AffineMatrix* pObj2Device);
132   FX_BOOL ContinueSingleObject(const CPDF_PageObject* pObj,
133                                const CFX_AffineMatrix* pObj2Device,
134                                IFX_Pause* pPause);
135   CPDF_RenderOptions m_Options;
136   CPDF_Dictionary* m_pFormResource;
137   CPDF_Dictionary* m_pPageResource;
138   CFX_PtrArray m_Type3FontCache;
139   CPDF_RenderContext* GetContext() { return m_pContext; }
140
141  protected:
142   friend class CPDF_ImageRenderer;
143   friend class CPDF_RenderContext;
144   void ProcessClipPath(CPDF_ClipPath ClipPath,
145                        const CFX_AffineMatrix* pObj2Device);
146   void DrawClipPath(CPDF_ClipPath ClipPath,
147                     const CFX_AffineMatrix* pObj2Device);
148   FX_BOOL ProcessTransparency(const CPDF_PageObject* PageObj,
149                               const CFX_AffineMatrix* pObj2Device);
150   void ProcessObjectNoClip(const CPDF_PageObject* PageObj,
151                            const CFX_AffineMatrix* pObj2Device);
152   void DrawObjWithBackground(const CPDF_PageObject* pObj,
153                              const CFX_AffineMatrix* pObj2Device);
154   FX_BOOL DrawObjWithBlend(const CPDF_PageObject* pObj,
155                            const CFX_AffineMatrix* pObj2Device);
156   FX_BOOL ProcessPath(CPDF_PathObject* pPathObj,
157                       const CFX_AffineMatrix* pObj2Device);
158   void ProcessPathPattern(CPDF_PathObject* pPathObj,
159                           const CFX_AffineMatrix* pObj2Device,
160                           int& filltype,
161                           FX_BOOL& bStroke);
162   void DrawPathWithPattern(CPDF_PathObject* pPathObj,
163                            const CFX_AffineMatrix* pObj2Device,
164                            CPDF_Color* pColor,
165                            FX_BOOL bStroke);
166   void DrawTilingPattern(CPDF_TilingPattern* pPattern,
167                          CPDF_PageObject* pPageObj,
168                          const CFX_AffineMatrix* pObj2Device,
169                          FX_BOOL bStroke);
170   void DrawShadingPattern(CPDF_ShadingPattern* pPattern,
171                           CPDF_PageObject* pPageObj,
172                           const CFX_AffineMatrix* pObj2Device,
173                           FX_BOOL bStroke);
174   FX_BOOL SelectClipPath(CPDF_PathObject* pPathObj,
175                          const CFX_AffineMatrix* pObj2Device,
176                          FX_BOOL bStroke);
177   FX_BOOL ProcessImage(CPDF_ImageObject* pImageObj,
178                        const CFX_AffineMatrix* pObj2Device);
179   FX_BOOL OutputBitmapAlpha(CPDF_ImageObject* pImageObj,
180                             const CFX_AffineMatrix* pImage2Device);
181   FX_BOOL OutputImage(CPDF_ImageObject* pImageObj,
182                       const CFX_AffineMatrix* pImage2Device);
183   FX_BOOL OutputDIBSource(const CFX_DIBSource* pOutputBitmap,
184                           FX_ARGB fill_argb,
185                           int bitmap_alpha,
186                           const CFX_AffineMatrix* pImage2Device,
187                           CPDF_ImageCache* pImageCache,
188                           FX_DWORD flags);
189   void CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
190                          int left,
191                          int top,
192                          FX_ARGB mask_argb,
193                          int bitmap_alpha,
194                          int blend_mode,
195                          int bIsolated);
196   FX_BOOL ProcessShading(CPDF_ShadingObject* pShadingObj,
197                          const CFX_AffineMatrix* pObj2Device);
198   void DrawShading(CPDF_ShadingPattern* pPattern,
199                    CFX_AffineMatrix* pMatrix,
200                    FX_RECT& clip_rect,
201                    int alpha,
202                    FX_BOOL bAlphaMode);
203   FX_BOOL ProcessType3Text(const CPDF_TextObject* textobj,
204                            const CFX_AffineMatrix* pObj2Device);
205   FX_BOOL ProcessText(const CPDF_TextObject* textobj,
206                       const CFX_AffineMatrix* pObj2Device,
207                       CFX_PathData* pClippingPath);
208   void DrawTextPathWithPattern(const CPDF_TextObject* textobj,
209                                const CFX_AffineMatrix* pObj2Device,
210                                CPDF_Font* pFont,
211                                FX_FLOAT font_size,
212                                const CFX_AffineMatrix* pTextMatrix,
213                                FX_BOOL bFill,
214                                FX_BOOL bStroke);
215   FX_BOOL ProcessForm(CPDF_FormObject* pFormObj,
216                       const CFX_AffineMatrix* pObj2Device);
217   CFX_DIBitmap* GetBackdrop(const CPDF_PageObject* pObj,
218                             const FX_RECT& rect,
219                             int& left,
220                             int& top,
221                             FX_BOOL bBackAlphaRequired);
222   CFX_DIBitmap* LoadSMask(CPDF_Dictionary* pSMaskDict,
223                           FX_RECT* pClipRect,
224                           const CFX_AffineMatrix* pMatrix);
225   void Init(CPDF_RenderContext* pParent);
226   static class CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont);
227   static CPDF_GraphicStates* CloneObjStates(const CPDF_GraphicStates* pPathObj,
228                                             FX_BOOL bStroke);
229   CPDF_TransferFunc* GetTransferFunc(CPDF_Object* pObject) const;
230   FX_ARGB GetFillArgb(const CPDF_PageObject* pObj,
231                       FX_BOOL bType3 = FALSE) const;
232   FX_ARGB GetStrokeArgb(const CPDF_PageObject* pObj) const;
233   CPDF_RenderContext* m_pContext;
234   FX_BOOL m_bStopped;
235   void DitherObjectArea(const CPDF_PageObject* pObj,
236                         const CFX_AffineMatrix* pObj2Device);
237   FX_BOOL GetObjectClippedRect(const CPDF_PageObject* pObj,
238                                const CFX_AffineMatrix* pObj2Device,
239                                FX_BOOL bLogical,
240                                FX_RECT& rect) const;
241   void GetScaledMatrix(CFX_Matrix& matrix) const;
242
243  protected:
244   static const int kRenderMaxRecursionDepth = 64;
245   static int s_CurrentRecursionDepth;
246
247   CFX_RenderDevice* m_pDevice;
248   CFX_AffineMatrix m_DeviceMatrix;
249   CPDF_ClipPath m_LastClipPath;
250   const CPDF_PageObject* m_pCurObj;
251   const CPDF_PageObject* m_pStopObj;
252   CPDF_GraphicStates m_InitialStates;
253   int m_HalftoneLimit;
254   IPDF_ObjectRenderer* m_pObjectRenderer;
255   FX_BOOL m_bPrint;
256   int m_Transparency;
257   int m_DitherBits;
258   FX_BOOL m_bDropObjects;
259   FX_BOOL m_bStdCS;
260   FX_DWORD m_GroupFamily;
261   FX_BOOL m_bLoadMask;
262   CPDF_Type3Char* m_pType3Char;
263   FX_ARGB m_T3FillColor;
264   int m_curBlend;
265 };
266 class CPDF_ImageLoader {
267  public:
268   CPDF_ImageLoader() {
269     m_pBitmap = NULL;
270     m_pMask = NULL;
271     m_MatteColor = 0;
272     m_bCached = FALSE;
273     m_nDownsampleWidth = 0;
274     m_nDownsampleHeight = 0;
275   }
276
277   FX_BOOL Load(const CPDF_ImageObject* pImage,
278                CPDF_PageRenderCache* pCache,
279                FX_BOOL bStdCS = FALSE,
280                FX_DWORD GroupFamily = 0,
281                FX_BOOL bLoadMask = FALSE,
282                CPDF_RenderStatus* pRenderStatus = NULL);
283
284   FX_BOOL StartLoadImage(const CPDF_ImageObject* pImage,
285                          CPDF_PageRenderCache* pCache,
286                          void*& LoadHandle,
287                          FX_BOOL bStdCS = FALSE,
288                          FX_DWORD GroupFamily = 0,
289                          FX_BOOL bLoadMask = FALSE,
290                          CPDF_RenderStatus* pRenderStatus = NULL,
291                          int32_t nDownsampleWidth = 0,
292                          int32_t nDownsampleHeight = 0);
293   FX_BOOL Continue(void* LoadHandle, IFX_Pause* pPause);
294   ~CPDF_ImageLoader();
295   CFX_DIBSource* m_pBitmap;
296   CFX_DIBSource* m_pMask;
297   FX_DWORD m_MatteColor;
298   FX_BOOL m_bCached;
299
300  protected:
301   int32_t m_nDownsampleWidth;
302   int32_t m_nDownsampleHeight;
303 };
304 class CPDF_ProgressiveImageLoaderHandle {
305  public:
306   CPDF_ProgressiveImageLoaderHandle();
307   ~CPDF_ProgressiveImageLoaderHandle();
308
309   FX_BOOL Start(CPDF_ImageLoader* pImageLoader,
310                 const CPDF_ImageObject* pImage,
311                 CPDF_PageRenderCache* pCache,
312                 FX_BOOL bStdCS = FALSE,
313                 FX_DWORD GroupFamily = 0,
314                 FX_BOOL bLoadMask = FALSE,
315                 CPDF_RenderStatus* pRenderStatus = NULL,
316                 int32_t nDownsampleWidth = 0,
317                 int32_t nDownsampleHeight = 0);
318   FX_BOOL Continue(IFX_Pause* pPause);
319
320  protected:
321   CPDF_ImageLoader* m_pImageLoader;
322   CPDF_PageRenderCache* m_pCache;
323   CPDF_ImageObject* m_pImage;
324   int32_t m_nDownsampleWidth;
325   int32_t m_nDownsampleHeight;
326 };
327 class CFX_ImageTransformer;
328
329 class CPDF_ImageRenderer : public IPDF_ObjectRenderer {
330  public:
331   CPDF_ImageRenderer();
332   ~CPDF_ImageRenderer() override;
333
334   // IPDF_ObjectRenderer
335   FX_BOOL Start(CPDF_RenderStatus* pStatus,
336                 const CPDF_PageObject* pObj,
337                 const CFX_AffineMatrix* pObj2Device,
338                 FX_BOOL bStdCS,
339                 int blendType = FXDIB_BLEND_NORMAL) override;
340   FX_BOOL Continue(IFX_Pause* pPause) override;
341
342   FX_BOOL Start(CPDF_RenderStatus* pStatus,
343                 const CFX_DIBSource* pDIBSource,
344                 FX_ARGB bitmap_argb,
345                 int bitmap_alpha,
346                 const CFX_AffineMatrix* pImage2Device,
347                 FX_DWORD flags,
348                 FX_BOOL bStdCS,
349                 int blendType = FXDIB_BLEND_NORMAL);
350
351  protected:
352   CPDF_RenderStatus* m_pRenderStatus;
353   CPDF_ImageObject* m_pImageObject;
354   int m_Status;
355   const CFX_AffineMatrix* m_pObj2Device;
356   CFX_AffineMatrix m_ImageMatrix;
357   CPDF_ImageLoader m_Loader;
358   const CFX_DIBSource* m_pDIBSource;
359   CFX_DIBitmap* m_pClone;
360   int m_BitmapAlpha;
361   FX_BOOL m_bPatternColor;
362   CPDF_Pattern* m_pPattern;
363   FX_ARGB m_FillArgb;
364   FX_DWORD m_Flags;
365   CPDF_QuickStretcher* m_pQuickStretcher;
366   CFX_ImageTransformer* m_pTransformer;
367   void* m_DeviceHandle;
368   void* m_LoadHandle;
369   FX_BOOL m_bStdCS;
370   int m_BlendType;
371   FX_BOOL StartBitmapAlpha();
372   FX_BOOL StartDIBSource();
373   FX_BOOL StartRenderDIBSource();
374   FX_BOOL StartLoadDIBSource();
375   FX_BOOL DrawMaskedImage();
376   FX_BOOL DrawPatternImage(const CFX_Matrix* pObj2Device);
377 };
378
379 class CPDF_ScaledRenderBuffer {
380  public:
381   CPDF_ScaledRenderBuffer();
382   ~CPDF_ScaledRenderBuffer();
383   FX_BOOL Initialize(CPDF_RenderContext* pContext,
384                      CFX_RenderDevice* pDevice,
385                      FX_RECT* pRect,
386                      const CPDF_PageObject* pObj,
387                      const CPDF_RenderOptions* pOptions = NULL,
388                      int max_dpi = 0);
389   CFX_RenderDevice* GetDevice() {
390     return m_pBitmapDevice ? m_pBitmapDevice : m_pDevice;
391   }
392   CFX_AffineMatrix* GetMatrix() { return &m_Matrix; }
393   void OutputToDevice();
394
395  private:
396   CFX_RenderDevice* m_pDevice;
397   CPDF_RenderContext* m_pContext;
398   FX_RECT m_Rect;
399   const CPDF_PageObject* m_pObject;
400   CFX_FxgeDevice* m_pBitmapDevice;
401   CFX_AffineMatrix m_Matrix;
402 };
403 class ICodec_ScanlineDecoder;
404 class CPDF_QuickStretcher {
405  public:
406   CPDF_QuickStretcher();
407   ~CPDF_QuickStretcher();
408   FX_BOOL Start(CPDF_ImageObject* pImageObj,
409                 CFX_AffineMatrix* pImage2Device,
410                 const FX_RECT* pClipBox);
411   FX_BOOL Continue(IFX_Pause* pPause);
412   CFX_DIBitmap* m_pBitmap;
413   int m_ResultLeft, m_ResultTop, m_ClipLeft, m_ClipTop;
414   int m_DestWidth, m_DestHeight, m_ResultWidth, m_ResultHeight;
415   int m_Bpp, m_SrcWidth, m_SrcHeight;
416   FX_BOOL m_bFlipX, m_bFlipY;
417   CPDF_ColorSpace* m_pCS;
418   ICodec_ScanlineDecoder* m_pDecoder;
419   CPDF_StreamAcc m_StreamAcc;
420   int m_LineIndex;
421 };
422 class CPDF_DeviceBuffer {
423  public:
424   CPDF_DeviceBuffer();
425   ~CPDF_DeviceBuffer();
426   FX_BOOL Initialize(CPDF_RenderContext* pContext,
427                      CFX_RenderDevice* pDevice,
428                      FX_RECT* pRect,
429                      const CPDF_PageObject* pObj,
430                      int max_dpi = 0);
431   void OutputToDevice();
432   CFX_DIBitmap* GetBitmap() const { return m_pBitmap; }
433   const CFX_AffineMatrix* GetMatrix() const { return &m_Matrix; }
434
435  private:
436   CFX_RenderDevice* m_pDevice;
437   CPDF_RenderContext* m_pContext;
438   FX_RECT m_Rect;
439   const CPDF_PageObject* m_pObject;
440   CFX_DIBitmap* m_pBitmap;
441   CFX_AffineMatrix m_Matrix;
442 };
443 class CPDF_ImageCache {
444  public:
445   CPDF_ImageCache(CPDF_Document* pDoc, CPDF_Stream* pStream);
446   ~CPDF_ImageCache();
447   void ClearImageData();
448   void Reset(const CFX_DIBitmap* pBitmap);
449   FX_BOOL GetCachedBitmap(CFX_DIBSource*& pBitmap,
450                           CFX_DIBSource*& pMask,
451                           FX_DWORD& MatteColor,
452                           CPDF_Dictionary* pPageResources,
453                           FX_BOOL bStdCS = FALSE,
454                           FX_DWORD GroupFamily = 0,
455                           FX_BOOL bLoadMask = FALSE,
456                           CPDF_RenderStatus* pRenderStatus = NULL,
457                           int32_t downsampleWidth = 0,
458                           int32_t downsampleHeight = 0);
459   FX_DWORD EstimateSize() const { return m_dwCacheSize; }
460   FX_DWORD GetTimeCount() const { return m_dwTimeCount; }
461   CPDF_Stream* GetStream() const { return m_pStream; }
462   void SetTimeCount(FX_DWORD dwTimeCount) { m_dwTimeCount = dwTimeCount; }
463   int m_dwTimeCount;
464
465  public:
466   int StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
467                            CPDF_Dictionary* pPageResources,
468                            FX_BOOL bStdCS = FALSE,
469                            FX_DWORD GroupFamily = 0,
470                            FX_BOOL bLoadMask = FALSE,
471                            CPDF_RenderStatus* pRenderStatus = NULL,
472                            int32_t downsampleWidth = 0,
473                            int32_t downsampleHeight = 0);
474   int Continue(IFX_Pause* pPause);
475   int ContinueGetCachedBitmap();
476   CFX_DIBSource* DetachBitmap();
477   CFX_DIBSource* DetachMask();
478   CFX_DIBSource* m_pCurBitmap;
479   CFX_DIBSource* m_pCurMask;
480   FX_DWORD m_MatteColor;
481   CPDF_RenderStatus* m_pRenderStatus;
482
483  protected:
484   CPDF_Document* m_pDocument;
485   CPDF_Stream* m_pStream;
486   CFX_DIBSource* m_pCachedBitmap;
487   CFX_DIBSource* m_pCachedMask;
488   FX_DWORD m_dwCacheSize;
489   void CalcSize();
490 };
491 typedef struct {
492   FX_FLOAT m_DecodeMin;
493   FX_FLOAT m_DecodeStep;
494   int m_ColorKeyMin;
495   int m_ColorKeyMax;
496 } DIB_COMP_DATA;
497
498 class CPDF_DIBSource : public CFX_DIBSource {
499  public:
500   CPDF_DIBSource();
501   ~CPDF_DIBSource() override;
502
503   FX_BOOL Load(CPDF_Document* pDoc,
504                const CPDF_Stream* pStream,
505                CPDF_DIBSource** ppMask,
506                FX_DWORD* pMatteColor,
507                CPDF_Dictionary* pFormResources,
508                CPDF_Dictionary* pPageResources,
509                FX_BOOL bStdCS = FALSE,
510                FX_DWORD GroupFamily = 0,
511                FX_BOOL bLoadMask = FALSE);
512
513   // CFX_DIBSource
514   FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const override;
515   uint8_t* GetBuffer() const override;
516   const uint8_t* GetScanline(int line) const override;
517   void DownSampleScanline(int line,
518                           uint8_t* dest_scan,
519                           int dest_bpp,
520                           int dest_width,
521                           FX_BOOL bFlipX,
522                           int clip_left,
523                           int clip_width) const override;
524   void SetDownSampleSize(int dest_width, int dest_height) const override;
525
526   CFX_DIBitmap* GetBitmap() const;
527   void ReleaseBitmap(CFX_DIBitmap*) const;
528   void ClearImageData();
529
530   int StartLoadDIBSource(CPDF_Document* pDoc,
531                          const CPDF_Stream* pStream,
532                          FX_BOOL bHasMask,
533                          CPDF_Dictionary* pFormResources,
534                          CPDF_Dictionary* pPageResources,
535                          FX_BOOL bStdCS = FALSE,
536                          FX_DWORD GroupFamily = 0,
537                          FX_BOOL bLoadMask = FALSE);
538   int ContinueLoadDIBSource(IFX_Pause* pPause);
539   int StratLoadMask();
540   int StartLoadMaskDIB();
541   int ContinueLoadMaskDIB(IFX_Pause* pPause);
542   int ContinueToLoadMask();
543   CPDF_DIBSource* DetachMask();
544   CPDF_DIBSource* m_pMask;
545   FX_DWORD m_MatteColor;
546   void* m_pJbig2Context;
547   CPDF_StreamAcc* m_pGlobalStream;
548   FX_BOOL m_bStdCS;
549   int m_Status;
550   CPDF_Stream* m_pMaskStream;
551   FX_BOOL m_bHasMask;
552
553  private:
554   FX_BOOL LoadColorInfo(CPDF_Dictionary* pFormResources,
555                         CPDF_Dictionary* pPageResources);
556   DIB_COMP_DATA* GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode,
557                                        FX_BOOL& bColorKey);
558   CPDF_DIBSource* LoadMask(FX_DWORD& MatteColor);
559   CPDF_DIBSource* LoadMaskDIB(CPDF_Stream* pMask);
560   void LoadJpxBitmap();
561   void LoadPalette();
562   int CreateDecoder();
563   void TranslateScanline24bpp(uint8_t* dest_scan,
564                               const uint8_t* src_scan) const;
565   void ValidateDictParam();
566   void DownSampleScanline1Bit(int orig_Bpp,
567                               int dest_Bpp,
568                               FX_DWORD src_width,
569                               const uint8_t* pSrcLine,
570                               uint8_t* dest_scan,
571                               int dest_width,
572                               FX_BOOL bFlipX,
573                               int clip_left,
574                               int clip_width) const;
575   void DownSampleScanline8Bit(int orig_Bpp,
576                               int dest_Bpp,
577                               FX_DWORD src_width,
578                               const uint8_t* pSrcLine,
579                               uint8_t* dest_scan,
580                               int dest_width,
581                               FX_BOOL bFlipX,
582                               int clip_left,
583                               int clip_width) const;
584   void DownSampleScanline32Bit(int orig_Bpp,
585                                int dest_Bpp,
586                                FX_DWORD src_width,
587                                const uint8_t* pSrcLine,
588                                uint8_t* dest_scan,
589                                int dest_width,
590                                FX_BOOL bFlipX,
591                                int clip_left,
592                                int clip_width) const;
593   FX_BOOL TransMask() const;
594
595   CPDF_Document* m_pDocument;
596   const CPDF_Stream* m_pStream;
597   CPDF_StreamAcc* m_pStreamAcc;
598   const CPDF_Dictionary* m_pDict;
599   CPDF_ColorSpace* m_pColorSpace;
600   FX_DWORD m_Family;
601   FX_DWORD m_bpc;
602   FX_DWORD m_bpc_orig;
603   FX_DWORD m_nComponents;
604   FX_DWORD m_GroupFamily;
605   FX_BOOL m_bLoadMask;
606   FX_BOOL m_bDefaultDecode;
607   FX_BOOL m_bImageMask;
608   FX_BOOL m_bDoBpcCheck;
609   FX_BOOL m_bColorKey;
610   DIB_COMP_DATA* m_pCompData;
611   uint8_t* m_pLineBuf;
612   uint8_t* m_pMaskedLine;
613   nonstd::unique_ptr<CFX_DIBitmap> m_pCachedBitmap;
614   ICodec_ScanlineDecoder* m_pDecoder;
615 };
616
617 #define FPDF_HUGE_IMAGE_SIZE 60000000
618 class CPDF_DIBTransferFunc : public CFX_FilteredDIB {
619  public:
620   CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc);
621   ~CPDF_DIBTransferFunc() override;
622
623   // CFX_FilteredDIB
624   FXDIB_Format GetDestFormat() override;
625   FX_ARGB* GetDestPalette() override { return NULL; }
626   void TranslateScanline(uint8_t* dest_buf,
627                          const uint8_t* src_buf) const override;
628   void TranslateDownSamples(uint8_t* dest_buf,
629                             const uint8_t* src_buf,
630                             int pixels,
631                             int Bpp) const override;
632
633   const uint8_t* m_RampR;
634   const uint8_t* m_RampG;
635   const uint8_t* m_RampB;
636 };
637
638 struct _CPDF_UniqueKeyGen {
639   void Generate(int count, ...);
640   FX_CHAR m_Key[128];
641   int m_KeyLen;
642 };
643
644 #endif  // CORE_SRC_FPDFAPI_FPDF_RENDER_RENDER_INT_H_