12#ifndef ZEPHYR_INCLUDE_DRIVERS_DISPLAY_COLOR_DITHER_H_
13#define ZEPHYR_INCLUDE_DRIVERS_DISPLAY_COLOR_DITHER_H_
109struct display_color_dither_rgb_error {
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
120#define COLOR_DITHER_DEFAULT_FMT PIXEL_FORMAT_I_4
123#define COLOR_DITHER_I4_BYTES(w, h) (DIV_ROUND_UP((w), 2U) * (h))
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
133#define COLOR_DITHER_ERRDIFF_NROWS 0
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
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]
148#define COLOR_DITHER_ERRDIFF_R2(tag) NULL
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
172#if defined(CONFIG_DISPLAY_COLOR_DITHER)
184 size_t converted_buf_size;
192 struct display_color_dither_rgb_error *err_rows[3];
195#elif defined(CONFIG_CPP)
201#if defined(CONFIG_DISPLAY_COLOR_DITHER) || defined(__DOXYGEN__)
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))
230#define DISPLAY_COLOR_DITHER_INIT(inst) \
232 .input_format = COLOR_DITHER_DEFAULT_FMT, \
233 .converted_buf = color_dither_buf_##inst, \
234 .converted_buf_size = sizeof(color_dither_buf_##inst), \
237 COLOR_DITHER_ERRDIFF_R0(inst), \
238 COLOR_DITHER_ERRDIFF_R1(inst), \
239 COLOR_DITHER_ERRDIFF_R2(inst), \
241 .err_row_len = COLOR_DITHER_ERRDIFF_LEN(DT_INST_PROP(inst, width)), \
333#define DISPLAY_COLOR_DITHER_DEFINE(inst)
334#define DISPLAY_COLOR_DITHER_INIT(inst) \
372 (void)current_pixel_format;
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