summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-28 18:01:10 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-28 18:01:10 +0000
commit6736fbdba4dd6de0f60e80afd64ede783f192b5d (patch)
tree3688ee34b38f2e96f8d8a234db1e0b1d58cb37b4
parent2bc440dc23bf8bb26198f1a853d7edf29b9c91ec (diff)
downloadnuttx-6736fbdba4dd6de0f60e80afd64ede783f192b5d.tar.gz
nuttx-6736fbdba4dd6de0f60e80afd64ede783f192b5d.tar.bz2
nuttx-6736fbdba4dd6de0f60e80afd64ede783f192b5d.zip
Add fill support for BPP < 8
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1335 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/graphics/nxglib/Make.defs4
-rw-r--r--nuttx/graphics/nxglib/nxglib_bitblit.h2
-rw-r--r--nuttx/graphics/nxglib/nxglib_fillrectangle.c66
-rw-r--r--nuttx/graphics/nxglib/nxglib_filltrapezoid.c58
4 files changed, 121 insertions, 9 deletions
diff --git a/nuttx/graphics/nxglib/Make.defs b/nuttx/graphics/nxglib/Make.defs
index de3bcf6c3..9502256cc 100644
--- a/nuttx/graphics/nxglib/Make.defs
+++ b/nuttx/graphics/nxglib/Make.defs
@@ -39,8 +39,8 @@ RFILL1_CSRCS = nxglib_fillrectangle_1bpp.c nxglib_fillrectangle_2bpp.c \
nxglib_fillrectangle_4bpp.c
RFILL2_CSRCS = nxglib_fillrectangle_8bpp.c nxglib_fillrectangle_16bpp.c \
nxglib_fillrectangle_24bpp.c nxglib_fillrectangle_32bpp.c
-#TFILL1_CSRCS = nxglib_filltrapezoid_1bpp.c nxglib_filltrapezoid_2bpp.c \
-# nxglib_filltrapezoid_4bpp.c
+TFILL1_CSRCS = nxglib_filltrapezoid_1bpp.c nxglib_filltrapezoid_2bpp.c \
+ nxglib_filltrapezoid_4bpp.c
TFILL2_CSRCS = nxglib_filltrapezoid_8bpp.c nxglib_filltrapezoid_16bpp.c \
nxglib_filltrapezoid_24bpp.c nxglib_filltrapezoid_32bpp.c
#RMOVE1_CSRCS = nxglib_moverectangle_1bpp.c nxglib_moverectangle_2bpp.c \
diff --git a/nuttx/graphics/nxglib/nxglib_bitblit.h b/nuttx/graphics/nxglib/nxglib_bitblit.h
index 523b55597..a35dd0a8b 100644
--- a/nuttx/graphics/nxglib/nxglib_bitblit.h
+++ b/nuttx/graphics/nxglib/nxglib_bitblit.h
@@ -63,7 +63,7 @@
# define NXGL_PIXELSHIFT 3
# define NXGL_PIXELMASK 7
-# define NXGL_MULTIPIXEL(p) ((p) ? 0xff | 0x00)
+# define NXGL_MULTIPIXEL(p) ((p) ? 0xff : 0x00)
# define NXGL_PIXEL_T ubyte
#elif NXGLIB_BITSPERPIXEL == 2
diff --git a/nuttx/graphics/nxglib/nxglib_fillrectangle.c b/nuttx/graphics/nxglib/nxglib_fillrectangle.c
index b5ed8d581..ca94a1092 100644
--- a/nuttx/graphics/nxglib/nxglib_fillrectangle.c
+++ b/nuttx/graphics/nxglib/nxglib_fillrectangle.c
@@ -87,7 +87,16 @@ void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX)
ubyte *line;
unsigned int width;
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 */
@@ -102,11 +111,64 @@ void NXGL_FUNCNAME(nxgl_fillrectangle,NXGLIB_SUFFIX)
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 */
- 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);
+#endif
line += stride;
}
}
diff --git a/nuttx/graphics/nxglib/nxglib_filltrapezoid.c b/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
index a4ea25e51..35ded6139 100644
--- a/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
+++ b/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
@@ -91,6 +91,7 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
nxgl_mxpixel_t color)
{
unsigned int stride;
+ unsigned int width;
ubyte *line;
int nrows;
b16_t x1;
@@ -100,6 +101,13 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
b16_t dx1dy;
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 */
stride = pinfo->stride;
@@ -155,10 +163,11 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
ngl_swap(dx1dy, dx2dy, tmp);
}
- /* Convert the positions to integer */
+ /* Convert the positions to integer and get the run width */
- ix1 = b16toi(x1);
- ix2 = b16toi(x2);
+ 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.
@@ -174,9 +183,50 @@ void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
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_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) */
- 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 */