From 04929030ff5ae1c13f22b36db29c58b9fbcebf87 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 17 Apr 2010 03:52:05 +0000 Subject: Framework for LCD rasterizers git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2598 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/graphics/nxbe/nxbe.h | 10 +- nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c | 179 ++++++++++++++++ nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c | 116 +++++++++++ nuttx/graphics/nxglib/lcd/nxglib_filltrapezoid.c | 251 +++++++++++++++++++++++ nuttx/graphics/nxglib/lcd/nxglib_moverectangle.c | 212 +++++++++++++++++++ 5 files changed, 763 insertions(+), 5 deletions(-) create mode 100755 nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c create mode 100755 nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c create mode 100755 nuttx/graphics/nxglib/lcd/nxglib_filltrapezoid.c create mode 100755 nuttx/graphics/nxglib/lcd/nxglib_moverectangle.c (limited to 'nuttx') diff --git a/nuttx/graphics/nxbe/nxbe.h b/nuttx/graphics/nxbe/nxbe.h index 3dec64b02..ce95481b3 100644 --- a/nuttx/graphics/nxbe/nxbe.h +++ b/nuttx/graphics/nxbe/nxbe.h @@ -84,17 +84,17 @@ struct nxbe_plane_s { /* Raster operation callbacks for this bits-per-pixel value */ - void (*fillrectangle)(FAR struct fb_planeinfo_s *pinfo, + void (*fillrectangle)(FAR NX_PLANEINFOTYPE *pinfo, FAR const struct nxgl_rect_s *rect, nxgl_mxpixel_t color); - void (*filltrapezoid)(FAR struct fb_planeinfo_s *pinfo, + void (*filltrapezoid)(FAR NX_PLANEINFOTYPE *pinfo, FAR const struct nxgl_trapezoid_s *trap, FAR const struct nxgl_rect_s *bounds, nxgl_mxpixel_t color); - void (*moverectangle)(FAR struct fb_planeinfo_s *pinfo, + void (*moverectangle)(FAR NX_PLANEINFOTYPE *pinfo, FAR const struct nxgl_rect_s *rect, FAR struct nxgl_point_s *offset); - void (*copyrectangle)(FAR struct fb_planeinfo_s *pinfo, + void (*copyrectangle)(FAR NX_PLANEINFOTYPE *pinfo, FAR const struct nxgl_rect_s *dest, FAR const void *src, FAR const struct nxgl_point_s *origin, @@ -102,7 +102,7 @@ struct nxbe_plane_s /* Framebuffer plane info describing destination video plane */ - struct fb_planeinfo_s pinfo; + NX_PLANEINFOTYPE pinfo; }; /* Clipping *****************************************************************/ diff --git a/nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c b/nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c new file mode 100755 index 000000000..62307233a --- /dev/null +++ b/nuttx/graphics/nxglib/lcd/nxglib_copyrectangle.c @@ -0,0 +1,179 @@ +/**************************************************************************** + * graphics/nxglib/lcd`/nxsglib_copyrectangle.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include +#include + +#include "nxglib_bitblit.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_copyrectangle_*bpp + * + * Descripton: + * Copy a rectangular bitmap image into the specific position in the + * framebuffer memory. + * + ****************************************************************************/ + +void NXGL_FUNCNAME(nxgl_copyrectangle,NXGLIB_SUFFIX) +(FAR struct lcd_planeinfo_s *pinfo, 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 = pinfo->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 +# 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 = (const uint8_t*)src + NXGL_SCALEX(dest->pt1.x - origin->x) + (dest->pt1.y - origin->y) * srcstride; + dline = pinfo->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--; + } + + /* 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); + } +#else + /* Copy the whole line */ + + NXGL_MEMCPY((NXGL_PIXEL_T*)dline, (NXGL_PIXEL_T*)sline, width); +#endif + dline += deststride; + sline += srcstride; + } +} diff --git a/nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c b/nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c new file mode 100755 index 000000000..50f037afb --- /dev/null +++ b/nuttx/graphics/nxglib/lcd/nxglib_fillrectangle.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * graphics/nxglib/lcd/nxglib_fillrectangle.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include +#include + +#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: nxgl_fillrectangle_*bpp + * + * Descripton: + * Fill a rectangle region in the framebuffer memory with a fixed color + * + ****************************************************************************/ + +void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX) +(FAR struct lcd_planeinfo_s *pinfo, FAR const struct nxgl_rect_s *rect, nxgl_mxpixel_t color) +{ + unsigned int ncols; + unsigned int nrows; + unsigned int row; + unsigned int col; + + /* Get the dimensions of the rectange to fill in pixels */ + + ncols = rect->pt2.x - rect->pt1.x + 1; + nrows = rect->pt2.y - rect->pt1.y + 1; + + /* Fill the run buffer with the selected color */ + + for (col = 0; col < ncols; col++) + { +#if NXGLIB_BITSPERPIXEL < 8 +#elif + g_runbuffer +#endif + } + + /* Then fill the rectangle line-by-line */ + + for (row = 0; row < nrows; row++) + { + /* Draw the entire raster line */ + + (void)pinfo->putrun(row, rect->pt2.x, g_runbuffer, ncols); + } +} diff --git a/nuttx/graphics/nxglib/lcd/nxglib_filltrapezoid.c b/nuttx/graphics/nxglib/lcd/nxglib_filltrapezoid.c new file mode 100755 index 000000000..6bb9da77e --- /dev/null +++ b/nuttx/graphics/nxglib/lcd/nxglib_filltrapezoid.c @@ -0,0 +1,251 @@ +/**************************************************************************** + * graphics/nxglib/lcd/nxglib_filltrapezoid.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include +#include + +#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. + * 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(nxgl_filltrapezoid,NXGLIB_SUFFIX)( + FAR struct lcd_planeinfo_s *pinfo, + FAR const struct nxgl_trapezoid_s *trap, + FAR const struct nxgl_rect_s *bounds, + nxgl_mxpixel_t color) +{ + unsigned int stride; + unsigned int width; + 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 + FAR uint8_t *dest; + uint8_t mpixel = NXGL_MULTIPIXEL(color); + uint8_t mask; + int lnlen; +#endif + + /* 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; + + /* 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 */ + + dx1dy = b16divi((trap->bot.x1 - x1), nrows - 1); + dx2dy = b16divi((trap->bot.x2 - x2), nrows - 1); + + /* Perform vertical clipping */ + + if (y1 < bounds->pt1.y) + { + /* 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) + { + /* 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 = pinfo->fbmem + y1 * stride ; + + /* 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 and get the run width */ + + ix1 = b16toi(x1); + ix2 = b16toi(x2); + width = ix2 - ix1 + 1; + + /* 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); + +#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 + /* Then draw the run from (line + ix1) to (line + ix2) */ + + NXGL_MEMSET(line + NXGL_SCALEX(ix1), (NXGL_PIXEL_T)color, width); +#endif + } + + /* 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/graphics/nxglib/lcd/nxglib_moverectangle.c b/nuttx/graphics/nxglib/lcd/nxglib_moverectangle.c new file mode 100755 index 000000000..035f052bc --- /dev/null +++ b/nuttx/graphics/nxglib/lcd/nxglib_moverectangle.c @@ -0,0 +1,212 @@ +/**************************************************************************** + * graphics/nxglib/lcd/nxglib_moverectangle.c + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include +#include + +#include "nxglib_bitblit.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxgl_lowresmemcpy + ****************************************************************************/ + +#if NXGLIB_BITSPERPIXEL < 8 +static inline void nxgl_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: 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 lcd_planeinfo_s *pinfo, 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 = pinfo->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 + + /* Case 1: The starting position is above the display */ + + if (offset->y < 0) + { + dline = pinfo->fbmem + rect->pt1.y * stride + NXGL_SCALEX(rect->pt1.x); + sline = dline - offset->y * stride - NXGL_SCALEX(offset->x); + + while (rows--) + { +#if NXGLIB_BITSPERPIXEL < 8 + nxgl_lowresmemcpy(dline, sline, width, leadmask, tailmask); +#else + NXGL_MEMCPY(dline, sline, width); +#endif + dline += stride; + sline += stride; + } + } + + /* Case 2: It's not */ + + else + { + dline = pinfo->fbmem + rect->pt2.y * stride + NXGL_SCALEX(rect->pt1.x); + sline = dline - offset->y * stride - NXGL_SCALEX(offset->x); + + while (rows--) + { + dline -= stride; + sline -= stride; +#if NXGLIB_BITSPERPIXEL < 8 + nxgl_lowresmemcpy(dline, sline, width, leadmask, tailmask); +#else + NXGL_MEMCPY(dline, sline, width); +#endif + } + } +} -- cgit v1.2.3