Add fill support for BPP < 8

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1335 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-11-28 18:01:10 +00:00
parent d7db3259ee
commit fada746d2d
4 changed files with 121 additions and 9 deletions

View File

@ -39,8 +39,8 @@ RFILL1_CSRCS = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
nxglib_fillrectangle_4bpp.c nxglib_fillrectangle_4bpp.c
RFILL2_CSRCS = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \ RFILL2_CSRCS = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \
nxglib_fillrectangle_24bpp.c nxglib_fillrectangle_32bpp.c nxglib_fillrectangle_24bpp.c nxglib_fillrectangle_32bpp.c
#TFILL1_CSRCS = nxglib_filltrapezoid_1bpp.c nxglib_filltrapezoid_2bpp.c \ TFILL1_CSRCS = nxglib_filltrapezoid_1bpp.c nxglib_filltrapezoid_2bpp.c \
# nxglib_filltrapezoid_4bpp.c nxglib_filltrapezoid_4bpp.c
TFILL2_CSRCS = nxglib_filltrapezoid_8bpp.c nxglib_filltrapezoid_16bpp.c \ TFILL2_CSRCS = nxglib_filltrapezoid_8bpp.c nxglib_filltrapezoid_16bpp.c \
nxglib_filltrapezoid_24bpp.c nxglib_filltrapezoid_32bpp.c nxglib_filltrapezoid_24bpp.c nxglib_filltrapezoid_32bpp.c
#RMOVE1_CSRCS = nxglib_moverectangle_1bpp.c nxglib_moverectangle_2bpp.c \ #RMOVE1_CSRCS = nxglib_moverectangle_1bpp.c nxglib_moverectangle_2bpp.c \

View File

@ -63,7 +63,7 @@
# define NXGL_PIXELSHIFT 3 # define NXGL_PIXELSHIFT 3
# define NXGL_PIXELMASK 7 # define NXGL_PIXELMASK 7
# define NXGL_MULTIPIXEL(p) ((p) ? 0xff | 0x00) # define NXGL_MULTIPIXEL(p) ((p) ? 0xff : 0x00)
# define NXGL_PIXEL_T ubyte # define NXGL_PIXEL_T ubyte
#elif NXGLIB_BITSPERPIXEL == 2 #elif NXGLIB_BITSPERPIXEL == 2

View File

@ -87,7 +87,16 @@ void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX)
ubyte *line; ubyte *line;
unsigned int width; unsigned int width;
unsigned int stride; unsigned int stride;
unsigned int rows; int rows;
#if NXGLIB_BITSPERPIXEL < 8
ubyte *dest;
ubyte mpixel = NXGL_MULTIPIXEL(color);
ubyte leadmask;
ubyte tailmask;
ubyte mask;
int lnlen;
#endif
/* Get the width of the framebuffer in bytes */ /* Get the width of the framebuffer in bytes */
@ -102,11 +111,64 @@ void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX)
line = pinfo->fbmem + rect->pt1.y * stride + NXGL_SCALEX(rect->pt1.x); line = pinfo->fbmem + rect->pt1.y * stride + NXGL_SCALEX(rect->pt1.x);
#if NXGLIB_BITSPERPIXEL < 8
# ifdef CONFIG_NXGL_PACKEDMSFIRST
/* Get the mask for pixels that are ordered so that they pack from the
* MS byte down.
*/
leadmask = (ubyte)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x)));
tailmask = (ubyte)(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 = (ubyte)(0xff << (8 - NXGL_REMAINDERX(rect->pt1.x)));
tailmask = (ubyte)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x-1)));
# endif
#endif
/* Then fill the rectangle line-by-line */ /* Then fill the rectangle line-by-line */
while (rows--) 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); NXGL_MEMSET(line, (NXGL_PIXEL_T)color, width);
#endif
line += stride; line += stride;
} }
} }

View File

@ -91,6 +91,7 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
nxgl_mxpixel_t color) nxgl_mxpixel_t color)
{ {
unsigned int stride; unsigned int stride;
unsigned int width;
ubyte *line; ubyte *line;
int nrows; int nrows;
b16_t x1; b16_t x1;
@ -100,6 +101,13 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
b16_t dx1dy; b16_t dx1dy;
b16_t dx2dy; b16_t dx2dy;
#if NXGLIB_BITSPERPIXEL < 8
ubyte *dest;
ubyte mpixel = NXGL_MULTIPIXEL(color);
ubyte mask;
int lnlen;
#endif
/* Get the width of the framebuffer in bytes */ /* Get the width of the framebuffer in bytes */
stride = pinfo->stride; stride = pinfo->stride;
@ -155,10 +163,11 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
ngl_swap(dx1dy, dx2dy, tmp); ngl_swap(dx1dy, dx2dy, tmp);
} }
/* Convert the positions to integer */ /* Convert the positions to integer and get the run width */
ix1 = b16toi(x1); ix1 = b16toi(x1);
ix2 = b16toi(x2); ix2 = b16toi(x2);
width = ix2 - ix1 + 1;
/* Handle some corner cases where we draw nothing. Otherwise, we will /* Handle some corner cases where we draw nothing. Otherwise, we will
* always draw at least one pixel. * always draw at least one pixel.
@ -174,9 +183,50 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
ix1 = ngl_clipl(ix1, bounds->pt1.x); ix1 = ngl_clipl(ix1, bounds->pt1.x);
ix2 = ngl_clipr(ix2, bounds->pt2.x); ix2 = ngl_clipr(ix2, bounds->pt2.x);
#if NXGLIB_BITSPERPIXEL < 8
/* Handle masking of the fractional initial byte */
#ifdef CONFIG_NXGL_PACKEDMSFIRST
mask = (ubyte)(0xff >> (8 - NXGL_REMAINDERX(ix1));
#else
mask = (ubyte)(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_NXGL_PACKEDMSFIRST
mask &= (ubyte)(0xff << (8 - NXGL_REMAINDERX(ix2)));
#else
mask &= (ubyte)(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) */ /* Then draw the run from (line + ix1) to (line + ix2) */
NXGL_MEMSET(line + NXGL_SCALEX(ix1), (NXGL_PIXEL_T)color, ix2 - ix1 + 1); NXGL_MEMSET(line + NXGL_SCALEX(ix1), (NXGL_PIXEL_T)color, width);
#endif
} }
/* Move to the start of the next line */ /* Move to the start of the next line */