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

Side by Side Diff: src/pdf/SkPDFUtils.cpp

Issue 2151863003: SkPdf: smaller color serialization (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkFixed - 2016-07-15 (Friday) 15:45:32 EDT Created 4 years, 5 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 | « src/pdf/SkPDFUtils.h ('k') | tests/PDFPrimitivesTest.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 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkFixed.h"
10 #include "SkGeometry.h" 11 #include "SkGeometry.h"
11 #include "SkPDFResourceDict.h" 12 #include "SkPDFResourceDict.h"
12 #include "SkPDFUtils.h" 13 #include "SkPDFUtils.h"
13 #include "SkStream.h" 14 #include "SkStream.h"
14 #include "SkString.h" 15 #include "SkString.h"
15 #include "SkPDFTypes.h" 16 #include "SkPDFTypes.h"
16 17
17 #include <cmath> 18 #include <cmath>
18 19
19 sk_sp<SkPDFArray> SkPDFUtils::RectToArray(const SkRect& rect) { 20 sk_sp<SkPDFArray> SkPDFUtils::RectToArray(const SkRect& rect) {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 SkString resourceName = SkPDFResourceDict::getResourceName( 245 SkString resourceName = SkPDFResourceDict::getResourceName(
245 SkPDFResourceDict::kPattern_ResourceType, 246 SkPDFResourceDict::kPattern_ResourceType,
246 objectIndex); 247 objectIndex);
247 content->writeText("/Pattern CS/Pattern cs/"); 248 content->writeText("/Pattern CS/Pattern cs/");
248 content->writeText(resourceName.c_str()); 249 content->writeText(resourceName.c_str());
249 content->writeText(" SCN/"); 250 content->writeText(" SCN/");
250 content->writeText(resourceName.c_str()); 251 content->writeText(resourceName.c_str());
251 content->writeText(" scn\n"); 252 content->writeText(" scn\n");
252 } 253 }
253 254
255 size_t SkPDFUtils::ColorToDecimal(uint8_t value, char result[5]) {
256 if (value == 255 || value == 0) {
257 result[0] = value ? '1' : '0';
258 result[1] = '\0';
259 return 1;
260 }
261 // int x = 0.5 + (1000.0 / 255.0) * value;
262 int x = SkFixedRoundToInt((SK_Fixed1 * 1000 / 255) * value);
263 result[0] = '.';
264 for (int i = 3; i > 0; --i) {
265 result[i] = '0' + x % 10;
266 x /= 10;
267 }
268 int j;
269 for (j = 3; j > 1; --j) {
270 if (result[j] != '0') {
271 break;
272 }
273 }
274 result[j + 1] = '\0';
275 return j + 1;
276 }
277
254 void SkPDFUtils::AppendScalar(SkScalar value, SkWStream* stream) { 278 void SkPDFUtils::AppendScalar(SkScalar value, SkWStream* stream) {
255 char result[kMaximumFloatDecimalLength]; 279 char result[kMaximumFloatDecimalLength];
256 size_t len = SkPDFUtils::FloatToDecimal(SkScalarToFloat(value), result); 280 size_t len = SkPDFUtils::FloatToDecimal(SkScalarToFloat(value), result);
257 SkASSERT(len < kMaximumFloatDecimalLength); 281 SkASSERT(len < kMaximumFloatDecimalLength);
258 stream->write(result, len); 282 stream->write(result, len);
259 } 283 }
260 284
261 /** Write a string into result, includeing a terminating '\0' (for 285 /** Write a string into result, includeing a terminating '\0' (for
262 unit testing). Return strlen(result) (for SkWStream::write) The 286 unit testing). Return strlen(result) (for SkWStream::write) The
263 resulting string will be in the form /[-]?([0-9]*.)?[0-9]+/ and 287 resulting string will be in the form /[-]?([0-9]*.)?[0-9]+/ and
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 uint8_t c = static_cast<uint8_t>(cin[i]); 430 uint8_t c = static_cast<uint8_t>(cin[i]);
407 static const char gHex[] = "0123456789ABCDEF"; 431 static const char gHex[] = "0123456789ABCDEF";
408 char hexValue[2]; 432 char hexValue[2];
409 hexValue[0] = gHex[(c >> 4) & 0xF]; 433 hexValue[0] = gHex[(c >> 4) & 0xF];
410 hexValue[1] = gHex[ c & 0xF]; 434 hexValue[1] = gHex[ c & 0xF];
411 wStream->write(hexValue, 2); 435 wStream->write(hexValue, 2);
412 } 436 }
413 wStream->writeText(">"); 437 wStream->writeText(">");
414 } 438 }
415 } 439 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFUtils.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698