wip remove newtypes, re-export constants from base lib

This commit is contained in:
Vinzenz Schroeter 2025-04-12 12:08:49 +02:00
parent d215f7199e
commit bb90af3a57
8 changed files with 150 additions and 168 deletions

View file

@ -8,6 +8,35 @@
#include <stdint.h>
#include <stdlib.h>
/**
* pixel count on whole screen
*/
#define PIXEL_COUNT (PIXEL_WIDTH * PIXEL_HEIGHT)
/**
* Display height in pixels
*
* # Examples
*
* ```rust
* # use servicepoint::{PIXEL_HEIGHT, PIXEL_WIDTH, Bitmap};
* let grid = Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT);
* ```
*/
#define PIXEL_HEIGHT (TILE_HEIGHT * TILE_SIZE)
/**
* Display width in pixels
*
* # Examples
*
* ```rust
* # use servicepoint::{PIXEL_HEIGHT, PIXEL_WIDTH, Bitmap};
* let grid = Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT);
* ```
*/
#define PIXEL_WIDTH (TILE_WIDTH * TILE_SIZE)
/**
* Count of possible brightness values
*/
@ -23,40 +52,60 @@
*/
#define SP_BRIGHTNESS_MIN 0
/**
* pixel count on whole screen
*/
#define SP_PIXEL_COUNT (SP_PIXEL_WIDTH * SP_PIXEL_HEIGHT)
/**
* Display height in pixels
*/
#define SP_PIXEL_HEIGHT (SP_TILE_HEIGHT * SP_TILE_SIZE)
/**
* Display width in pixels
*/
#define SP_PIXEL_WIDTH (SP_TILE_WIDTH * SP_TILE_SIZE)
/**
* Display tile count in the y-direction
*
* # Examples
*
* ```rust
* # use servicepoint::{Cp437Grid, TILE_HEIGHT, TILE_WIDTH};
* let grid = Cp437Grid::new(TILE_WIDTH, TILE_HEIGHT);
* ```
*/
#define SP_TILE_HEIGHT 20
#define TILE_HEIGHT 20
/**
* size of a single tile in one dimension
*/
#define SP_TILE_SIZE 8
#define TILE_SIZE 8
/**
* Display tile count in the x-direction
*
* # Examples
*
* ```rust
* # use servicepoint::{Cp437Grid, TILE_HEIGHT, TILE_WIDTH};
* let grid = Cp437Grid::new(TILE_WIDTH, TILE_HEIGHT);
* ```
*/
#define SP_TILE_WIDTH 56
#define TILE_WIDTH 56
/**
* Specifies the kind of compression to use.
* Specifies the kind of compression to use. Availability depends on features.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* // create command without payload compression
* # let pixels = Bitmap::max_sized();
* _ = BitmapCommand {
* origin: Origin::ZERO,
* bitmap: pixels,
* compression: CompressionCode::Uncompressed
* };
*
* // create command with payload compressed with lzma and appropriate header flags
* # let pixels = Bitmap::max_sized();
* _ = BitmapCommand {
* origin: Origin::ZERO,
* bitmap: pixels,
* compression: CompressionCode::Lzma
* };
* ```
*/
enum SPCompressionCode
enum CompressionCode
#ifdef __cplusplus
: uint16_t
#endif // __cplusplus
@ -64,26 +113,26 @@ enum SPCompressionCode
/**
* no compression
*/
SP_COMPRESSION_CODE_UNCOMPRESSED = 0,
COMPRESSION_CODE_UNCOMPRESSED = 0,
/**
* compress using flate2 with zlib header
*/
SP_COMPRESSION_CODE_ZLIB = 26490,
COMPRESSION_CODE_ZLIB = 26490,
/**
* compress using bzip2
*/
SP_COMPRESSION_CODE_BZIP2 = 25210,
COMPRESSION_CODE_BZIP2 = 25210,
/**
* compress using lzma
*/
SP_COMPRESSION_CODE_LZMA = 27770,
COMPRESSION_CODE_LZMA = 27770,
/**
* compress using Zstandard
*/
SP_COMPRESSION_CODE_ZSTD = 31347,
COMPRESSION_CODE_ZSTD = 31347,
};
#ifndef __cplusplus
typedef uint16_t SPCompressionCode;
typedef uint16_t CompressionCode;
#endif // __cplusplus
/**
@ -245,22 +294,6 @@ typedef ValueGrid_char CharGrid;
*/
typedef ValueGrid_u8 Cp437Grid;
/**
* A C-wrapper for grid containing codepage 437 characters.
*
* The encoding is currently not enforced.
*
* # Examples
*
* ```C
* Cp437Grid grid = sp_cp437_grid_new(4, 3);
* sp_cp437_grid_fill(grid, '?');
* sp_cp437_grid_set(grid, 0, 0, '!');
* sp_cp437_grid_free(grid);
* ```
*/
typedef Cp437Grid SPCp437Grid;
/**
* A raw header.
*
@ -1189,7 +1222,7 @@ size_t sp_char_grid_width(const CharGrid *char_grid);
*/
Command *sp_command_bitmap_linear(size_t offset,
SPBitVec *bit_vec,
SPCompressionCode compression);
CompressionCode compression);
/**
* Set pixel data according to an and-mask starting at the offset.
@ -1220,7 +1253,7 @@ Command *sp_command_bitmap_linear(size_t offset,
*/
Command *sp_command_bitmap_linear_and(size_t offset,
SPBitVec *bit_vec,
SPCompressionCode compression);
CompressionCode compression);
/**
* Set pixel data according to an or-mask starting at the offset.
@ -1251,7 +1284,7 @@ Command *sp_command_bitmap_linear_and(size_t offset,
*/
Command *sp_command_bitmap_linear_or(size_t offset,
SPBitVec *bit_vec,
SPCompressionCode compression);
CompressionCode compression);
/**
* Sets a window of pixels to the specified values.
@ -1278,7 +1311,7 @@ Command *sp_command_bitmap_linear_or(size_t offset,
Command *sp_command_bitmap_linear_win(size_t x,
size_t y,
Bitmap *bitmap,
SPCompressionCode compression);
CompressionCode compression);
/**
* Set pixel data according to a xor-mask starting at the offset.
@ -1309,7 +1342,7 @@ Command *sp_command_bitmap_linear_win(size_t x,
*/
Command *sp_command_bitmap_linear_xor(size_t offset,
SPBitVec *bit_vec,
SPCompressionCode compression);
CompressionCode compression);
/**
* Set the brightness of all tiles to the same value.
@ -1417,7 +1450,7 @@ Command *sp_command_clone(const Command *command);
*/
Command *sp_command_cp437_data(size_t x,
size_t y,
SPCp437Grid *grid);
Cp437Grid *grid);
/**
* A yet-to-be-tested command.
@ -1631,7 +1664,7 @@ bool sp_connection_send_packet(const UdpConnection *connection, Packet *packet);
* - the returned instance is freed in some way, either by using a consuming function or
* by explicitly calling `sp_cp437_grid_free`.
*/
SPCp437Grid *sp_cp437_grid_clone(const SPCp437Grid *cp437_grid);
Cp437Grid *sp_cp437_grid_clone(const Cp437Grid *cp437_grid);
/**
* Sets the value of all cells in the [SPCp437Grid].
@ -1652,7 +1685,7 @@ SPCp437Grid *sp_cp437_grid_clone(const SPCp437Grid *cp437_grid);
* - `cp437_grid` points to a valid [SPCp437Grid]
* - `cp437_grid` is not written to or read from concurrently
*/
void sp_cp437_grid_fill(SPCp437Grid *cp437_grid, uint8_t value);
void sp_cp437_grid_fill(Cp437Grid *cp437_grid, uint8_t value);
/**
* Deallocates a [SPCp437Grid].
@ -1671,7 +1704,7 @@ void sp_cp437_grid_fill(SPCp437Grid *cp437_grid, uint8_t value);
*
* [SPCommand]: [crate::SPCommand]
*/
void sp_cp437_grid_free(SPCp437Grid *cp437_grid);
void sp_cp437_grid_free(Cp437Grid *cp437_grid);
/**
* Gets the current value at the specified position.
@ -1693,7 +1726,7 @@ void sp_cp437_grid_free(SPCp437Grid *cp437_grid);
* - `cp437_grid` points to a valid [SPCp437Grid]
* - `cp437_grid` is not written to concurrently
*/
uint8_t sp_cp437_grid_get(const SPCp437Grid *cp437_grid, size_t x, size_t y);
uint8_t sp_cp437_grid_get(const Cp437Grid *cp437_grid, size_t x, size_t y);
/**
* Gets the height of the [SPCp437Grid] instance.
@ -1712,7 +1745,7 @@ uint8_t sp_cp437_grid_get(const SPCp437Grid *cp437_grid, size_t x, size_t y);
*
* - `cp437_grid` points to a valid [SPCp437Grid]
*/
size_t sp_cp437_grid_height(const SPCp437Grid *cp437_grid);
size_t sp_cp437_grid_height(const Cp437Grid *cp437_grid);
/**
* Loads a [SPCp437Grid] with the specified dimensions from the provided data.
@ -1733,10 +1766,10 @@ size_t sp_cp437_grid_height(const SPCp437Grid *cp437_grid);
* - the returned instance is freed in some way, either by using a consuming function or
* by explicitly calling `sp_cp437_grid_free`.
*/
SPCp437Grid *sp_cp437_grid_load(size_t width,
size_t height,
const uint8_t *data,
size_t data_length);
Cp437Grid *sp_cp437_grid_load(size_t width,
size_t height,
const uint8_t *data,
size_t data_length);
/**
* Creates a new [SPCp437Grid] with the specified dimensions.
@ -1750,8 +1783,8 @@ SPCp437Grid *sp_cp437_grid_load(size_t width,
* - the returned instance is freed in some way, either by using a consuming function or
* by explicitly calling `sp_cp437_grid_free`.
*/
SPCp437Grid *sp_cp437_grid_new(size_t width,
size_t height);
Cp437Grid *sp_cp437_grid_new(size_t width,
size_t height);
/**
* Sets the value of the specified position in the [SPCp437Grid].
@ -1778,7 +1811,7 @@ SPCp437Grid *sp_cp437_grid_new(size_t width,
*
* [SPBitVec]: [crate::SPBitVec]
*/
void sp_cp437_grid_set(SPCp437Grid *cp437_grid,
void sp_cp437_grid_set(Cp437Grid *cp437_grid,
size_t x,
size_t y,
uint8_t value);
@ -1800,7 +1833,7 @@ void sp_cp437_grid_set(SPCp437Grid *cp437_grid,
* - the returned memory range is never accessed after the passed [SPCp437Grid] has been freed
* - the returned memory range is never accessed concurrently, either via the [SPCp437Grid] or directly
*/
SPByteSlice sp_cp437_grid_unsafe_data_ref(SPCp437Grid *cp437_grid);
SPByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid *cp437_grid);
/**
* Gets the width of the [SPCp437Grid] instance.
@ -1819,7 +1852,7 @@ SPByteSlice sp_cp437_grid_unsafe_data_ref(SPCp437Grid *cp437_grid);
*
* - `cp437_grid` points to a valid [SPCp437Grid]
*/
size_t sp_cp437_grid_width(const SPCp437Grid *cp437_grid);
size_t sp_cp437_grid_width(const Cp437Grid *cp437_grid);
/**
* Clones a [SPPacket].