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