xref: /aosp_15_r20/external/pdfium/core/fxcodec/png/png_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_PNG_PNG_DECODER_H_
8 #define CORE_FXCODEC_PNG_PNG_DECODER_H_
9 
10 #include <memory>
11 
12 #include "core/fxcodec/progressive_decoder_iface.h"
13 #include "core/fxcrt/retain_ptr.h"
14 
15 #ifndef PDF_ENABLE_XFA_PNG
16 #error "PNG must be enabled"
17 #endif
18 
19 namespace fxcodec {
20 
21 class CFX_DIBAttribute;
22 
23 class PngDecoder {
24  public:
25   class Delegate {
26    public:
27     virtual bool PngReadHeader(int width,
28                                int height,
29                                int bpc,
30                                int pass,
31                                int* color_type,
32                                double* gamma) = 0;
33 
34     // Returns true on success. |pSrcBuf| will be set if this succeeds.
35     // |pSrcBuf| does not take ownership of the buffer.
36     virtual bool PngAskScanlineBuf(int line, uint8_t** pSrcBuf) = 0;
37 
38     virtual void PngFillScanlineBufCompleted(int pass, int line) = 0;
39   };
40 
41   static std::unique_ptr<ProgressiveDecoderIface::Context> StartDecode(
42       Delegate* pDelegate);
43 
44   static bool ContinueDecode(ProgressiveDecoderIface::Context* pContext,
45                              RetainPtr<CFX_CodecMemory> codec_memory,
46                              CFX_DIBAttribute* pAttribute);
47 
48   PngDecoder() = delete;
49   PngDecoder(const PngDecoder&) = delete;
50   PngDecoder& operator=(const PngDecoder&) = delete;
51 };
52 
53 }  // namespace fxcodec
54 
55 using PngDecoder = fxcodec::PngDecoder;
56 
57 #endif  // CORE_FXCODEC_PNG_PNG_DECODER_H_
58