fix 1bit bitmaps on msbfirst architectures + some indentation fixes

This commit is contained in:
Mikael Magnusson 2006-03-14 15:27:15 +00:00
parent bc1f845ada
commit f1ed62cead
2 changed files with 23 additions and 9 deletions

View file

@ -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;

View file

@ -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);