|
11 | 11 | from . import filters |
12 | 12 | from . import contrast |
13 | 13 | from . import harmonies |
| 14 | +from . import average |
14 | 15 | from . import util |
15 | 16 | from . import algebra as alg |
16 | 17 | from itertools import zip_longest as zipl |
|
61 | 62 | from .interpolate.bspline_natural import NaturalBSpline |
62 | 63 | from .interpolate.monotone import Monotone |
63 | 64 | from .types import Plugin |
64 | | -from typing import overload, Union, Sequence, Dict, List, Optional, Any, Callable, Tuple, Type, Mapping |
| 65 | +from typing import overload, Union, Sequence, Iterable, Dict, List, Optional, Any, Callable, Tuple, Type, Mapping |
65 | 66 |
|
66 | 67 |
|
67 | 68 | class ColorMatch: |
@@ -131,6 +132,7 @@ class Color(metaclass=ColorMeta): |
131 | 132 | INTERPOLATE = util.DEF_INTERPOLATE |
132 | 133 | DELTA_E = util.DEF_DELTA_E |
133 | 134 | HARMONY = util.DEF_HARMONY |
| 135 | + AVERAGE = util.DEF_AVERAGE |
134 | 136 | CHROMATIC_ADAPTATION = 'bradford' |
135 | 137 | CONTRAST = 'wcag21' |
136 | 138 |
|
@@ -657,7 +659,7 @@ def clip(self, space: Optional[str] = None) -> 'Color': |
657 | 659 | space = self.space() |
658 | 660 |
|
659 | 661 | # Convert to desired space |
660 | | - c = self.convert(space, in_place=True) |
| 662 | + c = self.convert(space, in_place=True, norm=False) |
661 | 663 | gamut.clip_channels(c) |
662 | 664 |
|
663 | 665 | # Adjust "this" color |
@@ -820,6 +822,26 @@ def interpolate( |
820 | 822 | **kwargs |
821 | 823 | ) |
822 | 824 |
|
| 825 | + @classmethod |
| 826 | + def average( |
| 827 | + cls, |
| 828 | + colors: Iterable[ColorInput], |
| 829 | + *, |
| 830 | + space: Optional[str] = None, |
| 831 | + out_space: Optional[str] = None, |
| 832 | + premultiplied: bool = True, |
| 833 | + **kwargs: Any |
| 834 | + ) -> 'Color': |
| 835 | + """Average the colors.""" |
| 836 | + |
| 837 | + if space is None: |
| 838 | + space = cls.AVERAGE |
| 839 | + |
| 840 | + if out_space is None: |
| 841 | + out_space = space |
| 842 | + |
| 843 | + return average.average(cls, colors, space, premultiplied).convert(out_space, in_place=True) |
| 844 | + |
823 | 845 | def filter( # noqa: A003 |
824 | 846 | self, |
825 | 847 | name: str, |
|
0 commit comments