• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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_GIF_DECODER_H_
8 #define CORE_FXCODEC_GIF_GIF_DECODER_H_
9 
10 #include <memory>
11 #include <utility>
12 
13 #include "core/fxcodec/gif/cfx_gif.h"
14 #include "core/fxcodec/progressive_decoder_iface.h"
15 #include "core/fxcrt/fx_coordinates.h"
16 #include "core/fxcrt/span.h"
17 
18 #ifndef PDF_ENABLE_XFA_GIF
19 #error "GIF must be enabled"
20 #endif
21 
22 namespace fxcodec {
23 
24 class GifDecoder {
25  public:
26   enum class Status {
27     kError,
28     kSuccess,
29     kUnfinished,
30   };
31 
32   class Delegate {
33    public:
34     virtual uint32_t GifCurrentPosition() const = 0;
35     virtual bool GifInputRecordPositionBuf(uint32_t rcd_pos,
36                                            const FX_RECT& img_rc,
37                                            pdfium::span<CFX_GifPalette> pal_ptr,
38                                            int32_t trans_index,
39                                            bool interlace) = 0;
40     virtual void GifReadScanline(int32_t row_num,
41                                  pdfium::span<uint8_t> row_buf) = 0;
42   };
43 
44   static std::unique_ptr<ProgressiveDecoderIface::Context> StartDecode(
45       Delegate* pDelegate);
46   static Status ReadHeader(ProgressiveDecoderIface::Context* context,
47                            int* width,
48                            int* height,
49                            pdfium::span<CFX_GifPalette>* pal_pp,
50                            int* bg_index);
51   static std::pair<Status, size_t> LoadFrameInfo(
52       ProgressiveDecoderIface::Context* context);
53   static Status LoadFrame(ProgressiveDecoderIface::Context* context,
54                           size_t frame_num);
55   static FX_FILESIZE GetAvailInput(ProgressiveDecoderIface::Context* context);
56   static bool Input(ProgressiveDecoderIface::Context* context,
57                     RetainPtr<CFX_CodecMemory> codec_memory);
58 
59   GifDecoder() = delete;
60   GifDecoder(const GifDecoder&) = delete;
61   GifDecoder& operator=(const GifDecoder&) = delete;
62 };
63 
64 }  // namespace fxcodec
65 
66 using GifDecoder = fxcodec::GifDecoder;
67 
68 #endif  // CORE_FXCODEC_GIF_GIF_DECODER_H_
69