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 19 matching lines...) Expand all Loading... | |
30 m_Pos = 0; | 30 m_Pos = 0; |
31 m_pLastObj = NULL; | 31 m_pLastObj = NULL; |
32 } | 32 } |
33 | 33 |
34 CPDF_StreamParser::~CPDF_StreamParser() { | 34 CPDF_StreamParser::~CPDF_StreamParser() { |
35 if (m_pLastObj) { | 35 if (m_pLastObj) { |
36 m_pLastObj->Release(); | 36 m_pLastObj->Release(); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, | 40 FX_DWORD DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, |
41 uint8_t*& dest_buf, | 41 uint8_t*& dest_buf, |
42 FX_DWORD& dest_size) { | 42 FX_DWORD& dest_size) { |
43 if (!pDecoder) { | 43 if (!pDecoder) { |
44 return (FX_DWORD)-1; | 44 return (FX_DWORD)-1; |
Tom Sepez
2016/03/16 18:34:58
nit:static_cast
Wei Li
2016/03/17 02:24:04
Done.
| |
45 } | 45 } |
46 int ncomps = pDecoder->CountComps(); | 46 int ncomps = pDecoder->CountComps(); |
47 int bpc = pDecoder->GetBPC(); | 47 int bpc = pDecoder->GetBPC(); |
48 int width = pDecoder->GetWidth(); | 48 int width = pDecoder->GetWidth(); |
49 int height = pDecoder->GetHeight(); | 49 int height = pDecoder->GetHeight(); |
50 int pitch = (width * ncomps * bpc + 7) / 8; | 50 int pitch = (width * ncomps * bpc + 7) / 8; |
51 if (height == 0 || pitch > (1 << 30) / height) { | 51 if (height == 0 || pitch > (1 << 30) / height) { |
52 delete pDecoder; | 52 delete pDecoder; |
53 return -1; | 53 return static_cast<FX_DWORD>(-1); |
54 } | 54 } |
55 dest_buf = FX_Alloc2D(uint8_t, pitch, height); | 55 dest_buf = FX_Alloc2D(uint8_t, pitch, height); |
56 dest_size = pitch * height; // Safe since checked alloc returned. | 56 dest_size = pitch * height; // Safe since checked alloc returned. |
57 for (int row = 0; row < height; row++) { | 57 for (int row = 0; row < height; row++) { |
58 const uint8_t* pLine = pDecoder->GetScanline(row); | 58 const uint8_t* pLine = pDecoder->GetScanline(row); |
59 if (!pLine) | 59 if (!pLine) |
60 break; | 60 break; |
61 | 61 |
62 FXSYS_memcpy(dest_buf + row * pitch, pLine, pitch); | 62 FXSYS_memcpy(dest_buf + row * pitch, pLine, pitch); |
63 } | 63 } |
(...skipping 13 matching lines...) Expand all Loading... | |
77 FX_DWORD limit, | 77 FX_DWORD limit, |
78 int width, | 78 int width, |
79 int height, | 79 int height, |
80 CFX_ByteString& decoder, | 80 CFX_ByteString& decoder, |
81 CPDF_Dictionary* pParam, | 81 CPDF_Dictionary* pParam, |
82 uint8_t*& dest_buf, | 82 uint8_t*& dest_buf, |
83 FX_DWORD& dest_size) { | 83 FX_DWORD& dest_size) { |
84 if (decoder == "CCITTFaxDecode" || decoder == "CCF") { | 84 if (decoder == "CCITTFaxDecode" || decoder == "CCF") { |
85 ICodec_ScanlineDecoder* pDecoder = | 85 ICodec_ScanlineDecoder* pDecoder = |
86 FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam); | 86 FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam); |
87 return _DecodeAllScanlines(pDecoder, dest_buf, dest_size); | 87 return DecodeAllScanlines(pDecoder, dest_buf, dest_size); |
88 } | 88 } |
89 if (decoder == "ASCII85Decode" || decoder == "A85") { | 89 if (decoder == "ASCII85Decode" || decoder == "A85") { |
90 return A85Decode(src_buf, limit, dest_buf, dest_size); | 90 return A85Decode(src_buf, limit, dest_buf, dest_size); |
91 } | 91 } |
92 if (decoder == "ASCIIHexDecode" || decoder == "AHx") { | 92 if (decoder == "ASCIIHexDecode" || decoder == "AHx") { |
93 return HexDecode(src_buf, limit, dest_buf, dest_size); | 93 return HexDecode(src_buf, limit, dest_buf, dest_size); |
94 } | 94 } |
95 if (decoder == "FlateDecode" || decoder == "Fl") { | 95 if (decoder == "FlateDecode" || decoder == "Fl") { |
96 return FPDFAPI_FlateOrLZWDecode(FALSE, src_buf, limit, pParam, dest_size, | 96 return FPDFAPI_FlateOrLZWDecode(FALSE, src_buf, limit, pParam, dest_size, |
97 dest_buf, dest_size); | 97 dest_buf, dest_size); |
98 } | 98 } |
99 if (decoder == "LZWDecode" || decoder == "LZW") { | 99 if (decoder == "LZWDecode" || decoder == "LZW") { |
100 return FPDFAPI_FlateOrLZWDecode(TRUE, src_buf, limit, pParam, 0, dest_buf, | 100 return FPDFAPI_FlateOrLZWDecode(TRUE, src_buf, limit, pParam, 0, dest_buf, |
101 dest_size); | 101 dest_size); |
102 } | 102 } |
103 if (decoder == "DCTDecode" || decoder == "DCT") { | 103 if (decoder == "DCTDecode" || decoder == "DCT") { |
104 ICodec_ScanlineDecoder* pDecoder = | 104 ICodec_ScanlineDecoder* pDecoder = |
105 CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( | 105 CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( |
106 src_buf, limit, width, height, 0, | 106 src_buf, limit, width, height, 0, |
107 pParam ? pParam->GetIntegerBy("ColorTransform", 1) : 1); | 107 pParam ? pParam->GetIntegerBy("ColorTransform", 1) : 1); |
108 return _DecodeAllScanlines(pDecoder, dest_buf, dest_size); | 108 return DecodeAllScanlines(pDecoder, dest_buf, dest_size); |
109 } | 109 } |
110 if (decoder == "RunLengthDecode" || decoder == "RL") { | 110 if (decoder == "RunLengthDecode" || decoder == "RL") { |
111 return RunLengthDecode(src_buf, limit, dest_buf, dest_size); | 111 return RunLengthDecode(src_buf, limit, dest_buf, dest_size); |
112 } | 112 } |
113 dest_size = 0; | 113 dest_size = 0; |
114 dest_buf = 0; | 114 dest_buf = 0; |
115 return (FX_DWORD)-1; | 115 return (FX_DWORD)-1; |
116 } | 116 } |
117 | 117 |
118 CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, | 118 CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 } | 879 } |
880 m_Status = Done; | 880 m_Status = Done; |
881 return; | 881 return; |
882 } | 882 } |
883 steps++; | 883 steps++; |
884 if (pPause && pPause->NeedToPauseNow()) { | 884 if (pPause && pPause->NeedToPauseNow()) { |
885 break; | 885 break; |
886 } | 886 } |
887 } | 887 } |
888 } | 888 } |
OLD | NEW |