summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/graphics/tiff/tiff_addstrip.c8
-rw-r--r--apps/graphics/tiff/tiff_initialize.c331
-rw-r--r--apps/include/tiff.h15
-rw-r--r--nuttx/sched/mq_send.c2
4 files changed, 337 insertions, 19 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;
diff --git a/apps/include/tiff.h b/apps/include/tiff.h
index 96d2241c9..9fa9a434a 100644
--- a/apps/include/tiff.h
+++ b/apps/include/tiff.h
@@ -232,6 +232,7 @@ struct tiff_header_s
uint8_t magic[2]; /* 2-3: 42 in appropriate byte order */
uint8_t offset[4]; /* 4-7: Offset to the first IFD */
};
+#define SIZEOF_TIFF_HEADER 8
/* "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
@@ -248,6 +249,7 @@ struct tiff_ifdentry_s
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) */
};
+#define SIZEOF_IFD_ENTRY 12
/************************************************************************************/
/* Structures needed to interface with the TIFF file creation library )and also
@@ -281,6 +283,12 @@ struct tiff_info_s
FAR const char *tmpfile1; /* Full path to first temporary file */
FAR const char *tmpfile2; /* Full path to second temporary file */
+ uint8_t pmi; /* PhotometricInterpretation, See TAG_PMI_* definitions */
+ uint8_t bps; /* BitsPerSample, Greyscale bits per sample (4 or 8) */
+ nxgl_coord_t rps; /* RowsPerStrip */
+ nxgl_coord_t imgwidth; /* Number of columns in the image */
+ nxgl_coord_t imgheight; /* Number of rows in the image */
+
/* 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
@@ -335,20 +343,19 @@ EXTERN int tiff_initialize(FAR struct tiff_info_s *info);
* 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.
*
************************************************************************************/
-EXTERN int tiff_addstrip(FAR struct tiff_info_s *info, FAR uint8_t *buffer,
- nxgl_coord_t npixels);
+EXTERN int tiff_addstrip(FAR struct tiff_info_s *info, FAR uint8_t *strip);
/************************************************************************************
* Name: tiff_finalize
diff --git a/nuttx/sched/mq_send.c b/nuttx/sched/mq_send.c
index d4644acb3..3a2284033 100644
--- a/nuttx/sched/mq_send.c
+++ b/nuttx/sched/mq_send.c
@@ -170,7 +170,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
if (mqmsg)
{
- /* Yes, peforrm the message send. */
+ /* Yes, perform the message send. */
ret = mq_dosend(mqdes, mqmsg, msg, msglen, prio);
}