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

Side by Side Diff: core/fxcodec/codec/fx_codec.cpp

Issue 2608663003: Pdfium Patch to restore PS Path (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « core/fxcodec/codec/ccodec_jpegmodule.h ('k') | core/fxcodec/codec/fx_codec_fax.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fxcodec/fx_codec.h" 7 #include "core/fxcodec/fx_codec.h"
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <memory> 10 #include <memory>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return true; 90 return true;
91 } 91 }
92 } 92 }
93 return false; 93 return false;
94 } 94 }
95 95
96 uint8_t* CCodec_ScanlineDecoder::ReadNextLine() { 96 uint8_t* CCodec_ScanlineDecoder::ReadNextLine() {
97 return v_GetNextLine(); 97 return v_GetNextLine();
98 } 98 }
99 99
100 bool CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf,
101 uint32_t src_size,
102 uint8_t*& dest_buf,
103 uint32_t& dest_size) {
104 // Handle edge cases
105 if (src_size == 0)
106 return false;
107 if (src_size == 1) {
108 dest_buf = FX_Alloc(uint8_t, 3);
109 dest_buf[0] = 0;
110 dest_buf[1] = src_buf[0];
111 dest_buf[2] = 128;
112 return true;
113 }
114
115 uint32_t est_size = src_size * 2;
116 dest_buf = FX_Alloc(uint8_t, est_size);
117
118 // Set up pointers.
119 uint8_t* out = dest_buf;
120 uint32_t run_start = 0;
121 uint32_t run_end = 1;
122 uint8_t x = src_buf[run_start];
123 uint8_t y = src_buf[run_end];
124 while (run_end < src_size) {
125 uint32_t max_len = run_start + 128 < src_size ? 128 : src_size - run_start;
126 while (x == y && ((run_end - run_start) < max_len - 1))
127 y = src_buf[++run_end];
128 // Reached end with matched run. Update variables to expected values.
129 if (x == y) {
130 run_end++;
131 if (run_end < src_size)
132 y = src_buf[run_end];
133 }
134 if (run_end - run_start > 1) { // Matched run
135 out[0] = 257 - (run_end - run_start);
136 out[1] = x;
137 x = y;
138 run_start = run_end;
139 run_end++;
140 if (run_end < src_size)
141 y = src_buf[run_end];
142 out += 2;
143 continue;
144 }
145 // Mismatched run
146 while (x != y && run_end <= run_start + max_len) {
147 out[(run_end - run_start)] = x;
148 x = y;
149 run_end++;
150 if (run_end == src_size) {
151 if (run_end <= run_start + max_len) {
152 out[(run_end - run_start)] = x;
153 run_end++;
154 }
155 break;
156 }
157 y = src_buf[run_end];
158 }
159 out[0] = run_end - run_start - 2;
160 out += run_end - run_start;
161 run_start = run_end - 1;
162 }
163 if (run_start < src_size) {
164 out[0] = 0;
165 out[1] = x;
166 out += 2;
167 }
168 *out = 128;
169 dest_size = out + 1 - dest_buf;
170 return true;
171 }
172
173 namespace A85Encode {
174 static const uint64_t a[4] = {256 * 256 * 256, 256 * 256, 256, 1};
175 static const uint64_t b[5] = {85 * 85 * 85 * 85, 85 * 85 * 85, 85 * 85, 85, 1};
176 }
177
178 bool CCodec_BasicModule::A85Encode(const uint8_t* src_buf,
179 uint32_t src_size,
180 uint8_t*& dest_buf,
181 uint32_t& dest_size) {
182 // Handle edge cases
183 if (src_size == 0) {
184 dest_size = 0;
185 return false;
186 }
187
188 uint32_t est_size = 5 * (src_size / 4 + 1) + src_size / 30 + 1;
189 dest_buf = FX_Alloc(uint8_t, est_size);
190
191 // Set up pointers.
192 uint8_t* out = dest_buf;
193 uint32_t pos = 0;
194 uint32_t line_length = 0;
195 while (src_size >= 4 && pos < src_size - 3) {
196 uint64_t val = (uint64_t)(src_buf[pos]) * A85Encode::a[0] +
197 (uint64_t)(src_buf[pos + 1]) * A85Encode::a[1] +
198 (uint64_t)(src_buf[pos + 2]) * A85Encode::a[2] +
199 (uint64_t)(src_buf[pos + 3]);
200 pos += 4;
201 if (val == 0) { // All zero special case
202 *out = 'z';
203 out++;
204 line_length++;
205 } else {
206 uint64_t c1 = val / A85Encode::b[0];
207 val -= c1 * A85Encode::b[0];
208 out[0] = (uint8_t)c1 + 33;
209 uint64_t c2 = val / A85Encode::b[1];
210 val -= c2 * A85Encode::b[1];
211 out[1] = (uint8_t)c2 + 33;
212 uint64_t c3 = val / A85Encode::b[2];
213 val -= c3 * A85Encode::b[2];
214 out[2] = (uint8_t)c3 + 33;
215 uint64_t c4 = val / A85Encode::b[3];
216 val -= c4 * A85Encode::b[3];
217 out[3] = (uint8_t)c4 + 33;
218 out[4] = (uint8_t)val + 33;
219 out += 5;
220 line_length += 5;
221 }
222 if (line_length >= 75) {
223 *out = '\r';
224 *++out = '\n';
225 out++;
226 line_length = 0;
227 }
228 }
229 if (pos < src_size) { // Leftover bytes
230 uint64_t val = 0;
231 uint32_t count = 0;
232 while (pos < src_size) {
233 val += (uint64_t)(src_buf[pos]) * A85Encode::a[count];
234 count++;
235 pos++;
236 }
237 for (uint32_t i = 0; i < count + 1; i++) {
238 uint64_t c = val / A85Encode::b[i];
239 val -= c * A85Encode::b[i];
240 out[i] = (uint8_t)c + 33;
241 }
242 out += count + 1;
243 }
244
245 out[0] = '~';
246 out[1] = '>';
247 out += 2;
248 dest_size = out - dest_buf;
249 return true;
250 }
251
100 #ifdef PDF_ENABLE_XFA 252 #ifdef PDF_ENABLE_XFA
101 CFX_DIBAttribute::CFX_DIBAttribute() 253 CFX_DIBAttribute::CFX_DIBAttribute()
102 : m_nXDPI(-1), 254 : m_nXDPI(-1),
103 m_nYDPI(-1), 255 m_nYDPI(-1),
104 m_fAspectRatio(-1.0f), 256 m_fAspectRatio(-1.0f),
105 m_wDPIUnit(0), 257 m_wDPIUnit(0),
106 m_nGifLeft(0), 258 m_nGifLeft(0),
107 m_nGifTop(0), 259 m_nGifTop(0),
108 m_pGifLocalPalette(nullptr), 260 m_pGifLocalPalette(nullptr),
109 m_nGifLocalPalNum(0), 261 m_nGifLocalPalNum(0),
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 int width, 461 int width,
310 int height, 462 int height,
311 int nComps, 463 int nComps,
312 int bpc) { 464 int bpc) {
313 auto pDecoder = pdfium::MakeUnique<CCodec_RLScanlineDecoder>(); 465 auto pDecoder = pdfium::MakeUnique<CCodec_RLScanlineDecoder>();
314 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, bpc)) 466 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, bpc))
315 return nullptr; 467 return nullptr;
316 468
317 return std::move(pDecoder); 469 return std::move(pDecoder);
318 } 470 }
OLDNEW
« no previous file with comments | « core/fxcodec/codec/ccodec_jpegmodule.h ('k') | core/fxcodec/codec/fx_codec_fax.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698