[Xcb] Bug in image handling on PPC

Barton C Massey bart at cs.pdx.edu
Tue Jul 29 21:31:02 PDT 2008


Thanks!  I'm trying to type over an absolutely horrible net
connection (worst in a long time) right now, so not too long
a message tongiht.  I got keithp to look at the bug, but
haven't heard back from him yet.  I have a prety good idea
what's up now (assuming that this is the behavior with the
patch I sent, yes?)  Will look again tomorrow when I'm back
in town.

	Bart

In message <200807292313.22171.doomster at knuut.de> you wrote:
> --Boundary-00=_yf4jIwl4ur+EkAC
> Content-Type: text/plain;
>   charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
> 
> On Thursday 24 July 2008 07:53:02 Ulrich Eckhardt wrote:
> > [...] xcb_image_convert() fails while manually converting the pixels works,
> > at least for the case at hand.
> 
> Take a look at the output of the attached file. If you compare the results 
> using xcb_convert_image() and xcb_image_{put,get}_pixel(), you will see that 
> the incorrect image (at least on my machine) is three bytes off simply! IOW, 
> the values in xcb_image_t's data are shifted by three bytes.
> 
> Uli
> 
> --Boundary-00=_yf4jIwl4ur+EkAC
> Content-Type: text/x-csrc;
>   charset="iso 8859-15";
>   name="image-fail1.c"
> Content-Transfer-Encoding: 7bit
> Content-Disposition: attachment;
> 	filename="image-fail1.c"
> 
> #include <stdio.h>
> #include <xcb/xcb_image.h>
> #include <stdlib.h>
> #include <string.h>
> 
> // write a pixmap to stdout
> void
> dump_image(xcb_image_t const* img)
> {
>     int x, y;
>     for( y=0; y!=img->height; ++y)
>     {
>         for( x=0; x!=img->width; ++x)
>         {
>             switch(xcb_image_get_pixel( img, x, y))
>             {
>             case 0:
>                 putc( '_', stdout);
>                 break;
>             case 1:
>                 putc( '*', stdout);
>                 break;
>             default:
>                 putc( '?', stdout);
>             }
>         }
>         putc( '\n', stdout);
>     }
> }
> 
> // convert byte order to string
> char const*
> byte_order_string(xcb_image_order_t t)
> {
>     switch(t)
>     {
>     case XCB_IMAGE_ORDER_LSB_FIRST:
>         return "XCB_IMAGE_ORDER_LSB_FIRST";
>     case XCB_IMAGE_ORDER_MSB_FIRST:
>         return "XCB_IMAGE_ORDER_MSB_FIRST";
>     }
>     return "<unknown>";
> }
> 
> // convert format to string
> char const*
> image_format_string(xcb_image_format_t t)
> {
>     switch(t)
>     {
>     case XCB_IMAGE_FORMAT_XY_BITMAP:
>         return "FORMAT_XY_BITMAP";
>     case XCB_IMAGE_FORMAT_XY_PIXMAP:
>         return "FORMAT_XY_PIXMAP";
>     case XCB_IMAGE_FORMAT_Z_PIXMAP:
>         return "FORMAT_Z_PIXMAP";
>     }
>     return "<unknown>";
> }
> 
> // write fields of an xcb_image_t structure
> // The flag 'with_data' says whether the contained bytes should be written, too.
> void
> dump_data(xcb_image_t const* img, int with_data)
> {
>     printf("{");
>     printf("width=%u, ", img->width);
>     printf("height=%u, ", img->height);
>     printf("format=%s, ", image_format_string(img->format));
>     printf("scanline_pad=%u, ", img->scanline_pad);
>     printf("depth=%u, ", img->depth);
>     printf("bpp=%u, ", img->bpp);
>     printf("unit=%u, ", img->unit);
>     printf("plane_mask=%x, ", img->plane_mask);
>     printf("byte_order=%s, ", byte_order_string(img->byte_order));
>     printf("bit_order=%s, ", byte_order_string(img->bit_order));
>     printf("stride=%u, ", img->stride);
>     printf("size=%u, ", img->size);
>     printf("base=%p, ", img->base);
>     if(with_data)
>     {
>         uint32_t i;
>         printf("data={");
>         for( i=0; i!=img->size; ++i)
>             printf("%02x ", img->data[i]);
>         printf("}");
>     }
>     else
>     {
>         printf("data=%p", img->data);
>     }
>     puts("}");
> }
> 
> void
> error( char const* msg)
> {
>     puts(msg);
>     exit(EXIT_FAILURE);
> }
> 
> // simple bitmap which looks like this:
> //  o x
> //  y 1
> // i.e. a square with markers for the axis'.
> unsigned const src_width = 16;
> unsigned const src_height = 16;
> static uint8_t const src_bits[] =
> {
>     0x0e,0x88,0x11,0x50,0x11,0x20,0x11,0x50,
>     0x0e,0x88,0x00,0x00,0x00,0x00,0x00,0x00,
>     0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x20,
>     0x0a,0x30,0x04,0x20,0x02,0x20,0x01,0x20
> };
> 
> int
> main()
> {
>     xcb_image_t* image;
>     xcb_image_t* fail;
>     unsigned x, y;
> 
>     image = xcb_image_create_from_bitmap_data( src_bits, src_width, src_height);
>     if (!image)
>         error("failed to parse source image data");
>     puts("original bitmap:");
>     dump_data(image, 1);
>     dump_image(image);
> 
> 
>     fail = xcb_image_create( image->width, image->height,
>                              image->format,
>                              32, // scanline_pad, was from setup!
>                              image->depth, image->bpp,
>                              32, // unit, was from setup!
>                              XCB_IMAGE_ORDER_MSB_FIRST, // byte_order, was from setup!
>                              XCB_IMAGE_ORDER_MSB_FIRST, // bit_order, was from setup!
>                              NULL, 0, NULL);
>     if(!fail)
>         error("failed to create target image");
> 
>     // zero out the allocated pixels
>     memset( fail->data, 0xcc, fail->size);
>     if(!xcb_image_convert( image, fail))
>         error("failed to convert image");
>     puts("converted using xcb_image_convert():");
>     dump_data(fail, 1);
>     dump_image(fail);
> 
>     // zero out the allocated pixels
>     memset( fail->data, 0xcc, fail->size);
>     for( y=0; y!=src_height; ++y)
>         for( x=0; x!=src_width; ++x)
>         {
>             uint32_t p = xcb_image_get_pixel( image, x, y);
>             xcb_image_put_pixel( fail, x, y, p);
>         }
> 
>     puts("converted using xcb_{get,put}_pixel():");
>     dump_data(fail, 1);
>     dump_image(fail);
> 
>     return EXIT_SUCCESS;
> }
> 
> --Boundary-00=_yf4jIwl4ur+EkAC
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
> 
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb
> --Boundary-00=_yf4jIwl4ur+EkAC--


More information about the Xcb mailing list