summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-11-23 14:17:40 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-11-25 15:57:36 -0800
commitf3d6f68106e60ac0d697202a8e32fa1466d38151 (patch)
treec0ce3fc1b89d568bd792ba9ea0a4136263b00f48 /src
parent0c1e378bc9555f6cf826bb38b1a36fa742f8ce9b (diff)
downloadqtlocation-mapboxgl-f3d6f68106e60ac0d697202a8e32fa1466d38151.tar.gz
[core] Always manually premultiply libpng output
It appears to be the only way to get the results we want in all cases.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/premultiply.cpp30
-rw-r--r--src/mbgl/util/premultiply.hpp14
2 files changed, 44 insertions, 0 deletions
diff --git a/src/mbgl/util/premultiply.cpp b/src/mbgl/util/premultiply.cpp
new file mode 100644
index 0000000000..3ee5a1e129
--- /dev/null
+++ b/src/mbgl/util/premultiply.cpp
@@ -0,0 +1,30 @@
+#include <mbgl/util/premultiply.hpp>
+
+#include <cmath>
+
+namespace mbgl {
+namespace util {
+
+PremultipliedImage premultiply(UnassociatedImage&& src) {
+ PremultipliedImage 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];
+ r = (r * a + 127) / 255;
+ g = (g * a + 127) / 255;
+ b = (b * a + 127) / 255;
+ }
+
+ return std::move(dst);
+}
+
+}
+}
diff --git a/src/mbgl/util/premultiply.hpp b/src/mbgl/util/premultiply.hpp
new file mode 100644
index 0000000000..9d9dcc6468
--- /dev/null
+++ b/src/mbgl/util/premultiply.hpp
@@ -0,0 +1,14 @@
+#ifndef MBGL_UTIL_PREMULTIPLY
+#define MBGL_UTIL_PREMULTIPLY
+
+#include <mbgl/util/image.hpp>
+
+namespace mbgl {
+namespace util {
+
+PremultipliedImage premultiply(UnassociatedImage&&);
+
+}
+}
+
+#endif