|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Compose 1-bpp images of arbitrary size with the canvas primitives. More...
Macros | |
| #define | HOST_SURFACE_MAX_PER_PLUGIN 2 |
| Maximum surfaces a plugin may hold at once. | |
| #define | HOST_SURFACE_MAX_BYTES 65536 |
| Maximum packed pixel bytes per surface (stride * height). | |
Functions | |
| int | host_surface_create (uint16_t w, uint16_t h) |
| Create a w x h surface, cleared to white. | |
| int | host_surface_destroy (uint32_t surface) |
| Destroy a surface and free its memory. | |
| int | host_surface_clear (uint32_t surface) |
| Clear a surface to white. | |
| int | host_surface_set_font (uint32_t surface, uint8_t font_id) |
| Select the font for subsequent text calls (HOST_FONT_* id). | |
| int | host_surface_set_text_size (uint32_t surface, uint8_t size) |
| Set the integer text scale (1..4) for subsequent text calls. | |
| int | host_surface_set_text_color (uint32_t surface, uint8_t inverted) |
| Draw text white-on-black (inverted != 0) or black-on-white. | |
| int | host_surface_set_shade (uint32_t surface, uint8_t shade) |
| Set the fill shade for filled shapes: 0 white .. 255 solid black. | |
| int | host_surface_draw_text (uint32_t surface, int16_t x, int16_t y, const char *text) |
| Draw UTF-8 text with the current font/size at (x, y) baseline-top. | |
| int | host_surface_draw_text_aligned (uint32_t surface, int16_t x, int16_t y, int16_t w, const char *text, uint8_t align) |
| Draw UTF-8 text aligned within a w-wide box starting at x. | |
| int | host_surface_measure_text (uint32_t surface, const char *text, uint16_t *out_w, uint16_t *out_h) |
| Measure UTF-8 text with the surface's current font/size. | |
| int | host_surface_draw_pixel (uint32_t surface, int16_t x, int16_t y) |
| Draw a pixel (current shade decides ink: shade > 0 draws black). | |
| int | host_surface_draw_line (uint32_t surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1) |
| Draw a line. | |
| int | host_surface_draw_rect (uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t filled) |
| Draw a rectangle; filled ones use the current shade. | |
| int | host_surface_draw_circle (uint32_t surface, int16_t x, int16_t y, int16_t r, uint8_t filled) |
| Draw a circle centered at (x, y); filled ones use the current shade. | |
| int | host_surface_draw_triangle (uint32_t surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t filled) |
| Draw a triangle; filled ones use the current shade. | |
| int | host_surface_draw_round_rect (uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint8_t filled) |
| Draw a rounded rectangle with corner radius r. | |
| int | host_surface_hline (uint32_t surface, int16_t x, int16_t y, int16_t w) |
| Draw a horizontal line of width w. | |
| int | host_surface_vline (uint32_t surface, int16_t x, int16_t y, int16_t h) |
| Draw a vertical line of height h. | |
| int | host_surface_draw_bitmap (uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *data, uint32_t len) |
| Blit a packed 1-bpp bitmap (MSB-first, set bit = black) at (x, y). | |
| int | host_surface_export (uint32_t surface, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes) |
| Copy the surface's packed pixel rows into out. | |
| int | host_surface_export_jpg (uint32_t surface, uint8_t quality, uint8_t *out, size_t out_size, uint32_t *out_len) |
| Encode the surface as a grayscale JPEG. | |
| int | host_surface_draw_sprite (uint32_t surface, int16_t x, int16_t y, uint32_t sprite) |
| Stamp a sprite's current frame onto a surface at (x, y). | |
Compose 1-bpp images of arbitrary size with the canvas primitives.
A surface is an offscreen render target independent of the view stack - e.g. 384 px wide for a thermal print band while the display is only 296x128. The draw API mirrors the canvas view (same fonts, shades and primitives); coordinates are raw surface pixels with no header offset. Export yields packed rows (MSB-first, set bit = black - the same layout as the QR and image APIs) or an encoded grayscale JPEG.
No capability required: pure compute with a hard memory cap. A plugin can hold at most 2 surfaces of up to 64 KiB pixel data each; all surfaces are freed when the plugin unloads.
| #define HOST_SURFACE_MAX_BYTES 65536 |
Maximum packed pixel bytes per surface (stride * height).
Definition at line 2183 of file host_api.h.
Referenced by host_surface_create().
| #define HOST_SURFACE_MAX_PER_PLUGIN 2 |
Maximum surfaces a plugin may hold at once.
Definition at line 2181 of file host_api.h.
Referenced by host_surface_create().
| int host_surface_clear | ( | uint32_t | surface | ) |
Clear a surface to white.
Definition at line 114 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_clear().
| int host_surface_create | ( | uint16_t | w, |
| uint16_t | h ) |
Create a w x h surface, cleared to white.
| w | Width in pixels, 1..1024. |
| h | Height in pixels, 1..2048; ((w+7)/8) * h <= HOST_SURFACE_MAX_BYTES. |
Definition at line 75 of file host_api_surface.cpp.
References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, HOST_SURFACE_MAX_BYTES, HOST_SURFACE_MAX_PER_PLUGIN, and plg_get_active_plugin().
Referenced by cdc::plugin_manager::w_host_surface_create().
| int host_surface_destroy | ( | uint32_t | surface | ) |
Destroy a surface and free its memory.
Definition at line 107 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_destroy().
| int host_surface_draw_bitmap | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| int16_t | w, | ||
| int16_t | h, | ||
| const uint8_t * | data, | ||
| uint32_t | len ) |
Blit a packed 1-bpp bitmap (MSB-first, set bit = black) at (x, y).
| len | Must be at least ((w + 7) / 8) * h. |
Definition at line 275 of file host_api_surface.cpp.
References HOST_ERR_INVALID_ARG, HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_draw_bitmap().
| int host_surface_draw_circle | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| int16_t | r, | ||
| uint8_t | filled ) |
Draw a circle centered at (x, y); filled ones use the current shade.
Definition at line 223 of file host_api_surface.cpp.
References cdc::ui::render::fillCircleDither(), HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_draw_circle().
| int host_surface_draw_line | ( | uint32_t | surface, |
| int16_t | x0, | ||
| int16_t | y0, | ||
| int16_t | x1, | ||
| int16_t | y1 ) |
Draw a line.
Definition at line 202 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_draw_line().
| int host_surface_draw_pixel | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y ) |
Draw a pixel (current shade decides ink: shade > 0 draws black).
Definition at line 195 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_draw_pixel().
| int host_surface_draw_rect | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| int16_t | w, | ||
| int16_t | h, | ||
| uint8_t | filled ) |
Draw a rectangle; filled ones use the current shade.
Definition at line 209 of file host_api_surface.cpp.
References cdc::ui::render::fillRectDither(), HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_draw_rect().
| int host_surface_draw_round_rect | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| int16_t | w, | ||
| int16_t | h, | ||
| int16_t | r, | ||
| uint8_t | filled ) |
Draw a rounded rectangle with corner radius r.
Definition at line 252 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_draw_round_rect().
| int host_surface_draw_sprite | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| uint32_t | sprite ) |
Stamp a sprite's current frame onto a surface at (x, y).
Composition helper: honors the sprite's mask and flip flags. Unlike host_view_canvas_draw_sprite this is an immediate pixel copy, not a reference.
Definition at line 318 of file host_api_surface.cpp.
References cdc::plugin_manager::PluginUiState::canvasView(), cdc::ui::anim::SpriteStore::FrameView::data, cdc::ui::render::drawBitmapMasked(), cdc::ui::anim::SpriteStore::FrameView::flags, cdc::ui::render::BlitOpts::flipH, cdc::ui::render::BlitOpts::flipV, cdc::ui::anim::SpriteStore::FrameView::h, HOST_ERR_NOT_FOUND, HOST_OK, cdc::plugin_manager::PluginUiState::instance(), cdc::ui::anim::SpriteStore::FrameView::mask, cdc::ui::render::BlitOpts::mask, cdc::ui::render::BlitOpts::opaque, cdc::ui::render::BlitOpts::rot90, cdc::ui::anim::SpriteStore::FrameView::scale, cdc::ui::render::BlitOpts::scale, cdc::ui::anim::SPRITE_FLAG_FLIP_H, cdc::ui::anim::SPRITE_FLAG_FLIP_V, cdc::ui::anim::SPRITE_FLAG_OPAQUE, cdc::ui::anim::SPRITE_FLAG_ROT_90, and cdc::ui::anim::SpriteStore::FrameView::w.
Referenced by cdc::plugin_manager::w_host_surface_draw_sprite().
| int host_surface_draw_text | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| const char * | text ) |
Draw UTF-8 text with the current font/size at (x, y) baseline-top.
Definition at line 151 of file host_api_surface.cpp.
References cdc::ui::render::drawText(), HOST_ERR_INVALID_ARG, HOST_ERR_NOT_FOUND, HOST_OK, and cdc::plugin_manager::toDisplay().
Referenced by cdc::plugin_manager::w_host_surface_draw_text().
| int host_surface_draw_text_aligned | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| int16_t | w, | ||
| const char * | text, | ||
| uint8_t | align ) |
Draw UTF-8 text aligned within a w-wide box starting at x.
| align | 0 = left, 1 = center, 2 = right. |
Definition at line 162 of file host_api_surface.cpp.
References cdc::ui::render::drawText(), HOST_ERR_INVALID_ARG, HOST_ERR_NOT_FOUND, HOST_OK, cdc::ui::render::measureText(), and cdc::plugin_manager::toDisplay().
Referenced by cdc::plugin_manager::w_host_surface_draw_text_aligned().
| int host_surface_draw_triangle | ( | uint32_t | surface, |
| int16_t | x0, | ||
| int16_t | y0, | ||
| int16_t | x1, | ||
| int16_t | y1, | ||
| int16_t | x2, | ||
| int16_t | y2, | ||
| uint8_t | filled ) |
Draw a triangle; filled ones use the current shade.
Definition at line 237 of file host_api_surface.cpp.
References cdc::ui::render::fillTriangleDither(), HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_draw_triangle().
| int host_surface_export | ( | uint32_t | surface, |
| uint8_t * | out, | ||
| size_t | out_size, | ||
| uint16_t * | out_stride_bytes ) |
Copy the surface's packed pixel rows into out.
| out_stride_bytes | Receives the row stride (width + 7) / 8. |
Definition at line 286 of file host_api_surface.cpp.
References HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, and HOST_ERR_NOT_FOUND.
Referenced by cdc::plugin_manager::w_host_surface_export().
| int host_surface_export_jpg | ( | uint32_t | surface, |
| uint8_t | quality, | ||
| uint8_t * | out, | ||
| size_t | out_size, | ||
| uint32_t * | out_len ) |
Encode the surface as a grayscale JPEG.
| quality | 1..100 (0 = 85). |
| out_len | Receives the encoded size; on HOST_ERR_NO_MEMORY it holds the required buffer size instead. |
Definition at line 298 of file host_api_surface.cpp.
References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_export_jpg().
| int host_surface_hline | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| int16_t | w ) |
Draw a horizontal line of width w.
Definition at line 261 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_hline().
| int host_surface_measure_text | ( | uint32_t | surface, |
| const char * | text, | ||
| uint16_t * | out_w, | ||
| uint16_t * | out_h ) |
Measure UTF-8 text with the surface's current font/size.
| out_w | Receives the rendered width in pixels. |
| out_h | Receives the rendered height in pixels. |
Definition at line 183 of file host_api_surface.cpp.
References HOST_ERR_INVALID_ARG, HOST_ERR_NOT_FOUND, HOST_OK, cdc::ui::render::measureText(), and cdc::plugin_manager::toDisplay().
Referenced by cdc::plugin_manager::w_host_surface_measure_text().
| int host_surface_set_font | ( | uint32_t | surface, |
| uint8_t | font_id ) |
Select the font for subsequent text calls (HOST_FONT_* id).
Definition at line 121 of file host_api_surface.cpp.
References HOST_ERR_INVALID_ARG, HOST_ERR_NOT_FOUND, HOST_OK, and cdc::ui::kFontIdCount.
Referenced by cdc::plugin_manager::w_host_surface_set_font().
| int host_surface_set_shade | ( | uint32_t | surface, |
| uint8_t | shade ) |
Set the fill shade for filled shapes: 0 white .. 255 solid black.
Definition at line 144 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_set_shade().
| int host_surface_set_text_color | ( | uint32_t | surface, |
| uint8_t | inverted ) |
Draw text white-on-black (inverted != 0) or black-on-white.
Definition at line 137 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_set_text_color().
| int host_surface_set_text_size | ( | uint32_t | surface, |
| uint8_t | size ) |
Set the integer text scale (1..4) for subsequent text calls.
Definition at line 129 of file host_api_surface.cpp.
References HOST_ERR_INVALID_ARG, HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_set_text_size().
| int host_surface_vline | ( | uint32_t | surface, |
| int16_t | x, | ||
| int16_t | y, | ||
| int16_t | h ) |
Draw a vertical line of height h.
Definition at line 268 of file host_api_surface.cpp.
References HOST_ERR_NOT_FOUND, and HOST_OK.
Referenced by cdc::plugin_manager::w_host_surface_vline().