summaryrefslogtreecommitdiff
path: root/platform
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 /platform
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 'platform')
-rw-r--r--platform/darwin/image.mm4
-rw-r--r--platform/default/headless_view.cpp4
-rw-r--r--platform/default/image.cpp8
-rw-r--r--platform/node/src/node_map.cpp2
-rw-r--r--platform/node/src/node_map.hpp2
5 files changed, 13 insertions, 7 deletions
diff --git a/platform/darwin/image.mm b/platform/darwin/image.mm
index e7187366b9..854b9157f8 100644
--- a/platform/darwin/image.mm
+++ b/platform/darwin/image.mm
@@ -10,7 +10,7 @@
namespace mbgl {
-std::string encodePNG(const UnassociatedImage& src) {
+std::string encodePNG(const PremultipliedImage& src) {
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, src.data.get(), src.size(), NULL);
if (!provider) {
return "";
@@ -23,7 +23,7 @@ std::string encodePNG(const UnassociatedImage& src) {
}
CGImageRef image = CGImageCreate(src.width, src.height, 8, 32, 4 * src.width, color_space,
- kCGBitmapByteOrderDefault | kCGImageAlphaLast, provider, NULL, false,
+ kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast, provider, NULL, false,
kCGRenderingIntentDefault);
if (!image) {
CGColorSpaceRelease(color_space);
diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp
index d96b3ffcd1..d6fd892700 100644
--- a/platform/default/headless_view.cpp
+++ b/platform/default/headless_view.cpp
@@ -167,13 +167,13 @@ void HeadlessView::resize(const uint16_t width, const uint16_t height) {
needsResize = true;
}
-UnassociatedImage HeadlessView::readStillImage() {
+PremultipliedImage HeadlessView::readStillImage() {
assert(isActive());
const unsigned int w = dimensions[0] * pixelRatio;
const unsigned int h = dimensions[1] * pixelRatio;
- UnassociatedImage image { w, h };
+ PremultipliedImage image { w, h };
MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get()));
const int stride = image.stride();
diff --git a/platform/default/image.cpp b/platform/default/image.cpp
index dc28c68ef9..bf8071af5c 100644
--- a/platform/default/image.cpp
+++ b/platform/default/image.cpp
@@ -1,5 +1,6 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/string.hpp>
+#include <mbgl/util/premultiply.hpp>
#include <png.h>
@@ -19,7 +20,12 @@ const static bool png_version_check = []() {
#pragma GCC diagnostic pop
namespace mbgl {
-std::string encodePNG(const UnassociatedImage& src) {
+std::string encodePNG(const PremultipliedImage& pre) {
+ PremultipliedImage copy { pre.width, pre.height };
+ std::copy(pre.data.get(), pre.data.get() + pre.size(), copy.data.get());
+
+ UnassociatedImage src = util::unpremultiply(std::move(copy));
+
png_voidp error_ptr = 0;
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, error_ptr, NULL, NULL);
if (!png_ptr) {
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 0ce7d9398b..d4c551d666 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -300,7 +300,7 @@ void NodeMap::startRender(std::unique_ptr<NodeMap::RenderOptions> options) {
map->setBearing(options->bearing);
map->setPitch(options->pitch);
- map->renderStill([this](const std::exception_ptr eptr, mbgl::UnassociatedImage&& result) {
+ map->renderStill([this](const std::exception_ptr eptr, mbgl::PremultipliedImage&& result) {
if (eptr) {
error = std::move(eptr);
uv_async_send(async);
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index 455d38e957..23cd3c9fab 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -49,7 +49,7 @@ public:
std::unique_ptr<mbgl::Map> map;
std::exception_ptr error;
- mbgl::UnassociatedImage image;
+ mbgl::PremultipliedImage image;
std::unique_ptr<Nan::Callback> callback;
// Async for delivering the notifications of render completion.