Img2Num C++ (Internal Developer Docs)  dev
API Documentation
LABPixel.h
1 #ifndef LABPIXEL_H
2 #define LABPIXEL_H
3 
4 #include <cmath>
5 
6 #include "internal/Pixel.h"
7 
8 /*
9 can support signed data types
10 preferrably float or double
11 */
12 
13 namespace ImageLib {
14 template <typename NumberT>
15 struct LABPixel : public Pixel<NumberT> {
16  // ----- Members -----
17  NumberT l, a, b;
18 
19  constexpr LABPixel(NumberT l = 0, NumberT a = 0, NumberT b = 0) : l(l), a(a), b(b) {
20  }
21 
22  // ----- Modifiers -----
23  [[nodiscard]] inline bool operator==(const LABPixel &other) const {
24  return l == other.l && a == other.a && b == other.b;
25  }
26  [[nodiscard]] inline bool operator!=(const LABPixel &other) const {
27  return !(*this == other);
28  }
29 
30  // ----- Utilities -----
31  inline void setGray(NumberT new_luma) {
32  l = new_luma;
33  a = b = 0;
34  }
35 
36  static inline float colorDistance(const LABPixel<NumberT> &a, const LABPixel<NumberT> &b) {
37  LABPixel<float> af{static_cast<float>(a.l), static_cast<float>(a.a),
38  static_cast<float>(a.b)};
39  LABPixel<float> bf{static_cast<float>(b.l), static_cast<float>(b.a),
40  static_cast<float>(b.b)};
41  return std::sqrt((a.l - b.l) * (a.l - b.l) + (a.a - b.a) * (a.a - b.a) +
42  (a.b - b.b) * (a.b - b.b));
43  }
44 
45 } __attribute__((packed));
46 } // namespace ImageLib
47 
48 #endif // LABPIXEL_H