Home | History | Annotate | Download | only in codec
      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_CODEC_CCODEC_JPEGMODULE_H_
      8 #define CORE_FXCODEC_CODEC_CCODEC_JPEGMODULE_H_
      9 
     10 #include <csetjmp>
     11 #include <memory>
     12 
     13 #include "core/fxcrt/fx_system.h"
     14 #include "core/fxcrt/retain_ptr.h"
     15 
     16 class CCodec_ScanlineDecoder;
     17 class CFX_DIBSource;
     18 
     19 #ifdef PDF_ENABLE_XFA
     20 class CFX_DIBAttribute;
     21 #endif  // PDF_ENABLE_XFA
     22 
     23 class CCodec_JpegModule {
     24  public:
     25   class Context {
     26    public:
     27     virtual ~Context() {}
     28     virtual jmp_buf* GetJumpMark() = 0;
     29   };
     30 
     31   std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(const uint8_t* src_buf,
     32                                                         uint32_t src_size,
     33                                                         int width,
     34                                                         int height,
     35                                                         int nComps,
     36                                                         bool ColorTransform);
     37   bool LoadInfo(const uint8_t* src_buf,
     38                 uint32_t src_size,
     39                 int* width,
     40                 int* height,
     41                 int* num_components,
     42                 int* bits_per_components,
     43                 bool* color_transform);
     44 
     45   std::unique_ptr<Context> Start();
     46   void Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size);
     47 
     48 #ifndef PDF_ENABLE_XFA
     49   int ReadHeader(Context* pContext, int* width, int* height, int* nComps);
     50 #else   // PDF_ENABLE_XFA
     51   int ReadHeader(Context* pContext,
     52                  int* width,
     53                  int* height,
     54                  int* nComps,
     55                  CFX_DIBAttribute* pAttribute);
     56 #endif  // PDF_ENABLE_XFA
     57 
     58   bool StartScanline(Context* pContext, int down_scale);
     59   bool ReadScanline(Context* pContext, uint8_t* dest_buf);
     60   uint32_t GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr);
     61 
     62 #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
     63   static bool JpegEncode(const RetainPtr<CFX_DIBSource>& pSource,
     64                          uint8_t** dest_buf,
     65                          size_t* dest_size);
     66 #endif  // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
     67 };
     68 
     69 #endif  // CORE_FXCODEC_CODEC_CCODEC_JPEGMODULE_H_
     70