apps/examples/nxlines: Clear a slightly larger rectangle than the one that we drew. This eliminates edge effects due to applying anti-aliasing twice: Once when the line was drawn, and again when the line was erased by overwriting it with the background color

This commit is contained in:
Gregory Nutt 2015-07-14 14:24:51 -06:00
parent 25d45d642f
commit 13a04b6255
2 changed files with 43 additions and 7 deletions

View File

@ -1350,4 +1350,11 @@
around dns_getserver() and dns_setserver() to isolate application
code from changes to those interfaces (2015-07-12).
* apps/nshlib: Add an nslookup command (2015-07-13).
* apps/examples/nxlines: If CONFIG_NX_ANTIALIASING=y, then the nxlines
example now erases a line that is 2 pixels longer and 2 pixels wideri
than the line it drew. That eliminates edges effects due to applying
the anti-aliasing algorithm twice. A better solution would be to makei
anti-aliasing an option for each graphics call so you would rend the
line with anti-aliasing ON and clear it with anti-aliasing OFF. but I
don't have the wherewithal for that change today (2015-04-14)`.

View File

@ -53,9 +53,19 @@
#include "nxlines.h"
/****************************************************************************
* Definitions
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_NX_ANTIALIASING
/* If anti-aliasing is enabled, then we must clear a slightly
* larger region to prevent wierd edge effects.
*/
# define CLEAR_WIDTH (CONFIG_EXAMPLES_NXLINES_LINEWIDTH + 2)
#else
# define CLEAR_WIDTH CONFIG_EXAMPLES_NXLINES_LINEWIDTH
#endif
#ifndef MIN
# define MIN(a,b) (a < b ? a : b)
#endif
@ -210,6 +220,8 @@ void nxlines_test(NXWINDOW hwnd)
nxgl_coord_t halfx;
nxgl_coord_t halfy;
b16_t angle;
b16_t sinangle;
b16_t cosangle;
int ret;
/* Get the maximum radius and center of the circle */
@ -279,8 +291,11 @@ void nxlines_test(NXWINDOW hwnd)
{
/* Determine the position of the line on this pass */
halfx = b16toi(b16muli(b16sin(angle), radius));
halfy = b16toi(b16muli(b16cos(angle), radius));
sinangle = b16sin(angle);
halfx = b16toi(b16muli(sinangle, radius));
cosangle = b16cos(angle);
halfy = b16toi(b16muli(cosangle, radius));
vector.pt1.x = center.x + halfx;
vector.pt1.y = center.y + halfy;
@ -293,8 +308,7 @@ void nxlines_test(NXWINDOW hwnd)
/* Clear the previous line by overwriting it with the circle color */
color[0] = CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR;
ret = nx_drawline((NXWINDOW)hwnd, &previous,
CONFIG_EXAMPLES_NXLINES_LINEWIDTH, color,
ret = nx_drawline((NXWINDOW)hwnd, &previous, CLEAR_WIDTH, color,
NX_LINECAP_NONE);
if (ret < 0)
{
@ -312,6 +326,23 @@ void nxlines_test(NXWINDOW hwnd)
printf("nxlines_test: nx_drawline failed clearing: %d\n", ret);
}
#ifdef CONFIG_NX_ANTIALIASING
/* If anti-aliasing is enabled, then we must clear a slightly
* larger region to prevent wierd edge effects.
*/
halfx = b16toi(b16muli(sinangle, radius + 1));
halfy = b16toi(b16muli(cosangle, radius + 1));
previous.pt1.x = center.x + halfx;
previous.pt1.y = center.y + halfy;
previous.pt2.x = center.x - halfx;
previous.pt2.y = center.y - halfy;
#else
memcpy(&previous, &vector, sizeof(struct nxgl_vector_s));
#endif
/* Set up for the next time through the loop then sleep for a bit. */
angle += b16PI / 16; /* 32 angular positions in full circle */
@ -332,8 +363,6 @@ void nxlines_test(NXWINDOW hwnd)
angle = 0;
#endif
}
memcpy(&previous, &vector, sizeof(struct nxgl_vector_s));
usleep(500*1000);
}
}