summaryrefslogtreecommitdiff
path: root/gdk/gdkrgb.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2005-05-09 22:54:10 +0000
committerOwen Taylor <otaylor@src.gnome.org>2005-05-09 22:54:10 +0000
commit485fd851791e731e3b919a78033c44f5ec5e1081 (patch)
treefdb4b4524a5af9238645003346a6ef476e3e44ae /gdk/gdkrgb.c
parente899aa852a9ac34558e689480c02c90e8f4d02cb (diff)
downloadgtk+-485fd851791e731e3b919a78033c44f5ec5e1081.tar.gz
Fill in unused bits so they can be used for the depth-32 target case.
2005-05-09 Owen Taylor <otaylor@redhat.com> * gdk/gdkrgb.c (gdk_rgb_convert_0888_br, gdk_rgb_convert_8880_br): Fill in unused bits so they can be used for the depth-32 target case. Rewrite so that that gives a marginal speedup rather than a marginal slowdown. (on x86) * gdk/gdkscreen.h gdk/x11/gdkscreen-x11.[ch] gdk/x11/gdkvisual-x11.c: Add gdk_screen_get_rgba_colormap/visual to get a visual for windows with an alpha channel, if one exists. * gdk/win32/gdkscreen-win32.c gdk/linux-fb/gdkscreen-fb.c: Stub out gdk_screen_get_rgba_colormap/visual. * gdk/x11/gdkcolor-x11.c (gdk_colormap_alloc_colors): computation of "unused" wasn't right for depth == 32, since it depended on shifting by 32. * gdk/gdkrgb.c: Fill in alpha bits with 1s. (Based on patch from Keith Packard, http://mail.gnome.org/archives/gtk-devel-list/2004-June/msg00080.html) * gdk/x11/gdkdrawable-x11.c (gdk_x11_drawable_get_picture): Implement again, without using Xft. * tests/testgtk.c: Add a test for windows with an alpha channel.
Diffstat (limited to 'gdk/gdkrgb.c')
-rw-r--r--gdk/gdkrgb.c92
1 files changed, 67 insertions, 25 deletions
diff --git a/gdk/gdkrgb.c b/gdk/gdkrgb.c
index e8c1e53602..d78584216d 100644
--- a/gdk/gdkrgb.c
+++ b/gdk/gdkrgb.c
@@ -719,6 +719,23 @@ gdk_rgb_get_info_from_colormap (GdkColormap *cmap)
return image_info;
}
+static guint32
+gdk_rgb_alpha_mask (GdkRgbInfo *image_info)
+{
+ guint padding;
+
+ /* Shifting by >= width-of-type isn't defined in C */
+ if (image_info->visual->depth >= 32)
+ padding = 0;
+ else
+ padding = ((~(guint32)0)) << image_info->visual->depth;
+
+ return ~(image_info->visual->red_mask |
+ image_info->visual->green_mask |
+ image_info->visual->blue_mask |
+ padding);
+}
+
static gulong
gdk_rgb_xpixel_from_rgb_internal (GdkColormap *colormap,
guint16 r, guint16 g, guint16 b)
@@ -767,6 +784,7 @@ gdk_rgb_xpixel_from_rgb_internal (GdkColormap *colormap,
pixel = (unused + ((r >> (16 - image_info->visual->red_prec)) << image_info->visual->red_shift) +
((g >> (16 - image_info->visual->green_prec)) << image_info->visual->green_shift) +
((b >> (16 - image_info->visual->blue_prec)) << image_info->visual->blue_shift));
+ pixel |= gdk_rgb_alpha_mask (image_info);
}
else if (image_info->visual->type == GDK_VISUAL_STATIC_GRAY ||
image_info->visual->type == GDK_VISUAL_GRAYSCALE)
@@ -2126,11 +2144,10 @@ gdk_rgb_convert_0888 (GdkRgbInfo *image_info, GdkImage *image,
guchar *buf, int rowstride,
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
- int x, y;
- guchar *obuf;
+ int y, w;
+ guchar *obuf, *p;
gint bpl;
guchar *bptr, *bp2;
- int r, g, b;
bptr = buf;
bpl = image->bpl;
@@ -2138,13 +2155,16 @@ gdk_rgb_convert_0888 (GdkRgbInfo *image_info, GdkImage *image,
for (y = 0; y < height; y++)
{
bp2 = bptr;
- for (x = 0; x < width; x++)
+ p = obuf;
+ w = width;
+ while (w--)
{
- r = bp2[0];
- g = bp2[1];
- b = bp2[2];
- ((guint32 *)obuf)[x] = (r << 16) | (g << 8) | b;
+ p[0] = bp2[2];
+ p[1] = bp2[1];
+ p[2] = bp2[0];
+ p[3] = 0xff;
bp2 += 3;
+ p += 4;
}
bptr += rowstride;
obuf += bpl;
@@ -2157,11 +2177,10 @@ gdk_rgb_convert_0888_br (GdkRgbInfo *image_info, GdkImage *image,
guchar *buf, int rowstride,
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
- int x, y;
- guchar *obuf;
+ int y, w;
+ guchar *obuf, *p;
gint bpl;
guchar *bptr, *bp2;
- int r, g, b;
bptr = buf;
bpl = image->bpl;
@@ -2169,13 +2188,16 @@ gdk_rgb_convert_0888_br (GdkRgbInfo *image_info, GdkImage *image,
for (y = 0; y < height; y++)
{
bp2 = bptr;
- for (x = 0; x < width; x++)
+ p = obuf;
+ w = width;
+ while (w--)
{
- r = bp2[0];
- g = bp2[1];
- b = bp2[2];
- ((guint32 *)obuf)[x] = (b << 24) | (g << 16) | (r << 8);
+ p[0] = 0xff;
+ p[1] = bp2[0];
+ p[2] = bp2[1];
+ p[3] = bp2[2];
bp2 += 3;
+ p += 4;
}
bptr += rowstride;
obuf += bpl;
@@ -2232,6 +2254,7 @@ gdk_rgb_convert_truecolor_lsb (GdkRgbInfo *image_info, GdkImage *image,
gint b_right, b_left;
gint bpp;
guint32 pixel;
+ guint32 alpha_mask = gdk_rgb_alpha_mask (image_info);
gint i;
r_right = 8 - image_info->visual->red_prec;
@@ -2255,7 +2278,7 @@ gdk_rgb_convert_truecolor_lsb (GdkRgbInfo *image_info, GdkImage *image,
b = bp2[2];
pixel = ((r >> r_right) << r_left) |
((g >> g_right) << g_left) |
- ((b >> b_right) << b_left);
+ ((b >> b_right) << b_left) | alpha_mask;
for (i = 0; i < bpp; i++)
{
*obptr++ = pixel & 0xff;
@@ -2285,6 +2308,7 @@ gdk_rgb_convert_truecolor_lsb_d (GdkRgbInfo *image_info, GdkImage *image,
gint b_right, b_left, b_prec;
gint bpp;
guint32 pixel;
+ guint32 alpha_mask = gdk_rgb_alpha_mask (image_info);
gint i;
gint dith;
gint r1, g1, b1;
@@ -2319,7 +2343,7 @@ gdk_rgb_convert_truecolor_lsb_d (GdkRgbInfo *image_info, GdkImage *image,
b1 = b + (dith >> b_prec);
pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) |
(((g1 - (g1 >> g_prec)) >> g_right) << g_left) |
- (((b1 - (b1 >> b_prec)) >> b_right) << b_left);
+ (((b1 - (b1 >> b_prec)) >> b_right) << b_left) | alpha_mask;
for (i = 0; i < bpp; i++)
{
*obptr++ = pixel & 0xff;
@@ -2349,6 +2373,7 @@ gdk_rgb_convert_truecolor_msb (GdkRgbInfo *image_info, GdkImage *image,
gint b_right, b_left;
gint bpp;
guint32 pixel;
+ guint32 alpha_mask = gdk_rgb_alpha_mask (image_info);
gint shift, shift_init;
r_right = 8 - image_info->visual->red_prec;
@@ -2373,7 +2398,7 @@ gdk_rgb_convert_truecolor_msb (GdkRgbInfo *image_info, GdkImage *image,
b = bp2[2];
pixel = ((r >> r_right) << r_left) |
((g >> g_right) << g_left) |
- ((b >> b_right) << b_left);
+ ((b >> b_right) << b_left) | alpha_mask;
for (shift = shift_init; shift >= 0; shift -= 8)
{
*obptr++ = (pixel >> shift) & 0xff;
@@ -2402,6 +2427,7 @@ gdk_rgb_convert_truecolor_msb_d (GdkRgbInfo *image_info, GdkImage *image,
gint b_right, b_left, b_prec;
gint bpp;
guint32 pixel;
+ guint32 alpha_mask = gdk_rgb_alpha_mask (image_info);
gint shift, shift_init;
gint dith;
gint r1, g1, b1;
@@ -2437,7 +2463,7 @@ gdk_rgb_convert_truecolor_msb_d (GdkRgbInfo *image_info, GdkImage *image,
b1 = b + (dith >> b_prec);
pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) |
(((g1 - (g1 >> g_prec)) >> g_right) << g_left) |
- (((b1 - (b1 >> b_prec)) >> b_right) << b_left);
+ (((b1 - (b1 >> b_prec)) >> b_right) << b_left) | alpha_mask;
for (shift = shift_init; shift >= 0; shift -= 8)
{
*obptr++ = (pixel >> shift) & 0xff;
@@ -3110,27 +3136,43 @@ gdk_rgb_select_conv (GdkRgbInfo *image_info)
(mask_bgr && byte_order == GDK_LSB_FIRST)))
conv = gdk_rgb_convert_888_msb;
#if G_BYTE_ORDER == G_BIG_ENDIAN
- else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR &&
+ else if (bpp == 32 &&
+ (depth == 24 || depth == 32) &&
+ vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_rgb && byte_order == GDK_LSB_FIRST))
conv = gdk_rgb_convert_0888_br;
- else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR &&
+ else if (bpp == 32 &&
+ (depth == 24 || depth == 32) &&
+ vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_rgb && byte_order == GDK_MSB_FIRST))
conv = gdk_rgb_convert_0888;
else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_bgr && byte_order == GDK_MSB_FIRST))
conv = gdk_rgb_convert_8880_br;
+ else if (bpp == 32 && depth == 32 && vtype == GDK_VISUAL_TRUE_COLOR &&
+ (mask_rgb && byte_order == GDK_LSB_FIRST))
+ conv = gdk_rgb_convert_8880_br;
+ else if (bpp == 32 && depth == 32 && vtype == GDK_VISUAL_TRUE_COLOR &&
+ (mask_rgb && byte_order == GDK_MSB_FIRST))
+ conv = gdk_rgb_convert_8880_br;
#else
- else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR &&
+ else if (bpp == 32 &&
+ (depth == 24 || depth == 32) &&
+ vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_rgb && byte_order == GDK_MSB_FIRST))
conv = gdk_rgb_convert_0888_br;
- else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR &&
+ else if (bpp == 32 &&
+ (depth == 24 || depth == 32) &&
+ vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_rgb && byte_order == GDK_LSB_FIRST))
conv = gdk_rgb_convert_0888;
else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_bgr && byte_order == GDK_LSB_FIRST))
conv = gdk_rgb_convert_8880_br;
+ else if (bpp == 32 && depth == 32 && vtype == GDK_VISUAL_TRUE_COLOR &&
+ (mask_rgb && byte_order == GDK_LSB_FIRST))
+ conv = gdk_rgb_convert_0888;
#endif
-
else if (vtype == GDK_VISUAL_TRUE_COLOR && byte_order == GDK_LSB_FIRST)
{
conv = gdk_rgb_convert_truecolor_lsb;