summaryrefslogtreecommitdiffstats
path: root/media/img_utils/include/img_utils/TiffWriter.h
diff options
context:
space:
mode:
Diffstat (limited to 'media/img_utils/include/img_utils/TiffWriter.h')
-rw-r--r--media/img_utils/include/img_utils/TiffWriter.h145
1 files changed, 101 insertions, 44 deletions
diff --git a/media/img_utils/include/img_utils/TiffWriter.h b/media/img_utils/include/img_utils/TiffWriter.h
index ec27fc3..b7af239 100644
--- a/media/img_utils/include/img_utils/TiffWriter.h
+++ b/media/img_utils/include/img_utils/TiffWriter.h
@@ -18,8 +18,10 @@
#define IMG_UTILS_TIFF_WRITER_H
#include <img_utils/EndianUtils.h>
+#include <img_utils/StripSource.h>
#include <img_utils/TiffEntryImpl.h>
#include <img_utils/TagDefinitions.h>
+#include <img_utils/TiffIfd.h>
#include <utils/Log.h>
#include <utils/Errors.h>
@@ -48,6 +50,10 @@ class Output;
*/
class ANDROID_API TiffWriter : public LightRefBase<TiffWriter> {
public:
+ enum SubIfdType {
+ SUBIFD = 0,
+ GPSINFO
+ };
/**
* Constructs a TiffWriter with the default tag mappings. This enables
@@ -77,6 +83,25 @@ class ANDROID_API TiffWriter : public LightRefBase<TiffWriter> {
* Write a TIFF header containing each IFD set. This will recursively
* write all SubIFDs and tags.
*
+ * Any StripSources passed in will be written to the output as image strips
+ * at the appropriate offests. The StripByteCounts, RowsPerStrip, and
+ * StripOffsets tags must be set to use this. To set these tags in a
+ * given IFD, use the addStrip method.
+ *
+ * Returns OK on success, or a negative error code on failure.
+ */
+ virtual status_t write(Output* out, StripSource** sources, size_t sourcesCount,
+ Endianness end = LITTLE);
+
+ /**
+ * Write a TIFF header containing each IFD set. This will recursively
+ * write all SubIFDs and tags.
+ *
+ * Image data for strips or tiles must be written separately at the
+ * appropriate offsets. These offsets must not fall within the file
+ * header written this way. The size of the header written is given
+ * by the getTotalSize() method.
+ *
* Returns OK on success, or a negative error code on failure.
*/
virtual status_t write(Output* out, Endianness end = LITTLE);
@@ -88,16 +113,7 @@ class ANDROID_API TiffWriter : public LightRefBase<TiffWriter> {
virtual uint32_t getTotalSize() const;
/**
- * Add the given entry to its default IFD. If that IFD does not
- * exist, it will be created.
- */
- virtual status_t addEntry(const sp<TiffEntry>& entry);
-
- /**
- * Build an entry for a known tag. This tag must be one of the tags
- * defined in one of the definition vectors this TIFF writer was constructed
- * with. The count and type are validated. If this succeeds, the resulting
- * entry will be placed in the outEntry pointer.
+ * Add an entry to the IFD with the given ID.
*
* Returns OK on success, or a negative error code on failure. Valid
* error codes for this method are:
@@ -106,16 +122,14 @@ class ANDROID_API TiffWriter : public LightRefBase<TiffWriter> {
* this tag.
* - BAD_TYPE - The type of the given data isn't compatible with the
* type required for this tag.
+ * - NAME_NOT_FOUND - No ifd exists with the given ID.
*/
- template<typename T>
- status_t buildEntry(uint16_t tag, uint32_t count, const T* data,
- /*out*/sp<TiffEntry>* outEntry) const;
+ virtual status_t addEntry(const sp<TiffEntry>& entry, uint32_t ifd);
- /**
+ /**
* Build an entry for a known tag and add it to the IFD with the given ID.
* This tag must be defined in one of the definition vectors this TIFF writer
- * was constructed with. The count and type are validated. If this succeeds,
- * the resulting entry will be placed in the outEntry pointer.
+ * was constructed with. The count and type are validated.
*
* Returns OK on success, or a negative error code on failure. Valid
* error codes for this method are:
@@ -130,18 +144,47 @@ class ANDROID_API TiffWriter : public LightRefBase<TiffWriter> {
status_t addEntry(uint16_t tag, uint32_t count, const T* data, uint32_t ifd);
/**
+ * Build an entry for a known tag. This tag must be one of the tags
+ * defined in one of the definition vectors this TIFF writer was constructed
+ * with. The count and type are validated. If this succeeds, the resulting
+ * entry will be placed in the outEntry pointer.
+ *
+ * Returns OK on success, or a negative error code on failure. Valid
+ * error codes for this method are:
+ * - BAD_INDEX - The given tag doesn't exist.
+ * - BAD_VALUE - The given count doesn't match the required count for
+ * this tag.
+ * - BAD_TYPE - The type of the given data isn't compatible with the
+ * type required for this tag.
+ */
+ template<typename T>
+ status_t buildEntry(uint16_t tag, uint32_t count, const T* data,
+ /*out*/sp<TiffEntry>* outEntry) const;
+
+ /**
+ * Convenience function to set the strip related tags for a given IFD.
+ *
+ * Call this before using a StripSource as an input to write.
+ * The following tags must be set before calling this method:
+ * - ImageWidth
+ * - ImageLength
+ * - SamplesPerPixel
+ * - BitsPerSample
+ *
+ * Returns OK on success, or a negative error code.
+ */
+ virtual status_t addStrip(uint32_t ifd);
+
+ /**
* Return the TIFF entry with the given tag ID in the IFD with the given ID,
* or an empty pointer if none exists.
*/
virtual sp<TiffEntry> getEntry(uint16_t tag, uint32_t ifd) const;
/**
- * Add the given IFD to the end of the top-level IFD chain. No
- * validation is done.
- *
- * Returns OK on success, or a negative error code on failure.
+ * Remove the TIFF entry with the given tag ID in the given IFD if it exists.
*/
- virtual status_t uncheckedAddIfd(const sp<TiffIfd>& ifd);
+ virtual void removeEntry(uint16_t tag, uint32_t ifd);
/**
* Create an empty IFD with the given ID and add it to the end of the
@@ -150,24 +193,10 @@ class ANDROID_API TiffWriter : public LightRefBase<TiffWriter> {
virtual status_t addIfd(uint32_t ifd);
/**
- * Build an entry. No validation is done.
- *
- * WARNING: Using this method can result in creating poorly formatted
- * TIFF files.
- *
- * Returns a TiffEntry with the given tag, type, count, endianness,
- * and data.
+ * Create an empty IFD with the given ID and add it as a SubIfd of the
+ * parent IFD.
*/
- template<typename T>
- static sp<TiffEntry> uncheckedBuildEntry(uint16_t tag, TagType type,
- uint32_t count, Endianness end, const T* data);
-
- /**
- * Utility function to build atag-to-definition mapping from a given
- * array of tag definitions.
- */
- static KeyedVector<uint16_t, const TagDefinition_t*> buildTagMap(
- const TagDefinition_t* definitions, size_t length);
+ virtual status_t addSubIfd(uint32_t parentIfd, uint32_t ifd, SubIfdType type = SUBIFD);
/**
* Returns the default type for the given tag ID.
@@ -181,15 +210,46 @@ class ANDROID_API TiffWriter : public LightRefBase<TiffWriter> {
virtual uint32_t getDefaultCount(uint16_t tag) const;
/**
+ * Returns true if an IFD with the given ID exists.
+ */
+ virtual bool hasIfd(uint32_t ifd) const;
+
+ /**
* Returns true if a definition exist for the given tag ID.
*/
virtual bool checkIfDefined(uint16_t tag) const;
/**
+ * Returns the name of the tag if a definition exists for the given tag
+ * ID, or null if no definition exists.
+ */
+ virtual const char* getTagName(uint16_t tag) const;
+
+ /**
* Print the currently configured IFDs and entries to logcat.
*/
virtual void log() const;
+ /**
+ * Build an entry. No validation is done.
+ *
+ * WARNING: Using this method can result in creating poorly formatted
+ * TIFF files.
+ *
+ * Returns a TiffEntry with the given tag, type, count, endianness,
+ * and data.
+ */
+ template<typename T>
+ static sp<TiffEntry> uncheckedBuildEntry(uint16_t tag, TagType type,
+ uint32_t count, Endianness end, const T* data);
+
+ /**
+ * Utility function to build atag-to-definition mapping from a given
+ * array of tag definitions.
+ */
+ static KeyedVector<uint16_t, const TagDefinition_t*> buildTagMap(
+ const TagDefinition_t* definitions, size_t length);
+
protected:
enum {
DEFAULT_NUM_TAG_MAPS = 4,
@@ -240,17 +300,14 @@ status_t TiffWriter::buildEntry(uint16_t tag, uint32_t count, const T* data,
template<typename T>
status_t TiffWriter::addEntry(uint16_t tag, uint32_t count, const T* data, uint32_t ifd) {
sp<TiffEntry> outEntry;
+
status_t ret = buildEntry<T>(tag, count, data, &outEntry);
if (ret != OK) {
ALOGE("%s: Could not build entry for tag %x.", __FUNCTION__, tag);
return ret;
}
- ssize_t index = mNamedIfds.indexOfKey(ifd);
- if (index < 0) {
- ALOGE("%s: No IFD %d set for this writer.", __FUNCTION__, ifd);
- return NAME_NOT_FOUND;
- }
- return mNamedIfds[index]->addEntry(outEntry);
+
+ return addEntry(outEntry, ifd);
}
template<typename T>