Skip to content

Bug in ev3c_lcd.c (with fix) #4

@lukastautz

Description

@lukastautz

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions