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