1 #ifndef IMAGE_IO_BASE_TYPES_H_ // NOLINT 2 #define IMAGE_IO_BASE_TYPES_H_ // NOLINT 3 4 #include <cstdint> 5 #include <cstdlib> 6 7 namespace photos_editing_formats { 8 namespace image_io { 9 10 /// The various integer and byte types used in this package. 11 using Byte = std::uint8_t; 12 using Int32 = std::int32_t; 13 using Int64 = std::int64_t; 14 using UInt8 = std::uint8_t; 15 using UInt16 = std::uint16_t; 16 using UInt32 = std::uint32_t; 17 using UInt64 = std::uint64_t; 18 19 /// A Byte value and a validity flag. 20 struct ValidatedByte { ValidatedByteValidatedByte21 explicit ValidatedByte(Byte value_arg) : value(value_arg), is_valid(true) {} 22 ValidatedByte(const ValidatedByte&) = default; 23 ValidatedByte& operator=(const ValidatedByte&) = default; 24 Byte value; 25 bool is_valid; 26 }; 27 28 /// Equality operator for ValidatedByte 29 inline bool operator==(const ValidatedByte& lhs, const ValidatedByte& rhs) { 30 return lhs.value == rhs.value && lhs.is_valid == rhs.is_valid; 31 } 32 33 /// Inquality operator for ValidatedByte 34 inline bool operator!=(const ValidatedByte& lhs, const ValidatedByte& rhs) { 35 return lhs.value != rhs.value || lhs.is_valid != rhs.is_valid; 36 } 37 38 /// @return a validated byte that has a false is_valid value. InvalidByte()39inline ValidatedByte InvalidByte() { 40 ValidatedByte invalid_byte(0); 41 invalid_byte.is_valid = false; 42 return invalid_byte; 43 } 44 45 } // namespace image_io 46 } // namespace photos_editing_formats 47 48 #endif // IMAGE_IO_BASE_TYPES_H_ // NOLINT 49