Fixes #1987: first pixel not drawn by Lua lcd.drawLine(), bmpLoad() last column not loaded for some bitmap widths, gtests added (ported from master)
This commit is contained in:
+5
-16
@@ -186,22 +186,11 @@ const pm_char * bmpLoad(uint8_t *bmp, const char *filename, const unsigned int w
|
||||
f_close(&bmpFile);
|
||||
return SDCARD_ERROR(result);
|
||||
}
|
||||
for (uint32_t j=0; j<rowSize; j++) {
|
||||
uint8_t * dst = dest + (i/2)*w + j*2;
|
||||
if (i & 1) {
|
||||
uint8_t val = palette[(buf[j] >> 4) & 0x0F] << 4;
|
||||
*dst |= val ^ 0xF0;
|
||||
if ((j+1)*2 >= w) break;
|
||||
val = palette[buf[j] & 0x0F] << 4;
|
||||
*(dst+1) |= val ^ 0xF0;
|
||||
}
|
||||
else {
|
||||
uint8_t val = palette[(buf[j] >> 4) & 0x0F];
|
||||
*dst |= val ^ 0x0F;
|
||||
if ((j+1)*2 >= w) break;
|
||||
val = palette[buf[j] & 0x0F];
|
||||
*(dst+1) |= val ^ 0x0F;
|
||||
}
|
||||
uint8_t * dst = dest + (i/2)*w;
|
||||
for (uint32_t j=0; j<w; j++) {
|
||||
uint8_t index = (buf[j/2] >> ((j & 1) ? 0 : 4)) & 0x0F;
|
||||
uint8_t val = palette[index] << ((i & 1) ? 4 : 0);
|
||||
*dst++ |= val ^ ((i & 1) ? 0xF0 : 0x0F);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -537,28 +537,30 @@ void lcd_line(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFl
|
||||
|
||||
if (dxabs >= dyabs) {
|
||||
/* the line is more horizontal than vertical */
|
||||
for (int i=0; i<dxabs; i++) {
|
||||
for (int i=0; i<=dxabs; i++) {
|
||||
y += dyabs;
|
||||
if (y>=dxabs) {
|
||||
y -= dxabs;
|
||||
py += sdy;
|
||||
}
|
||||
px += sdx;
|
||||
if ((1<<(px%8)) & pat)
|
||||
if ((1<<(px%8)) & pat) {
|
||||
lcd_plot(px, py, att);
|
||||
}
|
||||
px += sdx;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* the line is more vertical than horizontal */
|
||||
for (int i=0; i<dyabs; i++) {
|
||||
for (int i=0; i<=dyabs; i++) {
|
||||
x += dxabs;
|
||||
if (x >= dyabs) {
|
||||
x -= dyabs;
|
||||
px += sdx;
|
||||
}
|
||||
py += sdy;
|
||||
if ((1<<(py%8)) & pat)
|
||||
if ((1<<(py%8)) & pat) {
|
||||
lcd_plot(px, py, att);
|
||||
}
|
||||
py += sdy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 358 B |
@@ -380,6 +380,12 @@ TEST(Lcd, lcd_bmpLoadAndDisplay)
|
||||
bitmap.leakCheck();
|
||||
lcd_bmp(70, 2, bitmap.buffer());
|
||||
}
|
||||
{
|
||||
TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(20, 20));
|
||||
EXPECT_EQ(bmpLoad(bitmap.buffer(), "./tests/4b_20x20.bmp", 20, 20), (char *)0);
|
||||
bitmap.leakCheck();
|
||||
lcd_bmp(120, 2, bitmap.buffer());
|
||||
}
|
||||
EXPECT_TRUE(checkScreenshot("lcd_bmpLoadAndDisplay"));
|
||||
|
||||
// Test various bad BMP files, they should not display
|
||||
@@ -395,3 +401,43 @@ TEST(Lcd, lcd_bmpLoadAndDisplay)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
TEST(Lcd, lcd_line)
|
||||
{
|
||||
int start, length, xOffset;
|
||||
uint8_t pattern;
|
||||
|
||||
lcd_clear();
|
||||
|
||||
start = 5;
|
||||
pattern = SOLID;
|
||||
length = 40;
|
||||
xOffset = 0;
|
||||
lcd_line(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
|
||||
lcd_line(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
|
||||
|
||||
start = 10;
|
||||
pattern = DOTTED;
|
||||
length = 40;
|
||||
xOffset = 0;
|
||||
lcd_line(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
|
||||
lcd_line(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
|
||||
|
||||
start = 55;
|
||||
pattern = SOLID;
|
||||
length = -40;
|
||||
xOffset = 80;
|
||||
lcd_line(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
|
||||
lcd_line(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
|
||||
|
||||
start = 50;
|
||||
pattern = DOTTED;
|
||||
length = -40;
|
||||
xOffset = 80;
|
||||
lcd_line(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
|
||||
lcd_line(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
|
||||
|
||||
EXPECT_TRUE(checkScreenshot("lcd_line"));
|
||||
}
|
||||
#endif
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 454 B |
Reference in New Issue
Block a user