• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
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_JPEGMODULE_H_
8 #define CORE_FXCODEC_JPEG_JPEGMODULE_H_
9 
10 #include <csetjmp>
11 #include <memory>
12 
13 #include "build/build_config.h"
14 #include "core/fxcodec/codec_module_iface.h"
15 #include "third_party/base/optional.h"
16 #include "third_party/base/span.h"
17 
18 class CFX_DIBBase;
19 
20 namespace fxcodec {
21 
22 class CFX_DIBAttribute;
23 class ScanlineDecoder;
24 
25 class JpegModule final : public ModuleIface {
26  public:
27   struct JpegImageInfo {
28     int width;
29     int height;
30     int num_components;
31     int bits_per_components;
32     bool color_transform;
33   };
34 
35   std::unique_ptr<ScanlineDecoder> CreateDecoder(
36       pdfium::span<const uint8_t> src_span,
37       int width,
38       int height,
39       int nComps,
40       bool ColorTransform);
41 
42   // ModuleIface:
43   FX_FILESIZE GetAvailInput(Context* pContext) const override;
44   bool Input(Context* pContext,
45              RetainPtr<CFX_CodecMemory> codec_memory,
46              CFX_DIBAttribute* pAttribute) override;
47 
48   jmp_buf& GetJumpMark(Context* pContext);
49   Optional<JpegImageInfo> LoadInfo(pdfium::span<const uint8_t> src_span);
50 
51   std::unique_ptr<Context> Start();
52 
53 #ifdef PDF_ENABLE_XFA
54   int ReadHeader(Context* pContext,
55                  int* width,
56                  int* height,
57                  int* nComps,
58                  CFX_DIBAttribute* pAttribute);
59 #endif  // PDF_ENABLE_XFA
60 
61   bool StartScanline(Context* pContext, int down_scale);
62   bool ReadScanline(Context* pContext, uint8_t* dest_buf);
63 
64 #if defined(OS_WIN)
65   static bool JpegEncode(const RetainPtr<CFX_DIBBase>& pSource,
66                          uint8_t** dest_buf,
67                          size_t* dest_size);
68 #endif  // defined(OS_WIN)
69 };
70 
71 }  // namespace fxcodec
72 
73 using JpegModule = fxcodec::JpegModule;
74 
75 #endif  // CORE_FXCODEC_JPEG_JPEGMODULE_H_
76