summaryrefslogtreecommitdiff
path: root/nuttx/graphics/nxglib
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-28 13:20:36 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-28 13:20:36 +0000
commit0039d56702a25aec6ff26bed044cd607bc0306b4 (patch)
treeced0f16b3ad7a3e3cd7dc3e7e471483166df2edd /nuttx/graphics/nxglib
parentcb311769b6806d5eb0a0b976d062d3c1c3cad2d4 (diff)
downloadpx4-nuttx-0039d56702a25aec6ff26bed044cd607bc0306b4.tar.gz
px4-nuttx-0039d56702a25aec6ff26bed044cd607bc0306b4.tar.bz2
px4-nuttx-0039d56702a25aec6ff26bed044cd607bc0306b4.zip
Add support for trapezoidal fills
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1323 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/graphics/nxglib')
-rw-r--r--nuttx/graphics/nxglib/Make.defs6
-rw-r--r--nuttx/graphics/nxglib/nxglib_filltrapezoid.c60
-rw-r--r--nuttx/graphics/nxglib/nxglib_runoffset.c86
-rw-r--r--nuttx/graphics/nxglib/nxglib_trapoffset.c83
4 files changed, 215 insertions, 20 deletions
diff --git a/nuttx/graphics/nxglib/Make.defs b/nuttx/graphics/nxglib/Make.defs
index ab0427e8b..82ce3bdd9 100644
--- a/nuttx/graphics/nxglib/Make.defs
+++ b/nuttx/graphics/nxglib/Make.defs
@@ -51,10 +51,12 @@ RMOVE2_CSRCS = nxglib_moverectangle_8bpp.c nxglib_moverectangle_16bpp.c \
# nxglib_copyrectangle_4bpp.c
RCOPY2_CSRCS = nxglib_copyrectangle_8bpp.c nxglib_copyrectangle_16bpp.c \
nxglib_copyrectangle_24bpp.c nxglib_copyrectangle_32bpp.c
-RECT_CRCS = nxglib_rectcopy.c nxglib_rectoffset.c nxglib_vectoradd.c \
+RECT_CSRCS = nxglib_rectcopy.c nxglib_rectoffset.c nxglib_vectoradd.c \
nxglib_rectintersect.c nxglib_nonintersecting.c \
nxglib_rectoverlap.c nxglib_nullrect.c
+TRAP_CSRCS = nxglib_runoffset.c nxglib_trapoffset.c
NXGLIB_CSRCS = nxglib_rgb2yuv.c nxglib_yuv2rgb.c \
$(RFILL1_CSRCS) $(RFILL2_CSRCS) $(TFILL1_CSRCS) $(TFILL2_CSRCS) \
- $(RMOVE1_CSRCS) $(RMOVE2_CSRCS) $(RCOPY1_CSRCS) $(RCOPY2_CSRCS)
+ $(RMOVE1_CSRCS) $(RMOVE2_CSRCS) $(RCOPY1_CSRCS) $(RCOPY2_CSRCS) \
+ $(RECT_CSRCS) $(TRAP_CSRCS)
diff --git a/nuttx/graphics/nxglib/nxglib_filltrapezoid.c b/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
index 2343a4680..a4ea25e51 100644
--- a/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
+++ b/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
@@ -79,20 +79,24 @@
*
* Descripton:
* Fill a trapezoidal region in the framebuffer memory with a fixed color.
- * This is useful for drawing complex shape -- (most) complex shapes can be
- * broken into a set of trapezoids.
+ * Clip the trapezoid to lie within a boundng box. This is useful for
+ * drawing complex shapes that can be broken into a set of trapezoids.
*
****************************************************************************/
-void NXGL_FUNCNAME(nxglib_filltrapezoid,NXGLIB_SUFFIX)
-(FAR struct fb_videoinfo_s *vinfo, FAR struct fb_planeinfo_s *pinfo,
- FAR const struct nxgl_trapezoid_s *trap, nxgl_mxpixel_t color)
+void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ FAR const struct nxgl_rect_s *bounds,
+ nxgl_mxpixel_t color)
{
unsigned int stride;
ubyte *line;
int nrows;
b16_t x1;
b16_t x2;
+ nxgl_coord_t y1;
+ nxgl_coord_t y2;
b16_t dx1dy;
b16_t dx2dy;
@@ -102,18 +106,38 @@ void NXGL_FUNCNAME(nxglib_filltrapezoid,NXGLIB_SUFFIX)
/* Get the top run position and the number of rows to draw */
- x1 = trap->top.x1;
- x2 = trap->top.x2;
- nrows = trap->bot.y - trap->top.y + 1;
+ x1 = trap->top.x1;
+ x2 = trap->top.x2;
- /* Get the address of the first byte on the first line */
+ /* Calculate the slope of the left and right side of the trapezoid */
- line = pinfo->fbmem + trap->top.y * stride ;
+ dx1dy = b16divi((trap->bot.x1 - x1), nrows);
+ dx2dy = b16divi((trap->bot.x2 - x2), nrows);
- /* Calculate the slope of the left and right side of the trapezoid */
+ /* Perform vertical clipping */
+
+ y1 = trap->top.y;
+ if (y1 < bounds->pt1.y)
+ {
+ int dy = bounds->pt1.y - y1;
+ x1 += dy * dx1dy;
+ x2 += dy * dx2dy;
+ y1 = bounds->pt1.y;
+ }
+
+ y2 = trap->bot.y;
+ if (y2 > bounds->pt2.y)
+ {
+ y2 = bounds->pt2.y;
+ }
+
+ /* Then calculate the number of rows to render */
+
+ nrows = y2 - y1 + 1;
+
+ /* Get the address of the first byte on the first line */
- dx1dy = b16divi((trap->bot.x1 - x1), nrows);
- dx2dy = b16divi((trap->bot.x2 - x2), nrows);
+ line = pinfo->fbmem + y1 * stride ;
/* Then fill the trapezoid line-by-line */
@@ -140,17 +164,17 @@ void NXGL_FUNCNAME(nxglib_filltrapezoid,NXGLIB_SUFFIX)
* always draw at least one pixel.
*/
- if (x1 > x2 || ix2 < 0 || ix1 > vinfo->yres)
+ if (x1 > x2 || ix2 < bounds->pt1.x || ix1 > bounds->pt2.x)
{
- /* Get a clipped copies of the startingand ending X positions. This
+ /* Get a clipped copies of the starting and ending X positions. This
* clipped truncates "down" and gives the quantized pixel holding the
* fractional X position
*/
- ix1 = ngl_clipl(ix1, 0);
- ix2 = ngl_clipr(ix2, vinfo->yres);
+ ix1 = ngl_clipl(ix1, bounds->pt1.x);
+ ix2 = ngl_clipr(ix2, bounds->pt2.x);
- /* Then draw the run from (line + clipx1) to (line + clipx2) */
+ /* Then draw the run from (line + ix1) to (line + ix2) */
NXGL_MEMSET(line + NXGL_SCALEX(ix1), (NXGL_PIXEL_T)color, ix2 - ix1 + 1);
}
diff --git a/nuttx/graphics/nxglib/nxglib_runoffset.c b/nuttx/graphics/nxglib/nxglib_runoffset.c
new file mode 100644
index 000000000..02aaab894
--- /dev/null
+++ b/nuttx/graphics/nxglib/nxglib_runoffset.c
@@ -0,0 +1,86 @@
+/****************************************************************************
+ * graphics/nxglib/nxsglib_runoffset.c
+ *
+ * Copyright (C) 2008 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <fixedmath.h>
+#include <nuttx/nxglib.h>
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxgl_runoffset
+ *
+ * Description:
+ * Offset the run position by the specified dx, dy values.
+ *
+ ****************************************************************************/
+
+void nxgl_runoffset(FAR struct nxgl_run_s *dest,
+ FAR const struct nxgl_run_s *src,
+ nxgl_coord_t dx, nxgl_coord_t dy)
+{
+ b16_t b16dx = itob16(dx);
+ dest->x1 += b16dx;
+ dest->x2 += b16dx;
+ dest->y += dy;
+}
diff --git a/nuttx/graphics/nxglib/nxglib_trapoffset.c b/nuttx/graphics/nxglib/nxglib_trapoffset.c
new file mode 100644
index 000000000..4c6f1cffa
--- /dev/null
+++ b/nuttx/graphics/nxglib/nxglib_trapoffset.c
@@ -0,0 +1,83 @@
+/****************************************************************************
+ * graphics/nxglib/nxsglib_trapoffset.c
+ *
+ * Copyright (C) 2008 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <nuttx/nxglib.h>
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxgl_trapoffset
+ *
+ * Description:
+ * Offset the trapezoid position by the specified dx, dy values.
+ *
+ ****************************************************************************/
+
+void nxgl_trapoffset(FAR struct nxgl_trapezoid_s *dest,
+ FAR const struct nxgl_trapezoid_s *src,
+ nxgl_coord_t dx, nxgl_coord_t dy)
+{
+ nxgl_runoffset(&dest->top, &src->top, dx, dy);
+ nxgl_runoffset(&dest->bot, &src->bot, dx, dy);
+}