Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit fa1aa63

Browse files
committed
Merge pull request #59 from janek-warchol/master
Add AppleRGBColor
2 parents 8757798 + e2ded63 commit fa1aa63

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

colormath/color_objects.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,39 @@ class AdobeRGBColor(BaseRGBColor):
689689
}
690690

691691

692+
class AppleRGBColor(BaseRGBColor):
693+
"""
694+
Represents an AppleRGB color.
695+
696+
.. note:: If you pass in upscaled values, we automatically scale them
697+
down to 0.0-1.0. If you need the old upscaled values, you can
698+
retrieve them with :py:meth:`get_upscaled_value_tuple`.
699+
700+
:ivar float rgb_r: R coordinate
701+
:ivar float rgb_g: G coordinate
702+
:ivar float rgb_b: B coordinate
703+
:ivar bool is_upscaled: If True, RGB values are between 1-255. If False,
704+
0.0-1.0.
705+
"""
706+
707+
#: RGB space's gamma constant.
708+
rgb_gamma = 1.8
709+
#: The RGB space's native illuminant. Important when converting to XYZ.
710+
native_illuminant = "d65"
711+
conversion_matrices = {
712+
"xyz_to_rgb":
713+
numpy.array((
714+
(2.9515373, -1.2894116, -0.4738445),
715+
(-1.0851093, 1.9908566, 0.0372026),
716+
(0.0854934, -0.2694964, 1.0912975))),
717+
"rgb_to_xyz":
718+
numpy.array((
719+
(0.4497288, 0.3162486, 0.1844926),
720+
(0.2446525, 0.6720283, 0.0833192),
721+
(0.0251848, 0.1411824, 0.9224628))),
722+
}
723+
724+
692725
class HSLColor(ColorBase):
693726
"""
694727
Represents an HSL color.

tests/test_color_objects.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from colormath.color_conversions import convert_color
88
from colormath.color_objects import SpectralColor, XYZColor, xyYColor, \
99
LabColor, LuvColor, LCHabColor, LCHuvColor, sRGBColor, HSLColor, HSVColor, \
10-
CMYColor, CMYKColor, AdobeRGBColor, IPTColor
10+
CMYColor, CMYKColor, AdobeRGBColor, AppleRGBColor, IPTColor
1111

1212

1313
class BaseColorConversionTest(unittest.TestCase):
@@ -95,6 +95,11 @@ def test_conversion_to_rgb(self):
9595
rgb = convert_color(self.color, sRGBColor)
9696
self.assertColorMatch(rgb, sRGBColor(0.715, 0.349, 0.663))
9797

98+
def test_conversion_to_apple_rgb(self):
99+
self.color = XYZColor(0.0157, 0.0191, 0.0331)
100+
rgb = convert_color(self.color, AppleRGBColor)
101+
self.assertColorMatch(rgb, AppleRGBColor(0.0411, 0.1214, 0.1763))
102+
98103
def test_conversion_to_adobe_rgb(self):
99104
self.color = XYZColor(0.2553, 0.1125, 0.0011)
100105
rgb = convert_color(self.color, AdobeRGBColor)

0 commit comments

Comments
 (0)