| // Copyright 2026 Google LLC |
| // |
| // 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 |
| // |
| // https://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 THIRD_PARTY_CREDENTIO_FORMATS_TIFF_CONSTANTS_H_ |
| #define THIRD_PARTY_CREDENTIO_FORMATS_TIFF_CONSTANTS_H_ |
| |
| #include <cstdint> |
| |
| #include "absl/strings/string_view.h" |
| |
| namespace credentio { |
| |
| // The size of an IFD Entry: tag (2) + type (2) + count (4) + value/offset (4) |
| constexpr int64_t kTiffIfdEntrySize = 12; |
| |
| // The size of an IFD: count (2) + next offset (4) + with a single entry. |
| constexpr int64_t kTiffIdfOneEntrySize = 6 + kTiffIfdEntrySize; |
| |
| constexpr uint16_t kTiffBigEndian = 0x4d4d; |
| constexpr uint16_t kTiffLittleEndian = 0x4949; |
| |
| constexpr uint16_t kTiffMarker = 0x002a; |
| |
| constexpr uint32_t kTiffBigEndianHeader = 0x4d4d002a; |
| // This is for quick asset checking in BigEndian order if the asset is a valid |
| // LittleEndian TIFF. |
| constexpr uint32_t kTiffLittleEndianHeader = 0x49492a00; |
| |
| // This is the tag for the C2PA IFD Entry. |
| constexpr uint16_t kTiffTagC2pa = 0xcd41; |
| |
| // These are the tag pairs that are used for offsets and byte counts. |
| constexpr uint16_t kTiffTagStripOffsets = 0x0111; |
| constexpr uint16_t kTiffTagStripByteCounts = 0x0117; |
| constexpr uint16_t kTiffTagFreeOffsets = 0x0120; |
| constexpr uint16_t kTiffTagFreeByteCounts = 0x0121; |
| constexpr uint16_t kTiffTagTileOffsets = 0x0144; |
| constexpr uint16_t kTiffTagTileByteCounts = 0x0145; |
| |
| // The hex codes for IFD Entry Tags which contain Sub-IFDs. |
| constexpr uint16_t kTiffTagSubIfd = 0x014a; |
| constexpr uint16_t kTiffTagExifIfd = 0x8769; |
| constexpr uint16_t kTiffTagGpsInfo = 0x8825; |
| constexpr uint16_t kTiffTagInteroptabilityIfd = 0xA005; |
| |
| // This is the decimal tag for the GPS Info Sub-IFD converted to a string. |
| constexpr absl::string_view kTiffGpsInfoIdentifier = "34853"; |
| |
| // The maximum valid tag ID in the GPS Info Sub-IFD according to EXIF 2.32. |
| constexpr uint16_t kMaxGpsTag = 0x001f; |
| |
| // The hex codes for each of the IFD Entry Types. |
| constexpr uint16_t kTiffTypeByte = 0x0001; // uint8_t |
| constexpr uint16_t kTiffTypeAscii = 0x0002; // char |
| constexpr uint16_t kTiffTypeShort = 0x0003; // uint16_t |
| constexpr uint16_t kTiffTypeLong = 0x0004; // uint32_t |
| constexpr uint16_t kTiffTypeRational = 0x0005; // uint32_t/uint32_t |
| constexpr uint16_t kTiffTypeSByte = 0x0006; // int8_t |
| constexpr uint16_t kTiffTypeUndefined = 0x0007; // uint8_t (arbitrary data) |
| constexpr uint16_t kTiffTypeSShort = 0x0008; // int16_t |
| constexpr uint16_t kTiffTypeSLong = 0x0009; // int32_t |
| constexpr uint16_t kTiffTypeSRational = 0x000a; // int32_t/int32_t |
| constexpr uint16_t kTiffTypeFloat = 0x000b; // float (4-byte) |
| constexpr uint16_t kTiffTypeDouble = 0x000c; // double (8-byte) |
| |
| constexpr uint64_t SizeOfTiffType(uint16_t field_type) { |
| switch (field_type) { |
| case kTiffTypeByte: |
| return 1; |
| case kTiffTypeAscii: |
| return 1; |
| case kTiffTypeShort: |
| return 2; |
| case kTiffTypeLong: |
| return 4; |
| case kTiffTypeRational: |
| return 8; |
| case kTiffTypeSByte: |
| return 1; |
| case kTiffTypeUndefined: |
| return 1; |
| case kTiffTypeSShort: |
| return 2; |
| case kTiffTypeSLong: |
| return 4; |
| case kTiffTypeSRational: |
| return 8; |
| case kTiffTypeFloat: |
| return 4; |
| case kTiffTypeDouble: |
| return 8; |
| default: |
| return 1; |
| } |
| } |
| |
| constexpr uint64_t ByteSizeOfImageFileDirectory(uint16_t entry_count) { |
| return sizeof(uint16_t) + entry_count * kTiffIfdEntrySize + sizeof(uint32_t); |
| } |
| |
| } // namespace credentio |
| |
| #endif // THIRD_PARTY_CREDENTIO_FORMATS_TIFF_CONSTANTS_H_ |