Here's an example of drawing with memblocks:
I'm not sure how efficient the functions are as I wrote them a few years ago.
remstart
-------------------------------------------------------------------
program name: Memblock Bitmap Functions
-------------------------------------------------------------------
written by: Oli Burt
date: 6th April 2009 - 9th April 2009
-------------------------------------------------------------------
comments:
-------------------------------------------------------------------
remend
set display mode 640,480,32
make_memblock_bmp(1,640,480,32)
flood_memblock_bmp(1,rgb(255,255,255))
wirebox_memblock_bmp(1,200,100,300,250,rgb(255,0,0))
line_memblock_bmp(1,20,300,400,260,rgb(0,255,0))
make bitmap from memblock 0,1
wait key
delete memblock 1
end
`--------------
` Functions
`--------------
Function box_memblock_bmp(memblock,ax,ay,bx,by,colour)
`Read Header
width= memblock dword(memblock,0)
height= memblock dword(memblock,4)
byte_depth= memblock dword(memblock,8)/8
`Edit Memblock
for y = ay to by
for x = ax to bx
write memblock dword memblock,12+x*byte_depth+y*width*byte_depth, colour
next x
next x
Endfunction
`//
Function dot_memblock_bmp(memblock,x,y,colour)
`Read Header
width= memblock dword(memblock,0)
height= memblock dword(memblock,4)
byte_depth= memblock dword(memblock,8)/8
`Edit Memblock
write memblock dword memblock,12+x*byte_depth+y*width*byte_depth, colour
Endfunction
`//
Function flood_memblock_bmp(memblock,colour)
`Read Header
width= memblock dword(memblock,0)
height= memblock dword(memblock,4)
byte_depth= memblock dword(memblock,8)/8
`Edit Memblock
for y = 0 to height-1
for x = 0 to width-1
write memblock dword memblock,12+x*byte_depth+y*width*byte_depth, colour
next x
next y
Endfunction
`//
Function line_memblock_bmp(memblock,ax,ay,bx,by,colour)
`Read Header
width= memblock dword(memblock,0)
height= memblock dword(memblock,4)
byte_depth= memblock dword(memblock,8)/8
`Get Line Length (Hypotenuse of x/y triangle)
xdif= ax-bx
ydif= ay-by
hyp= sqrt(xdif*xdif + ydif*ydif)
`Edit Memblock
for pass = 1 to hyp
factor#= pass/(hyp*1.0)
x= ax - int((ax-bx)*factor#+.5)
y= ay - int((ay-by)*factor#+.5)
write memblock dword memblock,12+x*byte_depth+y*width*byte_depth, colour
next pass
Endfunction
`//
Function make_memblock_bmp(memblock,width,height,bit_depth)
if memblock exist(memblock) = 0
byte_depth= bit_depth/8
make memblock memblock,12+width*height*byte_depth^2
`Header (12 bytes)
write memblock dword memblock,0,width
write memblock dword memblock,4,height
write memblock dword memblock,8,bit_depth
endif
Endfunction
`//
Function point_memblock_bmp(memblock,x,y)
`Read Header
width= memblock dword(memblock,0)
height= memblock dword(memblock,4)
byte_depth= memblock dword(memblock,8)/8
`Read From Memblock
colour = memblock dword(memblock,12+x*byte_depth+y*width*byte_depth)
Endfunction colour
`//
Function make_reflect_memblock_bmp(memblock_b,memblock_a,colour)
`Read Header
width= memblock dword(memblock_a,0)
height= memblock dword(memblock_a,4)
byte_depth= memblock dword(memblock_a,8)/8
`Make Reflection Memblock
make memblock memblock_b,12+width*height*byte_depth^2
`Write Header (12 bytes)
write memblock dword memblock_b,0,width
write memblock dword memblock_b,4,height
write memblock dword memblock_b,8,bit_depth
`Reverse-Copy Memblock
for y = 0 to height-1
for x = 0 to width-1
copy= memblock dword(memblock_a,12+x*byte_depth+(height-1-y)*width*byte_depth)
write memblock dword memblock_b,12+x*byte_depth+y*width*byte_depth, copy
next x
next y
Endfunction
`//
Function wirebox_memblock_bmp(memblock,ax,ay,bx,by,colour)
`Read Header
width= memblock dword(memblock,0)
height= memblock dword(memblock,4)
byte_depth= memblock dword(memblock,8)/8
`Edit Memblock
for x = ax to bx
write memblock dword memblock,12+x*byte_depth+ay*width*byte_depth, colour
write memblock dword memblock,12+x*byte_depth+by*width*byte_depth, colour
next x
for y = ay to by
write memblock dword memblock,12+ax*byte_depth+y*width*byte_depth, colour
write memblock dword memblock,12+bx*byte_depth+y*width*byte_depth, colour
next y
Endfunction
`//
To convert a memblock to bitmap it needs to be in the correct format.
The first 12 bytes of any memblock bitmap are known as the header. This chunk of data stores the bitmap's dimensions: width, height and depth; each being stored in a 4B DWORD (12B/3 = 4B).
The rest of the memblock is one long stream of pixel data. The length of each pixel (in bytes) depends on the depth of the bitmap; annoyingly the depth of the bitmap is stored in bits but pixels are stored in bytes, so you will need to divide the bit-depth by eight to get the "byte-depth" (you'll see this in my code).
(Side-note: did you know the word "byte" comes from "by-eight"?)
Converting the 1D pixel data to 2D requires use of the width, height and depth values (you will see this in my code).
This whole process is basically controlling your own screen buffer. It's great for DBC since there is no un/lock pixels command.