The
get image command does not grab the alpha component from a bitmap correctly.
The following code produces two sets of images with alpha from a bitmap. The first set are produced using the get image command whereas the second are obtained using memblock commands. Both versions grab the colour from bitmap 1. The two sets should be identical.
However, the alpha component of the image produced by the get image version is corrupted. The image produced using memblocks is not corrupt. In each case the RGB channels are correct.
The following screenshot shows the corruption clearly as a black square in the upper left corner of the alpha map.
[Additional tests not detailed here show that the RGB channels are involved with the corruption in some way.]
` simple program to demonstrate "get image" alpha bug
set display mode desktop width(), desktop height(), 32
sync on : sync rate 60 : sync
set bitmap format 21
create bitmap 1, 128, 128
dim band(127)
dim myColour(127, 127) as dword
colour as dword
` initialise colour arrays into 4 bands
for b = 0 to 127
band(b) = (b/32) * 85
next b
for x = 0 to 127
for y = 0 to 127
` red is banded vertically
` green is banded horizontally
` blue is banded diagonally SW to NE
` alpha is fully transparent inside a circle, opaque outside the circle
red = band(x)
green = band(y)
blue = band((x + y)/2)
if (x - 64)^2 +(y - 64)^2 < 1024
alpha = 0
else
alpha = 255
endif
myColour(x, y) = alpha * 16777216 + red * 65536 + green * 256 + blue
dot x, y, myColour(x, y)
next y
next x
get image 1, 0, 0, 128, 128 ` this produces an image with the alpha value corrupted - see alpha component of dds file
save image "alpha corrupt.dds", 1
save image "alpha corrupt.bmp", 1 ` included for easy viewing of colour channels
` now create a second copy using the memblock commands
make memblock from image 1, 1 ` create a memblock of the correct size
` overwrite memblock colour information using same colour information from bitmap
position = 12
for x = 0 to 127
for y = 0 to 127
write memblock dword 1, position, point(x, y)
inc position, 4
next y
next x
make image from memblock 2, 1 ` this image is NOT corrupted - see alpha component of dds file
save image "alpha not corrupt.dds", 2
save image "alpha not corrupt.bmp", 2
set current bitmap 0
paste image 2, 0, 0
sync
wait key
end