From a50119daf92b52951c3a68fe70d8d5bf548adf55 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 3 Aug 2025 03:25:59 -0400 Subject: libgfx: draw: Add gfx_plot_point() pixel plotting Implement mechanism that allows one to plot pixels on the screen with a specific color at specific x/y coordinates. Example: -- struct gfx_point p = { .x = 150, .y = 200, .color = GFX_GREEN }; /* Draw green point at (150,200) */ gfx_plot_point(&ctx, &p); -- Signed-off-by: Ian Moffett --- lib/libgfx/src/draw.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib/libgfx/src/draw.c') diff --git a/lib/libgfx/src/draw.c b/lib/libgfx/src/draw.c index 8280f8a..9ef8630 100644 --- a/lib/libgfx/src/draw.c +++ b/lib/libgfx/src/draw.c @@ -95,6 +95,39 @@ gfx_draw_square(struct gfx_ctx *ctx, const struct gfx_shape *shape) return 0; } +/* + * Plot a single pixel (aka point) onto + * the screen. + * + * @ctx: The graphics context pointer + * @point: Point to plot + * + * Returns 0 on success, otherwise a less + * than zero value. + */ +int +gfx_plot_point(struct gfx_ctx *ctx, const struct gfx_point *point) +{ + uint32_t index; + + if (ctx == NULL || point == NULL) { + return -EINVAL; + } + + /* + * Is this even a valid point on the screen for + * us to plot on? + */ + if (gfx_pixel_bounds(ctx, point->x, point->y) < 0) { + return -1; + } + + /* Plot it !! */ + index = gfx_io_index(ctx, point->x, point->y); + ctx->io[index] = point->rgb; + return 0; +} + /* * Draw a shape onto the screen * -- cgit v1.2.3