Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / core / src / fxcodec / codec / fx_codec_progress.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _FX_CODEC_PROGRESS_H_\r
8 #define _FX_CODEC_PROGRESS_H_\r
9 #define FXCODEC_BLOCK_SIZE 4096\r
10 #define FXCODEC_PNG_GAMMA       2.2\r
11 #if _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_\r
12 #       undef FXCODEC_PNG_GAMMA\r
13 #       define FXCODEC_PNG_GAMMA        1.7\r
14 #endif\r
15 struct PixelWeight {\r
16     int         m_SrcStart;\r
17     int         m_SrcEnd;\r
18     int         m_Weights[1];\r
19 };\r
20 class CFXCODEC_WeightTable : public CFX_Object\r
21 {\r
22 public:\r
23     CFXCODEC_WeightTable()\r
24     {\r
25         m_pWeightTables = NULL;\r
26     }\r
27     ~CFXCODEC_WeightTable()\r
28     {\r
29         if(m_pWeightTables != NULL) {\r
30             FX_Free(m_pWeightTables);\r
31         }\r
32     }\r
33 \r
34     void                        Calc(int dest_len, int dest_min, int dest_max, int src_len, int src_min, int src_max, FX_BOOL bInterpol);\r
35     PixelWeight*        GetPixelWeight(int pixel)\r
36     {\r
37         return (PixelWeight*)(m_pWeightTables + (pixel - m_DestMin) * m_ItemSize);\r
38     }\r
39 \r
40     int                         m_DestMin, m_ItemSize;\r
41     FX_LPBYTE           m_pWeightTables;\r
42 };\r
43 class CFXCODEC_HorzTable : public CFX_Object\r
44 {\r
45 public:\r
46     CFXCODEC_HorzTable()\r
47     {\r
48         m_pWeightTables = NULL;\r
49     }\r
50     ~CFXCODEC_HorzTable()\r
51     {\r
52         if(m_pWeightTables != NULL) {\r
53             FX_Free(m_pWeightTables);\r
54         }\r
55     }\r
56 \r
57     void                        Calc(int dest_len, int src_len, FX_BOOL bInterpol);\r
58     PixelWeight*        GetPixelWeight(int pixel)\r
59     {\r
60         return (PixelWeight*)(m_pWeightTables + pixel * m_ItemSize);\r
61     }\r
62 \r
63     int                         m_ItemSize;\r
64     FX_LPBYTE           m_pWeightTables;\r
65 };\r
66 class CFXCODEC_VertTable : public CFX_Object\r
67 {\r
68 public:\r
69     CFXCODEC_VertTable()\r
70     {\r
71         m_pWeightTables = NULL;\r
72     }\r
73     ~CFXCODEC_VertTable()\r
74     {\r
75         if(m_pWeightTables != NULL) {\r
76             FX_Free(m_pWeightTables);\r
77         }\r
78     }\r
79     void                        Calc(int dest_len, int src_len);\r
80     PixelWeight*        GetPixelWeight(int pixel)\r
81     {\r
82         return (PixelWeight*)(m_pWeightTables + pixel * m_ItemSize);\r
83     }\r
84     int                         m_ItemSize;\r
85     FX_LPBYTE           m_pWeightTables;\r
86 };\r
87 enum FXCodec_Format {\r
88     FXCodec_Invalid = 0,\r
89     FXCodec_1bppGray = 0x101,\r
90     FXCodec_1bppRgb = 0x001,\r
91     FXCodec_8bppGray = 0x108,\r
92     FXCodec_8bppRgb = 0x008,\r
93     FXCodec_Rgb = 0x018,\r
94     FXCodec_Rgb32 = 0x020,\r
95     FXCodec_Argb = 0x220,\r
96     FXCodec_Cmyk = 0x120\r
97 };\r
98 class CCodec_ProgressiveDecoder : public ICodec_ProgressiveDecoder\r
99 {\r
100 public:\r
101     CCodec_ProgressiveDecoder(CCodec_ModuleMgr* pCodecMgr);\r
102     virtual ~CCodec_ProgressiveDecoder();\r
103 \r
104 public:\r
105     virtual FXCODEC_STATUS              LoadImageInfo(IFX_FileRead* pFile, FXCODEC_IMAGE_TYPE imageType, CFX_DIBAttribute* pAttribute);\r
106 \r
107     virtual FXCODEC_IMAGE_TYPE  GetType()\r
108     {\r
109         return m_imagType;\r
110     }\r
111     virtual FX_INT32                    GetWidth()\r
112     {\r
113         return m_SrcWidth;\r
114     }\r
115     virtual FX_INT32                    GetHeight()\r
116     {\r
117         return m_SrcHeight;\r
118     }\r
119     virtual FX_INT32                    GetNumComponents()\r
120     {\r
121         return m_SrcComponents;\r
122     }\r
123     virtual FX_INT32                    GetBPC()\r
124     {\r
125         return m_SrcBPC;\r
126     }\r
127     virtual void                                SetClipBox(FX_RECT* clip);\r
128     virtual FXCODEC_STATUS              GetFrames(FX_INT32& frames, IFX_Pause* pPause);\r
129 \r
130     virtual FXCODEC_STATUS              StartDecode(CFX_DIBitmap* pDIBitmap,\r
131                                             int start_x, int start_y, int size_x, int size_y,\r
132                                             FX_INT32 frames, FX_BOOL bInterpol);\r
133 \r
134     virtual FXCODEC_STATUS              ContinueDecode(IFX_Pause* pPause);\r
135 \r
136 protected:\r
137     FX_BOOL                                             DetectImageType(FXCODEC_IMAGE_TYPE imageType, CFX_DIBAttribute* pAttribute = NULL);\r
138     void                                                GetDownScale(int& down_scale);\r
139     void                                                GetTransMethod(FXDIB_Format des_format, FXCodec_Format src_format);\r
140     void                                                ReSampleScanline(CFX_DIBitmap* pDeviceBitmap, FX_INT32 des_line, FX_LPBYTE src_scan, FXCodec_Format src_format);\r
141     void                                                Resample(CFX_DIBitmap* pDeviceBitmap, FX_INT32 src_line, FX_LPBYTE src_scan, FXCodec_Format src_format);\r
142     void                                                ResampleVert(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row);\r
143     FX_BOOL                                             JpegReadMoreData(ICodec_JpegModule* pJpegModule, FXCODEC_STATUS& err_status);\r
144     static FX_BOOL                              PngReadHeaderFunc(void* pModule, int width, int height, int bpc, int pass, int* color_type, double* gamma);\r
145     static FX_BOOL                              PngAskScanlineBufFunc(void* pModule, int line, FX_LPBYTE& src_buf);\r
146     static void                                 PngFillScanlineBufCompletedFunc(void* pModule, int pass, int line);\r
147     void                                                PngOneOneMapResampleHorz(CFX_DIBitmap* pDeviceBitmap, FX_INT32 des_line, FX_LPBYTE src_scan, FXCodec_Format src_format);\r
148 \r
149     FX_BOOL                                             GifReadMoreData(ICodec_GifModule* pGifModule, FXCODEC_STATUS& err_status);\r
150     static void                                 GifRecordCurrentPositionCallback(void* pModule, FX_DWORD& cur_pos);\r
151     static FX_LPBYTE                    GifAskLocalPaletteBufCallback(void* pModule, FX_INT32 frame_num, FX_INT32 pal_size);\r
152     static FX_BOOL                              GifInputRecordPositionBufCallback(void* pModule, FX_DWORD rcd_pos, const FX_RECT& img_rc,\r
153             FX_INT32 pal_num, void* pal_ptr,\r
154             FX_INT32 delay_time, FX_BOOL user_input,\r
155             FX_INT32 trans_index, FX_INT32 disposal_method, FX_BOOL interlace);\r
156     static void                                 GifReadScanlineCallback(void* pModule, FX_INT32 row_num, FX_LPBYTE row_buf);\r
157     void                                                GifDoubleLineResampleVert(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row);\r
158     FX_BOOL                                             BmpReadMoreData(ICodec_BmpModule* pBmpModule, FXCODEC_STATUS& err_status);\r
159     static FX_BOOL                              BmpInputImagePositionBufCallback(void* pModule, FX_DWORD rcd_pos);\r
160     static void                                 BmpReadScanlineCallback(void* pModule, FX_INT32 row_num, FX_LPBYTE row_buf);\r
161     void                                                ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row);\r
162 public:\r
163     IFX_FileRead*                               m_pFile;\r
164     CCodec_ModuleMgr*                   m_pCodecMgr;\r
165     FX_LPVOID                                   m_pJpegContext;\r
166     FX_LPVOID                                   m_pPngContext;\r
167     FX_LPVOID                                   m_pGifContext;\r
168     FX_LPVOID                                   m_pBmpContext;\r
169     FX_LPVOID                                   m_pTiffContext;\r
170     FXCODEC_IMAGE_TYPE                  m_imagType;\r
171     FX_DWORD                                    m_offSet;\r
172     FX_LPBYTE                                   m_pSrcBuf;\r
173     FX_DWORD                                    m_SrcSize;\r
174     FX_LPBYTE                                   m_pDecodeBuf;\r
175     int                                                 m_ScanlineSize;\r
176     CFX_DIBitmap*                               m_pDeviceBitmap;\r
177     FX_BOOL                                             m_bInterpol;\r
178     CFXCODEC_WeightTable                m_WeightHorz;\r
179     CFXCODEC_VertTable                  m_WeightVert;\r
180     CFXCODEC_HorzTable                  m_WeightHorzOO;\r
181     int                 m_SrcWidth;\r
182     int                 m_SrcHeight;\r
183     int                 m_SrcComponents;\r
184     int                 m_SrcBPC;\r
185     FX_RECT             m_clipBox;\r
186     int                 m_startX;\r
187     int                 m_startY;\r
188     int                 m_sizeX;\r
189     int                 m_sizeY;\r
190     int                 m_TransMethod;\r
191     FX_ARGB*    m_pSrcPalette;\r
192     int                 m_SrcPaletteNumber;\r
193     int                 m_SrcRow;\r
194     FXCodec_Format m_SrcFormat;\r
195     int                 m_SrcPassNumber;\r
196     int                 m_FrameNumber;\r
197     int                 m_FrameCur;\r
198     int                         m_GifBgIndex;\r
199     FX_LPBYTE           m_pGifPalette;\r
200     FX_INT32            m_GifPltNumber;\r
201     int                         m_GifTransIndex;\r
202     FX_RECT                     m_GifFrameRect;\r
203     FX_BOOL                     m_BmpIsTopBottom;\r
204     FXCODEC_STATUS m_status;\r
205 };\r
206 #endif\r