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

Unified Diff: src/pdf/SkPDFUtils.cpp

Issue 2151863003: SkPdf: smaller color serialization (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-07-14 (Thursday) 13:36:29 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pdf/SkPDFUtils.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFUtils.cpp
diff --git a/src/pdf/SkPDFUtils.cpp b/src/pdf/SkPDFUtils.cpp
index b8d65092b07e8065f8cce15e2ba60fbf3eff7cc3..4d02aaadc750e2134c0110c97f15fe38f35f09db 100644
--- a/src/pdf/SkPDFUtils.cpp
+++ b/src/pdf/SkPDFUtils.cpp
@@ -251,6 +251,29 @@ void SkPDFUtils::ApplyPattern(int objectIndex, SkWStream* content) {
content->writeText(" scn\n");
}
+size_t SkPDFUtils::ColorToDecimal(uint8_t value, char result[5]) {
+ if (value == 255 || value == 0) {
+ result[0] = value ? '1' : '0';
+ result[1] = '\0';
+ return 1;
+ }
+ int x = (((1000 << 20) / 255) * value + (1 << 19)) >> 20;
+ // ((int)(0.5 + (1000.0 / 255.0) * value) == x);
tomhudson 2016/07/15 19:20:18 Not sure what the comment is doing here - it's mos
hal.canary 2016/07/15 19:46:42 To make this more clear, I am switching to SkFixed
+ result[0] = '.';
+ for (int i = 3; i > 0; --i) {
+ result[i] = '0' + x % 10;
+ x /= 10;
+ }
+ int j;
+ for (j = 3; j > 1; --j) {
tomhudson 2016/07/15 19:20:17 Trimming off trailing zeroes? Is this important?
hal.canary 2016/07/15 19:46:42 it's cheap to do here, and everyone wants smaller
+ if (result[j] != '0') {
+ break;
+ }
+ }
+ result[j + 1] = '\0';
+ return j + 1;
+}
+
void SkPDFUtils::AppendScalar(SkScalar value, SkWStream* stream) {
char result[kMaximumFloatDecimalLength];
size_t len = SkPDFUtils::FloatToDecimal(SkScalarToFloat(value), result);
« 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