xref: /aosp_15_r20/external/pdfium/core/fxcodec/gif/gif_decoder.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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 "third_party/base/containers/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                                            int32_t pal_num,
38                                            CFX_GifPalette* pal_ptr,
39                                            int32_t trans_index,
40                                            bool interlace) = 0;
41     virtual void GifReadScanline(int32_t row_num,
42                                  pdfium::span<uint8_t> row_buf) = 0;
43   };
44 
45   static std::unique_ptr<ProgressiveDecoderIface::Context> StartDecode(
46       Delegate* pDelegate);
47   static Status ReadHeader(ProgressiveDecoderIface::Context* context,
48                            int* width,
49                            int* height,
50                            int* pal_num,
51                            CFX_GifPalette** pal_pp,
52                            int* bg_index);
53   static std::pair<Status, size_t> LoadFrameInfo(
54       ProgressiveDecoderIface::Context* context);
55   static Status LoadFrame(ProgressiveDecoderIface::Context* context,
56                           size_t frame_num);
57   static FX_FILESIZE GetAvailInput(ProgressiveDecoderIface::Context* context);
58   static bool Input(ProgressiveDecoderIface::Context* context,
59                     RetainPtr<CFX_CodecMemory> codec_memory);
60 
61   GifDecoder() = delete;
62   GifDecoder(const GifDecoder&) = delete;
63   GifDecoder& operator=(const GifDecoder&) = delete;
64 };
65 
66 }  // namespace fxcodec
67 
68 using GifDecoder = fxcodec::GifDecoder;
69 
70 #endif  // CORE_FXCODEC_GIF_GIF_DECODER_H_
71