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