TiffEntry.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_ENTRY 18#define IMG_UTILS_TIFF_ENTRY 19 20#include <img_utils/TiffWritable.h> 21#include <img_utils/TiffHelpers.h> 22#include <img_utils/EndianUtils.h> 23 24#include <cutils/compiler.h> 25#include <utils/String8.h> 26#include <utils/Errors.h> 27#include <stdint.h> 28 29namespace android { 30namespace img_utils { 31 32#define COMPARE_DEF(op) \ 33inline bool operator op (const TiffEntry& entry) const; 34 35/** 36 * This class holds a single TIFF IFD entry. 37 */ 38class ANDROID_API TiffEntry : public TiffWritable { 39 public: 40 // TODO: Copy constructor/equals here. 41 virtual ~TiffEntry(); 42 43 /** 44 * Write the 12-byte IFD entry to the output. The given offset will be 45 * set as the tag value if the size of the tag value exceeds the max 46 * size for the TIFF Value field (4 bytes), and should be word aligned. 47 * 48 * Returns OK on success, or a negative error code on failure. 49 */ 50 virtual status_t writeTagInfo(uint32_t offset, /*out*/EndianOutput* out) const = 0; 51 52 /** 53 * Get the count set for this entry. This corresponds to the TIFF Count 54 * field. 55 */ 56 virtual uint32_t getCount() const = 0; 57 58 /** 59 * Get the tag id set for this entry. This corresponds to the TIFF Tag 60 * field. 61 */ 62 virtual uint16_t getTag() const = 0; 63 64 /** 65 * Get the type set for this entry. This corresponds to the TIFF Type 66 * field. 67 */ 68 virtual TagType getType() const = 0; 69 70 /** 71 * Get the defined endianness for this entry. If this is defined, 72 * the tag value will be written with the given byte order. 73 */ 74 virtual Endianness getEndianness() const = 0; 75 76 /** 77 * Get the value for this entry. This corresponds to the TIFF Value 78 * field. 79 * 80 * Returns NULL if the value is NULL, or if the type used does not 81 * match the type of this tag. 82 */ 83 template<typename T> 84 const T* getData() const; 85 86 String8 toString() const; 87 88 /** 89 * Force the type used here to be a valid TIFF type. 90 * 91 * Returns NULL if the given value is NULL, or if the type given does 92 * not match the type of the value given. 93 */ 94 template<typename T> 95 static const T* forceValidType(TagType type, const T* value); 96 97 virtual const void* getDataHelper() const = 0; 98 99 COMPARE_DEF(>) 100 COMPARE_DEF(<) 101 102 protected: 103 enum { 104 MAX_PRINT_STRING_LENGTH = 256 105 }; 106}; 107 108#define COMPARE(op) \ 109bool TiffEntry::operator op (const TiffEntry& entry) const { \ 110 return getComparableValue() op entry.getComparableValue(); \ 111} 112 113COMPARE(>) 114COMPARE(<) 115 116 117template<typename T> 118const T* TiffEntry::getData() const { 119 const T* value = reinterpret_cast<const T*>(getDataHelper()); 120 return forceValidType<T>(getType(), value); 121} 122 123#undef COMPARE 124#undef COMPARE_DEF 125 126} /*namespace img_utils*/ 127} /*namespace android*/ 128 129#endif /*IMG_UTILS_TIFF_ENTRY*/ 130