diff options
author | halcanary <halcanary@google.com> | 2016-07-15 13:41:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-15 13:41:28 -0700 |
commit | eb92cb3e84f49b5eedb22b36acffd895d6a90e5a (patch) | |
tree | 0735e84978ab91cfbf507573ac0726d9ea4cc50e /src/pdf/SkPDFUtils.h | |
parent | f0c30f55665eb3555ca438855d4995baed182e97 (diff) |
SkPdf: smaller color serialization
SkPDFUtils now has a special function (SkPDFUtils::AppendColorComponent)
just for writing out (color/255) as a decimal with three digits of
precision.
SkPDFUnion now has a type to represent a color component. It holds a
utint_8, but calls into AppendColorComponent to serialize.
Added a unit test that tests all possible input values.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2151863003
Review-Url: https://codereview.chromium.org/2151863003
Diffstat (limited to 'src/pdf/SkPDFUtils.h')
-rw-r--r-- | src/pdf/SkPDFUtils.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/pdf/SkPDFUtils.h b/src/pdf/SkPDFUtils.h index 3ddd3d0933..a9194f2e72 100644 --- a/src/pdf/SkPDFUtils.h +++ b/src/pdf/SkPDFUtils.h @@ -57,6 +57,15 @@ void DrawFormXObject(int objectIndex, SkWStream* content); void ApplyGraphicState(int objectIndex, SkWStream* content); void ApplyPattern(int objectIndex, SkWStream* content); +// Converts (value / 255.0) with three significant digits of accuracy. +// Writes value as string into result. Returns strlen() of result. +size_t ColorToDecimal(uint8_t value, char result[5]); +inline void AppendColorComponent(uint8_t value, SkWStream* wStream) { + char buffer[5]; + size_t len = SkPDFUtils::ColorToDecimal(value, buffer); + wStream->write(buffer, len); +} + // 3 = '-', '.', and '\0' characters. // 9 = number of significant digits // abs(FLT_MIN_10_EXP) = number of zeros in FLT_MIN |