Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Decode images without alpha channel to RGB buffers #4

Closed
kkaefer opened this Issue Jun 1, 2011 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

kkaefer commented Jun 1, 2011

...and don't do alpha blending for the lower layer. Could save us some time because we don't need to stretch out RGB buffers from decoded JPEGs to RGBA buffers.

Member

springmeyer commented Dec 6, 2012

In addition I wonder if we could see more gains from aggressively checking if images that may report themselves as png rgba are actually totally opaque:

something like this:

diff --git a/src/blend.cpp b/src/blend.cpp
index 4a45426..4e0344d 100644
--- a/src/blend.cpp
+++ b/src/blend.cpp
@@ -622,6 +622,29 @@ WORKER_BEGIN(Work_Blend) {
             }
         }

+        unsigned int *source = image->reader->surface;
+        int sourceX = std::max(0, -image->x);
+        int sourceY = std::max(0, -image->y);
+        int sourcePos = sourceY * image->width + sourceX;
+        int width = image->width - sourceX - std::max(0, image->x + image->width - baton->width);
+        int height = image->height - sourceY - std::max(0, image->y + image->height - baton->height);
+
+        unsigned has_alpha = false;
+        for (unsigned int y = 0; y < height; ++y)
+        {
+            for (unsigned int x = 0; x < width; ++x)
+            {
+                unsigned int& source_pixel = source[sourcePos + x];
+                unsigned a = (source_pixel >> 24) & 0xff;
+                if (a != 255)
+                    has_alpha = true;
+            }
+        }
+        if (!has_alpha) {
+            //std::clog << "no alpha for layer: " << index << "\n";
+            layer->alpha = false;
+        }
+
         bool coversWidth = image->x <= 0 && visibleWidth >= baton->width;
         bool coversHeight = image->y <= 0 && visibleHeight >= baton->height;
         if (!layer->alpha && coversWidth && coversHeight) {
@@ -634,6 +657,7 @@ WORKER_BEGIN(Work_Blend) {
         image->height = layer->height;
         image->reader = layer;
         size++;
+
     }
Member

springmeyer commented Jul 29, 2014

obsolete after #49 lands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment