From f1ed62cead95b1370e4282c2bf3303aa2d75803a Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Tue, 14 Mar 2006 15:27:15 +0000 Subject: [PATCH] fix 1bit bitmaps on msbfirst architectures + some indentation fixes --- render/color.c | 14 +++++++------- render/render.c | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/render/color.c b/render/color.c index 9f053e97..c53a366e 100644 --- a/render/color.c +++ b/render/color.c @@ -154,7 +154,7 @@ void RrReduceDepth(const RrInstance *inst, RrPixel32 *data, XImage *im) data += im->width; p16 += im->bytes_per_line/2; } - break; + break; case 8: g_assert(RrVisual(inst)->class != TrueColor); for (y = 0; y < im->height; y++) { @@ -163,12 +163,11 @@ void RrReduceDepth(const RrInstance *inst, RrPixel32 *data, XImage *im) data[x] >> RrDefaultRedOffset, data[x] >> RrDefaultGreenOffset, data[x] >> RrDefaultBlueOffset)->pixel; + } + data += im->width; + p8 += im->bytes_per_line; } - data += im->width; - p8 += im->bytes_per_line; - } - - break; + break; default: g_warning("your bit depth is currently unhandled\n"); } @@ -204,9 +203,10 @@ static void swap_byte_order(XImage *im) c[0] = c[1]; c[1] = t; case 8: + case 1: break; default: - g_warning("your bit depth is currently unhandled"); + g_warning("Your bit depth is currently unhandled"); } } di += im->bytes_per_line; diff --git a/render/render.c b/render/render.c index a4161405..36d26a6f 100644 --- a/render/render.c +++ b/render/render.c @@ -352,6 +352,14 @@ void RrMinsize(RrAppearance *a, gint *w, gint *h) if (*h < 1) *h = 1; } +void reverse_bits(gchar *c, gint n) +{ + gint i; + for (i = 0; i < n; i++) + *c++ = (((*c * 0x0802UL & 0x22110UL) | + (*c * 0x8020UL & 0x88440UL)) * 0x10101UL) >> 16; +} + gboolean RrPixmapToRGBA(const RrInstance *inst, Pixmap pmap, Pixmap mask, gint *w, gint *h, RrPixel32 **data) @@ -361,9 +369,10 @@ gboolean RrPixmapToRGBA(const RrInstance *inst, guint pw, ph, mw, mh, xb, xd, i, x, y, di; XImage *xi, *xm = NULL; - if (!XGetGeometry(RrDisplay(inst), - pmap, &xr, &xx, &xy, &pw, &ph, &xb, &xd)) + if (!XGetGeometry(RrDisplay(inst), pmap, + &xr, &xx, &xy, &pw, &ph, &xb, &xd)) return FALSE; + if (mask) { if (!XGetGeometry(RrDisplay(inst), mask, &xr, &xx, &xy, &mw, &mh, &xb, &xd)) @@ -384,8 +393,13 @@ gboolean RrPixmapToRGBA(const RrInstance *inst, XDestroyImage(xi); return FALSE; } + if ((xm->bits_per_pixel == 1) && (xm->bitmap_bit_order != LSBFirst)) + reverse_bits(xm->data, xm->bytes_per_line * xm->height); } + if ((xi->bits_per_pixel == 1) && (xi->bitmap_bit_order != LSBFirst)) + reverse_bits(xi->data, xi->bytes_per_line * xi->height); + *data = g_new(RrPixel32, pw * ph); RrIncreaseDepth(inst, *data, xi); -- 2.45.2