From eb92cb3e84f49b5eedb22b36acffd895d6a90e5a Mon Sep 17 00:00:00 2001 From: halcanary Date: Fri, 15 Jul 2016 13:41:27 -0700 Subject: 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 --- tests/PDFPrimitivesTest.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/PDFPrimitivesTest.cpp') diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 9e2a89e609..d816b60823 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -491,3 +491,16 @@ DEF_TEST(PDFPrimitives_Scalar, reporter) { check_pdf_scalar_serialization(reporter, inputFloat); } } + +// Test SkPDFUtils:: for accuracy. +DEF_TEST(PDFPrimitives_Color, reporter) { + char buffer[5]; + for (int i = 0; i < 256; ++i) { + size_t len = SkPDFUtils::ColorToDecimal(i, buffer); + REPORTER_ASSERT(reporter, len == strlen(buffer)); + float f; + REPORTER_ASSERT(reporter, 1 == sscanf(buffer, "%f", &f)); + int roundTrip = (int)(0.5 + f * 255); + REPORTER_ASSERT(reporter, roundTrip == i); + } +} -- cgit v1.2.3