Graphics

= Working with bitmaps and rastports = Bitmaps are low level primitives which consists of the pixel data for a graphics image. Rastports are high level objects which encapsulate bitmaps and encapsulate drawing information used with the bitmap.

Setting drawing colors
To set drawing colors you can use the pen system or RGB colour values. RGB color values are supported only on high color or true color targets. RGB colour is set with SetRPAttrs using RPTAG_FgColor and RPTAG_BgColor tags.

RGB drawing mode
You need to switch pen mode off only once if you are only using RGB color triplets. Setting a rendering pen with SetAPen, SetBPen and SetOPen switch the pen mode on automatically and the original rendering pen is restored.

Pen drawing mode
Using pen mode is more complicated but it is always only way to draw primitives to palette based rastports. You should always obtain the pen using your preferred color. When terminating your rendering target you have to release the drawing pen.

Using drawing pens is only for advanced developers.

Text
Here is an example how to draw test using RGB colour values:

Drawing lines
To draw lines you set the starting point with Move and then draw line to destination point with Draw.

Accessing single pixels
On palette based targets use ReadPixel and WritePixel to read/write pen values:

On high color and true color targets ReadRGBPixel and WriteRGBPixel work with direct RGB values:

Copy bitmap to bitmap
BltBitMap is used to copy a rectangle from a source bitmap to another bitmap.

The minterm should be always 0xc0. The mask parameter is used to select which bitmap planes are copied. This may speed up copy operation on OCS/AGA Amigas but most of time this should be set to 0xff. When copies overlap you must provide tempbuf what is large enough to store one scanline from the bitmap.

BltBitMapRastPort is similar but the destination is rastport.

ClipBlit is another form where both source and destinations are rastports.

When working with true color bitmaps it is possible use alpha blitting routines.

Copy from bitmap to memory
To read pixel array from the bitmap you use ReadPixelArray:

Copy from memory to bitmap
To write an array of pixels to the bitmap you use WritePixelArray or WritePixelArrayAlpha:

Image scaling operations
Thee different calls are available for image scaling.

Due to its complexity BitMapScale is not covered here.

ScalePixelArrayAlpha takes an ARGB source buffer what is scaled to a destination rastport.

= Create an offscreen bitmaps and rastports =

Sometimes it is necessary to render offscreen. This section describes how to create offscreen rastports on Amiga.

Create offscreen bitmap
Although bitmaps can be created manually (allocate some memory and call InitBitMap) we strongly encourage to use AllocBitMap. This ensures maximum compatibility and performance on different Amiga configurations.

When parameter reference_bitmap is not null it will be used as a reference for newly allocated bitmap to determine the best possible pixel format. If reference bitmap is screen bitmap or bitmap with palette information this palette will be inherited to new bitmap.

Create an offscreen rastport without clipping
To create simple offscreen rastport you only allocate some memory for rastport where you install your new pointer. These rastports are unsafe for rendering. Any drawing operation that is rendered outside the bitmap trash random memory.

Create an offscreen rastport with clipping
To create safe rastports where rendering outside bitmap is not allowed some more advanced techniques are needed. Those rastports must be created using layers.library routines which allocate and initialize clipping structures for you.