| OLD | NEW |
| (Empty) |
| 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_FXCODEC_CODEC_INCLUDE_CCODEC_PROGRESSIVEDECODER_H_ | |
| 8 #define CORE_FXCODEC_CODEC_INCLUDE_CCODEC_PROGRESSIVEDECODER_H_ | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "core/fxcodec/include/fx_codec_def.h" | |
| 13 #include "core/fxcrt/include/fx_system.h" | |
| 14 #include "core/fxge/include/fx_dib.h" | |
| 15 | |
| 16 class CCodec_BmpModule; | |
| 17 class CCodec_GifContext; | |
| 18 class CCodec_GifModule; | |
| 19 class CCodec_JpegModule; | |
| 20 class CCodec_ModuleMgr; | |
| 21 class CCodec_PngContext; | |
| 22 class CCodec_TiffContext; | |
| 23 class CFX_DIBAttribute; | |
| 24 class IFX_FileRead; | |
| 25 class IFX_Pause; | |
| 26 struct FXBMP_Context; | |
| 27 struct FXGIF_Context; | |
| 28 struct FXJPEG_Context; | |
| 29 struct FXPNG_Context; | |
| 30 | |
| 31 class CCodec_ProgressiveDecoder { | |
| 32 public: | |
| 33 enum FXCodec_Format { | |
| 34 FXCodec_Invalid = 0, | |
| 35 FXCodec_1bppGray = 0x101, | |
| 36 FXCodec_1bppRgb = 0x001, | |
| 37 FXCodec_8bppGray = 0x108, | |
| 38 FXCodec_8bppRgb = 0x008, | |
| 39 FXCodec_Rgb = 0x018, | |
| 40 FXCodec_Rgb32 = 0x020, | |
| 41 FXCodec_Argb = 0x220, | |
| 42 FXCodec_Cmyk = 0x120 | |
| 43 }; | |
| 44 | |
| 45 explicit CCodec_ProgressiveDecoder(CCodec_ModuleMgr* pCodecMgr); | |
| 46 ~CCodec_ProgressiveDecoder(); | |
| 47 | |
| 48 FXCODEC_STATUS LoadImageInfo(IFX_FileRead* pFile, | |
| 49 FXCODEC_IMAGE_TYPE imageType, | |
| 50 CFX_DIBAttribute* pAttribute, | |
| 51 bool bSkipImageTypeCheck); | |
| 52 | |
| 53 FXCODEC_IMAGE_TYPE GetType() const { return m_imagType; } | |
| 54 int32_t GetWidth() const { return m_SrcWidth; } | |
| 55 int32_t GetHeight() const { return m_SrcHeight; } | |
| 56 int32_t GetNumComponents() const { return m_SrcComponents; } | |
| 57 int32_t GetBPC() const { return m_SrcBPC; } | |
| 58 void SetClipBox(FX_RECT* clip); | |
| 59 | |
| 60 FXCODEC_STATUS GetFrames(int32_t& frames, IFX_Pause* pPause = nullptr); | |
| 61 FXCODEC_STATUS StartDecode(CFX_DIBitmap* pDIBitmap, | |
| 62 int start_x, | |
| 63 int start_y, | |
| 64 int size_x, | |
| 65 int size_y, | |
| 66 int32_t frames = 0, | |
| 67 FX_BOOL bInterpol = TRUE); | |
| 68 | |
| 69 FXCODEC_STATUS ContinueDecode(IFX_Pause* pPause = nullptr); | |
| 70 | |
| 71 struct PixelWeight { | |
| 72 int m_SrcStart; | |
| 73 int m_SrcEnd; | |
| 74 int m_Weights[1]; | |
| 75 }; | |
| 76 | |
| 77 class CFXCODEC_WeightTable { | |
| 78 public: | |
| 79 CFXCODEC_WeightTable(); | |
| 80 ~CFXCODEC_WeightTable(); | |
| 81 | |
| 82 void Calc(int dest_len, | |
| 83 int dest_min, | |
| 84 int dest_max, | |
| 85 int src_len, | |
| 86 int src_min, | |
| 87 int src_max, | |
| 88 FX_BOOL bInterpol); | |
| 89 PixelWeight* GetPixelWeight(int pixel) { | |
| 90 return reinterpret_cast<PixelWeight*>(m_pWeightTables.data() + | |
| 91 (pixel - m_DestMin) * m_ItemSize); | |
| 92 } | |
| 93 | |
| 94 int m_DestMin; | |
| 95 int m_ItemSize; | |
| 96 std::vector<uint8_t> m_pWeightTables; | |
| 97 }; | |
| 98 | |
| 99 class CFXCODEC_HorzTable { | |
| 100 public: | |
| 101 CFXCODEC_HorzTable(); | |
| 102 ~CFXCODEC_HorzTable(); | |
| 103 | |
| 104 void Calc(int dest_len, int src_len, FX_BOOL bInterpol); | |
| 105 PixelWeight* GetPixelWeight(int pixel) { | |
| 106 return reinterpret_cast<PixelWeight*>(m_pWeightTables.data() + | |
| 107 pixel * m_ItemSize); | |
| 108 } | |
| 109 | |
| 110 int m_ItemSize; | |
| 111 std::vector<uint8_t> m_pWeightTables; | |
| 112 }; | |
| 113 | |
| 114 class CFXCODEC_VertTable { | |
| 115 public: | |
| 116 CFXCODEC_VertTable(); | |
| 117 ~CFXCODEC_VertTable(); | |
| 118 | |
| 119 void Calc(int dest_len, int src_len); | |
| 120 PixelWeight* GetPixelWeight(int pixel) { | |
| 121 return reinterpret_cast<PixelWeight*>(m_pWeightTables.data() + | |
| 122 pixel * m_ItemSize); | |
| 123 } | |
| 124 int m_ItemSize; | |
| 125 std::vector<uint8_t> m_pWeightTables; | |
| 126 }; | |
| 127 | |
| 128 IFX_FileRead* m_pFile; | |
| 129 CCodec_ModuleMgr* m_pCodecMgr; | |
| 130 FXJPEG_Context* m_pJpegContext; | |
| 131 FXPNG_Context* m_pPngContext; | |
| 132 FXGIF_Context* m_pGifContext; | |
| 133 FXBMP_Context* m_pBmpContext; | |
| 134 CCodec_TiffContext* m_pTiffContext; | |
| 135 FXCODEC_IMAGE_TYPE m_imagType; | |
| 136 uint32_t m_offSet; | |
| 137 uint8_t* m_pSrcBuf; | |
| 138 uint32_t m_SrcSize; | |
| 139 uint8_t* m_pDecodeBuf; | |
| 140 int m_ScanlineSize; | |
| 141 CFX_DIBitmap* m_pDeviceBitmap; | |
| 142 FX_BOOL m_bInterpol; | |
| 143 CFXCODEC_WeightTable m_WeightHorz; | |
| 144 CFXCODEC_VertTable m_WeightVert; | |
| 145 CFXCODEC_HorzTable m_WeightHorzOO; | |
| 146 int m_SrcWidth; | |
| 147 int m_SrcHeight; | |
| 148 int m_SrcComponents; | |
| 149 int m_SrcBPC; | |
| 150 FX_RECT m_clipBox; | |
| 151 int m_startX; | |
| 152 int m_startY; | |
| 153 int m_sizeX; | |
| 154 int m_sizeY; | |
| 155 int m_TransMethod; | |
| 156 FX_ARGB* m_pSrcPalette; | |
| 157 int m_SrcPaletteNumber; | |
| 158 int m_SrcRow; | |
| 159 FXCodec_Format m_SrcFormat; | |
| 160 int m_SrcPassNumber; | |
| 161 int m_FrameNumber; | |
| 162 int m_FrameCur; | |
| 163 int m_GifBgIndex; | |
| 164 uint8_t* m_pGifPalette; | |
| 165 int32_t m_GifPltNumber; | |
| 166 int m_GifTransIndex; | |
| 167 FX_RECT m_GifFrameRect; | |
| 168 FX_BOOL m_BmpIsTopBottom; | |
| 169 FXCODEC_STATUS m_status; | |
| 170 | |
| 171 protected: | |
| 172 static FX_BOOL PngReadHeaderFunc(void* pModule, | |
| 173 int width, | |
| 174 int height, | |
| 175 int bpc, | |
| 176 int pass, | |
| 177 int* color_type, | |
| 178 double* gamma); | |
| 179 static FX_BOOL PngAskScanlineBufFunc(void* pModule, | |
| 180 int line, | |
| 181 uint8_t*& src_buf); | |
| 182 static void PngFillScanlineBufCompletedFunc(void* pModule, | |
| 183 int pass, | |
| 184 int line); | |
| 185 static void GifRecordCurrentPositionCallback(void* pModule, | |
| 186 uint32_t& cur_pos); | |
| 187 static uint8_t* GifAskLocalPaletteBufCallback(void* pModule, | |
| 188 int32_t frame_num, | |
| 189 int32_t pal_size); | |
| 190 static FX_BOOL GifInputRecordPositionBufCallback(void* pModule, | |
| 191 uint32_t rcd_pos, | |
| 192 const FX_RECT& img_rc, | |
| 193 int32_t pal_num, | |
| 194 void* pal_ptr, | |
| 195 int32_t delay_time, | |
| 196 FX_BOOL user_input, | |
| 197 int32_t trans_index, | |
| 198 int32_t disposal_method, | |
| 199 FX_BOOL interlace); | |
| 200 static void GifReadScanlineCallback(void* pModule, | |
| 201 int32_t row_num, | |
| 202 uint8_t* row_buf); | |
| 203 static FX_BOOL BmpInputImagePositionBufCallback(void* pModule, | |
| 204 uint32_t rcd_pos); | |
| 205 static void BmpReadScanlineCallback(void* pModule, | |
| 206 int32_t row_num, | |
| 207 uint8_t* row_buf); | |
| 208 | |
| 209 FX_BOOL DetectImageType(FXCODEC_IMAGE_TYPE imageType, | |
| 210 CFX_DIBAttribute* pAttribute); | |
| 211 void GetDownScale(int& down_scale); | |
| 212 void GetTransMethod(FXDIB_Format des_format, FXCodec_Format src_format); | |
| 213 void ReSampleScanline(CFX_DIBitmap* pDeviceBitmap, | |
| 214 int32_t des_line, | |
| 215 uint8_t* src_scan, | |
| 216 FXCodec_Format src_format); | |
| 217 void Resample(CFX_DIBitmap* pDeviceBitmap, | |
| 218 int32_t src_line, | |
| 219 uint8_t* src_scan, | |
| 220 FXCodec_Format src_format); | |
| 221 void ResampleVert(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row); | |
| 222 FX_BOOL JpegReadMoreData(CCodec_JpegModule* pJpegModule, | |
| 223 FXCODEC_STATUS& err_status); | |
| 224 void PngOneOneMapResampleHorz(CFX_DIBitmap* pDeviceBitmap, | |
| 225 int32_t des_line, | |
| 226 uint8_t* src_scan, | |
| 227 FXCodec_Format src_format); | |
| 228 FX_BOOL GifReadMoreData(CCodec_GifModule* pGifModule, | |
| 229 FXCODEC_STATUS& err_status); | |
| 230 void GifDoubleLineResampleVert(CFX_DIBitmap* pDeviceBitmap, | |
| 231 double scale_y, | |
| 232 int des_row); | |
| 233 FX_BOOL BmpReadMoreData(CCodec_BmpModule* pBmpModule, | |
| 234 FXCODEC_STATUS& err_status); | |
| 235 void ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row); | |
| 236 }; | |
| 237 | |
| 238 #endif // CORE_FXCODEC_CODEC_INCLUDE_CCODEC_PROGRESSIVEDECODER_H_ | |
| OLD | NEW |