TiffIfd.h revision e507721000647a7d8afe44c63ef7fd04ef8971b1
1/*
2 * Copyright 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef IMG_UTILS_TIFF_IFD_H
18#define IMG_UTILS_TIFF_IFD_H
19
20#include <img_utils/TiffWritable.h>
21#include <img_utils/TiffEntry.h>
22#include <img_utils/Output.h>
23#include <img_utils/SortedEntryVector.h>
24
25#include <cutils/compiler.h>
26#include <utils/Errors.h>
27#include <utils/String8.h>
28#include <utils/SortedVector.h>
29#include <utils/StrongPointer.h>
30#include <stdint.h>
31
32namespace android {
33namespace img_utils {
34
35/**
36 * This class holds a single TIFF Image File Directory (IFD) structure.
37 *
38 * This maps to the TIFF IFD structure that is logically composed of:
39 * - A 2-byte field listing the number of entries.
40 * - A list of 12-byte TIFF entries.
41 * - A 4-byte offset to the next IFD.
42 */
43class ANDROID_API TiffIfd : public TiffWritable {
44    public:
45        // TODO: Copy constructor/equals here - needed for SubIfds.
46        TiffIfd(uint32_t ifdId);
47        virtual ~TiffIfd();
48
49        /**
50         * Add a TiffEntry to this IFD or replace an existing entry with the
51         * same tag ID.  No validation is done.
52         *
53         * Returns OK on success, or a negative error code on failure.
54         */
55        virtual status_t addEntry(const sp<TiffEntry>& entry);
56
57        /**
58         * Set the pointer to the next IFD.  This is used to create a linked
59         * list of IFDs as defined by the TIFF 6.0 spec., and is not included
60         * when calculating the size of IFD and entries for the getSize()
61         * method (unlike SubIFDs).
62         */
63        virtual void setNextIfd(const sp<TiffIfd>& ifd);
64
65        /**
66         * Get the pointer to the next IFD, or NULL if none exists.
67         */
68        virtual sp<TiffIfd> getNextIfd() const;
69
70        /**
71         * Write the IFD data.  This includes the IFD header, entries, footer,
72         * and the corresponding values for each entry (recursively including
73         * sub-IFDs).  The written amount should end on a word boundary, and
74         * the given offset should be word aligned.
75         *
76         * Returns OK on success, or a negative error code on failure.
77         */
78        virtual status_t writeData(uint32_t offset, /*out*/EndianOutput* out) const;
79
80        /**
81         * Get the size of the IFD. This includes the IFD header, entries, footer,
82         * and the corresponding values for each entry (recursively including
83         * any sub-IFDs).
84         */
85        virtual uint32_t getSize() const;
86
87        /**
88         * Get the id of this IFD.
89         */
90        virtual uint32_t getId() const;
91
92        /**
93         * Get an entry with the given tag ID.
94         *
95         * Returns a strong pointer to the entry if it exists, or an empty strong
96         * pointer.
97         */
98        virtual sp<TiffEntry> getEntry(uint16_t tag) const;
99
100        /**
101         * Get a formatted string representing this IFD.
102         */
103        String8 toString() const;
104
105        /**
106         * Print a formatted string representing this IFD to logcat.
107         */
108        void log() const;
109
110        /**
111         * Get value used to determine sort order.
112         */
113        virtual uint32_t getComparableValue() const;
114    protected:
115        virtual uint32_t checkAndGetOffset(uint32_t offset) const;
116        SortedEntryVector mEntries;
117        sp<TiffIfd> mNextIfd;
118        uint32_t mIfdId;
119};
120
121} /*namespace img_utils*/
122} /*namespace android*/
123
124#endif /*IMG_UTILS_TIFF_IFD_H*/
125