# HG changeset patch # User ib # Date 1319112347 0 # Node ID b0c63b098b6b4f19d9e40146ce3a083ba89ba8d5 # Parent a7d1a3c3bc740489533ec5a8b318ab7cc989316c Fix bug in bpRenderMask(). Currently, it only works for images which width is a multiple of 8 pixels. Fix it to work with arbitrary images. diff -r a7d1a3c3bc74 -r b0c63b098b6b gui/util/bitmap.c --- a/gui/util/bitmap.c Thu Oct 20 11:15:30 2011 +0000 +++ b/gui/util/bitmap.c Thu Oct 20 12:05:47 2011 +0000 @@ -272,15 +272,15 @@ int bpRenderMask(const guiImage *in, guiImage *out) { uint32_t *buf; - unsigned long i; - int b = 0, c = 0; - unsigned char tmp = 0; + unsigned long x, y; + unsigned long i = 0, c = 0; + unsigned char tmp = 0, b = 1; int shaped = 0; out->Width = in->Width; out->Height = in->Height; out->Bpp = 1; - out->ImageSize = (out->Width * out->Height + 7) / 8; + out->ImageSize = ((out->Width + 7) / 8) * out->Height; out->Image = calloc(1, out->ImageSize); if (!out->Image) { @@ -290,24 +290,31 @@ buf = (uint32_t *)in->Image; - for (i = 0; i < out->Width * out->Height; i++) { - tmp >>= 1; - + for (y = 0; y < in->Height; y++) { + for (x = 0; x < in->Width; x++) { if (!IS_TRANSPARENT(buf[i])) - tmp |= 0x80; + tmp |= b; else { buf[i] = 0; shaped = 1; } - if (++b == 8) { + i++; + b <<= 1; + + if (b == 0) { out->Image[c++] = tmp; - tmp = b = 0; + tmp = 0; + b = 1; } } - if (b) - out->Image[c] = tmp; + if (b != 1) { + out->Image[c++] = tmp; + tmp = 0; + b = 1; + } + } if (!shaped) bpFree(out);