1 // Copyright 2017 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_GIF_CFX_GIFCONTEXT_H_ 8 #define CORE_FXCODEC_GIF_CFX_GIFCONTEXT_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxcodec/gif/cfx_gif.h" 14 #include "core/fxcodec/gif/cfx_lzwdecompressor.h" 15 #include "core/fxcodec/gif/gifmodule.h" 16 #include "core/fxcrt/fx_string.h" 17 #include "core/fxcrt/unowned_ptr.h" 18 19 class CFX_CodecMemory; 20 21 namespace fxcodec { 22 23 class CFX_GifContext : public ModuleIface::Context { 24 public: 25 CFX_GifContext(GifModule* gif_module, GifModule::Delegate* delegate); 26 ~CFX_GifContext() override; 27 28 void RecordCurrentPosition(uint32_t* cur_pos); 29 void ReadScanline(int32_t row_num, uint8_t* row_buf); 30 bool GetRecordPosition(uint32_t cur_pos, 31 int32_t left, 32 int32_t top, 33 int32_t width, 34 int32_t height, 35 int32_t pal_num, 36 CFX_GifPalette* pal, 37 int32_t delay_time, 38 bool user_input, 39 int32_t trans_index, 40 int32_t disposal_method, 41 bool interlace); 42 CFX_GifDecodeStatus ReadHeader(); 43 CFX_GifDecodeStatus GetFrame(); 44 CFX_GifDecodeStatus LoadFrame(int32_t frame_num); 45 void SetInputBuffer(RetainPtr<CFX_CodecMemory> codec_memory); 46 uint32_t GetAvailInput() const; GetFrameNum()47 size_t GetFrameNum() const { return images_.size(); } 48 49 UnownedPtr<GifModule> const gif_module_; 50 UnownedPtr<GifModule::Delegate> const delegate_; 51 std::vector<CFX_GifPalette> global_palette_; 52 uint8_t global_pal_exp_ = 0; 53 uint32_t img_row_offset_ = 0; 54 uint32_t img_row_avail_size_ = 0; 55 int32_t decode_status_ = GIF_D_STATUS_SIG; 56 std::unique_ptr<CFX_GifGraphicControlExtension> graphic_control_extension_; 57 std::vector<std::unique_ptr<CFX_GifImage>> images_; 58 std::unique_ptr<CFX_LZWDecompressor> lzw_decompressor_; 59 int width_ = 0; 60 int height_ = 0; 61 uint8_t bc_index_ = 0; 62 uint8_t global_sort_flag_ = 0; 63 uint8_t global_color_resolution_ = 0; 64 uint8_t img_pass_num_ = 0; 65 66 protected: 67 bool ReadAllOrNone(uint8_t* dest, uint32_t size); 68 CFX_GifDecodeStatus ReadGifSignature(); 69 CFX_GifDecodeStatus ReadLogicalScreenDescriptor(); 70 71 RetainPtr<CFX_CodecMemory> input_buffer_; 72 73 private: 74 void SaveDecodingStatus(int32_t status); 75 CFX_GifDecodeStatus DecodeExtension(); 76 CFX_GifDecodeStatus DecodeImageInfo(); 77 void DecodingFailureAtTailCleanup(CFX_GifImage* gif_image); 78 bool ScanForTerminalMarker(); 79 }; 80 81 } // namespace fxcodec 82 83 #endif // CORE_FXCODEC_GIF_CFX_GIFCONTEXT_H_ 84