1
0
Fork 0

[QP] Add RGB565 surface. Docs clarification, cleanup, tabsification, and reordering. (#18396)

This commit is contained in:
Nick Brassel 2022-09-19 07:30:08 +10:00 committed by GitHub
parent e9bdc4eeb1
commit 1849897444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 782 additions and 294 deletions

View file

@ -25,10 +25,10 @@ typedef struct qgf_image_handle_t {
static qgf_image_handle_t image_descriptors[QUANTUM_PAINTER_NUM_IMAGES] = {0};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_load_image_mem
// Helper: load image from stream
painter_image_handle_t qp_load_image_mem(const void *buffer) {
qp_dprintf("qp_load_image_mem: entry\n");
static painter_image_handle_t qp_load_image_internal(bool (*stream_factory)(qgf_image_handle_t *image, void *arg), void *arg) {
qp_dprintf("qp_load_image: entry\n");
qgf_image_handle_t *image = NULL;
// Find a free slot
@ -41,20 +41,18 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
// Drop out if not found
if (!image) {
qp_dprintf("qp_load_image_mem: fail (no free slot)\n");
qp_dprintf("qp_load_image: fail (no free slot)\n");
return NULL;
}
// Assume we can read the graphics descriptor
image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t));
// Update the length of the stream to match, and rewind to the start
image->mem_stream.length = qgf_get_total_size(&image->stream);
image->mem_stream.position = 0;
if (!stream_factory(image, arg)) {
qp_dprintf("qp_load_image: fail (could not create stream)\n");
return NULL;
}
// Now that we know the length, validate the input data
if (!qgf_validate_stream(&image->stream)) {
qp_dprintf("qp_load_image_mem: fail (failed validation)\n");
qp_dprintf("qp_load_image: fail (failed validation)\n");
return NULL;
}
@ -63,10 +61,30 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
// Validation success, we can return the handle
image->validate_ok = true;
qp_dprintf("qp_load_image_mem: ok\n");
qp_dprintf("qp_load_image: ok\n");
return (painter_image_handle_t)image;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_load_image_mem
static inline bool image_mem_stream_factory(qgf_image_handle_t *image, void *arg) {
void *buffer = arg;
// Assume we can read the graphics descriptor
image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t));
// Update the length of the stream to match, and rewind to the start
image->mem_stream.length = qgf_get_total_size(&image->stream);
image->mem_stream.position = 0;
return true;
}
painter_image_handle_t qp_load_image_mem(const void *buffer) {
return qp_load_image_internal(image_mem_stream_factory, (void *)buffer);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_close_image
@ -79,6 +97,7 @@ bool qp_close_image(painter_image_handle_t image) {
// Free up this image for use elsewhere.
qgf_image->validate_ok = false;
qp_stream_close(&qgf_image->stream);
return true;
}