new PNGReadWriter with libpng support

Andreas Raab andreas.raab at
Wed Nov 22 19:21:49 UTC 2006

Jens Lincke wrote:
>> All I find in there is
>> PNGReadWriter2>>primPNGReadImageFromByteArray: source onForm: form
>>         self primitiveFailed
> primPNGReadImageFromByteArray: source onForm: form
>    <primitive: 'primPNGReadImageFromByteArrayonForm' module: 
> 'PNGReadWriter2Plugin'>
>    self primitiveFailed

How odd. Why doesn't Squeaksource show the primitive? I just downloaded 
the package and sure enough the code is in there but when you browse it 
on SS it doesn't show.

>> I'm a little confused to see statements like here in the plugin:
>>    formPix isNil ifTrue: [formPix := 1].
> this is an artifact of the translation from c to slang
> the line came from the JPEGPlugin:
> formPix = (255 << 24) | (buffer[0][i+rOff] << 16) | (buffer[0][i+gOff] 
> << 8) | buffer[0][i+bOff];
>                                if (formPix == 0) formPix = 1;

Oh, interesting - indeed the code generator translates isNil 
specificially. I didn't even know that ;-) (but I still think this 
should say "formPix = 0" instead of "formPix isNil" in the Slang code)

>> this should be translated to isNil(formPix) and as far as I am aware 
>> there is no such function available anywhere. Also, it seems as if 
>> there are some serious hazards for decoding the PNG data - the code 
>> doesn't set a limit for the source of input when decoding so I presume 
>> libpng will simply fall over and break (possibly corrupting Squeak 
>> memory) if you give it partial input?
> there is an error handler for png errors, which will return to squeak, 
> but no other checks.

This sounds fishy ... how can libpng guarantee that it won't access data 
outside the source buffer if it doesn't even know how big the input is?

On a related note: For PNGReadWriter I spent some time making sure that 
we can write 16 bit forms with no loss in precision when using 
PNGReadWriter. The way I did this was to use the sBIT (basically storing 
the number of significant bits for each channel as 5:5:5:1) - is there a 
way of retrieving this information from PNGReadWriter2 so that client 
code can (safely) do the conversion from 32 -> 16 bit?

   - Andreas

More information about the Squeak-dev mailing list