[OLPC-Games] Weird Cairo ImageSurface issue

Mike C. Fletcher mcfletch at vrplumber.com
Mon Feb 4 00:51:42 EST 2008


Hi all, looking for some eyes to go over a problem...

Bug report on OLPCGames shows that on 32-bit machines, the svg sprite
rendering code is showing the wrong colours.  On 64-bit machines it
shows the correct colours.  The process used to render svg is like this:

Create a context with:

    csrf = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    context = cairo.Context (csrf)

draw into the context with an rsvg handle, then convert to a Pygame
image like this (just taking the path that the failing instances take):

    format = 'ARGB'
    ...
        data = csrf.get_data()
        ...
                import array
                a = array.array( 'I' )
                a.fromstring( data )
                a.byteswap()
                data = a.tostring()
        ...
        return pygame.image.fromstring(
            data,
            (width,height),
            format
        ) # there's the next

on AMD64 (using Pygame-ctypes due to a bug in regular Pygame), this
produces the correct colours and alpha channel.  On 32-bit machines
(which use non-ctypes Pygame) it produces colours that seem to have the
mapping:

A -> G
R -> B
G -> A
B -> R

applied to them, that is, shifted by 16 bits from where they should be. 
The csrf reports get_type() == 0, which is type ARGB, so it doesn't
*look* like a problem with the surface being e.g. 16-bit instead of 24 bit.

Anyway, I've burned a lot of hours looking for the problem.  It will
have to be something small, but I seem to be past the point of being
able to recognise it this evening.  If someone wants to poke at the
problem and tell me what I've done stupidly I would appreciate it.  I've
attached a simple test svg file to let you see the failure in svgspritetest.

Thanks all,
Mike

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: allcolours.svg
Type: image/svg+xml
Size: 5017 bytes
Desc: not available
Url : http://lists.laptop.org/pipermail/games/attachments/20080204/1aa63efa/attachment.svg 


More information about the Games mailing list