summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-11-25 13:49:12 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-11-25 15:57:37 -0800
commit1d33790dc06a1127e55753d123d55e6ec6e89713 (patch)
tree3db9915f722dada6375a273297647cc1b0c9df51 /src
parented5eb9edc1458692bf6ff71d5ec95a7d3400318f (diff)
downloadqtlocation-mapboxgl-1d33790dc06a1127e55753d123d55e6ec6e89713.tar.gz
[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.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/view.cpp2
-rw-r--r--src/mbgl/util/premultiply.cpp35
-rw-r--r--src/mbgl/util/premultiply.hpp1
3 files changed, 31 insertions, 7 deletions
diff --git a/src/mbgl/map/view.cpp b/src/mbgl/map/view.cpp
index fa8b7584cc..efbe0f1672 100644
--- a/src/mbgl/map/view.cpp
+++ b/src/mbgl/map/view.cpp
@@ -10,7 +10,7 @@ void View::initialize(Map *map_) {
map = map_;
}
-UnassociatedImage View::readStillImage() {
+PremultipliedImage View::readStillImage() {
return {};
}
diff --git a/src/mbgl/util/premultiply.cpp b/src/mbgl/util/premultiply.cpp
index 3ee5a1e129..8a62012251 100644
--- a/src/mbgl/util/premultiply.cpp
+++ b/src/mbgl/util/premultiply.cpp
@@ -6,14 +6,14 @@ namespace mbgl {
namespace util {
PremultipliedImage premultiply(UnassociatedImage&& src) {
- PremultipliedImage dst;
+ PremultipliedImage dst;
- dst.width = src.width;
- dst.height = src.height;
- dst.data = std::move(src.data);
+ dst.width = src.width;
+ dst.height = src.height;
+ dst.data = std::move(src.data);
- uint8_t* data = dst.data.get();
- for (size_t i = 0; i < dst.size(); i += 4) {
+ 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];
@@ -26,5 +26,28 @@ PremultipliedImage premultiply(UnassociatedImage&& src) {
return std::move(dst);
}
+UnassociatedImage unpremultiply(PremultipliedImage&& src) {
+ UnassociatedImage dst;
+
+ dst.width = src.width;
+ dst.height = src.height;
+ dst.data = std::move(src.data);
+
+ 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);
+}
+
}
}
diff --git a/src/mbgl/util/premultiply.hpp b/src/mbgl/util/premultiply.hpp
index 9d9dcc6468..8d87c157c8 100644
--- a/src/mbgl/util/premultiply.hpp
+++ b/src/mbgl/util/premultiply.hpp
@@ -7,6 +7,7 @@ namespace mbgl {
namespace util {
PremultipliedImage premultiply(UnassociatedImage&&);
+UnassociatedImage unpremultiply(PremultipliedImage&&);
}
}