Wide-Gamut Color Spaces

Gay.jl supports wide-gamut color spaces beyond standard sRGB, enabling richer, more vibrant colors on modern displays.

Color Space Comparison

Color SpaceCoverageUse Case
sRGB~35% of visibleWeb, legacy displays
Display P3~45% of visibleApple devices, DCI cinema
Rec.2020~76% of visibleHDR, UHDTV, future-proof

Setup

using Gay
using Colors: RGB, LCHab

Available Color Spaces

srgb = SRGB()
p3 = DisplayP3()
rec2020 = Rec2020()

println("Available color spaces:")
println("  • SRGB()")
println("  • DisplayP3()")
println("  • Rec2020()")
Available color spaces:
  • SRGB()
  • DisplayP3()
  • Rec2020()

Generating Colors in Different Spaces

println("\nSame seed (42) in different color spaces:")

gay_seed!(42)
c_srgb = next_color(SRGB())
println("sRGB:       ", c_srgb)

gay_seed!(42)
c_p3 = next_color(DisplayP3())
println("Display P3: ", c_p3)

gay_seed!(42)
c_rec2020 = next_color(Rec2020())
println("Rec.2020:   ", c_rec2020)

Same seed (42) in different color spaces:
sRGB:       RGB{Float64}(0.0,0.7327246286990455,0.0)
Display P3: RGB{Float64}(0.0,0.7327246286990455,0.0)
Rec.2020:   RGB{Float64}(0.0,0.7327246286990455,0.0)

Wide-Gamut Palettes

gay_seed!(1337)

println("\n6-color palettes per color space:")

println("\nsRGB palette:")
show_palette(next_palette(6, SRGB()))

gay_seed!(1337)
println("Display P3 palette:")
show_palette(next_palette(6, DisplayP3()))

gay_seed!(1337)
println("Rec.2020 palette:")
show_palette(next_palette(6, Rec2020()))

6-color palettes per color space:

sRGB palette:
████ #FF8AFF  ████ #00ABFF  ████ #261B00  ████ #0053AF  ████ #71E300  ████ #A60023
Display P3 palette:
████ #FF8AFF  ████ #00ABFF  ████ #261B00  ████ #0053AF  ████ #71E300  ████ #A60023
Rec.2020 palette:
████ #FF8AFF  ████ #00ABFF  ████ #261B00  ████ #0053AF  ████ #71E300  ████ #A60023

Perceptual Uniformity in LCH

Gay.jl samples colors in LCH (Lightness-Chroma-Hue) space to ensure perceptual uniformity.

Gamut Mapping Example

lch = LCHab(50, 100, 120)
rgb = convert(RGB, lch)

println("\nGamut mapping example:")
println("  LCH: L=$(lch.l), C=$(lch.c), H=$(lch.h)")
println("  RGB: R=$(round(rgb.r, digits=3)), G=$(round(rgb.g, digits=3)), B=$(round(rgb.b, digits=3))")

Gamut mapping example:
  LCH: L=50.0, C=100.0, H=120.0
  RGB: R=0.205, G=0.538, B=0.0

Practical Recommendations

ScenarioRecommended Space
Web graphicsSRGB()
macOS/iOS appsDisplayP3()
HDR videoRec2020()
Maximum vibrancyRec2020()
AccessibilitySRGB() (widest support)

Color Space Detection

println("\nTerminal color support check:")
println("  COLORTERM: ", get(ENV, "COLORTERM", "not set"))

println("\n◆ Wide-gamut color spaces example complete")

Terminal color support check:
  COLORTERM: not set

◆ Wide-gamut color spaces example complete