OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/fpdfapi/fpdf_page/pageint.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 m_Pos = 0; | 34 m_Pos = 0; |
35 m_pLastObj = NULL; | 35 m_pLastObj = NULL; |
36 } | 36 } |
37 | 37 |
38 CPDF_StreamParser::~CPDF_StreamParser() { | 38 CPDF_StreamParser::~CPDF_StreamParser() { |
39 if (m_pLastObj) { | 39 if (m_pLastObj) { |
40 m_pLastObj->Release(); | 40 m_pLastObj->Release(); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, | 44 FX_DWORD DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, |
45 uint8_t*& dest_buf, | 45 uint8_t*& dest_buf, |
46 FX_DWORD& dest_size) { | 46 FX_DWORD& dest_size) { |
47 if (!pDecoder) { | 47 if (!pDecoder) { |
48 return (FX_DWORD)-1; | 48 return static_cast<FX_DWORD>(-1); |
49 } | 49 } |
50 int ncomps = pDecoder->CountComps(); | 50 int ncomps = pDecoder->CountComps(); |
51 int bpc = pDecoder->GetBPC(); | 51 int bpc = pDecoder->GetBPC(); |
52 int width = pDecoder->GetWidth(); | 52 int width = pDecoder->GetWidth(); |
53 int height = pDecoder->GetHeight(); | 53 int height = pDecoder->GetHeight(); |
54 int pitch = (width * ncomps * bpc + 7) / 8; | 54 int pitch = (width * ncomps * bpc + 7) / 8; |
55 if (height == 0 || pitch > (1 << 30) / height) { | 55 if (height == 0 || pitch > (1 << 30) / height) { |
56 delete pDecoder; | 56 delete pDecoder; |
57 return -1; | 57 return static_cast<FX_DWORD>(-1); |
58 } | 58 } |
59 dest_buf = FX_Alloc2D(uint8_t, pitch, height); | 59 dest_buf = FX_Alloc2D(uint8_t, pitch, height); |
60 dest_size = pitch * height; // Safe since checked alloc returned. | 60 dest_size = pitch * height; // Safe since checked alloc returned. |
61 for (int row = 0; row < height; row++) { | 61 for (int row = 0; row < height; row++) { |
62 const uint8_t* pLine = pDecoder->GetScanline(row); | 62 const uint8_t* pLine = pDecoder->GetScanline(row); |
63 if (!pLine) | 63 if (!pLine) |
64 break; | 64 break; |
65 | 65 |
66 FXSYS_memcpy(dest_buf + row * pitch, pLine, pitch); | 66 FXSYS_memcpy(dest_buf + row * pitch, pLine, pitch); |
67 } | 67 } |
(...skipping 13 matching lines...) Expand all Loading... |
81 FX_DWORD limit, | 81 FX_DWORD limit, |
82 int width, | 82 int width, |
83 int height, | 83 int height, |
84 CFX_ByteString& decoder, | 84 CFX_ByteString& decoder, |
85 CPDF_Dictionary* pParam, | 85 CPDF_Dictionary* pParam, |
86 uint8_t*& dest_buf, | 86 uint8_t*& dest_buf, |
87 FX_DWORD& dest_size) { | 87 FX_DWORD& dest_size) { |
88 if (decoder == "CCITTFaxDecode" || decoder == "CCF") { | 88 if (decoder == "CCITTFaxDecode" || decoder == "CCF") { |
89 ICodec_ScanlineDecoder* pDecoder = | 89 ICodec_ScanlineDecoder* pDecoder = |
90 FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam); | 90 FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam); |
91 return _DecodeAllScanlines(pDecoder, dest_buf, dest_size); | 91 return DecodeAllScanlines(pDecoder, dest_buf, dest_size); |
92 } | 92 } |
93 if (decoder == "ASCII85Decode" || decoder == "A85") { | 93 if (decoder == "ASCII85Decode" || decoder == "A85") { |
94 return A85Decode(src_buf, limit, dest_buf, dest_size); | 94 return A85Decode(src_buf, limit, dest_buf, dest_size); |
95 } | 95 } |
96 if (decoder == "ASCIIHexDecode" || decoder == "AHx") { | 96 if (decoder == "ASCIIHexDecode" || decoder == "AHx") { |
97 return HexDecode(src_buf, limit, dest_buf, dest_size); | 97 return HexDecode(src_buf, limit, dest_buf, dest_size); |
98 } | 98 } |
99 if (decoder == "FlateDecode" || decoder == "Fl") { | 99 if (decoder == "FlateDecode" || decoder == "Fl") { |
100 return FPDFAPI_FlateOrLZWDecode(FALSE, src_buf, limit, pParam, dest_size, | 100 return FPDFAPI_FlateOrLZWDecode(FALSE, src_buf, limit, pParam, dest_size, |
101 dest_buf, dest_size); | 101 dest_buf, dest_size); |
102 } | 102 } |
103 if (decoder == "LZWDecode" || decoder == "LZW") { | 103 if (decoder == "LZWDecode" || decoder == "LZW") { |
104 return FPDFAPI_FlateOrLZWDecode(TRUE, src_buf, limit, pParam, 0, dest_buf, | 104 return FPDFAPI_FlateOrLZWDecode(TRUE, src_buf, limit, pParam, 0, dest_buf, |
105 dest_size); | 105 dest_size); |
106 } | 106 } |
107 if (decoder == "DCTDecode" || decoder == "DCT") { | 107 if (decoder == "DCTDecode" || decoder == "DCT") { |
108 ICodec_ScanlineDecoder* pDecoder = | 108 ICodec_ScanlineDecoder* pDecoder = |
109 CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( | 109 CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( |
110 src_buf, limit, width, height, 0, | 110 src_buf, limit, width, height, 0, |
111 pParam ? pParam->GetIntegerBy("ColorTransform", 1) : 1); | 111 pParam ? pParam->GetIntegerBy("ColorTransform", 1) : 1); |
112 return _DecodeAllScanlines(pDecoder, dest_buf, dest_size); | 112 return DecodeAllScanlines(pDecoder, dest_buf, dest_size); |
113 } | 113 } |
114 if (decoder == "RunLengthDecode" || decoder == "RL") { | 114 if (decoder == "RunLengthDecode" || decoder == "RL") { |
115 return RunLengthDecode(src_buf, limit, dest_buf, dest_size); | 115 return RunLengthDecode(src_buf, limit, dest_buf, dest_size); |
116 } | 116 } |
117 dest_size = 0; | 117 dest_size = 0; |
118 dest_buf = 0; | 118 dest_buf = 0; |
119 return (FX_DWORD)-1; | 119 return (FX_DWORD)-1; |
120 } | 120 } |
121 | 121 |
122 CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, | 122 CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 } | 883 } |
884 m_Status = Done; | 884 m_Status = Done; |
885 return; | 885 return; |
886 } | 886 } |
887 steps++; | 887 steps++; |
888 if (pPause && pPause->NeedToPauseNow()) { | 888 if (pPause && pPause->NeedToPauseNow()) { |
889 break; | 889 break; |
890 } | 890 } |
891 } | 891 } |
892 } | 892 } |
OLD | NEW |