[Image-SIG] Endian-ness bug? (Was Re: Problem choosing inks/drawing in GIF file)
Manoj Plakal
plakal@cs.wisc.edu
Tue, 10 Jul 2001 18:41:12 -0500
Manoj Plakal wrote (Tue, Jul 10, 2001 at 05:53:43AM -0500) :
> I'm trying to use PIL to draw a line
> graph on a pre-existing GIF template file.
>
> However, for some reason, no matter
> what palette index I specify as
> the ink, the lines I draw are all white
> (which happens to be the first color
> in the palette).
>
> Could anyone see what I'm doing wrong?
> Code is at the end of the message.
> This is with PIL-1.1.2, Python 2.1,
> Solaris 2.8.
I finally figured out the problem.
There seems to be a bug in the
support code in PIL where
_draw_lines() (in _imaging.c)
passes a pointer to an int
as the ink parameter to
the ImagingDrawLine() function
in libImaging which then treats it
as a pointer to unsigned char (UINT8).
This returns zero on big-endian
SPARC but returns the correct
ink value on little-endian x86.
I modified it myself to make
it work for me but I assumed
that this kind of stuff would
be handled by the configure
scripts since this kind of casting
makes assumptions about endian-ness.
Manoj
> ------------------------------------------
> import Image, ImageDraw
>
> image = Image.open( "graph_template.gif" ) # -- 500x600 GIF, 67-color palette
>
> draw = ImageDraw.Draw( image )
> draw.setink(1) # -- Orange-ish
> draw.line( [(52,550),(220,40)] )
> draw.setink(2) # -- another shade of orange
> draw.line( [(220,40),(300,550)] )
> draw.ellipse( (52,40,300,550) )
>
> image.save( "graph.gif" )
> ------------------------------------------
>