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.




INCLUDE "H6:RGBIMAGE.ACT" ;from task Bitmap
 
RGB black,yellow,violet,blue
 
PROC DrawImage(RgbImage POINTER img BYTE x,y)
  RGB c
  BYTE i,j
 
  FOR j=0 TO img.h-1
  DO
    FOR i=0 TO img.w-1
    DO
      GetRgbPixel(img,i,j,c)
      IF RgbEqual(c,yellow) THEN
        Color=1
      ELSEIF RgbEqual(c,violet) THEN
        Color=2
      ELSEIF RgbEqual(c,blue) THEN
        Color=3
      ELSE
        Color=0
      FI
      Plot(x+i,y+j)
    OD
  OD  
RETURN
 
PROC Main()
  RgbImage img
  BYTE CH=$02FC,width=[80],height=[60]
  BYTE ARRAY ptr(14400)
  BYTE i,x,y,c
 
  Graphics(7+16)
  SetColor(0,13,12) ;yellow
  SetColor(1,4,10)   ;violet
  SetColor(2,8,6)   ;blue
  SetColor(4,0,0)   ;black
 
  RgbBlack(black)
  RgbYellow(yellow)
  RgbViolet(violet)
  RgbBlue(blue)
 
  InitRgbImage(img,width,height,ptr)
  FillRgbImage(img,blue)
 
  FOR i=1 TO 1000
  DO
    c=Rand(3)
    x=Rand(width)
    y=Rand(height)
    IF c=0 THEN
      SetRgbPixel(img,x,y,yellow)
    ELSEIF c=1 THEN
      SetRgbPixel(img,x,y,violet)
    ELSE
      SetRgbPixel(img,x,y,black)
    FI
  OD
 
  DrawImage(img,(160-width)/2,(96-height)/2)
 
  DO UNTIL CH#$FF OD
  CH=$FF
RETURN