2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
29 namespace ColourHelpers
31 static uint8
floatToUInt8 (float n
) noexcept
33 return n
<= 0.0f
? 0 : (n
>= 1.0f
? 255 : (uint8
) roundToInt (n
* 255.0f
));
36 static float getHue (Colour col
)
38 auto r
= (int) col
.getRed();
39 auto g
= (int) col
.getGreen();
40 auto b
= (int) col
.getBlue();
42 auto hi
= jmax (r
, g
, b
);
43 auto lo
= jmin (r
, g
, b
);
47 if (hi
> 0 && ! approximatelyEqual (hi
, lo
))
49 auto invDiff
= 1.0f
/ (float) (hi
- lo
);
51 auto red
= (float) (hi
- r
) * invDiff
;
52 auto green
= (float) (hi
- g
) * invDiff
;
53 auto blue
= (float) (hi
- b
) * invDiff
;
55 if (r
== hi
) hue
= blue
- green
;
56 else if (g
== hi
) hue
= 2.0f
+ red
- blue
;
57 else hue
= 4.0f
+ green
- red
;
68 //==============================================================================
71 HSL (Colour col
) noexcept
73 auto r
= (int) col
.getRed();
74 auto g
= (int) col
.getGreen();
75 auto b
= (int) col
.getBlue();
77 auto hi
= jmax (r
, g
, b
);
78 auto lo
= jmin (r
, g
, b
);
83 lightness
= ((float) (hi
+ lo
) / 2.0f
) / 255.0f
;
85 if (lightness
<= 0.0f
)
90 if (1.0f
<= lightness
)
93 auto denominator
= 1.0f
- std::abs ((2.0f
* lightness
) - 1.0f
);
94 saturation
= ((float) (hi
- lo
) / 255.0f
) / denominator
;
97 Colour
toColour (Colour original
) const noexcept
99 return Colour::fromHSL (hue
, saturation
, lightness
, original
.getAlpha());
102 static PixelARGB
toRGB (float h
, float s
, float l
, uint8 alpha
) noexcept
104 auto v
= l
< 0.5f
? l
* (1.0f
+ s
) : l
+ s
- (l
* s
);
106 if (approximatelyEqual (v
, 0.0f
))
107 return PixelARGB (alpha
, 0, 0, 0);
109 auto min
= (2.0f
* l
) - v
;
110 auto sv
= (v
- min
) / v
;
112 h
= ((h
- std::floor (h
)) * 360.0f
) / 60.0f
;
113 auto f
= h
- std::floor (h
);
114 auto vsf
= v
* sv
* f
;
115 auto mid1
= min
+ vsf
;
118 if (h
< 1.0f
) return PixelARGB (alpha
, floatToUInt8 (v
), floatToUInt8 (mid1
), floatToUInt8 (min
));
119 else if (h
< 2.0f
) return PixelARGB (alpha
, floatToUInt8 (mid2
), floatToUInt8 (v
), floatToUInt8 (min
));
120 else if (h
< 3.0f
) return PixelARGB (alpha
, floatToUInt8 (min
), floatToUInt8 (v
), floatToUInt8 (mid1
));
121 else if (h
< 4.0f
) return PixelARGB (alpha
, floatToUInt8 (min
), floatToUInt8 (mid2
), floatToUInt8 (v
));
122 else if (h
< 5.0f
) return PixelARGB (alpha
, floatToUInt8 (mid1
), floatToUInt8 (min
), floatToUInt8 (v
));
123 else if (h
< 6.0f
) return PixelARGB (alpha
, floatToUInt8 (v
), floatToUInt8 (min
), floatToUInt8 (mid2
));
125 return PixelARGB (alpha
, 0, 0, 0);
128 float hue
= 0.0f
, saturation
= 0.0f
, lightness
= 0.0f
;
131 //==============================================================================
134 HSB (Colour col
) noexcept
136 auto r
= (int) col
.getRed();
137 auto g
= (int) col
.getGreen();
138 auto b
= (int) col
.getBlue();
140 auto hi
= jmax (r
, g
, b
);
141 auto lo
= jmin (r
, g
, b
);
145 saturation
= (float) (hi
- lo
) / (float) hi
;
147 if (saturation
> 0.0f
)
150 brightness
= (float) hi
/ 255.0f
;
154 Colour
toColour (Colour original
) const noexcept
156 return Colour (hue
, saturation
, brightness
, original
.getAlpha());
159 static PixelARGB
toRGB (float h
, float s
, float v
, uint8 alpha
) noexcept
161 v
= jlimit (0.0f
, 255.0f
, v
* 255.0f
);
162 auto intV
= (uint8
) roundToInt (v
);
165 return PixelARGB (alpha
, intV
, intV
, intV
);
168 h
= ((h
- std::floor (h
)) * 360.0f
) / 60.0f
;
169 auto f
= h
- std::floor (h
);
170 auto x
= (uint8
) roundToInt (v
* (1.0f
- s
));
172 if (h
< 1.0f
) return PixelARGB (alpha
, intV
, (uint8
) roundToInt (v
* (1.0f
- (s
* (1.0f
- f
)))), x
);
173 if (h
< 2.0f
) return PixelARGB (alpha
, (uint8
) roundToInt (v
* (1.0f
- s
* f
)), intV
, x
);
174 if (h
< 3.0f
) return PixelARGB (alpha
, x
, intV
, (uint8
) roundToInt (v
* (1.0f
- (s
* (1.0f
- f
)))));
175 if (h
< 4.0f
) return PixelARGB (alpha
, x
, (uint8
) roundToInt (v
* (1.0f
- s
* f
)), intV
);
176 if (h
< 5.0f
) return PixelARGB (alpha
, (uint8
) roundToInt (v
* (1.0f
- (s
* (1.0f
- f
)))), x
, intV
);
177 return PixelARGB (alpha
, intV
, x
, (uint8
) roundToInt (v
* (1.0f
- s
* f
)));
180 float hue
= 0.0f
, saturation
= 0.0f
, brightness
= 0.0f
;
183 //==============================================================================
186 YIQ (Colour c
) noexcept
188 auto r
= c
.getFloatRed();
189 auto g
= c
.getFloatGreen();
190 auto b
= c
.getFloatBlue();
192 y
= 0.2999f
* r
+ 0.5870f
* g
+ 0.1140f
* b
;
193 i
= 0.5957f
* r
- 0.2744f
* g
- 0.3212f
* b
;
194 q
= 0.2114f
* r
- 0.5225f
* g
- 0.3113f
* b
;
195 alpha
= c
.getFloatAlpha();
198 Colour
toColour() const noexcept
200 return Colour::fromFloatRGBA (y
+ 0.9563f
* i
+ 0.6210f
* q
,
201 y
- 0.2721f
* i
- 0.6474f
* q
,
202 y
- 1.1070f
* i
+ 1.7046f
* q
,
206 float y
= 0.0f
, i
= 0.0f
, q
= 0.0f
, alpha
= 0.0f
;
210 //==============================================================================
211 bool Colour::operator== (const Colour
& other
) const noexcept
{ return argb
.getNativeARGB() == other
.argb
.getNativeARGB(); }
212 bool Colour::operator!= (const Colour
& other
) const noexcept
{ return argb
.getNativeARGB() != other
.argb
.getNativeARGB(); }
214 //==============================================================================
215 Colour::Colour (uint32 col
) noexcept
216 : argb (static_cast<uint8
> ((col
>> 24) & 0xff),
217 static_cast<uint8
> ((col
>> 16) & 0xff),
218 static_cast<uint8
> ((col
>> 8) & 0xff),
219 static_cast<uint8
> (col
& 0xff))
223 Colour::Colour (uint8 red
, uint8 green
, uint8 blue
) noexcept
225 argb
.setARGB (0xff, red
, green
, blue
);
228 Colour
Colour::fromRGB (uint8 red
, uint8 green
, uint8 blue
) noexcept
230 return Colour (red
, green
, blue
);
233 Colour::Colour (uint8 red
, uint8 green
, uint8 blue
, uint8 alpha
) noexcept
235 argb
.setARGB (alpha
, red
, green
, blue
);
238 Colour
Colour::fromRGBA (uint8 red
, uint8 green
, uint8 blue
, uint8 alpha
) noexcept
240 return Colour (red
, green
, blue
, alpha
);
243 Colour::Colour (uint8 red
, uint8 green
, uint8 blue
, float alpha
) noexcept
245 argb
.setARGB (ColourHelpers::floatToUInt8 (alpha
), red
, green
, blue
);
248 Colour
Colour::fromFloatRGBA (float red
, float green
, float blue
, float alpha
) noexcept
250 return Colour (ColourHelpers::floatToUInt8 (red
),
251 ColourHelpers::floatToUInt8 (green
),
252 ColourHelpers::floatToUInt8 (blue
), alpha
);
255 Colour::Colour (float hue
, float saturation
, float brightness
, float alpha
) noexcept
256 : argb (ColourHelpers::HSB::toRGB (hue
, saturation
, brightness
, ColourHelpers::floatToUInt8 (alpha
)))
260 Colour
Colour::fromHSV (float hue
, float saturation
, float brightness
, float alpha
) noexcept
262 return Colour (hue
, saturation
, brightness
, alpha
);
265 Colour
Colour::fromHSL (float hue
, float saturation
, float lightness
, float alpha
) noexcept
268 hslColour
.argb
= ColourHelpers::HSL::toRGB (hue
, saturation
, lightness
, ColourHelpers::floatToUInt8 (alpha
));
273 Colour::Colour (float hue
, float saturation
, float brightness
, uint8 alpha
) noexcept
274 : argb (ColourHelpers::HSB::toRGB (hue
, saturation
, brightness
, alpha
))
278 Colour::Colour (PixelARGB argb_
) noexcept
283 Colour::Colour (PixelRGB rgb
) noexcept
284 : argb (Colour (rgb
.getInARGBMaskOrder()).argb
)
288 Colour::Colour (PixelAlpha alpha
) noexcept
289 : argb (Colour (alpha
.getInARGBMaskOrder()).argb
)
293 //==============================================================================
294 const PixelARGB
Colour::getPixelARGB() const noexcept
301 uint32
Colour::getARGB() const noexcept
303 return argb
.getInARGBMaskOrder();
306 //==============================================================================
307 bool Colour::isTransparent() const noexcept
309 return getAlpha() == 0;
312 bool Colour::isOpaque() const noexcept
314 return getAlpha() == 0xff;
317 Colour
Colour::withAlpha (uint8 newAlpha
) const noexcept
319 PixelARGB
newCol (argb
);
320 newCol
.setAlpha (newAlpha
);
321 return Colour (newCol
);
324 Colour
Colour::withAlpha (float newAlpha
) const noexcept
326 jassert (newAlpha
>= 0 && newAlpha
<= 1.0f
);
328 PixelARGB
newCol (argb
);
329 newCol
.setAlpha (ColourHelpers::floatToUInt8 (newAlpha
));
330 return Colour (newCol
);
333 Colour
Colour::withMultipliedAlpha (float alphaMultiplier
) const noexcept
335 jassert (alphaMultiplier
>= 0);
337 PixelARGB
newCol (argb
);
338 newCol
.setAlpha ((uint8
) jmin (0xff, roundToInt (alphaMultiplier
* newCol
.getAlpha())));
339 return Colour (newCol
);
342 //==============================================================================
343 Colour
Colour::overlaidWith (Colour src
) const noexcept
345 auto destAlpha
= getAlpha();
350 auto invA
= 0xff - (int) src
.getAlpha();
351 auto resA
= 0xff - (((0xff - destAlpha
) * invA
) >> 8);
356 auto da
= (invA
* destAlpha
) / resA
;
358 return Colour ((uint8
) (src
.getRed() + ((((int) getRed() - src
.getRed()) * da
) >> 8)),
359 (uint8
) (src
.getGreen() + ((((int) getGreen() - src
.getGreen()) * da
) >> 8)),
360 (uint8
) (src
.getBlue() + ((((int) getBlue() - src
.getBlue()) * da
) >> 8)),
364 Colour
Colour::interpolatedWith (Colour other
, float proportionOfOther
) const noexcept
366 if (proportionOfOther
<= 0)
369 if (proportionOfOther
>= 1.0f
)
372 PixelARGB
c1 (getPixelARGB());
373 PixelARGB
c2 (other
.getPixelARGB());
374 c1
.tween (c2
, (uint32
) roundToInt (proportionOfOther
* 255.0f
));
380 //==============================================================================
381 float Colour::getFloatRed() const noexcept
{ return getRed() / 255.0f
; }
382 float Colour::getFloatGreen() const noexcept
{ return getGreen() / 255.0f
; }
383 float Colour::getFloatBlue() const noexcept
{ return getBlue() / 255.0f
; }
384 float Colour::getFloatAlpha() const noexcept
{ return getAlpha() / 255.0f
; }
386 //==============================================================================
387 void Colour::getHSB (float& h
, float& s
, float& v
) const noexcept
389 ColourHelpers::HSB
hsb (*this);
395 void Colour::getHSL (float& h
, float& s
, float& l
) const noexcept
397 ColourHelpers::HSL
hsl (*this);
403 float Colour::getHue() const noexcept
{ return ColourHelpers::HSB (*this).hue
; }
404 float Colour::getSaturation() const noexcept
{ return ColourHelpers::HSB (*this).saturation
; }
405 float Colour::getBrightness() const noexcept
{ return ColourHelpers::HSB (*this).brightness
; }
407 float Colour::getSaturationHSL() const noexcept
{ return ColourHelpers::HSL (*this).saturation
; }
408 float Colour::getLightness() const noexcept
{ return ColourHelpers::HSL (*this).lightness
; }
410 Colour
Colour::withHue (float h
) const noexcept
{ ColourHelpers::HSB
hsb (*this); hsb
.hue
= h
; return hsb
.toColour (*this); }
411 Colour
Colour::withSaturation (float s
) const noexcept
{ ColourHelpers::HSB
hsb (*this); hsb
.saturation
= s
; return hsb
.toColour (*this); }
412 Colour
Colour::withBrightness (float v
) const noexcept
{ ColourHelpers::HSB
hsb (*this); hsb
.brightness
= v
; return hsb
.toColour (*this); }
414 Colour
Colour::withSaturationHSL (float s
) const noexcept
{ ColourHelpers::HSL
hsl (*this); hsl
.saturation
= s
; return hsl
.toColour (*this); }
415 Colour
Colour::withLightness (float l
) const noexcept
{ ColourHelpers::HSL
hsl (*this); hsl
.lightness
= l
; return hsl
.toColour (*this); }
417 float Colour::getPerceivedBrightness() const noexcept
419 return std::sqrt (0.241f
* square (getFloatRed())
420 + 0.691f
* square (getFloatGreen())
421 + 0.068f
* square (getFloatBlue()));
424 //==============================================================================
425 Colour
Colour::withRotatedHue (float amountToRotate
) const noexcept
427 ColourHelpers::HSB
hsb (*this);
428 hsb
.hue
+= amountToRotate
;
429 return hsb
.toColour (*this);
432 Colour
Colour::withMultipliedSaturation (float amount
) const noexcept
434 ColourHelpers::HSB
hsb (*this);
435 hsb
.saturation
= jmin (1.0f
, hsb
.saturation
* amount
);
436 return hsb
.toColour (*this);
439 Colour
Colour::withMultipliedSaturationHSL (float amount
) const noexcept
441 ColourHelpers::HSL
hsl (*this);
442 hsl
.saturation
= jmin (1.0f
, hsl
.saturation
* amount
);
443 return hsl
.toColour (*this);
446 Colour
Colour::withMultipliedBrightness (float amount
) const noexcept
448 ColourHelpers::HSB
hsb (*this);
449 hsb
.brightness
= jmin (1.0f
, hsb
.brightness
* amount
);
450 return hsb
.toColour (*this);
453 Colour
Colour::withMultipliedLightness (float amount
) const noexcept
455 ColourHelpers::HSL
hsl (*this);
456 hsl
.lightness
= jmin (1.0f
, hsl
.lightness
* amount
);
457 return hsl
.toColour (*this);
460 //==============================================================================
461 Colour
Colour::brighter (float amount
) const noexcept
463 jassert (amount
>= 0.0f
);
464 amount
= 1.0f
/ (1.0f
+ amount
);
466 return Colour ((uint8
) (255 - (amount
* (255 - getRed()))),
467 (uint8
) (255 - (amount
* (255 - getGreen()))),
468 (uint8
) (255 - (amount
* (255 - getBlue()))),
472 Colour
Colour::darker (float amount
) const noexcept
474 jassert (amount
>= 0.0f
);
475 amount
= 1.0f
/ (1.0f
+ amount
);
477 return Colour ((uint8
) (amount
* getRed()),
478 (uint8
) (amount
* getGreen()),
479 (uint8
) (amount
* getBlue()),
483 //==============================================================================
484 Colour
Colour::greyLevel (float brightness
) noexcept
486 auto level
= ColourHelpers::floatToUInt8 (brightness
);
487 return Colour (level
, level
, level
);
490 //==============================================================================
491 Colour
Colour::contrasting (float amount
) const noexcept
493 return overlaidWith ((getPerceivedBrightness() >= 0.5f
495 : Colours::white
).withAlpha (amount
));
498 Colour
Colour::contrasting (Colour target
, float minContrast
) const noexcept
500 ColourHelpers::YIQ
bg (*this);
501 ColourHelpers::YIQ
fg (target
);
503 if (std::abs (bg
.y
- fg
.y
) >= minContrast
)
506 auto y1
= jmax (0.0f
, bg
.y
- minContrast
);
507 auto y2
= jmin (1.0f
, bg
.y
+ minContrast
);
508 fg
.y
= (std::abs (y1
- bg
.y
) > std::abs (y2
- bg
.y
)) ? y1
: y2
;
510 return fg
.toColour();
513 Colour
Colour::contrasting (Colour colour1
,
514 Colour colour2
) noexcept
516 auto b1
= colour1
.getPerceivedBrightness();
517 auto b2
= colour2
.getPerceivedBrightness();
518 float best
= 0.0f
, bestDist
= 0.0f
;
520 for (float i
= 0.0f
; i
< 1.0f
; i
+= 0.02f
)
522 auto d1
= std::abs (i
- b1
);
523 auto d2
= std::abs (i
- b2
);
524 auto dist
= jmin (d1
, d2
, 1.0f
- d1
, 1.0f
- d2
);
533 return colour1
.overlaidWith (colour2
.withMultipliedAlpha (0.5f
))
534 .withBrightness (best
);
537 //==============================================================================
538 String
Colour::toString() const
540 return String::toHexString ((int) argb
.getInARGBMaskOrder());
543 Colour
Colour::fromString (StringRef encodedColourString
)
545 return Colour (CharacterFunctions::HexParser
<uint32
>::parse (encodedColourString
.text
));
548 String
Colour::toDisplayString (const bool includeAlphaValue
) const
550 return String::toHexString ((int) (argb
.getInARGBMaskOrder() & (includeAlphaValue
? 0xffffffff : 0xffffff)))
551 .paddedLeft ('0', includeAlphaValue
? 8 : 6)
556 //==============================================================================
557 //==============================================================================
560 class ColourTests
: public UnitTest
564 : UnitTest ("Colour", UnitTestCategories::graphics
)
567 void runTest() override
569 auto testColour
= [this] (Colour colour
,
570 uint8 expectedRed
, uint8 expectedGreen
, uint8 expectedBlue
,
571 uint8 expectedAlpha
= 255, float expectedFloatAlpha
= 1.0f
)
573 expectEquals (colour
.getRed(), expectedRed
);
574 expectEquals (colour
.getGreen(), expectedGreen
);
575 expectEquals (colour
.getBlue(), expectedBlue
);
576 expectEquals (colour
.getAlpha(), expectedAlpha
);
577 expectEquals (colour
.getFloatAlpha(), expectedFloatAlpha
);
580 beginTest ("Constructors");
583 testColour (c1
, (uint8
) 0, (uint8
) 0, (uint8
) 0, (uint8
) 0, 0.0f
);
585 Colour
c2 ((uint32
) 0);
586 testColour (c2
, (uint8
) 0, (uint8
) 0, (uint8
) 0, (uint8
) 0, 0.0f
);
588 Colour
c3 ((uint32
) 0xffffffff);
589 testColour (c3
, (uint8
) 255, (uint8
) 255, (uint8
) 255, (uint8
) 255, 1.0f
);
592 testColour (c4
, (uint8
) 0, (uint8
) 0, (uint8
) 0, (uint8
) 255, 1.0f
);
594 Colour
c5 (255, 255, 255);
595 testColour (c5
, (uint8
) 255, (uint8
) 255, (uint8
) 255, (uint8
) 255, 1.0f
);
597 Colour
c6 ((uint8
) 0, (uint8
) 0, (uint8
) 0, (uint8
) 0);
598 testColour (c6
, (uint8
) 0, (uint8
) 0, (uint8
) 0, (uint8
) 0, 0.0f
);
600 Colour
c7 ((uint8
) 255, (uint8
) 255, (uint8
) 255, (uint8
) 255);
601 testColour (c7
, (uint8
) 255, (uint8
) 255, (uint8
) 255, (uint8
) 255, 1.0f
);
603 Colour
c8 ((uint8
) 0, (uint8
) 0, (uint8
) 0, 0.0f
);
604 testColour (c8
, (uint8
) 0, (uint8
) 0, (uint8
) 0, (uint8
) 0, 0.0f
);
606 Colour
c9 ((uint8
) 255, (uint8
) 255, (uint8
) 255, 1.0f
);
607 testColour (c9
, (uint8
) 255, (uint8
) 255, (uint8
) 255, (uint8
) 255, 1.0f
);
613 testColour (Colour::fromHSV (0.0f
, 0.0f
, 0.0f
, 1.0f
), 0, 0, 0);
615 testColour (Colour::fromHSV (0.0f
, 0.0f
, 1.0f
, 1.0f
), 255, 255, 255);
617 testColour (Colour::fromHSV (0.0f
, 1.0f
, 1.0f
, 1.0f
), 255, 0, 0);
618 testColour (Colour::fromHSV (1.0f
, 1.0f
, 1.0f
, 1.0f
), 255, 0, 0);
620 testColour (Colour::fromHSV (120 / 360.0f
, 1.0f
, 1.0f
, 1.0f
), 0, 255, 0);
622 testColour (Colour::fromHSV (240 / 360.0f
, 1.0f
, 1.0f
, 1.0f
), 0, 0, 255);
624 testColour (Colour::fromHSV (60 / 360.0f
, 1.0f
, 1.0f
, 1.0f
), 255, 255, 0);
626 testColour (Colour::fromHSV (180 / 360.0f
, 1.0f
, 1.0f
, 1.0f
), 0, 255, 255);
628 testColour (Colour::fromHSV (300 / 360.0f
, 1.0f
, 1.0f
, 1.0f
), 255, 0, 255);
630 testColour (Colour::fromHSV (0.0f
, 0.0f
, 0.75f
, 1.0f
), 191, 191, 191);
632 testColour (Colour::fromHSV (0.0f
, 0.0f
, 0.5f
, 1.0f
), 128, 128, 128);
634 testColour (Colour::fromHSV (0.0f
, 1.0f
, 0.5f
, 1.0f
), 128, 0, 0);
636 testColour (Colour::fromHSV (60 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 128, 128, 0);
638 testColour (Colour::fromHSV (120 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 0, 128, 0);
640 testColour (Colour::fromHSV (300 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 128, 0, 128);
642 testColour (Colour::fromHSV (180 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 0, 128, 128);
644 testColour (Colour::fromHSV (240 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 0, 0, 128);
650 testColour (Colour::fromHSL (0.0f
, 0.0f
, 0.0f
, 1.0f
), 0, 0, 0);
652 testColour (Colour::fromHSL (0.0f
, 0.0f
, 1.0f
, 1.0f
), 255, 255, 255);
654 testColour (Colour::fromHSL (0.0f
, 1.0f
, 0.5f
, 1.0f
), 255, 0, 0);
655 testColour (Colour::fromHSL (1.0f
, 1.0f
, 0.5f
, 1.0f
), 255, 0, 0);
657 testColour (Colour::fromHSL (120 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 0, 255, 0);
659 testColour (Colour::fromHSL (240 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 0, 0, 255);
661 testColour (Colour::fromHSL (60 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 255, 255, 0);
663 testColour (Colour::fromHSL (180 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 0, 255, 255);
665 testColour (Colour::fromHSL (300 / 360.0f
, 1.0f
, 0.5f
, 1.0f
), 255, 0, 255);
667 testColour (Colour::fromHSL (0.0f
, 0.0f
, 0.75f
, 1.0f
), 191, 191, 191);
669 testColour (Colour::fromHSL (0.0f
, 0.0f
, 0.5f
, 1.0f
), 128, 128, 128);
671 testColour (Colour::fromHSL (0.0f
, 1.0f
, 0.25f
, 1.0f
), 128, 0, 0);
673 testColour (Colour::fromHSL (60 / 360.0f
, 1.0f
, 0.25f
, 1.0f
), 128, 128, 0);
675 testColour (Colour::fromHSL (120 / 360.0f
, 1.0f
, 0.25f
, 1.0f
), 0, 128, 0);
677 testColour (Colour::fromHSL (300 / 360.0f
, 1.0f
, 0.25f
, 1.0f
), 128, 0, 128);
679 testColour (Colour::fromHSL (180 / 360.0f
, 1.0f
, 0.25f
, 1.0f
), 0, 128, 128);
681 testColour (Colour::fromHSL (240 / 360.0f
, 1.0f
, 0.25f
, 1.0f
), 0, 0, 128);
684 beginTest ("Modifiers");
686 Colour
red (255, 0, 0);
687 testColour (red
, 255, 0, 0);
689 testColour (red
.withHue (120.0f
/ 360.0f
), 0, 255, 0);
690 testColour (red
.withSaturation (0.5f
), 255, 128, 128);
691 testColour (red
.withSaturationHSL (0.5f
), 191, 64, 64);
692 testColour (red
.withBrightness (0.5f
), 128, 0, 0);
693 testColour (red
.withLightness (1.0f
), 255, 255, 255);
694 testColour (red
.withRotatedHue (120.0f
/ 360.0f
), 0, 255, 0);
695 testColour (red
.withRotatedHue (480.0f
/ 360.0f
), 0, 255, 0);
696 testColour (red
.withRotatedHue (-240.0f
/ 360.0f
), 0, 255, 0);
697 testColour (red
.withRotatedHue (-600.0f
/ 360.0f
), 0, 255, 0);
698 testColour (red
.withMultipliedSaturation (0.0f
), 255, 255, 255);
699 testColour (red
.withMultipliedSaturationHSL (0.0f
), 128, 128, 128);
700 testColour (red
.withMultipliedBrightness (0.5f
), 128, 0, 0);
701 testColour (red
.withMultipliedLightness (2.0f
), 255, 255, 255);
702 testColour (red
.withMultipliedLightness (1.0f
), 255, 0, 0);
703 testColour (red
.withLightness (red
.getLightness()), 255, 0, 0);
708 static ColourTests colourTests
;