RGBSurface 64bit bug

I just filed a bug report for RGBSurface. When the sample code from Xojo is used, it runs fine when compiled 32 bit, but does not when compiled 64 bit;

[code]Dim surf As RGBSurface = somePicture.RGBSurface
Dim lastX As Integer = somePicture.Width - 1
Dim lastY As Integer = somePicture.Height - 1
For y As Integer = 0 To lastY
For x As Integer = 0 To lastX
If surf.Pixel(x,y) = &c000000 Then
surf.Pixel(x,y) = &cFFFFFF
End if
Next
Next

g.DrawPicture(somePicture, 0, 0, somePicture.Width, somePicture.Height)
[/code]

The expected behaviour is the black pixels to turn white, but in 64 bit, all pixels turn white.
The case is: 41938 - RGBsurface Mac 64bit bug

If anyone has a suggestion for a workaround that would be greatly appreciated.

It works just fine here.

You can replace Surf by somepicture.graphics but I suspect there is something else with your picture.

[code] Dim lastX As Integer = somePicture.Width - 1
Dim lastY As Integer = somePicture.Height - 1
For y As Integer = 0 To lastY
For x As Integer = 0 To lastX
If val(str(somepicture.graphics.Pixel(x,y))) < &h202020 Then
somepicture.graphics.Pixel(x,y) = &c00FF00
End if
Next
Next

g.DrawPicture(somePicture, 0, 0, somePicture.Width, somePicture.Height)[/code]

[quote=237541:@Michel Bujardet]It works just fine here.

You can replace Surf by somepicture.graphics but I suspect there is something else with your picture.

[code] Dim lastX As Integer = somePicture.Width - 1
Dim lastY As Integer = somePicture.Height - 1
For y As Integer = 0 To lastY
For x As Integer = 0 To lastX
If val(str(somepicture.graphics.Pixel(x,y))) < &h202020 Then
somepicture.graphics.Pixel(x,y) = &c00FF00
End if
Next
Next

g.DrawPicture(somePicture, 0, 0, somePicture.Width, somePicture.Height)[/code][/quote]

I thought caching the RGBsurface is the way to go instead if referencing to somepicture.graphics.pixel(x,y)

@Michel Bujardet : It works fine only in 32 bit, not in 64 bit. The image is a plain vanilla Jpeg;

The code in the canvas paint event;

[code] Dim surf As RGBSurface = AdeleMini.RGBSurface
Dim lastX As Int16 = AdeleMini.Width - 1
Dim lastY As Int16 = AdeleMini.Height - 1
For y As Int16 = 0 To lastY
For x As int16 = 0 To lastX
If surf.Pixel(x,y) = &c000000 Then
surf.Pixel(x,y) = &cFFFFFF
End if
Next
Next

g.DrawPicture(AdeleMini, 0, 0, AdeleMini.Width, AdeleMini.Height)[/code]

Maybe I’m missing something, but it does not show the same result in 64bit as in 32 bit

Following Michel’s comment on using graphics instead of RGBsurface; that does work as expected, so thanks for that suggestion Michel.
So is this a 64 bit bug in RGBsurface or am I just missing something on how RGBsurface works?

Confirmed in 2015R3

I also tried creating a local copy of the image and working on that.
Same thing.

Works fine substituting graphics for rgbsurface

[code] dim p as new picture (Adelemini.width,Adelemini.height,32)
p.Graphics.drawpicture Adelemini,0,0
Dim surf As RGBSurface = p.RGBSurface
Dim lastX As Int16 = AdeleMini.Width - 1
Dim lastY As Int16 = AdeleMini.Height - 1
For y As Int16 = 0 To lastY
For x As int16 = 0 To lastX
If surf.Pixel(x,y) = &c000000 Then
surf.Pixel(x,y) = &cFFFFFF
End if
Next
Next

g.DrawPicture(p, 0, 0, AdeleMini.Width, AdeleMini.Height)[/code]

@Jeff Tullin : Thanks Jeff, thought it was just me :slight_smile:

Both are fine, but RGBSurface is faster.

@Michel Bujardet :[quote]Both are fine, but RGBSurface is faster.[/quote]
That’s exactly why I would like it to work in 64 bit with RGBsurface instead of graphics, which it does not on 2015R3 or 2015R4

I investigated further. The bug is not in getting the pixel, it is in setting it.

This works just fine in a 64 bit build.

[code]dim p as new picture (Adelemini.width,Adelemini.height,32)
p.Graphics.drawpicture Adelemini,0,0
Dim surf As RGBSurface = p.RGBSurface
Dim lastX As Int16 = AdeleMini.Width - 1
Dim lastY As Int16 = AdeleMini.Height - 1
For y As Int16 = 0 To lastY
For x As int16 = 0 To lastX
If surf.Pixel(x,y) = &c000000 Then
AdeleMini.graphics.Pixel(x,y) = &cFFFFFF
End if
Next
Next

g.DrawPicture(p, 0, 0, AdeleMini.Width, AdeleMini.Height)[/code]

You should file a bug report.

@Michel Bujardet : Thanks, I did: case is: 41938 - RGBsurface Mac 64bit bug
I will add the fact that setting the surface pixel is the problem. Thank you for helping get to the root of the problem.

Something else seems odd.

To simply switch black to white, Transform is faster, and it does ‘work’ in 64bit.

[code] dim r(255) as integer
r(0) = 255
for z as integer = 1 to 255
r(z) = z
next

adelemini.RGBSurface.Transform ®
g.DrawPicture(adelemini, 0, 0, AdeleMini.Width, AdeleMini.Height)[/code]

But for some reason I cannot work out yet, it is making some pixels go blue, where the other method leaves it in sepia tones.

@Jeff Tullin : Thanks Jeff, but I’m using a custom algorithm so a transform won’t work for me.

A bug ? Really ? ;-:slight_smile:

I was thinking it is because she does not love Apple !

It works if you define 2 rgbSurface

[code] dim p as new picture (Adelemini.width,Adelemini.height,32)
p.Graphics.drawpicture Adelemini,0,0
Dim surf As RGBSurface = p.RGBSurface
dim origSurf as RGBSurface= Adelemini.RGBSurface // ref to original RGB surface
Dim lastX As Int16 = AdeleMini.Width - 1
Dim lastY As Int16 = AdeleMini.Height - 1
For y As Int16 = 0 To lastY
For x As int16 = 0 To lastX
If origSurf.Pixel(x,y) = &c000000 Then
surf.Pixel(x,y) = &cFFFFFF
End if
Next
Next

g.DrawPicture(p, 0, 0, AdeleMini.Width, AdeleMini.Height)[/code]