1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 20:35:17 +03:00

Projectkk2glider/issue 4449 drawline (#4464)

* Gtest pattern changed

* Fixes #4449: lcdDrawLine_line() was wrong for slanted lines [128x64]

* Fixes #4449: lcdDrawLine_line() was wrong for slanted lines [480x272]

* lcdDrawLine() coordinates check moved to Lua API
This commit is contained in:
Damjan Adamic 2017-02-16 00:23:42 +01:00 committed by Bertrand Songis
parent 53f55f8e1d
commit ee43d3fb97
7 changed files with 53 additions and 42 deletions

View file

@ -636,28 +636,28 @@ void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, Lc
if (dxabs >= dyabs) { if (dxabs >= dyabs) {
/* the line is more horizontal than vertical */ /* the line is more horizontal than vertical */
for (int i=0; i<=dxabs; i++) { for (int i=0; i<=dxabs; i++) {
if ((1<<(px%8)) & pat) {
lcdDrawPoint(px, py, att);
}
y += dyabs; y += dyabs;
if (y>=dxabs) { if (y>=dxabs) {
y -= dxabs; y -= dxabs;
py += sdy; py += sdy;
} }
if ((1<<(px%8)) & pat) {
lcdDrawPoint(px, py, att);
}
px += sdx; px += sdx;
} }
} }
else { else {
/* the line is more vertical than horizontal */ /* the line is more vertical than horizontal */
for (int i=0; i<=dyabs; i++) { for (int i=0; i<=dyabs; i++) {
if ((1<<(py%8)) & pat) {
lcdDrawPoint(px, py, att);
}
x += dxabs; x += dxabs;
if (x >= dyabs) { if (x >= dyabs) {
x -= dyabs; x -= dyabs;
px += sdx; px += sdx;
} }
if ((1<<(py%8)) & pat) {
lcdDrawPoint(px, py, att);
}
py += sdy; py += sdy;
} }
} }

View file

@ -420,8 +420,6 @@ void lcdDrawSolidHorizontalLine(coord_t x, coord_t y, coord_t w, LcdFlags att)
#if !defined(BOOT) #if !defined(BOOT)
void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att) void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att)
{ {
if (lcdIsPointOutside(x1, y1) || lcdIsPointOutside(x2, y2)) return;
int dx = x2-x1; /* the horizontal distance of the line */ int dx = x2-x1; /* the horizontal distance of the line */
int dy = y2-y1; /* the vertical distance of the line */ int dy = y2-y1; /* the vertical distance of the line */
int dxabs = abs(dx); int dxabs = abs(dx);

View file

@ -192,28 +192,28 @@ void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, Lc
if (dxabs >= dyabs) { if (dxabs >= dyabs) {
/* the line is more horizontal than vertical */ /* the line is more horizontal than vertical */
for (int i=0; i<=dxabs; i++) { for (int i=0; i<=dxabs; i++) {
if ((1<<(px%8)) & pat) {
lcdDrawPoint(px, py, att);
}
y += dyabs; y += dyabs;
if (y>=dxabs) { if (y>=dxabs) {
y -= dxabs; y -= dxabs;
py += sdy; py += sdy;
} }
if ((1<<(px%8)) & pat) {
lcdDrawPoint(px, py, att);
}
px += sdx; px += sdx;
} }
} }
else { else {
/* the line is more vertical than horizontal */ /* the line is more vertical than horizontal */
for (int i=0; i<=dyabs; i++) { for (int i=0; i<=dyabs; i++) {
if ((1<<(py%8)) & pat) {
lcdDrawPoint(px, py, att);
}
x += dxabs; x += dxabs;
if (x >= dyabs) { if (x >= dyabs) {
x -= dyabs; x -= dyabs;
px += sdx; px += sdx;
} }
if ((1<<(py%8)) & pat) {
lcdDrawPoint(px, py, att);
}
py += sdy; py += sdy;
} }
} }

View file

@ -106,6 +106,9 @@ static int luaLcdDrawLine(lua_State *L)
int pat = luaL_checkinteger(L, 5); int pat = luaL_checkinteger(L, 5);
int flags = luaL_checkinteger(L, 6); int flags = luaL_checkinteger(L, 6);
if (x1 < 0 || x1 >= LCD_W || y1 < 0 || y1 >= LCD_H || x2 < 0 || x2 >= LCD_W || y2 < 0 || y2 >= LCD_H)
return 0;
if (pat == SOLID) { if (pat == SOLID) {
if (x1 == x2) { if (x1 == x2) {
lcdDrawSolidVerticalLine(x1, y2 >= y1 ? y1 : y1+1, y2 >= y1 ? y2-y1+1 : y2-y1-1, flags); lcdDrawSolidVerticalLine(x1, y2 >= y1 ? y1 : y1+1, y2 >= y1 ? y2-y1+1 : y2-y1-1, flags);

View file

@ -404,7 +404,24 @@ TEST(Lcd, lcdDrawBitmapLoadAndDisplay)
} }
#endif #endif
#if defined(PCBTARANIS) && LCD_W >= 212 #if defined(PCBTARANIS)
void drawDiamond(int x, int y, int size)
{
int x1 = x - size;
int x2 = x;
int x3 = x + size;
int y1 = y - size;
int y2 = y;
int y3 = y + size;
lcdDrawLine( x1, y2, x2, y1, SOLID, FORCE);
lcdDrawLine( x2, y1, x3, y2, SOLID, FORCE);
lcdDrawLine( x3, y2, x2, y3, SOLID, FORCE);
lcdDrawLine( x2, y3, x1, y2, SOLID, FORCE);
}
TEST(Lcd, lcdDrawLine) TEST(Lcd, lcdDrawLine)
{ {
int start, length, xOffset; int start, length, xOffset;
@ -412,60 +429,53 @@ TEST(Lcd, lcdDrawLine)
lcdClear(); lcdClear();
start = 5; start = 2;
pattern = SOLID; pattern = SOLID;
length = 40; length = 40;
xOffset = 0; xOffset = 0;
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0); lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0); lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
start = 10; start = 4;
pattern = DOTTED; pattern = DOTTED;
length = 40; length = 40;
xOffset = 0; xOffset = 0;
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0); lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0); lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
start = 55; start = 56;
pattern = SOLID; pattern = SOLID;
length = -40; length = -40;
xOffset = 80; xOffset = 65;
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0); lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0); lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
start = 50; start = 54;
pattern = DOTTED; pattern = DOTTED;
length = -40; length = -40;
xOffset = 80; xOffset = 65;
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0); lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0); lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
// 45 deg lines // 45 deg lines
lcdDrawLine( 35, 40, 45, 40, SOLID, FORCE ); lcdDrawLine( 25, 30, 35, 30, SOLID, FORCE );
lcdDrawLine( 40, 35, 40, 45, SOLID, FORCE ); lcdDrawLine( 30, 25, 30, 35, SOLID, FORCE );
lcdDrawLine( 20, 40, 40, 20, SOLID, FORCE ); drawDiamond(30, 30, 10);
lcdDrawLine( 40, 20, 60, 40, SOLID, FORCE ); drawDiamond(30, 30, 20);
lcdDrawLine( 60, 40, 40, 60, SOLID, FORCE );
lcdDrawLine( 40, 60, 20, 40, SOLID, FORCE );
lcdDrawLine( 31, 39, 39, 31, SOLID, FORCE );
lcdDrawLine( 41, 31, 49, 39, SOLID, FORCE );
lcdDrawLine( 49, 41, 41, 49, SOLID, FORCE );
lcdDrawLine( 39, 49, 31, 41, SOLID, FORCE );
// slanted lines // slanted lines
lcdDrawLine( 150, 10, 190, 10, SOLID, FORCE ); lcdDrawLine( 60, 10, 100, 10, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 20, SOLID, FORCE ); lcdDrawLine( 60, 10, 100, 20, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 30, SOLID, FORCE ); lcdDrawLine( 60, 10, 100, 30, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 40, SOLID, FORCE ); lcdDrawLine( 60, 10, 100, 40, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 50, SOLID, FORCE ); lcdDrawLine( 60, 10, 100, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 50, SOLID, FORCE ); lcdDrawLine( 60, 10, 100, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 180, 50, SOLID, FORCE ); lcdDrawLine( 60, 10, 90, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 170, 50, SOLID, FORCE ); lcdDrawLine( 60, 10, 80, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 160, 50, SOLID, FORCE ); lcdDrawLine( 60, 10, 70, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 150, 50, SOLID, FORCE ); lcdDrawLine( 60, 10, 60, 50, SOLID, FORCE );
EXPECT_TRUE(checkScreenshot("lcdDrawLine")); EXPECT_TRUE(checkScreenshot("lcdDrawLine"));
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

After

Width:  |  Height:  |  Size: 1 KiB

Before After
Before After