-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixel.h
More file actions
32 lines (28 loc) · 746 Bytes
/
Pixel.h
File metadata and controls
32 lines (28 loc) · 746 Bytes
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
#ifndef PIXEL_H
#define PIXEL_H
#ifndef ABS
extern inline unsigned ABS(signed v) {
return v >= 0 ? v : -v;
}
#endif
union Pixel {
uint32_t index; // (when using a palette)
struct {
uint8_t b, g, r, a;
};
uint32_t value;
Pixel() : value(0) {}
Pixel(uint8_t r, uint8_t g, uint8_t b)
: r(r), g(g), b(b), a(255) {}
Pixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
: r(r), g(g), b(b), a(a) {}
Pixel(uint32_t value) : value(value) {}
unsigned colorDeltaWith(Pixel p) {
unsigned dr = ABS((signed) r - (signed) p.r),
dg = ABS((signed) g - (signed) p.g),
db = ABS((signed) b - (signed) p.b),
da = ABS((signed) a - (signed) p.a);
return dr * dr + dg * dg + db * db + da * da;
}
};
#endif