Skip to content

Commit

Permalink
Merge pull request #156 from bigclownlabs/lcd-draw-image
Browse files Browse the repository at this point in the history
Add image drawing
  • Loading branch information
blavka committed Nov 27, 2017
2 parents 0928e5a + af914f6 commit 202479c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bcl/inc/bc_image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#ifndef _BC_IMAGE
#define _BC_IMAGE

#include <bc_common.h>

typedef struct {
const uint8_t *data;
uint16_t width;
uint16_t height;
uint8_t dataSize;
} bc_image_t;

#endif // _BC_IMAGE
8 changes: 8 additions & 0 deletions bcl/inc/bc_module_lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


#include <bc_font_common.h>
#include <bc_image.h>
#include <bc_led.h>
#include <bc_button.h>

Expand Down Expand Up @@ -163,6 +164,13 @@ void bc_module_lcd_draw_rectangle(int x0, int y0, int x1, int y1, bool color);

void bc_module_lcd_draw_circle(int x0, int y0, int radius, bool color);

//! @brief Lcd draw image
//! @param[in] left Pixels from left edge
//! @param[in] top Pixels from top edge
//! @param[in] img Pointer to the image

void bc_module_lcd_draw_image(int left, int top, const bc_image_t *img);

//void bc_module_lcd_draw(const uint8_t *frame, uint8_t width, uint8_t height); // In pixels
//void bc_module_lcd_printf(uint8_t line, /*uint8_t size, font, */const uint8_t *string/*, ...*/);

Expand Down
3 changes: 3 additions & 0 deletions bcl/inc/bcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
#include <bc_data_stream.h>
#include <bc_flood_detector.h>
#include <bc_pulse_counter.h>
#include <bc_font_common.h>
#include <bc_image.h>


//! @mainpage Overview
//! Here you will find all the documented firmware SDK APIs.
Expand Down
25 changes: 25 additions & 0 deletions bcl/src/bc_module_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,31 @@ void bc_module_lcd_draw_circle(int x0, int y0, int radius, bool color)
}
}

void bc_module_lcd_draw_image(int left, int top, const bc_image_t *img)
{
uint8_t line;
uint8_t row;
uint8_t bytes_per_row = img->width / 8;

if(img->width % 8 != 0)
{
bytes_per_row++;
}

bc_tick_t start = bc_tick_get();

for (row = 0; row < img->height; row++) {
for (line = 0; line < img->width; line++) {
uint32_t byte_offset = line / 8 + row * bytes_per_row;
uint32_t bit = line % 8;
bc_module_lcd_draw_pixel(line + left, row + top, (img->data[byte_offset]) & (1 << bit));
}
}
volatile bc_tick_t duration = bc_tick_get() - start;
(void)duration;

}

/*
Framebuffer format for updating multiple lines, ideal for later DMA TX:
Expand Down

0 comments on commit 202479c

Please sign in to comment.