Allow blit8BitWidthBitmap draw bitmap width bigger then 8px

Allow draw in cell any type bitmap

Remove code doubles
pull/4/head
DiSlord 5 years ago
parent 1518e4bfd8
commit 174be32ec2

@ -601,9 +601,10 @@ void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height
const uint8_t *bitmap) const uint8_t *bitmap)
{ {
uint16_t *buf = spi_buffer; uint16_t *buf = spi_buffer;
uint8_t bits = 0;
for (uint16_t c = 0; c < height; c++) { for (uint16_t c = 0; c < height; c++) {
uint8_t bits = *bitmap++;
for (uint16_t r = 0; r < width; r++) { for (uint16_t r = 0; r < width; r++) {
if ((r&7) == 0) bits = *bitmap++;
*buf++ = (0x80 & bits) ? foreground_color : background_color; *buf++ = (0x80 & bits) ? foreground_color : background_color;
bits <<= 1; bits <<= 1;
} }

105
plot.c

@ -1704,56 +1704,21 @@ request_to_draw_cells_behind_numeric_input(void)
} }
static int static int
cell_drawchar(uint8_t ch, int x, int y) cell_blit_char_bitmap(int x, int y, uint16_t w, uint16_t h, const uint8_t *char_buf)
{ {
uint8_t bits; if (x <= -w)
int c, r, ch_size; return w;
const uint8_t *char_buf = FONT_GET_DATA(ch); uint8_t bits = 0;
ch_size = FONT_GET_WIDTH(ch); int r;
// if (y <= -FONT_GET_HEIGHT || y >= CELLHEIGHT || x <= -ch_size || x >= CELLWIDTH) for (; y < h+y; y++) {
// return ch_size; for (r = 0; r < w; r++) {
if (x <= -ch_size) if ((r&7)==0) bits = *char_buf++;
return ch_size; if (y >= 0 && x+r >= 0 && y < CELLHEIGHT && x+r < CELLWIDTH && (0x80 & bits))
for (c = 0; c < FONT_GET_HEIGHT; c++) { cell_buffer[y*CELLWIDTH + x + r] = foreground_color;
bits = *char_buf++;
if ((y + c) < 0 || (y + c) >= CELLHEIGHT)
continue;
for (r = 0; r < ch_size; r++) {
if ((x+r) >= 0 && (x+r) < CELLWIDTH && (0x80 & bits))
cell_buffer[(y+c)*CELLWIDTH + (x+r)] = foreground_color;
bits <<= 1;
}
}
return ch_size;
}
static int
cell_drawchar_size(uint8_t ch, int x, int y, int size)
{
uint8_t bits;
int c, r, ch_size;
const uint8_t *char_buf = FONT_GET_DATA(ch);
ch_size = FONT_GET_WIDTH(ch);
// if (y <= -FONT_GET_HEIGHT || y >= CELLHEIGHT || x <= -ch_size || x >= CELLWIDTH)
// return ch_size;
if (x <= -ch_size*size)
return ch_size*size;
for (c = 0; c < FONT_GET_HEIGHT; c++) {
for (int i=0; i < size; i++) {
bits = *char_buf;
if ((y + c*size+i) < 0 || (y + c*size+i) >= CELLHEIGHT)
continue;
for (r = 0; r < ch_size; r++) {
for (int j = 0; j < size; j++) {
if ((x+r*size + j) >= 0 && (x+r*size+j) < CELLWIDTH && (0x80 & bits))
cell_buffer[(y+c*size+i)*CELLWIDTH + (x+r*size+j)] = foreground_color;
}
bits <<= 1; bits <<= 1;
} }
} }
char_buf++; return w;
}
return ch_size*size;
} }
void void
@ -1764,58 +1729,66 @@ cell_drawstring(char *str, int x, int y)
while (*str) { while (*str) {
if (x >= CELLWIDTH) if (x >= CELLWIDTH)
return; return;
x += cell_drawchar(*str++, x, y); uint8_t ch = *str++;
x += cell_blit_char_bitmap(x, y, FONT_GET_WIDTH(ch), FONT_GET_HEIGHT, FONT_GET_DATA(ch));
} }
} }
void void
cell_drawstring_size(char *str, int x, int y, int size) cell_drawstring_7x13(char *str, int x, int y)
{ {
if (y <= -FONT_GET_HEIGHT*2 || y >= CELLHEIGHT) if (y <= -bFONT_GET_HEIGHT || y >= CELLHEIGHT)
return; return;
while (*str) { while (*str) {
if (x >= CELLWIDTH) if (x >= CELLWIDTH)
return; return;
x += cell_drawchar_size(*str++, x, y, size); uint8_t ch = *str++;
x += cell_blit_char_bitmap(x, y, bFONT_GET_WIDTH(ch), bFONT_GET_HEIGHT, bFONT_GET_DATA(ch));
} }
} }
#if 0
static int static int
cell_draw_bchar(uint8_t ch, int x, int y) cell_drawchar_size(uint8_t ch, int x, int y, int size)
{ {
uint8_t bits; uint8_t bits;
int c, r, ch_size; int c, r, ch_size;
const uint8_t *char_buf = bFONT_GET_DATA(ch); const uint8_t *char_buf = FONT_GET_DATA(ch);
ch_size = bFONT_GET_WIDTH(ch); ch_size = FONT_GET_WIDTH(ch);
// if (y <= -FONT_GET_HEIGHT || y >= CELLHEIGHT || x <= -ch_size || x >= CELLWIDTH) // if (y <= -FONT_GET_HEIGHT || y >= CELLHEIGHT || x <= -ch_size || x >= CELLWIDTH)
// return ch_size; // return ch_size;
if (x <= -ch_size) if (x <= -ch_size*size)
return ch_size; return ch_size*size;
for (c = 0; c < bFONT_GET_HEIGHT; c++) { for (c = 0; c < FONT_GET_HEIGHT; c++) {
bits = *char_buf++; for (int i=0; i < size; i++) {
if ((y + c) < 0 || (y + c) >= CELLHEIGHT) bits = *char_buf;
if ((y + c*size+i) < 0 || (y + c*size+i) >= CELLHEIGHT)
continue; continue;
for (r = 0; r < ch_size; r++) { for (r = 0; r < ch_size; r++) {
if ((x+r) >= 0 && (x+r) < CELLWIDTH && (0x80 & bits)) for (int j = 0; j < size; j++) {
cell_buffer[(y+c)*CELLWIDTH + (x+r)] = foreground_color; if ((x+r*size + j) >= 0 && (x+r*size+j) < CELLWIDTH && (0x80 & bits))
cell_buffer[(y+c*size+i)*CELLWIDTH + (x+r*size+j)] = foreground_color;
}
bits <<= 1; bits <<= 1;
} }
} }
return ch_size; char_buf++;
}
return ch_size*size;
} }
void void
cell_drawstring_7x13(char *str, int x, int y) cell_drawstring_size(char *str, int x, int y, int size)
{ {
if (y <= -bFONT_GET_HEIGHT || y >= CELLHEIGHT) if (y <= -FONT_GET_HEIGHT*2 || y >= CELLHEIGHT)
return; return;
while (*str) { while (*str) {
if (x >= CELLWIDTH) if (x >= CELLWIDTH)
return; return;
x += cell_draw_bchar(*str++, x, y); x += cell_drawchar_size(*str++, x, y, size);
} }
} }
#endif
#ifdef __VNA__ #ifdef __VNA__
static void static void

Loading…
Cancel
Save

Powered by TurnKey Linux.