Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp

Issue 1783933003: Split CPDF_Stream/CPDF_StreamAcc into separate files (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include "core/include/fpdfapi/cpdf_stream_acc.h"
8
9 #include "core/include/fpdfapi/cpdf_dictionary.h"
10 #include "core/include/fpdfapi/fpdf_parser_decode.h"
11
12 CPDF_StreamAcc::CPDF_StreamAcc()
13 : m_pData(nullptr),
14 m_dwSize(0),
15 m_bNewBuf(FALSE),
16 m_pImageParam(nullptr),
17 m_pStream(nullptr),
18 m_pSrcData(nullptr) {}
19
20 void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream,
21 FX_BOOL bRawAccess,
22 FX_DWORD estimated_size,
23 FX_BOOL bImageAcc) {
24 if (!pStream)
25 return;
26
27 m_pStream = pStream;
28 if (pStream->IsMemoryBased() &&
29 (!pStream->GetDict()->KeyExist("Filter") || bRawAccess)) {
30 m_dwSize = pStream->GetRawSize();
31 m_pData = pStream->GetRawData();
32 return;
33 }
34 uint8_t* pSrcData;
35 FX_DWORD dwSrcSize = pStream->GetRawSize();
36 if (dwSrcSize == 0)
37 return;
38
39 if (!pStream->IsMemoryBased()) {
40 pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize);
41 if (!pStream->ReadRawData(0, pSrcData, dwSrcSize))
42 return;
43 } else {
44 pSrcData = pStream->GetRawData();
45 }
46 uint8_t* pDecryptedData = pSrcData;
47 FX_DWORD dwDecryptedSize = dwSrcSize;
48 if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) {
49 m_pData = pDecryptedData;
50 m_dwSize = dwDecryptedSize;
51 } else {
52 FX_BOOL bRet = PDF_DataDecode(
53 pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData,
54 m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc);
55 if (!bRet) {
56 m_pData = pDecryptedData;
57 m_dwSize = dwDecryptedSize;
58 }
59 }
60 if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) {
61 FX_Free(pSrcData);
62 }
63 if (pDecryptedData != pSrcData && pDecryptedData != m_pData) {
64 FX_Free(pDecryptedData);
65 }
66 m_pSrcData = nullptr;
67 m_bNewBuf = m_pData != pStream->GetRawData();
68 }
69
70 CPDF_StreamAcc::~CPDF_StreamAcc() {
71 if (m_bNewBuf) {
72 FX_Free(m_pData);
73 }
74 FX_Free(m_pSrcData);
75 }
76
77 const uint8_t* CPDF_StreamAcc::GetData() const {
78 if (m_bNewBuf) {
79 return m_pData;
80 }
81 if (!m_pStream) {
82 return nullptr;
83 }
84 return m_pStream->GetRawData();
85 }
86
87 FX_DWORD CPDF_StreamAcc::GetSize() const {
88 if (m_bNewBuf) {
89 return m_dwSize;
90 }
91 if (!m_pStream) {
92 return 0;
93 }
94 return m_pStream->GetRawSize();
95 }
96
97 uint8_t* CPDF_StreamAcc::DetachData() {
98 if (m_bNewBuf) {
99 uint8_t* p = m_pData;
100 m_pData = nullptr;
101 m_dwSize = 0;
102 return p;
103 }
104 uint8_t* p = FX_Alloc(uint8_t, m_dwSize);
105 FXSYS_memcpy(p, m_pData, m_dwSize);
106 return p;
107 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/cpdf_stream.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698