Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
color_dither.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
11
12#ifndef ZEPHYR_INCLUDE_DRIVERS_DISPLAY_COLOR_DITHER_H_
13#define ZEPHYR_INCLUDE_DRIVERS_DISPLAY_COLOR_DITHER_H_
14
95
97#include <zephyr/sys/util.h>
98
99#ifdef __cplusplus
100extern "C" {
101#endif
103
109struct display_color_dither_rgb_error {
110 int16_t r;
111 int16_t g;
112 int16_t b;
113};
114
115#if defined(CONFIG_DISPLAY_COLOR_DITHER_DEFAULT_RGB888)
116#define COLOR_DITHER_DEFAULT_FMT PIXEL_FORMAT_RGB_888
117#elif defined(CONFIG_DISPLAY_COLOR_DITHER_DEFAULT_RGB565)
118#define COLOR_DITHER_DEFAULT_FMT PIXEL_FORMAT_RGB_565
119#else
120#define COLOR_DITHER_DEFAULT_FMT PIXEL_FORMAT_I_4
121#endif
122
123#define COLOR_DITHER_I4_BYTES(w, h) (DIV_ROUND_UP((w), 2U) * (h))
124
125/*
126 * Per-instance row buffers for the error-diffusion algorithms only.
127 */
128#if defined(CONFIG_DISPLAY_COLOR_DITHER_ALGORITHM_ATKINSON)
129#define COLOR_DITHER_ERRDIFF_NROWS 3
130#elif defined(CONFIG_DISPLAY_COLOR_DITHER_ALGORITHM_FLOYD_STEINBERG)
131#define COLOR_DITHER_ERRDIFF_NROWS 2
132#else
133#define COLOR_DITHER_ERRDIFF_NROWS 0
134#endif
135
136#if COLOR_DITHER_ERRDIFF_NROWS > 0
137#define COLOR_DITHER_ERRDIFF_LEN(w) ((w) + 2U)
138#define COLOR_DITHER_ERRDIFF_ROW(tag) color_dither_errdiff_row_##tag
139
140#define COLOR_DITHER_ERRDIFF_DEFINE(tag, w) \
141 static struct display_color_dither_rgb_error COLOR_DITHER_ERRDIFF_ROW( \
142 tag)[COLOR_DITHER_ERRDIFF_NROWS][COLOR_DITHER_ERRDIFF_LEN(w)]
143#define COLOR_DITHER_ERRDIFF_R0(tag) COLOR_DITHER_ERRDIFF_ROW(tag)[0]
144#define COLOR_DITHER_ERRDIFF_R1(tag) COLOR_DITHER_ERRDIFF_ROW(tag)[1]
145#if COLOR_DITHER_ERRDIFF_NROWS >= 3
146#define COLOR_DITHER_ERRDIFF_R2(tag) COLOR_DITHER_ERRDIFF_ROW(tag)[2]
147#else
148#define COLOR_DITHER_ERRDIFF_R2(tag) NULL
149#endif
150
151#else /* no error-diffusion algorithm selected */
152#define COLOR_DITHER_ERRDIFF_DEFINE(tag, w)
153#define COLOR_DITHER_ERRDIFF_LEN(w) 0U
154#define COLOR_DITHER_ERRDIFF_R0(tag) NULL
155#define COLOR_DITHER_ERRDIFF_R1(tag) NULL
156#define COLOR_DITHER_ERRDIFF_R2(tag) NULL
157#endif
158
160
172#if defined(CONFIG_DISPLAY_COLOR_DITHER)
180 enum display_pixel_format input_format;
182 uint8_t *converted_buf;
184 size_t converted_buf_size;
192 struct display_color_dither_rgb_error *err_rows[3];
194 size_t err_row_len;
195#elif defined(CONFIG_CPP)
196 /* An empty struct is not valid C, and compilers that accept it give
197 * it size 0 while C++ gives 1. Keep a byte so both languages agree.
198 */
199 uint8_t c;
200#endif /* CONFIG_DISPLAY_COLOR_DITHER */
201};
202
203#if defined(CONFIG_DISPLAY_COLOR_DITHER) || defined(__DOXYGEN__)
204
216#define DISPLAY_COLOR_DITHER_DEFINE(inst) \
217 static uint8_t color_dither_buf_##inst[COLOR_DITHER_I4_BYTES(DT_INST_PROP(inst, width), \
218 DT_INST_PROP(inst, height))]; \
219 COLOR_DITHER_ERRDIFF_DEFINE(inst, DT_INST_PROP(inst, width))
220
232#define DISPLAY_COLOR_DITHER_INIT(inst) \
233 { \
234 .input_format = COLOR_DITHER_DEFAULT_FMT, \
235 .converted_buf = color_dither_buf_##inst, \
236 .converted_buf_size = sizeof(color_dither_buf_##inst), \
237 .err_rows = \
238 { \
239 COLOR_DITHER_ERRDIFF_R0(inst), \
240 COLOR_DITHER_ERRDIFF_R1(inst), \
241 COLOR_DITHER_ERRDIFF_R2(inst), \
242 }, \
243 .err_row_len = COLOR_DITHER_ERRDIFF_LEN(DT_INST_PROP(inst, width)), \
244 }
245
271 const struct display_buffer_descriptor **desc, const void **buf,
272 struct display_buffer_descriptor *scratch);
273
292 struct display_capabilities *caps);
293
315 enum display_pixel_format pf);
316
329 enum display_pixel_format current_pixel_format);
330
331#else /* !CONFIG_DISPLAY_COLOR_DITHER */
332
334
335#define DISPLAY_COLOR_DITHER_DEFINE(inst)
336#define DISPLAY_COLOR_DITHER_INIT(inst) \
337 { \
338 }
339
340static inline int display_color_dither_prepare(const struct device *dev,
342 const struct display_buffer_descriptor **desc,
343 const void **buf,
344 struct display_buffer_descriptor *scratch)
345{
346 (void)dev;
347 (void)state;
348 (void)desc;
349 (void)buf;
350 (void)scratch;
351
352 return 0;
353}
354
356 struct display_capabilities *caps)
357{
358 (void)state;
359 (void)caps;
360}
361
363 enum display_pixel_format pf)
364{
365 (void)state;
366
367 return pf == PIXEL_FORMAT_I_4 ? 0 : -ENOTSUP;
368}
369
371 enum display_pixel_format current_pixel_format)
372{
373 (void)state;
374 (void)current_pixel_format;
375
376 return false;
377}
378
380
381#endif /* CONFIG_DISPLAY_COLOR_DITHER */
382
383#ifdef __cplusplus
384}
385#endif
386
390
391#endif /* ZEPHYR_INCLUDE_DRIVERS_DISPLAY_COLOR_DITHER_H_ */
workaround assembler barfing for ST r
Definition asm-macro-32-bit-gnu.h:27
Main header file for display driver API.
int display_color_dither_set_input_format(struct display_color_dither_state *state, enum display_pixel_format pf)
Select the helper input pixel format.
bool display_color_dither_is_active(const struct display_color_dither_state *state, enum display_pixel_format current_pixel_format)
Report whether the helper is actively converting input to native I_4.
void display_color_dither_patch_caps(struct display_color_dither_state *state, struct display_capabilities *caps)
Add helper-managed RGB formats to display capabilities.
int display_color_dither_prepare(const struct device *dev, struct display_color_dither_state *state, const struct display_buffer_descriptor **desc, const void **buf, struct display_buffer_descriptor *scratch)
Prepare a write buffer for a PIXEL_FORMAT_I_4 native path.
display_pixel_format
Display pixel formats.
Definition display.h:49
@ PIXEL_FORMAT_I_4
4-bit indexed color format with 2 pixels packed per byte.
Definition display.h:232
#define ENOTSUP
Unsupported value.
Definition errno.h:115
state
Definition parser_state.h:29
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__INT16_TYPE__ int16_t
Definition stdint.h:73
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
Structure to describe display data buffer layout.
Definition display.h:373
Structure holding display capabilities.
Definition display.h:351
Runtime state owned by the color dithering helper for one display device instance.
Definition color_dither.h:171
Misc utilities.