2024-05-12 21:14:23 +02:00
|
|
|
/* Generated with cbindgen:0.26.0 */
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pixel count on whole screen
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
#define sp_PIXEL_COUNT (sp_PIXEL_WIDTH * sp_PIXEL_HEIGHT)
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* screen height in pixels
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
#define sp_PIXEL_HEIGHT (sp_TILE_HEIGHT * sp_TILE_SIZE)
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* screen width in pixels
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
#define sp_PIXEL_WIDTH (sp_TILE_WIDTH * sp_TILE_SIZE)
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tile count in the y-direction
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
#define sp_TILE_HEIGHT 20
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* size of a single tile in one dimension
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
#define sp_TILE_SIZE 8
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* tile count in the x-direction
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
#define sp_TILE_WIDTH 56
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies the kind of compression to use. Availability depends on features.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
enum sp_CompressionCode
|
2024-05-12 21:14:23 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
: uint16_t
|
|
|
|
#endif // __cplusplus
|
|
|
|
{
|
|
|
|
Uncompressed = 0,
|
2024-05-16 21:32:33 +02:00
|
|
|
Zlib = 26490,
|
|
|
|
Bzip2 = 25210,
|
|
|
|
Lzma = 27770,
|
|
|
|
Zstd = 31347,
|
2024-05-12 21:14:23 +02:00
|
|
|
};
|
|
|
|
#ifndef __cplusplus
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef uint16_t sp_CompressionCode;
|
2024-05-12 21:14:23 +02:00
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A vector of bits
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef struct sp_BitVec sp_BitVec;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
2024-05-15 20:34:51 +02:00
|
|
|
* A 2D grid of bytes
|
2024-05-12 21:14:23 +02:00
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef struct sp_ByteGrid sp_ByteGrid;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A command to send to the display.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef struct sp_Command sp_Command;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A connection to the display.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef struct sp_Connection sp_Connection;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
|
|
|
* The raw packet. Should probably not be used directly.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef struct sp_Packet sp_Packet;
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
|
|
|
* A grid of pixels stored in packed bytes.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef struct sp_PixelGrid sp_PixelGrid;
|
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
|
|
|
*
|
|
|
|
* Usage of this type is inherently unsafe.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef struct sp_CByteSlice {
|
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-05-26 13:15:11 +02:00
|
|
|
} sp_CByteSlice;
|
2024-05-15 20:34:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type alias for documenting the meaning of the u16 in enum values
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef size_t sp_Offset;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
|
|
|
* Type alias for documenting the meaning of the u16 in enum values
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
typedef uint8_t sp_Brightness;
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clones a `BitVec`.
|
|
|
|
* The returned instance has to be freed with `bit_vec_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_BitVec *sp_bit_vec_clone(const struct sp_BitVec *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deallocates a `BitVec`.
|
|
|
|
*
|
|
|
|
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_bit_vec_dealloc(struct sp_BitVec *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the value of all bits in the `BitVec`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_bit_vec_fill(struct sp_BitVec *this_, bool value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the value of a bit from the `BitVec`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
bool sp_bit_vec_get(const struct sp_BitVec *this_, size_t index);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 23:17:29 +02:00
|
|
|
/**
|
|
|
|
* Returns true if length is 0.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
bool sp_bit_vec_is_empty(const struct sp_BitVec *this_);
|
2024-05-15 23:17:29 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
|
|
|
* Gets the length of the `BitVec` in bits.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
size_t sp_bit_vec_len(const struct sp_BitVec *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a `BitVec` from the provided data.
|
|
|
|
* The returned instance has to be freed with `bit_vec_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_BitVec *sp_bit_vec_load(const uint8_t *data, size_t data_length);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new `BitVec` instance.
|
|
|
|
* The returned instance has to be freed with `bit_vec_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_BitVec *sp_bit_vec_new(size_t size);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the value of a bit in the `BitVec`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
bool sp_bit_vec_set(struct sp_BitVec *this_, size_t index, bool value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
|
|
|
* Gets an unsafe reference to the data of the `BitVec` instance.
|
|
|
|
*
|
|
|
|
* ## Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure to never access the returned memory after the `BitVec`
|
|
|
|
* instance has been consumed or manually deallocated.
|
|
|
|
*
|
|
|
|
* Reading and writing concurrently to either the original instance or the returned data will
|
|
|
|
* result in undefined behavior.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_CByteSlice sp_bit_vec_unsafe_data_ref(struct sp_BitVec *this_);
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
|
|
|
* Clones a `ByteGrid`.
|
|
|
|
* The returned instance has to be freed with `byte_grid_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_ByteGrid *sp_byte_grid_clone(const struct sp_ByteGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deallocates a `ByteGrid`.
|
|
|
|
*
|
|
|
|
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_byte_grid_dealloc(struct sp_ByteGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills the whole `ByteGrid` with the specified value
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_byte_grid_fill(struct sp_ByteGrid *this_, uint8_t value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current value at the specified position
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
uint8_t sp_byte_grid_get(const struct sp_ByteGrid *this_, size_t x, size_t y);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the height in pixels of the `ByteGrid` instance.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
size_t sp_byte_grid_height(const struct sp_ByteGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a `ByteGrid` with the specified dimensions from the provided data.
|
|
|
|
* The returned instance has to be freed with `byte_grid_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_ByteGrid *sp_byte_grid_load(size_t width,
|
|
|
|
size_t height,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new `ByteGrid` instance.
|
|
|
|
* The returned instance has to be freed with `byte_grid_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_ByteGrid *sp_byte_grid_new(size_t width, size_t height);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the current value at the specified position
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_byte_grid_set(struct sp_ByteGrid *this_,
|
|
|
|
size_t x,
|
|
|
|
size_t y,
|
|
|
|
uint8_t value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
|
|
|
* Gets an unsafe reference to the data of the `ByteGrid` instance.
|
|
|
|
*
|
|
|
|
* ## Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure to never access the returned memory after the `ByteGrid`
|
|
|
|
* instance has been consumed or manually deallocated.
|
|
|
|
*
|
|
|
|
* Reading and writing concurrently to either the original instance or the returned data will
|
|
|
|
* result in undefined behavior.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_CByteSlice sp_byte_grid_unsafe_data_ref(struct sp_ByteGrid *this_);
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
|
|
|
* Gets the width in pixels of the `ByteGrid` instance.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
size_t sp_byte_grid_width(const struct sp_ByteGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::BitmapLinear` instance.
|
|
|
|
* The passed `BitVec` gets deallocated in the process.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_bitmap_linear(sp_Offset offset,
|
|
|
|
struct sp_BitVec *bit_vec,
|
|
|
|
sp_CompressionCode compression);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::BitmapLinearAnd` instance.
|
|
|
|
* The passed `BitVec` gets deallocated in the process.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_bitmap_linear_and(sp_Offset offset,
|
|
|
|
struct sp_BitVec *bit_vec,
|
|
|
|
sp_CompressionCode compression);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::BitmapLinearOr` instance.
|
|
|
|
* The passed `BitVec` gets deallocated in the process.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_bitmap_linear_or(sp_Offset offset,
|
|
|
|
struct sp_BitVec *bit_vec,
|
|
|
|
sp_CompressionCode compression);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::BitmapLinearWin` instance.
|
|
|
|
* The passed `PixelGrid` gets deallocated in the process.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_bitmap_linear_win(size_t x,
|
|
|
|
size_t y,
|
|
|
|
struct sp_PixelGrid *byte_grid,
|
|
|
|
sp_CompressionCode compression_code);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::BitmapLinearXor` instance.
|
|
|
|
* The passed `BitVec` gets deallocated in the process.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_bitmap_linear_xor(sp_Offset offset,
|
|
|
|
struct sp_BitVec *bit_vec,
|
|
|
|
sp_CompressionCode compression);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::Brightness` instance
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_brightness(sp_Brightness brightness);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::CharBrightness` instance.
|
|
|
|
* The passed `ByteGrid` gets deallocated in the process.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_char_brightness(size_t x,
|
|
|
|
size_t y,
|
|
|
|
struct sp_ByteGrid *byte_grid);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::Clear` instance
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_clear(void);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clones a `Command` instance
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_clone(const struct sp_Command *original);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::Cp437Data` instance.
|
|
|
|
* The passed `ByteGrid` gets deallocated in the process.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_cp437_data(size_t x,
|
|
|
|
size_t y,
|
|
|
|
struct sp_ByteGrid *byte_grid);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deallocates a `Command`. Note that connection_send does this implicitly, so you only need
|
|
|
|
* to do this if you use the library for parsing commands.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_command_dealloc(struct sp_Command *ptr);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::FadeOut` instance
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_fade_out(void);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a new `Command::HardReset` instance
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_hard_reset(void);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
|
|
|
* Tries to turn a `Packet` into a `Command`. The packet is gets deallocated in the process.
|
|
|
|
*
|
|
|
|
* Returns: pointer to command or NULL
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Command *sp_command_try_from_packet(struct sp_Packet *packet);
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
|
|
|
* Closes and deallocates a connection instance
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_connection_dealloc(struct sp_Connection *ptr);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new instance of Connection.
|
|
|
|
* The returned instance has to be deallocated with `connection_dealloc`.
|
|
|
|
*
|
|
|
|
* returns: NULL if connection fails or connected instance
|
|
|
|
*
|
|
|
|
* Panics: bad string encoding
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Connection *sp_connection_open(const char *host);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends the command instance. The instance is consumed / destroyed and cannot be used after this call.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
bool sp_connection_send(const struct sp_Connection *connection,
|
|
|
|
struct sp_Packet *command_ptr);
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-15 23:17:29 +02:00
|
|
|
/**
|
|
|
|
* Deallocates a `Packet`.
|
|
|
|
*
|
|
|
|
* Note: do not call this if the instance has been consumed in another way, e.g. by sending it.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_packet_dealloc(struct sp_Packet *this_);
|
2024-05-15 23:17:29 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
|
|
|
* Turns a `Command` into a `Packet`. The command gets deallocated in the process.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Packet *sp_packet_from_command(struct sp_Command *command);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 23:17:29 +02:00
|
|
|
/**
|
|
|
|
* Tries to load a `Packet` from the passed array with the specified length.
|
|
|
|
*
|
|
|
|
* returns: NULL in case of an error, pointer to the allocated packet otherwise
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_Packet *sp_packet_try_load(const uint8_t *data, size_t length);
|
2024-05-15 23:17:29 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
|
|
|
* Clones a `PixelGrid`.
|
|
|
|
* The returned instance has to be freed with `pixel_grid_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_PixelGrid *sp_pixel_grid_clone(const struct sp_PixelGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deallocates a `PixelGrid`.
|
|
|
|
*
|
|
|
|
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_pixel_grid_dealloc(struct sp_PixelGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills the whole `PixelGrid` with the specified value
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_pixel_grid_fill(struct sp_PixelGrid *this_, bool value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current value at the specified position
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
bool sp_pixel_grid_get(const struct sp_PixelGrid *this_, size_t x, size_t y);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the height in pixels of the `PixelGrid` instance.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
size_t sp_pixel_grid_height(const struct sp_PixelGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a `PixelGrid` with the specified dimensions from the provided data.
|
|
|
|
* The returned instance has to be freed with `pixel_grid_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_PixelGrid *sp_pixel_grid_load(size_t width,
|
|
|
|
size_t height,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new `PixelGrid` instance.
|
|
|
|
* The returned instance has to be freed with `pixel_grid_dealloc`.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_PixelGrid *sp_pixel_grid_new(size_t width, size_t height);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the current value at the specified position
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
void sp_pixel_grid_set(struct sp_PixelGrid *this_,
|
|
|
|
size_t x,
|
|
|
|
size_t y,
|
|
|
|
bool value);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
/**
|
|
|
|
* Gets an unsafe reference to the data of the `PixelGrid` instance.
|
|
|
|
*
|
|
|
|
* ## Safety
|
|
|
|
*
|
|
|
|
* The caller has to make sure to never access the returned memory after the `PixelGrid`
|
|
|
|
* instance has been consumed or manually deallocated.
|
|
|
|
*
|
|
|
|
* Reading and writing concurrently to either the original instance or the returned data will
|
|
|
|
* result in undefined behavior.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
struct sp_CByteSlice sp_pixel_grid_unsafe_data_ref(struct sp_PixelGrid *this_);
|
2024-05-15 20:34:51 +02:00
|
|
|
|
2024-05-12 21:14:23 +02:00
|
|
|
/**
|
|
|
|
* Gets the width in pixels of the `PixelGrid` instance.
|
|
|
|
*/
|
2024-05-26 13:15:11 +02:00
|
|
|
size_t sp_pixel_grid_width(const struct sp_PixelGrid *this_);
|
2024-05-12 21:14:23 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif // __cplusplus
|