OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef CORE_FXCODEC_CODEC_FX_CODEC_PROGRESS_H_ | 7 #ifndef CORE_FXCODEC_CODEC_INCLUDE_CCODEC_PROGRESSIVEDECODER_H_ |
8 #define CORE_FXCODEC_CODEC_FX_CODEC_PROGRESS_H_ | 8 #define CORE_FXCODEC_CODEC_INCLUDE_CCODEC_PROGRESSIVEDECODER_H_ |
9 | 9 |
10 #include "core/fxcodec/include/fx_codec.h" | 10 #include "core/fxcodec/include/fx_codec_def.h" |
11 #include "core/fxcrt/include/fx_memory.h" | |
12 #include "core/fxcrt/include/fx_system.h" | 11 #include "core/fxcrt/include/fx_system.h" |
13 #include "core/fxge/include/fx_dib.h" | 12 #include "core/fxge/include/fx_dib.h" |
14 | 13 |
15 #define FXCODEC_BLOCK_SIZE 4096 | 14 class CCodec_BmpModule; |
16 #define FXCODEC_PNG_GAMMA 2.2 | 15 class CCodec_GifContext; |
| 16 class CCodec_GifModule; |
| 17 class CCodec_JpegModule; |
| 18 class CCodec_ModuleMgr; |
| 19 class CCodec_PngContext; |
| 20 class CCodec_TiffContext; |
| 21 class CFX_DIBAttribute; |
| 22 class IFX_FileRead; |
| 23 class IFX_Pause; |
| 24 struct FXBMP_Context; |
| 25 struct FXGIF_Context; |
| 26 struct FXJPEG_Context; |
| 27 struct FXPNG_Context; |
17 | 28 |
18 #if _FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_ | 29 class CCodec_ProgressiveDecoder { |
19 #undef FXCODEC_PNG_GAMMA | 30 public: |
20 #define FXCODEC_PNG_GAMMA 1.7 | 31 enum FXCodec_Format { |
21 #endif | 32 FXCodec_Invalid = 0, |
| 33 FXCodec_1bppGray = 0x101, |
| 34 FXCodec_1bppRgb = 0x001, |
| 35 FXCodec_8bppGray = 0x108, |
| 36 FXCodec_8bppRgb = 0x008, |
| 37 FXCodec_Rgb = 0x018, |
| 38 FXCodec_Rgb32 = 0x020, |
| 39 FXCodec_Argb = 0x220, |
| 40 FXCodec_Cmyk = 0x120 |
| 41 }; |
22 | 42 |
23 struct PixelWeight { | |
24 int m_SrcStart; | |
25 int m_SrcEnd; | |
26 int m_Weights[1]; | |
27 }; | |
28 | |
29 class CFXCODEC_WeightTable { | |
30 public: | |
31 CFXCODEC_WeightTable() { m_pWeightTables = NULL; } | |
32 ~CFXCODEC_WeightTable() { FX_Free(m_pWeightTables); } | |
33 | |
34 void Calc(int dest_len, | |
35 int dest_min, | |
36 int dest_max, | |
37 int src_len, | |
38 int src_min, | |
39 int src_max, | |
40 FX_BOOL bInterpol); | |
41 PixelWeight* GetPixelWeight(int pixel) { | |
42 return (PixelWeight*)(m_pWeightTables + (pixel - m_DestMin) * m_ItemSize); | |
43 } | |
44 | |
45 int m_DestMin, m_ItemSize; | |
46 uint8_t* m_pWeightTables; | |
47 }; | |
48 class CFXCODEC_HorzTable { | |
49 public: | |
50 CFXCODEC_HorzTable() { m_pWeightTables = NULL; } | |
51 ~CFXCODEC_HorzTable() { FX_Free(m_pWeightTables); } | |
52 | |
53 void Calc(int dest_len, int src_len, FX_BOOL bInterpol); | |
54 PixelWeight* GetPixelWeight(int pixel) { | |
55 return (PixelWeight*)(m_pWeightTables + pixel * m_ItemSize); | |
56 } | |
57 | |
58 int m_ItemSize; | |
59 uint8_t* m_pWeightTables; | |
60 }; | |
61 class CFXCODEC_VertTable { | |
62 public: | |
63 CFXCODEC_VertTable() { m_pWeightTables = NULL; } | |
64 ~CFXCODEC_VertTable() { FX_Free(m_pWeightTables); } | |
65 void Calc(int dest_len, int src_len); | |
66 PixelWeight* GetPixelWeight(int pixel) { | |
67 return (PixelWeight*)(m_pWeightTables + pixel * m_ItemSize); | |
68 } | |
69 int m_ItemSize; | |
70 uint8_t* m_pWeightTables; | |
71 }; | |
72 enum FXCodec_Format { | |
73 FXCodec_Invalid = 0, | |
74 FXCodec_1bppGray = 0x101, | |
75 FXCodec_1bppRgb = 0x001, | |
76 FXCodec_8bppGray = 0x108, | |
77 FXCodec_8bppRgb = 0x008, | |
78 FXCodec_Rgb = 0x018, | |
79 FXCodec_Rgb32 = 0x020, | |
80 FXCodec_Argb = 0x220, | |
81 FXCodec_Cmyk = 0x120 | |
82 }; | |
83 class CCodec_ProgressiveDecoder : public ICodec_ProgressiveDecoder { | |
84 public: | |
85 CCodec_ProgressiveDecoder(CCodec_ModuleMgr* pCodecMgr); | 43 CCodec_ProgressiveDecoder(CCodec_ModuleMgr* pCodecMgr); |
86 ~CCodec_ProgressiveDecoder() override; | 44 ~CCodec_ProgressiveDecoder(); |
87 | 45 |
88 FXCODEC_STATUS LoadImageInfo(IFX_FileRead* pFile, | 46 FXCODEC_STATUS LoadImageInfo(IFX_FileRead* pFile, |
89 FXCODEC_IMAGE_TYPE imageType, | 47 FXCODEC_IMAGE_TYPE imageType, |
90 CFX_DIBAttribute* pAttribute) override; | 48 CFX_DIBAttribute* pAttribute); |
91 | 49 |
92 FXCODEC_IMAGE_TYPE GetType() const override { return m_imagType; } | 50 FXCODEC_IMAGE_TYPE GetType() const { return m_imagType; } |
93 int32_t GetWidth() const override { return m_SrcWidth; } | 51 int32_t GetWidth() const { return m_SrcWidth; } |
94 int32_t GetHeight() const override { return m_SrcHeight; } | 52 int32_t GetHeight() const { return m_SrcHeight; } |
95 int32_t GetNumComponents() const override { return m_SrcComponents; } | 53 int32_t GetNumComponents() const { return m_SrcComponents; } |
96 int32_t GetBPC() const override { return m_SrcBPC; } | 54 int32_t GetBPC() const { return m_SrcBPC; } |
97 void SetClipBox(FX_RECT* clip) override; | 55 void SetClipBox(FX_RECT* clip); |
98 | 56 |
99 FXCODEC_STATUS GetFrames(int32_t& frames, IFX_Pause* pPause) override; | 57 FXCODEC_STATUS GetFrames(int32_t& frames, IFX_Pause* pPause = nullptr); |
100 FXCODEC_STATUS StartDecode(CFX_DIBitmap* pDIBitmap, | 58 FXCODEC_STATUS StartDecode(CFX_DIBitmap* pDIBitmap, |
101 int start_x, | 59 int start_x, |
102 int start_y, | 60 int start_y, |
103 int size_x, | 61 int size_x, |
104 int size_y, | 62 int size_y, |
105 int32_t frames, | 63 int32_t frames = 0, |
106 FX_BOOL bInterpol) override; | 64 FX_BOOL bInterpol = TRUE); |
107 | 65 |
108 FXCODEC_STATUS ContinueDecode(IFX_Pause* pPause) override; | 66 FXCODEC_STATUS ContinueDecode(IFX_Pause* pPause = nullptr); |
| 67 |
| 68 struct PixelWeight { |
| 69 int m_SrcStart; |
| 70 int m_SrcEnd; |
| 71 int m_Weights[1]; |
| 72 }; |
| 73 |
| 74 class CFXCODEC_WeightTable { |
| 75 public: |
| 76 CFXCODEC_WeightTable() { m_pWeightTables = NULL; } |
| 77 ~CFXCODEC_WeightTable() { FX_Free(m_pWeightTables); } |
| 78 |
| 79 void Calc(int dest_len, |
| 80 int dest_min, |
| 81 int dest_max, |
| 82 int src_len, |
| 83 int src_min, |
| 84 int src_max, |
| 85 FX_BOOL bInterpol); |
| 86 PixelWeight* GetPixelWeight(int pixel) { |
| 87 return (PixelWeight*)(m_pWeightTables + (pixel - m_DestMin) * m_ItemSize); |
| 88 } |
| 89 |
| 90 int m_DestMin, m_ItemSize; |
| 91 uint8_t* m_pWeightTables; |
| 92 }; |
| 93 |
| 94 class CFXCODEC_HorzTable { |
| 95 public: |
| 96 CFXCODEC_HorzTable() { m_pWeightTables = NULL; } |
| 97 ~CFXCODEC_HorzTable() { FX_Free(m_pWeightTables); } |
| 98 |
| 99 void Calc(int dest_len, int src_len, FX_BOOL bInterpol); |
| 100 PixelWeight* GetPixelWeight(int pixel) { |
| 101 return (PixelWeight*)(m_pWeightTables + pixel * m_ItemSize); |
| 102 } |
| 103 |
| 104 int m_ItemSize; |
| 105 uint8_t* m_pWeightTables; |
| 106 }; |
| 107 |
| 108 class CFXCODEC_VertTable { |
| 109 public: |
| 110 CFXCODEC_VertTable() { m_pWeightTables = NULL; } |
| 111 ~CFXCODEC_VertTable() { FX_Free(m_pWeightTables); } |
| 112 void Calc(int dest_len, int src_len); |
| 113 PixelWeight* GetPixelWeight(int pixel) { |
| 114 return (PixelWeight*)(m_pWeightTables + pixel * m_ItemSize); |
| 115 } |
| 116 int m_ItemSize; |
| 117 uint8_t* m_pWeightTables; |
| 118 }; |
| 119 |
| 120 IFX_FileRead* m_pFile; |
| 121 CCodec_ModuleMgr* m_pCodecMgr; |
| 122 FXJPEG_Context* m_pJpegContext; |
| 123 FXPNG_Context* m_pPngContext; |
| 124 FXGIF_Context* m_pGifContext; |
| 125 FXBMP_Context* m_pBmpContext; |
| 126 CCodec_TiffContext* m_pTiffContext; |
| 127 FXCODEC_IMAGE_TYPE m_imagType; |
| 128 uint32_t m_offSet; |
| 129 uint8_t* m_pSrcBuf; |
| 130 uint32_t m_SrcSize; |
| 131 uint8_t* m_pDecodeBuf; |
| 132 int m_ScanlineSize; |
| 133 CFX_DIBitmap* m_pDeviceBitmap; |
| 134 FX_BOOL m_bInterpol; |
| 135 CFXCODEC_WeightTable m_WeightHorz; |
| 136 CFXCODEC_VertTable m_WeightVert; |
| 137 CFXCODEC_HorzTable m_WeightHorzOO; |
| 138 int m_SrcWidth; |
| 139 int m_SrcHeight; |
| 140 int m_SrcComponents; |
| 141 int m_SrcBPC; |
| 142 FX_RECT m_clipBox; |
| 143 int m_startX; |
| 144 int m_startY; |
| 145 int m_sizeX; |
| 146 int m_sizeY; |
| 147 int m_TransMethod; |
| 148 FX_ARGB* m_pSrcPalette; |
| 149 int m_SrcPaletteNumber; |
| 150 int m_SrcRow; |
| 151 FXCodec_Format m_SrcFormat; |
| 152 int m_SrcPassNumber; |
| 153 int m_FrameNumber; |
| 154 int m_FrameCur; |
| 155 int m_GifBgIndex; |
| 156 uint8_t* m_pGifPalette; |
| 157 int32_t m_GifPltNumber; |
| 158 int m_GifTransIndex; |
| 159 FX_RECT m_GifFrameRect; |
| 160 FX_BOOL m_BmpIsTopBottom; |
| 161 FXCODEC_STATUS m_status; |
109 | 162 |
110 protected: | 163 protected: |
111 static FX_BOOL PngReadHeaderFunc(void* pModule, | 164 static FX_BOOL PngReadHeaderFunc(void* pModule, |
112 int width, | 165 int width, |
113 int height, | 166 int height, |
114 int bpc, | 167 int bpc, |
115 int pass, | 168 int pass, |
116 int* color_type, | 169 int* color_type, |
117 double* gamma); | 170 double* gamma); |
118 static FX_BOOL PngAskScanlineBufFunc(void* pModule, | 171 static FX_BOOL PngAskScanlineBufFunc(void* pModule, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void GetTransMethod(FXDIB_Format des_format, FXCodec_Format src_format); | 204 void GetTransMethod(FXDIB_Format des_format, FXCodec_Format src_format); |
152 void ReSampleScanline(CFX_DIBitmap* pDeviceBitmap, | 205 void ReSampleScanline(CFX_DIBitmap* pDeviceBitmap, |
153 int32_t des_line, | 206 int32_t des_line, |
154 uint8_t* src_scan, | 207 uint8_t* src_scan, |
155 FXCodec_Format src_format); | 208 FXCodec_Format src_format); |
156 void Resample(CFX_DIBitmap* pDeviceBitmap, | 209 void Resample(CFX_DIBitmap* pDeviceBitmap, |
157 int32_t src_line, | 210 int32_t src_line, |
158 uint8_t* src_scan, | 211 uint8_t* src_scan, |
159 FXCodec_Format src_format); | 212 FXCodec_Format src_format); |
160 void ResampleVert(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row); | 213 void ResampleVert(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row); |
161 FX_BOOL JpegReadMoreData(ICodec_JpegModule* pJpegModule, | 214 FX_BOOL JpegReadMoreData(CCodec_JpegModule* pJpegModule, |
162 FXCODEC_STATUS& err_status); | 215 FXCODEC_STATUS& err_status); |
163 void PngOneOneMapResampleHorz(CFX_DIBitmap* pDeviceBitmap, | 216 void PngOneOneMapResampleHorz(CFX_DIBitmap* pDeviceBitmap, |
164 int32_t des_line, | 217 int32_t des_line, |
165 uint8_t* src_scan, | 218 uint8_t* src_scan, |
166 FXCodec_Format src_format); | 219 FXCodec_Format src_format); |
167 FX_BOOL GifReadMoreData(ICodec_GifModule* pGifModule, | 220 FX_BOOL GifReadMoreData(CCodec_GifModule* pGifModule, |
168 FXCODEC_STATUS& err_status); | 221 FXCODEC_STATUS& err_status); |
169 void GifDoubleLineResampleVert(CFX_DIBitmap* pDeviceBitmap, | 222 void GifDoubleLineResampleVert(CFX_DIBitmap* pDeviceBitmap, |
170 double scale_y, | 223 double scale_y, |
171 int des_row); | 224 int des_row); |
172 FX_BOOL BmpReadMoreData(ICodec_BmpModule* pBmpModule, | 225 FX_BOOL BmpReadMoreData(CCodec_BmpModule* pBmpModule, |
173 FXCODEC_STATUS& err_status); | 226 FXCODEC_STATUS& err_status); |
174 void ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row); | 227 void ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row); |
175 | |
176 public: | |
177 IFX_FileRead* m_pFile; | |
178 CCodec_ModuleMgr* m_pCodecMgr; | |
179 void* m_pJpegContext; | |
180 void* m_pPngContext; | |
181 void* m_pGifContext; | |
182 void* m_pBmpContext; | |
183 void* m_pTiffContext; | |
184 FXCODEC_IMAGE_TYPE m_imagType; | |
185 uint32_t m_offSet; | |
186 uint8_t* m_pSrcBuf; | |
187 uint32_t m_SrcSize; | |
188 uint8_t* m_pDecodeBuf; | |
189 int m_ScanlineSize; | |
190 CFX_DIBitmap* m_pDeviceBitmap; | |
191 FX_BOOL m_bInterpol; | |
192 CFXCODEC_WeightTable m_WeightHorz; | |
193 CFXCODEC_VertTable m_WeightVert; | |
194 CFXCODEC_HorzTable m_WeightHorzOO; | |
195 int m_SrcWidth; | |
196 int m_SrcHeight; | |
197 int m_SrcComponents; | |
198 int m_SrcBPC; | |
199 FX_RECT m_clipBox; | |
200 int m_startX; | |
201 int m_startY; | |
202 int m_sizeX; | |
203 int m_sizeY; | |
204 int m_TransMethod; | |
205 FX_ARGB* m_pSrcPalette; | |
206 int m_SrcPaletteNumber; | |
207 int m_SrcRow; | |
208 FXCodec_Format m_SrcFormat; | |
209 int m_SrcPassNumber; | |
210 int m_FrameNumber; | |
211 int m_FrameCur; | |
212 int m_GifBgIndex; | |
213 uint8_t* m_pGifPalette; | |
214 int32_t m_GifPltNumber; | |
215 int m_GifTransIndex; | |
216 FX_RECT m_GifFrameRect; | |
217 FX_BOOL m_BmpIsTopBottom; | |
218 FXCODEC_STATUS m_status; | |
219 }; | 228 }; |
220 | 229 |
221 #endif // CORE_FXCODEC_CODEC_FX_CODEC_PROGRESS_H_ | 230 #endif // CORE_FXCODEC_CODEC_INCLUDE_CCODEC_PROGRESSIVEDECODER_H_ |
OLD | NEW |