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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
|
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2015 - ROLI Ltd.
Permission is granted to use this software under the terms of either:
a) the GPL v2 (or any later version)
b) the Affero GPL v3
Details of these licenses can be found at: www.gnu.org/licenses
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.juce.com for more information.
==============================================================================
*/
#ifndef JUCE_PIXELFORMATS_H_INCLUDED
#define JUCE_PIXELFORMATS_H_INCLUDED
//==============================================================================
#if JUCE_MSVC
#pragma pack (push, 1)
#endif
class PixelRGB;
class PixelAlpha;
inline uint32 maskPixelComponents (uint32 x) noexcept
{
return (x >> 8) & 0x00ff00ff;
}
inline uint32 clampPixelComponents (uint32 x) noexcept
{
return (x | (0x01000100 - maskPixelComponents (x))) & 0x00ff00ff;
}
//==============================================================================
/**
Represents a 32-bit INTERNAL pixel with premultiplied alpha, and can perform compositing
operations with it.
This is used internally by the imaging classes.
@see PixelRGB
*/
class JUCE_API PixelARGB
{
public:
/** Creates a pixel without defining its colour. */
PixelARGB() noexcept {}
~PixelARGB() noexcept {}
PixelARGB (const uint8 a, const uint8 r, const uint8 g, const uint8 b) noexcept
{
components.b = b;
components.g = g;
components.r = r;
components.a = a;
}
//==============================================================================
/** Returns a uint32 which represents the pixel in a platform dependent format. */
forcedinline uint32 getNativeARGB() const noexcept { return internal; }
/** Returns a uint32 which will be in argb order as if constructed with the following mask operation
((alpha << 24) | (red << 16) | (green << 8) | blue). */
forcedinline uint32 getInARGBMaskOrder() const noexcept
{
#if JUCE_ANDROID
return (uint32) ((components.a << 24) | (components.r << 16) | (components.g << 8) | (components.b << 0));
#else
return getNativeARGB();
#endif
}
/** Returns a uint32 which when written to memory, will be in the order a, r, g, b. In other words,
if the return-value is read as a uint8 array then the elements will be in the order of a, r, g, b*/
inline uint32 getInARGBMemoryOrder() const noexcept
{
#if JUCE_BIG_ENDIAN
return getInARGBMaskOrder();
#else
return (uint32) ((components.b << 24) | (components.g << 16) | (components.r << 8) | components.a);
#endif
}
/** Return channels with an even index and insert zero bytes between them. This is useful for blending
operations. The exact channels which are returned is platform dependent. */
forcedinline uint32 getEvenBytes() const noexcept { return 0x00ff00ff & internal; }
/** Return channels with an odd index and insert zero bytes between them. This is useful for blending
operations. The exact channels which are returned is platform dependent. */
forcedinline uint32 getOddBytes() const noexcept { return 0x00ff00ff & (internal >> 8); }
//==============================================================================
forcedinline uint8 getAlpha() const noexcept { return components.a; }
forcedinline uint8 getRed() const noexcept { return components.r; }
forcedinline uint8 getGreen() const noexcept { return components.g; }
forcedinline uint8 getBlue() const noexcept { return components.b; }
#if JUCE_GCC && ! JUCE_CLANG
// NB these are here as a workaround because GCC refuses to bind to packed values.
forcedinline uint8& getAlpha() noexcept { return comps [indexA]; }
forcedinline uint8& getRed() noexcept { return comps [indexR]; }
forcedinline uint8& getGreen() noexcept { return comps [indexG]; }
forcedinline uint8& getBlue() noexcept { return comps [indexB]; }
#else
forcedinline uint8& getAlpha() noexcept { return components.a; }
forcedinline uint8& getRed() noexcept { return components.r; }
forcedinline uint8& getGreen() noexcept { return components.g; }
forcedinline uint8& getBlue() noexcept { return components.b; }
#endif
//==============================================================================
/** Copies another pixel colour over this one.
This doesn't blend it - this colour is simply replaced by the other one.
*/
template <class Pixel>
forcedinline void set (const Pixel& src) noexcept
{
internal = src.getNativeARGB();
}
//==============================================================================
/** Sets the pixel's colour from individual components. */
void setARGB (const uint8 a, const uint8 r, const uint8 g, const uint8 b) noexcept
{
components.b = b;
components.g = g;
components.r = r;
components.a = a;
}
//==============================================================================
/** Blends another pixel onto this one.
This takes into account the opacity of the pixel being overlaid, and blends
it accordingly.
*/
template <class Pixel>
forcedinline void blend (const Pixel& src) noexcept
{
uint32 rb = src.getEvenBytes();
uint32 ag = src.getOddBytes();
const uint32 alpha = 0x100 - (ag >> 16);
rb += maskPixelComponents (getEvenBytes() * alpha);
ag += maskPixelComponents (getOddBytes() * alpha);
internal = clampPixelComponents (rb) | (clampPixelComponents (ag) << 8);
}
/** Blends another pixel onto this one.
This takes into account the opacity of the pixel being overlaid, and blends
it accordingly.
*/
forcedinline void blend (const PixelRGB src) noexcept;
/** Blends another pixel onto this one, applying an extra multiplier to its opacity.
The opacity of the pixel being overlaid is scaled by the extraAlpha factor before
being used, so this can blend semi-transparently from a PixelRGB argument.
*/
template <class Pixel>
forcedinline void blend (const Pixel& src, uint32 extraAlpha) noexcept
{
uint32 rb = maskPixelComponents (extraAlpha * src.getEvenBytes());
uint32 ag = maskPixelComponents (extraAlpha * src.getOddBytes());
const uint32 alpha = 0x100 - (ag >> 16);
rb += maskPixelComponents (getEvenBytes() * alpha);
ag += maskPixelComponents (getOddBytes() * alpha);
internal = clampPixelComponents (rb) | (clampPixelComponents (ag) << 8);
}
/** Blends another pixel with this one, creating a colour that is somewhere
between the two, as specified by the amount.
*/
template <class Pixel>
forcedinline void tween (const Pixel& src, const uint32 amount) noexcept
{
uint32 dEvenBytes = getEvenBytes();
dEvenBytes += (((src.getEvenBytes() - dEvenBytes) * amount) >> 8);
dEvenBytes &= 0x00ff00ff;
uint32 dOddBytes = getOddBytes();
dOddBytes += (((src.getOddBytes() - dOddBytes) * amount) >> 8);
dOddBytes &= 0x00ff00ff;
dOddBytes <<= 8;
dOddBytes |= dEvenBytes;
internal = dOddBytes;
}
//==============================================================================
/** Replaces the colour's alpha value with another one. */
forcedinline void setAlpha (const uint8 newAlpha) noexcept
{
components.a = newAlpha;
}
/** Multiplies the colour's alpha value with another one. */
forcedinline void multiplyAlpha (int multiplier) noexcept
{
// increment alpha by 1, so that if multiplier == 255 (full alpha),
// this function will not change the values.
++multiplier;
internal = ((((uint32) multiplier) * getOddBytes()) & 0xff00ff00)
| (((((uint32) multiplier) * getEvenBytes()) >> 8) & 0x00ff00ff);
}
forcedinline void multiplyAlpha (const float multiplier) noexcept
{
multiplyAlpha ((int) (multiplier * 255.0f));
}
inline PixelARGB getUnpremultiplied() const noexcept { PixelARGB p (internal); p.unpremultiply(); return p; }
/** Premultiplies the pixel's RGB values by its alpha. */
forcedinline void premultiply() noexcept
{
const uint32 alpha = components.a;
if (alpha < 0xff)
{
if (alpha == 0)
{
components.b = 0;
components.g = 0;
components.r = 0;
}
else
{
components.b = (uint8) ((components.b * alpha + 0x7f) >> 8);
components.g = (uint8) ((components.g * alpha + 0x7f) >> 8);
components.r = (uint8) ((components.r * alpha + 0x7f) >> 8);
}
}
}
/** Unpremultiplies the pixel's RGB values. */
forcedinline void unpremultiply() noexcept
{
const uint32 alpha = components.a;
if (alpha < 0xff)
{
if (alpha == 0)
{
components.b = 0;
components.g = 0;
components.r = 0;
}
else
{
components.b = (uint8) jmin ((uint32) 0xffu, (components.b * 0xffu) / alpha);
components.g = (uint8) jmin ((uint32) 0xffu, (components.g * 0xffu) / alpha);
components.r = (uint8) jmin ((uint32) 0xffu, (components.r * 0xffu) / alpha);
}
}
}
forcedinline void desaturate() noexcept
{
if (components.a < 0xff && components.a > 0)
{
const int newUnpremultipliedLevel = (0xff * ((int) components.r + (int) components.g + (int) components.b) / (3 * components.a));
components.r = components.g = components.b
= (uint8) ((newUnpremultipliedLevel * components.a + 0x7f) >> 8);
}
else
{
components.r = components.g = components.b
= (uint8) (((int) components.r + (int) components.g + (int) components.b) / 3);
}
}
//==============================================================================
/** The indexes of the different components in the byte layout of this type of colour. */
#if JUCE_ANDROID
#if JUCE_BIG_ENDIAN
enum { indexA = 0, indexR = 3, indexG = 2, indexB = 1 };
#else
enum { indexA = 3, indexR = 0, indexG = 1, indexB = 2 };
#endif
#else
#if JUCE_BIG_ENDIAN
enum { indexA = 0, indexR = 1, indexG = 2, indexB = 3 };
#else
enum { indexA = 3, indexR = 2, indexG = 1, indexB = 0 };
#endif
#endif
private:
//==============================================================================
PixelARGB (const uint32 internalValue) noexcept
: internal (internalValue)
{
}
//==============================================================================
struct Components
{
#if JUCE_ANDROID
#if JUCE_BIG_ENDIAN
uint8 a, b, g, r;
#else
uint8 r, g, b, a;
#endif
#else
#if JUCE_BIG_ENDIAN
uint8 a, r, g, b;
#else
uint8 b, g, r, a;
#endif
#endif
} JUCE_PACKED;
union
{
uint32 internal;
Components components;
#if JUCE_GCC
uint8 comps[4]; // helper struct needed because gcc does not allow references to packed union members
#endif
};
}
#ifndef DOXYGEN
JUCE_PACKED
#endif
;
//==============================================================================
/**
Represents a 24-bit RGB pixel, and can perform compositing operations on it.
This is used internally by the imaging classes.
@see PixelARGB
*/
class JUCE_API PixelRGB
{
public:
/** Creates a pixel without defining its colour. */
PixelRGB() noexcept {}
~PixelRGB() noexcept {}
//==============================================================================
/** Returns a uint32 which represents the pixel in a platform dependent format which is compatible
with the native format of a PixelARGB.
@see PixelARGB::getNativeARGB */
forcedinline uint32 getNativeARGB() const noexcept
{
#if JUCE_ANDROID
return (uint32) ((0xff << 24) | r | (g << 8) | (b << 16));
#else
return (uint32) ((0xff << 24) | b | (g << 8) | (r << 16));
#endif
}
/** Returns a uint32 which will be in argb order as if constructed with the following mask operation
((alpha << 24) | (red << 16) | (green << 8) | blue). */
forcedinline uint32 getInARGBMaskOrder() const noexcept
{
#if JUCE_ANDROID
return (uint32) ((0xff << 24) | (r << 16) | (g << 8) | (b << 0));
#else
return getNativeARGB();
#endif
}
/** Returns a uint32 which when written to memory, will be in the order a, r, g, b. In other words,
if the return-value is read as a uint8 array then the elements will be in the order of a, r, g, b*/
inline uint32 getInARGBMemoryOrder() const noexcept
{
#if JUCE_BIG_ENDIAN
return getInARGBMaskOrder();
#else
return (uint32) ((b << 24) | (g << 16) | (r << 8) | 0xff);
#endif
}
/** Return channels with an even index and insert zero bytes between them. This is useful for blending
operations. The exact channels which are returned is platform dependent but compatible with the
return value of getEvenBytes of the PixelARGB class.
@see PixelARGB::getEvenBytes */
forcedinline uint32 getEvenBytes() const noexcept
{
#if JUCE_ANDROID
return (uint32) (r | (b << 16));
#else
return (uint32) (b | (r << 16));
#endif
}
/** Return channels with an odd index and insert zero bytes between them. This is useful for blending
operations. The exact channels which are returned is platform dependent but compatible with the
return value of getOddBytes of the PixelARGB class.
@see PixelARGB::getOddBytes */
forcedinline uint32 getOddBytes() const noexcept { return (uint32)0xff0000 | g; }
//==============================================================================
forcedinline uint8 getAlpha() const noexcept { return 0xff; }
forcedinline uint8 getRed() const noexcept { return r; }
forcedinline uint8 getGreen() const noexcept { return g; }
forcedinline uint8 getBlue() const noexcept { return b; }
forcedinline uint8& getRed() noexcept { return r; }
forcedinline uint8& getGreen() noexcept { return g; }
forcedinline uint8& getBlue() noexcept { return b; }
//==============================================================================
/** Copies another pixel colour over this one.
This doesn't blend it - this colour is simply replaced by the other one.
Because PixelRGB has no alpha channel, any alpha value in the source pixel
is thrown away.
*/
template <class Pixel>
forcedinline void set (const Pixel& src) noexcept
{
b = src.getBlue();
g = src.getGreen();
r = src.getRed();
}
/** Sets the pixel's colour from individual components. */
void setARGB (const uint8, const uint8 red, const uint8 green, const uint8 blue) noexcept
{
r = red;
g = green;
b = blue;
}
//==============================================================================
/** Blends another pixel onto this one.
This takes into account the opacity of the pixel being overlaid, and blends
it accordingly.
*/
template <class Pixel>
forcedinline void blend (const Pixel& src) noexcept
{
const uint32 alpha = (uint32) (0x100 - src.getAlpha());
// getEvenBytes returns 0x00rr00bb on non-android
uint32 rb = clampPixelComponents (src.getEvenBytes() + maskPixelComponents (getEvenBytes() * alpha));
// getOddBytes returns 0x00aa00gg on non-android
uint32 ag = clampPixelComponents (src.getOddBytes() + ((g * alpha) >> 8));
g = (uint8) (ag & 0xff);
#if JUCE_ANDROID
b = (uint8) (rb >> 16);
r = (uint8) (rb & 0xff);
#else
r = (uint8) (rb >> 16);
b = (uint8) (rb & 0xff);
#endif
}
forcedinline void blend (const PixelRGB src) noexcept
{
set (src);
}
/** Blends another pixel onto this one, applying an extra multiplier to its opacity.
The opacity of the pixel being overlaid is scaled by the extraAlpha factor before
being used, so this can blend semi-transparently from a PixelRGB argument.
*/
template <class Pixel>
forcedinline void blend (const Pixel& src, uint32 extraAlpha) noexcept
{
uint32 ag = maskPixelComponents (extraAlpha * src.getOddBytes());
uint32 rb = maskPixelComponents (extraAlpha * src.getEvenBytes());
const uint32 alpha = 0x100 - (ag >> 16);
ag = clampPixelComponents (ag + (g * alpha >> 8));
rb = clampPixelComponents (rb + maskPixelComponents (getEvenBytes() * alpha));
g = (uint8) (ag & 0xff);
#if JUCE_ANDROID
b = (uint8) (rb >> 16);
r = (uint8) (rb & 0xff);
#else
r = (uint8) (rb >> 16);
b = (uint8) (rb & 0xff);
#endif
}
/** Blends another pixel with this one, creating a colour that is somewhere
between the two, as specified by the amount.
*/
template <class Pixel>
forcedinline void tween (const Pixel& src, const uint32 amount) noexcept
{
uint32 dEvenBytes = getEvenBytes();
dEvenBytes += (((src.getEvenBytes() - dEvenBytes) * amount) >> 8);
uint32 dOddBytes = getOddBytes();
dOddBytes += (((src.getOddBytes() - dOddBytes) * amount) >> 8);
g = (uint8) (dOddBytes & 0xff); // dOddBytes = 0x00aa00gg
#if JUCE_ANDROID
r = (uint8) (dEvenBytes & 0xff); // dEvenBytes = 0x00bb00rr
b = (uint8) (dEvenBytes >> 16);
#else
b = (uint8) (dEvenBytes & 0xff); // dEvenBytes = 0x00rr00bb
r = (uint8) (dEvenBytes >> 16);
#endif
}
//==============================================================================
/** This method is included for compatibility with the PixelARGB class. */
forcedinline void setAlpha (const uint8) noexcept {}
/** Multiplies the colour's alpha value with another one. */
forcedinline void multiplyAlpha (int) noexcept {}
/** Multiplies the colour's alpha value with another one. */
forcedinline void multiplyAlpha (float) noexcept {}
/** Premultiplies the pixel's RGB values by its alpha. */
forcedinline void premultiply() noexcept {}
/** Unpremultiplies the pixel's RGB values. */
forcedinline void unpremultiply() noexcept {}
forcedinline void desaturate() noexcept
{
r = g = b = (uint8) (((int) r + (int) g + (int) b) / 3);
}
//==============================================================================
/** The indexes of the different components in the byte layout of this type of colour. */
#if JUCE_MAC
enum { indexR = 0, indexG = 1, indexB = 2 };
#else
enum { indexR = 2, indexG = 1, indexB = 0 };
#endif
private:
//==============================================================================
PixelRGB (const uint32 internal) noexcept
{
#if JUCE_ANDROID
b = (uint8) (internal >> 16);
g = (uint8) (internal >> 8);
r = (uint8) (internal);
#else
r = (uint8) (internal >> 16);
g = (uint8) (internal >> 8);
b = (uint8) (internal);
#endif
}
//==============================================================================
#if JUCE_MAC
uint8 r, g, b;
#else
uint8 b, g, r;
#endif
}
#ifndef DOXYGEN
JUCE_PACKED
#endif
;
forcedinline void PixelARGB::blend (const PixelRGB src) noexcept
{
set (src);
}
//==============================================================================
/**
Represents an 8-bit single-channel pixel, and can perform compositing operations on it.
This is used internally by the imaging classes.
@see PixelARGB, PixelRGB
*/
class JUCE_API PixelAlpha
{
public:
/** Creates a pixel without defining its colour. */
PixelAlpha() noexcept {}
~PixelAlpha() noexcept {}
//==============================================================================
/** Returns a uint32 which represents the pixel in a platform dependent format which is compatible
with the native format of a PixelARGB.
@see PixelARGB::getNativeARGB */
forcedinline uint32 getNativeARGB() const noexcept { return (uint32) ((a << 24) | (a << 16) | (a << 8) | a); }
/** Returns a uint32 which will be in argb order as if constructed with the following mask operation
((alpha << 24) | (red << 16) | (green << 8) | blue). */
forcedinline uint32 getInARGBMaskOrder() const noexcept { return getNativeARGB(); }
/** Returns a uint32 which when written to memory, will be in the order a, r, g, b. In other words,
if the return-value is read as a uint8 array then the elements will be in the order of a, r, g, b*/
inline uint32 getInARGBMemoryOrder() const noexcept { return getNativeARGB(); }
/** Return channels with an even index and insert zero bytes between them. This is useful for blending
operations. The exact channels which are returned is platform dependent but compatible with the
return value of getEvenBytes of the PixelARGB class.
@see PixelARGB::getEvenBytes */
forcedinline uint32 getEvenBytes() const noexcept { return (uint32) ((a << 16) | a); }
/** Return channels with an odd index and insert zero bytes between them. This is useful for blending
operations. The exact channels which are returned is platform dependent but compatible with the
return value of getOddBytes of the PixelARGB class.
@see PixelARGB::getOddBytes */
forcedinline uint32 getOddBytes() const noexcept { return (uint32) ((a << 16) | a); }
//==============================================================================
forcedinline uint8 getAlpha() const noexcept { return a; }
forcedinline uint8& getAlpha() noexcept { return a; }
forcedinline uint8 getRed() const noexcept { return 0; }
forcedinline uint8 getGreen() const noexcept { return 0; }
forcedinline uint8 getBlue() const noexcept { return 0; }
//==============================================================================
/** Copies another pixel colour over this one.
This doesn't blend it - this colour is simply replaced by the other one.
*/
template <class Pixel>
forcedinline void set (const Pixel& src) noexcept
{
a = src.getAlpha();
}
/** Sets the pixel's colour from individual components. */
forcedinline void setARGB (const uint8 a_, const uint8 /*r*/, const uint8 /*g*/, const uint8 /*b*/) noexcept
{
a = a_;
}
//==============================================================================
/** Blends another pixel onto this one.
This takes into account the opacity of the pixel being overlaid, and blends
it accordingly.
*/
template <class Pixel>
forcedinline void blend (const Pixel& src) noexcept
{
const int srcA = src.getAlpha();
a = (uint8) ((a * (0x100 - srcA) >> 8) + srcA);
}
/** Blends another pixel onto this one, applying an extra multiplier to its opacity.
The opacity of the pixel being overlaid is scaled by the extraAlpha factor before
being used, so this can blend semi-transparently from a PixelRGB argument.
*/
template <class Pixel>
forcedinline void blend (const Pixel& src, uint32 extraAlpha) noexcept
{
++extraAlpha;
const int srcAlpha = (int) ((extraAlpha * src.getAlpha()) >> 8);
a = (uint8) ((a * (0x100 - srcAlpha) >> 8) + srcAlpha);
}
/** Blends another pixel with this one, creating a colour that is somewhere
between the two, as specified by the amount.
*/
template <class Pixel>
forcedinline void tween (const Pixel& src, const uint32 amount) noexcept
{
a += ((src.getAlpha() - a) * amount) >> 8;
}
//==============================================================================
/** Replaces the colour's alpha value with another one. */
forcedinline void setAlpha (const uint8 newAlpha) noexcept
{
a = newAlpha;
}
/** Multiplies the colour's alpha value with another one. */
forcedinline void multiplyAlpha (int multiplier) noexcept
{
++multiplier;
a = (uint8) ((a * multiplier) >> 8);
}
forcedinline void multiplyAlpha (const float multiplier) noexcept
{
a = (uint8) (a * multiplier);
}
/** Premultiplies the pixel's RGB values by its alpha. */
forcedinline void premultiply() noexcept {}
/** Unpremultiplies the pixel's RGB values. */
forcedinline void unpremultiply() noexcept {}
forcedinline void desaturate() noexcept {}
//==============================================================================
/** The indexes of the different components in the byte layout of this type of colour. */
enum { indexA = 0 };
private:
//==============================================================================
PixelAlpha (const uint32 internal) noexcept
{
a = (uint8) (internal >> 24);
}
//==============================================================================
uint8 a;
}
#ifndef DOXYGEN
JUCE_PACKED
#endif
;
#if JUCE_MSVC
#pragma pack (pop)
#endif
#endif // JUCE_PIXELFORMATS_H_INCLUDED
|