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.




 
'GENERIC BITMAP
 
type pixel byte r,g,b
 
'===========
class BitMap
'===========
 
% sp   sizeof(pixel)
sys    wx,wy,px,py
string buf
sys    pb
method Constructor(sys x=640,y=480) { wx=x : wy=y : buf=nuls x*y*sp : pb=strptr buf}
method Destructor()                 {buf="" : wx=0 : wy=0 : pb=0}
method GetPixel(sys x,y,pixel*p)    {copy @p,pb+(y*wx+x)*sp,sp}
method SetPixel(sys x,y,pixel*p)    {copy pb+(y*wx+x)*sp,@p,sp}
'
method Fill(pixel*p)
  sys i, e=wx*wy*sp+pb-1
  for i=pb to e step sp {copy i,@p,sp}
end method
 
end class
 
pixel p,q
 
new BitMap m(400,400) 'width, height in pixels
 
p<=100,120,140 'red,green,blue
 
m.fill p
 
m.getPixel 200,100,q
print "" q.r "," q.g "," q.b 'result 100,120,140
q<=10,20,40
m.setPixel 200,100,q
m.getPixel 200,100,p
print "" p.r "," p.g "," p.b 'result 10,20,40
 
 
del m
 