summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libgfx/include/libgfx/draw.h1
-rw-r--r--lib/libgfx/src/draw.c28
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/libgfx/include/libgfx/draw.h b/lib/libgfx/include/libgfx/draw.h
index 9f56f6c..96fe35a 100644
--- a/lib/libgfx/include/libgfx/draw.h
+++ b/lib/libgfx/include/libgfx/draw.h
@@ -103,6 +103,7 @@ struct gfx_point {
int gfx_draw_shape(struct gfx_ctx *ctx, const struct gfx_shape *shape);
int gfx_plot_point(struct gfx_ctx *ctx, const struct gfx_point *point);
+color_t gfx_get_pix(struct gfx_ctx *ctx, uint32_t x, uint32_t y);
__always_inline static inline size_t
gfx_io_index(struct gfx_ctx *ctx, scrpos_t x, scrpos_t y)
diff --git a/lib/libgfx/src/draw.c b/lib/libgfx/src/draw.c
index 9ef8630..784110a 100644
--- a/lib/libgfx/src/draw.c
+++ b/lib/libgfx/src/draw.c
@@ -129,6 +129,34 @@ gfx_plot_point(struct gfx_ctx *ctx, const struct gfx_point *point)
}
/*
+ * Grab the RGB value of a single pixel on
+ * the scren.
+ *
+ * @ctx: Graphics context pointer
+ * @x: X position to sample
+ * @y: Y position to sample
+ */
+color_t
+gfx_get_pix(struct gfx_ctx *ctx, uint32_t x, uint32_t y)
+{
+ const color_t ERROR_COLOR = GFX_BLACK;
+ uint32_t index;
+
+ /* The 'ctx' argument is required */
+ if (ctx == NULL) {
+ return ERROR_COLOR;
+ }
+
+ /* Are we within bounds of the screen */
+ if (gfx_pixel_bounds(ctx, x, y) < 0) {
+ return ERROR_COLOR;
+ }
+
+ index = gfx_io_index(ctx, x, y);
+ return ctx->io[index];
+}
+
+/*
* Draw a shape onto the screen
*
* @ctx: libgfx graphics context