From 1d33790dc06a1127e55753d123d55e6ec6e89713 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 25 Nov 2015 13:49:12 -0800 Subject: [core] Fix image type of Map::renderStill It's a premultiplied image. This implies that we were misusing encodePNG in most cases, as we were passing premultiplied pixels which were then interpreted as unmultiplied. I changed encodePNG to accept premultipled pixels, and unpremultiply in the implementations. --- test/fixtures/util.cpp | 34 +++------------------------------- test/fixtures/util.hpp | 2 +- 2 files changed, 4 insertions(+), 32 deletions(-) (limited to 'test/fixtures') diff --git a/test/fixtures/util.cpp b/test/fixtures/util.cpp index aa6371a4c7..ebd530eaac 100644 --- a/test/fixtures/util.cpp +++ b/test/fixtures/util.cpp @@ -85,45 +85,17 @@ uint64_t crc64(const std::string& str) { return crc64(str.data(), str.size()); } -UnassociatedImage unpremultiply(const PremultipliedImage& src) { - UnassociatedImage dst { src.width, src.height }; - std::copy(src.data.get(), src.data.get() + src.size(), dst.data.get()); - - uint8_t* data = dst.data.get(); - for (size_t i = 0; i < dst.size(); i += 4) { - uint8_t& r = data[i + 0]; - uint8_t& g = data[i + 1]; - uint8_t& b = data[i + 2]; - uint8_t& a = data[i + 3]; - if (a) { - r = (255 * r + (a / 2)) / a; - g = (255 * g + (a / 2)) / a; - b = (255 * b + (a / 2)) / a; - } - } - - return std::move(dst); -} - void checkImage(const std::string& base, - const UnassociatedImage& actual, + const PremultipliedImage& actual, double imageThreshold, double pixelThreshold) { - // TODO: the pixels produced by Map::renderStill are probably actually premultiplied, - // but Map::renderStill produces an UnassociatedImage. This probably should be fixed; - // here we just hack around it by copying the pixels to a PremultipliedImage (and - // un-premultiplying them when updating expected.png, since encodePNG wants - // un-premultiplied pixels). - PremultipliedImage actualActual { actual.width, actual.height }; - std::copy(actual.data.get(), actual.data.get() + actual.size(), actualActual.data.get()); - if (getenv("UPDATE")) { - util::write_file(base + "/expected.png", encodePNG(unpremultiply(actualActual))); + util::write_file(base + "/expected.png", encodePNG(actual)); return; } PremultipliedImage expected = decodeImage(util::read_file(base + "/expected.png")); - UnassociatedImage diff { expected.width, expected.height }; + PremultipliedImage diff { expected.width, expected.height }; ASSERT_EQ(expected.width, actual.width); ASSERT_EQ(expected.height, actual.height); diff --git a/test/fixtures/util.hpp b/test/fixtures/util.hpp index b369979e9c..16edfbace3 100644 --- a/test/fixtures/util.hpp +++ b/test/fixtures/util.hpp @@ -25,7 +25,7 @@ uint64_t crc64(const char*, size_t); uint64_t crc64(const std::string&); void checkImage(const std::string& base, - const UnassociatedImage& actual, + const PremultipliedImage& actual, double imageThreshold = 0, double pixelThreshold = 0); -- cgit v1.2.1