expo: Allow changing scene_img data

In some cases we want to change the image data used by a scene_img. Add
a function to handle this.

Adjust the BMP function to use a const for the data, since it is not
allowed to change it.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-05-24 09:41:10 -06:00
parent 872733ec11
commit 2b226cb9e7
5 changed files with 34 additions and 4 deletions

View File

@@ -1173,6 +1173,19 @@ void scene_highlight_first(struct scene *scn)
}
}
int scene_img_set_data(struct scene *scn, uint id, const void *data, int size)
{
struct scene_obj_img *img;
img = scene_obj_find(scn, id, SCENEOBJT_IMAGE);
if (!img)
return log_msg_ret("sid", -ENOENT);
img->data = data;
/* TODO: Consider using an abuf for the image */
return 0;
}
static int scene_obj_open(struct scene *scn, struct scene_obj *obj)
{
int ret;

View File

@@ -242,10 +242,10 @@ static void video_splash_align_axis(int *axis, unsigned long panel_size,
*axis = max(0, (int)axis_alignment);
}
void video_bmp_get_info(void *bmp_image, ulong *widthp, ulong *heightp,
void video_bmp_get_info(const void *bmp_image, ulong *widthp, ulong *heightp,
uint *bpixp)
{
struct bmp_image *bmp = bmp_image;
const struct bmp_image *bmp = bmp_image;
*widthp = get_unaligned_le32(&bmp->header.width);
*heightp = get_unaligned_le32(&bmp->header.height);

View File

@@ -368,7 +368,7 @@ static inline bool scene_obj_can_highlight(const struct scene_obj *obj)
*/
struct scene_obj_img {
struct scene_obj obj;
char *data;
const char *data;
};
/**
@@ -708,6 +708,17 @@ void scene_highlight_first(struct scene *scn);
*/
void scene_set_highlight_id(struct scene *scn, uint id);
/**
* scene_img_set_data() - Set the image data for an image object
*
* @scn: Scene to update
* @id: ID of existing image obejct
* @data: Image data to use
* @size: Size of image data
* Returns: 0 if OK, -ENOENT if @id is invalid
*/
int scene_img_set_data(struct scene *scn, uint id, const void *data, int size);
/**
* scene_set_open() - Set whether an item is open or not
*

View File

@@ -310,7 +310,7 @@ void video_sync_all(void);
* @heightp: Returns height in pixels
* @bpixp: Returns log2 of bits per pixel
*/
void video_bmp_get_info(void *bmp_image, ulong *widthp, ulong *heightp,
void video_bmp_get_info(const void *bmp_image, ulong *widthp, ulong *heightp,
uint *bpixp);
/**

View File

@@ -262,6 +262,7 @@ static int expo_object_attr(struct unit_test_state *uts)
struct expo *exp;
ulong start_mem;
char name[100];
char image[10];
ofnode node;
char *data;
int id;
@@ -305,6 +306,11 @@ static int expo_object_attr(struct unit_test_state *uts)
ut_assertok(expo_setup_theme(exp, node));
ut_asserteq(30, txt->gen.font_size);
/* try setting up a fake image */
strcpy(image, "wibble");
ut_assertok(scene_img_set_data(scn, OBJ_LOGO, image, sizeof(image)));
ut_asserteq_str("wibble", img->data);
expo_destroy(exp);
ut_assertok(ut_check_delta(start_mem));