[Cuis-dev] BMP Reader broken

Juan Vuletich juan at cuis.st
Sun Mar 17 11:17:32 PDT 2024


Hi Dave,

On 3/16/2024 6:22 PM, lewis--- via Cuis-dev wrote:
>
> Hi Hilaire,
>
> I compared the behavior in Squeak with both opensmalltalk-vm and with 
> V3 interpreter VM.
>
> In Squeak:
> ImageReadWriter formFromFileNamed: 'splash.bmp'. "==> Form(400x300x32)"
>
> In Cuis (with the same VM):
> ImageReadWriter formFromFileEntry: 'splash.bmp' asFileEntry. "==> Error"
>
> I see two possible issues here.
> 1) The call to #primitiveRead24BmpLine is failing in both Squeak and 
> Cuis. This may be a problem in the VM plugin (or maybe it is expected 
> in this case, I am not sure).
>
> 2) In the primitive fallback code in method 
> #read24BmpLine:into:startingAt:width: the error happens at the 
> "formBits at: (bitsIndex := bitsIndex+1) put: rgb". The formBits is a 
> BitMap, so maybe the some difference between Squeak and Cuis here.
>
> I also tried Squeak with a V3 image and interpreter VM, and the 
> results are the same as with opensmalltalk-vm. The form is created 
> successfully, and the #primitiveRead24BmpLine call fails and goes to 
> the fallback code.
>
> At this point I cannot say if there primitive failure is a problem in 
> the VM plugin, or if the primitive failure is normal and expected for 
> this particular case. But I can say that the actual Error in Cuis must 
> be something related to the fallback code when it updates the formBits 
> BitMap.
>
> Dave
>

As I said in a separate email, Vanessa found the origin of the problem, 
and the fix is now at GitHub.

Still, as you say, the primitive fails, both in Cuis and Squeak, but 
only the first time it is called. The lines are read in reverse order, 
so the line that is first copied is actually the last one.

In #read24BmpLine:into:startingAt:width:, at the start of the fallback 
code, I added this line: `{formBitsIndex+width. formBits size} print.`. 
Then tried to load Hilaire's BMP. In the Transcript I got #(63601 
63600). So, in BMPReadWriterPlugin.c, the lines that read:

     if (!(((formBitsIndex + width) <= formBitsSize)
&& ((width * 3) <= pixelLineSize))) {
         return primitiveFail();

should actually read

     if (!(((formBitsIndex + width - 1) <= formBitsSize)
&& ((width * 3) <= pixelLineSize))) {
         return primitiveFail();

and the primitive will not fail.

It is a minor bug, with no practical consequences, so this is not really 
important. But I found this while investigating the BMP read failure, 
and I thought it was worth commenting.

Thanks,

-- 
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240317/a57ecb96/attachment.htm>


More information about the Cuis-dev mailing list