[vte/wip/sixels: 57/111] sixel: Output premultiplied alpha




commit 706e581a1d279698439240d94aaee9c0b0e30a67
Author: Hans Petter Jansson <hpj cl no>
Date:   Sat Aug 8 20:42:49 2020 +0200

    sixel: Output premultiplied alpha

 src/sixel.cc | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/src/sixel.cc b/src/sixel.cc
index 94151398..035c8752 100644
--- a/src/sixel.cc
+++ b/src/sixel.cc
@@ -328,11 +328,26 @@ sixel_parser_finalize(sixel_state_t *st, unsigned char *pixels)
        dst = pixels;
        for (y = 0; y < st->image.height; ++y) {
                for (x = 0; x < st->image.width; ++x) {
-                       color = st->image.palette[*src++];
-                       *dst++ = color >> 16 & 0xff;   /* b */
-                       *dst++ = color >> 8 & 0xff;    /* g */
-                       *dst++ = color >> 0 & 0xff;    /* r */
-                       *dst++ = 0xff;                 /* a */
+                        sixel_color_no_t pen = *src++;
+
+                        /* FIXME-hpj: We may want to make this branch-free, among other
+                         * performance improvements. */
+
+                        if (pen == 0) {
+                                /* Cairo wants premultiplied alpha: Transparent
+                                 * areas must be all zeroes. */
+
+                                *dst++ = 0;
+                                *dst++ = 0;
+                                *dst++ = 0;
+                                *dst++ = 0;
+                        } else {
+                                color = st->image.palette[pen];
+                                *dst++ = color >> 16 & 0xff;   /* b */
+                                *dst++ = color >> 8 & 0xff;    /* g */
+                                *dst++ = color >> 0 & 0xff;    /* r */
+                                *dst++ = 0xff;                 /* a */
+                        }
                }
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]