From 9bf41b7c331a95477d8a4c095b7802f7a2f8d913 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 6 Aug 2014 06:23:25 +0200 Subject: framebuffer.c: line drawing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/framebuffer.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/framebuffer.h | 24 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+) (limited to 'src') diff --git a/src/framebuffer.c b/src/framebuffer.c index 2418934..b830d6e 100644 --- a/src/framebuffer.c +++ b/src/framebuffer.c @@ -161,9 +161,55 @@ void fb_fill_rectangle(framebuffer_t* restrict fb, uint32_t colour, for (y_ = y; y_ != y2; y_++, mem += fb->line_length) for (x_ = x1; x_ != x2; x_ += fb->bytes_per_pixel) + { + int8_t* pixel = mem + x_; + *(uint32_t*)pixel = colour; + } +} + + +/** + * Draw a horizontal line segment on a framebuffer + * + * @param fb The framebuffer + * @param colour The colour to use when drawing the rectangle + * @param x The starting pixel on the X axis for the line segment + * @param y The starting pixel on the Y axis for the line segment + * @param length The length of the line segment, in pixels + */ +void fb_draw_horizontal_line(framebuffer_t* restrict fb, uint32_t colour, + uint32_t x, uint32_t y, uint32_t length) +{ + int8_t* mem = fb->mem + y * fb->line_length; + size_t x1 = x * fb->bytes_per_pixel; + size_t x2 = (x + length) * fb->bytes_per_pixel; + size_t x_; + + for (x_ = x1; x_ != x2; x_ += fb->bytes_per_pixel) { int8_t* pixel = mem + x_; *(uint32_t*)pixel = colour; } } + +/** + * Draw a vertical line segment on a framebuffer + * + * @param fb The framebuffer + * @param colour The colour to use when drawing the rectangle + * @param x The starting pixel on the X axis for the line segment + * @param y The starting pixel on the Y axis for the line segment + * @param length The length of the line segment, in pixels + */ +void fb_draw_vertical_line(framebuffer_t* restrict fb, uint32_t colour, + uint32_t x, uint32_t y, uint32_t length) +{ + int8_t* mem = fb->mem + y * fb->line_length + x * fb->bytes_per_pixel; + size_t y2 = y + length; + size_t y_; + + for (y_ = y; y_ != y2; y_++, mem += fb->line_length) + *(uint32_t*)mem = colour; +} + diff --git a/src/framebuffer.h b/src/framebuffer.h index 701ccea..7ef1fed 100644 --- a/src/framebuffer.h +++ b/src/framebuffer.h @@ -108,6 +108,30 @@ uint32_t fb_colour(int red, int green, int blue); void fb_fill_rectangle(framebuffer_t* restrict fb, uint32_t colour, uint32_t x, uint32_t y, uint32_t width, uint32_t height); +/** + * Draw a horizontal line segment on a framebuffer + * + * @param fb The framebuffer + * @param colour The colour to use when drawing the rectangle + * @param x The starting pixel on the X axis for the line segment + * @param y The starting pixel on the Y axis for the line segment + * @param length The length of the line segment, in pixels + */ +void fb_draw_horizontal_line(framebuffer_t* restrict fb, uint32_t colour, + uint32_t x, uint32_t y, uint32_t length); + +/** + * Draw a vertical line segment on a framebuffer + * + * @param fb The framebuffer + * @param colour The colour to use when drawing the rectangle + * @param x The starting pixel on the X axis for the line segment + * @param y The starting pixel on the Y axis for the line segment + * @param length The length of the line segment, in pixels + */ +void fb_draw_vertical_line(framebuffer_t* restrict fb, uint32_t colour, + uint32_t x, uint32_t y, uint32_t length); + #endif -- cgit v1.2.3-70-g09d2