Scope
pixel.h
Go to the documentation of this file.
1 #pragma once
2 
5 namespace scope {
6 
8 inline uint8_t to8(const uint16_t& shortval) {
9  return static_cast<uint8_t>(shortval >> 8);
10 }
11 
13 inline uint8_t to8hist(const uint16_t& s, const uint16_t& l, const uint16_t& u) {
14  return ( (s <= l) ? 0 : (s >= u) ? 255 : to8(s) );
15 }
16 
18 inline uint8_t to8hist_mod(const uint16_t& s, const uint16_t& l, const uint16_t& u) {
19  if ( s <= l )
20  return 0;
21  if ( s >= u )
22  return UINT8_MAX;
23  uint8_t ranged = ( (s-l) * 255 / (u-l));
24  return ranged;
25 }
26 
28 inline uint8_t to8hist_mod2(const uint16_t& s, const uint16_t& l, const uint16_t& u, const uint16_t& scaler) {
29  if ( s <= l )
30  return 0;
31  if ( s >= u )
32  return UINT8_MAX;
33  uint8_t ranged = ( (s-l) * scaler);
34  return ranged;
35 }
36 
38 struct BGRA8Pixel {
40  uint8_t B;
41 
43  uint8_t G;
44 
46  uint8_t R;
47 
49  uint8_t A;
50 
53  : B(0)
54  , G(0)
55  , R(0)
56  , A(255)
57  {}
58 
60  BGRA8Pixel(const uint8_t& val)
61  : B(val)
62  , G(val)
63  , R(val)
64  , A(255)
65  {}
66 
68  BGRA8Pixel(const uint8_t& vB, const uint8_t& vG, const uint8_t& vR)
69  : B(vB)
70  , G(vG)
71  , R(vR)
72  , A(255)
73  {}
74 
76  BGRA8Pixel& operator= (const uint8_t& val) {
77  B = G = R = val;
78  A = 255;
79  return *this;
80  }
81 
84  return BGRA8Pixel((B > (0xFF - adder.B)) ? 0xFF : B + adder.B
85  , (G > (0xFF - adder.G)) ? 0xFF : G + adder.G
86  , (R > (0xFF - adder.R)) ? 0xFF : R + adder.R);
87  }
88 
90  inline BGRA8Pixel& operator+= (const BGRA8Pixel& adder) {
91  B = (B > (0xFF - adder.B)) ? 0xFF : B + adder.B;
92  G = (G > (0xFF - adder.G)) ? 0xFF : G + adder.G;
93  R = (R > (0xFF - adder.R)) ? 0xFF : R + adder.R;
94  return *this;
95  }
96 
99  inline void to_blue(const uint8_t& val) { B = val; }
100  inline void to_green(const uint8_t& val) { G = val; }
101  inline void to_red(const uint8_t& val) { R = val; }
102  inline void to_gray(const uint8_t& val) { B = G = R = val; }
104 };
105 
106 }
uint8_t G
green value
Definition: pixel.h:43
uint8_t A
alpha value
Definition: pixel.h:49
BGRA8Pixel & operator+=(const BGRA8Pixel &adder)
satured addition (evtl do with MMX / 8 pixel at the same time because 64bit?!)
Definition: pixel.h:90
BGRA8Pixel(const uint8_t &val)
Sets all colors to val (=> gray) and alpha to opaque.
Definition: pixel.h:60
Encapsulated a 4-byte pixel in BGRA format for use with Direct2D.
Definition: pixel.h:38
uint8_t B
blue value
Definition: pixel.h:40
uint8_t R
red value
Definition: pixel.h:46
BGRA8Pixel & operator=(const uint8_t &val)
Sets all colors to val => gray and alpha to opaque.
Definition: pixel.h:76
BGRA8Pixel(const uint8_t &vB, const uint8_t &vG, const uint8_t &vR)
Sets all colors as desired.
Definition: pixel.h:68
BGRA8Pixel()
Initialize to opaque black.
Definition: pixel.h:52
BGRA8Pixel operator+(const BGRA8Pixel &adder)
satured addition (evtl do with MMX / 8 pixel at the same time because 64bit?!)
Definition: pixel.h:83