Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in ev3c_lcd.c (with fix) #4

Open
lukastautz opened this issue Oct 25, 2022 · 0 comments
Open

Bug in ev3c_lcd.c (with fix) #4

lukastautz opened this issue Oct 25, 2022 · 0 comments

Comments

@lukastautz
Copy link

lukastautz commented Oct 25, 2022

I have found a bug in src/ev3c_lcd.c because of that rectangle frames which aren't squares are only half-drawed (that means, the line below and right aren't drawed).
I found the reason of this bug: in line 258, 264, 273 and 279 are the variables w and h (width and height) interchanged.
The fixed ev3_rectangle_lcd_out is:

void ev3_rectangle_lcd_out(int32_t x,int32_t y,int32_t w,int32_t h,int32_t bit)
{
	int32_t a;
	int32_t minx = x;
	int32_t miny = y;
	int32_t maxx = x+w;
	int32_t maxy = y+h;
	if (minx >= (int32_t)EV3_X_LCD)
		return;
	if (miny >= (int32_t)EV3_Y_LCD)
		return;
	if (maxx < 0)
		return;
	if (maxy < 0)
		return;
	if (minx < 0)
		minx = 0;
	if (miny < 0)
		miny = 0;
	if (maxx >= EV3_X_LCD)
		maxx = EV3_X_LCD-1;
	if (maxy >= EV3_Y_LCD)
		maxy = EV3_Y_LCD-1;

	if (bit)
	{
		if (y == miny)
			for (a = minx; a <= maxx; a++)
				EV3_PIXEL_SET(a,miny);
		if (y+h == maxy)
			for (a = minx; a <= maxx; a++)
				EV3_PIXEL_SET(a,maxy);
		if (x == minx)
			for (a = miny+1; a <= maxy-1; a++)
				EV3_PIXEL_SET(minx,a);
		if (x+w == maxx)
			for (a = miny+1; a <= maxy-1; a++)
				EV3_PIXEL_SET(maxx,a);
	}
	else
	{
		if (y == miny)
			for (a = minx; a <= maxx; a++)
				EV3_PIXEL_UNSET(a,miny);
		if (y+h == maxy)
			for (a = minx; a <= maxx; a++)
				EV3_PIXEL_UNSET(a,maxy);
		if (x == minx)
			for (a = miny+1; a <= maxy-1; a++)
				EV3_PIXEL_UNSET(minx,a);
		if (x+w == maxx)
			for (a = miny+1; a <= maxy-1; a++)
				EV3_PIXEL_UNSET(maxx,a);
	}
}

Remark that if (y+w == maxy) is changed to if (y+h == maxy) and if (x+h == maxx) is changed to if (x+w == maxx).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant