gdk: speed up gray image drawing

This commit is contained in:
Daemonratte 2026-08-19 22:23:32 +02:00
commit 863f708271

View file

@ -3415,6 +3415,50 @@ gdk_rgb_gray_to_stage (GdkRgbInfo *image_info,
/* Generic gray conversion function - convert to 24bit packed, then go
from there. */
static void
gdk_rgb_convert_gray_0888_native (GdkRgbInfo *image_info, GdkImage *image,
gint x0, gint y0, gint width, gint height,
const guchar *buf, gint rowstride,
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
gint y, w;
gint bpl = image->bpl;
guchar *obuf = ((guchar *) image->mem) + y0 * bpl + x0 * 4;
for (y = 0; y < height; y++)
{
const guchar *p = buf;
guchar *q = obuf;
w = width;
while (w--)
{
guchar g = *p++;
/*
* Store bytes explicitly here. Word-store performance varies by
* microarchitecture even within one ISA, so keep this generic path
* free of CPU-specific runtime dispatch.
*/
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
q[0] = g;
q[1] = g;
q[2] = g;
q[3] = 0xff;
#else
q[0] = 0xff;
q[1] = g;
q[2] = g;
q[3] = g;
#endif
q += 4;
}
buf += rowstride;
obuf += bpl;
}
}
static void
gdk_rgb_convert_gray_generic (GdkRgbInfo *image_info, GdkImage *image,
gint x0, gint y0, gint width, gint height,
@ -3787,14 +3831,34 @@ gdk_rgb_select_conv (GdkRgbInfo *image_info)
conv_d = conv;
if (conv == gdk_rgb_convert_0888)
conv_32 = gdk_rgb_convert_32_0888;
{
conv_32 = gdk_rgb_convert_32_0888;
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
conv_gray = gdk_rgb_convert_gray_0888_native;
#endif
}
else if (conv == gdk_rgb_convert_0888_br)
conv_32 = gdk_rgb_convert_32_0888_br;
{
conv_32 = gdk_rgb_convert_32_0888_br;
#if G_BYTE_ORDER == G_BIG_ENDIAN
conv_gray = gdk_rgb_convert_gray_0888_native;
#endif
}
if (conv_d == gdk_rgb_convert_0888)
conv_32_d = gdk_rgb_convert_32_0888;
{
conv_32_d = gdk_rgb_convert_32_0888;
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
conv_gray_d = gdk_rgb_convert_gray_0888_native;
#endif
}
else if (conv_d == gdk_rgb_convert_0888_br)
conv_32_d = gdk_rgb_convert_32_0888_br;
{
conv_32_d = gdk_rgb_convert_32_0888_br;
#if G_BYTE_ORDER == G_BIG_ENDIAN
conv_gray_d = gdk_rgb_convert_gray_0888_native;
#endif
}
image_info->conv = conv;
image_info->conv_d = conv_d;