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