| 1 | // Copyright 2017 The PDFium Authors |
| 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 "scanlinedecoder.h" |
| 8 | |
| 9 | #include <pdfium/core/fxcrt/pauseindicator_iface.h> |
| 10 | |
| 11 | namespace fxcodec { |
| 12 | |
| 13 | ScanlineDecoder::ScanlineDecoder() : ScanlineDecoder(0, 0, 0, 0, 0, 0, 0) {} |
| 14 | |
| 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 | |
| 32 | pdfium::span<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 (!Rewind()) |
| 38 | return pdfium::span<const uint8_t>(); |
| 39 | m_NextLine = 0; |
| 40 | } |
| 41 | while (m_NextLine < line) { |
| 42 | GetNextLine(); |
| 43 | m_NextLine++; |
| 44 | } |
| 45 | m_pLastScanline = GetNextLine(); |
| 46 | m_NextLine++; |
| 47 | return m_pLastScanline; |
| 48 | } |
| 49 | |
| 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 | Rewind(); |
| 56 | m_NextLine = 0; |
| 57 | } |
| 58 | m_pLastScanline = pdfium::span<uint8_t>(); |
| 59 | while (m_NextLine < line) { |
| 60 | m_pLastScanline = GetNextLine(); |
| 61 | m_NextLine++; |
| 62 | if (pPause && pPause->NeedToPauseNow()) { |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | } // namespace fxcodec |