From e56b1f34a0bfa3684d086c98b890d85099c93464 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 12 Jan 2016 13:30:39 -0800 Subject: [PATCH] remove bilinear scaling, fix #3164 --- src/mbgl/sprite/sprite_atlas.cpp | 2 +- src/mbgl/util/scaling.cpp | 44 -------------------------- src/mbgl/util/scaling.hpp | 4 --- test/miscellaneous/bilinear.cpp | 54 -------------------------------- test/test.gypi | 1 - 5 files changed, 1 insertion(+), 104 deletions(-) delete mode 100644 test/miscellaneous/bilinear.cpp diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp index a20f6f0fe36..b7e482e253a 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -122,7 +122,7 @@ void SpriteAtlas::copy(const Holder& holder, const bool wrap) { static_cast(dst.originalW * pixelRatio), static_cast(dst.originalH * pixelRatio) }; - util::bilinearScale(srcData, srcSize, srcPos, dstData, dstSize, dstPos, wrap); + util::nearestNeighborScale(srcData, srcSize, srcPos, dstData, dstSize, dstPos); // Add borders around the copied image if required. if (wrap) { diff --git a/src/mbgl/util/scaling.cpp b/src/mbgl/util/scaling.cpp index 9b32650511a..1959e5ada6c 100644 --- a/src/mbgl/util/scaling.cpp +++ b/src/mbgl/util/scaling.cpp @@ -4,12 +4,6 @@ namespace { using namespace mbgl; -inline uint8_t bilinearInterpolate(uint8_t tl, uint8_t tr, uint8_t bl, uint8_t br, double dx, double dy) { - const double t = dx * (tr - tl) + tl; - const double b = dx * (br - bl) + bl; - return t + dy * (b - t); -} - template inline const uint8_t& b(const uint32_t& w) { return reinterpret_cast(&w)[i]; @@ -47,44 +41,6 @@ vec2 getBounds(const vec2& srcSize, const Rect& sr namespace mbgl { namespace util { -void bilinearScale(const uint32_t* srcData, const vec2& srcSize, - const Rect& srcPos, uint32_t* dstData, const vec2& dstSize, - const Rect& dstPos, bool wrap) { - const auto factor = getFactor(srcPos, dstPos); - const auto bounds = getBounds(srcSize, srcPos, dstSize, dstPos, factor); - - uint32_t x, y; - size_t i = dstSize.x * dstPos.y + dstPos.x; - for (y = 0; y < bounds.y; y++) { - const double fractY = y * factor.y; - const uint32_t Y0 = fractY; - const uint32_t Y1 = wrap ? (Y0 + 1) % srcPos.h : (Y0 + 1); - const uint32_t srcY0 = srcPos.y + Y0; - const uint32_t srcY1 = std::min(srcPos.y + Y1, srcSize.y - 1); - for (x = 0; x < bounds.x; x++) { - const double fractX = x * factor.x; - const uint32_t X0 = fractX; - const uint32_t X1 = wrap ? (X0 + 1) % srcPos.w : (X0 + 1); - const uint32_t srcX0 = srcPos.x + X0; - const uint32_t srcX1 = std::min(srcPos.x + X1, srcSize.x - 1); - - const uint32_t tl = srcData[srcSize.x * srcY0 + srcX0]; - const uint32_t tr = srcData[srcSize.x * srcY0 + srcX1]; - const uint32_t bl = srcData[srcSize.x * srcY1 + srcX0]; - const uint32_t br = srcData[srcSize.x * srcY1 + srcX1]; - - const double dx = fractX - X0; - const double dy = fractY - Y0; - uint32_t& dst = dstData[i + x]; - b<0>(dst) = bilinearInterpolate(b<0>(tl), b<0>(tr), b<0>(bl), b<0>(br), dx, dy); - b<1>(dst) = bilinearInterpolate(b<1>(tl), b<1>(tr), b<1>(bl), b<1>(br), dx, dy); - b<2>(dst) = bilinearInterpolate(b<2>(tl), b<2>(tr), b<2>(bl), b<2>(br), dx, dy); - b<3>(dst) = bilinearInterpolate(b<3>(tl), b<3>(tr), b<3>(bl), b<3>(br), dx, dy); - } - i += dstSize.x; - } -} - void nearestNeighborScale(const uint32_t* srcData, const vec2& srcSize, const Rect& srcPos, uint32_t* dstData, const vec2& dstSize, const Rect& dstPos) { diff --git a/src/mbgl/util/scaling.hpp b/src/mbgl/util/scaling.hpp index a2d582de1c0..b034afc42c1 100644 --- a/src/mbgl/util/scaling.hpp +++ b/src/mbgl/util/scaling.hpp @@ -10,10 +10,6 @@ namespace mbgl { namespace util { -void bilinearScale(const uint32_t* srcData, const vec2& srcSize, - const Rect& srcPos, uint32_t* dstData, const vec2& dstSize, - const Rect& dstPos, bool wrap); - void nearestNeighborScale(const uint32_t* srcData, const vec2& srcSize, const Rect& srcPos, uint32_t* dstData, const vec2& dstSize, const Rect& dstPos); diff --git a/test/miscellaneous/bilinear.cpp b/test/miscellaneous/bilinear.cpp deleted file mode 100644 index 3184e5739d4..00000000000 --- a/test/miscellaneous/bilinear.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "../fixtures/util.hpp" -#include -#include -#include -#include -#include - -#include -#include - -using namespace mbgl; - -TEST(Bilinear, Scaling) { - // We're reading from a custom "image format" that has a uint32_t width/height prefix and then - // raw RGBA data. We can't use the built-in PNG reading routines because they are reading - // premultiplied images by default. - const std::string sprite = util::decompress(util::read_file("test/fixtures/sprites/bright.bin")); - const uint8_t *src = reinterpret_cast(sprite.data()); - ASSERT_GT(sprite.length(), 8u); - const uint32_t width = src[0] << 24 | src[1] << 16 | src[2] << 8 | src[3]; - const uint32_t height = src[4] << 24 | src[5] << 16 | src[6] << 8 | src[7]; - ASSERT_EQ(sprite.length(), 2 * sizeof(uint32_t) + width * height * sizeof(uint32_t)); - - const uint32_t *srcData = reinterpret_cast(src + 8); - const vec2 srcSize { width, height }; - const vec2 dstSize { 128, 128 }; - - UnassociatedImage dst { dstSize.x, dstSize.y }; - uint32_t *dstData = reinterpret_cast(dst.data.get()); - std::fill(dstData, dstData + dstSize.x * dstSize.y, 0xFFFF00FF); - - util::bilinearScale(srcData, srcSize, { 0, 0, 24, 24 }, dstData, dstSize, { 8, 8, 24, 24 }, false); - util::bilinearScale(srcData, srcSize, { 26, 0, 24, 24 }, dstData, dstSize, { 0, 40, 48, 48 }, false); - util::bilinearScale(srcData, srcSize, { 26, 26, 24, 24 }, dstData, dstSize, { 52, 40, 36, 36 }, false); - util::bilinearScale(srcData, srcSize, { 26, 26, 24, 24 }, dstData, dstSize, { 52, 40, 36, 36 }, false); - util::bilinearScale(srcData, srcSize, { 104, 0, 24, 24 }, dstData, dstSize, { 96, 0, 48, 48 }, false); - util::bilinearScale(srcData, srcSize, { 52, 260, 24, 24 }, dstData, dstSize, { 108, 108, 38, 38 }, false); - util::bilinearScale(srcData, srcSize, { 380, 0, 24, 24 }, dstData, dstSize, { 36, 0, 24, 24 }, false); - util::bilinearScale(srcData, srcSize, { 396, 396, 24, 24 }, dstData, dstSize, { 0, 0, 50, 50 }, false); - util::bilinearScale(srcData, srcSize, { 380, 182, 12, 12 }, dstData, dstSize, { 52, 80, 24, 24 }, false); - - // From the bottom - util::bilinearScale(srcData, srcSize, { 252, 380, 12, 12 }, dstData, dstSize, { 0, 90, 12, 12 }, false); - util::bilinearScale(srcData, srcSize, { 252, 380, 12, 12 }, dstData, dstSize, { 18, 90, 24, 24 }, false); - - const std::string data { reinterpret_cast(dstData), dstSize.x * dstSize.y * sizeof(uint32_t) }; - util::write_file("test/fixtures/sprites/atlas_actual.png", encodePNG(util::premultiply(std::move(dst)))); - util::write_file("test/fixtures/sprites/atlas_actual.bin", util::compress(data)); - - const std::string reference = util::decompress(util::read_file("test/fixtures/sprites/atlas_reference.bin")); - - EXPECT_EQ(reference.size(), data.size()); - EXPECT_TRUE(0 == std::memcmp(data.data(), reference.data(), data.size())); -} diff --git a/test/test.gypi b/test/test.gypi index 6a6ba507c64..44334b2c215 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -47,7 +47,6 @@ 'miscellaneous/async_task.cpp', 'miscellaneous/clip_ids.cpp', 'miscellaneous/binpack.cpp', - 'miscellaneous/bilinear.cpp', 'miscellaneous/comparisons.cpp', 'miscellaneous/functions.cpp', 'miscellaneous/geo.cpp',