The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

733 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. #if JUCE_MSVC
  17. #pragma pack (push, 1)
  18. #endif
  19. class PixelRGB;
  20. class PixelAlpha;
  21. inline uint32 maskPixelComponents (uint32 x) noexcept
  22. {
  23. return (x >> 8) & 0x00ff00ff;
  24. }
  25. inline uint32 clampPixelComponents (uint32 x) noexcept
  26. {
  27. return (x | (0x01000100 - maskPixelComponents (x))) & 0x00ff00ff;
  28. }
  29. //==============================================================================
  30. /**
  31. Represents a 32-bit INTERNAL pixel with premultiplied alpha, and can perform compositing
  32. operations with it.
  33. This is used internally by the imaging classes.
  34. @see PixelRGB
  35. @tags{Graphics}
  36. */
  37. class JUCE_API PixelARGB
  38. {
  39. public:
  40. /** Creates a pixel without defining its colour. */
  41. PixelARGB() = default;
  42. ~PixelARGB() = default;
  43. PixelARGB (const uint8 a, const uint8 r, const uint8 g, const uint8 b) noexcept
  44. {
  45. components.b = b;
  46. components.g = g;
  47. components.r = r;
  48. components.a = a;
  49. }
  50. //==============================================================================
  51. /** Returns a uint32 which represents the pixel in a platform dependent format. */
  52. forcedinline uint32 getNativeARGB() const noexcept { return internal; }
  53. /** Returns a uint32 which will be in argb order as if constructed with the following mask operation
  54. ((alpha << 24) | (red << 16) | (green << 8) | blue). */
  55. forcedinline uint32 getInARGBMaskOrder() const noexcept
  56. {
  57. #if JUCE_ANDROID
  58. return (uint32) ((components.a << 24) | (components.r << 16) | (components.g << 8) | (components.b << 0));
  59. #else
  60. return getNativeARGB();
  61. #endif
  62. }
  63. /** Returns a uint32 which when written to memory, will be in the order a, r, g, b. In other words,
  64. if the return-value is read as a uint8 array then the elements will be in the order of a, r, g, b*/
  65. inline uint32 getInARGBMemoryOrder() const noexcept
  66. {
  67. #if JUCE_BIG_ENDIAN
  68. return getInARGBMaskOrder();
  69. #else
  70. return (uint32) ((components.b << 24) | (components.g << 16) | (components.r << 8) | components.a);
  71. #endif
  72. }
  73. /** Return channels with an even index and insert zero bytes between them. This is useful for blending
  74. operations. The exact channels which are returned is platform dependent. */
  75. forcedinline uint32 getEvenBytes() const noexcept { return 0x00ff00ff & internal; }
  76. /** Return channels with an odd index and insert zero bytes between them. This is useful for blending
  77. operations. The exact channels which are returned is platform dependent. */
  78. forcedinline uint32 getOddBytes() const noexcept { return 0x00ff00ff & (internal >> 8); }
  79. //==============================================================================
  80. forcedinline uint8 getAlpha() const noexcept { return components.a; }
  81. forcedinline uint8 getRed() const noexcept { return components.r; }
  82. forcedinline uint8 getGreen() const noexcept { return components.g; }
  83. forcedinline uint8 getBlue() const noexcept { return components.b; }
  84. //==============================================================================
  85. /** Copies another pixel colour over this one.
  86. This doesn't blend it - this colour is simply replaced by the other one.
  87. */
  88. template <class Pixel>
  89. forcedinline void set (const Pixel& src) noexcept
  90. {
  91. internal = src.getNativeARGB();
  92. }
  93. //==============================================================================
  94. /** Sets the pixel's colour from individual components. */
  95. void setARGB (const uint8 a, const uint8 r, const uint8 g, const uint8 b) noexcept
  96. {
  97. components.b = b;
  98. components.g = g;
  99. components.r = r;
  100. components.a = a;
  101. }
  102. //==============================================================================
  103. /** Blends another pixel onto this one.
  104. This takes into account the opacity of the pixel being overlaid, and blends
  105. it accordingly.
  106. */
  107. template <class Pixel>
  108. forcedinline void blend (const Pixel& src) noexcept
  109. {
  110. uint32 rb = src.getEvenBytes();
  111. uint32 ag = src.getOddBytes();
  112. const uint32 alpha = 0x100 - (ag >> 16);
  113. rb += maskPixelComponents (getEvenBytes() * alpha);
  114. ag += maskPixelComponents (getOddBytes() * alpha);
  115. internal = clampPixelComponents (rb) | (clampPixelComponents (ag) << 8);
  116. }
  117. /** Blends another pixel onto this one.
  118. This takes into account the opacity of the pixel being overlaid, and blends
  119. it accordingly.
  120. */
  121. forcedinline void blend (const PixelRGB src) noexcept;
  122. /** Blends another pixel onto this one, applying an extra multiplier to its opacity.
  123. The opacity of the pixel being overlaid is scaled by the extraAlpha factor before
  124. being used, so this can blend semi-transparently from a PixelRGB argument.
  125. */
  126. template <class Pixel>
  127. forcedinline void blend (const Pixel& src, uint32 extraAlpha) noexcept
  128. {
  129. uint32 rb = maskPixelComponents (extraAlpha * src.getEvenBytes());
  130. uint32 ag = maskPixelComponents (extraAlpha * src.getOddBytes());
  131. const uint32 alpha = 0x100 - (ag >> 16);
  132. rb += maskPixelComponents (getEvenBytes() * alpha);
  133. ag += maskPixelComponents (getOddBytes() * alpha);
  134. internal = clampPixelComponents (rb) | (clampPixelComponents (ag) << 8);
  135. }
  136. /** Blends another pixel with this one, creating a colour that is somewhere
  137. between the two, as specified by the amount.
  138. */
  139. template <class Pixel>
  140. forcedinline void tween (const Pixel& src, const uint32 amount) noexcept
  141. {
  142. uint32 dEvenBytes = getEvenBytes();
  143. dEvenBytes += (((src.getEvenBytes() - dEvenBytes) * amount) >> 8);
  144. dEvenBytes &= 0x00ff00ff;
  145. uint32 dOddBytes = getOddBytes();
  146. dOddBytes += (((src.getOddBytes() - dOddBytes) * amount) >> 8);
  147. dOddBytes &= 0x00ff00ff;
  148. dOddBytes <<= 8;
  149. dOddBytes |= dEvenBytes;
  150. internal = dOddBytes;
  151. }
  152. //==============================================================================
  153. /** Replaces the colour's alpha value with another one. */
  154. forcedinline void setAlpha (const uint8 newAlpha) noexcept
  155. {
  156. components.a = newAlpha;
  157. }
  158. /** Multiplies the colour's alpha value with another one. */
  159. forcedinline void multiplyAlpha (int multiplier) noexcept
  160. {
  161. // increment alpha by 1, so that if multiplier == 255 (full alpha),
  162. // this function will not change the values.
  163. ++multiplier;
  164. internal = ((((uint32) multiplier) * getOddBytes()) & 0xff00ff00)
  165. | (((((uint32) multiplier) * getEvenBytes()) >> 8) & 0x00ff00ff);
  166. }
  167. forcedinline void multiplyAlpha (const float multiplier) noexcept
  168. {
  169. multiplyAlpha ((int) (multiplier * 255.0f));
  170. }
  171. inline PixelARGB getUnpremultiplied() const noexcept { PixelARGB p (internal); p.unpremultiply(); return p; }
  172. /** Premultiplies the pixel's RGB values by its alpha. */
  173. forcedinline void premultiply() noexcept
  174. {
  175. const uint32 alpha = components.a;
  176. if (alpha < 0xff)
  177. {
  178. if (alpha == 0)
  179. {
  180. components.b = 0;
  181. components.g = 0;
  182. components.r = 0;
  183. }
  184. else
  185. {
  186. components.b = (uint8) ((components.b * alpha + 0x7f) >> 8);
  187. components.g = (uint8) ((components.g * alpha + 0x7f) >> 8);
  188. components.r = (uint8) ((components.r * alpha + 0x7f) >> 8);
  189. }
  190. }
  191. }
  192. /** Unpremultiplies the pixel's RGB values. */
  193. forcedinline void unpremultiply() noexcept
  194. {
  195. const uint32 alpha = components.a;
  196. if (alpha < 0xff)
  197. {
  198. if (alpha == 0)
  199. {
  200. components.b = 0;
  201. components.g = 0;
  202. components.r = 0;
  203. }
  204. else
  205. {
  206. components.b = (uint8) jmin ((uint32) 0xffu, (components.b * 0xffu) / alpha);
  207. components.g = (uint8) jmin ((uint32) 0xffu, (components.g * 0xffu) / alpha);
  208. components.r = (uint8) jmin ((uint32) 0xffu, (components.r * 0xffu) / alpha);
  209. }
  210. }
  211. }
  212. forcedinline void desaturate() noexcept
  213. {
  214. if (components.a < 0xff && components.a > 0)
  215. {
  216. const int newUnpremultipliedLevel = (0xff * ((int) components.r + (int) components.g + (int) components.b) / (3 * components.a));
  217. components.r = components.g = components.b
  218. = (uint8) ((newUnpremultipliedLevel * components.a + 0x7f) >> 8);
  219. }
  220. else
  221. {
  222. components.r = components.g = components.b
  223. = (uint8) (((int) components.r + (int) components.g + (int) components.b) / 3);
  224. }
  225. }
  226. //==============================================================================
  227. /** The indexes of the different components in the byte layout of this type of colour. */
  228. #if JUCE_ANDROID
  229. #if JUCE_BIG_ENDIAN
  230. enum { indexA = 0, indexR = 3, indexG = 2, indexB = 1 };
  231. #else
  232. enum { indexA = 3, indexR = 0, indexG = 1, indexB = 2 };
  233. #endif
  234. #else
  235. #if JUCE_BIG_ENDIAN
  236. enum { indexA = 0, indexR = 1, indexG = 2, indexB = 3 };
  237. #else
  238. enum { indexA = 3, indexR = 2, indexG = 1, indexB = 0 };
  239. #endif
  240. #endif
  241. private:
  242. //==============================================================================
  243. PixelARGB (uint32 internalValue) noexcept : internal (internalValue)
  244. {
  245. }
  246. //==============================================================================
  247. struct Components
  248. {
  249. #if JUCE_ANDROID
  250. #if JUCE_BIG_ENDIAN
  251. uint8 a, b, g, r;
  252. #else
  253. uint8 r, g, b, a;
  254. #endif
  255. #else
  256. #if JUCE_BIG_ENDIAN
  257. uint8 a, r, g, b;
  258. #else
  259. uint8 b, g, r, a;
  260. #endif
  261. #endif
  262. } JUCE_PACKED;
  263. union
  264. {
  265. uint32 internal;
  266. Components components;
  267. };
  268. }
  269. #ifndef DOXYGEN
  270. JUCE_PACKED
  271. #endif
  272. ;
  273. //==============================================================================
  274. /**
  275. Represents a 24-bit RGB pixel, and can perform compositing operations on it.
  276. This is used internally by the imaging classes.
  277. @see PixelARGB
  278. @tags{Graphics}
  279. */
  280. class JUCE_API PixelRGB
  281. {
  282. public:
  283. /** Creates a pixel without defining its colour. */
  284. PixelRGB() = default;
  285. ~PixelRGB() = default;
  286. //==============================================================================
  287. /** Returns a uint32 which represents the pixel in a platform dependent format which is compatible
  288. with the native format of a PixelARGB.
  289. @see PixelARGB::getNativeARGB */
  290. forcedinline uint32 getNativeARGB() const noexcept
  291. {
  292. #if JUCE_ANDROID
  293. return (uint32) ((0xffu << 24) | r | ((uint32) g << 8) | ((uint32) b << 16));
  294. #else
  295. return (uint32) ((0xffu << 24) | b | ((uint32) g << 8) | ((uint32) r << 16));
  296. #endif
  297. }
  298. /** Returns a uint32 which will be in argb order as if constructed with the following mask operation
  299. ((alpha << 24) | (red << 16) | (green << 8) | blue). */
  300. forcedinline uint32 getInARGBMaskOrder() const noexcept
  301. {
  302. #if JUCE_ANDROID
  303. return (uint32) ((0xffu << 24) | b | ((uint32) g << 8) | ((uint32) r << 16));
  304. #else
  305. return getNativeARGB();
  306. #endif
  307. }
  308. /** Returns a uint32 which when written to memory, will be in the order a, r, g, b. In other words,
  309. if the return-value is read as a uint8 array then the elements will be in the order of a, r, g, b*/
  310. inline uint32 getInARGBMemoryOrder() const noexcept
  311. {
  312. #if JUCE_BIG_ENDIAN
  313. return getInARGBMaskOrder();
  314. #else
  315. return (uint32) ((b << 24) | (g << 16) | (r << 8) | 0xff);
  316. #endif
  317. }
  318. /** Return channels with an even index and insert zero bytes between them. This is useful for blending
  319. operations. The exact channels which are returned is platform dependent but compatible with the
  320. return value of getEvenBytes of the PixelARGB class.
  321. @see PixelARGB::getEvenBytes */
  322. forcedinline uint32 getEvenBytes() const noexcept
  323. {
  324. #if JUCE_ANDROID
  325. return (uint32) (r | (b << 16));
  326. #else
  327. return (uint32) (b | (r << 16));
  328. #endif
  329. }
  330. /** Return channels with an odd index and insert zero bytes between them. This is useful for blending
  331. operations. The exact channels which are returned is platform dependent but compatible with the
  332. return value of getOddBytes of the PixelARGB class.
  333. @see PixelARGB::getOddBytes */
  334. forcedinline uint32 getOddBytes() const noexcept { return (uint32)0xff0000 | g; }
  335. //==============================================================================
  336. forcedinline uint8 getAlpha() const noexcept { return 0xff; }
  337. forcedinline uint8 getRed() const noexcept { return r; }
  338. forcedinline uint8 getGreen() const noexcept { return g; }
  339. forcedinline uint8 getBlue() const noexcept { return b; }
  340. //==============================================================================
  341. /** Copies another pixel colour over this one.
  342. This doesn't blend it - this colour is simply replaced by the other one.
  343. Because PixelRGB has no alpha channel, any alpha value in the source pixel
  344. is thrown away.
  345. */
  346. template <class Pixel>
  347. forcedinline void set (const Pixel& src) noexcept
  348. {
  349. b = src.getBlue();
  350. g = src.getGreen();
  351. r = src.getRed();
  352. }
  353. /** Sets the pixel's colour from individual components. */
  354. void setARGB (const uint8, const uint8 red, const uint8 green, const uint8 blue) noexcept
  355. {
  356. r = red;
  357. g = green;
  358. b = blue;
  359. }
  360. //==============================================================================
  361. /** Blends another pixel onto this one.
  362. This takes into account the opacity of the pixel being overlaid, and blends
  363. it accordingly.
  364. */
  365. template <class Pixel>
  366. forcedinline void blend (const Pixel& src) noexcept
  367. {
  368. const uint32 alpha = (uint32) (0x100 - src.getAlpha());
  369. // getEvenBytes returns 0x00rr00bb on non-android
  370. uint32 rb = clampPixelComponents (src.getEvenBytes() + maskPixelComponents (getEvenBytes() * alpha));
  371. // getOddBytes returns 0x00aa00gg on non-android
  372. uint32 ag = clampPixelComponents (src.getOddBytes() + ((g * alpha) >> 8));
  373. g = (uint8) (ag & 0xff);
  374. #if JUCE_ANDROID
  375. b = (uint8) (rb >> 16);
  376. r = (uint8) (rb & 0xff);
  377. #else
  378. r = (uint8) (rb >> 16);
  379. b = (uint8) (rb & 0xff);
  380. #endif
  381. }
  382. forcedinline void blend (const PixelRGB src) noexcept
  383. {
  384. set (src);
  385. }
  386. /** Blends another pixel onto this one, applying an extra multiplier to its opacity.
  387. The opacity of the pixel being overlaid is scaled by the extraAlpha factor before
  388. being used, so this can blend semi-transparently from a PixelRGB argument.
  389. */
  390. template <class Pixel>
  391. forcedinline void blend (const Pixel& src, uint32 extraAlpha) noexcept
  392. {
  393. uint32 ag = maskPixelComponents (extraAlpha * src.getOddBytes());
  394. uint32 rb = maskPixelComponents (extraAlpha * src.getEvenBytes());
  395. const uint32 alpha = 0x100 - (ag >> 16);
  396. ag = clampPixelComponents (ag + (g * alpha >> 8));
  397. rb = clampPixelComponents (rb + maskPixelComponents (getEvenBytes() * alpha));
  398. g = (uint8) (ag & 0xff);
  399. #if JUCE_ANDROID
  400. b = (uint8) (rb >> 16);
  401. r = (uint8) (rb & 0xff);
  402. #else
  403. r = (uint8) (rb >> 16);
  404. b = (uint8) (rb & 0xff);
  405. #endif
  406. }
  407. /** Blends another pixel with this one, creating a colour that is somewhere
  408. between the two, as specified by the amount.
  409. */
  410. template <class Pixel>
  411. forcedinline void tween (const Pixel& src, const uint32 amount) noexcept
  412. {
  413. uint32 dEvenBytes = getEvenBytes();
  414. dEvenBytes += (((src.getEvenBytes() - dEvenBytes) * amount) >> 8);
  415. uint32 dOddBytes = getOddBytes();
  416. dOddBytes += (((src.getOddBytes() - dOddBytes) * amount) >> 8);
  417. g = (uint8) (dOddBytes & 0xff); // dOddBytes = 0x00aa00gg
  418. #if JUCE_ANDROID
  419. r = (uint8) (dEvenBytes & 0xff); // dEvenBytes = 0x00bb00rr
  420. b = (uint8) (dEvenBytes >> 16);
  421. #else
  422. b = (uint8) (dEvenBytes & 0xff); // dEvenBytes = 0x00rr00bb
  423. r = (uint8) (dEvenBytes >> 16);
  424. #endif
  425. }
  426. //==============================================================================
  427. /** This method is included for compatibility with the PixelARGB class. */
  428. forcedinline void setAlpha (const uint8) noexcept {}
  429. /** Multiplies the colour's alpha value with another one. */
  430. forcedinline void multiplyAlpha (int) noexcept {}
  431. /** Multiplies the colour's alpha value with another one. */
  432. forcedinline void multiplyAlpha (float) noexcept {}
  433. /** Premultiplies the pixel's RGB values by its alpha. */
  434. forcedinline void premultiply() noexcept {}
  435. /** Unpremultiplies the pixel's RGB values. */
  436. forcedinline void unpremultiply() noexcept {}
  437. forcedinline void desaturate() noexcept
  438. {
  439. r = g = b = (uint8) (((int) r + (int) g + (int) b) / 3);
  440. }
  441. //==============================================================================
  442. /** The indexes of the different components in the byte layout of this type of colour. */
  443. #if JUCE_MAC
  444. enum { indexR = 0, indexG = 1, indexB = 2 };
  445. #else
  446. enum { indexR = 2, indexG = 1, indexB = 0 };
  447. #endif
  448. private:
  449. //==============================================================================
  450. PixelRGB (const uint32 internal) noexcept
  451. {
  452. #if JUCE_ANDROID
  453. b = (uint8) (internal >> 16);
  454. g = (uint8) (internal >> 8);
  455. r = (uint8) (internal);
  456. #else
  457. r = (uint8) (internal >> 16);
  458. g = (uint8) (internal >> 8);
  459. b = (uint8) (internal);
  460. #endif
  461. }
  462. //==============================================================================
  463. #if JUCE_MAC
  464. uint8 r, g, b;
  465. #else
  466. uint8 b, g, r;
  467. #endif
  468. }
  469. #ifndef DOXYGEN
  470. JUCE_PACKED
  471. #endif
  472. ;
  473. forcedinline void PixelARGB::blend (const PixelRGB src) noexcept
  474. {
  475. set (src);
  476. }
  477. //==============================================================================
  478. /**
  479. Represents an 8-bit single-channel pixel, and can perform compositing operations on it.
  480. This is used internally by the imaging classes.
  481. @see PixelARGB, PixelRGB
  482. @tags{Graphics}
  483. */
  484. class JUCE_API PixelAlpha
  485. {
  486. public:
  487. /** Creates a pixel without defining its colour. */
  488. PixelAlpha() = default;
  489. ~PixelAlpha() = default;
  490. //==============================================================================
  491. /** Returns a uint32 which represents the pixel in a platform dependent format which is compatible
  492. with the native format of a PixelARGB.
  493. @see PixelARGB::getNativeARGB */
  494. forcedinline uint32 getNativeARGB() const noexcept { return (uint32) ((a << 24) | (a << 16) | (a << 8) | a); }
  495. /** Returns a uint32 which will be in argb order as if constructed with the following mask operation
  496. ((alpha << 24) | (red << 16) | (green << 8) | blue). */
  497. forcedinline uint32 getInARGBMaskOrder() const noexcept { return getNativeARGB(); }
  498. /** Returns a uint32 which when written to memory, will be in the order a, r, g, b. In other words,
  499. if the return-value is read as a uint8 array then the elements will be in the order of a, r, g, b*/
  500. inline uint32 getInARGBMemoryOrder() const noexcept { return getNativeARGB(); }
  501. /** Return channels with an even index and insert zero bytes between them. This is useful for blending
  502. operations. The exact channels which are returned is platform dependent but compatible with the
  503. return value of getEvenBytes of the PixelARGB class.
  504. @see PixelARGB::getEvenBytes */
  505. forcedinline uint32 getEvenBytes() const noexcept { return (uint32) ((a << 16) | a); }
  506. /** Return channels with an odd index and insert zero bytes between them. This is useful for blending
  507. operations. The exact channels which are returned is platform dependent but compatible with the
  508. return value of getOddBytes of the PixelARGB class.
  509. @see PixelARGB::getOddBytes */
  510. forcedinline uint32 getOddBytes() const noexcept { return (uint32) ((a << 16) | a); }
  511. //==============================================================================
  512. forcedinline uint8 getAlpha() const noexcept { return a; }
  513. forcedinline uint8 getRed() const noexcept { return 0; }
  514. forcedinline uint8 getGreen() const noexcept { return 0; }
  515. forcedinline uint8 getBlue() const noexcept { return 0; }
  516. //==============================================================================
  517. /** Copies another pixel colour over this one.
  518. This doesn't blend it - this colour is simply replaced by the other one.
  519. */
  520. template <class Pixel>
  521. forcedinline void set (const Pixel& src) noexcept
  522. {
  523. a = src.getAlpha();
  524. }
  525. /** Sets the pixel's colour from individual components. */
  526. forcedinline void setARGB (const uint8 a_, const uint8 /*r*/, const uint8 /*g*/, const uint8 /*b*/) noexcept
  527. {
  528. a = a_;
  529. }
  530. //==============================================================================
  531. /** Blends another pixel onto this one.
  532. This takes into account the opacity of the pixel being overlaid, and blends
  533. it accordingly.
  534. */
  535. template <class Pixel>
  536. forcedinline void blend (const Pixel& src) noexcept
  537. {
  538. const int srcA = src.getAlpha();
  539. a = (uint8) ((a * (0x100 - srcA) >> 8) + srcA);
  540. }
  541. /** Blends another pixel onto this one, applying an extra multiplier to its opacity.
  542. The opacity of the pixel being overlaid is scaled by the extraAlpha factor before
  543. being used, so this can blend semi-transparently from a PixelRGB argument.
  544. */
  545. template <class Pixel>
  546. forcedinline void blend (const Pixel& src, uint32 extraAlpha) noexcept
  547. {
  548. ++extraAlpha;
  549. const int srcAlpha = (int) ((extraAlpha * src.getAlpha()) >> 8);
  550. a = (uint8) ((a * (0x100 - srcAlpha) >> 8) + srcAlpha);
  551. }
  552. /** Blends another pixel with this one, creating a colour that is somewhere
  553. between the two, as specified by the amount.
  554. */
  555. template <class Pixel>
  556. forcedinline void tween (const Pixel& src, const uint32 amount) noexcept
  557. {
  558. a += ((src.getAlpha() - a) * amount) >> 8;
  559. }
  560. //==============================================================================
  561. /** Replaces the colour's alpha value with another one. */
  562. forcedinline void setAlpha (const uint8 newAlpha) noexcept
  563. {
  564. a = newAlpha;
  565. }
  566. /** Multiplies the colour's alpha value with another one. */
  567. forcedinline void multiplyAlpha (int multiplier) noexcept
  568. {
  569. ++multiplier;
  570. a = (uint8) ((a * multiplier) >> 8);
  571. }
  572. forcedinline void multiplyAlpha (const float multiplier) noexcept
  573. {
  574. a = (uint8) (a * multiplier);
  575. }
  576. /** Premultiplies the pixel's RGB values by its alpha. */
  577. forcedinline void premultiply() noexcept {}
  578. /** Unpremultiplies the pixel's RGB values. */
  579. forcedinline void unpremultiply() noexcept {}
  580. forcedinline void desaturate() noexcept {}
  581. //==============================================================================
  582. /** The indexes of the different components in the byte layout of this type of colour. */
  583. enum { indexA = 0 };
  584. private:
  585. //==============================================================================
  586. PixelAlpha (const uint32 internal) noexcept
  587. {
  588. a = (uint8) (internal >> 24);
  589. }
  590. //==============================================================================
  591. uint8 a;
  592. }
  593. #ifndef DOXYGEN
  594. JUCE_PACKED
  595. #endif
  596. ;
  597. #if JUCE_MSVC
  598. #pragma pack (pop)
  599. #endif
  600. } // namespace juce