2024-05-12 21:14:23 +02:00
|
|
|
/* Generated with cbindgen:0.26.0 */
|
|
|
|
|
2024-09-07 13:22:41 +02:00
|
|
|
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
|
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* pixel count on whole screen
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
#define SP_PIXEL_COUNT (SP_PIXEL_WIDTH * SP_PIXEL_HEIGHT)
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Display height in pixels
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
#define SP_PIXEL_HEIGHT (SP_TILE_HEIGHT * SP_TILE_SIZE)
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Display width in pixels
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
#define SP_PIXEL_WIDTH (SP_TILE_WIDTH * SP_TILE_SIZE)
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Display tile count in the y-direction
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
#define SP_TILE_HEIGHT 20
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* size of a single tile in one dimension
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
#define SP_TILE_SIZE 8
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Display tile count in the x-direction
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
#define SP_TILE_WIDTH 56
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-05 21:15:53 +02:00
|
|
|
* Specifies the kind of compression to use.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
enum SPCompressionCode
|
2024-05-12 21:14:23 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
: uint16_t
|
|
|
|
#endif // __cplusplus
|
|
|
|
{
|
2024-05-28 21:28:42 +02:00
|
|
|
/**
|
|
|
|
* no compression
|
|
|
|
*/
|
2024-05-12 21:14:23 +02:00
|
|
|
Uncompressed = 0,
|
2024-05-28 21:28:42 +02:00
|
|
|
/**
|
|
|
|
* compress using flate2 with zlib header
|
|
|
|
*/
|
2024-05-16 21:32:33 +02:00
|
|
|
Zlib = 26490,
|
2024-05-28 21:28:42 +02:00
|
|
|
/**
|
|
|
|
* compress using bzip2
|
|
|
|
*/
|
2024-05-16 21:32:33 +02:00
|
|
|
Bzip2 = 25210,
|
2024-05-28 21:28:42 +02:00
|
|
|
/**
|
|
|
|
* compress using lzma
|
|
|
|
*/
|
2024-05-16 21:32:33 +02:00
|
|
|
Lzma = 27770,
|
2024-05-28 21:28:42 +02:00
|
|
|
/**
|
|
|
|
* compress using Zstandard
|
|
|
|
*/
|
2024-05-16 21:32:33 +02:00
|
|
|
Zstd = 31347,
|
2024-05-12 21:14:23 +02:00
|
|
|
};
|
|
|
|
#ifndef __cplusplus
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef uint16_t SPCompressionCode;
|
2024-05-12 21:14:23 +02:00
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
/**
|
2024-09-05 21:15:53 +02:00
|
|
|
* A vector of bits
|
2024-08-29 19:39:18 +02:00
|
|
|
*
|
|
|
|
* # Examples
|
2024-09-05 21:15:53 +02:00
|
|
|
* ```C
|
|
|
|
* SPBitVec vec = sp_bit_vec_new(8);
|
|
|
|
* sp_bit_vec_set(vec, 5, true);
|
2024-09-07 14:19:18 +02:00
|
|
|
* sp_bit_vec_free(vec);
|
2024-08-29 19:39:18 +02:00
|
|
|
* ```
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef struct SPBitVec SPBitVec;
|
2024-06-23 15:42:15 +02:00
|
|
|
|
2024-08-29 19:39:18 +02:00
|
|
|
/**
|
2024-09-05 21:15:53 +02:00
|
|
|
* A grid containing brightness values.
|
|
|
|
*
|
|
|
|
* # Examples
|
|
|
|
* ```C
|
|
|
|
* SPConnection connection = sp_connection_open("127.0.0.1:2342");
|
|
|
|
* if (connection == NULL)
|
|
|
|
* return 1;
|
|
|
|
*
|
|
|
|
* SPBrightnessGrid grid = sp_brightness_grid_new(2, 2);
|
|
|
|
* sp_brightness_grid_set(grid, 0, 0, 0);
|
|
|
|
* sp_brightness_grid_set(grid, 1, 1, 10);
|
|
|
|
*
|
|
|
|
* SPCommand command = sp_command_char_brightness(grid);
|
2024-09-07 14:19:18 +02:00
|
|
|
* sp_connection_free(connection);
|
2024-09-05 21:15:53 +02:00
|
|
|
* ```
|
2024-08-29 19:39:18 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef struct SPBrightnessGrid SPBrightnessGrid;
|
2024-06-23 15:42:15 +02:00
|
|
|
|
2024-08-29 20:39:42 +02:00
|
|
|
/**
|
2024-08-29 22:02:53 +02:00
|
|
|
* A low-level display command.
|
|
|
|
*
|
|
|
|
* This struct and associated functions implement the UDP protocol for the display.
|
|
|
|
*
|
2024-09-07 11:44:42 +02:00
|
|
|
* To send a `SPCommand`, use a `SPConnection`.
|
2024-09-05 21:15:53 +02:00
|
|
|
*
|
|
|
|
* # Examples
|
|
|
|
*
|
|
|
|
* ```C
|
|
|
|
* sp_connection_send(connection, sp_command_clear());
|
|
|
|
* sp_connection_send(connection, sp_command_brightness(5));
|
|
|
|
* ```
|
2024-08-29 20:39:42 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef struct SPCommand SPCommand;
|
2024-08-29 20:39:42 +02:00
|
|
|
|
2024-08-29 19:39:18 +02:00
|
|
|
/**
|
2024-09-05 21:15:53 +02:00
|
|
|
* A connection to the display.
|
2024-08-29 19:39:18 +02:00
|
|
|
*
|
2024-09-05 21:15:53 +02:00
|
|
|
* # Examples
|
|
|
|
*
|
|
|
|
* ```C
|
|
|
|
* CConnection connection = sp_connection_open("172.23.42.29:2342");
|
|
|
|
* if (connection != NULL)
|
|
|
|
* sp_connection_send(connection, sp_command_clear());
|
|
|
|
* ```
|
2024-08-29 19:39:18 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef struct SPConnection SPConnection;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-05 21:15:53 +02:00
|
|
|
* A C-wrapper for grid containing codepage 437 characters.
|
|
|
|
*
|
|
|
|
* The encoding is currently not enforced.
|
2024-08-29 19:39:18 +02:00
|
|
|
*
|
|
|
|
* # Examples
|
2024-09-05 21:15:53 +02:00
|
|
|
*
|
|
|
|
* ```C
|
|
|
|
* Cp437Grid grid = sp_cp437_grid_new(4, 3);
|
|
|
|
* sp_cp437_grid_fill(grid, '?');
|
|
|
|
* sp_cp437_grid_set(grid, 0, 0, '!');
|
2024-09-07 14:19:18 +02:00
|
|
|
* sp_cp437_grid_free(grid);
|
2024-08-29 19:39:18 +02:00
|
|
|
* ```
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef struct SPCp437Grid SPCp437Grid;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
2024-09-05 21:15:53 +02:00
|
|
|
* The raw packet
|
2024-05-15 20:34:51 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef struct SPPacket SPPacket;
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
2024-09-05 21:15:53 +02:00
|
|
|
* A grid of pixels.
|
|
|
|
*
|
|
|
|
* # Examples
|
|
|
|
*
|
|
|
|
* ```C
|
|
|
|
* Cp437Grid grid = sp_pixel_grid_new(8, 3);
|
|
|
|
* sp_pixel_grid_fill(grid, true);
|
|
|
|
* sp_pixel_grid_set(grid, 0, 0, false);
|
2024-09-07 14:19:18 +02:00
|
|
|
* sp_pixel_grid_free(grid);
|
2024-09-05 21:15:53 +02:00
|
|
|
* ```
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef struct SPPixelGrid SPPixelGrid;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
2024-05-15 23:17:29 +02:00
|
|
|
* Represents a span of memory (`&mut [u8]` ) as a struct usable by C code.
|
2024-05-15 20:34:51 +02:00
|
|
|
*
|
2024-09-07 12:23:32 +02:00
|
|
|
* You should not create an instance of this type in your C code.
|
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
|
|
|
* - accesses to the memory pointed to with `start` is never accessed outside `length`
|
|
|
|
* - the lifetime of the `CByteSlice` does not outlive the memory it points to, as described in
|
|
|
|
* the function returning this type.
|
2024-09-07 12:23:32 +02:00
|
|
|
* - an instance of this created from C is never passed to a consuming function, as the rust code
|
|
|
|
* will try to free the memory of a potentially separate allocator.
|
2024-05-15 20:34:51 +02:00
|
|
|
*/
|
2024-09-05 21:15:53 +02:00
|
|
|
typedef struct SPByteSlice {
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
|
|
|
* The start address of the memory
|
|
|
|
*/
|
|
|
|
uint8_t *start;
|
|
|
|
/**
|
|
|
|
* The amount of memory in bytes
|
|
|
|
*/
|
|
|
|
size_t length;
|
2024-09-05 21:15:53 +02:00
|
|
|
} SPByteSlice;
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Clones a `SPBitVec`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
2024-09-07 13:22:41 +02:00
|
|
|
* - `this` is not written to concurrently
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_bit_vec_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPBitVec *sp_bit_vec_clone(const struct SPBitVec *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets the value of all bits in the `SPBitVec`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Arguments
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `value`: the value to set all bits to
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
|
|
|
* - `this` is not written to or read from concurrently
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_bit_vec_fill(struct SPBitVec *this_, bool value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Deallocates a `SPBitVec`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
|
|
|
* - `this` is not used concurrently or after this call
|
|
|
|
* - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_bit_vec_free(struct SPBitVec *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 23:17:29 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the value of a bit from the `SPBitVec`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Arguments
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to read from
|
|
|
|
* - `index`: the bit index to read
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* returns: value of the bit
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* When accessing `index` out of bounds.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
|
|
|
* - `this` is not written to concurrently
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
bool sp_bit_vec_get(const struct SPBitVec *this_, size_t index);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Returns true if length is 0.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
bool sp_bit_vec_is_empty(const struct SPBitVec *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the length of the `SPBitVec` in bits.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
size_t sp_bit_vec_len(const struct SPBitVec *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Interpret the data as a series of bits and load then into a new `SPBitVec` instance.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `data` points to a valid memory location of at least `data_length`
|
|
|
|
* bytes in size.
|
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_bit_vec_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPBitVec *sp_bit_vec_load(const uint8_t *data,
|
|
|
|
size_t data_length);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Creates a new `SPBitVec` instance.
|
2024-05-15 20:34:51 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Arguments
|
2024-05-15 20:34:51 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `size`: size in bits.
|
|
|
|
*
|
|
|
|
* returns: `SPBitVec` with all bits set to false.
|
|
|
|
*
|
|
|
|
* # Panics
|
2024-05-15 20:34:51 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* When `size` is not divisible by 8.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_bit_vec_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPBitVec *sp_bit_vec_new(size_t size);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets the value of a bit in the `SPBitVec`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Arguments
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to write to
|
|
|
|
* - `index`: the bit index to edit
|
|
|
|
* - `value`: the value to set the bit to
|
|
|
|
*
|
|
|
|
* returns: old value of the bit
|
|
|
|
*
|
|
|
|
* # Panics
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* When accessing `index` out of bounds.
|
2024-05-12 21:14:23 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
|
|
|
* - `this` is not written to or read from concurrently
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_bit_vec_set(struct SPBitVec *this_, size_t index, bool value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets an unsafe reference to the data of the `SPBitVec` instance.
|
2024-08-29 19:39:18 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* ## Safety
|
2024-08-29 19:39:18 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
|
|
|
* - `this` points to a valid `SPBitVec`
|
|
|
|
* - the returned memory range is never accessed after the passed `SPBitVec` has been freed
|
|
|
|
* - the returned memory range is never accessed concurrently, either via the `SPBitVec` or directly
|
|
|
|
*/
|
|
|
|
struct SPByteSlice sp_bit_vec_unsafe_data_ref(struct SPBitVec *this_);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clones a `SPBrightnessGrid`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBrightnessGrid`
|
|
|
|
* - `this` is not written to concurrently
|
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_brightness_grid_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPBrightnessGrid *sp_brightness_grid_clone(const struct SPBrightnessGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets the value of all cells in the `SPBrightnessGrid`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Arguments
|
|
|
|
*
|
|
|
|
* - `this`: instance to write to
|
|
|
|
* - `value`: the value to set all cells to
|
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
|
|
|
* - When providing an invalid brightness value
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBrightnessGrid`
|
|
|
|
* - `this` is not written to or read from concurrently
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_brightness_grid_fill(struct SPBrightnessGrid *this_, uint8_t value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Deallocates a `SPBrightnessGrid`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBrightnessGrid`
|
2024-09-07 13:22:41 +02:00
|
|
|
* - `this` is not used concurrently or after this call
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_brightness_grid_free(struct SPBrightnessGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the current value at the specified position.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to read from
|
|
|
|
* - `x` and `y`: position of the cell to read
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* When accessing `x` or `y` out of bounds.
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBrightnessGrid`
|
|
|
|
* - `this` is not written to concurrently
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
uint8_t sp_brightness_grid_get(const struct SPBrightnessGrid *this_,
|
|
|
|
size_t x,
|
|
|
|
size_t y);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the height of the `SPBrightnessGrid` instance.
|
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
|
|
|
* - `this`: instance to read from
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBrightnessGrid`
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
size_t sp_brightness_grid_height(const struct SPBrightnessGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Loads a `SPBrightnessGrid` with the specified dimensions from the provided data.
|
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
|
|
|
* When the provided `data_length` is not sufficient for the `height` and `width`
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `data` points to a valid memory location of at least `data_length`
|
|
|
|
* bytes in size.
|
2024-09-07 13:22:41 +02:00
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:19:18 +02:00
|
|
|
* by explicitly calling `sp_brightness_grid_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPBrightnessGrid *sp_brightness_grid_load(size_t width,
|
|
|
|
size_t height,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Creates a new `SPBrightnessGrid` with the specified dimensions.
|
|
|
|
*
|
|
|
|
* returns: `SPBrightnessGrid` initialized to 0.
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_brightness_grid_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPBrightnessGrid *sp_brightness_grid_new(size_t width,
|
|
|
|
size_t height);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets the value of the specified position in the `SPBrightnessGrid`.
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* # Arguments
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to write to
|
|
|
|
* - `x` and `y`: position of the cell
|
|
|
|
* - `value`: the value to write to the cell
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* returns: old value of the cell
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - When accessing `x` or `y` out of bounds.
|
|
|
|
* - When providing an invalid brightness value
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
|
|
|
* - `this` is not written to or read from concurrently
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_brightness_grid_set(struct SPBrightnessGrid *this_,
|
|
|
|
size_t x,
|
|
|
|
size_t y,
|
|
|
|
uint8_t value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets an unsafe reference to the data of the `SPBrightnessGrid` instance.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* ## Safety
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* The caller has to make sure that:
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBrightnessGrid`
|
|
|
|
* - the returned memory range is never accessed after the passed `SPBrightnessGrid` has been freed
|
|
|
|
* - the returned memory range is never accessed concurrently, either via the `SPBrightnessGrid` or directly
|
|
|
|
*/
|
|
|
|
struct SPByteSlice sp_brightness_grid_unsafe_data_ref(struct SPBrightnessGrid *this_);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the width of the `SPBrightnessGrid` instance.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Arguments
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to read from
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBrightnessGrid`
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
size_t sp_brightness_grid_width(const struct SPBrightnessGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::BitmapLinear` instance.
|
|
|
|
* The passed `SPBitVec` gets consumed.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* Set pixel data starting at the pixel offset on screen.
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
|
|
|
* once the starting row is full, overwriting will continue on column 0.
|
|
|
|
*
|
|
|
|
* The contained `SPBitVec` is always uncompressed.
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `bit_vec` points to a valid instance of `SPBitVec`
|
|
|
|
* - `bit_vec` is not used concurrently or after this call
|
|
|
|
* - `compression` matches one of the allowed enum values
|
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_bitmap_linear(size_t offset,
|
|
|
|
struct SPBitVec *bit_vec,
|
|
|
|
SPCompressionCode compression);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::BitmapLinearAnd` instance.
|
|
|
|
* The passed `SPBitVec` gets consumed.
|
|
|
|
*
|
|
|
|
* Set pixel data according to an and-mask starting at the offset.
|
|
|
|
*
|
|
|
|
* The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
|
|
|
* once the starting row is full, overwriting will continue on column 0.
|
|
|
|
*
|
|
|
|
* The contained `SPBitVec` is always uncompressed.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `bit_vec` points to a valid instance of `SPBitVec`
|
|
|
|
* - `bit_vec` is not used concurrently or after this call
|
|
|
|
* - `compression` matches one of the allowed enum values
|
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_bitmap_linear_and(size_t offset,
|
|
|
|
struct SPBitVec *bit_vec,
|
|
|
|
SPCompressionCode compression);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::BitmapLinearOr` instance.
|
|
|
|
* The passed `SPBitVec` gets consumed.
|
|
|
|
*
|
|
|
|
* Set pixel data according to an or-mask starting at the offset.
|
|
|
|
*
|
|
|
|
* The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
|
|
|
* once the starting row is full, overwriting will continue on column 0.
|
|
|
|
*
|
|
|
|
* The contained `SPBitVec` is always uncompressed.
|
2024-09-07 11:44:42 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `bit_vec` points to a valid instance of `SPBitVec`
|
|
|
|
* - `bit_vec` is not used concurrently or after this call
|
|
|
|
* - `compression` matches one of the allowed enum values
|
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_bitmap_linear_or(size_t offset,
|
|
|
|
struct SPBitVec *bit_vec,
|
|
|
|
SPCompressionCode compression);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::BitmapLinearWin` instance.
|
|
|
|
* The passed `SPPixelGrid` gets consumed.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets a window of pixels to the specified values
|
|
|
|
*
|
|
|
|
* # Safety
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `pixel_grid` points to a valid instance of `SPPixelGrid`
|
|
|
|
* - `pixel_grid` is not used concurrently or after this call
|
|
|
|
* - `compression` matches one of the allowed enum values
|
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-05-15 20:34:51 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_bitmap_linear_win(size_t x,
|
|
|
|
size_t y,
|
|
|
|
struct SPPixelGrid *pixel_grid,
|
|
|
|
SPCompressionCode compression_code);
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::BitmapLinearXor` instance.
|
|
|
|
* The passed `SPBitVec` gets consumed.
|
|
|
|
*
|
|
|
|
* Set pixel data according to a xor-mask starting at the offset.
|
|
|
|
*
|
|
|
|
* The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
|
|
|
* once the starting row is full, overwriting will continue on column 0.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* The contained `SPBitVec` is always uncompressed.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `bit_vec` points to a valid instance of `SPBitVec`
|
|
|
|
* - `bit_vec` is not used concurrently or after this call
|
|
|
|
* - `compression` matches one of the allowed enum values
|
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_bitmap_linear_xor(size_t offset,
|
|
|
|
struct SPBitVec *bit_vec,
|
|
|
|
SPCompressionCode compression);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the
|
|
|
|
* same value.
|
2024-05-12 21:14:23 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Panics
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - When the provided brightness value is out of range (0-11).
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_brightness(uint8_t brightness);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::CharBrightness` instance.
|
|
|
|
* The passed `SPBrightnessGrid` gets consumed.
|
|
|
|
*
|
|
|
|
* Set the brightness of individual tiles in a rectangular area of the display.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `grid` points to a valid instance of `SPBrightnessGrid`
|
|
|
|
* - `grid` is not used concurrently or after this call
|
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_char_brightness(size_t x,
|
|
|
|
size_t y,
|
|
|
|
struct SPBrightnessGrid *grid);
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-06-23 15:42:15 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::Clear` instance.
|
|
|
|
*
|
|
|
|
* Set all pixels to the off state. Does not affect brightness.
|
|
|
|
*
|
|
|
|
* # Examples
|
|
|
|
*
|
|
|
|
* ```C
|
|
|
|
* sp_connection_send(connection, sp_command_clear());
|
|
|
|
* ```
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_clear(void);
|
2024-06-23 15:42:15 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Clones a `SPCommand` instance.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid instance of `SPCommand`
|
2024-09-07 13:22:41 +02:00
|
|
|
* - `this` is not written to concurrently
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_clone(const struct SPCommand *original);
|
2024-06-23 15:42:15 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::Cp437Data` instance.
|
|
|
|
* The passed `SPCp437Grid` gets consumed.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* Show text on the screen.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* <div class="warning">
|
|
|
|
* The library does not currently convert between UTF-8 and CP-437.
|
|
|
|
* Because Rust expects UTF-8 strings, it might be necessary to only send ASCII for now.
|
|
|
|
* </div>
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Safety
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* The caller has to make sure that:
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `grid` points to a valid instance of `SPCp437Grid`
|
|
|
|
* - `grid` is not used concurrently or after this call
|
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
|
|
|
*/
|
|
|
|
struct SPCommand *sp_command_cp437_data(size_t x,
|
|
|
|
size_t y,
|
|
|
|
struct SPCp437Grid *grid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::FadeOut` instance.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_fade_out(void);
|
2024-06-23 15:42:15 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Deallocates a `SPCommand`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Examples
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* ```C
|
|
|
|
* SPCommand c = sp_command_clear();
|
|
|
|
* sp_command_free(c);
|
|
|
|
* ```
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPCommand`
|
|
|
|
* - `this` is not used concurrently or after this call
|
|
|
|
* - `this` was not passed to another consuming function, e.g. to create a `SPPacket`
|
2024-06-23 15:42:15 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_command_free(struct SPCommand *ptr);
|
2024-06-23 15:42:15 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Allocates a new `Command::HardReset` instance.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* Kills the udp daemon on the display, which usually results in a restart.
|
|
|
|
* Please do not send this in your normal program flow.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_hard_reset(void);
|
2024-06-23 15:42:15 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Tries to turn a `SPPacket` into a `SPCommand`. The packet is deallocated in the process.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* Returns: pointer to new `SPCommand` instance or NULL
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `SPPacket` points to a valid instance of `SPPacket`
|
|
|
|
* - `SPPacket` is not used concurrently or after this call
|
|
|
|
* - the result is checked for NULL
|
|
|
|
* - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_command_free`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCommand *sp_command_try_from_packet(struct SPPacket *packet);
|
2024-06-23 15:42:15 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Closes and deallocates a `SPConnection`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Safety
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPConnection`
|
|
|
|
* - `this` is not used concurrently or after this call
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_connection_free(struct SPConnection *ptr);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Creates a new instance of `SPConnection`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* returns: NULL if connection fails, or connected instance
|
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
|
|
|
* Bad string encoding
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:19:18 +02:00
|
|
|
* by explicitly calling `sp_connection_free`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*/
|
2024-09-07 13:22:41 +02:00
|
|
|
struct SPConnection *sp_connection_open(const char *host);
|
2024-06-23 15:42:15 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sends a `SPPacket` to the display using the `SPConnection`.
|
|
|
|
* The passed `SPPacket` gets consumed.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* returns: true in case of success
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* # Safety
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* The caller has to make sure that:
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `SPConnection` points to a valid instance of `SPConnection`
|
|
|
|
* - `SPPacket` points to a valid instance of `SPPacket`
|
|
|
|
* - `SPPacket` is not used concurrently or after this call
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
|
|
|
bool sp_connection_send(const struct SPConnection *connection,
|
|
|
|
struct SPPacket *packet);
|
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Clones a `SPCp437Grid`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* # Safety
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPCp437Grid`
|
|
|
|
* - `this` is not written to concurrently
|
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_cp437_grid_free`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCp437Grid *sp_cp437_grid_clone(const struct SPCp437Grid *this_);
|
2024-06-23 15:42:15 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets the value of all cells in the `SPCp437Grid`.
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Arguments
|
2024-06-23 15:42:15 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to write to
|
|
|
|
* - `value`: the value to set all cells to
|
2024-08-29 22:21:21 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPCp437Grid`
|
|
|
|
* - `this` is not written to or read from concurrently
|
2024-08-29 22:21:21 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_cp437_grid_fill(struct SPCp437Grid *this_, uint8_t value);
|
2024-08-29 22:21:21 +02:00
|
|
|
|
2024-05-15 23:17:29 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Deallocates a `SPCp437Grid`.
|
2024-05-15 23:17:29 +02:00
|
|
|
*
|
2024-05-28 22:23:21 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPCp437Grid`
|
2024-05-28 22:23:21 +02:00
|
|
|
* - `this` is not used concurrently or after this call
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
|
2024-05-15 23:17:29 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_cp437_grid_free(struct SPCp437Grid *this_);
|
2024-05-15 23:17:29 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the current value at the specified position.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to read from
|
|
|
|
* - `x` and `y`: position of the cell to read
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* When accessing `x` or `y` out of bounds.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPCp437Grid`
|
|
|
|
* - `this` is not written to concurrently
|
2024-05-15 20:34:51 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
uint8_t sp_cp437_grid_get(const struct SPCp437Grid *this_, size_t x, size_t y);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 23:17:29 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the height of the `SPCp437Grid` instance.
|
2024-05-15 23:17:29 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* # Arguments
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to read from
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPCp437Grid`
|
2024-05-15 23:17:29 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
size_t sp_cp437_grid_height(const struct SPCp437Grid *this_);
|
2024-05-15 23:17:29 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Loads a `SPCp437Grid` with the specified dimensions from the provided data.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Panics
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* When the provided `data_length` is not sufficient for the `height` and `width`
|
2024-05-12 21:14:23 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `data` points to a valid memory location of at least `data_length`
|
|
|
|
* bytes in size.
|
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_cp437_grid_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCp437Grid *sp_cp437_grid_load(size_t width,
|
|
|
|
size_t height,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-09-07 13:22:41 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Creates a new `SPCp437Grid` with the specified dimensions.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* returns: `SPCp437Grid` initialized to 0.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_cp437_grid_free`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPCp437Grid *sp_cp437_grid_new(size_t width,
|
|
|
|
size_t height);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets the value of the specified position in the `SPCp437Grid`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
|
|
|
* - `this`: instance to write to
|
|
|
|
* - `x` and `y`: position of the cell
|
|
|
|
* - `value`: the value to write to the cell
|
|
|
|
*
|
|
|
|
* returns: old value of the cell
|
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
|
|
|
* When accessing `x` or `y` out of bounds.
|
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPBitVec`
|
2024-09-07 13:22:41 +02:00
|
|
|
* - `this` is not written to or read from concurrently
|
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_cp437_grid_set(struct SPCp437Grid *this_,
|
2024-09-07 13:22:41 +02:00
|
|
|
size_t x,
|
|
|
|
size_t y,
|
2024-09-07 14:19:18 +02:00
|
|
|
uint8_t value);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets an unsafe reference to the data of the `SPCp437Grid` instance.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* ## Safety
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPCp437Grid`
|
|
|
|
* - 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
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPByteSlice sp_cp437_grid_unsafe_data_ref(struct SPCp437Grid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the width of the `SPCp437Grid` instance.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
2024-08-29 19:39:18 +02:00
|
|
|
* - `this`: instance to read from
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPCp437Grid`
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
size_t sp_cp437_grid_width(const struct SPCp437Grid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Clones a `SPPacket`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Safety
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
|
|
|
* - `this` points to a valid `SPPacket`
|
|
|
|
* - `this` is not written to concurrently
|
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_packet_free`.
|
|
|
|
*/
|
|
|
|
struct SPPacket *sp_packet_clone(const struct SPPacket *this_);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deallocates a `SPPacket`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPPacket`
|
|
|
|
* - `this` is not used concurrently or after this call
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_packet_free(struct SPPacket *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Turns a `SPCommand` into a `SPPacket`.
|
|
|
|
* The `SPCommand` gets consumed.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* # Safety
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* The caller has to make sure that:
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `SPCommand` points to a valid instance of `SPCommand`
|
|
|
|
* - `SPCommand` is not used concurrently or after this call
|
|
|
|
* - the returned `SPPacket` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_packet_free`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPPacket *sp_packet_from_command(struct SPCommand *command);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Tries to load a `SPPacket` from the passed array with the specified length.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* returns: NULL in case of an error, pointer to the allocated packet otherwise
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `data` points to a valid memory region of at least `length` bytes
|
|
|
|
* - `data` is not written to concurrently
|
|
|
|
* - the returned `SPPacket` instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_packet_free`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPPacket *sp_packet_try_load(const uint8_t *data,
|
|
|
|
size_t length);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Clones a `SPPixelGrid`.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPPixelGrid`
|
|
|
|
* - `this` is not written to concurrently
|
2024-05-28 21:28:42 +02:00
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:19:18 +02:00
|
|
|
* by explicitly calling `sp_pixel_grid_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPPixelGrid *sp_pixel_grid_clone(const struct SPPixelGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets the state of all pixels in the `SPPixelGrid`.
|
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
|
|
|
* - `this`: instance to write to
|
|
|
|
* - `value`: the value to set all pixels to
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* # Safety
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* The caller has to make sure that:
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPPixelGrid`
|
|
|
|
* - `this` is not written to or read from concurrently
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_pixel_grid_fill(struct SPPixelGrid *this_, bool value);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Deallocates a `SPPixelGrid`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPPixelGrid`
|
2024-09-07 13:22:41 +02:00
|
|
|
* - `this` is not used concurrently or after this call
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` was not passed to another consuming function, e.g. to create a `SPCommand`
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_pixel_grid_free(struct SPPixelGrid *this_);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the current value at the specified position in the `SPPixelGrid`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
|
|
|
* - `this`: instance to read from
|
|
|
|
* - `x` and `y`: position of the cell to read
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* When accessing `x` or `y` out of bounds.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPPixelGrid`
|
2024-09-07 13:22:41 +02:00
|
|
|
* - `this` is not written to concurrently
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
bool sp_pixel_grid_get(const struct SPPixelGrid *this_, size_t x, size_t y);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets the height in pixels of the `SPPixelGrid` instance.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to read from
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPPixelGrid`
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
size_t sp_pixel_grid_height(const struct SPPixelGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Loads a `SPPixelGrid` with the specified dimensions from the provided data.
|
2024-05-15 20:34:51 +02:00
|
|
|
*
|
2024-09-07 13:22:41 +02:00
|
|
|
* # Arguments
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `width`: size in pixels in x-direction
|
|
|
|
* - `height`: size in pixels in y-direction
|
|
|
|
*
|
|
|
|
* returns: `SPPixelGrid` that contains a copy of the provided data
|
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
|
|
|
* - when the dimensions and data size do not match exactly.
|
|
|
|
* - when the width is not dividable by 8
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
2024-05-15 20:34:51 +02:00
|
|
|
*
|
2024-05-28 21:28:42 +02:00
|
|
|
* The caller has to make sure that:
|
2024-05-15 20:34:51 +02:00
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `data` points to a valid memory location of at least `data_length` bytes in size.
|
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_pixel_grid_free`.
|
2024-05-15 20:34:51 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPPixelGrid *sp_pixel_grid_load(size_t width,
|
|
|
|
size_t height,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length);
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Creates a new `SPPixelGrid` with the specified dimensions.
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `width`: size in pixels in x-direction
|
|
|
|
* - `height`: size in pixels in y-direction
|
|
|
|
*
|
|
|
|
* returns: `SPPixelGrid` initialized to all pixels off
|
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
|
|
|
* - when the width is not dividable by 8
|
2024-05-28 21:28:42 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
* by explicitly calling `sp_pixel_grid_free`.
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPPixelGrid *sp_pixel_grid_new(size_t width,
|
|
|
|
size_t height);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Sets the value of the specified position in the `SPPixelGrid`.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this`: instance to write to
|
|
|
|
* - `x` and `y`: position of the cell
|
|
|
|
* - `value`: the value to write to the cell
|
|
|
|
*
|
|
|
|
* returns: old value of the cell
|
|
|
|
*
|
|
|
|
* # Panics
|
|
|
|
*
|
|
|
|
* When accessing `x` or `y` out of bounds.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPPixelGrid`
|
|
|
|
* - `this` is not written to or read from concurrently
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
void sp_pixel_grid_set(struct SPPixelGrid *this_,
|
|
|
|
size_t x,
|
|
|
|
size_t y,
|
|
|
|
bool value);
|
2024-09-07 13:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-07 14:19:18 +02:00
|
|
|
* Gets an unsafe reference to the data of the `SPPixelGrid` instance.
|
2024-09-07 13:22:41 +02:00
|
|
|
*
|
|
|
|
* ## Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
2024-09-07 14:19:18 +02:00
|
|
|
* - `this` points to a valid `SPPixelGrid`
|
|
|
|
* - the returned memory range is never accessed after the passed `SPPixelGrid` has been freed
|
|
|
|
* - the returned memory range is never accessed concurrently, either via the `SPPixelGrid` or directly
|
2024-09-07 13:22:41 +02:00
|
|
|
*/
|
2024-09-07 14:19:18 +02:00
|
|
|
struct SPByteSlice sp_pixel_grid_unsafe_data_ref(struct SPPixelGrid *this_);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the width in pixels of the `SPPixelGrid` instance.
|
|
|
|
*
|
|
|
|
* # Arguments
|
|
|
|
*
|
|
|
|
* - `this`: instance to read from
|
|
|
|
*
|
|
|
|
* # Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure that:
|
|
|
|
*
|
|
|
|
* - `this` points to a valid `SPPixelGrid`
|
|
|
|
*/
|
|
|
|
size_t sp_pixel_grid_width(const struct SPPixelGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif // __cplusplus
|