Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bitmap

Pure types package for bitmap and color representation in bare-metal Ada applications.

Overview

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.

Features

  • 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)

API

Color Modes

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;

Color Type

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);

Geometry Types

type Point is record
   X : Integer;
   Y : Integer;
end record;

type Rect is record
   X      : Integer;
   Y      : Integer;
   Width  : Natural;
   Height : Natural;
end record;

Bitmap Buffer

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;

Utility Functions

function Bits_Per_Pixel (Mode : Bitmap_Color_Mode) return Positive;
function UInt8s_Per_Pixel (Mode : Bitmap_Color_Mode) return Positive;

Usage

Define Colors

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);

Create Bitmap Buffer Descriptor

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 bytes

Define Regions

Screen : constant Bitmap.Rect := (0, 0, 800, 480);
Button : constant Bitmap.Rect := (100, 200, 150, 50);
Origin : constant Bitmap.Point := (0, 0);

Design Rationale

Pure Package

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.

Representation Clause

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).

Swapped Field

The Swapped field in Bitmap_Buffer indicates whether X and Y coordinates should be transposed, supporting displays mounted in portrait vs. landscape orientation.

Integration

Add to your alire.toml:

[[depends-on]]
bitmap = "^0.1.0"

Dependencies

  • machine_types - Provides MT.UInt8 type

Used By

  • dc_generic - Display controller interface
  • fb_generic - Framebuffer interface

License

MIT OR Apache-2.0 WITH LLVM-exception

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages