summaryrefslogtreecommitdiff
path: root/core/include/fxcodec/fx_codec.h
blob: 593940df8415ad913bfc99f6ed575c1823399c62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_INCLUDE_FXCODEC_FX_CODEC_H_
#define CORE_INCLUDE_FXCODEC_FX_CODEC_H_

#include <vector>

#include "core/include/fxcrt/fx_basic.h"
#include "fx_codec_def.h"
#include "third_party/base/nonstd_unique_ptr.h"

class CFX_DIBSource;
class CJPX_Decoder;
class CPDF_PrivateData;
class CPDF_StreamAcc;
class ICodec_ScanlineDecoder;
class ICodec_BasicModule;
class ICodec_FaxModule;
class ICodec_JpegModule;
class ICodec_JpxModule;
class ICodec_Jbig2Module;
class ICodec_IccModule;
class ICodec_FlateModule;
class ICodec_ScanlineDecoder;

class CCodec_ModuleMgr {
 public:
  CCodec_ModuleMgr();

  ICodec_BasicModule* GetBasicModule() const { return m_pBasicModule.get(); }
  ICodec_FaxModule* GetFaxModule() const { return m_pFaxModule.get(); }
  ICodec_JpegModule* GetJpegModule() const { return m_pJpegModule.get(); }
  ICodec_JpxModule* GetJpxModule() const { return m_pJpxModule.get(); }
  ICodec_Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
  ICodec_IccModule* GetIccModule() const { return m_pIccModule.get(); }
  ICodec_FlateModule* GetFlateModule() const { return m_pFlateModule.get(); }

 protected:
  nonstd::unique_ptr<ICodec_BasicModule> m_pBasicModule;
  nonstd::unique_ptr<ICodec_FaxModule> m_pFaxModule;
  nonstd::unique_ptr<ICodec_JpegModule> m_pJpegModule;
  nonstd::unique_ptr<ICodec_JpxModule> m_pJpxModule;
  nonstd::unique_ptr<ICodec_Jbig2Module> m_pJbig2Module;
  nonstd::unique_ptr<ICodec_IccModule> m_pIccModule;
  nonstd::unique_ptr<ICodec_FlateModule> m_pFlateModule;
};
class ICodec_BasicModule {
 public:
  virtual ~ICodec_BasicModule() {}
  virtual ICodec_ScanlineDecoder* CreateRunLengthDecoder(const uint8_t* src_buf,
                                                         FX_DWORD src_size,
                                                         int width,
                                                         int height,
                                                         int nComps,
                                                         int bpc) = 0;
};

class ICodec_ScanlineDecoder {
 public:
  virtual ~ICodec_ScanlineDecoder() {}

  virtual FX_DWORD GetSrcOffset() = 0;

  virtual void DownScale(int dest_width, int dest_height) = 0;

  virtual const uint8_t* GetScanline(int line) = 0;

  virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) = 0;

  virtual int GetWidth() = 0;

  virtual int GetHeight() = 0;

  virtual int CountComps() = 0;

  virtual int GetBPC() = 0;

  virtual FX_BOOL IsColorTransformed() = 0;

  virtual void ClearImageData() = 0;
};

class ICodec_FlateModule {
 public:
  virtual ~ICodec_FlateModule() {}
  virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf,
                                                FX_DWORD src_size,
                                                int width,
                                                int height,
                                                int nComps,
                                                int bpc,
                                                int predictor,
                                                int Colors,
                                                int BitsPerComponent,
                                                int Columns) = 0;
  virtual FX_DWORD FlateOrLZWDecode(FX_BOOL bLZW,
                                    const uint8_t* src_buf,
                                    FX_DWORD src_size,
                                    FX_BOOL bEarlyChange,
                                    int predictor,
                                    int Colors,
                                    int BitsPerComponent,
                                    int Columns,
                                    FX_DWORD estimated_size,
                                    uint8_t*& dest_buf,
                                    FX_DWORD& dest_size) = 0;
  virtual bool Encode(const uint8_t* src_buf,
                      FX_DWORD src_size,
                      uint8_t** dest_buf,
                      FX_DWORD* dest_size) = 0;
  virtual bool PngEncode(const uint8_t* src_buf,
                         FX_DWORD src_size,
                         uint8_t** dest_buf,
                         FX_DWORD* dest_size) = 0;
};
class ICodec_FaxModule {
 public:
  virtual ~ICodec_FaxModule() {}

  virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf,
                                                FX_DWORD src_size,
                                                int width,
                                                int height,
                                                int K,
                                                FX_BOOL EndOfLine,
                                                FX_BOOL EncodedByteAlign,
                                                FX_BOOL BlackIs1,
                                                int Columns,
                                                int Rows) = 0;
};

class ICodec_JpegModule {
 public:
  virtual ~ICodec_JpegModule() {}

  virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf,
                                                FX_DWORD src_size,
                                                int width,
                                                int height,
                                                int nComps,
                                                FX_BOOL ColorTransform) = 0;

  virtual bool LoadInfo(const uint8_t* src_buf,
                        FX_DWORD src_size,
                        int* width,
                        int* height,
                        int* num_components,
                        int* bits_per_components,
                        bool* color_transform) = 0;

  virtual void* Start() = 0;

  virtual void Finish(void* pContext) = 0;

  virtual void Input(void* pContext,
                     const uint8_t* src_buf,
                     FX_DWORD src_size) = 0;

  virtual int ReadHeader(void* pContext,
                         int* width,
                         int* height,
                         int* nComps) = 0;

  virtual int StartScanline(void* pContext, int down_scale) = 0;

  virtual FX_BOOL ReadScanline(void* pContext, uint8_t* dest_buf) = 0;

  virtual FX_DWORD GetAvailInput(void* pContext,
                                 uint8_t** avail_buf_ptr = NULL) = 0;
};

class ICodec_JpxModule {
 public:
  virtual ~ICodec_JpxModule() {}

  virtual CJPX_Decoder* CreateDecoder(const uint8_t* src_buf,
                                      FX_DWORD src_size,
                                      bool use_colorspace) = 0;

  virtual void GetImageInfo(CJPX_Decoder* pDecoder,
                            FX_DWORD* width,
                            FX_DWORD* height,
                            FX_DWORD* components) = 0;

  virtual bool Decode(CJPX_Decoder* pDecoder,
                      uint8_t* dest_data,
                      int pitch,
                      const std::vector<uint8_t>& offsets) = 0;

  virtual void DestroyDecoder(CJPX_Decoder* pDecoder) = 0;
};

class ICodec_Jbig2Module {
 public:
  virtual ~ICodec_Jbig2Module() {}

  virtual void* CreateJbig2Context() = 0;

  virtual FXCODEC_STATUS StartDecode(void* pJbig2Context,
                                     CFX_PrivateData* pPrivateData,
                                     FX_DWORD width,
                                     FX_DWORD height,
                                     CPDF_StreamAcc* src_stream,
                                     CPDF_StreamAcc* global_stream,
                                     uint8_t* dest_buf,
                                     FX_DWORD dest_pitch,
                                     IFX_Pause* pPause) = 0;

  virtual FXCODEC_STATUS ContinueDecode(void* pJbig2Content,
                                        IFX_Pause* pPause) = 0;
  virtual void DestroyJbig2Context(void* pJbig2Content) = 0;
};

class ICodec_IccModule {
 public:
  typedef enum {
    IccCS_Unknown = 0,
    IccCS_XYZ,
    IccCS_Lab,
    IccCS_Luv,
    IccCS_YCbCr,
    IccCS_Yxy,
    IccCS_Hsv,
    IccCS_Hls,
    IccCS_Gray,
    IccCS_Rgb,
    IccCS_Cmyk,
    IccCS_Cmy
  } IccCS;
  typedef struct _IccParam {
    FX_DWORD Version;
    IccCS ColorSpace;
    FX_DWORD dwProfileType;
    FX_DWORD dwFormat;
    uint8_t* pProfileData;
    FX_DWORD dwProfileSize;
    double Gamma;
  } IccParam;

  virtual ~ICodec_IccModule() {}

  virtual IccCS GetProfileCS(const uint8_t* pProfileData,
                             unsigned int dwProfileSize) = 0;

  virtual IccCS GetProfileCS(IFX_FileRead* pFile) = 0;

  virtual void* CreateTransform(
      ICodec_IccModule::IccParam* pInputParam,
      ICodec_IccModule::IccParam* pOutputParam,
      ICodec_IccModule::IccParam* pProofParam = NULL,
      FX_DWORD dwIntent = Icc_INTENT_PERCEPTUAL,
      FX_DWORD dwFlag = Icc_FLAGS_DEFAULT,
      FX_DWORD dwPrfIntent = Icc_INTENT_ABSOLUTE_COLORIMETRIC,
      FX_DWORD dwPrfFlag = Icc_FLAGS_SOFTPROOFING) = 0;

  virtual void* CreateTransform_sRGB(
      const uint8_t* pProfileData,
      FX_DWORD dwProfileSize,
      int32_t& nComponents,
      int32_t intent = 0,
      FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT) = 0;

  virtual void* CreateTransform_CMYK(
      const uint8_t* pSrcProfileData,
      FX_DWORD dwSrcProfileSize,
      int32_t& nSrcComponents,
      const uint8_t* pDstProfileData,
      FX_DWORD dwDstProfileSize,
      int32_t intent = 0,
      FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT,
      FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT) = 0;

  virtual void DestroyTransform(void* pTransform) = 0;

  virtual void Translate(void* pTransform,
                         FX_FLOAT* pSrcValues,
                         FX_FLOAT* pDestValues) = 0;

  virtual void TranslateScanline(void* pTransform,
                                 uint8_t* pDest,
                                 const uint8_t* pSrc,
                                 int pixels) = 0;
  virtual void SetComponents(FX_DWORD nComponents) = 0;
};

void AdobeCMYK_to_sRGB(FX_FLOAT c,
                       FX_FLOAT m,
                       FX_FLOAT y,
                       FX_FLOAT k,
                       FX_FLOAT& R,
                       FX_FLOAT& G,
                       FX_FLOAT& B);
void AdobeCMYK_to_sRGB1(uint8_t c,
                        uint8_t m,
                        uint8_t y,
                        uint8_t k,
                        uint8_t& R,
                        uint8_t& G,
                        uint8_t& B);
FX_BOOL MD5ComputeID(const void* buf, FX_DWORD dwSize, uint8_t ID[16]);
void FaxG4Decode(const uint8_t* src_buf,
                 FX_DWORD src_size,
                 int* pbitpos,
                 uint8_t* dest_buf,
                 int width,
                 int height,
                 int pitch);

#endif  // CORE_INCLUDE_FXCODEC_FX_CODEC_H_