summaryrefslogtreecommitdiffstats
path: root/media/img_utils/include/img_utils/TiffEntry.h
blob: 4d672b244c074cae46fdc43b4058bd8b5a876dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMG_UTILS_TIFF_ENTRY
#define IMG_UTILS_TIFF_ENTRY

#include <img_utils/TiffWritable.h>
#include <img_utils/TiffHelpers.h>
#include <img_utils/EndianUtils.h>

#include <cutils/compiler.h>
#include <utils/String8.h>
#include <utils/Errors.h>
#include <stdint.h>

namespace android {
namespace img_utils {

#define COMPARE_DEF(op) \
inline bool operator op (const TiffEntry& entry) const;

/**
 * This class holds a single TIFF IFD entry.
 *
 * Subclasses are expected to support assignment and copying operations.
 */
class ANDROID_API TiffEntry : public TiffWritable {
    public:
        virtual ~TiffEntry();

        /**
         * Write the 12-byte IFD entry to the output. The given offset will be
         * set as the tag value if the size of the tag value exceeds the max
         * size for the TIFF Value field (4 bytes), and should be word aligned.
         *
         * Returns OK on success, or a negative error code on failure.
         */
        virtual status_t writeTagInfo(uint32_t offset, /*out*/EndianOutput* out) const = 0;

        /**
         * Get the count set for this entry. This corresponds to the TIFF Count
         * field.
         */
        virtual uint32_t getCount() const = 0;

        /**
         * Get the tag id set for this entry. This corresponds to the TIFF Tag
         * field.
         */
        virtual uint16_t getTag() const = 0;

        /**
         * Get the type set for this entry.  This corresponds to the TIFF Type
         * field.
         */
        virtual TagType getType() const = 0;

        /**
         * Get the defined endianness for this entry.  If this is defined,
         * the tag value will be written with the given byte order.
         */
        virtual Endianness getEndianness() const = 0;

        /**
         * Get the value for this entry.  This corresponds to the TIFF Value
         * field.
         *
         * Returns NULL if the value is NULL, or if the type used does not
         * match the type of this tag.
         */
        template<typename T>
        const T* getData() const;

        virtual String8 toString() const;

        /**
         * Force the type used here to be a valid TIFF type.
         *
         * Returns NULL if the given value is NULL, or if the type given does
         * not match the type of the value given.
         */
        template<typename T>
        static const T* forceValidType(TagType type, const T* value);

        virtual const void* getDataHelper() const = 0;

        COMPARE_DEF(>)
        COMPARE_DEF(<)

    protected:
        enum {
            MAX_PRINT_STRING_LENGTH = 256
        };
};

#define COMPARE(op) \
bool TiffEntry::operator op (const TiffEntry& entry) const { \
    return getComparableValue() op entry.getComparableValue(); \
}

COMPARE(>)
COMPARE(<)


template<typename T>
const T* TiffEntry::getData() const {
    const T* value = reinterpret_cast<const T*>(getDataHelper());
    return forceValidType<T>(getType(), value);
}

#undef COMPARE
#undef COMPARE_DEF

} /*namespace img_utils*/
} /*namespace android*/

#endif /*IMG_UTILS_TIFF_ENTRY*/