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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
// 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 "../fxcrt/fx_ext.h"
#include "fx_codec_def.h"
#include "fx_codec_provider.h"
class CFX_DIBSource;
class ICodec_ScanlineDecoder;
class ICodec_ProgressiveDecoder;
class ICodec_BasicModule;
class ICodec_FaxModule;
class ICodec_JpegModule;
class ICodec_JpxModule;
class ICodec_Jbig2Module;
class ICodec_IccModule;
class ICodec_FlateModule;
class ICodec_Jbig2Encoder;
class ICodec_PngModule;
class ICodec_GifModule;
class ICodec_BmpModule;
class ICodec_TiffModule;
class CFX_DIBAttribute;
class ICodec_ScanlineDecoder;
class CCodec_ModuleMgr
{
public:
static CCodec_ModuleMgr* Create();
void Destroy();
void InitJbig2Decoder();
void InitJpxDecoder();
void InitIccDecoder();
ICodec_ProgressiveDecoder* CreateProgressiveDecoder();
ICodec_Jbig2Encoder* CreateJbig2Encoder();
protected:
CCodec_ModuleMgr();
~CCodec_ModuleMgr();
public:
ICodec_BasicModule* GetBasicModule()
{
return m_pBasicModule;
}
ICodec_FaxModule* GetFaxModule()
{
return m_pFaxModule;
}
ICodec_JpegModule* GetJpegModule()
{
return m_pJpegModule;
}
ICodec_JpxModule* GetJpxModule()
{
return m_pJpxModule;
}
ICodec_Jbig2Module* GetJbig2Module()
{
return m_pJbig2Module;
}
ICodec_IccModule* GetIccModule()
{
return m_pIccModule;
}
ICodec_FlateModule* GetFlateModule()
{
return m_pFlateModule;
}
ICodec_PngModule* GetPngModule()
{
return m_pPngModule;
}
ICodec_GifModule* GetGifModule()
{
return m_pGifModule;
}
ICodec_BmpModule* GetBmpModule()
{
return m_pBmpModule;
}
ICodec_TiffModule* GetTiffModule()
{
return m_pTiffModule;
}
protected:
ICodec_BasicModule* m_pBasicModule;
ICodec_FaxModule* m_pFaxModule;
ICodec_JpegModule* m_pJpegModule;
ICodec_JpxModule* m_pJpxModule;
ICodec_Jbig2Module* m_pJbig2Module;
ICodec_IccModule* m_pIccModule;
ICodec_FlateModule* m_pFlateModule;
ICodec_PngModule* m_pPngModule;
ICodec_GifModule* m_pGifModule;
ICodec_BmpModule* m_pBmpModule;
ICodec_TiffModule* m_pTiffModule;
};
class ICodec_BasicModule
{
public:
virtual ~ICodec_BasicModule() {}
virtual FX_BOOL RunLengthEncode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf,
FX_DWORD& dest_size) = 0;
virtual FX_BOOL A85Encode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf,
FX_DWORD& dest_size) = 0;
virtual ICodec_ScanlineDecoder* CreateRunLengthDecoder(FX_LPCBYTE 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 FX_LPBYTE 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(FX_LPCBYTE 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 FX_BYTE* src_buf, FX_DWORD src_size, FX_BOOL bEarlyChange,
int predictor, int Colors, int BitsPerComponent, int Columns,
FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size) = 0;
virtual FX_BOOL Encode(const FX_BYTE* src_buf, FX_DWORD src_size,
int predictor, int Colors, int BitsPerComponent, int Columns,
FX_LPBYTE& dest_buf, FX_DWORD& dest_size) = 0;
virtual FX_BOOL Encode(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size) = 0;
};
class ICodec_FaxModule
{
public:
virtual ~ICodec_FaxModule() {}
virtual ICodec_ScanlineDecoder* CreateDecoder(FX_LPCBYTE 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;
virtual FX_BOOL Encode(FX_LPCBYTE src_buf, int width, int height, int pitch,
FX_LPBYTE& dest_buf, FX_DWORD& dest_size) = 0;
};
class ICodec_JpegModule
{
public:
virtual ~ICodec_JpegModule() {}
virtual void SetPovider(IFX_JpegProvider* pJP) = 0;
virtual ICodec_ScanlineDecoder* CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size,
int width, int height, int nComps, FX_BOOL ColorTransform) = 0;
virtual FX_BOOL LoadInfo(FX_LPCBYTE src_buf, FX_DWORD src_size, int& width, int& height,
int& num_components, int& bits_per_components, FX_BOOL& color_transform,
FX_LPBYTE* icc_buf_ptr = NULL, FX_DWORD* icc_length = NULL) = 0;
virtual FX_BOOL Encode(const class CFX_DIBSource* pSource, FX_LPBYTE& dest_buf, FX_STRSIZE& dest_size, int quality = 75,
FX_LPCBYTE icc_buf = NULL, FX_DWORD icc_length = 0) = 0;
virtual void* Start() = 0;
virtual void Finish(void* pContext) = 0;
virtual void Input(void* pContext, FX_LPCBYTE src_buf, FX_DWORD src_size) = 0;
virtual int ReadHeader(void* pContext, int* width, int* height, int* nComps, CFX_DIBAttribute* pAttribute = NULL) = 0;
virtual int StartScanline(void* pContext, int down_scale) = 0;
virtual FX_BOOL ReadScanline(void* pContext, FX_LPBYTE dest_buf) = 0;
virtual FX_DWORD GetAvailInput(void* pContext, FX_LPBYTE* avail_buf_ptr = NULL) = 0;
};
class ICodec_JpxModule
{
public:
virtual ~ICodec_JpxModule() {}
virtual FX_LPVOID CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_BOOL useColorSpace = FALSE) = 0;
virtual void GetImageInfo(FX_LPVOID ctx, FX_DWORD& width, FX_DWORD& height,
FX_DWORD& codestream_nComps, FX_DWORD& output_nComps) = 0;
virtual FX_BOOL Decode(FX_LPVOID ctx, FX_LPBYTE dest_data, int pitch,
FX_BOOL bTranslateColor, FX_LPBYTE offsets) = 0;
virtual void DestroyDecoder(FX_LPVOID ctx) = 0;
};
class ICodec_PngModule
{
public:
virtual ~ICodec_PngModule() {}
virtual void* Start(void* pModule) = 0;
virtual void Finish(void* pContext) = 0;
virtual FX_BOOL Input(void* pContext, FX_LPCBYTE src_buf, FX_DWORD src_size, CFX_DIBAttribute* pAttribute = NULL) = 0;
FX_BOOL (*ReadHeaderCallback)(void* pModule, int width, int height, int bpc, int pass, int* color_type, double* gamma);
FX_BOOL (*AskScanlineBufCallback)(void* pModule, int line, FX_LPBYTE& src_buf);
void (*FillScanlineBufCompletedCallback)(void* pModule, int pass, int line);
};
class ICodec_GifModule
{
public:
virtual ~ICodec_GifModule() {}
virtual void* Start(void* pModule) = 0;
virtual void Finish(void* pContext) = 0;
virtual FX_DWORD GetAvailInput(void* pContext, FX_LPBYTE* avail_buf_ptr = NULL) = 0;
virtual void Input(void* pContext, FX_LPCBYTE src_buf, FX_DWORD src_size) = 0;
virtual FX_INT32 ReadHeader(void* pContext, int* width, int* height,
int* pal_num, void** pal_pp, int* bg_index, CFX_DIBAttribute* pAttribute = NULL) = 0;
virtual FX_INT32 LoadFrameInfo(void* pContext, int* frame_num) = 0;
void (*RecordCurrentPositionCallback)(void* pModule, FX_DWORD& cur_pos);
FX_LPBYTE (*AskLocalPaletteBufCallback)(void* pModule, FX_INT32 frame_num, FX_INT32 pal_size);
virtual FX_INT32 LoadFrame(void* pContext, int frame_num, CFX_DIBAttribute* pAttribute = NULL) = 0;
FX_BOOL (*InputRecordPositionBufCallback)(void* pModule, FX_DWORD rcd_pos, const FX_RECT& img_rc,
FX_INT32 pal_num, void* pal_ptr,
FX_INT32 delay_time, FX_BOOL user_input,
FX_INT32 trans_index, FX_INT32 disposal_method, FX_BOOL interlace);
void (*ReadScanlineCallback)(void* pModule, FX_INT32 row_num, FX_LPBYTE row_buf);
};
class ICodec_BmpModule
{
public:
virtual ~ICodec_BmpModule() {}
virtual void* Start(void* pModule) = 0;
virtual void Finish(void* pContext) = 0;
virtual FX_DWORD GetAvailInput(void* pContext, FX_LPBYTE* avail_buf_ptr = NULL) = 0;
virtual void Input(void* pContext, FX_LPCBYTE src_buf, FX_DWORD src_size) = 0;
virtual FX_INT32 ReadHeader(void* pContext, FX_INT32* width, FX_INT32* height, FX_BOOL* tb_flag, FX_INT32* components,
int* pal_num, FX_DWORD** pal_pp, CFX_DIBAttribute* pAttribute = NULL) = 0;
virtual FX_INT32 LoadImage(void* pContext) = 0;
FX_BOOL (*InputImagePositionBufCallback)(void* pModule, FX_DWORD rcd_pos);
void (*ReadScanlineCallback)(void* pModule, FX_INT32 row_num, FX_LPBYTE row_buf);
};
class ICodec_TiffModule
{
public:
virtual ~ICodec_TiffModule() {}
virtual FX_LPVOID CreateDecoder(IFX_FileRead* file_ptr) = 0;
virtual void GetFrames(FX_LPVOID ctx, FX_INT32& frames) = 0;
virtual FX_BOOL LoadFrameInfo(FX_LPVOID ctx, FX_INT32 frame, FX_DWORD& width, FX_DWORD& height, FX_DWORD& comps, FX_DWORD& bpc, CFX_DIBAttribute* pAttribute = NULL) = 0;
virtual FX_BOOL Decode(FX_LPVOID ctx, class CFX_DIBitmap* pDIBitmap) = 0;
virtual void DestroyDecoder(FX_LPVOID ctx) = 0;
};
class ICodec_Jbig2Module
{
public:
virtual ~ICodec_Jbig2Module() {}
virtual FX_BOOL Decode(FX_DWORD width, FX_DWORD height, FX_LPCBYTE src_buf, FX_DWORD src_size,
FX_LPCBYTE global_data, FX_DWORD global_size, FX_LPBYTE dest_buf, FX_DWORD dest_pitch) = 0;
virtual FX_BOOL Decode(IFX_FileRead* file_ptr, FX_DWORD& width, FX_DWORD& height,
FX_DWORD& pitch, FX_LPBYTE& dest_buf) = 0;
virtual void* CreateJbig2Context() = 0;
virtual FXCODEC_STATUS StartDecode(void* pJbig2Context, FX_DWORD width, FX_DWORD height, FX_LPCBYTE src_buf, FX_DWORD src_size,
FX_LPCBYTE global_data, FX_DWORD global_size, FX_LPBYTE dest_buf, FX_DWORD dest_pitch, IFX_Pause* pPause) = 0;
virtual FXCODEC_STATUS StartDecode(void* pJbig2Context, IFX_FileRead* file_ptr,
FX_DWORD& width, FX_DWORD& height, FX_DWORD& pitch, FX_LPBYTE& dest_buf, IFX_Pause* pPause) = 0;
virtual FXCODEC_STATUS ContinueDecode(void* pJbig2Content, IFX_Pause* pPause) = 0;
virtual void DestroyJbig2Context(void* pJbig2Content) = 0;
};
class ICodec_ProgressiveDecoder
{
public:
virtual ~ICodec_ProgressiveDecoder() {}
virtual FXCODEC_STATUS LoadImageInfo(IFX_FileRead* pFile, FXCODEC_IMAGE_TYPE imageType = FXCODEC_IMAGE_UNKNOWN, CFX_DIBAttribute* pAttribute = NULL) = 0;
virtual FXCODEC_IMAGE_TYPE GetType() = 0;
virtual FX_INT32 GetWidth() = 0;
virtual FX_INT32 GetHeight() = 0;
virtual FX_INT32 GetNumComponents() = 0;
virtual FX_INT32 GetBPC() = 0;
virtual void SetClipBox(FX_RECT* clip) = 0;
virtual FXCODEC_STATUS GetFrames(FX_INT32& frames, IFX_Pause* pPause = NULL) = 0;
virtual FXCODEC_STATUS StartDecode(class CFX_DIBitmap* pDIBitmap,
FX_INT32 start_x, FX_INT32 start_y, FX_INT32 size_x, FX_INT32 size_y,
FX_INT32 frames = 0, FX_BOOL bInterpol = TRUE) = 0;
virtual FXCODEC_STATUS ContinueDecode(IFX_Pause* pPause = NULL) = 0;
};
class ICodec_Jbig2Encoder
{
public:
virtual ~ICodec_Jbig2Encoder() {}
};
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;
FX_LPBYTE pProfileData;
FX_DWORD dwProfileSize;
double Gamma;
} IccParam;
virtual ~ICodec_IccModule() {}
virtual IccCS GetProfileCS(FX_LPCBYTE pProfileData, unsigned int dwProfileSize) = 0;
virtual IccCS GetProfileCS(IFX_FileRead* pFile) = 0;
virtual FX_LPVOID 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 FX_LPVOID CreateTransform_sRGB(FX_LPCBYTE pProfileData, FX_DWORD dwProfileSize, FX_INT32& nComponents, FX_INT32 intent = 0,
FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT) = 0;
virtual FX_LPVOID CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, FX_DWORD dwSrcProfileSize, FX_INT32& nSrcComponents,
FX_LPCBYTE pDstProfileData, FX_DWORD dwDstProfileSize, FX_INT32 intent = 0,
FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT,
FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT
) = 0;
virtual void DestroyTransform(FX_LPVOID pTransform) = 0;
virtual void Translate(FX_LPVOID pTransform, FX_FLOAT* pSrcValues, FX_FLOAT* pDestValues) = 0;
virtual void TranslateScanline(FX_LPVOID pTransform, FX_LPBYTE pDest, FX_LPCBYTE 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(FX_BYTE c, FX_BYTE m, FX_BYTE y, FX_BYTE k, FX_BYTE& R, FX_BYTE& G, FX_BYTE& B);
FX_BOOL MD5ComputeID(FX_LPCVOID buf, FX_DWORD dwSize, FX_BYTE ID[16]);
class CFX_DIBAttribute
{
public:
CFX_DIBAttribute();
~CFX_DIBAttribute();
FX_INT32 m_nXDPI;
FX_INT32 m_nYDPI;
FX_FLOAT m_fAspectRatio;
FX_WORD m_wDPIUnit;
CFX_ByteString m_strAuthor;
FX_BYTE m_strTime[20];
FX_INT32 m_nGifLeft;
FX_INT32 m_nGifTop;
FX_DWORD* m_pGifLocalPalette;
FX_DWORD m_nGifLocalPalNum;
FX_INT32 m_nBmpCompressType;
class IFX_DIBAttributeExif* m_pExif;
};
class IFX_DIBAttributeExif
{
public:
virtual ~IFX_DIBAttributeExif() {};
virtual FX_BOOL GetInfo(FX_WORD tag, FX_LPVOID val) = 0;
};
#endif // CORE_INCLUDE_FXCODEC_FX_CODEC_H_
|