http://www.aros.orgAROS-ExecTeam AROSAROS-Exec Archives

Home

English

Deutsch

Ελληυικά

Français

Italiano

Nederlands

Polski

Português

Русский

Español

Suomi

Svenska

Česky


News

Archive

Introduction

Status
Screenshots
Ports
License

Download


Documentation

Users
Installation
Using
Shell commands
Applications
FAQ
Developers
Contribute
Roadmap
Bug Tracker
Working with Subversion
Compiling
Application Development Manual
Zune Application Development Manual
System Development Manual
Debugging Manual
Reference
Specifications
UI Style Guide
Documenting
Porting
Translating
Summaries
Links

Contact

Mailing lists
IRC channels

Credits

Acknowledgements


Pictures

Developers
Developers en Masse

Sponsors

Linking

Links

SourceForge Logo

AROS Application Development Manual

Index

Warning

This document is not finished! It is highly likely that many parts are out-of-date, contain incorrect information or are simply missing altogether. If you want to help rectify this, please contact us.

graphics.library

Bitmaps

Bitmaps are the drawing sheets of AROS. They are coordinate systems with the zero point in the upper left corner. The X axis goes from left to right, y axis from top to bottom. The number of possible colors depends on the depth of the bitmap:

Depth Colors
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
15 32,768
16 65,536
24 16,777,216

The depths from 1 to 8 are LUT (look-up-table) modes. This means the red, green and blue (RGB) value for each color is stored in a table. The index will then be stored as pen number in the bitmap.

The depths 15 and 16 are called high color, 24 is called true color. Unlike LUT mode the RGB value is stored directly in the bitmap.

The graphics library has only a limited support for high-/true color modes. Some of the drawing functions work only with LUT modes. For a full access you need the functions from the cybergraphics library.

GetBitMapAttr() query bitmap attributes. Use this instead of peeking in bitmap structure
AllocBitMap() allocate and initialize bitmap
AllocScreenBitMap() (private AROS function)
SetFrontBitMap() (private AROS function)
InitBitMap() initialize bitmap
FreeBitMap() free resources allocated by a bitmap
AllocRaster() allocate a single bitplane
FreeRaster() free a single bitplane
CopySBitMap() syncronize super-bitmap (see Intuition)
SyncSBitMap() syncronize super-bitmap

RastPort

The connection between the bitmaps and most drawing functions is done by a rastport. The rastport contains information about drawing pens, line and area patterns, drawing mode and text font.

You can connect more than one rastport to a bitmap. This allows a fast switch between different drawing configurations. But in AROS you aren't allowed to just copy a rastport, you have to use the function CloneRastPort().

Some Intuition elements like screens and windows already have a RastPort element. You can immediately use it for your drawing operations.

Object Structure RastPort
screen struct Screen RastPort
window struct Window *RPort

If you create a bitmap and want to draw into it you have to create the rastport by yourself. Warning: this example is simplified and lacks checks of return values:

struct BitMap *bm = AllocBitMap(400, 300, 8, BMF_CLEAR, NULL);
struct RastPort *rp = CreateRastPort();
rp->BitMap = bm;
...
WritePixel(rp, 50, 30);
...
FreeRastPort(rp);
FreeBitMap(bm);

Pens

A rastport contains 3 pens. The A (foreground, primary) pen, B (background, secondary) pen and the O (area outline) pen. The latter is used by the area fill and flood fill functions.

Drawing modes

  • JAM1: draw only with A pen.

  • JAM2: draw bit 1 in a pattern with A pen, bit 0 with B pen

  • COMPLEMENT: for each set bit the state in the target is reversed

  • INVERSVID: is used for text rendering
    • JAM1|INVERSVID: text appears as transparent letter surrounded by foreground color
    • JAM2|INVERSVID: like previos, but letter is drawn with background color.

TODO: check whether the drawing modes are really available.

Pattern

The line pattern can be set with the macro SetDrPt(). The second paramter is a 16 bit pattern:

SetDrPt(&rastPort, 0xCCCC);

The pattern can be reset with:

SetDrPt(&rastPort, ~0);

For area patterns exists the macro SetAfPt(). The width is 16 bit, the height a power of two (2, 4, 8, 16, ...). The third parameter is the n in 2^n=height:

UWORD areaPattern[] =
{
    0x5555, 0xAAAA
};
SetAfPt(&rastPort, areaPattern, 1);

Colored patterns are possible with a negative value for the height. There must be the same number of bitplanes in the pattern as in the target bitmap.

Reset of area pattern:

SetAfPt(&rastPort, NULL, 0);
CloneRastPort() copy rastport
CreateRastPort() create rastport
InitRastPort() initialize rastport
DeinitRastPort() deinitialize rastport
FreeRastPort() free rastport
SetAPen() set primary pen
GetAPen() get primary pen
SetBPen() set secondary pen
GetBPen() get secondary pen
SetOPen() set area outline pen and switch on outline mode (macro in graphics/gfxmacros.h)
SetOutlinePen() set area outline pen
GetOutlinePen() get area outline pen
BNDRYOFF() switch off area outline mode (macro in graphics/gfxmacros.h)
SetDrMd() set drawing mode
GetDrMd() get drawing mode
SetDrPt() set line pattern (macro in graphics/gfxmacros.h)
SetAfPt() set area pattern (macro in graphics/gfxmacros.h)
SetABPenDrMd() set primary pen, secondary pen and drawing mode in one step
SetRPAttrsA() set misc. drawing attributes
GetRPAttrsA() get misc. drawing attributes
InitTmpRas() initialize a TmpRas structure.
SetWriteMask() set write mask

Drawing functions

A line is drawn by setting the pen position with Move() to the start and with Draw() to the end position.

For the Flood() function you have to attach a TmpRas to the rastport as explained unter Area operations.

Move() change pen position
Draw() draw a line from current pen position to given coordinate
DrawEllipse() draw an ellipse
DrawCircle() draw a circle (macro in graphics/gfxmacros.h)
PolyDraw() draw connected lines from an array of points
WritePixel() write a single pixel
ReadPixel() read the pen value of a pixel
EraseRect() fill rectangular area with current backfill hook (TODO: what's this?)
SetRast() fill entire drawing area with given pen
RectFill() fill a rectangular area with the current rastport settings
Flood() flood fill an arbitrary shape

Data moving

BltBitMap() copy rectangular area
BltBitMapRastPort() copy rectangular area
BltRastPortBitMap() copy rectangular area (AROS extension)
ClipBlit() copy rectangular area with layers and clip rects. Use this if you want to blit into a window
BltClear() set a memory block to zero. On classic Amigas this block must be in chip ram.
BltMaskBitMapRastPort() copy rectangular area with using a mask
BltPattern() draw a rectangular pattern into a bitmap
BltTemplate() draw a rectangular pattern into a bitmap
BitMapScale() copy a rectangular area and change its size
ScalerDiv() helper function for BitMapScale()
ScrollRaster() move rectangular area within a bitmap
ScrollRasterBF() move rectangular area, fill free space with EraseRect()
WriteChunkyPixels() write rectangular area from an array with pen values
WritePixelArray8() write rectangular area from an array with pen values
ReadPixelArray8() read rectangular area into memory
WritePixelLine8() write horiz. line from an array with pen values
ReadPixelLine8() read horiz. line from into memory

Area operations

The area functions allow a fast drawing of filled polygons and ellipses.

In order to use this functions you need a struct AreaInfo which must be connected to the rastport. The area buffer must be WORD-aligned (it must have an even address). You need five bytes per vertex:

#define AREA_SIZE 200
WORD areaBuffer[AREA_SIZE];
struct AreaInfo areaInfo = {0};
memset(areabuffer, 0, sizeof(areabuffer));
InitArea(&areaInfo, areaBuffer, sizeof(areaBuffer)/5);
rastPort->AreaInfo = &areaInfo;

Additionally, you need a TmpRas structure. It should have the same width and height as the bitmap you want to draw into:

#define WIDTH 400
#define HEIGHT 300
PLANEPTR rasplane = AllocRaster(WIDTH, HEIGHT);
struct TmpRas tmpRas = {0};
InitTmpRas(&tmpRas, rasPlane, WIDTH * HEIGHT);
rastPort->TmpRas = &tmpRas;
InitArea() initalizes the AreaInfo
AreaMove() closes open polygon and sets start point for a new polygon. You don't have to connect the end point to the start point.
AreaDraw() add point to vector buffer
AreaEllipse() add filled ellipse to vector buffer
AreaEnd() start filling operation

Text

OpenFont() open a font which is in the system font list. Better use OpenDiskFont() from the diskfont library.
CloseFont() close font, which had been opened by OpenFont() or OpenDiskFont()
AddFont() add font to the system list
RemFont() remove font from system list
SetFont() set current font of rastport
AskFont() get TextAttr for current rastport font
SetSoftStyle() set soft style bits of current font
AskSoftStyle() get soft style bits of current font
Text() render text at current pen position
ClearEOL() clear from current position to end of line
ClearScreen() clear from current position to end of rastport
ExtendFont() extend struct TextFont by a struct ExtendFont
StripFont() remove tf_Extension from a font
TextLength() calculate the width of a string in pixels. You can use TextExtent() if you need more detailed information
TextExtent() fill TextExtend structure with information about current font
FontExtent() fill TextExtend structure with information about given font
TextFit() count the number of characters which will fit into given bounds
WeighTAMatch() checks how well two different fonts match

Clipping

Bitmaps which you have created with AllocBitMap() don't have a clipping rectangle. This means that you trash memory when you draw outside the bitmap. You can either take care about your drawing operations or you can install a clipping rectangle. There are two possibilities:

  • Using the tag RPTAG_ClipRectangle in SetRPAttrsA():

    struct Rectangle rect = {0, 0, 399, 299};
    SetRPAttrs(&rastPort, RPTAG_ClipRectangle, &rect, TAG_DONE);
    
  • Installing a layer:

    li = NewLayerInfo())
    rastPort.Layer = CreateUpfrontLayer(li, rastPort->BitMap, 0, 0, width - 1, height - 1, 0, NULL))
    
    ...
    
    DeleteLayer(0,rastPort.Layer)
    DisposeLayerInfo(li)
    

The latter is compatible with AmigaOS.

Color

So far we have only used the SetXPen() functions to select the drawing pens. Now we look how we can change the red, green blue values of the pens.

We have to differ two cases:
The colormap belongs us.
We can change the colors as we like with the LoadRGB..., SetRGB... functions. We'll get a private colormap when we open a private screen.
We want draw into a window on a public Screen.
We have to query a shared pen with the ObtainBestPenA() function. Otherwise we would change the colors used by other applications.
GetColorMap() allocate and initialize colormap
FreeColorMap() free colormap
AttachPalExtra() allocate and attach palette sharing structure to a colormap
FindColor() find closest matching color
ObtainBestPenA() search for closest color match or allocate a new pen
ObtainPen() obtain a free palette entry
ReleasePen() frees a pen created with ObtainPen() or ObtainBestPenA()
GetRGB32() read a series of RGB values from a colormap
GetRGB4() reads RGB value of a single color register (deprecated)
LoadRGB32() set a series of RGB values for this viewport
LoadRGB4() set RGB color values from an array (deprecated)
SetMaxPen() set maximum pen value for a rastport
SetRGB32() set one color register for a viewport
SetRGB32CM() set one color register for a colormap
SetRGB4() set one color register for a viewport (deprecated)
SetRGB4CM() set one color register for a colormap (deprecated)

Copyright © 1995-2008, The AROS Development Team. All rights reserved.
Amiga® is a trademark of Amiga Inc. All other trademarks belong to their respective owners.