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