Home | History | Annotate | Download | only in render
      1 // Copyright 2017 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_FPDFAPI_RENDER_CPDF_DIBSOURCE_H_
      8 #define CORE_FPDFAPI_RENDER_CPDF_DIBSOURCE_H_
      9 
     10 #include <map>
     11 #include <memory>
     12 #include <vector>
     13 
     14 #include "core/fpdfapi/page/cpdf_clippath.h"
     15 #include "core/fpdfapi/page/cpdf_countedobject.h"
     16 #include "core/fpdfapi/page/cpdf_graphicstates.h"
     17 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
     18 #include "core/fpdfapi/render/cpdf_imageloader.h"
     19 #include "core/fpdfapi/render/cpdf_rendercontext.h"
     20 #include "core/fpdfapi/render/cpdf_renderoptions.h"
     21 #include "core/fxge/cfx_fxgedevice.h"
     22 #include "core/fxge/cfx_renderdevice.h"
     23 
     24 class CCodec_Jbig2Context;
     25 class CCodec_ScanlineDecoder;
     26 class CPDF_Color;
     27 class CPDF_Dictionary;
     28 class CPDF_Document;
     29 class CPDF_Stream;
     30 
     31 typedef struct {
     32   FX_FLOAT m_DecodeMin;
     33   FX_FLOAT m_DecodeStep;
     34   int m_ColorKeyMin;
     35   int m_ColorKeyMax;
     36 } DIB_COMP_DATA;
     37 
     38 #define FPDF_HUGE_IMAGE_SIZE 60000000
     39 
     40 class CPDF_DIBSource : public CFX_DIBSource {
     41  public:
     42   CPDF_DIBSource();
     43   ~CPDF_DIBSource() override;
     44 
     45   bool Load(CPDF_Document* pDoc, const CPDF_Stream* pStream);
     46 
     47   // CFX_DIBSource
     48   bool SkipToScanline(int line, IFX_Pause* pPause) const override;
     49   uint8_t* GetBuffer() const override;
     50   const uint8_t* GetScanline(int line) const override;
     51   void DownSampleScanline(int line,
     52                           uint8_t* dest_scan,
     53                           int dest_bpp,
     54                           int dest_width,
     55                           bool bFlipX,
     56                           int clip_left,
     57                           int clip_width) const override;
     58 
     59   uint32_t GetMatteColor() const { return m_MatteColor; }
     60 
     61   int StartLoadDIBSource(CPDF_Document* pDoc,
     62                          const CPDF_Stream* pStream,
     63                          bool bHasMask,
     64                          CPDF_Dictionary* pFormResources,
     65                          CPDF_Dictionary* pPageResources,
     66                          bool bStdCS = false,
     67                          uint32_t GroupFamily = 0,
     68                          bool bLoadMask = false);
     69   int ContinueLoadDIBSource(IFX_Pause* pPause);
     70   int StratLoadMask();
     71   int StartLoadMaskDIB();
     72   int ContinueLoadMaskDIB(IFX_Pause* pPause);
     73   int ContinueToLoadMask();
     74   CPDF_DIBSource* DetachMask();
     75 
     76  private:
     77   bool LoadColorInfo(const CPDF_Dictionary* pFormResources,
     78                      const CPDF_Dictionary* pPageResources);
     79   DIB_COMP_DATA* GetDecodeAndMaskArray(bool& bDefaultDecode, bool& bColorKey);
     80   void LoadJpxBitmap();
     81   void LoadPalette();
     82   int CreateDecoder();
     83   void TranslateScanline24bpp(uint8_t* dest_scan,
     84                               const uint8_t* src_scan) const;
     85   void ValidateDictParam();
     86   void DownSampleScanline1Bit(int orig_Bpp,
     87                               int dest_Bpp,
     88                               uint32_t src_width,
     89                               const uint8_t* pSrcLine,
     90                               uint8_t* dest_scan,
     91                               int dest_width,
     92                               bool bFlipX,
     93                               int clip_left,
     94                               int clip_width) const;
     95   void DownSampleScanline8Bit(int orig_Bpp,
     96                               int dest_Bpp,
     97                               uint32_t src_width,
     98                               const uint8_t* pSrcLine,
     99                               uint8_t* dest_scan,
    100                               int dest_width,
    101                               bool bFlipX,
    102                               int clip_left,
    103                               int clip_width) const;
    104   void DownSampleScanline32Bit(int orig_Bpp,
    105                                int dest_Bpp,
    106                                uint32_t src_width,
    107                                const uint8_t* pSrcLine,
    108                                uint8_t* dest_scan,
    109                                int dest_width,
    110                                bool bFlipX,
    111                                int clip_left,
    112                                int clip_width) const;
    113   bool TransMask() const;
    114 
    115   CPDF_Document* m_pDocument;
    116   const CPDF_Stream* m_pStream;
    117   std::unique_ptr<CPDF_StreamAcc> m_pStreamAcc;
    118   const CPDF_Dictionary* m_pDict;
    119   CPDF_ColorSpace* m_pColorSpace;
    120   uint32_t m_Family;
    121   uint32_t m_bpc;
    122   uint32_t m_bpc_orig;
    123   uint32_t m_nComponents;
    124   uint32_t m_GroupFamily;
    125   uint32_t m_MatteColor;
    126   bool m_bLoadMask;
    127   bool m_bDefaultDecode;
    128   bool m_bImageMask;
    129   bool m_bDoBpcCheck;
    130   bool m_bColorKey;
    131   bool m_bHasMask;
    132   bool m_bStdCS;
    133   DIB_COMP_DATA* m_pCompData;
    134   uint8_t* m_pLineBuf;
    135   uint8_t* m_pMaskedLine;
    136   std::unique_ptr<CFX_DIBitmap> m_pCachedBitmap;
    137   std::unique_ptr<CCodec_ScanlineDecoder> m_pDecoder;
    138   CPDF_DIBSource* m_pMask;
    139   std::unique_ptr<CPDF_StreamAcc> m_pGlobalStream;
    140   std::unique_ptr<CCodec_Jbig2Context> m_pJbig2Context;
    141   CPDF_Stream* m_pMaskStream;
    142   int m_Status;
    143 };
    144 
    145 #endif  // CORE_FPDFAPI_RENDER_CPDF_DIBSOURCE_H_
    146