Fix numerous errors in trapezoid rendering and wide line drawing algorithms

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3840 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-08-03 16:04:48 +00:00
parent e185a02245
commit b9adbc1d99
9 changed files with 218 additions and 49 deletions

View File

@ -1971,4 +1971,4 @@
* arch/arm/src/lpc17xx/chip.h: Fix some chip memory configuration errors
for the LPC1764, LPC1756, and LPC1754 (submitted by Li Zhuoy (Lzzy))
* arch/arm/src/lpc17xx/lpc17_can.h: Revised CAN driver submitted by
Li Zhuoy (Lzzy).
Li Zhuoy (Lzzy). The driver now supports both CAN1 and CAN2.

View File

@ -524,6 +524,38 @@ CONFIG_EXAMPLES_NX_CLIENTPRIO=80
CONFIG_EXAMPLES_NX_SERVERPRIO=120
CONFIG_EXAMPLES_NX_NOTIFYSIGNO=4
#
# Settings for examples/nxlines
#
# CONFIG_EXAMPLES_NXLINES_BUILTIN -- Build the NXLINES example as a "built-in"
# that can be executed from the NSH command line
# CONFIG_EXAMPLES_NXLINES_VPLANE -- The plane to select from the frame-
# buffer driver for use in the test. Default: 0
# CONFIG_EXAMPLES_NXLINES_DEVNO - The LCD device to select from the LCD
# driver for use in the test: Default: 0
# CONFIG_EXAMPLES_NXLINES_BGCOLOR -- The color of the background. Default
# depends on CONFIG_EXAMPLES_NXLINES_BPP.
# CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in
# pixels (default: 16)
# CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the lines drawn in the
# background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP.
# CONFIG_EXAMPLES_NXLINES_BPP -- Pixels per pixel to use. Valid options
# include 2, 4, 8, 16, 24, and 32. Default is 16.
# CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on
# this platform requires some unusual initialization. This is the
# for, for example, SPI LCD/OLED devices. If this configuration is
# selected, then the platform code must provide an LCD initialization
# function.
#
CONFIG_EXAMPLES_NXLINES_BUILTIN=n
CONFIG_EXAMPLES_NXLINES_VPLANE=0
CONFIG_EXAMPLES_NXLINES_DEVNO=0
#CONFIG_EXAMPLES_NXLINES_BGCOLOR=
CONFIG_EXAMPLES_NXLINES_LINEWIDTH=16
#CONFIG_EXAMPLES_NXLINES_LINECOLOR=
CONFIG_EXAMPLES_NXLINES_BPP=CONFIG_SIM_FBBPP
CONFIG_EXAMPLES_NXLINES_EXTERNINIT=n
#
# Settings for examples/mount
CONFIG_EXAMPLES_MOUNT_DEVNAME="/dev/ram0"

View File

@ -1132,6 +1132,38 @@ CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5=y
CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0=n
CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT=n
#
# Settings for examples/nxlines
#
# CONFIG_EXAMPLES_NXLINES_BUILTIN -- Build the NXLINES example as a "built-in"
# that can be executed from the NSH command line
# CONFIG_EXAMPLES_NXLINES_VPLANE -- The plane to select from the frame-
# buffer driver for use in the test. Default: 0
# CONFIG_EXAMPLES_NXLINES_DEVNO - The LCD device to select from the LCD
# driver for use in the test: Default: 0
# CONFIG_EXAMPLES_NXLINES_BGCOLOR -- The color of the background. Default
# depends on CONFIG_EXAMPLES_NXLINES_BPP.
# CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in
# pixels (default: 16)
# CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the lines drawn in the
# background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP.
# CONFIG_EXAMPLES_NXLINES_BPP -- Pixels per pixel to use. Valid options
# include 2, 4, 8, 16, 24, and 32. Default is 16.
# CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on
# this platform requires some unusual initialization. This is the
# for, for example, SPI LCD/OLED devices. If this configuration is
# selected, then the platform code must provide an LCD initialization
# function.
#
CONFIG_EXAMPLES_NXLINES_BUILTIN=n
CONFIG_EXAMPLES_NXLINES_VPLANE=0
CONFIG_EXAMPLES_NXLINES_DEVNO=0
CONFIG_EXAMPLES_NXLINES_BGCOLOR=0x0320
CONFIG_EXAMPLES_NXLINES_LINEWIDTH=16
CONFIG_EXAMPLES_NXLINES_LINECOLOR=0xffe0
CONFIG_EXAMPLES_NXLINES_BPP=16
CONFIG_EXAMPLES_NXLINES_EXTERNINIT=n
#
# Settings for examples/usbstorage
#

View File

@ -1083,6 +1083,38 @@ CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5=y
CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0=n
CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT=n
#
# Settings for examples/nxlines
#
# CONFIG_EXAMPLES_NXLINES_BUILTIN -- Build the NXLINES example as a "built-in"
# that can be executed from the NSH command line
# CONFIG_EXAMPLES_NXLINES_VPLANE -- The plane to select from the frame-
# buffer driver for use in the test. Default: 0
# CONFIG_EXAMPLES_NXLINES_DEVNO - The LCD device to select from the LCD
# driver for use in the test: Default: 0
# CONFIG_EXAMPLES_NXLINES_BGCOLOR -- The color of the background. Default
# depends on CONFIG_EXAMPLES_NXLINES_BPP.
# CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in
# pixels (default: 16)
# CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the lines drawn in the
# background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP.
# CONFIG_EXAMPLES_NXLINES_BPP -- Pixels per pixel to use. Valid options
# include 2, 4, 8, 16, 24, and 32. Default is 16.
# CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on
# this platform requires some unusual initialization. This is the
# for, for example, SPI LCD/OLED devices. If this configuration is
# selected, then the platform code must provide an LCD initialization
# function.
#
CONFIG_EXAMPLES_NXLINES_BUILTIN=n
CONFIG_EXAMPLES_NXLINES_VPLANE=0
CONFIG_EXAMPLES_NXLINES_DEVNO=0
CONFIG_EXAMPLES_NXLINES_BGCOLOR=0x0320
CONFIG_EXAMPLES_NXLINES_LINEWIDTH=16
CONFIG_EXAMPLES_NXLINES_LINECOLOR=0xffe0
CONFIG_EXAMPLES_NXLINES_BPP=16
CONFIG_EXAMPLES_NXLINES_EXTERNINIT=n
#
# Stack and heap information
#

View File

@ -1110,7 +1110,7 @@ CONFIG_EXAMPLES_NXTEXT_NOTIFYSIGNO=4
# Settings for examples/nximage
#
# CONFIG_EXAMPLES_NXIMAGE_BUILTIN -- Build the NXIMAGE example as a "built-in"
# that can be executed from the NSH command line
# that can be executed from the NSH command line
# CONFIG_EXAMPLES_NXIMAGE_VPLANE -- The plane to select from the frame-
# buffer driver for use in the test. Default: 0
# CONFIG_EXAMPLES_NXIMAGE_DEVNO - The LCD device to select from the LCD
@ -1143,6 +1143,38 @@ CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5=y
CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0=n
CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT=n
#
# Settings for examples/nxlines
#
# CONFIG_EXAMPLES_NXLINES_BUILTIN -- Build the NXLINES example as a "built-in"
# that can be executed from the NSH command line
# CONFIG_EXAMPLES_NXLINES_VPLANE -- The plane to select from the frame-
# buffer driver for use in the test. Default: 0
# CONFIG_EXAMPLES_NXLINES_DEVNO - The LCD device to select from the LCD
# driver for use in the test: Default: 0
# CONFIG_EXAMPLES_NXLINES_BGCOLOR -- The color of the background. Default
# depends on CONFIG_EXAMPLES_NXLINES_BPP.
# CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in
# pixels (default: 16)
# CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the lines drawn in the
# background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP.
# CONFIG_EXAMPLES_NXLINES_BPP -- Pixels per pixel to use. Valid options
# include 2, 4, 8, 16, 24, and 32. Default is 16.
# CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on
# this platform requires some unusual initialization. This is the
# for, for example, SPI LCD/OLED devices. If this configuration is
# selected, then the platform code must provide an LCD initialization
# function.
#
CONFIG_EXAMPLES_NXLINES_BUILTIN=n
CONFIG_EXAMPLES_NXLINES_VPLANE=0
CONFIG_EXAMPLES_NXLINES_DEVNO=0
CONFIG_EXAMPLES_NXLINES_BGCOLOR=0x0320
CONFIG_EXAMPLES_NXLINES_LINEWIDTH=16
CONFIG_EXAMPLES_NXLINES_LINECOLOR=0xffe0
CONFIG_EXAMPLES_NXLINES_BPP=16
CONFIG_EXAMPLES_NXLINES_EXTERNINIT=n
#
# Stack and heap information
#

View File

@ -115,8 +115,8 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
/* Get the top run position and the number of rows to draw */
x1 = trap->top.x1;
x2 = trap->top.x2;
x1 = trap->top.x1;
x2 = trap->top.x2;
/* Calculate the number of rows to render */
@ -133,6 +133,15 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
if (y1 < bounds->pt1.y)
{
/* Is the entire trapezoid "above" the clipping window? */
if (y2 < bounds->pt1.y)
{
/* Yes.. then do nothing */
return;
}
/* Calculate the x values for the new top run */
int dy = bounds->pt1.y - y1;
@ -147,6 +156,15 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
if (y2 > bounds->pt2.y)
{
/* Is the entire trapezoid "below" the clipping window? */
if (y1 > bounds->pt2.y)
{
/* Yes.. then do nothing */
return;
}
/* Clip and re-calculate the number of rows to render */
y2 = bounds->pt2.y;

View File

@ -124,14 +124,23 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)
/* Calculate the slope of the left and right side of the trapezoid */
dy = boty - topy;
dx1dy = b16divi((botx1 - topx1), dy);
dx2dy = b16divi((botx2 - topx2), dy);
dy = boty - topy;
dx1dy = b16divi((botx1 - topx1), dy);
dx2dy = b16divi((botx2 - topx2), dy);
/* Perform vertical clipping */
if (topy < bounds->pt1.y)
{
/* Is the entire trapezoid "above" the clipping window? */
if (boty < bounds->pt1.y)
{
/* Yes.. then do nothing */
return;
}
/* Calculate the x values for the new top run */
dy = bounds->pt1.y - topy;
@ -145,6 +154,15 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)
if (boty > bounds->pt2.y)
{
/* Is the entire trapezoid "below" the clipping window? */
if (topy > bounds->pt2.y)
{
/* Yes.. then do nothing */
return;
}
/* Calculate the x values for the new bottom run */
dy = boty - bounds->pt2.y;

View File

@ -70,7 +70,7 @@
* Name: nxgl_runoffset
*
* Description:
* Offset the run position by the specified dx, dy values.
* Offset the run position by the specified (integer) dx, dy values.
*
****************************************************************************/
@ -79,7 +79,7 @@ void nxgl_runoffset(FAR struct nxgl_run_s *dest,
nxgl_coord_t dx, nxgl_coord_t dy)
{
b16_t b16dx = itob16(dx);
dest->x1 += b16dx;
dest->x2 += b16dx;
dest->y += dy;
dest->x1 = src->x1 + b16dx;
dest->x2 = src->x2 + b16dx;
dest->y = src->y + dy;
}

View File

@ -112,15 +112,16 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
nxgl_coord_t linewidth)
{
struct nxgl_vector_s line;
struct nxgl_point_s pt;
nxgl_coord_t iheight;
nxgl_coord_t iwidth;
nxgl_coord_t iy;
nxgl_coord_t triheight;
nxgl_coord_t adjwidth;
nxgl_coord_t xoffset;
nxgl_coord_t halfoffset;
nxgl_coord_t halfheight;
b16_t adjwidth;
b16_t xoffset;
b16_t halfoffset;
b16_t angle;
b16_t b16x;
/* First, check the linewidth */
@ -226,13 +227,17 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
angle = b16atan2(itob16(iheight), itob16(iwidth));
triheight = b16toi(linewidth * b16cos(angle));
adjwidth = b16toi(b16divb16(itob16(linewidth), b16sin(angle)));
xoffset = (linewidth * linewidth + (adjwidth >> 1)) / adjwidth;
adjwidth = b16divb16(itob16(linewidth), b16sin(angle));
xoffset = itob16(linewidth * linewidth);
xoffset = b16divb16(xoffset, adjwidth);
halfoffset = (xoffset >> 1);
halfheight = (triheight >> 1);
/* Return the top triangle (if there is one) */
/* Return the top triangle (if there is one). NOTE that the horizontal
* (z) positions are represented with 16 bits of fraction. The vertical
* (y) positions, on the other hand, are integer.
*/
if (triheight > 0)
{
@ -240,53 +245,53 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
{
/* Line is going "south east" */
pt.x = line.pt1.x - halfoffset;
pt.y = line.pt1.y + halfheight;
b16x = itob16(line.pt1.x) - halfoffset;
iy = line.pt1.y + halfheight;
traps[0].top.x1 = pt.x + xoffset;
traps[0].top.x1 = b16x + xoffset;
traps[0].top.x2 = traps[0].top.x1;
traps[0].top.y = pt.y - triheight + 1;
traps[0].bot.x1 = pt.x;
traps[0].bot.x2 = pt.x + adjwidth - 1;
traps[0].bot.y = pt.y;
traps[0].top.y = iy - triheight + 1;
traps[0].bot.x1 = b16x;
traps[0].bot.x2 = b16x + adjwidth - b16ONE;
traps[0].bot.y = iy;
pt.x = line.pt2.x + halfoffset;
pt.y = line.pt2.y - halfheight;
b16x = itob16(line.pt2.x) + halfoffset;
iy = itob16(line.pt2.y) - halfheight;
traps[2].top.x1 = pt.x - adjwidth + 1;
traps[2].top.x2 = pt.x;
traps[2].top.y = pt.y;
traps[2].bot.x1 = pt.x - xoffset;
traps[2].top.x1 = b16x - adjwidth + b16ONE;
traps[2].top.x2 = b16x;
traps[2].top.y = iy;
traps[2].bot.x1 = b16x - xoffset;
traps[2].bot.x2 = traps[2].bot.x1;
traps[2].bot.y = pt.y + triheight - 1;
traps[2].bot.y = iy + triheight - 1;
}
else
{
/* Line is going "south west" */
pt.x = line.pt1.x + halfoffset;
pt.y = line.pt1.y + halfheight;
b16x = itob16(line.pt1.x) + halfoffset;
iy = itob16(line.pt1.y) + halfheight;
traps[0].top.x1 = pt.x - xoffset;
traps[0].top.x1 = b16x - xoffset;
traps[0].top.x2 = traps[0].top.x1;
traps[0].top.y = pt.y - triheight + 1;
traps[0].bot.x1 = pt.x - adjwidth + 1;
traps[0].bot.x2 = pt.x;
traps[0].bot.y = pt.y;
traps[0].top.y = iy - triheight + 1;
traps[0].bot.x1 = b16x - adjwidth + b16ONE;
traps[0].bot.x2 = b16x;
traps[0].bot.y = iy;
pt.x = line.pt2.x - halfoffset;
pt.y = line.pt2.y - halfheight;
b16x = itob16(line.pt2.x) - halfoffset;
iy = itob16(line.pt2.y) - halfheight;
traps[2].top.x1 = pt.x;
traps[2].top.x2 = pt.x + adjwidth - 1;
traps[2].top.y = pt.y;
traps[2].bot.x1 = pt.x + xoffset;
traps[2].top.x1 = b16x;
traps[2].top.x2 = b16x + adjwidth - b16ONE;
traps[2].top.y = iy;
traps[2].bot.x1 = b16x + xoffset;
traps[2].bot.x2 = traps[2].bot.x1;
traps[2].bot.y = pt.y + triheight - 1;
traps[2].bot.y = iy + triheight - 1;
}
/* The center parallelogram is the horizontal edge of each triangle.
* Note the minor inefficency: that horizontal edge is drawn twice.
* Note the minor inefficency: that horizontal edges are drawn twice.
*/
traps[1].top.x1 = traps[0].bot.x1;
@ -304,11 +309,11 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
* bottom. Just return the center parallelogram.
*/
traps[1].top.x1 = line.pt1.x - halfoffset;
traps[1].top.x1 = itob16(line.pt1.x) - halfoffset;
traps[1].top.x2 = traps[1].top.x1 + adjwidth - 1;
traps[1].top.y = line.pt1.y;
traps[1].bot.x1 = line.pt2.x - halfoffset;
traps[1].bot.x1 = itob16(line.pt2.x) - halfoffset;
traps[1].bot.x2 = traps[1].bot.x1 + adjwidth - 1;
traps[1].bot.y = line.pt2.y;
return 1;