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 // `line` must be within [0, height]. 35 virtual uint8_t* PngAskScanlineBuf(int line) = 0; 36 37 virtual void PngFillScanlineBufCompleted(int pass, int line) = 0; 38 }; 39 40 static std::unique_ptr<ProgressiveDecoderIface::Context> StartDecode( 41 Delegate* pDelegate); 42 43 static bool ContinueDecode(ProgressiveDecoderIface::Context* pContext, 44 RetainPtr<CFX_CodecMemory> codec_memory, 45 CFX_DIBAttribute* pAttribute); 46 47 PngDecoder() = delete; 48 PngDecoder(const PngDecoder&) = delete; 49 PngDecoder& operator=(const PngDecoder&) = delete; 50 }; 51 52 } // namespace fxcodec 53 54 using PngDecoder = fxcodec::PngDecoder; 55 56 #endif // CORE_FXCODEC_PNG_PNG_DECODER_H_ 57