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 26 matching lines...) Expand all Loading... |
37 m_Pos = 0; | 37 m_Pos = 0; |
38 m_pLastObj = NULL; | 38 m_pLastObj = NULL; |
39 } | 39 } |
40 | 40 |
41 CPDF_StreamParser::~CPDF_StreamParser() { | 41 CPDF_StreamParser::~CPDF_StreamParser() { |
42 if (m_pLastObj) { | 42 if (m_pLastObj) { |
43 m_pLastObj->Release(); | 43 m_pLastObj->Release(); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 uint32_t DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, | 47 uint32_t DecodeAllScanlines(CCodec_ScanlineDecoder* pDecoder, |
48 uint8_t*& dest_buf, | 48 uint8_t*& dest_buf, |
49 uint32_t& dest_size) { | 49 uint32_t& dest_size) { |
50 if (!pDecoder) { | 50 if (!pDecoder) { |
51 return FX_INVALID_OFFSET; | 51 return FX_INVALID_OFFSET; |
52 } | 52 } |
53 int ncomps = pDecoder->CountComps(); | 53 int ncomps = pDecoder->CountComps(); |
54 int bpc = pDecoder->GetBPC(); | 54 int bpc = pDecoder->GetBPC(); |
55 int width = pDecoder->GetWidth(); | 55 int width = pDecoder->GetWidth(); |
56 int height = pDecoder->GetHeight(); | 56 int height = pDecoder->GetHeight(); |
57 int pitch = (width * ncomps * bpc + 7) / 8; | 57 int pitch = (width * ncomps * bpc + 7) / 8; |
58 if (height == 0 || pitch > (1 << 30) / height) { | 58 if (height == 0 || pitch > (1 << 30) / height) { |
59 delete pDecoder; | 59 delete pDecoder; |
60 return FX_INVALID_OFFSET; | 60 return FX_INVALID_OFFSET; |
61 } | 61 } |
62 dest_buf = FX_Alloc2D(uint8_t, pitch, height); | 62 dest_buf = FX_Alloc2D(uint8_t, pitch, height); |
63 dest_size = pitch * height; // Safe since checked alloc returned. | 63 dest_size = pitch * height; // Safe since checked alloc returned. |
64 for (int row = 0; row < height; row++) { | 64 for (int row = 0; row < height; row++) { |
65 const uint8_t* pLine = pDecoder->GetScanline(row); | 65 const uint8_t* pLine = pDecoder->GetScanline(row); |
66 if (!pLine) | 66 if (!pLine) |
67 break; | 67 break; |
68 | 68 |
69 FXSYS_memcpy(dest_buf + row * pitch, pLine, pitch); | 69 FXSYS_memcpy(dest_buf + row * pitch, pLine, pitch); |
70 } | 70 } |
71 uint32_t srcoff = pDecoder->GetSrcOffset(); | 71 uint32_t srcoff = pDecoder->GetSrcOffset(); |
72 delete pDecoder; | 72 delete pDecoder; |
73 return srcoff; | 73 return srcoff; |
74 } | 74 } |
75 | 75 |
76 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( | 76 CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( |
77 const uint8_t* src_buf, | 77 const uint8_t* src_buf, |
78 uint32_t src_size, | 78 uint32_t src_size, |
79 int width, | 79 int width, |
80 int height, | 80 int height, |
81 const CPDF_Dictionary* pParams); | 81 const CPDF_Dictionary* pParams); |
82 | 82 |
83 uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf, | 83 uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf, |
84 uint32_t limit, | 84 uint32_t limit, |
85 int width, | 85 int width, |
86 int height, | 86 int height, |
87 CFX_ByteString& decoder, | 87 CFX_ByteString& decoder, |
88 CPDF_Dictionary* pParam, | 88 CPDF_Dictionary* pParam, |
89 uint8_t*& dest_buf, | 89 uint8_t*& dest_buf, |
90 uint32_t& dest_size) { | 90 uint32_t& dest_size) { |
91 if (decoder == "CCITTFaxDecode" || decoder == "CCF") { | 91 if (decoder == "CCITTFaxDecode" || decoder == "CCF") { |
92 ICodec_ScanlineDecoder* pDecoder = | 92 CCodec_ScanlineDecoder* pDecoder = |
93 FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam); | 93 FPDFAPI_CreateFaxDecoder(src_buf, limit, width, height, pParam); |
94 return DecodeAllScanlines(pDecoder, dest_buf, dest_size); | 94 return DecodeAllScanlines(pDecoder, dest_buf, dest_size); |
95 } | 95 } |
96 if (decoder == "ASCII85Decode" || decoder == "A85") { | 96 if (decoder == "ASCII85Decode" || decoder == "A85") { |
97 return A85Decode(src_buf, limit, dest_buf, dest_size); | 97 return A85Decode(src_buf, limit, dest_buf, dest_size); |
98 } | 98 } |
99 if (decoder == "ASCIIHexDecode" || decoder == "AHx") { | 99 if (decoder == "ASCIIHexDecode" || decoder == "AHx") { |
100 return HexDecode(src_buf, limit, dest_buf, dest_size); | 100 return HexDecode(src_buf, limit, dest_buf, dest_size); |
101 } | 101 } |
102 if (decoder == "FlateDecode" || decoder == "Fl") { | 102 if (decoder == "FlateDecode" || decoder == "Fl") { |
103 return FPDFAPI_FlateOrLZWDecode(FALSE, src_buf, limit, pParam, dest_size, | 103 return FPDFAPI_FlateOrLZWDecode(FALSE, src_buf, limit, pParam, dest_size, |
104 dest_buf, dest_size); | 104 dest_buf, dest_size); |
105 } | 105 } |
106 if (decoder == "LZWDecode" || decoder == "LZW") { | 106 if (decoder == "LZWDecode" || decoder == "LZW") { |
107 return FPDFAPI_FlateOrLZWDecode(TRUE, src_buf, limit, pParam, 0, dest_buf, | 107 return FPDFAPI_FlateOrLZWDecode(TRUE, src_buf, limit, pParam, 0, dest_buf, |
108 dest_size); | 108 dest_size); |
109 } | 109 } |
110 if (decoder == "DCTDecode" || decoder == "DCT") { | 110 if (decoder == "DCTDecode" || decoder == "DCT") { |
111 ICodec_ScanlineDecoder* pDecoder = | 111 CCodec_ScanlineDecoder* pDecoder = |
112 CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( | 112 CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( |
113 src_buf, limit, width, height, 0, | 113 src_buf, limit, width, height, 0, |
114 pParam ? pParam->GetIntegerBy("ColorTransform", 1) : 1); | 114 pParam ? pParam->GetIntegerBy("ColorTransform", 1) : 1); |
115 return DecodeAllScanlines(pDecoder, dest_buf, dest_size); | 115 return DecodeAllScanlines(pDecoder, dest_buf, dest_size); |
116 } | 116 } |
117 if (decoder == "RunLengthDecode" || decoder == "RL") { | 117 if (decoder == "RunLengthDecode" || decoder == "RL") { |
118 return RunLengthDecode(src_buf, limit, dest_buf, dest_size); | 118 return RunLengthDecode(src_buf, limit, dest_buf, dest_size); |
119 } | 119 } |
120 dest_size = 0; | 120 dest_size = 0; |
121 dest_buf = 0; | 121 dest_buf = 0; |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 } | 885 } |
886 m_Status = Done; | 886 m_Status = Done; |
887 return; | 887 return; |
888 } | 888 } |
889 steps++; | 889 steps++; |
890 if (pPause && pPause->NeedToPauseNow()) { | 890 if (pPause && pPause->NeedToPauseNow()) { |
891 break; | 891 break; |
892 } | 892 } |
893 } | 893 } |
894 } | 894 } |
OLD | NEW |