diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index fb6b3dec7..456c5108d 100755 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -111,3 +111,4 @@ and command can be executed numerous times. Add a new verify command that will write to a register, read from register, and verify that returned value. + * apps/graphics/tiff: Add a library that can be used to create TIFF files. \ No newline at end of file diff --git a/apps/graphics/Makefile b/apps/graphics/Makefile new file mode 100644 index 000000000..01775a2e3 --- /dev/null +++ b/apps/graphics/Makefile @@ -0,0 +1,72 @@ +############################################################################ +# apps/graphics/Makefile +# +# Copyright (C) 2011 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)/.config # Current configuration + +# Sub-directories + +SUBDIRS = tiff + +# Sub-directories that might need context setup + +CNTXTDIRS = + +all: nothing +.PHONY: nothing context depend clean distclean + +nothing: + +context: + @for dir in $(CNTXTDIRS) ; do \ + $(MAKE) -C $$dir context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \ + done + +depend: + @for dir in $(SUBDIRS) ; do \ + $(MAKE) -C $$dir depend TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \ + done + +clean: + @for dir in $(SUBDIRS) ; do \ + $(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \ + done + +distclean: clean + @for dir in $(SUBDIRS) ; do \ + $(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \ + done + +-include Make.dep + diff --git a/apps/graphics/tiff/Makefile b/apps/graphics/tiff/Makefile new file mode 100644 index 000000000..9fc762c9c --- /dev/null +++ b/apps/graphics/tiff/Makefile @@ -0,0 +1,93 @@ +############################################################################ +# apps/graphics/tiff/Makefile +# +# Copyright (C) 2011 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)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# NuttX NX Graphics Example. + +ASRCS = +CSRCS = tiff_addstrip.c tiff_finalize.c tiff_initialize.c tiff_utils.c + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +ifeq ($(WINTOOL),y) + BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}" +else + BIN = "$(APPDIR)/libapps$(LIBEXT)" +endif + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: context clean depend distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + @( for obj in $(OBJS) ; do \ + $(call ARCHIVE, $(BIN), $${obj}); \ + done ; ) + @touch .built + +context: + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + @rm -f *.o *~ .*.swp .built + $(call CLEAN) + +distclean: clean + @rm -f Make.dep .depend + +-include Make.dep diff --git a/apps/graphics/tiff/tiff_addstrip.c b/apps/graphics/tiff/tiff_addstrip.c new file mode 100644 index 000000000..360c71fc8 --- /dev/null +++ b/apps/graphics/tiff/tiff_addstrip.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * apps/graphics/tiff/tiff_addstrip.c + * + * Copyright (C) 2011 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 "tiff_internal.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tiff_addstrip + * + * Description: + * Add an image data strip. + * + * Input Parameters: + * info - A pointer to the caller allocated parameter passing/TIFF state instance. + * buffer - A buffer containing a single row of data. + * npixels - The number of pixels (not necessarily bytes) in the row of data. + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ****************************************************************************/ + +int tiff_addstrip(FAR struct tiff_info_s *info, FAR uint8_t *buffer, + nxgl_coord_t npixels) +{ +#warning "Missing logic" + return -ENOSYS; +} + diff --git a/apps/graphics/tiff/tiff_finalize.c b/apps/graphics/tiff/tiff_finalize.c new file mode 100644 index 000000000..de9011833 --- /dev/null +++ b/apps/graphics/tiff/tiff_finalize.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * apps/graphics/tiff/tiff_finalize.c + * + * Copyright (C) 2011 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 + +#include "tiff_internal.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tiff_finalize + * + * Description: + * Finalize the TIFF output file, completing the TIFF file creation steps. + * + * Input Parameters: + * info - A pointer to the caller allocated parameter passing/TIFF state + * instance. + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ****************************************************************************/ + +int tiff_finalize(FAR struct tiff_info_s *info) +{ + int ret = -EINVAL; + + DEBUGASSERT(info && info->outfd >= 0 && info->tmp1fd >= 0 && info->tmp2fd >= 0); + + /* Fix-up the StripOffsets and StripByteCounts IFD entries in the outfile */ +#warning "Missing logic" + + /* Append the StripOffsets and StripByteCounts entries to the outfile */ +#warning "Missing logic" + + /* Append the strip image data to the outfile */ +#warning "Missing logic" + + /* Close all files */ + + (void)close(info->outfd); + (void)close(info->tmp1fd); + (void)close(info->tmp2fd); + info->outfd = -1; + info->tmp1fd = -1; + info->tmp2fd = -1; + + /* And remove the temporary files */ +#warning "Missing logic" + return ret; +} + diff --git a/apps/graphics/tiff/tiff_initialize.c b/apps/graphics/tiff/tiff_initialize.c new file mode 100644 index 000000000..8998f37c4 --- /dev/null +++ b/apps/graphics/tiff/tiff_initialize.c @@ -0,0 +1,190 @@ +/**************************************************************************** + * apps/graphics/tiff/tiff_initialize.c + * + * Copyright (C) 2011 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 + +#include + +#include "tiff_internal.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tiff_writeheader + * + * Description: + * Setup to create a new TIFF file. + * + * Input Parameters: + * info - A pointer to the caller allocated parameter passing/TIFF state instance. + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ****************************************************************************/ + +static inline int tiff_writeheader(FAR struct tiff_info_s *info) +{ + struct tiff_header_s hdr; + int ret; + + /* 0-1: Byte order */ + +#ifdef CONFIG_ENDIAN_BIG + hdr.order[0] = 'M'; /* "MM"=big endian */ + hdr.order[1] = 'M'; +#else + hdr.order[0] = 'I'; /* "II"=little endian */ + hdr.order[1] = 'I'; +#endif + + /* 2-3: 42 in appropriate byte order */ + + tiff_put16(hdr.magic, 42); + + /* 4-7: Offset to the first IFD */ + + tiff_put16(hdr.offset, sizeof(struct tiff_header_s)); + + /* Write the header to the output file */ + + ret = tiff_write(info->outfd, &hdr, sizeof(struct tiff_header_s)); + if (ret == OK) + { + info->outsize = sizeof(struct tiff_header_s); + } + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tiff_initialize + * + * Description: + * Setup to create a new TIFF file. + * + * Input Parameters: + * info - A pointer to the caller allocated parameter passing/TIFF state instance. + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ****************************************************************************/ + +int tiff_initialize(FAR struct tiff_info_s *info) +{ + int ret = -EINVAL; + + DEBUGASSERT(info && info->outfile && info->tmpfile1 && info->tmpfile2); + + /* Open all output files */ + + info->outfd = open(info->outfile, O_WRONLY|O_CREAT|O_TRUNC, 0666); + if (info->outfd < 0) + { + gdbg("Failed to open %s for writing: %d\n", info->outfile, errno); + goto errout; + } + + info->tmp1fd = open(info->tmpfile1, O_WRONLY|O_CREAT|O_TRUNC, 0666); + if (info->tmp1fd < 0) + { + gdbg("Failed to open %s for writing: %d\n", info->tmpfile1, errno); + goto errout_with_outfd; + } + + info->tmp2fd = open(info->tmpfile1, O_WRONLY|O_CREAT|O_TRUNC, 0666); + if (info->tmp2fd < 0) + { + gdbg("Failed to open %s for writing: %d\n", info->tmpfile1, errno); + goto errout_with_tmp1fd; + } + + /* Write the TIFF header data to the outfile */ + + ret = tiff_writeheader(info); + if (ret < 0) + { + goto errout_with_tmp2fd; + } + + /* Write the IFD data to the outfile */ +#warning "Missing Logic" + return OK; + +errout_with_tmp2fd: + (void)close(info->tmp2fd); + info->tmp2fd = -1; +errout_with_tmp1fd: + (void)close(info->tmp1fd); + info->tmp1fd = -1; +errout_with_outfd: + (void)close(info->outfd); + info->outfd = -1; +errout: + return ret; +} + diff --git a/apps/graphics/tiff/tiff_internal.h b/apps/graphics/tiff/tiff_internal.h new file mode 100644 index 000000000..a4a8eb7fa --- /dev/null +++ b/apps/graphics/tiff/tiff_internal.h @@ -0,0 +1,99 @@ +/**************************************************************************** + * apps/graphics/tiff/tiff_internal.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __APPS_GRPHICS_TIFF_TIFF_INTERNAL_H +#define __APPS_GRPHICS_TIFF_TIFF_INTERNAL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tiff_write + * + * Description: + * Write TIFF data to the specified file + * + * Input Parameters: + * fd - Open file descriptor to write to + * buffer - Read-only buffer containing the data to be written + * count - The number of bytes to write + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ****************************************************************************/ + +EXTERN int tiff_write(int fd, FAR void *buffer, size_t count); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __APPS_GRPHICS_TIFF_TIFF_INTERNAL_H */ + diff --git a/apps/graphics/tiff/tiff_utils.c b/apps/graphics/tiff/tiff_utils.c new file mode 100644 index 000000000..13f9e6801 --- /dev/null +++ b/apps/graphics/tiff/tiff_utils.c @@ -0,0 +1,171 @@ +/**************************************************************************** + * apps/graphics/tiff/tiff_utils.c + * + * Copyright (C) 2011 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 + +#include "tiff_internal.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tiff_put16 and tiff_put32 + * + * Description: + * Put 16 and 32 values in the correct byte order at the specified position. + * + * Input Parameters: + * dest - The location to store the multi-byte data + * value - The value to be stored + * + * Returned Value: + * None + * + ****************************************************************************/ + +void tiff_put16(FAR uint8_t *dest, uint16_t value) +{ +#ifdef CONFIG_ENDIAN_BIG + *dest++ = (uint8_t)(value >> 8); + *dest = (uint8_t)(value & 0xff); +#else + *dest++ = (uint8_t)(value & 0xff); + *dest = (uint8_t)(value >> 8); +#endif +} + +void tiff_put32(FAR uint8_t *dest, uint32_t value) +{ +#ifdef CONFIG_ENDIAN_BIG + tiff_put16(dest, (uint16_t)(value >> 16)); + tiff_put16(dest+2, (uint16_t)(value & 0xffff)); +#else + tiff_put16(dest, (uint16_t)(value & 0xffff)); + tiff_put16(dest+2, (uint16_t)(value >> 16)); +#endif +} + +/**************************************************************************** + * Name: tiff_write + * + * Description: + * Write TIFF data to the specified file + * + * Input Parameters: + * fd - Open file descriptor to write to + * buffer - Read-only buffer containing the data to be written + * count - The number of bytes to write + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ****************************************************************************/ + +int tiff_write(int fd, FAR void *buffer, size_t count) +{ + ssize_t nbytes; + int errval; + + /* This loop retries the write until either: (1) it completes successfully, + * or (2) until an irrecoverble error occurs. + */ + + while (count > 0) + { + /* Do the write */ + + nbytes = write(fd, buffer, count); + + /* Check for an error */ + + if (nbytes < 0) + { + /* EINTR is not an error.. this just means that the write was + * interrupted by a signal. + */ + + errval = errno; + if (errval != EINTR) + { + /* Other errors are bad news and we will break out with an error */ + + return -errval; + } + } + + /* What if the the write returns some number of bytes other than the requested number? */ + + else + { + DEBUGASSERT(nbytes < count && nbytes != 0); + count -= nbytes; + } + } + + return OK; +} + diff --git a/apps/include/tiff.h b/apps/include/tiff.h new file mode 100644 index 000000000..96d2241c9 --- /dev/null +++ b/apps/include/tiff.h @@ -0,0 +1,392 @@ +/************************************************************************************ + * apps/include/tiff.h + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Reference: + * "TIFF, Revision 6.0, Final," June 3, 1992, Adobe Developers Association. + * + * 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. + * + ************************************************************************************/ + +#ifndef __APPS_INCLUDE_TIFF_H +#define __APPS_INCLUDE_TIFF_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#include + +/************************************************************************************ + * Pre-Processor Definitions + ************************************************************************************/ +/* Configuration ********************************************************************/ + +/* TIFF File Format Definitions *****************************************************/ +/* Values for the IFD field type */ + +#define IFD_FIELD_BYTE 1 /* 8-bit unsigned integer */ +#define IFD_FIELD_ASCII 2 /* 8-bit byte that contains a 7-bit ASCII code. + * The last byte must be NUL */ +#define IFD_FIELD_SHORT 3 /* 16-bit (2-byte) unsigned integer */ +#define IFD_FIELD_LONG 4 /* 32-bit (4-byte) unsigned integer */ +#define IFD_FIELD_RATIONAL 5 /* Two LONGs: the first represents the + * numerator of a fraction, the second the + * denominator */ +#define IFD_FIELD_SBYTE 6 /* An 8-bit signed (twos-complement) integer */ +#define IFD_FIELD_UNDEFINED 7 /* An 8-bit byte that may contain anything, + * depending on the definition of the field */ +#define IFD_FIELD_SSHORT 8 /* A 16-bit (2-byte) signed (twos-complement) + * integer */ +#define IFD_FIELD_SLONG 9 /* A 32-bit (4-byte) signed (twos-complement) + * integer */ +#define IFD_FIELD_SRATIONAL 10 /* Two SLONG’s: the first represents the + * numerator of a fraction, the second the + * denominator */ +#define IFD_FIELD_FLOAT 11 /* Single precision (4-byte) IEEE format */ +#define IFD_FIELD_DOUBLE 12 /* Double precision (8-byte) IEEE format */ + +/* Values for the IFD tag type */ + +#define IFD_TAG_NEWSUBFILETYPE 254 /* NewSubfileType, LONG */ +# define TAG_SUBFILETYPE_REDUCED (1 << 0) /* Bit 0: Reduced resolution verson of image */ +# define TAG_SUBFILETYPE_SINGLE (1 << 1) /* Bit 1: Single page of a multi-page image */ +# define TAG_SUBFILETYPE_TRANSP (1 << 2) /* Bit 2: Defines a transparency mask for image */ +#define IFD_TAG_SUBFILETYPE 255 /* SubfileType, SHORT */ +# define TAG_SUBFILETYPE_FULL 1 /* Full-resolution image data */ +# define TAG_SUBFILETYPE_REDUCED 2 /* Reduced-resolution image data */ +# define TAG_SUBFILETYPE_SINGLE 3 /* Single page of a multi-page image */ +#define IFD_TAG_IMAGEWIDTH 256 /* ImageLength, SHORT or LONG (Required) */ +#define IFD_TAG_IMAGELENGTH 257 /* ImageWidth, SHORT or LONG (Required) */ +#define IFD_TAG_BITSPERSAMPLE 258 /* BitsPerSample, SHORT (Required + * in greyscale and pallette-color image files) */ +#define IFD_TAG_COMPRESSION 259 /* Compression, SHORT (Required) */ +# define TAG_COMP_NONE 1 /* No compression */ +# define TAG_COMP_CCITT 2 /* CCITT Group 3 1-Dimensional Modified Huffman + * run length encoding */ +# define TAG_COMP_T4 3 /* CCITT T.4 bi-level encoding */ +# define TAG_COMP_T6 4 /* CCITT T.6 bi-level encoding */ +# define TAG_COMP_LZW 5 /* LZW */ +# define TAG_COMP_JPEG 6 /* LZW */ +# define TAG_COMP_NONE 32773 /* PackBits compression */ +#define IFD_TAG_PMI 262 /* PhotometricInterpretation, SHORT (Required) */ +# define TAG_PMI_WHITE 0 /* WhiteIsZero */ +# define TAG_PMI_BLACK 1 /* BlackIsZero */ +# define TAG_PMI_RGB 2 /* RGB */ +# define TAG_PMI_PALETTE 3 /* Palette color */ +# define TAG_PMI_TRANSP 4 /* Transparency mask */ +# define TAG_PMI_CMYK 5 /* CMYK */ +# define TAG_PMI_YCbCr 6 /* YCbCr */ +# define TAG_PMI_CIELAB 8 /* 1976 CIE L*a*b* */ +#define IFD_TAG_THRESHHOLDING 263 /* Threshholding, SHORT */ +# define TAG_THRESHHOLD_NONE 1 /* No dithering or halftoning has been applied */ +# define TAG_THRESHHOLD_ORDERED 2 /* Ordered dither or halftone technique has been applied */ +# define TAG_THRESHHOLD_RANDOM 3 /* Randomized process has been applied */ +#define IFD_TAG_CELLWIDTH 264 /* CellWidth, SHORT */ +#define IFD_TAG_CELLLENGTH 265 /* CellLength, SHORT */ +#define IFD_TAG_FILLORDER 266 /* FillOrder, SHORT */ +# define TAG_FILLORDER_HIGH 1 /* Lower column values are stored in the + * higher-order bits */ +# define TAG_FILLORDER_LOW 2 /* Lower column values are stored in the + * lower-order bits */ +#define IFD_TAG_DOCUMENTNAME 269 /* DocumentName, ASCII */ +#define IFD_TAG_IMAGEDESCRIPTION 270 /* ImageDescription, ASCII */ +#define IFD_TAG_MAKE 271 /* Make, ASCII */ +#define IFD_TAG_MODEL 272 /* Model, ASCII */ +#define IFD_TAG_STRIPOFFSETS 273 /* StripOffsets, SHORT or LONG (Required) */ +#define IFD_TAG_ORIENTATION 274 /* Orientation, SHORT */ +# define TAG_ORIENTATION_TL 1 /* (0,0)=top left */ +# define TAG_ORIENTATION_TR 2 /* (0,0)=top right */ +# define TAG_ORIENTATION_BR 3 /* (0,0)=bottom right */ +# define TAG_ORIENTATION_BL 4 /* (0,0)=bottom left */ +# define TAG_ORIENTATION_LT 5 /* (0,0)=left top */ +# define TAG_ORIENTATION_RT 6 /* (0,0)=right top */ +# define TAG_ORIENTATION_RB 7 /* (0,0)=right bottom */ +# define TAG_ORIENTATION_LB 8 /* (0,0)=left bottom */ +#define IFD_TAG_SAMPLESPERPIXEL 277 /* SamplesPerPixel, SHORT (Required in + * RGB full color files) */ +#define IFD_TAG_ROWSPERSTRIP 278 /* RowsPerStrip, SHORT or LONG (Required) */ +#define IFD_TAG_STRIPCOUNTS 279 /* StripByteCounts, SHORT or LONG (Required) */ +#define IFD_TAG_MINSAMPLEVALUE 280 /* MinSampleValue, SHORT */ +#define IFD_TAG_MAXSAMPLEVALUE 281 /* MaxSampleValue, SHORT */ +#define IFD_TAG_XRESOLUTION 282 /* XResolution, RATIONAL (Required) */ +#define IFD_TAG_YRESOLUTION 283 /* YResolution, RATIONAL (Required) */ +#define IFD_TAG_PLANARCONFIG 284 /* PlanarConfiguration, SHORT */ +# define TAG_PLCONFIG_CHUNKY 1 /* Chunky format */ +# define TAG_PLCONFIG_PLANAR 2 /* Planar format */ +#define IFD_TAG_PAGENAME 285 /* PageName, ASCII */ +#define IFD_TAG_XPOSITION 286 /* XPosition, RATIONAL */ +#define IFD_TAG_YPOSITION 287 /* YPosition, RATIONAL */ +#define IFD_TAG_FREEOFFSETS 288 /* FreeOffsets, LONG */ +#define IFD_TAG_FREEBYTECOUNTS 289 /* FreeByteCounts, LONG */ +#define IFD_TAG_GRAYRESPONSEUNIT 290 /* GrayResponseUnit, SHORT */ +# define TAG_GRAYRESPUNIT_10THS 1 /* Number represents tenths of a unit */ +# define TAG_GRAYRESPUNIT_100THS 2 /* Number represents hundredths of a unit */ +# define TAG_GRAYRESPUNIT_1KTHS 3 /* Number represents thousandths of a unit */ +# define TAG_GRAYRESPUNIT_10KTHS 4 /* Number represents ten-thousandths of a unit */ +# define TAG_GRAYRESPUNIT_100KTHS 5 /* Number represents hundred-thousandths of a unit */ +#define IFD_TAG_GRAYRESPONSECURVE 291 /* GrayResponseCurve, SHORT */ +#define IFD_TAG_T4OPTIONS 292 /* T4Options, LONG */ +# define TAG_T4OPTIONS_2D (1 << 0) /* 2-dimensional coding */ +# define TAG_T4OPTIONS_NONE (1 << 1) /* Uncompressed mode */ +# define TAG_T4OPTIONS_FILL (1 << 2) /* Fill bits have been added */ +#define IFD_TAG_T6OPTIONS 293 /* T6Options, LONG */ +# define TAG_T6OPTIONS_NONE (1 << 1) /* Uncompressed mode allowed */ +#define IFD_TAG_RESUNIT 296 /* ResolutionUnit, SHORT (Required) */ +# define TAG_RESUNIT_NONE 1 /* No absolute unit of measurement */ +# define TAG_RESUNIT_INCH 2 /* Inch (default) */ +# define TAG_RESUNIT_CENTIMETER 3 /* Centimeter */ +#define IFD_TAG_PAGENUMBER 297 /* PageNumber, SHORT */ +#define IFD_TAG_TRANSFERFUNCTION 301 /* TransferFunction, SHORT */ +#define IFD_TAG_SOFTWARE 305 /* Software, ASCII */ +#define IFD_TAG_DATETIME 306 /* DateTime, ASCII */ +#define IFD_TAG_ARTIST 315 /* Artist, ASCII */ +#define IFD_TAG_HOSTCOMPUTER 316 /* HostComputer, ASCII */ +#define IFD_TAG_PREDICTOR 317 /* Predictor SHORT */ +# define TAG_PREDICTOR_NONE 1 /* No prediction scheme used before coding */ +# define TAG_PREDICTOR_HORIZ 2 /* Horizontal differencing */ +#define IFD_TAG_WHITEPOINT 318 /* WhitePoint, RATIONAL */ +#define IFD_TAG_PRIMARYCHROMA 319 /* PrimaryChromaticities, RATIONAL */ +#define IFD_TAG_COLORMAP 320 /* ColorMap, SHORT (Required in palette + * color image files) */ +#define IFD_TAG_HALFTONEHINTS 321 /* HalftoneHints, SHORT */ +#define IFD_TAG_TILEWIDTH 322 /* TileWidth, SHORT or LONG */ +#define IFD_TAG_TILELENGTH 323 /* TileLength, SHORT or LONG */ +#define IFD_TAG_TILEOFFSETS 324 /* TileOffsets, LONG */ +#define IFD_TAG_TILEBYTECOUNTS 325 /* TileByteCounts, SHORT or LONG */ +#define IFD_TAG_INKSET 332 /* InkSet, SHORT */ +# define TAG_INKSET_CMYK 1 /* CMYK */ +# define TAG_INKSET_OTHER 2 /* Not CMYK */ +#define IFD_TAG_INKNAMES 333 /* InkNames, ASCII */ +#define IFD_TAG_NUMBEROFINKS 334 /* NumberOfInks, SHORT */ +#define IFD_TAG_DOTRANGE 336 /* DotRange, BYTE or SHORT */ +#define IFD_TAG_TARGETPRINTER 337 /* TargetPrinter, ASCII */ +#define IFD_TAG_EXTRASAMPLES 338 /* ExtraSamples, SHORT */ +# define TAG_EXTSAMP_UNSPEC 0 /* Unspecified */ +# define TAG_EXTSAMP_ASSOCALPHA 1 /* Associated alpha data */ +# define TAG_EXTSAMP_UNASSALPHA 2 /* Unassociated alpha data */ +#define IFD_TAG_SAMPLEFORMAT 339 /* SampleFormat, SHORT */ +# define TAG_SAMPLEFMT_UNSIGED 1 /* Unsigned integer data */ +# define TAG_SAMPLEFMT_SIGNED 2 /* Two’s complement signed integer data */ +# define TAG_SAMPLEFMT_FLOAT 3 /* IEEE floating point data */ +# define TAG_SAMPLEFMT_UNDEFINED 4 /* Undefined data format */ +#define IFD_TAG_SMINSAMPLEVALUE 340 /* SMinSampleValue, type matches sample data */ +#define IFD_TAG_SMAXSAMPLEVALUE 341 /* SMaxSampleValue, type matches sample data */ +#define IFD_TAG_TRANSFERRANGE 342 /* TransferRange, SHORT */ +#define IFD_TAG_JPEGPROC 512 /* JPEGProc, SHORT */ +#define IFD_TAG_JPEGFMT 513 /* JPEGInterchangeFormat, LONG */ +#define IFD_TAG_JPEGLENGTH 514 /* JPEGInterchangeFormatLength, LONG */ +#define IFD_TAG_JPEGRESTART 515 /* JPEGRestartInterval, SHORT */ +#define IFD_TAG_JPEGLLPREDICTORS 517 /* JPEGLosslessPredictors, SHORT */ +#define IFD_TAG_JPEGPOINTXFORMS 518 /* JPEGPointTransforms, SHORT */ +#define IFD_TAG_JPEGQTABLES 519 /* JPEGQTables, LONG */ +#define IFD_TAG_JPEGDCTABLES 520 /* JPEGDCTables, LONG */ +#define IFD_TAG_JPEGACTABLES 521 /* JPEGACTables, LONG */ +#define IFD_TAG_YCbCrCOEFFS 529 /* YCbCrCoefficients, RATIONAL */ +#define IFD_TAG_YCbCrSUBSAMPLING 530 /* YCbCrSubSampling, SHORT */ +#define IFD_TAG_YCbCrPOSITIONING 531 /* YCbCrPositioning, SHORT */ +#define IFD_TAG_REFERENCEBW 532 /* ReferenceBlackWhite, RATIONAL */ +#define IFD_TAG_COPYRIGHT 33432 /* Copyright, ASCII */ + +/************************************************************************************ + * Public Types + ************************************************************************************/ +/* TIFF File Format Structure *******************************************************/ +/* "A TIFF file begins with an 8-byte image file header that points to an + * image file directory (IFD). An image file directory contains information + * about the image, as well as pointers to the actual image data." + */ + +struct tiff_header_s +{ + uint8_t order[2]; /* 0-1: Byte order: "II"=little endian, "MM"=big endian */ + uint8_t magic[2]; /* 2-3: 42 in appropriate byte order */ + uint8_t offset[4]; /* 4-7: Offset to the first IFD */ +}; + +/* "An Image File Directory (IFD) consists of a 2-byte count of the number + * of directory entries (i.e., the number of fields), followed by a sequence + * of 12-byte field entries, followed by a 4-byte offset of the next IFD (or + * 0 if none). + * + * Each 12-byte IFD entry has the following format: + */ + +struct tiff_ifdentry_s +{ + uint8_t tag[2]; /* 0-1: The Tag that identifies the field */ + uint8_t type[2]; /* 2-3 The field Type */ + uint8_t count[4]; /* 4-7: The number of values of the indicated type */ + uint8_t offset[4]; /* 8-11: The Value Offset (or the value itself) */ +}; + +/************************************************************************************/ +/* Structures needed to interface with the TIFF file creation library )and also + * structures used only internally by the TIFF file creation library). + */ + +/* This structure describes on strip in tmpfile2 */ + +struct tiff_strip_s +{ + uint32_t offset; /* Offset to the strip data in tmpfile1 */ + uint32_t count; /* Count of pixels in the strip */ +}; + +/* These type is used to hold information about the TIFF file under + * construction + */ + +struct tiff_info_s +{ + /* The first fields are used to pass information to the TIFF file creation + * logic via tiff_initialize(). + * + * Filenames. Three file names are required. (1) path to the final + * output file and (2) two paths to temporary files. One temporary file + * (tmpfile1) will be used to hold the strip image data and the other + * (tmpfile2) will be used to hold strip offset and count information. + */ + + FAR const char *outfile; /* Full path to the final output file name */ + FAR const char *tmpfile1; /* Full path to first temporary file */ + FAR const char *tmpfile2; /* Full path to second temporary file */ + + /* The second set of fields are used only internally by the TIFF file + * creation logic. These fields must be set to zero initially by the + * caller of tiff_initialize(). User logic should not depend upon any + * definitions in the following -- they are subject to change without + * notice. + */ + + nxgl_coord_t nstrips; /* Number of strips in tmpfile3 */ + int outfd; /* outfile file descriptor */ + int tmp1fd; /* tmpfile1 file descriptor */ + int tmp2fd; /* tmpfile2 file descriptor */ + off_t outsize; /* Current size of outfile */ + off_t tmp1size; /* Current size of tmpfile1 */ + off_t sooffset; /* Offset to StripOffsets IFD entry in outfile */ + off_t sbcffset; /* Offset to StripByteCounts IFD entry in outfile */ +}; + +/************************************************************************************ + * Public Function Prototypes + ************************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/************************************************************************************ + * Name: tiff_initialize + * + * Description: + * Setup to create a new TIFF file. The overall steps to creating a TIFF file are + * as follows: + * + * 1) Create an initialize a struct tiff_info_s instance + * 2) Call tiff_initialize() to setup the file creation + * 3) Call tiff_addstrip() repeatedly to add strips to the graphic image + * 4) Call tiff_finalize() to complete the file creation. + * + * Input Parameters: + * info - A pointer to the caller allocated parameter passing/TIFF state instance. + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ************************************************************************************/ + +EXTERN int tiff_initialize(FAR struct tiff_info_s *info); + +/************************************************************************************ + * Name: tiff_addstrip + * + * Description: + * Add an image data strip. + * + * Input Parameters: + * info - A pointer to the caller allocated parameter passing/TIFF state instance. + * buffer - A buffer containing a single row of data. + * npixels - The number of pixels (not necessarily bytes) in the row of data. + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ************************************************************************************/ + +EXTERN int tiff_addstrip(FAR struct tiff_info_s *info, FAR uint8_t *buffer, + nxgl_coord_t npixels); + +/************************************************************************************ + * Name: tiff_finalize + * + * Description: + * Finalize the TIFF output file, completing the TIFF file creation steps. + * + * Input Parameters: + * info - A pointer to the caller allocated parameter passing/TIFF state instance. + * + * Returned Value: + * Zero (OK) on success. A negated errno value on failure. + * + ************************************************************************************/ + +EXTERN int tiff_finalize(FAR struct tiff_info_s *info); + +/************************************************************************************ + * Name: tiff_put16 and tiff_put32 + * + * Description: + * Put 16 and 32 values in the correct byte order at the specified position. + * + * Input Parameters: + * dest - The location to store the multi-byte data + * value - The value to be stored + * + * Returned Value: + * None + * + ************************************************************************************/ + +EXTERN void tiff_put16(FAR uint8_t *dest, uint16_t value); +EXTERN void tiff_put32(FAR uint8_t *dest, uint32_t value); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __APPS_INCLUDE_TIFF_H */ diff --git a/nuttx/graphics/nxsu/nxfe.h b/nuttx/graphics/nxsu/nxfe.h index 59e5c185d..59f5b7e61 100644 --- a/nuttx/graphics/nxsu/nxfe.h +++ b/nuttx/graphics/nxsu/nxfe.h @@ -181,5 +181,5 @@ EXTERN int nxsu_mousereport(struct nxbe_window_s *wnd); } #endif -#endif /* __GRAPHICS_NSMU_NXFE_H */ +#endif /* __GRAPHICS_NXSU_NXFE_H */