From: Benjamin Otte Date: Fri, 21 Jul 2023 23:29:24 +0000 (+0200) Subject: gdk: Make A8 and A16 formats premultiplied X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~52^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4a8122f6859f268bc886133164b5d055a2c89bad;p=gtk4.git gdk: Make A8 and A16 formats premultiplied The relevant question here is about details, because we have to choose if we declare alpha-only formats as having their (nonexistant) color channels premultiplied or not, so that the code paths using them can do the right thing. Because we are premultiplied by default, it makes sense to treat alpha like that, because then the alpha-only code doesn't need to do workarounds for straight alpha. Where this is relevant of course is when expanding the alpha channel into color channels, where we want to end up with white. So make sure we do color = alpha there instead of color = 1 like we did before. --- diff --git a/gdk/gdkmemoryformat.c b/gdk/gdkmemoryformat.c index 40fea6987e..95663e9ba7 100644 --- a/gdk/gdkmemoryformat.c +++ b/gdk/gdkmemoryformat.c @@ -69,9 +69,9 @@ name ## _to_float (float *dest, \ for (gsize i = 0; i < n; i++) \ { \ T *src = (T *) (src_data + i * bpp); \ - if (G >= 0) dest[0] = (float) src[G] / scale; else dest[0] = 1.0; \ - dest[1] = dest[2] = dest[0]; \ if (A >= 0) dest[3] = (float) src[A] / scale; else dest[3] = 1.0; \ + if (G >= 0) dest[0] = (float) src[G] / scale; else dest[0] = dest[3]; \ + dest[1] = dest[2] = dest[0]; \ dest += 4; \ } \ } \ @@ -588,22 +588,22 @@ static const GdkMemoryFormatDescription memory_formats[] = { g16_from_float, }, [GDK_MEMORY_A8] = { - GDK_MEMORY_ALPHA_STRAIGHT, + GDK_MEMORY_ALPHA_PREMULTIPLIED, 1, G_ALIGNOF (guchar), GDK_MEMORY_U8, { 0, 0, 3, 0 }, - { GL_R8, GL_RED, GL_UNSIGNED_BYTE, { GL_ONE, GL_ONE, GL_ONE, GL_RED } }, + { GL_R8, GL_RED, GL_UNSIGNED_BYTE, { GL_RED, GL_RED, GL_RED, GL_RED } }, a8_to_float, a8_from_float, }, [GDK_MEMORY_A16] = { - GDK_MEMORY_ALPHA_STRAIGHT, + GDK_MEMORY_ALPHA_PREMULTIPLIED, 2, G_ALIGNOF (guint16), GDK_MEMORY_U16, { 0, 0, 3, 0 }, - { GL_R16, GL_RED, GL_UNSIGNED_SHORT, { GL_ONE, GL_ONE, GL_ONE, GL_RED } }, + { GL_R16, GL_RED, GL_UNSIGNED_SHORT, { GL_RED, GL_RED, GL_RED, GL_RED } }, a16_to_float, a16_from_float, }, diff --git a/testsuite/gdk/memorytexture.c b/testsuite/gdk/memorytexture.c index c963be8c5b..c42bda7024 100644 --- a/testsuite/gdk/memorytexture.c +++ b/testsuite/gdk/memorytexture.c @@ -287,6 +287,8 @@ gdk_memory_format_is_premultiplied (GdkMemoryFormat format) case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED: case GDK_MEMORY_G8A8_PREMULTIPLIED: case GDK_MEMORY_G16A16_PREMULTIPLIED: + case GDK_MEMORY_A8: + case GDK_MEMORY_A16: case GDK_MEMORY_A16_FLOAT: case GDK_MEMORY_A32_FLOAT: return TRUE; @@ -307,8 +309,6 @@ gdk_memory_format_is_premultiplied (GdkMemoryFormat format) case GDK_MEMORY_G8A8: case GDK_MEMORY_G16: case GDK_MEMORY_G16A16: - case GDK_MEMORY_A8: - case GDK_MEMORY_A16: return FALSE; case GDK_MEMORY_N_FORMATS: