• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
8 
9 #include "core/fxcrt/ifx_pauseindicator.h"
10 
CCodec_ScanlineDecoder()11 CCodec_ScanlineDecoder::CCodec_ScanlineDecoder()
12     : CCodec_ScanlineDecoder(0, 0, 0, 0, 0, 0, 0) {}
13 
CCodec_ScanlineDecoder(int nOrigWidth,int nOrigHeight,int nOutputWidth,int nOutputHeight,int nComps,int nBpc,uint32_t nPitch)14 CCodec_ScanlineDecoder::CCodec_ScanlineDecoder(int nOrigWidth,
15                                                int nOrigHeight,
16                                                int nOutputWidth,
17                                                int nOutputHeight,
18                                                int nComps,
19                                                int nBpc,
20                                                uint32_t nPitch)
21     : m_OrigWidth(nOrigWidth),
22       m_OrigHeight(nOrigHeight),
23       m_OutputWidth(nOutputWidth),
24       m_OutputHeight(nOutputHeight),
25       m_nComps(nComps),
26       m_bpc(nBpc),
27       m_Pitch(nPitch),
28       m_NextLine(-1),
29       m_pLastScanline(nullptr) {}
30 
~CCodec_ScanlineDecoder()31 CCodec_ScanlineDecoder::~CCodec_ScanlineDecoder() {}
32 
GetScanline(int line)33 const uint8_t* CCodec_ScanlineDecoder::GetScanline(int line) {
34   if (m_NextLine == line + 1)
35     return m_pLastScanline;
36 
37   if (m_NextLine < 0 || m_NextLine > line) {
38     if (!v_Rewind())
39       return nullptr;
40     m_NextLine = 0;
41   }
42   while (m_NextLine < line) {
43     ReadNextLine();
44     m_NextLine++;
45   }
46   m_pLastScanline = ReadNextLine();
47   m_NextLine++;
48   return m_pLastScanline;
49 }
50 
SkipToScanline(int line,IFX_PauseIndicator * pPause)51 bool CCodec_ScanlineDecoder::SkipToScanline(int line,
52                                             IFX_PauseIndicator* pPause) {
53   if (m_NextLine == line || m_NextLine == line + 1)
54     return false;
55 
56   if (m_NextLine < 0 || m_NextLine > line) {
57     v_Rewind();
58     m_NextLine = 0;
59   }
60   m_pLastScanline = nullptr;
61   while (m_NextLine < line) {
62     m_pLastScanline = ReadNextLine();
63     m_NextLine++;
64     if (pPause && pPause->NeedToPauseNow()) {
65       return true;
66     }
67   }
68   return false;
69 }
70 
ReadNextLine()71 uint8_t* CCodec_ScanlineDecoder::ReadNextLine() {
72   return v_GetNextLine();
73 }
74