Zephyr API Documentation 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 /* C++ does not allow empty structs, add an extra 1 byte. */
197 uint8_t c;
198#endif /* CONFIG_DISPLAY_COLOR_DITHER */
199};
200
201#if defined(CONFIG_DISPLAY_COLOR_DITHER) || defined(__DOXYGEN__)
202
214#define DISPLAY_COLOR_DITHER_DEFINE(inst) \
215 static uint8_t color_dither_buf_##inst[COLOR_DITHER_I4_BYTES(DT_INST_PROP(inst, width), \
216 DT_INST_PROP(inst, height))]; \
217 COLOR_DITHER_ERRDIFF_DEFINE(inst, DT_INST_PROP(inst, width))
218
230#define DISPLAY_COLOR_DITHER_INIT(inst) \
231 { \
232 .input_format = COLOR_DITHER_DEFAULT_FMT, \
233 .converted_buf = color_dither_buf_##inst, \
234 .converted_buf_size = sizeof(color_dither_buf_##inst), \
235 .err_rows = \
236 { \
237 COLOR_DITHER_ERRDIFF_R0(inst), \
238 COLOR_DITHER_ERRDIFF_R1(inst), \
239 COLOR_DITHER_ERRDIFF_R2(inst), \
240 }, \
241 .err_row_len = COLOR_DITHER_ERRDIFF_LEN(DT_INST_PROP(inst, width)), \
242 }
243
269 const struct display_buffer_descriptor **desc, const void **buf,
270 struct display_buffer_descriptor *scratch);
271
290 struct display_capabilities *caps);
291
313 enum display_pixel_format pf);
314
327 enum display_pixel_format current_pixel_format);
328
329#else /* !CONFIG_DISPLAY_COLOR_DITHER */
330
332
333#define DISPLAY_COLOR_DITHER_DEFINE(inst)
334#define DISPLAY_COLOR_DITHER_INIT(inst) \
335 { \
336 }
337
338static inline int display_color_dither_prepare(const struct device *dev,
340 const struct display_buffer_descriptor **desc,
341 const void **buf,
342 struct display_buffer_descriptor *scratch)
343{
344 (void)dev;
345 (void)state;
346 (void)desc;
347 (void)buf;
348 (void)scratch;
349
350 return 0;
351}
352
354 struct display_capabilities *caps)
355{
356 (void)state;
357 (void)caps;
358}
359
361 enum display_pixel_format pf)
362{
363 (void)state;
364
365 return pf == PIXEL_FORMAT_I_4 ? 0 : -ENOTSUP;
366}
367
369 enum display_pixel_format current_pixel_format)
370{
371 (void)state;
372 (void)current_pixel_format;
373
374 return false;
375}
376
378
379#endif /* CONFIG_DISPLAY_COLOR_DITHER */
380
381#ifdef __cplusplus
382}
383#endif
384
388
389#endif /* ZEPHYR_INCLUDE_DRIVERS_DISPLAY_COLOR_DITHER_H_ */
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:114
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:513
Structure to describe display data buffer layout.
Definition display.h:350
Structure holding display capabilities.
Definition display.h:330
Runtime state owned by the color dithering helper for one display device instance.
Definition color_dither.h:171
Misc utilities.