RGBSurface broken or my test is wrong?

Hi,

I’m getting a wrong behaviour in a project, and it looks like I can reproduce it in a sample code. But I’m unsure whether it’s a Xojo bug or if I’m expecting wrong. In this code, the pixel returned by RGBSurface.Pixel is always black.

Here’s the test code (executed on MacOS 12):

Var Pict As Picture=new Picture(32,32)

Pict.Graphics.AntiAliased=False
for i as Integer=0 to 30 step 2 'Draw stipped lines
  Pict.Graphics.DrawLine i,0,i+32,32
  Pict.Graphics.DrawLine 0,i,32,i+32
next i

Var rs1 As RGBSurface=Pict.RGBSurface
Var dct As new Dictionary 'Will hold how many different colours are in the picture

for x as Integer=0 to Pict.Width-1
  for y as Integer=0 to Pict.Height-1
    Var c As Color=rs1.Pixel(x,y) 'Get each pixel's colour
    
    dct.Value(c)=dct.Lookup(c,0)+1
  next y
next x
Break
Return True

At the end, the dictionary just contains one key (the black colour) and its value=1024. All pixels are reported black.
But am I perhaps doing something incorrectly, like constructing the picture with alpha support while I shouldn’t or it’s just a plain bug?
If it’s a bug, how can I work around it?
(more than 1 hour of researches hasn’t led to a solution)

Edit: I’ve found adding the 3rd parameter (depth) when constructing the picture solves the problem. Still, the current behaviour is unexpected with no depth provided, right? (I’d expect at least an exception, if it’s unsupported).

I dont see you setting a color here.
With no color depth, you have a picture that has no real color.
If you don’t explicitly set a drawing color, maybe you are drawing in black on black.
With a color depth, you are drawing in black on white?

to test that theory, try

Var Pict As Picture=new Picture(32,32)
Pict.Graphics.AntiAliased=False
Pict.Graphics.forecolor = &cff0000    // or whatever the API2 equivalent is.

The picture starts plain white and the default drawing colour is black, so this part works as expected.
Have you tried my example and got a black picture? To me, the picture shows fine but the RGBSurface code looks broken.

I tried your theory, without setting a depth, and… that’s odd…
With specifically setting the drawing colour to green, I get two colours from the RGBSurface (black and green); the picture, however, shows stripped as white and green.
And without setting the drawing colour (keeping the default black), the RGBSurface test returns only black; the picture shows stripped white and black.

My assumption that the RGBSurface was broken came from my guess that the picture starts brand white (it used to be so, earlier; also the IDE shows white stripes after drawing my test code).
Actually, it looks like the picture doesn’t start white (despite the IDE showing white stripes). So it’s rather the IDE that shows white pixels where they’re not really white.
Thanks; useful theory.

My assumption that the RGBSurface was broken came from my guess that the picture starts brand white (it used to be so, earlier; also the IDE shows white stripes after drawing my test code).
Actually, it looks like the picture doesn’t start white

I’ve had a lot of similar trouble recently when being given images that had transparent areas.
Some situations draw the transparent areas as black and look awful.
Some show the transparent areas as white.
Looks like the Xojo GUI merges the transparent image onto a white background in the IDE, for purely cosmetic reasons.

I now do the same when called upon to display an image to a user.