summaryrefslogtreecommitdiff
path: root/platform/default/png_reader.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-08-04 17:45:26 +0200
committerKonstantin Käfer <mail@kkaefer.com>2015-08-04 18:49:51 +0200
commit56a4268ccaf34fbb5e45d3a63c27efea9e23178e (patch)
treeb595fb186e90f7e98e665ef4ffafdd2ebbf30d93 /platform/default/png_reader.cpp
parent3b4a0b228cd95f203e12c224db99e27fe1132cf0 (diff)
downloadqtlocation-mapboxgl-56a4268ccaf34fbb5e45d3a63c27efea9e23178e.tar.gz
manually premultiply the image if libpng can't do it
Diffstat (limited to 'platform/default/png_reader.cpp')
-rw-r--r--platform/default/png_reader.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp
index 42b6946096..04f547d8ec 100644
--- a/platform/default/png_reader.cpp
+++ b/platform/default/png_reader.cpp
@@ -160,8 +160,6 @@ void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char *
#ifdef PNG_ALPHA_PREMULTIPLIED
png_set_alpha_mode(png_ptr, PNG_ALPHA_PREMULTIPLIED, PNG_GAMMA_LINEAR);
-#else
- // TODO: Manually premultiply the image data.
#endif
if (x0 == 0 && y0 == 0 && w >= width_ && h >= height_)
@@ -180,6 +178,20 @@ void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char *
for (unsigned row = 0; row < height_; ++row)
rows[row] = (png_bytep)image + row * width_ * 4 ;
png_read_image(png_ptr, rows.get());
+ fprintf(stderr, "manual premultiplication\n");
+
+#ifndef PNG_ALPHA_PREMULTIPLIED
+ // Manually premultiply the image if libpng didn't do it for us.
+ for (unsigned row = 0; row < height_; ++row) {
+ for (unsigned x = 0; x < width_; x++) {
+ png_byte* ptr = &(rows[row][x * 4]);
+ const float a = ptr[3] / 255.0f;
+ ptr[0] *= a;
+ ptr[1] *= a;
+ ptr[2] *= a;
+ }
+ }
+#endif
}
else
{
@@ -193,6 +205,7 @@ void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char *
png_read_row(png_ptr,row.get(),0);
if (i >= y0 && i < (y0 + h))
{
+ // TODO: premultiply this
std::copy(&row[x0 * 4], &row[x0 * 4] + w * 4, image + i * width_* 4);
}
}