[Xcb-commit] 4 commits - aux image

Keith Packard keithp at kemper.freedesktop.org
Sun Sep 7 21:50:58 PDT 2008


 aux/xcb_bitops.h  |    2 
 image/.gitignore  |    1 
 image/Makefile.am |    8 +
 image/test_swap.c |  211 ++++++++++++++++++++++++++++++++++++++++
 image/xcb_image.c |  282 +++++++++++++++++++++---------------------------------
 5 files changed, 334 insertions(+), 170 deletions(-)

New commits:
commit ea2fe131f8fabc14d1c2bb7a978a551da141675d
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Sep 7 21:50:49 2008 -0700

    Add test_swap to image/.gitignore

diff --git a/image/.gitignore b/image/.gitignore
index 7cae81e..de1725d 100644
--- a/image/.gitignore
+++ b/image/.gitignore
@@ -2,3 +2,4 @@ test_xcb_image
 test_xcb_image_shm
 test_formats
 test_bitmap
+test_swap
commit 042c47c603f6cf71fe9f5014e5741185ca5a0f4b
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Sep 7 21:48:41 2008 -0700

    Rework image format conversion code to pass test_swap test case.
    
    Numerous bugs were uncovered with the new test case, this fixes all of them.
    Perhaps this code will work on MSB machines now?

diff --git a/image/xcb_image.c b/image/xcb_image.c
index ee374cc..10b4b0c 100644
--- a/image/xcb_image.c
+++ b/image/xcb_image.c
@@ -62,7 +62,7 @@ format_valid (uint8_t depth, uint8_t bpp, uint8_t unit,
 	      xcb_image_format_t format, uint8_t xpad)
 {
   xcb_image_format_t  ef = effective_format(format, bpp);
-  if (depth > bpp || bpp > unit)
+  if (depth > bpp)
       return 0;
   switch(ef) {
   case XCB_IMAGE_FORMAT_XY_PIXMAP:
@@ -125,12 +125,10 @@ xcb_image_annotate (xcb_image_t *image)
   xcb_image_format_t  ef = effective_format(image->format, image->bpp);
   switch (ef) {
   case XCB_IMAGE_FORMAT_XY_PIXMAP:
-      image->plane_mask = xcb_mask(image->depth);
       image->stride = xcb_roundup(image->width, image->scanline_pad) >> 3;
       image->size = image->height * image->stride * image->depth;
       break;
   case XCB_IMAGE_FORMAT_Z_PIXMAP:
-      image->plane_mask = 0;
       image->stride = xcb_roundup((uint32_t)image->width *
 				  (uint32_t)image->bpp,
 				  image->scanline_pad) >> 3;
@@ -239,6 +237,7 @@ xcb_image_create (uint16_t           width,
   image->depth = depth;
   image->bpp = bpp;
   image->unit = unit;
+  image->plane_mask = xcb_mask(depth);
   image->byte_order = byte_order;
   image->bit_order = bit_order;
   xcb_image_annotate(image);
@@ -527,6 +526,32 @@ xcb_image_shm_get (xcb_connection_t *      conn,
 }
 
 
+static uint32_t
+xy_image_byte (xcb_image_t *image, uint32_t x)
+{
+    x >>= 3;
+    if (image->byte_order == XCB_IMAGE_ORDER_LSB_FIRST)
+	return x;
+    switch (image->unit) {
+    default:
+    case 8:
+	return x;
+    case 16:
+	return x ^ 1;
+    case 32:
+	return x ^ 3;
+    }
+}
+
+static uint32_t
+xy_image_bit (xcb_image_t *image, uint32_t x)
+{
+    x &= 7;
+    if (image->bit_order == XCB_IMAGE_ORDER_MSB_FIRST)
+	x = 7 - x;
+    return x;
+}
+
 /* GetPixel/PutPixel */
 
 /* XXX this is the most hideously done cut-and-paste
@@ -543,36 +568,24 @@ xcb_image_put_pixel (xcb_image_t *image,
   if (x > image->width || y > image->height)
       return;
   row = image->data + (y * image->stride);
-  switch (image->format) {
+  switch (effective_format(image->format, image->bpp)) {
   case XCB_IMAGE_FORMAT_XY_BITMAP:
   case XCB_IMAGE_FORMAT_XY_PIXMAP:
       /* block */ {
 	  int  p;
 	  uint32_t   plane_mask = image->plane_mask;
 	  uint8_t *  plane = row;
-	  uint32_t   ulog = image->bpp >> 4;
-	  uint32_t   unit = (x >> 3) & ~xcb_mask(ulog);
-	  uint32_t   byte = (x >> 3) & xcb_mask(ulog);
-	  uint32_t   bit = x & 7;
-
-	  if (image->byte_order == XCB_IMAGE_ORDER_MSB_FIRST)
-	      byte = xcb_mask(ulog) - byte;
-	  if (image->bit_order == XCB_IMAGE_ORDER_MSB_FIRST) {
-	      bit = 7 - bit;
-	  } else {
-	      pixel = xcb_bit_reverse(pixel, image->bpp);
-	      plane_mask = xcb_bit_reverse(plane_mask, image->bpp);
-	  }
-	  for (p = 0; p < image->bpp; p++) {
-	      if (plane_mask & 1) {
-		  uint8_t *  bp = plane + (unit | byte);
-		  uint8_t    m = 1 << bit;
-		  uint8_t    p = (pixel & 1) << bit;
-		  *bp = (*bp & ~m) | p;
+	  uint32_t   byte = xy_image_byte(image, x);
+	  uint32_t   bit = xy_image_bit(image,x);
+	  uint8_t    mask = 1 << bit;
+
+	  for (p = image->bpp - 1; p >= 0; p--) {
+	      if ((plane_mask >> p) & 1) {
+		  uint8_t *  bp = plane + byte;
+		  uint8_t    this_bit = ((pixel >> p) & 1) << bit;
+		  *bp = (*bp & ~mask) | this_bit;
 	      }
 	      plane += image->stride * image->height;
-	      pixel >>= 1;
-	      plane_mask >>= 1;
 	  }
       }
       break;
@@ -657,36 +670,24 @@ xcb_image_get_pixel (xcb_image_t *image,
 
   assert(x < image->width && y < image->height);
   row = image->data + (y * image->stride);
-  switch (image->format) {
+  switch (effective_format(image->format, image->bpp)) {
   case XCB_IMAGE_FORMAT_XY_BITMAP:
   case XCB_IMAGE_FORMAT_XY_PIXMAP:
       /* block */ {
 	  int  p;
 	  uint32_t   plane_mask = image->plane_mask;
 	  uint8_t *  plane = row;
-	  uint32_t   ulog = image->bpp >> 4;
-	  uint32_t   unit = (x >> 3) & ~xcb_mask(ulog);
-	  uint32_t   byte = (x >> 3) & xcb_mask(ulog);
-	  uint32_t   bit = x & 7;
-
-	  if (image->byte_order == XCB_IMAGE_ORDER_MSB_FIRST)
-	      byte = xcb_mask(ulog) - byte;
-	  if (image->bit_order == XCB_IMAGE_ORDER_MSB_FIRST) {
-	      bit = 7 - bit;
-	  } else {
-	      plane_mask = xcb_bit_reverse(plane_mask, image->bpp);
-	  }
-	  for (p = 0; p < image->bpp; p++) {
+	  uint32_t   byte = xy_image_byte(image, x);
+	  uint32_t   bit = xy_image_bit(image,x);
+
+	  for (p = image->bpp - 1; p >= 0; p--) {
 	      pixel <<= 1;
-	      if (plane_mask & 1) {
-		  uint8_t *  bp = plane + (unit | byte);
+	      if ((plane_mask >> p) & 1) {
+		  uint8_t *  bp = plane + byte;
 		  pixel |= (*bp >> bit) & 1;
 	      }
 	      plane += image->stride * image->height;
-	      plane_mask >>= 1;
 	  }
-	  if (image->bit_order == XCB_IMAGE_ORDER_LSB_FIRST)
-	      pixel = xcb_bit_reverse(pixel, image->bpp);
       }
       return pixel;
   case XCB_IMAGE_FORMAT_Z_PIXMAP:
@@ -830,20 +831,17 @@ swap_image(uint8_t *	     src,
            uint32_t 	     src_stride,
 	   uint8_t *	     dst,
 	   uint32_t 	     dst_stride,
-	   uint8_t const *   byte_order,
-	   int		     unit_bytes,
-	   uint16_t 	     height,
+	   uint32_t 	     height,
+	   uint32_t	     byteswap,
 	   int		     bitswap,
 	   int               nibbleswap)
 {
   while (height--) {
-      uint32_t    minor = 0;
-      uint32_t    major = 0;
       uint32_t    s;
 
       for (s = 0; s < src_stride; s++) {
 	  uint8_t   b;
-	  uint32_t  d = major + byte_order[minor];
+	  uint32_t  d = s ^ byteswap;
 
 	  if (d > dst_stride)
 	      continue;
@@ -854,77 +852,44 @@ swap_image(uint8_t *	     src,
 	  if (nibbleswap)
 	      b = (b << 4) | (b >> 4);
 	  dst[d] = b;
-
-	  if (++minor == unit_bytes) 
-	  {
-	      minor = 0; 
-	      major += unit_bytes;
-	  }
       }
       src += src_stride;
       dst += dst_stride;
   }
 }
 
-/* Note that all of these permutations are self-inverse.
-   Applying them twice yields the identity permutation, i.e p*p = i
-   This means that we only have to care about the
-   source and destination size and whether they mismatch, not
-   the actual endiannesses. */
-static uint8_t const forward_order[4] = {0, 1, 2, 3};
-static uint8_t const reverse_order[4] = {3, 2, 1, 0};
-static uint8_t const reverse_word_order[4] = {2, 3, 0, 1};
-
-static uint8_t const *
-conversion_byte_order(xcb_image_t *src, xcb_image_t *dst)
+/* Which order are bytes in (low two bits), given
+ * code which accesses an image one byte at a time
+ */
+static uint32_t
+byte_order(xcb_image_t *i)
 {
-    uint8_t  nbytes = src->unit >> 3;
-    
-    if (src->byte_order == dst->byte_order)
-	return forward_order;
-    if (nbytes >= 1 && nbytes <= 4)
-	return &reverse_order[4 - nbytes];
-    return forward_order;
-}
-
+    uint32_t flip = i->byte_order == XCB_IMAGE_ORDER_MSB_FIRST;
 
-#define R1 forward_order
-#define R2 reverse_word_order
-#define R4 reverse_order
-#define W4 reverse_word_order
-
-static uint8_t const * const bbo_reverse[3][3] =
-        /* 8  16  32*/
-  /*8*/ {{R1, R2, R4},
- /*16*/  {R2, R2, W4},
- /*32*/  {R4, W4, R4}};
+    switch (i->unit) {
+    default:
+    case 8:
+	return 0;
+    case 16:
+	return flip;
+    case 32:
+	return flip | (flip << 1);
+    }
+}
 
-static uint8_t const *
-bitmap_conversion_byte_order(xcb_image_t *src, xcb_image_t *dst)
+/* Convert from one byte order to another by flipping the 
+ * low two bits of the byte index along a scanline
+ */
+static uint32_t 
+conversion_byte_swap(xcb_image_t *src, xcb_image_t *dst)
 {
-    uint8_t  srclog = src->unit >> 4;
-    uint8_t  dstlog = dst->unit >> 4;
-    int sbo = src->byte_order;
-    int dbo = dst->byte_order;
-
-    if (srclog == 0)
-	sbo = XCB_IMAGE_ORDER_LSB_FIRST;
-    if (dstlog == 0)
-	dbo = XCB_IMAGE_ORDER_LSB_FIRST;
-    if (dbo == sbo)
-	return forward_order;
-    return bbo_reverse[srclog][dstlog];
+    return byte_order(src) ^ byte_order(dst);
 }
 
-
 xcb_image_t *
 xcb_image_convert (xcb_image_t *  src,
 		   xcb_image_t *  dst)
 {
-  uint32_t            x;
-  uint32_t            y;
-  int                 format_compatible = 0;
-  int                 bitmap = 0;
   xcb_image_format_t  ef = effective_format(src->format, src->bpp);
 
   /* Things will go horribly wrong here if a bad
@@ -932,74 +897,53 @@ xcb_image_convert (xcb_image_t *  src,
      up front just to be nice. */
   assert(image_format_valid(src));
   assert(image_format_valid(dst));
-  if (src->depth != dst->depth ||
-      src->width != dst->width ||
+  
+  /* images must be the same size
+   * (yes, we could copy a sub-set)
+   */
+  if (src->width != dst->width ||
       src->height != dst->height)
       return 0;
-  switch (ef) {
-  case XCB_IMAGE_FORMAT_XY_PIXMAP:
-      bitmap = src->depth == 1;
-      format_compatible = src->format == dst->format || bitmap;
-      /* Case: Formats are identical.  Just copy. */
-      if (format_compatible &&
-	  src->bpp == dst->bpp &&
-	  src->unit == dst->unit &&
-	  src->scanline_pad == dst->scanline_pad &&
-	  src->byte_order == dst->byte_order &&
-	  src->bit_order == dst->bit_order) {
-	  memcpy(dst->data, src->data, src->size);
-	  return dst;
-      }
-      break;
-  case XCB_IMAGE_FORMAT_Z_PIXMAP:
-      format_compatible = src->format == dst->format;
-      /* Case: Formats are identical.  Just copy. */
-      if (format_compatible &&
-	  src->bpp == dst->bpp &&
-	  src->byte_order == dst->byte_order) {
-	  memcpy(dst->data, src->data, src->size);
-	  return dst;
-      }
-      break;
-  default:
-      assert(0);
-  }
-  /* Case: Bitmap scanline units are always compatible.  Copy and convert. */
-  if (bitmap) {
-      uint8_t const * const
-	       byte_order = bitmap_conversion_byte_order(src, dst);
-      int      bitswap = src->bit_order != dst->bit_order;
-      uint8_t  unit = src->unit;
-      
-      if (dst->unit < unit)
-	  unit = dst->unit;
-      swap_image(src->data, src->stride,
-		     dst->data, dst->stride,
-		     byte_order, unit >> 3,
-		     src->height, bitswap, 0);
-      return dst;
-  }
-  /* Case: Pixmap scanline units are identical.  Copy and convert. */
-  if (format_compatible && src->bpp == dst->bpp) {
-      uint8_t const * const
-	   byte_order = conversion_byte_order(src, dst);
-      int  bitswap = src->bit_order != dst->bit_order;
-      int  nibbleswap = src->byte_order != dst->byte_order &&
-                        src->bpp == 4;
-      swap_image(src->data, src->stride,
-		     dst->data, dst->stride,
-		     byte_order, src->unit >> 3,
-		     src->height, bitswap, nibbleswap);
-      return dst;
-  }
 
-  /* General case: Slow pixel copy. Should we optimize
-     Z24<->Z32 copies of either endianness? */
-  for (y = 0; y < src->height; y++) {
-      for (x = 0; x < src->width; x++) {
-	  uint32_t  pixel = xcb_image_get_pixel(src, x, y);
-	  xcb_image_put_pixel(dst, x, y, pixel);
+  if (ef == effective_format(dst->format, dst->bpp) &&
+      src->bpp == dst->bpp)
+  {
+    if (src->unit == dst->unit &&
+	src->scanline_pad == dst->scanline_pad &&
+	src->byte_order == dst->byte_order &&
+	(ef == XCB_IMAGE_FORMAT_Z_PIXMAP ||
+	 src->bit_order == dst->bit_order)) {
+      memcpy(dst->data, src->data, src->size);
+    } else {
+      int	bitswap = 0;
+      int	nibbleswap = 0;
+      uint32_t	byteswap = conversion_byte_swap(src, dst);
+      uint32_t	height = src->height;;
+
+      if (ef == XCB_IMAGE_FORMAT_Z_PIXMAP) {
+	if (src->bpp == 4 && src->byte_order != dst->byte_order)
+	  nibbleswap = 1;
+      } else {
+	if (src->bit_order != dst->bit_order)
+	  bitswap = 1;
+	height *= src->depth;
       }
+      swap_image (src->data, src->stride, dst->data, dst->stride,
+		  height, byteswap, bitswap, nibbleswap);
+    }
+  }
+  else
+  {
+    uint32_t            x;
+    uint32_t            y;
+    /* General case: Slow pixel copy. Should we optimize
+       Z24<->Z32 copies of either endianness? */
+    for (y = 0; y < src->height; y++) {
+	for (x = 0; x < src->width; x++) {
+	    uint32_t  pixel = xcb_image_get_pixel(src, x, y);
+	    xcb_image_put_pixel(dst, x, y, pixel);
+	}
+    }
   }
   return dst;
 }
commit 3f57cdc48e5c40fe62161627bfdae613a70ed1d1
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Sep 7 21:46:45 2008 -0700

    xcb_mask must not be zero when n == 32.
    
    left shift of a 32-bit value by 32 is undefined, don't try to use it.

diff --git a/aux/xcb_bitops.h b/aux/xcb_bitops.h
index 48c3401..a6872a1 100644
--- a/aux/xcb_bitops.h
+++ b/aux/xcb_bitops.h
@@ -51,7 +51,7 @@
 _X_INLINE static uint32_t
 xcb_mask(uint32_t n)
 {
-    return (1 << n) - 1;
+    return n == 32 ? ~0 : (1 << n) - 1;
 }
 
 
commit eb56963f11c5f3c4031a89e75cbef385c848b59e
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Sep 7 21:45:50 2008 -0700

    Add image conversion test case for 'make check'
    
    test_swap converts between most possible image formats, checking results
    against a fixed image.

diff --git a/image/Makefile.am b/image/Makefile.am
index a039c2b..a18b228 100644
--- a/image/Makefile.am
+++ b/image/Makefile.am
@@ -18,6 +18,14 @@ EXTRA_DIST=xcb-image.pc.in
 
 EXTRA_PROGRAMS = test_xcb_image test_xcb_image_shm test_formats test_bitmap
 
+check_PROGRAMS = test_swap
+
+TESTS=test_swap
+
+test_swap_SOURCES = test_swap.c
+test_swap_CPPFLAGS = $(XCB_CFLAGS) $(XCB_SHM_CFLAGS) $(XCB_AUX_CFLAGS)
+test_swap_LDADD = $(XCB_LIBS) $(XCB_AUX_LIBS) $(XCB_IMAGE_LIBS)
+
 test_xcb_image_SOURCES = test_xcb_image.c
 test_xcb_image_CPPFLAGS = $(XCB_CFLAGS) $(XCB_SHM_CFLAGS) $(XCB_AUX_CFLAGS)
 test_xcb_image_LDADD = $(XCB_LIBS) $(XCB_AUX_LIBS) $(XCB_IMAGE_LIBS)
diff --git a/image/test_swap.c b/image/test_swap.c
new file mode 100644
index 0000000..800e451
--- /dev/null
+++ b/image/test_swap.c
@@ -0,0 +1,211 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <xcb/xcb.h>
+#include "../aux/xcb_aux.h"
+#include "xcb_image.h"
+
+xcb_image_format_t  formats[] = {
+    XCB_IMAGE_FORMAT_Z_PIXMAP,
+    XCB_IMAGE_FORMAT_XY_PIXMAP,
+    XCB_IMAGE_FORMAT_XY_BITMAP,
+};
+#define SIZE(a) (sizeof (a) / sizeof (a[0]))
+#define NFORMAT SIZE(formats)
+
+int bpps[] = {
+    1, 4, 8, 16, 32
+};
+#define NBPP SIZE(bpps)
+
+int units[] = {
+    8, 16, 32
+};
+#define NUNIT SIZE(units)
+
+xcb_image_order_t   byte_orders[] = {
+    XCB_IMAGE_ORDER_LSB_FIRST,
+    XCB_IMAGE_ORDER_MSB_FIRST
+};
+#define NBYTE_ORDER SIZE(byte_orders)
+
+static
+uint32_t pixel_mask (int bpp)
+{
+    if (bpp == 32)
+	return 0xffffffff;
+    return (1 << bpp) - 1;
+}
+
+int
+compare_image(xcb_image_t *a, xcb_image_t *b)
+{
+    int x, y;
+    uint32_t	a_pixel, b_pixel;
+    uint32_t	mask = pixel_mask (a->bpp) & pixel_mask (b->bpp);
+
+    for (y = 0; y < a->height; y++)
+	for (x = 0; x < a->width; x++) {
+	    a_pixel = xcb_image_get_pixel (a, x, y) & mask;
+	    b_pixel = xcb_image_get_pixel (b, x, y) & mask;
+	    if (a_pixel != b_pixel) {
+		fprintf (stderr, "fail at %d,%d: 0x%x != 0x%x\n",
+			 x, y, a_pixel, b_pixel);
+		return 0;
+	    }
+	}
+    return 1;
+}
+
+#define test_width  63
+#define test_height 2
+
+static xcb_image_t *
+create_test_image (void)
+{
+    xcb_image_t	*test_image;
+    int		x, y;
+    uint32_t	pixel;
+    test_image = xcb_image_create(test_width, test_height,
+				  XCB_IMAGE_FORMAT_Z_PIXMAP,
+				  32,
+				  32,
+				  32,
+				  32,
+				  XCB_IMAGE_ORDER_LSB_FIRST,
+				  XCB_IMAGE_ORDER_LSB_FIRST,
+				  NULL, 0, NULL);
+
+    pixel = 0;
+    for (y = 0; y < test_height; y++)
+	for (x = 0; x < test_width; x++) {
+	    xcb_image_put_pixel (test_image, x, y, pixel);
+	    pixel++;
+	}
+    return test_image;
+}
+
+static void
+convert_test (xcb_image_t *test, xcb_image_t *a)
+{
+    int		x, y;
+
+    for (y = 0; y < test->height; y++)
+	for (x = 0; x < test->width; x++)
+	    xcb_image_put_pixel (a, x, y, xcb_image_get_pixel (test, x, y));
+}
+
+static char *
+order_name (xcb_image_order_t order) {
+  if (order == XCB_IMAGE_ORDER_MSB_FIRST)
+    return "MSB";
+  else
+    return "LSB";
+}
+
+static void
+print_format (xcb_image_t *image)
+{
+  switch (image->format) {
+  case XCB_IMAGE_FORMAT_Z_PIXMAP: fprintf (stderr, "Z pixmap"); break;
+  case XCB_IMAGE_FORMAT_XY_PIXMAP: fprintf (stderr, "XY pixmap"); break;
+  case XCB_IMAGE_FORMAT_XY_BITMAP: fprintf (stderr, "XY bitmap"); break;
+  }
+  fprintf (stderr, " pad: %d bpp: %d depth: %d unit: %d planemask: 0x%08x",
+	   image->scanline_pad, image->bpp, image->depth, image->unit,
+	   image->plane_mask);
+  fprintf (stderr, " byte order: %s bit order: %s stride: %d\n",
+	   order_name (image->byte_order), order_name (image->bit_order),
+	   image->stride);
+}
+
+int main (int argc, char **argv) {
+  xcb_image_t	*test_image;
+  xcb_image_t	*src_image;
+  xcb_image_t	*dst_image;
+  int		dst_format_i, dst_bpp_i, dst_unit_i, dst_byte_order_i, dst_bit_order_i;
+  int		src_format_i, src_bpp_i, src_unit_i, src_byte_order_i, src_bit_order_i;
+  xcb_image_format_t	dst_format, src_format;
+  int		dst_bpp, src_bpp;
+  int		dst_unit, src_unit;
+  int		dst_byte_order, src_byte_order;
+  int		dst_bit_order, src_bit_order;
+
+  test_image = create_test_image ();
+
+  for (dst_format_i = 0; dst_format_i < NFORMAT; dst_format_i++) {
+    dst_format = formats[dst_format_i];
+    for (src_format_i = 0; src_format_i < NFORMAT; src_format_i++) {
+      src_format = formats[src_format_i];
+      for (dst_bpp_i = 0; dst_bpp_i < NBPP; dst_bpp_i++) {
+	dst_bpp = bpps[dst_bpp_i];
+	for (src_bpp_i = 0; src_bpp_i < NBPP; src_bpp_i++) {
+	  src_bpp = bpps[src_bpp_i];
+	  for (dst_unit_i = 0; dst_unit_i < NUNIT; dst_unit_i++) {
+	    dst_unit = units[dst_unit_i];
+	    if (dst_format == XCB_IMAGE_FORMAT_Z_PIXMAP) {
+	      if (dst_bpp == 4 && dst_unit != 8)
+		continue;
+	      if (dst_bpp > 4 && dst_unit != dst_bpp)
+		continue;
+	    }
+	    if (dst_format == XCB_IMAGE_FORMAT_XY_BITMAP && dst_bpp != 1)
+	      continue;
+	    for (src_unit_i = 0; src_unit_i < NUNIT; src_unit_i++) {
+	      src_unit = units[src_unit_i];
+	      if (src_format == XCB_IMAGE_FORMAT_Z_PIXMAP) {
+		if (src_bpp == 4 && src_unit != 8)
+		  continue;
+		if (src_bpp > 4 && src_unit != src_bpp)
+		  continue;
+	      }
+	      if (src_format == XCB_IMAGE_FORMAT_XY_BITMAP && src_bpp != 1)
+		continue;
+	      for (dst_byte_order_i = 0; dst_byte_order_i < NBYTE_ORDER; dst_byte_order_i++) {
+		dst_byte_order = byte_orders[dst_byte_order_i];
+		for (src_byte_order_i = 0; src_byte_order_i < NBYTE_ORDER; src_byte_order_i++) {
+		  src_byte_order = byte_orders[src_byte_order_i];
+		  for (dst_bit_order_i = 0; dst_bit_order_i < NBYTE_ORDER; dst_bit_order_i++) {
+		    dst_bit_order = byte_orders[dst_bit_order_i];
+		    if (dst_format == XCB_IMAGE_FORMAT_Z_PIXMAP && dst_bit_order != dst_byte_order)
+		      continue;
+		    for (src_bit_order_i = 0; src_bit_order_i < NBYTE_ORDER; src_bit_order_i++) {
+		      src_bit_order = byte_orders[src_bit_order_i];
+		      if (src_format == XCB_IMAGE_FORMAT_Z_PIXMAP && src_bit_order != src_byte_order)
+			continue;
+		      src_image = xcb_image_create (test_width, test_height, src_format, 32, src_bpp, src_bpp, src_unit,
+						    src_byte_order, src_bit_order, NULL, 0, NULL);
+		      dst_image = xcb_image_create (test_width, test_height, dst_format, 32, dst_bpp, dst_bpp, dst_unit,
+						    dst_byte_order, dst_bit_order, NULL, 0, NULL);
+		      convert_test (test_image, src_image);
+		      if (!compare_image (test_image, src_image)) {
+			fprintf (stderr, "Initialization failure:\n");
+			fprintf (stderr, "src format: "); print_format(src_image);
+			exit (1);
+		      }
+		      xcb_image_convert (src_image, dst_image);
+		      if (!compare_image (src_image, dst_image)) {
+			/*
+			 * Call the conversion function again so that debugging
+			 * is easier
+			 */
+			fprintf (stderr, "Conversion failure:\n");
+			fprintf (stderr, "src format: "); print_format(src_image);
+			fprintf (stderr, "dst format: "); print_format(dst_image);
+			exit (1);
+		      }
+		      xcb_image_destroy (src_image);
+		      xcb_image_destroy (dst_image);
+		    }
+		  }
+		}
+	      }
+	    }
+	  }
+	}
+      }
+    }
+  }
+  return 0;
+}


More information about the xcb-commit mailing list