Here is a little simple pixel plotter I wrote awhile ago, using an uncompressed gif this only supports 4 index colors(trivial to change to support up to 127 colors). When I was trying to find something faster then doing DrawRect(x,y,1,1,c) . Maybe someone can find a use, my 8080 space invaders emulator port was still way to slow
😞Thanks,
Troy
main.brs
' ******
' ****** Create a GIF For Roku by Troy Davis(GPF)
' ******
Library "v30/bslDefender.brs"
Function IsHD()
di = CreateObject("roDeviceInfo")
if di.GetDisplayType() = "HDTV" then return true
return false
End Function
function main()
width%=160
height%=144
bckcolrindx%=0
trnspclrindx%=0
theGIF = CreateObject("roByteArray")
tmpfilename = "tmp:/1.gif"
print "Temp File "+tmpfilename
backstop = CreateObject("roParagraphScreen")
backstop.show()
if IsHD()
screen=CreateObject("roScreen", true, 854, 480) '
else
screen=CreateObject("roScreen", true)
endif
msgport = CreateObject("roMessagePort")
screen.SetPort(msgport)
initgif(width%,height%,bckcolrindx%,trnspclrindx%,theGIF)
print "Gif Init done"
for y% = 0 to (height%-1)
for x%=0 to (width%-1)
plotgif(x%,y%,width%, fix( (x%+y%) MOD 3),theGIF )
end for
end for
print "Gif Plotting done"
savegif(tmpfilename,theGIF)
print "Gif saved done"
newGIF=CreateObject("roBitmap", tmpfilename)
print "Gif loading done"
if newGIF = invalid
print "newGIF create failed"
stop
endif
screen.drawobject(50, 50, newGIF)
screen.SwapBuffers()
print "Gif drawing done"
DeleteFile(tmpfilename)
codes = bslUniversalControlEventCodes()
pressedState = -1 ' If > 0, is the button currently in pressed state
while true
if pressedState = -1 then
msg=wait(0, msgport) ' wait for a button press
else
msg=wait(1, msgport) ' wait for a button release or move in current pressedState direction
endif
if type(msg)="roUniversalControlEvent" then
keypressed = msg.GetInt()
print "keypressed=";keypressed
if keypressed=codes.BUTTON_BACK_PRESSED then
pressedState = -1
exit while
end if
else if msg = invalid then
print "eventLoop timeout pressedState = "; pressedState
end if
end while
end function
gifplotter.brs
' ****************************************************************
' * Generates a GIF with 4 colors that can be updated *
' * For Roku by Troy Davis(GPF) *
' ****************************************************************
function initgif (width% as integer, height% as integer, backgroundcolorindex% as integer, transparentcolorindex% as integer, theGIF as object)' as object', colorpal as object, numcolors as integer) as
bodylength%=fix((width%*height%)/126)
bodyremain%=(width%*height%) MOD 126
'theGIF.setresize( 416+(bodylength%*128)+bodyremain%+6,false)
theGIF.push(asc("G"))
theGIF.push(asc("I"))
theGIF.push(asc("F"))
theGIF.push(asc("8"))
theGIF.push(asc("9"))
theGIF.push(asc("a"))
theGIF.push(0) ' Width
theGIF.push(1) ' Width
theGIF.push(0) ' Height
theGIF.push(1) ' Height
theGIF.push(&HF1) ' GCT follows for 4 colors
theGIF.push(0) ' Background color
theGIF.push(0) ' default pixel aspect ratio
theGIF.push(0) ' Color 0 Black
theGIF.push(0) ' Color 0 Black
theGIF.push(0) ' Color 0 Black
theGIF.push(&HFF) ' Color 1 White
theGIF.push(&HFF) ' Color 1 White
theGIF.push(&HFF) ' Color 1 White
theGIF.push(&HFF) ' Color 2 Red
theGIF.push(0) ' Color 2 Red
theGIF.push(0) ' Color 2 Red
theGIF.push(0) ' Color 3 Green
theGIF.push(&HFF) ' Color 3 Green
theGIF.push(0) ' Color 3 Green
theGIF.push(&H21) ' Graphic Control Extension
theGIF.push(&HF9) ' Graphic Control Extension
theGIF.push(4) ' 4 bytes of GCE data follow
theGIF.push(1) ' there is a transparent background color
theGIF.push(0) ' delay for animation: not used
theGIF.push(0) ' there is a transparent background color
theGIF.push(0) ' color #0 is transparent
theGIF.push(0) ' end of GCE block
theGIF.push(&H2C) ' Image Descriptor
theGIF.push(0) ' NW corner position of image in logical screen
theGIF.push(0) ' NW corner position of image in logical screen
theGIF.push(0) ' NW corner position of image in logical screen
theGIF.push(0) ' NW corner position of image in logical screen
theGIF.push(0) ' Width
theGIF.push(1) ' Width
theGIF.push(0) ' Height
theGIF.push(1) ' Height
theGIF.push(0) ' no local color table
theGIF.push(7) ' Start of image - LZW minimum code size
'theGIF.ReadFile("pkg:/data/gifhead.bin")
'm.width%=width%
'm.height%=height%
tempw%=(width% and &HFF)
theGIF[6]=tempw%
theGIF[38]=tempw%
tempw%=((width%/256) and &HFF)
theGIF[7]=tempw%
theGIF[39]=tempw%
temph%=(height% and &HFF)
theGIF[8]=temph%
theGIF[40]=temph%
temph%=((height%/256) and &HFF)
theGIF[9]=temph%
theGIF[41]=temph%
theGIF[11]=backgroundcolorindex%
theGIF[30]=transparentcolorindex%
gifpart = CreateObject("roByteArray")
'gifpart.ReadFile("pkg:/data/gifpart.bin")
gifpart.fromhexstring(String(252,"0"))
For i%=0 to bodylength%-1
if (i% <> bodylength%)
theGIF.push(127)
theGIF.push(128)
end if
theGIF.append(gifpart)
end for
theGIF.push(3+bodyremain%)
theGIF.push(128)
For i%=0 to bodyremain%-1
theGIF.push(0)
end for
theGIF.push(129)
theGIF.push(0)
theGIF.push(0)
theGIF.push(59)
end function
function plotgif (x% as integer, y% as integer, width% as integer, colorindex% as integer, theGIF as object)' as object
theGIF[(46+(((width%)*y%+x%))+( fix(((width%)*y%+x%)/126)*2))] = colorindex%
'return theGIF
end function
function savegif (filename as string, theGIF as object)
'?theGIF.count()
'print "File "+filename
theGIF.writefile(filename)
'myurl=CreateObject("roUrlTransfer")
'myurl.SetUrl("http://192.168.0.2/roku/upload.php")
'myurl.AddHeader("Content-Type", "image/png")
'myurl.PostFromFile(filename)
return 1
end function