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