Skip to content
CShift0.32

Bitmap

Struct · namespace Amiga · AmigaOS only · Since 0.20

struct Bitmap

A picture in chip memory: Depth bitplanes of Width x Height pixels, one after the other (plane p starts at Plane(p)). Width is a multiple of 16.

Name Description
Width The width in pixels (a multiple of 16).
Height The height in pixels.
Depth The number of bitplanes (1 to 6): the bitmap has 2^Depth colors.
BytesPerRow The bytes of one row of a plane (Width / 8).
PlaneSize The bytes of one plane (BytesPerRow * Height).
int Width

The width in pixels (a multiple of 16).

int Height

The height in pixels.

int Depth

The number of bitplanes (1 to 6): the bitmap has 2^Depth colors.

int BytesPerRow

The bytes of one row of a plane (Width / 8).

int PlaneSize

The bytes of one plane (BytesPerRow * Height).

Name Description
Create A cleared bitmap in chip memory.
static Optional<Bitmap> Create(int width, int height, int depth)

A cleared bitmap in chip memory.

Parameters

  • width: a multiple of 16, up to 1024.
  • height: up to 1024.
  • depth: the number of bitplanes, 1 to 6.

Returns nothing (null) if there is not enough chip memory.

Panics when a size is out of range.

Name Description
Free Gives the chip memory back (after the blitter is done with it).
Plane The address of bitplane p (0 to Depth - 1).
Clear Sets all pixels to color 0 (with the blitter).
FillRect A filled rectangle of w x h pixels at (x, y) in color (with the blitter).
DrawRect The outline of a rectangle of w x h pixels at (x, y) in color.
SetPixel Sets the pixel at (x, y) to color (nothing happens outside of the bitmap).
GetPixel The color of the pixel at (x, y).
DrawLine A line from (x0, y0) to (x1, y1) in color, both ends included.
DrawPattern Pixels from text, one string per row: ‘0’..‘9’ and ‘A’..‘V’ are the colors 0..31, every other character (‘.’, ’ ’) leaves the pixel as it is.
Copy Copies w x h pixels from (sx, sy) of source to (x, y) (the planes both have; source and destination must not overlap).
DrawMasked Draws a shape (a “bob”): w x h pixels from (sx, sy) of source to (x, y), only where mask (a bitmap with one plane, the same size as source, e.g. source.MakeMask()) has a 1.
MakeMask A mask for DrawMasked: a bitmap with one plane that is 1 where this bitmap’s color is not 0; null if there is not enough chip memory.
DrawText Text in the system font (Topaz 8 or the font set in the preferences), at (x, y) = the top left corner of the first character; the pixels around the letters stay.
void Free()

Gives the chip memory back (after the blitter is done with it).

uint8* Plane(int p)

The address of bitplane p (0 to Depth - 1).

void Clear()

Sets all pixels to color 0 (with the blitter).

void FillRect(int x, int y, int w, int h, int color)

A filled rectangle of w x h pixels at (x, y) in color (with the blitter).

void DrawRect(int x, int y, int w, int h, int color)

The outline of a rectangle of w x h pixels at (x, y) in color.

void SetPixel(int x, int y, int color)

Sets the pixel at (x, y) to color (nothing happens outside of the bitmap).

int GetPixel(int x, int y)

The color of the pixel at (x, y).

Returns 0 outside of the bitmap.

void DrawLine(int x0, int y0, int x1, int y1, int color)

A line from (x0, y0) to (x1, y1) in color, both ends included.

void DrawPattern(int x, int y, ReadOnlySlice<StringSlice> rows)

Pixels from text, one string per row: ‘0’..‘9’ and ‘A’..‘V’ are the colors 0..31, every other character (‘.’, ’ ’) leaves the pixel as it is.

void DrawPattern(int x, int y, ReadOnlySlice<string> rows)

The same with the rows as strings, e.g. the lines of a file: const ReadOnlySlice<string> Ball = embed_lines("ball.txt"); … bitmap.DrawPattern(0, 0, Ball);

void DrawPattern(int x, int y, int width, ReadOnlySlice<uint8> pattern)

Draws a given color pattern. Each byte in the pattern gives a color index (0..31). Higher values are ignored (not drawn).

If the number of given color indices is not a multiple of width, the last row is still partially drawn.

Parameters

  • x: x coordinate.
  • y: y coordinate.
  • width: (row) width.
  • pattern: the given color indices.

Since 0.25

void Copy(const ref Bitmap source, int sx, int sy, int x, int y, int w, int h)

Copies w x h pixels from (sx, sy) of source to (x, y) (the planes both have; source and destination must not overlap). The blitter does it when x % 16 >= sx % 16 (e.g. sources at multiples of 16), the CPU otherwise; it is fastest for whole words (x, sx and w multiples of 16).

void DrawMasked(const ref Bitmap source, const ref Bitmap mask, int sx, int sy, int x, int y, int w, int h)

Draws a shape (a “bob”): w x h pixels from (sx, sy) of source to (x, y), only where mask (a bitmap with one plane, the same size as source, e.g. source.MakeMask()) has a 1. sx must be a multiple of 16; the pixels right of the shape up to the next multiple of 16 are drawn too where the mask has a 1. The blitter does it when the shape is inside the bitmap from left to right, the CPU otherwise.

Optional<Bitmap> MakeMask()

A mask for DrawMasked: a bitmap with one plane that is 1 where this bitmap’s color is not 0; null if there is not enough chip memory.

int DrawText(int x, int y, StringSlice text, int color)

Text in the system font (Topaz 8 or the font set in the preferences), at (x, y) = the top left corner of the first character; the pixels around the letters stay. UTF-8 characters up to U+00FF are shown, others as ‘?’. The x after the text is returned.