diff --git a/Makefile b/Makefile index 3d0bea1687..de2dec084b 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ ADDON_DIRS := $(PCODE_DIR) $(NX_DIR) # (except for parts of FSDIRS). We will exclude FSDIRS # from the build if file descriptor support is disabled -NONFSDIRS = sched lib $(ARCH_SRC) mm examples/$(CONFIG_EXAMPLE) $(ADDON_DIRS) +NONFSDIRS = sched lib $(ARCH_SRC) mm examples/$(CONFIG_EXAMPLE) $(ADDON_DIRS) graphics/nxglib FSDIRS = fs drivers ifeq ($(CONFIG_NET),y) @@ -93,7 +93,8 @@ endif # is disabled. LINKLIBS = sched/libsched$(LIBEXT) $(ARCH_SRC)/libarch$(LIBEXT) mm/libmm$(LIBEXT) \ - lib/liblib$(LIBEXT) examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE)$(LIBEXT) + lib/liblib$(LIBEXT) examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE)$(LIBEXT) \ + graphics/nxglib/libnxglib$(LIBEXT) ifeq ($(CONFIG_NET),y) LINKLIBS += net/libnet$(LIBEXT) netutils/libnetutils$(LIBEXT) @@ -202,6 +203,9 @@ drivers/libdrivers$(LIBEXT): context pcode/libpcode$(LIBEXT): context @$(MAKE) -C pcode TOPDIR="$(TOPDIR)" libpcode$(LIBEXT) +graphics/nxglib/libnxglib$(LIBEXT): context + @$(MAKE) -C graphics/nxglib TOPDIR="$(TOPDIR)" libnxglib$(LIBEXT) + graphics/nx/libnx$(LIBEXT): context @$(MAKE) -C graphics/nx TOPDIR="$(TOPDIR)" libnx$(LIBEXT) diff --git a/graphics/nxglib/Makefile b/graphics/nxglib/Makefile new file mode 100644 index 0000000000..04ba1358c8 --- /dev/null +++ b/graphics/nxglib/Makefile @@ -0,0 +1,75 @@ +############################################################################ +# grapics/nxglib/Makefile +# +# Copyright (C) 2008 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. +# +############################################################################ + +-include $(TOPDIR)/Make.defs + +ASRCS = +AOBJS = $(ASRCS:.S=$(OBJEXT)) + +CSRCS = nxglib_rgb2yuv.c nxglib_yuv2rgb.c +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +BIN = libnxglib$(LIBEXT) + +all: $(BIN) + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +$(BIN): $(OBJS) + @( for obj in $(OBJS) ; do \ + $(call ARCHIVE, $@, $${obj}); \ + done ; ) + +.depend: Makefile $(SRCS) + @$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + @rm -f $(BIN) *~ .*.swp + $(call CLEAN) + +distclean: clean + @rm -f Make.dep .depend + +-include Make.dep diff --git a/graphics/nxglib/nxglib_rgb2yuv.c b/graphics/nxglib/nxglib_rgb2yuv.c new file mode 100644 index 0000000000..e76cf98c22 --- /dev/null +++ b/graphics/nxglib/nxglib_rgb2yuv.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * graphics/color/nxglib_rgb2yuv.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +#define b16_P0813 0x000014d0 /* 0.0813 */ +#define b16_P1140 0x00001d2f /* 0.1140 */ +#define b16_P1687 0x00002b30 /* 0.1687 */ +#define b16_P2990 0x00004c8b /* 0.2990 */ +#define b16_P3313 0x000054d0 /* 0.3313 */ +#define b16_P4187 0x00006b30 /* 0.4187 */ +#define b16_P5000 0x00008000 /* 0.5000 */ +#define b16_P5870 0x00009646 /* 0.5870 */ +#define b16_128P0 0x00800000 /* 128.0 */ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxglib_rgb2yuv + * + * Description: + * Convert 8-bit RGB triplet to 8-bit YUV triplet + * + * + ****************************************************************************/ + +void nxglib_rgb2yuv(ubyte r, ubyte g, ubyte b, ubyte *y, ubyte *u, ubyte *v) +{ + /* Per the JFIF specification: + * + * Y = (0.2990 * R) + (0.5870 * G) + (0.1140 * B) + * U = 128 - (0.1687 * R) - (0.3313 * G) + (0.5000 * B) + * V = 128 + (0.5000 * R) - (0.4187 * G) - (0.0813 * B); + */ + + *y = (ubyte)b16toi(b16muli(b16_P2990, r) + b16muli(b16_P5870, g) + b16muli(b16_P1140, b)); + *u = (ubyte)b16toi(b16_128P0 - b16muli(b16_P1687, r) - b16muli(b16_P3313, g) + b16muli(b16_P5000, b)); + *v = (ubyte)b16toi(b16_128P0 + b16muli(b16_P5000, r) - b16muli(b16_P4187, g) - b16muli(b16_P0813, b)); +} diff --git a/graphics/nxglib/nxglib_yuv2rgb.c b/graphics/nxglib/nxglib_yuv2rgb.c new file mode 100644 index 0000000000..f39a442b67 --- /dev/null +++ b/graphics/nxglib/nxglib_yuv2rgb.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * graphics/color/nxglib_yuv2rgb.c + * + * Copyright (C) 2008 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 + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +#define b16_P3441 0x0000581a /* 0.344147 */ +#define b16_P7141 0x0000b6d2 /* 0.714142 */ +#define b16_1P402 0x000166ea /* 1.402008 */ +#define b16_1P772 0x0001c5a2 /* 1.722003 */ +#define b16_128P0 0x00800000 /* 128.000000 */ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxglib_yuv2rgb + * + * Description: + * Convert 8-bit RGB triplet to 8-bit YUV triplet + * + * + ****************************************************************************/ + +void nxglib_yuv2rgb(ubyte y, ubyte u, ubyte v, ubyte *r, ubyte *g, ubyte *b) +{ + b16_t vm128 = itob16(v) - b16_128P0; + b16_t um128 = itob16(u) - b16_128P0; + + /* Per the JFIF specification: + * + * R = Y + 1.40200 * (V - 128.0) + * G = Y - 0.34414 * (U - 128.0) - 0.71414 * (V - 128.0) + * B = Y + 1.77200 * (U - 128.0) + */ + + *r = (ubyte)b16toi(itob16(y) + b16muli(b16_1P402, vm128)); + *g = (ubyte)b16toi(itob16(y) - b16muli(b16_P3441, um128) - b16muli(b16_P7141, vm128)); + *b = (ubyte)b16toi(itob16(y) + b16muli(b16_1P772, um128)); +} diff --git a/include/fixedmath.h b/include/fixedmath.h index 08eda02485..3f9e8e0e61 100644 --- a/include/fixedmath.h +++ b/include/fixedmath.h @@ -112,7 +112,8 @@ /* Conversions */ #define b8toi(a) ((a) >> 8) /* Conversion to integer */ -#define itob8(i) ((i) << 8) /* Conversion from integer */ +#define itob8(i) ((b8_t)(i) << 8) /* Conversion from integer */ +#define uitoub8(i) ((ub8_t)(i) << 8) /* Conversion from unsigned integer */ #define b8tof(b) (((float)b)/256.0) /* Conversion to float */ #define ftob8(f) (b8_t)(((f)*256.0)) /* Conversion from float */ #define b8trunc(a) ((a) & 0xff00) /* Truncate to integer b8 */ @@ -140,7 +141,8 @@ /* Conversions */ #define b16toi(a) ((a) >> 16) /* Conversion to integer */ -#define itob16(i) ((i) << 16) /* Conversion from integer */ +#define itob16(i) ((b16_t)(i) << 16) /* Conversion from integer */ +#define uitoub16(i) ((ub16_t)(i) << 16) /* Conversion from unsigned integer */ #define b16tof(b) (((float)b)/65536.0) /* Conversion to float */ #define ftob16(f) (b16_t)(((f)*65536.0)) /* Conversion from float */ #define b16trunc(a) ((a) & 0xffff0000) /* Truncate to integer */ diff --git a/include/nuttx/fb.h b/include/nuttx/fb.h index f8d9eb9f34..97b3f791d7 100644 --- a/include/nuttx/fb.h +++ b/include/nuttx/fb.h @@ -213,11 +213,11 @@ struct fb_cmap_s /* Each color component. Any may be NULL if not used */ - uint16 *red; /* Table of red values */ - uint16 *green; /* Table of red values */ - uint16 *blue; /* Table of red values */ + ubyte *red; /* Table of 8-bit red values */ + ubyte *green; /* Table of 8-bit green values */ + ubyte *blue; /* Table of 8-bit blue values */ #ifdef CONFIG_FB_TRANSPARENCY - uint16 *transp; /* Table of transparency */ + ubyte *transp; /* Table of 8-bit transparency */ #endif }; #endif