xref: /aosp_15_r20/external/pdfium/core/fxcodec/jpeg/jpeg_progressive_decoder.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2020 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_JPEG_JPEG_PROGRESSIVE_DECODER_H_
8 #define CORE_FXCODEC_JPEG_JPEG_PROGRESSIVE_DECODER_H_
9 
10 #include <setjmp.h>
11 
12 #include <memory>
13 
14 #include "core/fxcodec/progressive_decoder_iface.h"
15 #include "third_party/base/no_destructor.h"
16 
17 namespace fxcodec {
18 
19 class CFX_DIBAttribute;
20 
21 class JpegProgressiveDecoder final : public ProgressiveDecoderIface {
22  public:
23   static JpegProgressiveDecoder* GetInstance();
24 
25   static std::unique_ptr<Context> Start();
26 
27   static jmp_buf& GetJumpMark(Context* pContext);
28 
29   static int ReadHeader(Context* pContext,
30                         int* width,
31                         int* height,
32                         int* nComps,
33                         CFX_DIBAttribute* pAttribute);
34 
35   static bool StartScanline(Context* pContext, int down_scale);
36   static bool ReadScanline(Context* pContext, uint8_t* dest_buf);
37 
38   // ProgressiveDecoderIface:
39   FX_FILESIZE GetAvailInput(Context* pContext) const override;
40   bool Input(Context* pContext,
41              RetainPtr<CFX_CodecMemory> codec_memory) override;
42 
43  private:
44   friend pdfium::base::NoDestructor<JpegProgressiveDecoder>;
45 
46   JpegProgressiveDecoder();
47   ~JpegProgressiveDecoder() override;
48 };
49 
50 }  // namespace fxcodec
51 
52 using JpegProgressiveDecoder = fxcodec::JpegProgressiveDecoder;
53 
54 #endif  // CORE_FXCODEC_JPEG_JPEG_PROGRESSIVE_DECODER_H_
55