Show a basic storage type to handle a simple RGB raster graphics image,
and some primitive associated functions.

If possible provide a function to allocate an uninitialised image,
given its width and height, and provide 3 additional functions:

   one to fill an image with a plain RGB color,
   one to set a given pixel with a color,
   one to get the color of a pixel.


(If there are specificities about the storage or the allocation, explain those.)

These functions are used as a base for the articles in the category raster graphics operations, 
and a basic output function to check the results
is available in the article write ppm file.




hex
0000ff constant red
00ff00 constant green
ff0000 constant blue
decimal
 
1 cells constant pixel
: pixels cells ;
 
: bdim ( bmp -- w h ) 2@ ;
: bheight ( bmp -- h ) @ ;
: bwidth ( bmp -- w ) bdim drop ;
: bdata ( bmp -- addr ) 2 cells + ;
 
: bitmap ( w h -- bmp )
  2dup * pixels bdata allocate throw
  dup >r 2! r> ;
 
: bfill ( pixel bmp -- )
  dup bdata swap bdim * pixels
  bounds do
    dup i !
  pixel +loop
  drop ;
 
: bxy ( x y bmp -- addr )
  dup >r bwidth * + pixels r> bdata + ;
 
: b@ ( x y bmp -- pixel ) bxy @ ;
: b! ( pixel x y bmp -- ) bxy ! ;
 
: bshow ( bmp -- )
  hex
  dup bdim
  0 do cr
    dup 0 do
      over i j rot b@ if [char] * else bl then emit  \ 7 u.r
    loop
  loop
  2drop decimal ;
 
4 3 bitmap value test
red test bfill
test bshow cr