summaryrefslogtreecommitdiff
path: root/apps/graphics
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-09-20 23:10:25 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-09-20 23:10:25 +0000
commitdfa9ad91efa32959ed7b5c971aa6181a1704455d (patch)
treefa3777e1ff36e7e438f9bc8cc16d0b3f724cccec /apps/graphics
parent0e69fff93f13982c5f90a88050bcbd8bd1e0b2d7 (diff)
downloadnuttx-dfa9ad91efa32959ed7b5c971aa6181a1704455d.tar.gz
nuttx-dfa9ad91efa32959ed7b5c971aa6181a1704455d.tar.bz2
nuttx-dfa9ad91efa32959ed7b5c971aa6181a1704455d.zip
More TIFF logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3965 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/graphics')
-rw-r--r--apps/graphics/tiff/tiff_addstrip.c8
-rw-r--r--apps/graphics/tiff/tiff_initialize.c331
2 files changed, 325 insertions, 14 deletions
diff --git a/apps/graphics/tiff/tiff_addstrip.c b/apps/graphics/tiff/tiff_addstrip.c
index 360c71fc8..a31b6622d 100644
--- a/apps/graphics/tiff/tiff_addstrip.c
+++ b/apps/graphics/tiff/tiff_addstrip.c
@@ -75,20 +75,20 @@
* Name: tiff_addstrip
*
* Description:
- * Add an image data strip.
+ * Add an image data strip. The size of the strip in pixels must be equal
+ * to the RowsPerStrip x ImageWidth values that were provided to
+ * tiff_initialize().
*
* 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)
+int tiff_addstrip(FAR struct tiff_info_s *info, FAR uint8_t *strip)
{
#warning "Missing logic"
return -ENOSYS;
diff --git a/apps/graphics/tiff/tiff_initialize.c b/apps/graphics/tiff/tiff_initialize.c
index 8998f37c4..9c17e4da3 100644
--- a/apps/graphics/tiff/tiff_initialize.c
+++ b/apps/graphics/tiff/tiff_initialize.c
@@ -52,6 +52,147 @@
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
+/* Bi-level Images
+ *
+ * Offset Description Contents/Notes
+ * Header: 0 Byte Order "II" or "MM"
+ * 2 Magic Number 42
+ * 4 1st IFD offset 10
+ * 8 [2 bytes padding]
+ * IFD: 10 Number of Directory Entries 12
+ * 12 NewSubfileType
+ * 24 ImageWidth Number of columns is a user parmeter
+ * 36 ImageLength Number of rows is a user parameter
+ * 48 Compression Hard-coded no compression (for now)
+ * 60 PhotometricInterpretation Value is a user parameter
+ * 72 StripOffsets Offset and count determined at run time
+ * 84 RowsPerStrip Value is a user parameter
+ * 96 StripByteCounts Offset and count determined at run time
+ * 108 XResolution Value is a user parameter
+ * 120 YResolution Value is a user parameter
+ * 132 Resolution Unit Hard-coded to 1
+ * 144 Software
+ * 156 DateTime
+ * 168 Next IFD offset 0
+ * 170 [2 bytes padding]
+ * Values:
+ * 172 XResolution nnnn 1, nnnn is user supplied
+ * 180 YResolution nnnn 1, nnnn is user supplied
+ * 188 "NuttX" Length = 6 (includeing NUL terminator)
+ * 194 "YYYY:MM:DD HH:MM:SS" Length = 20 (ncluding NUL terminator)
+ * 214 [2 bytes padding]
+ * 216 StripOffsets Beginning of strip offsets
+ * xxx StripByteCounts Beginning of strip byte counts
+ * xxx [Probably padding]
+ * xxx Data for strips Beginning of strip data
+ */
+
+#define TIFF_IFD_OFFSET (SIZEOF_TIFF_HEADER+2)
+
+#define TIFF_BILEV_NIFDENTRIES 12
+#define TIFF_BILEV_STRIPIFDOFFS 72
+#define TIFF_BILEV_STRIPBCIFDOFFS 96
+#define TIFF_BILEV_VALOFFSET 172
+#define TIFF_BILEV_XRESOFFSET 172
+#define TIFF_BILEV_YRESOFFSET 180
+#define TIFF_BILEV_SWOFFSET 188
+#define TIFF_BILEV_DATEOFFSET 194
+#define TIFF_BILEV_STRIPOFFSET 216
+
+/* Greyscale Images have one additional IFD entry: BitsPerSample (4 or 8)
+ *
+ * Header: 0 Byte Order "II" or "MM"
+ * 2 Magic Number 42
+ * 4 1st IFD offset 10
+ * 8 [2 bytes padding]
+ * IFD: 10 Number of Directory Entries 13
+ * 12 NewSubfileType
+ * 24 ImageWidth Number of columns is a user parmeter
+ * 36 ImageLength Number of rows is a user parameter
+ * 48 BitsPerSample
+ * 60 Compression Hard-coded no compression (for now)
+ * 72 PhotometricInterpretation Value is a user parameter
+ * 84 StripOffsets Offset and count determined at run time
+ * 96 RowsPerStrip Value is a user parameter
+ * 108 StripByteCounts Offset and count determined at run time
+ * 120 XResolution Value is a user parameter
+ * 132 YResolution Value is a user parameter
+ * 144 Resolution Unit Hard-coded to 1
+ * 156 Software
+ * 168 DateTime
+ * 180 Next IFD offset 0
+ * 182 [2 bytes padding]
+ * Values:
+ * 184 XResolution nnnn 1, nnnn is user supplied
+ * 192 YResolution nnnn 1, nnnn is user supplied
+ * 200 "NuttX" Length = 6 (includeing NUL terminator)
+ * 206 "YYYY:MM:DD HH:MM:SS" Length = 20 (ncluding NUL terminator)
+ * 226 [2 bytes padding]
+ * 228 StripOffsets Beginning of strip offsets
+ * xxx StripByteCounts Beginning of strip byte counts
+ * xxx [Probably padding]
+ * xxx Data for strips Beginning of strip data
+ */
+
+#define TIFF_GREY_NIFDENTRIES 13
+#define TIFF_GREY_STRIPIFDOFFS 84
+#define TIFF_GREY_STRIPBCIFDOFFS 108
+#define TIFF_GREY_VALOFFSET 184
+#define TIFF_GREY_XRESOFFSET 184
+#define TIFF_GREY_YRESOFFSET 192
+#define TIFF_GREY_SWOFFSET 200
+#define TIFF_GREY_DATEOFFSET 206
+#define TIFF_GREY_STRIPOFFSET 228
+
+/* RGB Images have two additional IFD entries: BitsPerSample (8,8,8) and
+ * SamplesPerPixel (3):
+ *
+ * Header: 0 Byte Order "II" or "MM"
+ * 2 Magic Number 42
+ * 4 1st IFD offset 10
+ * 8 [2 bytes padding]
+ * IFD: 10 Number of Directory Entries 14
+ * 12 NewSubfileType
+ * 24 ImageWidth Number of columns is a user parmeter
+ * 36 ImageLength Number of rows is a user parameter
+ * 48 BitsPerSample 8, 8, 8
+ * 60 Compression Hard-coded no compression (for now)
+ * 72 PhotometricInterpretation Value is a user parameter
+ * 84 StripOffsets Offset and count determined at run time
+ * 96 SamplesPerPixel Hard-coded to 3
+ * 108 RowsPerStrip Value is a user parameter
+ * 120 StripByteCounts Offset and count determined at run time
+ * 132 XResolution Value is a user parameter
+ * 144 YResolution Value is a user parameter
+ * 156 Resolution Unit Hard-coded to 1
+ * 168 Software
+ * 180 DateTime
+ * 192 Next IFD offset 0
+ * 194 [2 bytes padding]
+ * Values:
+ * 196 XResolution nnnn 1, nnnn is user supplied
+ * 204 YResolution nnnn 1, nnnn is user supplied
+ * 212 BitsPerSample 8, 8, 8
+ * 218 [2 bytes padding]
+ * 220 "NuttX" Length = 6 (includeing NUL terminator)
+ * 226 "YYYY:MM:DD HH:MM:SS" Length = 20 (ncluding NUL terminator)
+ * 246 [2 bytes padding]
+ * 248 StripOffsets Beginning of strip offsets
+ * xxx StripByteCounts Beginning of strip byte counts
+ * xxx [Probably padding]
+ * xxx Data for strips Beginning of strip data
+ */
+
+#define TIFF_RGB_NIFDENTRIES 13
+#define TIFF_RGB_STRIPIFDOFFS 84
+#define TIFF_RGB_STRIPBCIFDOFFS 120
+#define TIFF_RGB_VALOFFSET 196
+#define TIFF_RGB_XRESOFFSET 196
+#define TIFF_RGB_YRESOFFSET 204
+#define TIFF_RGB_BPSOFFSET 212
+#define TIFF_RGB_SWOFFSET 220
+#define TIFF_RGB_DATEOFFSET 226
+#define TIFF_RGB_STRIPOFFSET 248
/****************************************************************************
* Private Types
@@ -70,20 +211,46 @@
****************************************************************************/
/****************************************************************************
- * Name: tiff_writeheader
+ * Name: tiff_putint16
+ *
+ * Description:
+ * Write two bytes to the outfile.
+ *
+ * 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 int tiff_putint16(FAR struct tiff_info_s *info, uint16_t value)
+{
+ uint8_t bytes[2];
+
+ /* Write the two bytes to the output file */
+
+ tiff_put16(bytes, value);
+ return tiff_write(info->outfd, bytes, 2);
+}
+
+/****************************************************************************
+ * Name: tiff_putheader
*
* Description:
* Setup to create a new TIFF file.
*
* Input Parameters:
- * info - A pointer to the caller allocated parameter passing/TIFF state instance.
+ * 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)
+static inline int tiff_putheader(FAR struct tiff_info_s *info)
{
struct tiff_header_s hdr;
int ret;
@@ -103,17 +270,161 @@ static inline int tiff_writeheader(FAR struct tiff_info_s *info)
tiff_put16(hdr.magic, 42);
/* 4-7: Offset to the first IFD */
-
- tiff_put16(hdr.offset, sizeof(struct tiff_header_s));
+
+ tiff_put16(hdr.offset, TIFF_IFD_OFFSET);
/* Write the header to the output file */
- ret = tiff_write(info->outfd, &hdr, sizeof(struct tiff_header_s));
- if (ret == OK)
+ ret = tiff_write(info->outfd, &hdr, SIZEOF_TIFF_HEADER);
+ if (ret != OK)
{
- info->outsize = sizeof(struct tiff_header_s);
+ return ret;
}
- return ret;
+
+ /* Two pad bytes following the header */
+
+ ret = tiff_putint16(info, 0);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: tiff_putifdentry
+ *
+ * Description:
+ * Variouis IFD entry writing routines
+ *
+ * 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 int tiff_putifdentry(FAR struct tiff_info_s *info, uint16_t tag,
+ uint16_t type, uint32_t count, uint32_t offset)
+{
+ struct tiff_ifdentry_s ifd;
+ tiff_put16(ifd.tag, tag);
+ tiff_put16(ifd.type, type);
+ tiff_put32(ifd.count, count);
+ tiff_put32(ifd.offset, offset);
+ return tiff_write(info->outfd, &ifd, SIZEOF_IFD_ENTRY);
+}
+
+static int tiff_putifdentry16(FAR struct tiff_info_s *info, uint16_t tag,
+ uint16_t type, uint32_t count, uint16_t value)
+{
+ union
+ {
+ uint8_t b[4];
+ uint32_t w;
+ } u;
+
+ u.w = 0;
+ tiff_put16(u.b, value);
+ return tiff_putifdentry(info, tag, count, type, u.w);
+}
+
+/****************************************************************************
+ * Name: tiff_*
+ *
+ * Description:
+ * Variouis IFD entry writing routines
+ *
+ * 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 int tiff_newsubfiletype(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry16(info, IFD_TAG_NEWSUBFILETYPE, IFD_FIELD_LONG, 1, 0);
+}
+
+static int tiff_imagewidth(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry16(info, IFD_TAG_IMAGEWIDTH, IFD_FIELD_SHORT, 1, info->imgwidth);
+}
+
+static int tiff_imagelength(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry16(info, IFD_TAG_IMAGELENGTH, IFD_FIELD_SHORT, 1, info->imgheight);
+}
+
+static int tiff_greybitspersample(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry16(info, IFD_TAG_BITSPERSAMPLE, IFD_FIELD_SHORT, 1, info->bps);
+}
+
+static int tiff_rgbbitspersample(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry(info, IFD_TAG_BITSPERSAMPLE, IFD_FIELD_SHORT, 3, TIFF_RGB_BPSOFFSET);
+}
+
+static int tiff_compression(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry16(info, IFD_TAG_COMPRESSION, IFD_FIELD_SHORT, 1, TAG_COMP_NONE);
+}
+
+static int tiff_photointerp(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry16(info, IFD_TAG_PMI, IFD_FIELD_SHORT, 1, info->pmi);
+}
+
+static int tiff_stripoffsets(FAR struct tiff_info_s *info, uint32_t count, uint32_t offset)
+{
+ return tiff_putifdentry(info, IFD_TAG_STRIPOFFSETS, IFD_FIELD_LONG, count, offset);
+}
+
+static int tiff_samplesperpixel(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry16(info, IFD_TAG_SAMPLESPERPIXEL, IFD_FIELD_SHORT, 1, 3);
+}
+
+static int tiff_rowsperstrip(FAR struct tiff_info_s *info)
+{
+ return tiff_putifdentry16(info, IFD_TAG_ROWSPERSTRIP, IFD_FIELD_SHORT, 1, info->rps);
+}
+
+static int tiff_stripbytecounts(FAR struct tiff_info_s *info, uint32_t count, uint32_t offset)
+{
+ return tiff_putifdentry(info, IFD_TAG_STRIPCOUNTS, IFD_FIELD_LONG, count, offset);
+}
+
+static int tiff_xresolution(FAR struct tiff_info_s *info)
+{
+# warning "Missing logic"
+ return -ENOSYS;
+}
+
+static int tiff_yresolution(FAR struct tiff_info_s *info)
+{
+# warning "Missing logic"
+ return -ENOSYS;
+}
+
+static int tiff_resolutionunit(FAR struct tiff_info_s *info)
+{
+# warning "Missing logic"
+ return -ENOSYS;
+}
+
+static int tiff_software(FAR struct tiff_info_s *info)
+{
+# warning "Missing logic"
+ return -ENOSYS;
+}
+
+static int tiff_datetime(FAR struct tiff_info_s *info)
+{
+# warning "Missing logic"
+ return -ENOSYS;
}
/****************************************************************************
@@ -165,7 +476,7 @@ int tiff_initialize(FAR struct tiff_info_s *info)
/* Write the TIFF header data to the outfile */
- ret = tiff_writeheader(info);
+ ret = tiff_putheader(info);
if (ret < 0)
{
goto errout_with_tmp2fd;