5 #include <SDL_pixels.h> 29 Uint8
r()
const {
return color().r; }
31 Uint8
g()
const {
return color().g; }
33 Uint8
b()
const {
return color().b; }
35 Uint8
a()
const {
return color().a; }
70 switch (
fmt_.BytesPerPixel)
72 case 1: *
static_cast<Uint8*
>(
target_) = static_cast<Uint8>(raw);
break;
73 case 2: *
static_cast<Uint16*
>(
target_) = static_cast<Uint16>(raw);
break;
75 if constexpr (SDL_BYTEORDER == SDL_BIG_ENDIAN)
77 static_cast<Uint8*
>(
target_)[0] = static_cast<Uint8>((raw >> 16) & 0xFF);
78 static_cast<Uint8*
>(
target_)[1] = static_cast<Uint8>((raw >> 8) & 0xFF);
79 static_cast<Uint8*
>(
target_)[2] = static_cast<Uint8>(raw & 0xFF);
83 static_cast<Uint8*
>(
target_)[0] = static_cast<Uint8>(raw & 0xFF);
84 static_cast<Uint8*
>(
target_)[1] = static_cast<Uint8>((raw >> 8) & 0xFF);
85 static_cast<Uint8*
>(
target_)[2] = static_cast<Uint8>((raw >> 16) & 0xFF);
88 case 4: *
static_cast<Uint32*
>(
target_) = raw;
break;
94 switch (
fmt_.BytesPerPixel)
96 case 1:
return *
static_cast<Uint8*
>(
target_);
97 case 2:
return *
static_cast<Uint16*
>(
target_);
99 if constexpr (SDL_BYTEORDER == SDL_BIG_ENDIAN)
101 return static_cast<Uint8*
>(
target_)[0] << 16 | static_cast<Uint8*>(
target_)[1] << 8
102 |
static_cast<Uint8*
>(
target_)[2];
106 return static_cast<Uint8*
>(
target_)[0] | static_cast<Uint8*>(
target_)[1] << 8
107 |
static_cast<Uint8*
>(
target_)[2] << 16;
109 case 4:
return *
static_cast<Uint32*
>(
target_);
Pixel & operator=(Color const &c)
Set color to this pixel via operator =.
Uint8 g() const
Get green channel as byte.
void set_b(Uint8 b)
Set blue channel from given byte.
void set_g(Uint8 g)
Set green channel from given byte.
Uint8 r() const
Get red channel as byte.
void set_raw(Uint32 raw)
Set this pixel from a 32byte value.
Pixel(void *target, SDL_PixelFormat const &fmt)
Construct a pixel structure.
void set_r(Uint8 r)
Set red channel from given byte.
C++ wrapping around the SDL_Color structure.
Uint32 get_raw() const
Get pixel as 32 bit value.
Define to deactivate exception support.
const SDL_PixelFormat & fmt_
Used pixel format on this format.
Represent a 4 channel pixel.
void set_color(Color const &c)
Set color to this pixel.
void * target_
pointer to target structure
Uint8 b() const
Get blue channel as byte.
Color color() const
Get color.
Uint8 a() const
Get alpha channel as byte.
Uint32 as_uint(SDL_PixelFormat const &format) const
Return the color of the current object as a 32bit number (4 bytes)
void set_a(Uint8 a)
Set alpha channel from given byte.