Skip to content

Commit c50a48a

Browse files
Finomniskartben
authored andcommitted
display: sdl: add CONFIG_SDL_DISPLAY_COLOR_TINT
Allows the SDL display to be tinted in a specific color, to allow the simulation of monochrome colored displays like `R8` (`L8` + tint `0xff0000`) Signed-off-by: Martin Stumpf <finomnis@gmail.com>
1 parent 2be724d commit c50a48a

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

doc/releases/release-notes-4.3.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ New APIs and options
8787

8888
* Display
8989

90-
* Added new pixel format :c:enum:`PIXEL_FORMAT_AL_88`
90+
* :c:enumerator:`PIXEL_FORMAT_AL_88`
9191

9292
* SDL
9393

9494
* :kconfig:option:`CONFIG_SDL_DISPLAY_DEFAULT_PIXEL_FORMAT_AL_88`
95+
* :kconfig:option:`CONFIG_SDL_DISPLAY_COLOR_TINT`
9596

9697
* Logging:
9798

drivers/display/Kconfig.sdl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,21 @@ config SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_1
8484
default 0xcccccc
8585
help
8686
The color of the odd cells in the transparency grid.
87+
Byte order: RGB_888
8788

8889
config SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_2
8990
hex "Transparency grid cell color 2"
9091
default 0xbbbbbb
9192
help
9293
The color of the even cells in the transparency grid.
94+
Byte order: RGB_888
95+
96+
config SDL_DISPLAY_COLOR_TINT
97+
hex "Color filter applied on top of the display data"
98+
default 0xffffff
99+
help
100+
Can be used to simulate colored monochrome displays, like R8 (L8 + tint 0xff0000).
101+
Byte order: RGB_888
93102

94103
config SDL_DISPLAY_THREAD_PRIORITY
95104
int "SDL display thread priority"

drivers/display/display_sdl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ static void exec_sdl_task(const struct device *dev, const struct sdl_display_tas
8989
disp_data->mutex, disp_data->texture,
9090
disp_data->background_texture, disp_data->buf,
9191
disp_data->display_on,
92-
task->write.desc->frame_incomplete);
92+
task->write.desc->frame_incomplete,
93+
CONFIG_SDL_DISPLAY_COLOR_TINT);
9394
break;
9495
case SDL_BLANKING_OFF:
9596
sdl_display_blanking_off_bottom(disp_data->renderer, disp_data->texture,
96-
disp_data->background_texture);
97+
disp_data->background_texture,
98+
CONFIG_SDL_DISPLAY_COLOR_TINT);
9799
break;
98100
case SDL_BLANKING_ON:
99101
sdl_display_blanking_on_bottom(disp_data->renderer);

drivers/display/display_sdl_bottom.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int sdl_display_init_bottom(uint16_t height, uint16_t width, uint16_t zoom_pct,
109109
void sdl_display_write_bottom(const uint16_t height, const uint16_t width, const uint16_t x,
110110
const uint16_t y, void *renderer, void *mutex, void *texture,
111111
void *background_texture, uint8_t *buf, bool display_on,
112-
bool frame_incomplete)
112+
bool frame_incomplete, uint32_t color_tint)
113113
{
114114
SDL_Rect rect;
115115
int err;
@@ -130,7 +130,12 @@ void sdl_display_write_bottom(const uint16_t height, const uint16_t width, const
130130
if (display_on && !frame_incomplete) {
131131
SDL_RenderClear(renderer);
132132
SDL_RenderCopy(renderer, background_texture, NULL, NULL);
133+
SDL_SetTextureColorMod(texture,
134+
(color_tint >> 16) & 0xff,
135+
(color_tint >> 8) & 0xff,
136+
color_tint & 0xff);
133137
SDL_RenderCopy(renderer, texture, NULL, NULL);
138+
SDL_SetTextureColorMod(texture, 255, 255, 255);
134139
SDL_RenderPresent(renderer);
135140
}
136141

@@ -171,11 +176,17 @@ int sdl_display_read_bottom(const uint16_t height, const uint16_t width,
171176
return err;
172177
}
173178

174-
void sdl_display_blanking_off_bottom(void *renderer, void *texture, void *background_texture)
179+
void sdl_display_blanking_off_bottom(void *renderer, void *texture, void *background_texture,
180+
uint32_t color_tint)
175181
{
176182
SDL_RenderClear(renderer);
177183
SDL_RenderCopy(renderer, background_texture, NULL, NULL);
184+
SDL_SetTextureColorMod(texture,
185+
(color_tint >> 16) & 0xff,
186+
(color_tint >> 8) & 0xff,
187+
color_tint & 0xff);
178188
SDL_RenderCopy(renderer, texture, NULL, NULL);
189+
SDL_SetTextureColorMod(texture, 255, 255, 255);
179190
SDL_RenderPresent(renderer);
180191
}
181192

drivers/display/display_sdl_bottom.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ int sdl_display_init_bottom(uint16_t height, uint16_t width, uint16_t zoom_pct,
2929
void sdl_display_write_bottom(const uint16_t height, const uint16_t width, const uint16_t x,
3030
const uint16_t y, void *renderer, void *mutex, void *texture,
3131
void *background_texture, uint8_t *buf, bool display_on,
32-
bool frame_incomplete);
32+
bool frame_incomplete, uint32_t color_tint);
3333
int sdl_display_read_bottom(const uint16_t height, const uint16_t width, const uint16_t x,
3434
const uint16_t y, void *renderer, void *buf, uint16_t pitch,
3535
void *mutex, void *texture, void *read_texture);
36-
void sdl_display_blanking_off_bottom(void *renderer, void *texture, void *background_texture);
36+
void sdl_display_blanking_off_bottom(void *renderer, void *texture, void *background_texture,
37+
uint32_t color_tint);
3738
void sdl_display_blanking_on_bottom(void *renderer);
3839
void sdl_display_cleanup_bottom(void **window, void **renderer, void **mutex, void **texture,
3940
void **read_texture, void **background_texture);

0 commit comments

Comments
 (0)