Clean up CPDF_AnnotList.
[pdfium.git] / core / include / fxcodec / fx_codec.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_INCLUDE_FXCODEC_FX_CODEC_H_
8 #define CORE_INCLUDE_FXCODEC_FX_CODEC_H_
9
10 #include <vector>
11
12 #include "../../../third_party/base/nonstd_unique_ptr.h"
13 #include "../fxcrt/fx_basic.h"
14 #include "fx_codec_def.h"
15
16 class CFX_DIBSource;
17 class CJPX_Decoder;
18 class CPDF_PrivateData;
19 class CPDF_StreamAcc;
20 class ICodec_ScanlineDecoder;
21 class ICodec_BasicModule;
22 class ICodec_FaxModule;
23 class ICodec_JpegModule;
24 class ICodec_JpxModule;
25 class ICodec_Jbig2Module;
26 class ICodec_IccModule;
27 class ICodec_FlateModule;
28 class ICodec_Jbig2Encoder;
29 class ICodec_ScanlineDecoder;
30
31 class CCodec_ModuleMgr {
32  public:
33   CCodec_ModuleMgr();
34   ICodec_Jbig2Encoder* CreateJbig2Encoder();
35   ICodec_BasicModule* GetBasicModule() const { return m_pBasicModule.get(); }
36   ICodec_FaxModule* GetFaxModule() const { return m_pFaxModule.get(); }
37   ICodec_JpegModule* GetJpegModule() const { return m_pJpegModule.get(); }
38   ICodec_JpxModule* GetJpxModule() const { return m_pJpxModule.get(); }
39   ICodec_Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
40   ICodec_IccModule* GetIccModule() const { return m_pIccModule.get(); }
41   ICodec_FlateModule* GetFlateModule() const { return m_pFlateModule.get(); }
42
43  protected:
44   nonstd::unique_ptr<ICodec_BasicModule> m_pBasicModule;
45   nonstd::unique_ptr<ICodec_FaxModule> m_pFaxModule;
46   nonstd::unique_ptr<ICodec_JpegModule> m_pJpegModule;
47   nonstd::unique_ptr<ICodec_JpxModule> m_pJpxModule;
48   nonstd::unique_ptr<ICodec_Jbig2Module> m_pJbig2Module;
49   nonstd::unique_ptr<ICodec_IccModule> m_pIccModule;
50   nonstd::unique_ptr<ICodec_FlateModule> m_pFlateModule;
51 };
52 class ICodec_BasicModule {
53  public:
54   virtual ~ICodec_BasicModule() {}
55   virtual FX_BOOL RunLengthEncode(const uint8_t* src_buf,
56                                   FX_DWORD src_size,
57                                   uint8_t*& dest_buf,
58                                   FX_DWORD& dest_size) = 0;
59   virtual FX_BOOL A85Encode(const uint8_t* src_buf,
60                             FX_DWORD src_size,
61                             uint8_t*& dest_buf,
62                             FX_DWORD& dest_size) = 0;
63   virtual ICodec_ScanlineDecoder* CreateRunLengthDecoder(const uint8_t* src_buf,
64                                                          FX_DWORD src_size,
65                                                          int width,
66                                                          int height,
67                                                          int nComps,
68                                                          int bpc) = 0;
69 };
70
71 class ICodec_ScanlineDecoder {
72  public:
73   virtual ~ICodec_ScanlineDecoder() {}
74
75   virtual FX_DWORD GetSrcOffset() = 0;
76
77   virtual void DownScale(int dest_width, int dest_height) = 0;
78
79   virtual const uint8_t* GetScanline(int line) = 0;
80
81   virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) = 0;
82
83   virtual int GetWidth() = 0;
84
85   virtual int GetHeight() = 0;
86
87   virtual int CountComps() = 0;
88
89   virtual int GetBPC() = 0;
90
91   virtual FX_BOOL IsColorTransformed() = 0;
92
93   virtual void ClearImageData() = 0;
94 };
95
96 class ICodec_FlateModule {
97  public:
98   virtual ~ICodec_FlateModule() {}
99   virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf,
100                                                 FX_DWORD src_size,
101                                                 int width,
102                                                 int height,
103                                                 int nComps,
104                                                 int bpc,
105                                                 int predictor,
106                                                 int Colors,
107                                                 int BitsPerComponent,
108                                                 int Columns) = 0;
109   virtual FX_DWORD FlateOrLZWDecode(FX_BOOL bLZW,
110                                     const uint8_t* src_buf,
111                                     FX_DWORD src_size,
112                                     FX_BOOL bEarlyChange,
113                                     int predictor,
114                                     int Colors,
115                                     int BitsPerComponent,
116                                     int Columns,
117                                     FX_DWORD estimated_size,
118                                     uint8_t*& dest_buf,
119                                     FX_DWORD& dest_size) = 0;
120   virtual FX_BOOL Encode(const uint8_t* src_buf,
121                          FX_DWORD src_size,
122                          int predictor,
123                          int Colors,
124                          int BitsPerComponent,
125                          int Columns,
126                          uint8_t*& dest_buf,
127                          FX_DWORD& dest_size) = 0;
128   virtual FX_BOOL Encode(const uint8_t* src_buf,
129                          FX_DWORD src_size,
130                          uint8_t*& dest_buf,
131                          FX_DWORD& dest_size) = 0;
132 };
133 class ICodec_FaxModule {
134  public:
135   virtual ~ICodec_FaxModule() {}
136
137   virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf,
138                                                 FX_DWORD src_size,
139                                                 int width,
140                                                 int height,
141                                                 int K,
142                                                 FX_BOOL EndOfLine,
143                                                 FX_BOOL EncodedByteAlign,
144                                                 FX_BOOL BlackIs1,
145                                                 int Columns,
146                                                 int Rows) = 0;
147
148   virtual FX_BOOL Encode(const uint8_t* src_buf,
149                          int width,
150                          int height,
151                          int pitch,
152                          uint8_t*& dest_buf,
153                          FX_DWORD& dest_size) = 0;
154 };
155 class ICodec_JpegModule {
156  public:
157   virtual ~ICodec_JpegModule() {}
158
159   virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf,
160                                                 FX_DWORD src_size,
161                                                 int width,
162                                                 int height,
163                                                 int nComps,
164                                                 FX_BOOL ColorTransform) = 0;
165
166   virtual FX_BOOL LoadInfo(const uint8_t* src_buf,
167                            FX_DWORD src_size,
168                            int& width,
169                            int& height,
170                            int& num_components,
171                            int& bits_per_components,
172                            FX_BOOL& color_transform,
173                            uint8_t** icc_buf_ptr = NULL,
174                            FX_DWORD* icc_length = NULL) = 0;
175
176   virtual FX_BOOL Encode(const class CFX_DIBSource* pSource,
177                          uint8_t*& dest_buf,
178                          FX_STRSIZE& dest_size,
179                          int quality = 75,
180                          const uint8_t* icc_buf = NULL,
181                          FX_DWORD icc_length = 0) = 0;
182
183   virtual void* Start() = 0;
184
185   virtual void Finish(void* pContext) = 0;
186
187   virtual void Input(void* pContext,
188                      const uint8_t* src_buf,
189                      FX_DWORD src_size) = 0;
190
191   virtual int ReadHeader(void* pContext,
192                          int* width,
193                          int* height,
194                          int* nComps) = 0;
195
196   virtual int StartScanline(void* pContext, int down_scale) = 0;
197
198   virtual FX_BOOL ReadScanline(void* pContext, uint8_t* dest_buf) = 0;
199
200   virtual FX_DWORD GetAvailInput(void* pContext,
201                                  uint8_t** avail_buf_ptr = NULL) = 0;
202 };
203
204 class ICodec_JpxModule {
205  public:
206   virtual ~ICodec_JpxModule() {}
207
208   virtual CJPX_Decoder* CreateDecoder(const uint8_t* src_buf,
209                                       FX_DWORD src_size,
210                                       bool use_colorspace) = 0;
211
212   virtual void GetImageInfo(CJPX_Decoder* pDecoder,
213                             FX_DWORD* width,
214                             FX_DWORD* height,
215                             FX_DWORD* components) = 0;
216
217   virtual bool Decode(CJPX_Decoder* pDecoder,
218                       uint8_t* dest_data,
219                       int pitch,
220                       const std::vector<uint8_t>& offsets) = 0;
221
222   virtual void DestroyDecoder(CJPX_Decoder* pDecoder) = 0;
223 };
224
225 class ICodec_Jbig2Module {
226  public:
227   virtual ~ICodec_Jbig2Module() {}
228
229   virtual void* CreateJbig2Context() = 0;
230
231   virtual FXCODEC_STATUS StartDecode(void* pJbig2Context,
232                                      CFX_PrivateData* pPrivateData,
233                                      FX_DWORD width,
234                                      FX_DWORD height,
235                                      CPDF_StreamAcc* src_stream,
236                                      CPDF_StreamAcc* global_stream,
237                                      uint8_t* dest_buf,
238                                      FX_DWORD dest_pitch,
239                                      IFX_Pause* pPause) = 0;
240
241   virtual FXCODEC_STATUS ContinueDecode(void* pJbig2Content,
242                                         IFX_Pause* pPause) = 0;
243   virtual void DestroyJbig2Context(void* pJbig2Content) = 0;
244 };
245 class ICodec_Jbig2Encoder {
246  public:
247   virtual ~ICodec_Jbig2Encoder() {}
248 };
249 class ICodec_IccModule {
250  public:
251   typedef enum {
252     IccCS_Unknown = 0,
253     IccCS_XYZ,
254     IccCS_Lab,
255     IccCS_Luv,
256     IccCS_YCbCr,
257     IccCS_Yxy,
258     IccCS_Hsv,
259     IccCS_Hls,
260     IccCS_Gray,
261     IccCS_Rgb,
262     IccCS_Cmyk,
263     IccCS_Cmy
264   } IccCS;
265   typedef struct _IccParam {
266     FX_DWORD Version;
267     IccCS ColorSpace;
268     FX_DWORD dwProfileType;
269     FX_DWORD dwFormat;
270     uint8_t* pProfileData;
271     FX_DWORD dwProfileSize;
272     double Gamma;
273   } IccParam;
274
275   virtual ~ICodec_IccModule() {}
276
277   virtual IccCS GetProfileCS(const uint8_t* pProfileData,
278                              unsigned int dwProfileSize) = 0;
279
280   virtual IccCS GetProfileCS(IFX_FileRead* pFile) = 0;
281
282   virtual void* CreateTransform(
283       ICodec_IccModule::IccParam* pInputParam,
284       ICodec_IccModule::IccParam* pOutputParam,
285       ICodec_IccModule::IccParam* pProofParam = NULL,
286       FX_DWORD dwIntent = Icc_INTENT_PERCEPTUAL,
287       FX_DWORD dwFlag = Icc_FLAGS_DEFAULT,
288       FX_DWORD dwPrfIntent = Icc_INTENT_ABSOLUTE_COLORIMETRIC,
289       FX_DWORD dwPrfFlag = Icc_FLAGS_SOFTPROOFING) = 0;
290
291   virtual void* CreateTransform_sRGB(
292       const uint8_t* pProfileData,
293       FX_DWORD dwProfileSize,
294       int32_t& nComponents,
295       int32_t intent = 0,
296       FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT) = 0;
297
298   virtual void* CreateTransform_CMYK(
299       const uint8_t* pSrcProfileData,
300       FX_DWORD dwSrcProfileSize,
301       int32_t& nSrcComponents,
302       const uint8_t* pDstProfileData,
303       FX_DWORD dwDstProfileSize,
304       int32_t intent = 0,
305       FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT,
306       FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT) = 0;
307
308   virtual void DestroyTransform(void* pTransform) = 0;
309
310   virtual void Translate(void* pTransform,
311                          FX_FLOAT* pSrcValues,
312                          FX_FLOAT* pDestValues) = 0;
313
314   virtual void TranslateScanline(void* pTransform,
315                                  uint8_t* pDest,
316                                  const uint8_t* pSrc,
317                                  int pixels) = 0;
318   virtual void SetComponents(FX_DWORD nComponents) = 0;
319 };
320 void AdobeCMYK_to_sRGB(FX_FLOAT c,
321                        FX_FLOAT m,
322                        FX_FLOAT y,
323                        FX_FLOAT k,
324                        FX_FLOAT& R,
325                        FX_FLOAT& G,
326                        FX_FLOAT& B);
327 void AdobeCMYK_to_sRGB1(uint8_t c,
328                         uint8_t m,
329                         uint8_t y,
330                         uint8_t k,
331                         uint8_t& R,
332                         uint8_t& G,
333                         uint8_t& B);
334 FX_BOOL MD5ComputeID(const void* buf, FX_DWORD dwSize, uint8_t ID[16]);
335
336 void FaxG4Decode(const uint8_t* src_buf,
337                  FX_DWORD src_size,
338                  int* pbitpos,
339                  uint8_t* dest_buf,
340                  int width,
341                  int height,
342                  int pitch);
343
344 #endif  // CORE_INCLUDE_FXCODEC_FX_CODEC_H_