From 833025f5dd6f73a1411ea2215075084049f36d15 Mon Sep 17 00:00:00 2001 From: Lephe Date: Mon, 29 Jan 2024 09:49:34 +0100 Subject: [PATCH] render-fx: turn bopti_image_t's data array into a pointer It used to be a flexible array member because in the old days fxconv could only output a fixed set of bytes, so any referencing was out the question. Nowadays fxconv can output pretty much anything. Separating the data pointer will be useful for PythonExtra to expose it as a Python bytes() or bytearray() object while using the gint API. --- TODO | 1 + include/gint/display-fx.h | 14 +++++++++++++- src/render-fx/bopti.c | 5 ++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index d6d3e38..501e373 100644 --- a/TODO +++ b/TODO @@ -17,6 +17,7 @@ Extensions on existing code: * core: run destructors when a task-switch results in leaving the app * fs: support read-only files backed with GetBlockAddress() on fx-CG * kernel: SH4- or G-III-specific linker scripts? +* render: Properly document bopti fx. Also make it faster maybe? Future directions: * Audio playback using TSWilliamson's libsnd method diff --git a/include/gint/display-fx.h b/include/gint/display-fx.h index 7c7d7db..3835986 100644 --- a/include/gint/display-fx.h +++ b/include/gint/display-fx.h @@ -61,6 +61,12 @@ typedef enum } color_t; +/* Profiles: + 0: MONO (1 layer: color) + 1: ALPHA (2 layers: color, alpha) + 2: GRAY (2 layers: light, dark) + 3: GRAY_ALPHA (3 layers: light, dark, alpha) */ + //--- // Image rendering (bopti) //--- @@ -83,10 +89,16 @@ typedef struct uint height :12; /* Raw layer data */ - uint8_t data[]; + uint8_t *data; } GPACKED(4) bopti_image_t; +/* Number of layers in the image. */ +GINLINE static int image_layer_count(int profile) +{ + return profile + (profile <= 1); +} + #ifdef __cplusplus } #endif diff --git a/src/render-fx/bopti.c b/src/render-fx/bopti.c index 460e88c..51a7f3d 100644 --- a/src/render-fx/bopti.c +++ b/src/render-fx/bopti.c @@ -164,8 +164,7 @@ void bopti_render(bopti_image_t const *img, struct rbox *rbox, uint32_t *v1, masks(rbox->visual_x, rbox->visual_x + rbox->width - 1, vm); /* Number of layers per profile */ - static const int layer_count[] = { 1, 2, 2, 3 }; - int layers = layer_count[img->profile]; + int layers = image_layer_count(img->profile); /* For each pair of consecutive VRAM elements involved, create a mask from the intersection of the standard vram mask with the shift-mask @@ -222,7 +221,7 @@ void bopti_render_scsp(bopti_image_t const *img, struct rbox *rbox, (0xffffffff << (32 - rbox->width)) >> (rbox->visual_x & 31); /* Number of layers */ - int layers = img->profile - (img->profile >> 1) + 1; + int layers = image_layer_count(img->profile); /* Number of longwords to skip between rows of [img] */ int img_stride = ((img->width + 31) >> 5) * layers;