Add another rasterizer

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1314 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-11-26 19:39:54 +00:00
parent e77aa25163
commit 347bc09e47
11 changed files with 283 additions and 54 deletions

View file

@ -585,3 +585,5 @@
* Added fixed precision math support
* Added some color converson routines into what may become a real graphics library someday.
* Added a framebuffer driver for the DM320 (untested on initial check-in)
* Network: add support for outgoing multicast addresses
* Added some rasterizers to the graphics library

View file

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
<p>Last Updated: November 25, 2008</p>
<p>Last Updated: November 26, 2008</p>
</td>
</tr>
</table>
@ -1221,6 +1221,8 @@ nuttx-0.3.19 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
* Added fixed precision math support
* Added some color converson routines into what may become a real graphics library someday.
* Added a framebuffer driver for the DM320 (untested on initial check-in)
* Network: add support for outgoing multicast addresses
* Added some rasterizers to the graphics library
pascal-0.1.3 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;

View file

@ -62,9 +62,10 @@ BIN = libgraphics$(LIBEXT)
VPATH = nxglib:nx
all: $(BIN)
.PHONY : depend clean distclean gensources gen1bppsources gen2bppsource gen4bppsource \
gen8bppsource gen16bppsource gen24bppsource gen32bppsources
all: mklibgraphics
.PHONY : depend clean distclean mklibgraphics gensources gen1bppsources \
gen2bppsource gen4bppsource gen8bppsource gen16bppsource gen24bppsource \
gen32bppsources
gen1bppsources:
@make -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1
@ -95,11 +96,13 @@ $(AOBJS): %$(OBJEXT): %.S
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): gensources $(OBJS)
$(BIN): $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $@, $${obj}); \
done ; )
mklibgraphics: gensources $(BIN)
.depend: gensources Makefile $(SRCS)
@$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@

View file

@ -35,9 +35,14 @@
NXGLIB_ASRCS =
#FILL_CSRCS1 = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
#FILL1_CSRCS = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
# nxglib_fillrectangle_4bpp.c
FILL_CSRCS2 = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \
FILL2_CSRCS = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \
nxglib_fillrectangle_24bpp.c nxglib_fillrectangle_32bpp.c
NXGLIB_CSRCS = nxglib_rgb2yuv.c nxglib_yuv2rgb.c $(FILL_CSRCS1) $(FILL_CSRCS2)
#MOVE1_CSRCS = nxglib_moverectangle_1bpp.c nxglib_moverectangle_2bpp.c \
# nxglib_moverectangle_4bpp.c
MOVE2_CSRCS = nxglib_moverectangle_8bpp.c nxglib_moverectangle_16bpp.c \
nxglib_moverectangle_24bpp.c nxglib_moverectangle_32bpp.c
NXGLIB_CSRCS = nxglib_rgb2yuv.c nxglib_yuv2rgb.c \
$(FILL1_CSRCS) $(FILL2_CSRCS) $(MOVE1_CSRCS) $(MOVE2_CSRCS)

View file

@ -65,8 +65,12 @@ FILL1_CSRCS = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
nxglib_fillrectangle_4bpp.c
FILL2_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 \
nxglib_moverectangle_4bpp.c
MOVE2_CSRCS = nxglib_moverectangle_8bpp.c nxglib_moverectangle_16bpp.c \
nxglib_moverectangle_24bpp.c nxglib_moverectangle_32bpp.c
GEN_CSRCS = $(FILL1_CSRCS) $(FILL2_CSRCS)
GEN_CSRCS = $(FILL1_CSRCS) $(FILL2_CSRCS) $(MOVE1_CSRCS) $(MOVE2_CSRCS)
all: $(GEN_CSRCS)
.PHONY : clean distclean
@ -81,9 +85,18 @@ ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, nxglib_fillrectangle.c, $@)
endif
$(MOVE1_CSRCS) : nxglib_moverectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, nxglib_moverectangle.c, $@)
endif
$(MOVE2_CSRCS) : nxglib_moverectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, nxglib_moverectangle.c, $@)
endif
clean:
@rm -f *~ .*.swp
distclean: clean
@rm -f nxglib_fillrectangle_*bpp.c
@rm -f nxglib_fillrectangle_*bpp.c nxglib_moverectangle_*bpp.c

View file

@ -61,69 +61,69 @@
#if NXGLIB_BITSPERPIXEL == 1
# define NX_PIXELSHIFT 3
# define NX_PIXELMASK 7
# define NX_MULTIPIXEL(p) ((p) ? 0xff | 0x00)
# define NX_PIXEL_T ubyte
# define NXGL_PIXELSHIFT 3
# define NXGL_PIXELMASK 7
# define NXGL_MULTIPIXEL(p) ((p) ? 0xff | 0x00)
# define NXGL_PIXEL_T ubyte
#elif NXGLIB_BITSPERPIXEL == 2
# define NX_PIXELSHIFT 2
# define NX_PIXELMASK 3
# define NX_MULTIPIXEL(p) ((ubyte)(p) << 6 | (ubyte)(p) << 4 | (ubyte)(p) << 2 | (p))
# define NX_PIXEL_T ubyte
# define NXGL_PIXELSHIFT 2
# define NXGL_PIXELMASK 3
# define NXGL_MULTIPIXEL(p) ((ubyte)(p) << 6 | (ubyte)(p) << 4 | (ubyte)(p) << 2 | (p))
# define NXGL_PIXEL_T ubyte
#elif NXGLIB_BITSPERPIXEL == 4
# define NX_PIXELSHIFT 1
# define NX_PIXELMASK 1
# define NX_MULTIPIXEL(p) ((ubyte)(p) << 4 | (p))
# define NX_PIXEL_T ubyte
# define NXGL_PIXELSHIFT 1
# define NXGL_PIXELMASK 1
# define NXGL_MULTIPIXEL(p) ((ubyte)(p) << 4 | (p))
# define NXGL_PIXEL_T ubyte
#elif NXGLIB_BITSPERPIXEL == 8
# define NX_SCALEX(x) (x)
# define NX_PIXEL_T ubyte
# define NXGL_SCALEX(x) (x)
# define NXGL_PIXEL_T ubyte
#elif NXGLIB_BITSPERPIXEL == 16
# define NX_SCALEX(x) ((x) << 1)
# define NX_PIXEL_T uint16
# define NXGL_SCALEX(x) ((x) << 1)
# define NXGL_PIXEL_T uint16
#elif NXGLIB_BITSPERPIXEL == 24
# define NX_SCALEX(x) (((x) << 1) + (x))
# define NX_PIXEL_T uint32
# define NXGL_SCALEX(x) (((x) << 1) + (x))
# define NXGL_PIXEL_T uint32
#elif NXGLIB_BITSPERPIXEL == 32
# define NX_SCALEX(x) ((x) << 2)
# define NX_PIXEL_T uint32
# define NXGL_SCALEX(x) ((x) << 2)
# define NXGL_PIXEL_T uint32
#endif
#if NXGLIB_BITSPERPIXEL < 8
# define NX_SCALEX(x) ((x) >> NX_PIXELSHIFT)
# define NX_REMAINDERX(x) ((x) & NX_PIXELMASK)
# define NX_ALIGNDOWN(x) ((x) & ~NX_PIXELMASK)
# define NX_ALIGNUP(x) (((x) + NX_PIXELMASK) & ~NX_PIXELMASK)
# define NXGL_SCALEX(x) ((x) >> NXGL_PIXELSHIFT)
# define NXGL_REMAINDERX(x) ((x) & NXGL_PIXELMASK)
# define NXGL_ALIGNDOWN(x) ((x) & ~NXGL_PIXELMASK)
# define NXGL_ALIGNUP(x) (((x) + NXGL_PIXELMASK) & ~NXGL_PIXELMASK)
# ifdef CONFIG_NX_PACKEDMSFIRST
# define NX_MASKEDSRC1(s,r) ((s) & (((ubyte)0xff) >> (8 - ((r) << pixelshift))))
# define NX_MASKEDVALUE1(s,r) ((s) & (((ubyte)0xff) << ((r) << NX_PIXELSHFIT)))
# define NX_MASKEDSRC2(s,r) ((s) & (((ubyte)0xff) >> ((r) << pixelshift)))
# define NX_MASKEDVALUE2(s,r) ((s) & (((ubyte)0xff) << (8 - ((r) << NX_PIXELSHFIT))))
# ifdef CONFIG_NXGL_PACKEDMSFIRST
# define NXGL_MASKEDSRC1(s,r) ((s) & (((ubyte)0xff) >> (8 - ((r) << pixelshift))))
# define NXGL_MASKEDVALUE1(s,r) ((s) & (((ubyte)0xff) << ((r) << NXGL_PIXELSHFIT)))
# define NXGL_MASKEDSRC2(s,r) ((s) & (((ubyte)0xff) >> ((r) << pixelshift)))
# define NXGL_MASKEDVALUE2(s,r) ((s) & (((ubyte)0xff) << (8 - ((r) << NXGL_PIXELSHFIT))))
# else
# define NX_MASKEDSRC1(s,r) ((s) & (((ubyte)0xff) >> ((r) << pixelshift)))
# define NX_MASKEDVALUE1(s,r) ((s) & (((ubyte)0xff) << (8 - ((r) << NX_PIXELSHFIT))))
# define NX_MASKEDSRC2(s,r) ((s) & (((ubyte)0xff) >> (8 - ((r) << pixelshift))))
# define NX_MASKEDVALUE2(s,r) ((s) & (((ubyte)0xff) << ((r) << NX_PIXELSHFIT)))
# define NXGL_MASKEDSRC1(s,r) ((s) & (((ubyte)0xff) >> ((r) << pixelshift)))
# define NXGL_MASKEDVALUE1(s,r) ((s) & (((ubyte)0xff) << (8 - ((r) << NXGL_PIXELSHFIT))))
# define NXGL_MASKEDSRC2(s,r) ((s) & (((ubyte)0xff) >> (8 - ((r) << pixelshift))))
# define NXGL_MASKEDVALUE2(s,r) ((s) & (((ubyte)0xff) << ((r) << NXGL_PIXELSHFIT)))
# endif
# define NXGL_MEMSET(dest,value,width) \
{ \
FAR ubyte *_ptr = (FAR ubyte*)dest; \
int nbytes = NX_SCALEX(width); \
int nbytes = NXGL_SCALEX(width); \
while (nbytes--) \
{ \
*_ptr++ = value; \
@ -133,8 +133,8 @@
{ \
FAR ubyte *_dptr = (FAR ubyte*)dest; \
FAR ubyte *_sptr = (FAR ubyte*)src; \
int nbytes = NX_SCALEX(width); \
while (npixels--) \
int nbytes = NXGL_SCALEX(width); \
while (nbytes--) \
{ \
*_dptr++ = *_sptr++; \
} \

View file

@ -74,7 +74,7 @@
****************************************************************************/
/****************************************************************************
* Name: nxgl_fillrectangle*
* Name: nxgl_fillrectangle_*bpp
*
* Descripton:
* Fill a rectangle region in the framebuffer memory with a fixed color
@ -82,7 +82,7 @@
****************************************************************************/
void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX)
(FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect, NX_PIXEL_T color)
(FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect, NXGL_PIXEL_T color)
{
ubyte *line;
unsigned int width;
@ -100,7 +100,7 @@ void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX)
/* Get the address of the first byte in the first line to write */
line = pinfo->fbmem + rect->pt1.y * stride + NX_SCALEX(rect->pt1.x);
line = pinfo->fbmem + rect->pt1.y * stride + NXGL_SCALEX(rect->pt1.x);
/* Then fill the rectangle line-by-line */

View file

@ -0,0 +1,126 @@
/****************************************************************************
* graphics/nxglib/nxglib_moverectangle.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: nxgl_moverectangle_*bpp
*
* Descripton:
* Move a rectangular region from location to another in the
* framebuffer memory.
*
****************************************************************************/
void NXGL_FUNCNAME(nxgl_moverectangle,NXGLIB_SUFFIX)
(FAR struct fb_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset)
{
const ubyte *sptr;
ubyte *dptr;
unsigned int width;
unsigned int stride;
unsigned int rows;
/* Get the width of the framebuffer in bytes */
stride = pinfo->stride;
/* Get the dimensions of the rectange to fill: height in rows and width in bytes */
width = NXGL_SCALEX(rect->pt2.x - rect->pt1.x);
rows = rect->pt2.y - rect->pt1.y;
/* Case 1: The starting position is above the display */
if (offset->y < 0)
{
dptr = pinfo->fbmem + rect->pt1.y * stride + NXGL_SCALEX(rect->pt1.x);
sptr = dptr - offset->y * stride - NXGL_SCALEX(offset->x);
while (rows--)
{
NXGL_MEMCPY(dptr, sptr, width);
dptr += stride;
sptr += stride;
}
}
else
{
dptr = pinfo->fbmem + rect->pt2.y * stride + NXGL_SCALEX(rect->pt1.x);
sptr = dptr - offset->y * stride - NXGL_SCALEX(offset->x);
while (rows--)
{
dptr -= stride;
sptr -= stride;
NXGL_MEMCPY(dptr, sptr, width);
}
}
}

View file

@ -85,7 +85,6 @@
* Description:
* Convert 8-bit RGB triplet to 8-bit YUV triplet
*
*
****************************************************************************/
void nxgl_rgb2yuv(ubyte r, ubyte g, ubyte b, ubyte *y, ubyte *u, ubyte *v)

View file

@ -81,7 +81,6 @@
* Description:
* Convert 8-bit RGB triplet to 8-bit YUV triplet
*
*
****************************************************************************/
void nxgl_yuv2rgb(ubyte y, ubyte u, ubyte v, ubyte *r, ubyte *g, ubyte *b)

View file

@ -68,8 +68,8 @@ struct nxgl_point_s
struct nxgl_rect_s
{
struct nxgl_point_t pt1; /* Upper, left-hand corner */
struct nxgl_point_t pt2; /* Lower, right-hand corner */
struct nxgl_point_s pt1; /* Upper, left-hand corner */
struct nxgl_point_s pt2; /* Lower, right-hand corner */
};
/****************************************************************************
@ -88,11 +88,91 @@ extern "C" {
* Public Function Prototypes
****************************************************************************/
/* Color conversons */
/* Color conversons *********************************************************/
/****************************************************************************
* Name: nxgl_rgb2yuv
*
* Description:
* Convert 8-bit RGB triplet to 8-bit YUV triplet
*
****************************************************************************/
EXTERN void nxgl_rgb2yuv(ubyte r, ubyte g, ubyte b, ubyte *y, ubyte *u, ubyte *v);
/****************************************************************************
* Name: nxgl_yuv2rgb
*
* Description:
* Convert 8-bit RGB triplet to 8-bit YUV triplet
*
****************************************************************************/
EXTERN void nxgl_yuv2rgb(ubyte y, ubyte u, ubyte v, ubyte *r, ubyte *g, ubyte *b);
/* Rasterizers **************************************************************/
/****************************************************************************
* Name: nxgl_fillrectangle_*bpp
*
* Descripton:
* Fill a rectangle region in the framebuffer memory with a fixed color
*
****************************************************************************/
EXTERN void nxgl_fillrectangle_1bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
ubyte color);
EXTERN void nxgl_fillrectangle_2bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
ubyte color);
EXTERN void nxgl_fillrectangle_4bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
ubyte color);
EXTERN void nxgl_fillrectangle_8bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
ubyte color);
EXTERN void nxgl_fillrectangle_16bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
uint16 color);
EXTERN void nxgl_fillrectangle_24bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
uint32 color);
EXTERN void nxgl_fillrectangle_32bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
uint32 color);
/****************************************************************************
* Name: nxgl_moverectangle_*bpp
*
* Descripton:
* Move a rectangular region from location to another in the
* framebuffer memory.
*
****************************************************************************/
EXTERN void nxgl_moverectangle_1bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset);
EXTERN void nxgl_moverectangle_2bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset);
EXTERN void nxgl_moverectangle_4bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset);
EXTERN void nxgl_moverectangle_8bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset);
EXTERN void nxgl_moverectangle_16bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset);
EXTERN void nxgl_moverectangle_24bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset);
EXTERN void nxgl_moverectangle_32bpp(FAR struct fb_planeinfo_s *pinfo,
FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset);
#undef EXTERN
#if defined(__cplusplus)
}