summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-26 22:20:00 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-26 22:20:00 +0000
commit555e551c46f5c9dbd74f92239c0078a6feb65568 (patch)
treea6a8386ea7e9e1095291ef60bbdab7a86058a5de /nuttx
parent2371b78045295bfddaf54c65b579f804ef0b58b0 (diff)
downloadpx4-nuttx-555e551c46f5c9dbd74f92239c0078a6feb65568.tar.gz
px4-nuttx-555e551c46f5c9dbd74f92239c0078a6feb65568.tar.bz2
px4-nuttx-555e551c46f5c9dbd74f92239c0078a6feb65568.zip
Add more rasterizers
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1316 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/graphics/nxglib/Make.defs19
-rw-r--r--nuttx/graphics/nxglib/Makefile.sources51
-rw-r--r--nuttx/graphics/nxglib/nxglib_bitblit.h26
-rw-r--r--nuttx/graphics/nxglib/nxglib_copyrectangle.c112
-rw-r--r--nuttx/graphics/nxglib/nxglib_filltrapezoid.c167
-rw-r--r--nuttx/include/nuttx/nxglib.h122
6 files changed, 469 insertions, 28 deletions
diff --git a/nuttx/graphics/nxglib/Make.defs b/nuttx/graphics/nxglib/Make.defs
index 9d7a16d8e..4010fc601 100644
--- a/nuttx/graphics/nxglib/Make.defs
+++ b/nuttx/graphics/nxglib/Make.defs
@@ -35,14 +35,23 @@
NXGLIB_ASRCS =
-#FILL1_CSRCS = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
+#RFILL1_CSRCS = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
# nxglib_fillrectangle_4bpp.c
-FILL2_CSRCS = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \
+RFILL2_CSRCS = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \
nxglib_fillrectangle_24bpp.c nxglib_fillrectangle_32bpp.c
-#MOVE1_CSRCS = nxglib_moverectangle_1bpp.c nxglib_moverectangle_2bpp.c \
+#TFILL1_CSRCS = nxglib_filltrapezoid_1bpp.c nxglib_filltrapezoid_2bpp.c \
+# nxglib_filltrapezoid_4bpp.c
+TFILL2_CSRCS = nxglib_filltrapezoid_8bpp.c nxglib_filltrapezoid_16bpp.c \
+ nxglib_filltrapezoid_24bpp.c nxglib_filltrapezoid_32bpp.c
+#RMOVE1_CSRCS = nxglib_moverectangle_1bpp.c nxglib_moverectangle_2bpp.c \
# nxglib_moverectangle_4bpp.c
-MOVE2_CSRCS = nxglib_moverectangle_8bpp.c nxglib_moverectangle_16bpp.c \
+RMOVE2_CSRCS = nxglib_moverectangle_8bpp.c nxglib_moverectangle_16bpp.c \
nxglib_moverectangle_24bpp.c nxglib_moverectangle_32bpp.c
+#RCOPY1_CSRCS = nxglib_copyrectangle_1bpp.c nxglib_copyrectangle_2bpp.c \
+# nxglib_copyrectangle_4bpp.c
+RCOPY2_CSRCS = nxglib_copyrectangle_8bpp.c nxglib_copyrectangle_16bpp.c \
+ nxglib_copyrectangle_24bpp.c nxglib_copyrectangle_32bpp.c
NXGLIB_CSRCS = nxglib_rgb2yuv.c nxglib_yuv2rgb.c \
- $(FILL1_CSRCS) $(FILL2_CSRCS) $(MOVE1_CSRCS) $(MOVE2_CSRCS)
+ $(RFILL1_CSRCS) $(RFILL2_CSRCS) $(TFILL1_CSRCS) $(TFILL2_CSRCS) \
+ $(RMOVE1_CSRCS) $(RMOVE2_CSRCS) $(RCOPY1_CSRCS) $(RCOPY2_CSRCS)
diff --git a/nuttx/graphics/nxglib/Makefile.sources b/nuttx/graphics/nxglib/Makefile.sources
index a282867a1..4ec65944f 100644
--- a/nuttx/graphics/nxglib/Makefile.sources
+++ b/nuttx/graphics/nxglib/Makefile.sources
@@ -61,42 +61,73 @@ endif
CPPFLAGS += -DNXGLIB_BITSPERPIXEL=$(NXGLIB_BITSPERPIXEL)
CPPFLAGS += -DNXGLIB_SUFFIX=$(NXGLIB_SUFFIX)
-FILL1_CSRCS = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
+RFILL1_CSRCS = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
nxglib_fillrectangle_4bpp.c
-FILL2_CSRCS = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \
+RFILL2_CSRCS = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \
nxglib_fillrectangle_24bpp.c nxglib_fillrectangle_32bpp.c
-MOVE1_CSRCS = nxglib_moverectangle_1bpp.c nxglib_moverectangle_2bpp.c \
+TFILL1_CSRCS = nxglib_filltrapezoid_1bpp.c nxglib_filltrapezoid_2bpp.c \
+ nxglib_filltrapezoid_4bpp.c
+TFILL2_CSRCS = nxglib_filltrapezoid_8bpp.c nxglib_filltrapezoid_16bpp.c \
+ nxglib_filltrapezoid_24bpp.c nxglib_filltrapezoid_32bpp.c
+RMOVE1_CSRCS = nxglib_moverectangle_1bpp.c nxglib_moverectangle_2bpp.c \
nxglib_moverectangle_4bpp.c
-MOVE2_CSRCS = nxglib_moverectangle_8bpp.c nxglib_moverectangle_16bpp.c \
+RMOVE2_CSRCS = nxglib_moverectangle_8bpp.c nxglib_moverectangle_16bpp.c \
nxglib_moverectangle_24bpp.c nxglib_moverectangle_32bpp.c
+RCOPY1_CSRCS = nxglib_copyrectangle_1bpp.c nxglib_copyrectangle_2bpp.c \
+ nxglib_copyrectangle_4bpp.c
+RCOPY2_CSRCS = nxglib_copyrectangle_8bpp.c nxglib_copyrectangle_16bpp.c \
+ nxglib_copyrectangle_24bpp.c nxglib_copyrectangle_32bpp.c
-GEN_CSRCS = $(FILL1_CSRCS) $(FILL2_CSRCS) $(MOVE1_CSRCS) $(MOVE2_CSRCS)
+GEN_CSRCS = $(RFILL1_CSRCS) $(RFILL2_CSRCS) $(TFILL1_CSRCS) $(TFILL2_CSRCS) \
+ $(RMOVE1_CSRCS) $(RMOVE2_CSRCS) $(RCOPY1_CSRCS) $(RCOPY2_CSRCS)
all: $(GEN_CSRCS)
.PHONY : clean distclean
-$(FILL1_CSRCS) : nxglib_fillrectangle.c nxglib_bitblit.h
+$(RFILL1_CSRCS) : nxglib_fillrectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, nxglib_fillrectangle.c, $@)
endif
-$(FILL2_CSRCS) : nxglib_fillrectangle.c nxglib_bitblit.h
+$(RFILL2_CSRCS) : nxglib_fillrectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, nxglib_fillrectangle.c, $@)
endif
-$(MOVE1_CSRCS) : nxglib_moverectangle.c nxglib_bitblit.h
+$(TFILL1_CSRCS) : nxglib_filltrapezoid.c nxglib_bitblit.h
+ifneq ($(NXGLIB_BITSPERPIXEL),)
+ $(call PREPROCESS, nxglib_filltrapezoid.c, $@)
+endif
+
+$(TFILL2_CSRCS) : nxglib_filltrapezoid.c nxglib_bitblit.h
+ifneq ($(NXGLIB_BITSPERPIXEL),)
+ $(call PREPROCESS, nxglib_filltrapezoid.c, $@)
+endif
+
+$(RMOVE1_CSRCS) : nxglib_moverectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, nxglib_moverectangle.c, $@)
endif
-$(MOVE2_CSRCS) : nxglib_moverectangle.c nxglib_bitblit.h
+$(RMOVE2_CSRCS) : nxglib_moverectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, nxglib_moverectangle.c, $@)
endif
+
+$(RCOPY1_CSRCS) : nxglib_copyrectangle.c nxglib_bitblit.h
+ifneq ($(NXGLIB_BITSPERPIXEL),)
+ $(call PREPROCESS, nxglib_copyrectangle.c, $@)
+endif
+
+$(RCOPY2_CSRCS) : nxglib_copyrectangle.c nxglib_bitblit.h
+ifneq ($(NXGLIB_BITSPERPIXEL),)
+ $(call PREPROCESS, nxglib_copyrectangle.c, $@)
+endif
+
clean:
@rm -f *~ .*.swp
distclean: clean
- @rm -f nxglib_fillrectangle_*bpp.c nxglib_moverectangle_*bpp.c
+ @rm -f nxglib_fillrectangle_*bpp.c nxglib_filltrapezoid_*bpp.c
+ @rm -f nxglib_moverectangle_*bpp.c nxglib_copyrectangle_*bpp.c
diff --git a/nuttx/graphics/nxglib/nxglib_bitblit.h b/nuttx/graphics/nxglib/nxglib_bitblit.h
index c53e369cf..523b55597 100644
--- a/nuttx/graphics/nxglib/nxglib_bitblit.h
+++ b/nuttx/graphics/nxglib/nxglib_bitblit.h
@@ -123,8 +123,8 @@
# define NXGL_MEMSET(dest,value,width) \
{ \
FAR ubyte *_ptr = (FAR ubyte*)dest; \
- int nbytes = NXGL_SCALEX(width); \
- while (nbytes--) \
+ int _nby = NXGL_SCALEX(width); \
+ while (_nby--) \
{ \
*_ptr++ = value; \
} \
@@ -133,8 +133,8 @@
{ \
FAR ubyte *_dptr = (FAR ubyte*)dest; \
FAR ubyte *_sptr = (FAR ubyte*)src; \
- int nbytes = NXGL_SCALEX(width); \
- while (nbytes--) \
+ int _nby = NXGL_SCALEX(width); \
+ while (_nby--) \
{ \
*_dptr++ = *_sptr++; \
} \
@@ -143,8 +143,9 @@
#elif NXGLIB_BITSPERPIXEL == 24
# define NXGL_MEMSET(dest,value,width) \
{ \
- FAR ubyte *_ptr = (FAR ubyte*)dest; \
- while (width--) \
+ FAR ubyte *_ptr = (FAR ubyte*)dest; \
+ nxgl_coord_t _npix = width; \
+ while (_npix--) \
{ \
*_ptr++ = value; \
*_ptr++ = value >> 8; \
@@ -153,9 +154,10 @@
}
# define NXGL_MEMCPY(dest,src,width) \
{ \
- FAR ubyte *_dptr = (FAR ubyte*)dest; \
- FAR ubyte *_sptr = (FAR ubyte*)src; \
- while (width--) \
+ FAR ubyte *_dptr = (FAR ubyte*)dest; \
+ FAR ubyte *_sptr = (FAR ubyte*)src; \
+ nxgl_coord_t _npix = width; \
+ while (_npix--) \
{ \
*_dptr++ = *_sptr++; \
*_dptr++ = *_sptr++; \
@@ -166,7 +168,8 @@
# define NXGL_MEMSET(dest,value,width) \
{ \
FAR nx_pixel_t *_ptr = (FAR ubyte*)dest; \
- while (width--) \
+ nxgl_coord_t _npix = width; \
+ while (_npix--) \
{ \
*_ptr++ = value; \
} \
@@ -175,7 +178,8 @@
{ \
FAR nx_pixel_t *_dptr = (FAR ubyte*)dest; \
FAR nx_pixel_t *_sptr = (FAR ubyte*)src; \
- while (width--) \
+ nxgl_coord_t _npix = width; \
+ while (_npix--) \
{ \
*_dptr++ = *_sptr++; \
} \
diff --git a/nuttx/graphics/nxglib/nxglib_copyrectangle.c b/nuttx/graphics/nxglib/nxglib_copyrectangle.c
new file mode 100644
index 000000000..0dd01853c
--- /dev/null
+++ b/nuttx/graphics/nxglib/nxglib_copyrectangle.c
@@ -0,0 +1,112 @@
+/****************************************************************************
+ * graphics/nxglib/nxsglib_copyrectangle.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/fb.h>
+#include <nuttx/nxglib.h>
+
+#include "nxglib_bitblit.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxs_copyrectangle_*bpp
+ *
+ * Descripton:
+ * Copy a rectangular bitmap image into the specific position in the
+ * framebuffer memory.
+ *
+ ****************************************************************************/
+
+void NXGL_FUNCNAME(nxs_copyrectangle,NXGLIB_SUFFIX)
+(FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *dest,
+ FAR const NXGL_PIXEL_T *src, FAR const struct nxgl_point_s *origin,
+ unsigned int srcstride)
+{
+ const ubyte *sptr;
+ ubyte *dptr;
+ unsigned int width;
+ unsigned int deststride;
+ unsigned int rows;
+
+ /* Get the width of the framebuffer in bytes */
+
+ deststride = pinfo->stride;
+
+ /* Get the dimensions of the rectange to fill: height in rows and width in bytes */
+
+ width = NXGL_SCALEX(dest->pt2.x - dest->pt1.x);
+ rows = dest->pt2.y - dest->pt1.y;
+
+ /* Then copy the image */
+
+ sptr = (const ubyte*)src + NXGL_SCALEX(dest->pt1.x - origin->x) + (dest->pt1.y - origin->y) * srcstride;
+ dptr = pinfo->fbmem + dest->pt1.y * deststride + NXGL_SCALEX(dest->pt1.x);
+
+ while (rows--)
+ {
+ NXGL_MEMCPY(dest, sptr, width);
+ dptr += deststride;
+ sptr += srcstride;
+ }
+}
diff --git a/nuttx/graphics/nxglib/nxglib_filltrapezoid.c b/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
new file mode 100644
index 000000000..f1f13a00f
--- /dev/null
+++ b/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
@@ -0,0 +1,167 @@
+/****************************************************************************
+ * graphics/nxglib/nxglib_filltrapezoid.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/fb.h>
+#include <nuttx/nxglib.h>
+
+#include "nxglib_bitblit.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+#ifndef NXGLIB_SUFFIX
+# error "NXGLIB_SUFFIX must be defined before including this header file"
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxglib_filltrapezoid_*bpp
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+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_PIXEL_T color)
+{
+ unsigned int stride;
+ ubyte *line;
+ int nrows;
+ b16_t x1;
+ b16_t x2;
+ b16_t dx1dy;
+ b16_t dx2dy;
+
+ /* Get the width of the framebuffer in bytes */
+
+ stride = pinfo->stride;
+
+ /* 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;
+
+ /* Get the address of the first byte on the first line */
+
+ line = pinfo->fbmem + trap->top.y * stride ;
+
+ /* Calculate the slope of the left and right side of the trapezoid */
+
+ dx1dy = b16divi((trap->bot.x1 - x1), nrows);
+ dx2dy = b16divi((trap->bot.x2 - x2), nrows);
+
+ /* Then fill the trapezoid line-by-line */
+
+ while (nrows--)
+ {
+ int ix1;
+ int ix2;
+
+ /* Handle the special case where the sides cross (as in an hourglass) */
+
+ if (x1 > x2)
+ {
+ b16_t tmp;
+ ngl_swap(x1, x2, tmp);
+ ngl_swap(dx1dy, dx2dy, tmp);
+ }
+
+ /* Convert the positions to integer */
+
+ ix1 = b16toi(x1);
+ ix2 = b16toi(x2);
+
+ /* Handle some corner cases where we draw nothing. Otherwise, we will
+ * always draw at least one pixel.
+ */
+
+ if (x1 > x2 || ix2 < 0 || ix1 > vinfo->yres)
+ {
+ /* Get a clipped copies of the startingand 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);
+
+ /* Then draw the run from (line + clipx1) to (line + clipx2) */
+
+ NXGL_MEMSET(line + NXGL_SCALEX(ix1), color, ix2 - ix1 + 1);
+ }
+
+ /* Move to the start of the next line */
+
+ line += stride;
+
+ /* Add the dx/dy value to get the run positions on the next row */
+
+ x1 += dx1dy;
+ x2 += dx2dy;
+ }
+}
diff --git a/nuttx/include/nuttx/nxglib.h b/nuttx/include/nuttx/nxglib.h
index a7abe89df..6e2d6a794 100644
--- a/nuttx/include/nuttx/nxglib.h
+++ b/nuttx/include/nuttx/nxglib.h
@@ -42,6 +42,18 @@
#include <nuttx/config.h>
#include <sys/types.h>
+#include <fixedmath.h>
+
+/****************************************************************************
+ * Pre-processor definitions
+ ****************************************************************************/
+
+#define ngl_min(a,b) ((a) < (b) ? (a) : (b))
+#define ngl_max(a,b) ((a) > (b) ? (a) : (b))
+#define ngl_swap(a,b,t) do { t = a; a = b; b = t; } while (0);
+#define ngl_clipl(a,mn) ((a) < (mn) ? (mn) : (a))
+#define ngl_clipr(a,mx) ((a) > (mx) ? (mx) : (a))
+#define ngl_clip(a,mx,mn) ((a) < (mn) ? (mn) : (a) > (mx) ? (mx) : (a))
/****************************************************************************
* Public Types
@@ -60,8 +72,8 @@ typedef sint16 nxgl_coord_t;
struct nxgl_point_s
{
- nxgl_coord_t x; /* Range: 0 to screen width - 1 */
- nxgl_coord_t y; /* Rnage: 0 to screen height - 1*/
+ nxgl_coord_t x; /* X position, range: 0 to screen width - 1 */
+ nxgl_coord_t y; /* Y position, range: 0 to screen height - 1 */
};
/* Describes a rectangle on the display */
@@ -72,6 +84,28 @@ struct nxgl_rect_s
struct nxgl_point_s pt2; /* Lower, right-hand corner */
};
+/* Describes a run, i.e., a horizontal line. Note that the start/end positions
+ * have fractional precision. This is necessary for good joining of trapezoids
+ * when a more complex shape is decomposed into trapezoids
+ */
+
+struct nxgl_run_s
+{
+ b16_t x1; /* Left X position, range: 0 to x2 */
+ b16_t x2; /* Right X position, range: x1 to screen width - 1 */
+ nxgl_coord_t y; /* Top Y position, range: 0 to screen height - 1 */
+};
+
+/* Describes a horizontal trapezoid on the display in terms the run at the
+ * top of the trapezoid and the run at the bottom
+ */
+
+struct nxgl_trapezoid_s
+{
+ struct nxgl_run_s top; /* Top run */
+ struct nxgl_run_s bot; /* bottom run */
+};
+
/****************************************************************************
* Public Data
****************************************************************************/
@@ -143,6 +177,45 @@ EXTERN void nxgl_fillrectangle_32bpp(FAR struct fb_planeinfo_s *pinfo,
uint32 color);
/****************************************************************************
+ * Name: nxglib_filltrapezoid_*bpp
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+EXTERN void nxglib_filltrapezoid_1bpp(FAR struct fb_videoinfo_s *vinfo,
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ ubyte color);
+EXTERN void nxglib_filltrapezoid_2bpp(FAR struct fb_videoinfo_s *vinfo,
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ ubyte color);
+EXTERN void nxglib_filltrapezoid_4bpp(FAR struct fb_videoinfo_s *vinfo,
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ ubyte color);
+EXTERN void nxglib_filltrapezoid_8bpp(FAR struct fb_videoinfo_s *vinfo,
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ ubyte color);
+EXTERN void nxglib_filltrapezoid_16bpp(FAR struct fb_videoinfo_s *vinfo,
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ uint16 color);
+EXTERN void nxglib_filltrapezoid_24bpp(FAR struct fb_videoinfo_s *vinfo,
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ uint32 color);
+EXTERN void nxglib_filltrapezoid_32bpp(FAR struct fb_videoinfo_s *vinfo,
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ uint32 color);
+
+/****************************************************************************
* Name: nxgl_moverectangle_*bpp
*
* Descripton:
@@ -173,6 +246,51 @@ EXTERN void nxgl_moverectangle_32bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset);
+/****************************************************************************
+ * Name: nxs_copyrectangle_*bpp
+ *
+ * Descripton:
+ * Copy a rectangular bitmap image into the specific position in the
+ * framebuffer memory.
+ *
+ ****************************************************************************/
+
+EXTERN void nxs_copyrectangle_1bpp(FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const ubyte *src,
+ FAR const struct nxgl_point_s *origin,
+ unsigned int srcstride);
+EXTERN void nxs_copyrectangle_2bpp(FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const ubyte *src,
+ FAR const struct nxgl_point_s *origin,
+ unsigned int srcstride);
+EXTERN void nxs_copyrectangle_4bpp(FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const ubyte *src,
+ FAR const struct nxgl_point_s *origin,
+ unsigned int srcstride);
+EXTERN void nxs_copyrectangle_8bpp(FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const ubyte *src,
+ FAR const struct nxgl_point_s *origin,
+ unsigned int srcstride);
+EXTERN void nxs_copyrectangle_16bpp(FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const uint16 *src,
+ FAR const struct nxgl_point_s *origin,
+ unsigned int srcstride);
+EXTERN void nxs_copyrectangle_24bpp(FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const uint32 *src,
+ FAR const struct nxgl_point_s *origin,
+ unsigned int srcstride);
+EXTERN void nxs_copyrectangle_32bpp(FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const uint32 *src,
+ FAR const struct nxgl_point_s *origin,
+ unsigned int srcstride);
+
#undef EXTERN
#if defined(__cplusplus)
}