summaryrefslogtreecommitdiff
path: root/includes/image_io/base/types.h
blob: ed4935067040165db5e56286f9e177a9ceb98316 (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
#ifndef IMAGE_IO_BASE_TYPES_H_  // NOLINT
#define IMAGE_IO_BASE_TYPES_H_  // NOLINT

#include <cstdint>
#include <cstdlib>

namespace photos_editing_formats {
namespace image_io {

/// The various integer and byte types used in this package.
using Byte = std::uint8_t;
using Int32 = std::int32_t;
using Int64 = std::int64_t;
using UInt8 = std::uint8_t;
using UInt16 = std::uint16_t;
using UInt32 = std::uint32_t;
using UInt64 = std::uint64_t;

/// A Byte value and a validity flag.
struct ValidatedByte {
  explicit ValidatedByte(Byte value_arg) : value(value_arg), is_valid(true) {}
  ValidatedByte(const ValidatedByte&) = default;
  ValidatedByte& operator=(const ValidatedByte&) = default;
  Byte value;
  bool is_valid;
};

/// Equality operator for ValidatedByte
inline bool operator==(const ValidatedByte& lhs, const ValidatedByte& rhs) {
  return lhs.value == rhs.value && lhs.is_valid == rhs.is_valid;
}

/// Inquality operator for ValidatedByte
inline bool operator!=(const ValidatedByte& lhs, const ValidatedByte& rhs) {
  return lhs.value != rhs.value || lhs.is_valid != rhs.is_valid;
}

/// @return a validated byte that has a false is_valid value.
inline ValidatedByte InvalidByte() {
  ValidatedByte invalid_byte(0);
  invalid_byte.is_valid = false;
  return invalid_byte;
}

}  // namespace image_io
}  // namespace photos_editing_formats

#endif // IMAGE_IO_BASE_TYPES_H_  // NOLINT