Strict
Import mojo2
Import brl.databuffer
Function Main:Int()
New Game
Return 0
End
Class Game Extends App
Field checkred:Int = 206, checkgreen:Int = 246, checkblue:Int = 4, checkalpha:Int = 255 ' << Good test
Field xxx:Int, yyy:Int,screen2:Image, r:Int, g:Int, b:Int, a:Int, sprite:Canvas, canvas:Canvas
Field cc:Float[4], pixels:DataBuffer = New DataBuffer(4*320*200), ptr:Int = 0
Method OnCreate:Int()
canvas=New Canvas
SetSwapInterval 1 ; SetUpdateRate 0
screen2=New Image(320,200,0,0,0) ; sprite=New Canvas(screen2)
cc[0] = checkred/255.0 ; cc[1] = checkgreen/255.0 ; cc[2] = checkblue/255.0 ; cc[3] = checkalpha/255.0
sprite.SetColor cc[0],cc[1],cc[2],cc[3]
sprite.DrawRect 0,0,320,200 ; sprite.Flush
Return 0
End
Method OnRender:Int()
canvas.Clear 0,0,0,0
canvas.SetColor 1,1,1,1
For Local temp:Int = 0 To 100 ' x100 faster test
yyy= Int(ptr/320) ; xxx= ptr-(yyy*320) ; ptr = ptr + 1 ; If ptr > (320*200) Then ptr = 0
sprite.ReadPixels(xxx,yyy,1,1, pixels)
Local pixel:Int[] = ColorToRgb(pixels.PeekInt(Int(Int(0)*4+Int(0)*320*4)))
r = pixel[3] ; g = pixel[2] ; b = pixel[1] ; a = pixel[0]
If r <> checkred Or g <> checkgreen Or b <> checkblue Or a <> checkalpha Then sprite.SetColor 0,0,0,1 ; sprite.DrawRect xxx,yyy,1,1
If r = checkred And g = checkgreen And b = checkblue And a = checkalpha Then sprite.SetColor 0,1,0,1 ; sprite.DrawRect xxx,yyy,1,1 ' Green if okay
Next
sprite.Flush ; canvas.SetColor 1,1,1,1 ; canvas.DrawRect 0,0,640,400,screen2,0,0,320,200
canvas.Flush
Return 0
End
Function ColorToRgb:Int[](value:Int)
' If value < 0 Then Print "negative"
Local resp:Int[] ; resp = resp.Resize(4)
Local v:Int = value ; resp[3] = v & 255 ; v = v Shr 8 ; resp[2] = v & 255 ; v = v Shr 8 ; resp[1] = v & 255 ; v = v Shr 8 ; resp[0] = v & 255
Return resp
End
End