Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
remove bilinear scaling, fix #3164
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Jan 13, 2016
1 parent 1d791ca commit e56b1f3
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 104 deletions.
2 changes: 1 addition & 1 deletion src/mbgl/sprite/sprite_atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void SpriteAtlas::copy(const Holder& holder, const bool wrap) {
static_cast<uint32_t>(dst.originalW * pixelRatio),
static_cast<uint32_t>(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) {
Expand Down
44 changes: 0 additions & 44 deletions src/mbgl/util/scaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <size_t i>
inline const uint8_t& b(const uint32_t& w) {
return reinterpret_cast<const uint8_t*>(&w)[i];
Expand Down Expand Up @@ -47,44 +41,6 @@ vec2<uint32_t> getBounds(const vec2<uint32_t>& srcSize, const Rect<uint32_t>& sr
namespace mbgl {
namespace util {

void bilinearScale(const uint32_t* srcData, const vec2<uint32_t>& srcSize,
const Rect<uint32_t>& srcPos, uint32_t* dstData, const vec2<uint32_t>& dstSize,
const Rect<uint32_t>& 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<uint32_t>& srcSize,
const Rect<uint32_t>& srcPos, uint32_t* dstData,
const vec2<uint32_t>& dstSize, const Rect<uint32_t>& dstPos) {
Expand Down
4 changes: 0 additions & 4 deletions src/mbgl/util/scaling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
namespace mbgl {
namespace util {

void bilinearScale(const uint32_t* srcData, const vec2<uint32_t>& srcSize,
const Rect<uint32_t>& srcPos, uint32_t* dstData, const vec2<uint32_t>& dstSize,
const Rect<uint32_t>& dstPos, bool wrap);

void nearestNeighborScale(const uint32_t* srcData, const vec2<uint32_t>& srcSize,
const Rect<uint32_t>& srcPos, uint32_t* dstData,
const vec2<uint32_t>& dstSize, const Rect<uint32_t>& dstPos);
Expand Down
54 changes: 0 additions & 54 deletions test/miscellaneous/bilinear.cpp

This file was deleted.

1 change: 0 additions & 1 deletion test/test.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e56b1f3

Please sign in to comment.