Pure types package for bitmap and color representation in bare-metal Ada applications.
bitmap provides common types for working with bitmaps, colors, and pixel formats in embedded graphics applications. It defines no operations—only types—making it a pure dependency for display controller and framebuffer packages.
- Multiple pixel format support (ARGB8888, RGB888, RGB565, etc.)
- Color representation with ARGB components
- Point and rectangle geometry types
- Bitmap buffer descriptor
- Bits-per-pixel calculations
- Zero dependencies (pragma Pure)
type Bitmap_Color_Mode is
(ARGB_8888, -- 32-bit: 8-bit alpha, 8-bit RGB
RGB_888, -- 24-bit: 8-bit RGB
RGB_565, -- 16-bit: 5-bit R, 6-bit G, 5-bit B
ARGB_1555, -- 16-bit: 1-bit alpha, 5-bit RGB
ARGB_4444, -- 16-bit: 4-bit alpha, 4-bit RGB
L_8, -- 8-bit luminance
AL_44, -- 8-bit: 4-bit alpha, 4-bit luminance
AL_88, -- 16-bit: 8-bit alpha, 8-bit luminance
L_4, -- 4-bit luminance
A_8, -- 8-bit alpha
A_4) -- 4-bit alpha
with Size => 4;type Bitmap_Color is record
Alpha : UInt8;
Red : UInt8;
Green : UInt8;
Blue : UInt8;
end record with Size => 32;
-- Predefined colors
Transparent : constant Bitmap_Color := (0, 0, 0, 0);
Black : constant Bitmap_Color := (255, 0, 0, 0);
White : constant Bitmap_Color := (255, 255, 255, 255);type Point is record
X : Integer;
Y : Integer;
end record;
type Rect is record
X : Integer;
Y : Integer;
Width : Natural;
Height : Natural;
end record;type Bitmap_Buffer is record
Addr : System.Address := System.Null_Address;
Width : Natural := 0;
Height : Natural := 0;
Color_Mode : Bitmap_Color_Mode := ARGB_8888;
Swapped : Boolean := False;
end record;
function Buffer_Size (Buffer : Bitmap_Buffer) return Natural;function Bits_Per_Pixel (Mode : Bitmap_Color_Mode) return Positive;
function UInt8s_Per_Pixel (Mode : Bitmap_Color_Mode) return Positive;with Bitmap;
Red : constant Bitmap.Bitmap_Color := (255, 255, 0, 0);
Green : constant Bitmap.Bitmap_Color := (255, 0, 255, 0);
Blue : constant Bitmap.Bitmap_Color := (255, 0, 0, 255);with Bitmap;
with System;
Framebuffer : aliased array (0 .. 800 * 480 - 1) of MT.UInt16
with Alignment => 4;
Buffer : constant Bitmap.Bitmap_Buffer :=
(Addr => Framebuffer'Address,
Width => 800,
Height => 480,
Color_Mode => Bitmap.RGB_565,
Swapped => False);
Size : constant Natural := Bitmap.Buffer_Size (Buffer);
-- Returns (800 * 480 * 16 + 7) / 8 = 768000 bytesScreen : constant Bitmap.Rect := (0, 0, 800, 480);
Button : constant Bitmap.Rect := (100, 200, 150, 50);
Origin : constant Bitmap.Point := (0, 0);bitmap is declared pragma Pure, meaning it has no state and no dependencies beyond the Ada standard. This makes it safe to use from any context and allows aggressive compiler optimization.
The Bitmap_Color type uses a representation clause to match the ARGB8888 memory layout expected by hardware display controllers (Blue at lowest address, Alpha at highest).
The Swapped field in Bitmap_Buffer indicates whether X and Y coordinates should be transposed, supporting displays mounted in portrait vs. landscape orientation.
Add to your alire.toml:
[[depends-on]]
bitmap = "^0.1.0"machine_types- ProvidesMT.UInt8type
dc_generic- Display controller interfacefb_generic- Framebuffer interface
MIT OR Apache-2.0 WITH LLVM-exception