[Image-SIG] Having trouble with raw encoder.

Alex Tweedly alex at tweedly.net
Wed Jul 6 02:02:53 CEST 2005

I receive data from an external source, 4 bytes per pixel, as 
<0><r><g><b> and I want to, amongst other things, save it as a jpg file.

I'm having trouble getting this to work properly. I thought it should be 
simple - but it doesn't seem to be, so I guess I'm misunderstanding 
something. I reproduced the problem in a small sample function 
independent of my data source:

> def handle(filename):
>     orig = Image.open(filename)
>     print orig.format, orig.size, orig.mode
>     xrgbstring = orig.tostring('raw', "XRGB")
>     print  "length of xrgbstring", len(xrgbstring), [ord(x) for x in 
> xrgbstring[:20]]
>     t2 = Image.fromstring("RGB", orig.size, xrgbstring, 'raw', "XRGB")
>     t2.save("t2.jpg")

The second print statement confirms for me that I have got this data 
into the same format as I need to deal with - and I expected the 
following 'fromstring' to give me the correct result. But once saved, 
"t2.jpg" looks all wrong - looks like  4 ghostly copies of the original.

I did notice that in unpack.c, the entry for XRGB says

>     {"RGB",    "XRGB",        24,    ImagingUnpackXRGB},

and wondered why "24" bits - seemed like it should be 32 - but I know 
I'm well out of my depth here, and it's time to ask for help.

Any ideas or suggestions ?

Alex Tweedly       http://www.tweedly.net

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.8.8/37 - Release Date: 01/07/2005

More information about the Image-SIG mailing list