31 #pragma pack (push, 1)
39 return (x >> 8) & 0x00ff00ff;
44 return (x | (0x01000100 - maskPixelComponents (x))) & 0x00ff00ff;
81 return (
uint32) ((components.a << 24) | (components.r << 16) | (components.g << 8) | (components.b << 0));
83 return getNativeARGB();
92 return getInARGBMaskOrder();
94 return (
uint32) ((components.b << 24) | (components.g << 16) | (components.r << 8) | components.a);
108 forcedinline uint8 getRed() const noexcept {
return components.r; }
109 forcedinline uint8 getGreen() const noexcept {
return components.g; }
110 forcedinline uint8 getBlue() const noexcept {
return components.b; }
117 template <
class Pixel>
120 internal = src.getNativeARGB();
139 template <
class Pixel>
142 auto rb = src.getEvenBytes();
143 auto ag = src.getOddBytes();
145 const auto alpha = 0x100 - (ag >> 16);
147 rb += maskPixelComponents (getEvenBytes() * alpha);
148 ag += maskPixelComponents (getOddBytes() * alpha);
150 internal = clampPixelComponents (rb) | (clampPixelComponents (ag) << 8);
166 template <
class Pixel>
169 auto rb = maskPixelComponents (extraAlpha * src.getEvenBytes());
170 auto ag = maskPixelComponents (extraAlpha * src.getOddBytes());
172 const auto alpha = 0x100 - (ag >> 16);
174 rb += maskPixelComponents (getEvenBytes() * alpha);
175 ag += maskPixelComponents (getOddBytes() * alpha);
177 internal = clampPixelComponents (rb) | (clampPixelComponents (ag) << 8);
183 template <
class Pixel>
186 auto dEvenBytes = getEvenBytes();
187 dEvenBytes += (((src.getEvenBytes() - dEvenBytes) * amount) >> 8);
188 dEvenBytes &= 0x00ff00ff;
190 auto dOddBytes = getOddBytes();
191 dOddBytes += (((src.getOddBytes() - dOddBytes) * amount) >> 8);
192 dOddBytes &= 0x00ff00ff;
195 dOddBytes |= dEvenBytes;
196 internal = dOddBytes;
203 components.a = newAlpha;
213 internal = ((((
uint32) multiplier) * getOddBytes()) & 0xff00ff00)
214 | (((((
uint32) multiplier) * getEvenBytes()) >> 8) & 0x00ff00ff);
217 forcedinline void multiplyAlpha (
float multiplier)
noexcept
219 multiplyAlpha ((
int) (multiplier * 255.0f));
223 inline PixelARGB getUnpremultiplied() const noexcept
225 PixelARGB p (internal);
233 const auto alpha = components.a;
245 components.b = (
uint8) ((components.b * alpha + 0x7f) >> 8);
246 components.g = (
uint8) ((components.g * alpha + 0x7f) >> 8);
247 components.r = (
uint8) ((components.r * alpha + 0x7f) >> 8);
255 const auto alpha = components.a;
267 components.b = (
uint8)
jmin ((
uint32) 0xffu, (components.b * 0xffu) / alpha);
268 components.g = (
uint8)
jmin ((
uint32) 0xffu, (components.g * 0xffu) / alpha);
269 components.r = (
uint8)
jmin ((
uint32) 0xffu, (components.r * 0xffu) / alpha);
276 if (components.a < 0xff && components.a > 0)
278 const auto newUnpremultipliedLevel = (0xff * ((
int) components.r + (
int) components.g + (
int) components.b) / (3 * components.a));
280 components.r = components.g = components.b
281 = (
uint8) ((newUnpremultipliedLevel * components.a + 0x7f) >> 8);
285 components.r = components.g = components.b
286 = (uint8) (((
int) components.r + (
int) components.g + (
int) components.b) / 3);
294 enum { indexA = 0, indexR = 3, indexG = 2, indexB = 1 };
296 enum { indexA = 3, indexR = 0, indexG = 1, indexB = 2 };
300 enum { indexA = 0, indexR = 1, indexG = 2, indexB = 3 };
302 enum { indexA = 3, indexR = 2, indexG = 1, indexB = 0 };
308 PixelARGB (uint32 internalValue) noexcept
334 Components components;
380 return getNativeARGB();
389 return getInARGBMaskOrder();
391 return (
uint32) ((b << 24) | (g << 16) | (r << 8) | 0xff);
403 return (
uint32) (r | (b << 16));
405 return (
uint32) (b | (r << 16));
418 forcedinline uint8 getRed() const noexcept {
return r; }
419 forcedinline uint8 getGreen() const noexcept {
return g; }
420 forcedinline uint8 getBlue() const noexcept {
return b; }
429 template <
class Pixel>
451 template <
class Pixel>
454 const auto alpha = (
uint32) (0x100 - src.getAlpha());
457 const auto rb = clampPixelComponents (src.getEvenBytes() + maskPixelComponents (getEvenBytes() * alpha));
459 const auto ag = clampPixelComponents (src.getOddBytes() + ((g * alpha) >> 8));
461 g = (
uint8) (ag & 0xff);
464 b = (
uint8) (rb >> 16);
465 r = (
uint8) (rb & 0xff);
467 r = (
uint8) (rb >> 16);
468 b = (
uint8) (rb & 0xff);
482 template <
class Pixel>
485 auto ag = maskPixelComponents (extraAlpha * src.getOddBytes());
486 auto rb = maskPixelComponents (extraAlpha * src.getEvenBytes());
488 const auto alpha = 0x100 - (ag >> 16);
490 ag = clampPixelComponents (ag + (g * alpha >> 8));
491 rb = clampPixelComponents (rb + maskPixelComponents (getEvenBytes() * alpha));
493 g = (
uint8) (ag & 0xff);
496 b = (
uint8) (rb >> 16);
497 r = (
uint8) (rb & 0xff);
499 r = (
uint8) (rb >> 16);
500 b = (
uint8) (rb & 0xff);
507 template <
class Pixel>
510 auto dEvenBytes = getEvenBytes();
511 dEvenBytes += (((src.getEvenBytes() - dEvenBytes) * amount) >> 8);
513 auto dOddBytes = getOddBytes();
514 dOddBytes += (((src.getOddBytes() - dOddBytes) * amount) >> 8);
516 g = (
uint8) (dOddBytes & 0xff);
519 r = (
uint8) (dEvenBytes & 0xff);
520 b = (
uint8) (dEvenBytes >> 16);
522 b = (
uint8) (dEvenBytes & 0xff);
523 r = (
uint8) (dEvenBytes >> 16);
545 r = g = b = (
uint8) (((
int) r + (
int) g + (
int) b) / 3);
551 enum { indexR = 0, indexG = 1, indexB = 2 };
553 enum { indexR = 2, indexG = 1, indexB = 0 };
558 PixelRGB (uint32 internal)
noexcept
561 b = (uint8) (internal >> 16);
562 g = (uint8) (internal >> 8);
563 r = (uint8) (internal);
565 r = (uint8) (internal >> 16);
566 g = (uint8) (internal >> 8);
567 b = (uint8) (internal);
636 forcedinline uint8 getRed() const noexcept {
return 0; }
637 forcedinline uint8 getGreen() const noexcept {
return 0; }
638 forcedinline uint8 getBlue() const noexcept {
return 0; }
645 template <
class Pixel>
663 template <
class Pixel>
666 const auto srcA = src.getAlpha();
667 a = (
uint8) ((a * (0x100 - srcA) >> 8) + srcA);
675 template <
class Pixel>
679 const auto srcAlpha = (
int) ((extraAlpha * src.getAlpha()) >> 8);
680 a = (
uint8) ((a * (0x100 - srcAlpha) >> 8) + srcAlpha);
686 template <
class Pixel>
689 a += ((src.getAlpha() - a) * amount) >> 8;
703 a = (
uint8) ((a * multiplier) >> 8);
706 forcedinline void multiplyAlpha (
float multiplier)
noexcept
708 a = (
uint8) (a * multiplier);
725 PixelAlpha (uint32 internal) noexcept
726 : a ((uint8) (internal >> 24)) { }
Represents a 32-bit INTERNAL pixel with premultiplied alpha, and can perform compositing operations w...
forcedinline void tween(const Pixel &src, uint32 amount) noexcept
Blends another pixel with this one, creating a colour that is somewhere between the two,...
forcedinline void set(const Pixel &src) noexcept
Copies another pixel colour over this one.
PixelARGB() noexcept=default
Creates a pixel without defining its colour.
uint32 getInARGBMemoryOrder() const noexcept
Returns a uint32 which when written to memory, will be in the order a, r, g, b.
forcedinline uint32 getNativeARGB() const noexcept
Returns a uint32 which represents the pixel in a platform dependent format.
forcedinline void setAlpha(uint8 newAlpha) noexcept
Replaces the colour's alpha value with another one.
forcedinline void blend(const Pixel &src) noexcept
Blends another pixel onto this one.
forcedinline void unpremultiply() noexcept
Unpremultiplies the pixel's RGB values.
forcedinline uint32 getInARGBMaskOrder() const noexcept
Returns a uint32 which will be in argb order as if constructed with the following mask operation ((al...
forcedinline void blend(const Pixel &src, uint32 extraAlpha) noexcept
Blends another pixel onto this one, applying an extra multiplier to its opacity.
void setARGB(uint8 a, uint8 r, uint8 g, uint8 b) noexcept
Sets the pixel's colour from individual components.
forcedinline void premultiply() noexcept
Premultiplies the pixel's RGB values by its alpha.
forcedinline uint32 getEvenBytes() const noexcept
Return channels with an even index and insert zero bytes between them.
forcedinline void multiplyAlpha(int multiplier) noexcept
Multiplies the colour's alpha value with another one.
forcedinline uint32 getOddBytes() const noexcept
Return channels with an odd index and insert zero bytes between them.
Represents an 8-bit single-channel pixel, and can perform compositing operations on it.
forcedinline void setARGB(uint8 a_, uint8, uint8, uint8) noexcept
Sets the pixel's colour from individual components.
uint32 getInARGBMemoryOrder() const noexcept
Returns a uint32 which when written to memory, will be in the order a, r, g, b.
forcedinline void tween(const Pixel &src, uint32 amount) noexcept
Blends another pixel with this one, creating a colour that is somewhere between the two,...
forcedinline void multiplyAlpha(int multiplier) noexcept
Multiplies the colour's alpha value with another one.
forcedinline uint32 getEvenBytes() const noexcept
Return channels with an even index and insert zero bytes between them.
forcedinline void setAlpha(uint8 newAlpha) noexcept
Replaces the colour's alpha value with another one.
forcedinline void premultiply() noexcept
Premultiplies the pixel's RGB values by its alpha.
forcedinline void blend(const Pixel &src) noexcept
Blends another pixel onto this one.
forcedinline uint32 getInARGBMaskOrder() const noexcept
Returns a uint32 which will be in argb order as if constructed with the following mask operation ((al...
forcedinline void set(const Pixel &src) noexcept
Copies another pixel colour over this one.
forcedinline uint32 getOddBytes() const noexcept
Return channels with an odd index and insert zero bytes between them.
forcedinline void unpremultiply() noexcept
Unpremultiplies the pixel's RGB values.
PixelAlpha() noexcept=default
Creates a pixel without defining its colour.
forcedinline void blend(const Pixel &src, uint32 extraAlpha) noexcept
Blends another pixel onto this one, applying an extra multiplier to its opacity.
Represents a 24-bit RGB pixel, and can perform compositing operations on it.
forcedinline void premultiply() noexcept
Premultiplies the pixel's RGB values by its alpha.
forcedinline void setAlpha(uint8) noexcept
This method is included for compatibility with the PixelARGB class.
forcedinline uint32 getInARGBMaskOrder() const noexcept
Returns a uint32 which will be in argb order as if constructed with the following mask operation ((al...
forcedinline uint32 getOddBytes() const noexcept
Return channels with an odd index and insert zero bytes between them.
void setARGB(uint8, uint8 red, uint8 green, uint8 blue) noexcept
Sets the pixel's colour from individual components.
forcedinline void set(const Pixel &src) noexcept
Copies another pixel colour over this one.
forcedinline void blend(const Pixel &src, uint32 extraAlpha) noexcept
Blends another pixel onto this one, applying an extra multiplier to its opacity.
forcedinline void blend(const Pixel &src) noexcept
Blends another pixel onto this one.
forcedinline void multiplyAlpha(int) noexcept
Multiplies the colour's alpha value with another one.
uint32 getInARGBMemoryOrder() const noexcept
Returns a uint32 which when written to memory, will be in the order a, r, g, b.
forcedinline uint32 getEvenBytes() const noexcept
Return channels with an even index and insert zero bytes between them.
forcedinline void tween(const Pixel &src, uint32 amount) noexcept
Blends another pixel with this one, creating a colour that is somewhere between the two,...
PixelRGB() noexcept=default
Creates a pixel without defining its colour.
forcedinline void unpremultiply() noexcept
Unpremultiplies the pixel's RGB values.
forcedinline void multiplyAlpha(float) noexcept
Multiplies the colour's alpha value with another one.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.