gdk: speed up RGB32 drawing

This commit is contained in:
Daemonratte 2026-08-18 20:57:39 +02:00
commit 43d974d20f

View file

@ -3247,6 +3247,83 @@ gdk_rgb_ensure_stage (GdkRgbInfo *image_info)
return image_info->stage_buf;
}
static void
gdk_rgb_convert_32_0888 (GdkRgbInfo *image_info, GdkImage *image,
gint x0, gint y0, gint width, gint height,
const guchar *buf, int rowstride,
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
int y, w;
guchar *obuf, *p;
gint bpl;
const guchar *bptr, *bp2;
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4;
for (y = 0; y < height; y++)
{
bp2 = bptr;
p = obuf;
w = width;
while (w--)
{
#if G_BYTE_ORDER == G_LITTLE_ENDIAN && GLIB_SIZEOF_VOID_P == 8 && \
(defined(__x86_64__) || defined(__amd64__))
guint32 pixel;
pixel = 0xff000000U |
((guint32) bp2[0] << 16) |
((guint32) bp2[1] << 8) |
(guint32) bp2[2];
memcpy (p, &pixel, sizeof (pixel));
#else
p[0] = bp2[2];
p[1] = bp2[1];
p[2] = bp2[0];
p[3] = 0xff;
#endif
bp2 += 4;
p += 4;
}
bptr += rowstride;
obuf += bpl;
}
}
static void
gdk_rgb_convert_32_0888_br (GdkRgbInfo *image_info, GdkImage *image,
gint x0, gint y0, gint width, gint height,
const guchar *buf, int rowstride,
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
int y, w;
guchar *obuf, *p;
gint bpl;
const guchar *bptr, *bp2;
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4;
for (y = 0; y < height; y++)
{
bp2 = bptr;
p = obuf;
w = width;
while (w--)
{
p[0] = 0xff;
p[1] = bp2[0];
p[2] = bp2[1];
p[3] = bp2[2];
bp2 += 4;
p += 4;
}
bptr += rowstride;
obuf += bpl;
}
}
/* This is slow. Speed me up, please. */
static void
gdk_rgb_32_to_stage (GdkRgbInfo *image_info,
@ -3709,6 +3786,16 @@ gdk_rgb_select_conv (GdkRgbInfo *image_info)
if (conv_d == NULL)
conv_d = conv;
if (conv == gdk_rgb_convert_0888)
conv_32 = gdk_rgb_convert_32_0888;
else if (conv == gdk_rgb_convert_0888_br)
conv_32 = gdk_rgb_convert_32_0888_br;
if (conv_d == gdk_rgb_convert_0888)
conv_32_d = gdk_rgb_convert_32_0888;
else if (conv_d == gdk_rgb_convert_0888_br)
conv_32_d = gdk_rgb_convert_32_0888_br;
image_info->conv = conv;
image_info->conv_d = conv_d;