• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/codec/ccodec_gifmodule.h"
14 #include "core/fxcodec/gif/cfx_gif.h"
15 #include "core/fxcodec/gif/cfx_lzwdecompressor.h"
16 #include "core/fxcrt/fx_string.h"
17 #include "core/fxcrt/unowned_ptr.h"
18 
19 class CFX_GifContext : public CCodec_GifModule::Context {
20  public:
21   CFX_GifContext(CCodec_GifModule* gif_module,
22                  CCodec_GifModule::Delegate* delegate);
23   ~CFX_GifContext() override;
24 
25   void RecordCurrentPosition(uint32_t* cur_pos);
26   void ReadScanline(int32_t row_num, uint8_t* row_buf);
27   bool GetRecordPosition(uint32_t cur_pos,
28                          int32_t left,
29                          int32_t top,
30                          int32_t width,
31                          int32_t height,
32                          int32_t pal_num,
33                          CFX_GifPalette* pal,
34                          int32_t delay_time,
35                          bool user_input,
36                          int32_t trans_index,
37                          int32_t disposal_method,
38                          bool interlace);
39   CFX_GifDecodeStatus ReadHeader();
40   CFX_GifDecodeStatus GetFrame();
41   CFX_GifDecodeStatus LoadFrame(int32_t frame_num);
42   void SetInputBuffer(uint8_t* src_buf, uint32_t src_size);
43   uint32_t GetAvailInput(uint8_t** avail_buf) const;
GetFrameNum()44   size_t GetFrameNum() const { return images_.size(); }
45 
46   UnownedPtr<CCodec_GifModule> gif_module_;
47   UnownedPtr<CCodec_GifModule::Delegate> delegate_;
48   std::vector<CFX_GifPalette> global_palette_;
49   uint8_t global_pal_exp_;
50   uint32_t img_row_offset_;
51   uint32_t img_row_avail_size_;
52   uint32_t avail_in_;
53   int32_t decode_status_;
54   uint32_t skip_size_;
55   ByteString cmt_data_;
56   std::unique_ptr<CFX_GifGraphicControlExtension> graphic_control_extension_;
57   uint8_t* next_in_;
58   std::vector<std::unique_ptr<CFX_GifImage>> images_;
59   std::unique_ptr<CFX_LZWDecompressor> lzw_decompressor_;
60   int width_;
61   int height_;
62   uint8_t bc_index_;
63   uint8_t pixel_aspect_;
64   uint8_t global_sort_flag_;
65   uint8_t global_color_resolution_;
66   uint8_t img_pass_num_;
67 
68  protected:
69   uint8_t* ReadData(uint8_t** des_buf_pp, uint32_t data_size);
70   CFX_GifDecodeStatus ReadGifSignature();
71   CFX_GifDecodeStatus ReadLogicalScreenDescriptor();
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 };
79 
80 #endif  // CORE_FXCODEC_GIF_CFX_GIFCONTEXT_H_
81