[MPlayer-cvslog] r34218 - trunk/gui/util/bitmap.c

ib subversion at mplayerhq.hu
Thu Oct 20 14:05:47 CEST 2011


Author: ib
Date: Thu Oct 20 14:05:47 2011
New Revision: 34218

Log:
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.

Modified:
   trunk/gui/util/bitmap.c

Modified: trunk/gui/util/bitmap.c
==============================================================================
--- trunk/gui/util/bitmap.c	Thu Oct 20 13:15:30 2011	(r34217)
+++ trunk/gui/util/bitmap.c	Thu Oct 20 14:05:47 2011	(r34218)
@@ -272,15 +272,15 @@ void bpFree(guiImage *img)
 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 @@ int bpRenderMask(const guiImage *in, gui
 
     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);


More information about the MPlayer-cvslog mailing list