graphics: Clone logic for new bit blitters for per-window framebuffers.

This commit is contained in:
Gregory Nutt 2019-03-14 13:18:55 -06:00
parent f2d90e6298
commit 49635f6e1f
13 changed files with 1446 additions and 23 deletions

View File

@ -65,25 +65,46 @@ all: mklibgraphics
gen32bppsources
gen1bppsources:
$(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES)
ifeq ($(CONFIG_NX_RAMBACKED),y)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES)
endif
gen2bppsource:
$(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES)
ifeq ($(CONFIG_NX_RAMBACKED),y)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES)
endif
gen4bppsource:
$(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES)
ifeq ($(CONFIG_NX_RAMBACKED),y)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES)
endif
gen8bppsource:
$(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES)
ifeq ($(CONFIG_NX_RAMBACKED),y)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES)
endif
gen16bppsource:
$(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES)
ifeq ($(CONFIG_NX_RAMBACKED),y)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES)
endif
gen24bppsource:
$(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES)
ifeq ($(CONFIG_NX_RAMBACKED),y)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES)
endif
gen32bppsources:
$(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
ifeq ($(CONFIG_NX_RAMBACKED),y)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
endif
gensources: gen1bppsources gen2bppsource gen4bppsource gen8bppsource gen16bppsource gen24bppsource gen32bppsources
@ -107,12 +128,14 @@ depend: .depend
context: gensources
clean:
$(Q) $(MAKE) -C nxglib -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(call DELFILE, $(BIN))
$(call CLEAN)
distclean: clean
$(Q) $(MAKE) -C nxglib -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.devblit distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(Q) $(MAKE) -C nxglib -f Makefile.pwfb distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(call DELFILE, Make.dep)
$(call DELFILE, .depend)

View File

@ -4,4 +4,10 @@
/nxglib_filltrapezoid_*bpp.c
/nxglib_moverectangle_*bpp.c
/nxglib_copyrectangle_*bpp.c
/pwfb_setpixel_*bpp.c
/pwfb_fillrectangle_*bpp.c
/pwfb_getrectangle_*bpp.c
/pwfb_filltrapezoid_*bpp.c
/pwfb_moverectangle_*bpp.c
/pwfb_copyrectangle_*bpp.c

View File

@ -63,6 +63,40 @@ CSRCS += nxglib_copyrectangle_4bpp.c nxglib_copyrectangle_8bpp.c
CSRCS += nxglib_copyrectangle_16bpp.c nxglib_copyrectangle_24bpp.c
CSRCS += nxglib_copyrectangle_32bpp.c
ifeq ($(CONFIG_NX_RAMBACKED),y)
CSRCS += pwfb_setpixel_1bpp.c pwfb_setpixel_2bpp.c
CSRCS += pwfb_setpixel_4bpp.c pwfb_setpixel_8bpp.c
CSRCS += pwfb_setpixel_16bpp.c pwfb_setpixel_24bpp.c
CSRCS += pwfb_setpixel_32bpp.c
CSRCS += pwfb_fillrectangle_1bpp.c pwfb_fillrectangle_2bpp.c
CSRCS += pwfb_fillrectangle_4bpp.c pwfb_fillrectangle_8bpp.c
CSRCS += pwfb_fillrectangle_16bpp.c pwfb_fillrectangle_24bpp.c
CSRCS += pwfb_fillrectangle_32bpp.c
CSRCS += pwfb_getrectangle_1bpp.c pwfb_getrectangle_2bpp.c
CSRCS += pwfb_getrectangle_4bpp.c pwfb_getrectangle_8bpp.c
CSRCS += pwfb_getrectangle_16bpp.c pwfb_getrectangle_24bpp.c
CSRCS += pwfb_getrectangle_32bpp.c
CSRCS += pwfb_filltrapezoid_1bpp.c pwfb_filltrapezoid_2bpp.c
CSRCS += pwfb_filltrapezoid_4bpp.c pwfb_filltrapezoid_8bpp.c
CSRCS += pwfb_filltrapezoid_16bpp.c pwfb_filltrapezoid_24bpp.c
CSRCS += pwfb_filltrapezoid_32bpp.c
CSRCS += pwfb_moverectangle_1bpp.c pwfb_moverectangle_2bpp.c
CSRCS += pwfb_moverectangle_4bpp.c pwfb_moverectangle_8bpp.c
CSRCS += pwfb_moverectangle_16bpp.c pwfb_moverectangle_24bpp.c
CSRCS += pwfb_moverectangle_32bpp.c
CSRCS += pwfb_copyrectangle_1bpp.c pwfb_copyrectangle_2bpp.c
CSRCS += pwfb_copyrectangle_4bpp.c pwfb_copyrectangle_8bpp.c
CSRCS += pwfb_copyrectangle_16bpp.c pwfb_copyrectangle_24bpp.c
CSRCS += pwfb_copyrectangle_32bpp.c
endif
DEPPATH += --dep-path nxglib
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxglib}
#VPATH += :nxglib

View File

@ -1,7 +1,7 @@
############################################################################
# graphics/nxglib/Makefile.sources
# graphics/nxglib/Makefile.devblit
#
# Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved.
# Copyright (C) 2008, 2010-2011, 2019 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without

View File

@ -0,0 +1,171 @@
############################################################################
# graphics/nxglib/Makefile.pwfb
#
# Copyright (C) 2019 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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.
#
############################################################################
-include $(TOPDIR)/Make.defs
ifeq ($(NXGLIB_BITSPERPIXEL),1)
NXGLIB_SUFFIX := _1bpp
SETP_CSRC := pwfb_setpixel_1bpp.c
RFILL_CSRC := pwfb_fillrectangle_1bpp.c
RGET_CSRC := pwfb_getrectangle_1bpp.c
TFILL_CSRC := pwfb_filltrapezoid_1bpp.c
RMOVE_CSRC := pwfb_moverectangle_1bpp.c
RCOPY_CSRC := pwfb_copyrectangle_1bpp.c
endif
ifeq ($(NXGLIB_BITSPERPIXEL),2)
NXGLIB_SUFFIX := _2bpp
SETP_CSRC := pwfb_setpixel_2bpp.c
RFILL_CSRC := pwfb_fillrectangle_2bpp.c
RGET_CSRC := pwfb_getrectangle_2bpp.c
TFILL_CSRC := pwfb_filltrapezoid_2bpp.c
RMOVE_CSRC := pwfb_moverectangle_2bpp.c
RCOPY_CSRC := pwfb_copyrectangle_2bpp.c
endif
ifeq ($(NXGLIB_BITSPERPIXEL),4)
NXGLIB_SUFFIX := _4bpp
SETP_CSRC := pwfb_setpixel_4bpp.c
RFILL_CSRC := pwfb_fillrectangle_4bpp.c
RGET_CSRC := pwfb_getrectangle_4bpp.c
TFILL_CSRC := pwfb_filltrapezoid_4bpp.c
RMOVE_CSRC := pwfb_moverectangle_4bpp.c
RCOPY_CSRC := pwfb_copyrectangle_4bpp.c
endif
ifeq ($(NXGLIB_BITSPERPIXEL),8)
NXGLIB_SUFFIX := _8bpp
SETP_CSRC := pwfb_setpixel_8bpp.c
RFILL_CSRC := pwfb_fillrectangle_8bpp.c
RGET_CSRC := pwfb_getrectangle_8bpp.c
TFILL_CSRC := pwfb_filltrapezoid_8bpp.c
RMOVE_CSRC := pwfb_moverectangle_8bpp.c
RCOPY_CSRC := pwfb_copyrectangle_8bpp.c
endif
ifeq ($(NXGLIB_BITSPERPIXEL),16)
NXGLIB_SUFFIX := _16bpp
SETP_CSRC := pwfb_setpixel_16bpp.c
RFILL_CSRC := pwfb_fillrectangle_16bpp.c
RGET_CSRC := pwfb_getrectangle_16bpp.c
TFILL_CSRC := pwfb_filltrapezoid_16bpp.c
RMOVE_CSRC := pwfb_moverectangle_16bpp.c
RCOPY_CSRC := pwfb_copyrectangle_16bpp.c
endif
ifeq ($(NXGLIB_BITSPERPIXEL),24)
NXGLIB_SUFFIX := _24bpp
SETP_CSRC := pwfb_setpixel_24bpp.c
RFILL_CSRC := pwfb_fillrectangle_24bpp.c
RGET_CSRC := pwfb_getrectangle_24bpp.c
TFILL_CSRC := pwfb_filltrapezoid_24bpp.c
RMOVE_CSRC := pwfb_moverectangle_24bpp.c
RCOPY_CSRC := pwfb_copyrectangle_24bpp.c
endif
ifeq ($(NXGLIB_BITSPERPIXEL),32)
NXGLIB_SUFFIX := _32bpp
SETP_CSRC := pwfb_setpixel_32bpp.c
RFILL_CSRC := pwfb_fillrectangle_32bpp.c
RGET_CSRC := pwfb_getrectangle_32bpp.c
TFILL_CSRC := pwfb_filltrapezoid_32bpp.c
RMOVE_CSRC := pwfb_moverectangle_32bpp.c
RCOPY_CSRC := pwfb_copyrectangle_32bpp.c
endif
CPPFLAGS += -DNXGLIB_BITSPERPIXEL=$(NXGLIB_BITSPERPIXEL)
CPPFLAGS += -DNXGLIB_SUFFIX=$(NXGLIB_SUFFIX)
SETP_TMP = $(SETP_CSRC:.c=.i)
RFILL_TMP = $(RFILL_CSRC:.c=.i)
RGET_TMP = $(RGET_CSRC:.c=.i)
TFILL_TMP = $(TFILL_CSRC:.c=.i)
RMOVE_TMP = $(RMOVE_CSRC:.c=.i)
RCOPY_TMP = $(RCOPY_CSRC:.c=.i)
GEN_CSRCS = $(SETP_CSRC) $(RFILL_CSRC) $(RGET_CSRC) $(TFILL_CSRC) $(RMOVE_CSRC) $(RCOPY_CSRC)
BLITDIR = pwfb
all: $(GEN_CSRCS)
.PHONY : clean distclean
$(SETP_CSRC) : $(BLITDIR)/pwfb_setpixel.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, $(BLITDIR)/pwfb_setpixel.c, $(SETP_TMP))
$(Q) cat $(SETP_TMP) | sed -e "/^#/d" >$@
$(Q) rm -f $(SETP_TMP)
endif
$(RFILL_CSRC) : $(BLITDIR)/pwfb_fillrectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, $(BLITDIR)/pwfb_fillrectangle.c, $(RFILL_TMP))
$(Q) cat $(RFILL_TMP) | sed -e "/^#/d" >$@
$(Q) rm -f $(RFILL_TMP)
endif
$(RGET_CSRC) : $(BLITDIR)/pwfb_getrectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, $(BLITDIR)/pwfb_getrectangle.c, $(RGET_TMP))
$(Q) cat $(RGET_TMP) | sed -e "/^#/d" >$@
$(Q) rm -f $(RGET_TMP)
endif
$(TFILL_CSRC) : $(BLITDIR)/pwfb_filltrapezoid.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, $(BLITDIR)/pwfb_filltrapezoid.c, $(TFILL_TMP))
$(Q) cat $(TFILL_TMP) | sed -e "/^#/d" >$@
$(Q) rm -f $(TFILL_TMP)
endif
$(RMOVE_CSRC) : $(BLITDIR)/pwfb_moverectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, $(BLITDIR)/pwfb_moverectangle.c, $(RMOVE_TMP))
$(Q) cat $(RMOVE_TMP) | sed -e "/^#/d" >$@
$(Q) rm -f $(RMOVE_TMP)
endif
$(RCOPY_CSRC) : $(BLITDIR)/pwfb_copyrectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
$(call PREPROCESS, $(BLITDIR)/pwfb_copyrectangle.c, $(RCOPY_TMP))
$(Q) cat $(RCOPY_TMP) | sed -e "/^#/d" >$@
$(Q) rm -f $(RCOPY_TMP)
endif
clean:
$(call DELFILE, *.i)
$(call CLEAN)
distclean: clean
$(call DELFILE, pwfb_setpixel_*bpp.c)
$(call DELFILE, pwfb_fillrectangle_*bpp.c)
$(call DELFILE, pwfb_getrectangle_*bpp.c)
$(call DELFILE, pwfb_filltrapezoid_*bpp.c)
$(call DELFILE, pwfb_moverectangle_*bpp.c)
$(call DELFILE, pwfb_copyrectangle_*bpp.c)

View File

@ -236,7 +236,8 @@
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C" {
extern "C"
{
#else
#define EXTERN extern
#endif

View File

@ -68,14 +68,6 @@
static uint8_t g_wide_2bpp[4] = { 0x00, 0x55, 0xaa, 0xff };
#endif
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
@ -171,6 +163,7 @@ static inline void nxgl_fillrun_16bpp(FAR uint16_t *run, nxgl_mxpixel_t color,
static inline void nxgl_fillrun_24bpp(FAR uint32_t *run, nxgl_mxpixel_t color, size_t npixels)
{
/* Fill the run with the color (it is okay to run a fractional byte overy the end */
#warning "Assuming 24-bit color is not packed"
while (npixels-- > 0)
{
@ -192,5 +185,3 @@ static inline void nxgl_fillrun_32bpp(FAR uint32_t *run, nxgl_mxpixel_t color, s
# error "Unsupported value of NXGLIB_BITSPERPIXEL"
#endif
#endif /* __GRAPHICS_NXGLIB_NXGLIB_FILLRUN_H */

View File

@ -0,0 +1,163 @@
/****************************************************************************
* graphics/nxglib/pwfb/pwfb_copyrectangle.c
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <stdint.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxbe.h>
#include "nxglib_bitblit.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pwfb_copyrectangle_*bpp
*
* Description:
* Copy a rectangular bitmap image into the specific position in the
* framebuffer memory.
*
****************************************************************************/
void NXGL_FUNCNAME(pwfb_copyrectangle, NXGLIB_SUFFIX)
(FAR struct nxbe_window_s *bwnd, FAR const struct nxgl_rect_s *dest,
FAR const void *src, FAR const struct nxgl_point_s *origin,
unsigned int srcstride)
{
FAR const uint8_t *sline;
FAR uint8_t *dline;
unsigned int width;
unsigned int deststride;
unsigned int rows;
#if NXGLIB_BITSPERPIXEL < 8
FAR const uint8_t *sptr;
FAR uint8_t *dptr;
uint8_t leadmask;
uint8_t tailmask;
uint8_t mask;
int lnlen;
#endif
/* Get the width of the framebuffer in bytes */
deststride = bwnd->stride;
/* Get the dimensions of the rectange to fill: width in pixels,
* height in rows
*/
width = dest->pt2.x - dest->pt1.x + 1;
rows = dest->pt2.y - dest->pt1.y + 1;
#if NXGLIB_BITSPERPIXEL < 8
/* REVISIT: Doesn't the following assume 8 pixels in a byte */
# ifdef CONFIG_NX_PACKEDMSFIRST
/* Get the mask for pixels that are ordered so that they pack from the
* MS byte down.
*/
leadmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(dest->pt1.x)));
tailmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(dest->pt2.x-1)));
# else
/* Get the mask for pixels that are ordered so that they pack from the
* LS byte up.
*/
leadmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(dest->pt1.x)));
tailmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(dest->pt1.x-1)));
# endif
#endif
/* Then copy the image */
sline = (FAR const uint8_t *)src +
NXGL_SCALEX(dest->pt1.x - origin->x) +
(dest->pt1.y - origin->y) * srcstride;
dline = (FAR uint8_t *)bwnd->fbmem + dest->pt1.y * deststride +
NXGL_SCALEX(dest->pt1.x);
while (rows--)
{
#if NXGLIB_BITSPERPIXEL < 8
/* Handle masking of the fractional initial byte */
mask = leadmask;
sptr = sline;
dptr = dline;
lnlen = width;
if (lnlen > 1 && mask)
{
dptr[0] = (dptr[0] & ~mask) | (sptr[0] & mask);
mask = 0xff;
dptr++;
sptr++;
lnlen--; /* REVISIT: Is this correct? */
}
/* Handle masking of the fractional final byte */
mask &= tailmask;
if (lnlen > 0 && mask)
{
dptr[lnlen-1] = (dptr[lnlen-1] & ~mask) | (sptr[lnlen-1] & mask);
lnlen--; /* REVISIT: Is this correct? */
}
/* Handle all of the unmasked bytes in-between */
if (lnlen > 0)
{
NXGL_MEMCPY(dptr, sptr, lnlen);
}
#else
/* Copy the whole line */
NXGL_MEMCPY((NXGL_PIXEL_T *)dline, (NXGL_PIXEL_T *)sline, width);
#endif
dline += deststride;
sline += srcstride;
}
}

View File

@ -0,0 +1,162 @@
/****************************************************************************
* graphics/nxglib/fb/pwfb_fillrectangle.c
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <stdint.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxbe.h>
#include "nxglib_bitblit.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NXGLIB_SUFFIX
# error "NXGLIB_SUFFIX must be defined before including this header file"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pwfb_fillrectangle_*bpp
*
* Description:
* Fill a rectangle region in the framebuffer memory with a fixed color
*
****************************************************************************/
void NXGL_FUNCNAME(pwfb_fillrectangle, NXGLIB_SUFFIX)
(FAR struct nxbe_window_s *bwnd,
FAR const struct nxgl_rect_s *rect,
NXGL_PIXEL_T color)
{
FAR uint8_t *line;
unsigned int width;
unsigned int stride;
int rows;
#if NXGLIB_BITSPERPIXEL < 8
FAR uint8_t *dest;
uint8_t mpixel = NXGL_MULTIPIXEL(color);
uint8_t leadmask;
uint8_t tailmask;
uint8_t mask;
int lnlen;
#endif
/* Get the width of the framebuffer in bytes */
stride = bwnd->stride;
/* Get the dimensions of the rectange to fill in pixels */
width = rect->pt2.x - rect->pt1.x + 1;
rows = rect->pt2.y - rect->pt1.y + 1;
/* Get the address of the first byte in the first line to write */
line = (FAR uint8_t *)bwnd->fbmem + rect->pt1.y * stride +
NXGL_SCALEX(rect->pt1.x);
#if NXGLIB_BITSPERPIXEL < 8
# ifdef CONFIG_NX_PACKEDMSFIRST
/* Get the mask for pixels that are ordered so that they pack from the
* MS byte down.
*/
leadmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x)));
tailmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt2.x-1)));
# else
/* Get the mask for pixels that are ordered so that they pack from the
* LS byte up.
*/
leadmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt1.x)));
tailmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x-1)));
# endif
#endif
/* Then fill the rectangle line-by-line */
while (rows-- > 0)
{
#if NXGLIB_BITSPERPIXEL < 8
/* Handle masking of the fractional initial byte */
mask = leadmask;
dest = line;
lnlen = width;
if (lnlen > 1 && mask)
{
dest[0] = (dest[0] & ~mask) | (mpixel & mask);
mask = 0xff;
dest++;
lnlen--;
}
/* Handle masking of the fractional final byte */
mask &= tailmask;
if (lnlen > 0 && mask)
{
dest[lnlen-1] = (dest[lnlen-1] & ~mask) | (mpixel & mask);
lnlen--;
}
/* Handle all of the unmasked bytes in-between */
if (lnlen > 0)
{
NXGL_MEMSET(dest, (NXGL_PIXEL_T)color, lnlen);
}
#else
/* Draw the entire raster line */
NXGL_MEMSET(line, (NXGL_PIXEL_T)color, width);
#endif
line += stride;
}
}

View File

@ -0,0 +1,305 @@
/****************************************************************************
* graphics/nxglib/fb/pwfb_filltrapezoid.c
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <stdint.h>
#include <fixedmath.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxbe.h>
#include "nxglib_bitblit.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Make sure that this file is used in the proper context */
#ifndef NXGLIB_SUFFIX
# error "NXGLIB_SUFFIX must be defined before including this header file"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pwfb_filltrapezoid*bpp
*
* Description:
* Fill a trapezoidal region in the framebuffer memory with a fixed color.
* 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(pwfb_filltrapezoid, NXGLIB_SUFFIX)(
FAR struct nxbe_window_s *bwnd,
FAR const struct nxgl_trapezoid_s *trap,
FAR const struct nxgl_rect_s *bounds,
NXGL_PIXEL_T color)
{
unsigned int stride;
unsigned int width;
FAR uint8_t *dest;
FAR uint8_t *line;
int nrows;
b16_t x1;
b16_t x2;
nxgl_coord_t y1;
nxgl_coord_t y2;
b16_t dx1dy;
b16_t dx2dy;
#if NXGLIB_BITSPERPIXEL < 8
uint8_t mpixel = NXGL_MULTIPIXEL(color);
uint8_t mask;
int lnlen;
#endif
/* Get the width of the framebuffer in bytes */
stride = bwnd->stride;
/* Get the top run position and the number of rows to draw */
x1 = trap->top.x1;
x2 = trap->top.x2;
/* Calculate the number of rows to render */
y1 = trap->top.y;
y2 = trap->bot.y;
nrows = y2 - y1 + 1;
/* Calculate the slope of the left and right side of the trapezoid */
if (nrows > 1)
{
dx1dy = b16divi((trap->bot.x1 - x1), nrows - 1);
dx2dy = b16divi((trap->bot.x2 - x2), nrows - 1);
}
else
{
/* The trapezoid is a run! Use the average width. */
x1 = (x1 + trap->bot.x1) >> 1;
x2 = (x2 + trap->bot.x2) >> 1;
dx1dy = 0;
dx2dy = 0;
}
/* Perform vertical clipping */
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;
x1 += dy * dx1dy;
x2 += dy * dx2dy;
/* Clip and re-calculate the number of rows to render */
y1 = bounds->pt1.y;
nrows = y2 - y1 + 1;
}
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;
nrows = y2 - y1 + 1;
}
/* Get the address of the first byte on the first line */
line = (FAR uint8_t *)bwnd->fbmem + y1 * stride ;
/* Then fill the trapezoid line-by-line */
while (nrows--)
{
#ifdef CONFIG_NX_ANTIALIASING
b16_t frac;
#endif
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 >= bounds->pt1.x && ix1 <= bounds->pt2.x)
{
/* 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, bounds->pt1.x);
ix2 = ngl_clipr(ix2, bounds->pt2.x);
/* Get the run length for the clipped row */
width = ix2 - ix1 + 1;
#if NXGLIB_BITSPERPIXEL < 8
/* Handle masking of the fractional initial byte */
#ifdef CONFIG_NX_PACKEDMSFIRST
mask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(ix1)));
#else
mask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(ix1)));
#endif
dest = line;
lnlen = width;
if (lnlen > 1 && mask)
{
dest[0] = (dest[0] & ~mask) | (mpixel & mask);
mask = 0xff;
dest++;
lnlen--;
}
/* Handle masking of the fractional final byte */
#ifdef CONFIG_NX_PACKEDMSFIRST
mask &= (uint8_t)(0xff << (8 - NXGL_REMAINDERX(ix2)));
#else
mask &= (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(ix2)));
#endif
if (lnlen > 0 && mask)
{
dest[lnlen-1] = (dest[lnlen-1] & ~mask) | (mpixel & mask);
lnlen--;
}
/* Handle all of the unmasked bytes in-between */
if (lnlen > 0)
{
NXGL_MEMSET(dest, (NXGL_PIXEL_T)color, lnlen);
}
#else /* NXGLIB_BITSPERPIXEL < 8 */
/* Then draw the run from (line + ix1) to (line + ix2) */
dest = line + NXGL_SCALEX(ix1);
#ifdef CONFIG_NX_ANTIALIASING
/* Perform blending on the first pixel of the row */
frac = b16ONE - b16frac(x1);
NXGL_BLEND(dest, (NXGL_PIXEL_T)color, frac);
dest += NXGL_SCALEX(1);
width--;
if (width > 0)
{
/* Copy pixels between the first and last pixel of the row. */
if (width > 1)
{
NXGL_MEMSET(dest, (NXGL_PIXEL_T)color, width-1);
}
/* And blend the final pixel */
dest += NXGL_SCALEX(width-1);
frac = b16frac(x2);
NXGL_BLEND(dest, (NXGL_PIXEL_T)color, frac);
}
#else /* CONFIG_NX_ANTIALIASING */
NXGL_MEMSET(dest, (NXGL_PIXEL_T)color, width);
#endif /* CONFIG_NX_ANTIALIASING */
#endif /* NXGLIB_BITSPERPIXEL < 8 */
}
/* 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;
}
}

View File

@ -0,0 +1,187 @@
/****************************************************************************
* graphics/nxglib/fb/pwfb_getrectangle.c
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <stdint.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxbe.h>
#include "nxglib_bitblit.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: pwfb_lowresmemcpy
****************************************************************************/
#if NXGLIB_BITSPERPIXEL < 8
static inline void pwfb_lowresmemcpy(FAR uint8_t *dline,
FAR const uint8_t *sline,
unsigned int width, uint8_t leadmask,
uint8_t tailmask)
{
FAR const uint8_t *sptr;
FAR uint8_t *dptr;
uint8_t mask;
int lnlen;
/* Handle masking of the fractional initial byte */
mask = leadmask;
sptr = sline;
dptr = dline;
lnlen = width;
if (lnlen > 1 && mask)
{
dptr[0] = (dptr[0] & ~mask) | (sptr[0] & mask);
mask = 0xff;
dptr++;
sptr++;
lnlen--;
}
/* Handle masking of the fractional final byte */
mask &= tailmask;
if (lnlen > 0 && mask)
{
dptr[lnlen-1] = (dptr[lnlen-1] & ~mask) | (sptr[lnlen-1] & mask);
lnlen--;
}
/* Handle all of the unmasked bytes in-between */
if (lnlen > 0)
{
NXGL_MEMCPY(dptr, sptr, lnlen);
}
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pwfb_getrectangle_*bpp
*
* Description:
* Fetch a rectangular region from framebuffer memory. The source is
* expressed as a rectangle.
*
****************************************************************************/
void NXGL_FUNCNAME(pwfb_getrectangle, NXGLIB_SUFFIX)
(FAR struct nxbe_window_s *bwnd, FAR const struct nxgl_rect_s *rect,
FAR void *dest, unsigned int deststride)
{
FAR const uint8_t *sline;
FAR uint8_t *dline;
unsigned int width;
unsigned int fbstride;
unsigned int rows;
#if NXGLIB_BITSPERPIXEL < 8
uint8_t leadmask;
uint8_t tailmask;
#endif
/* Get the width of the framebuffer in bytes */
fbstride = bwnd->stride;
/* Get the dimensions of the rectange to copy: width in pixels, height
* in rows
*/
width = rect->pt2.x - rect->pt1.x + 1;
rows = rect->pt2.y - rect->pt1.y + 1;
#if NXGLIB_BITSPERPIXEL < 8
# ifdef CONFIG_NX_PACKEDMSFIRST
/* Get the mask for pixels that are ordered so that they pack from the
* MS byte down.
*/
leadmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x)));
tailmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt2.x-1)));
# else
/* Get the mask for pixels that are ordered so that they pack from the
* LS byte up.
*/
leadmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt1.x)));
tailmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x-1)));
# endif
#endif
/* sline = address of the first pixel in the top row of the source in
* framebuffer memory
*/
sline = (FAR uint8_t *)bwnd->fbmem + rect->pt1.y * fbstride +
NXGL_SCALEX(rect->pt1.x);
/* dline = address of the first row pixel */
dline = (FAR uint8_t *)dest;
/* Yes.. Copy the rectangle */
while (rows--)
{
/* Copy the row */
#if NXGLIB_BITSPERPIXEL < 8
pwfb_lowresmemcpy(dline, sline, width, leadmask, tailmask);
#else
NXGL_MEMCPY(dline, sline, width);
#endif
/* Point to the next source/dest row below the current one */
dline += deststride;
sline += fbstride;
}
}

View File

@ -0,0 +1,239 @@
/****************************************************************************
* graphics/nxglib/fb/pwfb_moverectangle.c
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <stdint.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxbe.h>
#include "nxglib_bitblit.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: pwfb_lowresmemcpy
****************************************************************************/
#if NXGLIB_BITSPERPIXEL < 8
static inline void pwfb_lowresmemcpy(FAR uint8_t *dline,
FAR const uint8_t *sline,
unsigned int width, uint8_t leadmask,
uint8_t tailmask)
{
FAR const uint8_t *sptr;
FAR uint8_t *dptr;
uint8_t mask;
int lnlen;
/* Handle masking of the fractional initial byte */
mask = leadmask;
sptr = sline;
dptr = dline;
lnlen = width;
if (lnlen > 1 && mask)
{
dptr[0] = (dptr[0] & ~mask) | (sptr[0] & mask);
mask = 0xff;
dptr++;
sptr++;
lnlen--;
}
/* Handle masking of the fractional final byte */
mask &= tailmask;
if (lnlen > 0 && mask)
{
dptr[lnlen-1] = (dptr[lnlen-1] & ~mask) | (sptr[lnlen-1] & mask);
lnlen--;
}
/* Handle all of the unmasked bytes in-between */
if (lnlen > 0)
{
NXGL_MEMCPY(dptr, sptr, lnlen);
}
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pwfb_moverectangle_*bpp
*
* Description:
* Move a rectangular region from location to another in the
* framebuffer memory. The source is expressed as a rectangle; the
* destination position is expressed as a point corresponding to the
* translation of the upper, left-hand corner.
*
****************************************************************************/
void NXGL_FUNCNAME(pwfb_moverectangle,NXGLIB_SUFFIX)
(FAR struct nxbe_window_s *bwnd, FAR const struct nxgl_rect_s *rect,
FAR struct nxgl_point_s *offset)
{
FAR const uint8_t *sline;
FAR uint8_t *dline;
unsigned int width;
unsigned int stride;
unsigned int rows;
#if NXGLIB_BITSPERPIXEL < 8
uint8_t leadmask;
uint8_t tailmask;
#endif
/* Get the width of the framebuffer in bytes */
stride = bwnd->stride;
/* Get the dimensions of the rectange to fill: width in pixels, height
* in rows
*/
width = rect->pt2.x - rect->pt1.x + 1;
rows = rect->pt2.y - rect->pt1.y + 1;
#if NXGLIB_BITSPERPIXEL < 8
# ifdef CONFIG_NX_PACKEDMSFIRST
/* Get the mask for pixels that are ordered so that they pack from the
* MS byte down.
*/
leadmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x)));
tailmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt2.x-1)));
# else
/* Get the mask for pixels that are ordered so that they pack from the
* LS byte up.
*/
leadmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt1.x)));
tailmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x-1)));
# endif
#endif
/* sline = address of the first pixel in the top row of the source in
* framebuffer memory
*/
sline = (FAR uint8_t *)bwnd->fbmem + rect->pt1.y * stride +
NXGL_SCALEX(rect->pt1.x);
/* dline = address of the first pixel in the top row of the destination
* in framebuffer memory. We get dline by subtract the offset from the
* source position.
*/
dline = (FAR uint8_t *)bwnd->fbmem + offset->y * stride +
NXGL_SCALEX(offset->x);
/* Case 1: Is the destination position above the displayed position?
* If the destination position is less then then the src address, then the
* destination is offset to a position below (and or to the left) of the
* source in framebuffer memory.
*/
if (offset->y < rect->pt1.y ||
(offset->y < rect->pt1.y && offset->x <= rect->pt1.x))
{
/* Yes.. Copy the rectangle from top down (i.e., adding the stride
* to move to the next, lower row) */
while (rows--)
{
/* Copy the row */
#if NXGLIB_BITSPERPIXEL < 8
pwfb_lowresmemcpy(dline, sline, width, leadmask, tailmask);
#else
NXGL_MEMCPY(dline, sline, width);
#endif
/* Point to the next source/dest row below the current one */
dline += stride;
sline += stride;
}
}
/* Case 2: No.. the destination position is above (or to the left of)
* the displayed source position
*/
else
{
/* Adjust sline and dline to point to the bottom row (+1) of the
* source and destination rectangles in framebuffer memory.
*/
unsigned int hoffset = rows * stride;
sline += hoffset;
dline += hoffset;
/* Copy the rectangle from the bottom up (i.e., subtracting stride
* to re-position to the previous, higher row)
*/
while (rows--)
{
/* Point to the next source/dest row above the current one */
dline -= stride;
sline -= stride;
/* Copy the row */
#if NXGLIB_BITSPERPIXEL < 8
pwfb_lowresmemcpy(dline, sline, width, leadmask, tailmask);
#else
NXGL_MEMCPY(dline, sline, width);
#endif
}
}
}

View File

@ -0,0 +1,141 @@
/****************************************************************************
* graphics/nxglib/fb/pwfb_setpixel.c
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <stdint.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxbe.h>
#include "nxglib_bitblit.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NXGLIB_SUFFIX
# error "NXGLIB_SUFFIX must be defined before including this header file"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pwfb_setpixel_*bpp
*
* Description:
* Draw a single pixel in frambuffer memory at the given position and with
* the given color. This is equivalent to nxgl_fillrectangle_*bpp() with
* a 1x1 rectangle but is more efficient.
*
****************************************************************************/
void NXGL_FUNCNAME(pwfb_setpixel, NXGLIB_SUFFIX)
(FAR struct nxbe_window_s *bwnd,
FAR const struct nxgl_point_s *pos,
NXGL_PIXEL_T color)
{
FAR uint8_t *dest;
#if NXGLIB_BITSPERPIXEL < 8
uint8_t shift;
uint8_t mask;
#else
FAR NXGL_PIXEL_T *pixel;
#endif
/* Get the address of the first byte of the pixel to write */
dest = (FAR uint8_t *)bwnd->fbmem + pos->y * bwnd->stride +
NXGL_SCALEX(pos->x);
#if NXGLIB_BITSPERPIXEL < 8
/* Shift the color into the proper position */
# ifdef CONFIG_NX_PACKEDMSFIRST
#if NXGLIB_BITSPERPIXEL == 1
shift = (7 - (pos->x & 7)); /* Shift is 0, 1, ... 7 */
mask = (1 << shift); /* Mask is 0x01, 0x02, .. 0x80 */
color <<= shift; /* Color is positioned under the mask */
#elif NXGLIB_BITSPERPIXEL == 2
shift = (6 - ((pos->x & 3) << 1)); /* Shift is 0, 2, 4, or 6 */
mask = (3 << shift); /* Mask is 0x03, 0x0c, 0x30, or 0xc0 */
color <<= shift; /* Color is positioned under the mask */
#elif NXGLIB_BITSPERPIXEL == 4
shift = (4 - ((pos->x & 1) << 2)); /* Shift is 0 or 4 */
mask = (15 << shift); /* Mask is 0x0f or 0xf0 */
color <<= shift; /* Color is positioned under the mask */
#else
# error "Unsupport pixel depth"
#endif
# else /* CONFIG_NX_PACKEDMSFIRST */
#if NXGLIB_BITSPERPIXEL == 1
shift = (pos->x & 7); /* Shift is 0, 1, ... 7 */
mask = (1 << shift); /* Mask is 0x01, 0x02, .. 0x80 */
color <<= shift; /* Color is positioned under the mask */
#elif NXGLIB_BITSPERPIXEL == 2
shift = (pos->x & 3) << 1; /* Shift is 0, 2, 4, or 6 */
mask = (3 << shift); /* Mask is 0x03, 0x0c, 0x30, or 0xc0 */
color <<= shift; /* Color is positioned under the mask */
#elif NXGLIB_BITSPERPIXEL == 4
shift = (pos->x & 1) << 2; /* Shift is 0 or 4 */
mask = (15 << shift); /* Mask is 0x0f or 0xf0 */
color <<= shift; /* Color is positioned under the mask */
#else
# error "Unsupport pixel depth"
#endif
#endif /* CONFIG_NX_PACKEDMSFIRST */
/* Handle masking of the fractional byte */
*dest = (*dest & ~mask) | (color & mask);
#else
/* Write the pixel (proper alignment assumed) */
pixel = (FAR NXGL_PIXEL_T *)dest;
*pixel = color;
#endif
}