I've been playing around with Skidracer's 'bank to buffer' code snippet that appeared in the Blitz newsletter, and am running into some weird issues...
I am trying to copy an image into the buffer to start out with, but apparently am doing something wrong: while the image shows up in the buffer, the colors are all off, and not what they supposed to be. The problem appears to be somewher in the 'image2bank' function below:
Now... Through experimentations and such I determined that for a 16 bit image, the colors are stored in two bytes. One byte containing Red/Green, and one byte containing Blue/???.
Some basic testing showed this:
$F000 - Red
$0F00 - Green
$FF00 - Yellow
$00FF - Bright blue
$00F0 - darker blue
$FFF0 - pale yellow
$FFFF - white
To me, this appears to indicate that the BLUE color is actually stored in a 256-color gradation instead of 16, like red and green are, unless I'm misinterpreting these results.
So... I tried to convert these red/green/blue values back into a short, and poke it into the image bank... But like I said before *something* is very wrong, since the colors are completely messed up. I tried a bunch of variations, including poking the red/green and blue bytes seperately using pokebyte, but am running in the exact same issue.
I'm about ready to beat my head against a wall here: what am I doing wrong?!
Any help would be much appreciated.
I am trying to copy an image into the buffer to start out with, but apparently am doing something wrong: while the image shows up in the buffer, the colors are all off, and not what they supposed to be. The problem appears to be somewher in the 'image2bank' function below:
Const screenwidth=640 Const screenheight=480 Global img% Function CopyBankToBuffer(bank3,buffer) ; lock the image for byte transfer LockBuffer buffer ; test locked imagebuffer is 16 bits per pixel If LockedFormat(buffer)<>1 UnlockBuffer buffer Notify("this test is 16 bit display mode only") End EndIf ; cache buffer variables imagebank=LockedPixels(buffer) pitch=LockedPitch(buffer) ; copy bank to image line by line For y=1 To screenheight CopyBank bank3,srcoff,imagebank,destoff,screenwidth*2 srcoff=srcoff+screenwidth*2 destoff=destoff+pitch Next UnlockBuffer buffer End Function Function image2bank(bank3) DrawImage img%,0,0 LockBuffer BackBuffer() For y=0 To screenheight-1 For x=0 To screenwidth-1 arg=ReadPixelFast (x,y,BackBuffer()) ; Extract 1 byte Red, Green, Blue values, and divide by 16 to convert to ; a value between 0 and F - blue does not get divided and stays original argr=(arg And $ff0000) Shr 20 argg=(arg And $ff00) Shr 12 argb=(arg And $ff) Shr 4 ; reconstruct the color value in 16 bit format ; ??? is the Blue part correct ??? arg=(argr Shl 12)+(argg Shl 8)+argb PokeShort bank3,o,arg o=o+2 Next Next UnlockBuffer BackBuffer() End Function Graphics screenwidth,screenheight,16,2 SetBuffer BackBuffer() bank2=CreateBank(screenwidth*screenheight*2) img%=LoadImage("x:\monkey5.jpg") SetBuffer BackBuffer() DrawBlock img%,0,0 image2bank(bank2) Flip WaitKey() copybanktobuffer(bank2,BackBuffer()) Flip WaitKey() End
Now... Through experimentations and such I determined that for a 16 bit image, the colors are stored in two bytes. One byte containing Red/Green, and one byte containing Blue/???.
Some basic testing showed this:
$F000 - Red
$0F00 - Green
$FF00 - Yellow
$00FF - Bright blue
$00F0 - darker blue
$FFF0 - pale yellow
$FFFF - white
To me, this appears to indicate that the BLUE color is actually stored in a 256-color gradation instead of 16, like red and green are, unless I'm misinterpreting these results.
So... I tried to convert these red/green/blue values back into a short, and poke it into the image bank... But like I said before *something* is very wrong, since the colors are completely messed up. I tried a bunch of variations, including poking the red/green and blue bytes seperately using pokebyte, but am running in the exact same issue.
I'm about ready to beat my head against a wall here: what am I doing wrong?!
Any help would be much appreciated.