Added support for cut off bitmaps
This commit is contained in:
parent
cbc18d15e9
commit
672a5e9502
47
st7735.c
47
st7735.c
|
@ -308,29 +308,36 @@ void st7735_fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t color
|
||||||
|
|
||||||
|
|
||||||
void st7735_draw_bitmap(uint8_t x, uint8_t y, PGM_P bitmap) {
|
void st7735_draw_bitmap(uint8_t x, uint8_t y, PGM_P bitmap) {
|
||||||
if(x >= st7735_width || y >= st7735_height) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t w = pgm_read_word(bitmap);
|
uint8_t w = pgm_read_word(bitmap);
|
||||||
bitmap += 2;
|
bitmap += 2;
|
||||||
uint8_t h = pgm_read_word(bitmap);
|
uint8_t h = pgm_read_word(bitmap);
|
||||||
bitmap += 2;
|
bitmap += 2;
|
||||||
|
uint8_t max_x = x + w - 1;
|
||||||
|
uint8_t max_y = y + h - 1;
|
||||||
|
|
||||||
if((x + w - 1) >= st7735_width) {
|
if(x >= st7735_width || y >= st7735_height) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if((y + h - 1) >= st7735_height) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
st7735_set_addr_win(x, y, x + w - 1, y + h - 1);
|
if(max_x >= st7735_width) {
|
||||||
|
max_x = st7735_width - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(max_y >= st7735_height) {
|
||||||
|
max_y = st7735_height - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
st7735_set_addr_win(x, y, max_x, max_y);
|
||||||
|
|
||||||
st7735_set_rs();
|
st7735_set_rs();
|
||||||
spi_unset_cs();
|
spi_unset_cs();
|
||||||
|
|
||||||
for(uint8_t i = 0; i < h; i++) {
|
for(uint8_t i = 0; i < h; i++) {
|
||||||
for(uint8_t j = 0; j < w; j++) {
|
for(uint8_t j = 0; j < w; j++) {
|
||||||
|
if((x + j) >= st7735_width || (y + i) >= st7735_height) {
|
||||||
|
bitmap += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
uint16_t color = pgm_read_word(bitmap);
|
uint16_t color = pgm_read_word(bitmap);
|
||||||
st7735_write_color(color);
|
st7735_write_color(color);
|
||||||
bitmap += 2;
|
bitmap += 2;
|
||||||
|
@ -343,19 +350,22 @@ void st7735_draw_bitmap(uint8_t x, uint8_t y, PGM_P bitmap) {
|
||||||
void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_set, uint16_t color_unset) {
|
void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_set, uint16_t color_unset) {
|
||||||
uint8_t w = pgm_read_byte(bitmap++);
|
uint8_t w = pgm_read_byte(bitmap++);
|
||||||
uint8_t h = pgm_read_byte(bitmap++);
|
uint8_t h = pgm_read_byte(bitmap++);
|
||||||
|
uint8_t max_x = x + w - 1;
|
||||||
|
uint8_t max_y = y + h - 1;
|
||||||
|
|
||||||
if(x >= st7735_width || y >= st7735_height) {
|
if(x >= st7735_width || y >= st7735_height) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((x + w - 1) >= st7735_width) {
|
if(max_x >= st7735_width) {
|
||||||
return;
|
max_x = st7735_width - 1;
|
||||||
}
|
|
||||||
if((y + h - 1) >= st7735_height) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
st7735_set_addr_win(x, y, x + w - 1, y + h - 1);
|
if(max_y >= st7735_height) {
|
||||||
|
max_y = st7735_height - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
st7735_set_addr_win(x, y, max_x, max_y);
|
||||||
|
|
||||||
st7735_set_rs();
|
st7735_set_rs();
|
||||||
spi_unset_cs();
|
spi_unset_cs();
|
||||||
|
@ -365,9 +375,13 @@ void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_
|
||||||
for(uint8_t i = 0; i < h; i++) {
|
for(uint8_t i = 0; i < h; i++) {
|
||||||
for(uint8_t j = 0; j < w; j++) {
|
for(uint8_t j = 0; j < w; j++) {
|
||||||
if(bit_pos % 8 == 0) {
|
if(bit_pos % 8 == 0) {
|
||||||
byte = pgm_read_byte(bitmap++);
|
byte = pgm_read_byte(bitmap++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((x + j) >= st7735_width || (y + i) >= st7735_height) {
|
||||||
|
bit_pos++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(byte & (1 << (bit_pos % 8))) {
|
if(byte & (1 << (bit_pos % 8))) {
|
||||||
st7735_write_color(color_set);
|
st7735_write_color(color_set);
|
||||||
}
|
}
|
||||||
|
@ -379,5 +393,4 @@ void st7735_draw_mono_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint16_t color_
|
||||||
}
|
}
|
||||||
|
|
||||||
spi_set_cs();
|
spi_set_cs();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue