This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit 690d4ce80cb139771e35a9fd1dd2f835aa34bf2e
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Sat Dec 14 08:16:05 2024 +0100

    image: Add optional alpha check requested by loaders
---
 src/lib/Imlib2_Loader.h |  4 ++++
 src/lib/image.c         | 30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/src/lib/Imlib2_Loader.h b/src/lib/Imlib2_Loader.h
index 897e923..0466997 100644
--- a/src/lib/Imlib2_Loader.h
+++ b/src/lib/Imlib2_Loader.h
@@ -171,6 +171,10 @@ struct _ImlibImage {
     int             frame;
 };
 
+#define LDR_ALPHA_NO            0       /* No alpha */
+#define LDR_ALPHA_YES           1       /* Has alpha */
+#define LDR_ALPHA_CHECK         2       /* May have alpa pixels */
+
 /* Must match the ones in Imlib2.h.in */
 #define FF_IMAGE_ANIMATED       (1 << 0)        /* Frames are an animated sequence    */
 #define FF_FRAME_BLEND          (1 << 1)        /* Blend current onto previous frame  */
diff --git a/src/lib/image.c b/src/lib/image.c
index 9fcb389..cc01f4f 100644
--- a/src/lib/image.c
+++ b/src/lib/image.c
@@ -21,6 +21,10 @@
 #include "x11_pixmap.h"
 #endif
 
+#define LDR_ALPHA_NO            0       /* No alpha */
+#define LDR_ALPHA_YES           1       /* Has alpha */
+#define LDR_ALPHA_CHECK         2       /* May have alpa pixels */
+
 struct _ImlibImageFileInfo {
     struct _ImlibImageFileInfo *next;
     char           *name;
@@ -410,6 +414,26 @@ __imlib_CreateImage(int w, int h, uint32_t *data, int zero)
     return im;
 }
 
+static void
+__imlib_ImageCheckAlpha(ImlibImage *im)
+{
+    int             x, y;
+    const uint32_t *p;
+
+    p = im->data;
+
+    for (y = 0; y < im->h; y++)
+    {
+        for (x = 0; x < im->w; x++, p++)
+        {
+            if (A_VAL(p) != 0xff)
+                return;
+        }
+    }
+
+    im->has_alpha = 0;
+}
+
 static int
 __imlib_LoadImageWrapper(const ImlibLoader *l, ImlibImage *im, int load_data)
 {
@@ -444,6 +468,12 @@ __imlib_LoadImageWrapper(const ImlibLoader *l, ImlibImage *im, int load_data)
         im->format = NULL;
     }
 
+    if (load_data && im->has_alpha >= LDR_ALPHA_CHECK)
+    {
+        im->has_alpha = !!im->has_alpha;        /* Normalize */
+        __imlib_ImageCheckAlpha(im);
+    }
+
     return rc;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to