Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Dec 5, 2024
1 parent c133e06 commit d237102
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
24 changes: 14 additions & 10 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Changelog

## 4.0.2

- **FIX**: Fix averaging issues.
- Polar spaces should set hues to undefined when colors are evenly distributed as circular means cannot be found
in these cases.
- When averaging within a polar space, if the hue is determined to be undefined during averaging, the color will
be treated as if achromatic.
- Transparency, when premultiplication is enabled, is now taken into account when processing hues in averaging.
- When premultiplication is enabled and a color has undefined transparency, it will be treated as if fully
transparent.
## 4.1.0

- **NEW**: The `powerless` parameter is deprecated in `average()` as it is required to be always on for proper polar
space averaging.
- **FIX**: Polar space averaging was not setting hues to undefined when colors are evenly distributed. This is
required as circular means cannot be found in these cases.
- **FIX**: When averaging within a polar space, if the result hue is determined to be undefined at the end of
averaging, the color will be treated as if achromatic, setting saturation/chroma as necessary. This is needed to
prevent serialization of achromatic colors to a non-achromatic color when undefined values are resolved.
- **FIX**: Fully transparent colors should only contribute alpha in color averaging, regardless of `premultiply`
setting. This prevents fully transparent color channels, which provide no meaniful data, from distorting averages.
- **FIX**: When averaging in a polar space, if a color is considered achromatic but does not have an undefined hue,
the hue will be treated as undefined. Essentially the `powerless` parameter is now always `True`. This ensures that
achromatic colors properly contribute to the average without distorting the hue.

## 4.0.1

Expand Down
5 changes: 5 additions & 0 deletions docs/src/markdown/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,11 @@ Return

///

/// warning | Deprecated 4.1
`powerless` parameter has been deprecated in 4.1 and as it is now always enabled. The parameter no longer does anything
and will be removed in the future.
///

## `#!py Color.filter` {#cvd}

```py
Expand Down
35 changes: 21 additions & 14 deletions docs/src/markdown/average.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,28 @@ Color.average(['red', 'yellow', 'orange', 'green'])
ColorAide can average colors in rectangular spaces and cylindrical spaces. When applying averaging in a cylindrical
space, hues will be averaged taking the circular mean.

Cylindrical averaging may not provide as good of results as using rectangular spaces, but is provided to provide a sane
approach if a cylindrical space is used.
Colors that appear to be achromatic will have their hue treated as undefined, even if the hue is defined.

Cylindrical averaging may provide very different results that averaging in rectangular spaces.

```py play
Color.average(['orange', 'yellow', 'red'])
Color.average(['orange', 'yellow', 'red'], space='hsl')
Color.average(['purple', 'green', 'blue'])
Color.average(['purple', 'green', 'blue'], space='hsl')
```

Because calculations are done in a cylindrical space, the averaged colors can be different than what is acquired with
rectangular space averaging.
It should be noted that when averaging colors with hues which are evently distributed around the color wheel, the result
will produce an achromatic hue. When achromatic hues are produced during circular mean, the color will discard
chroma/saturation information, producing an achromatic color.

```py play
Color.average(['purple', 'green', 'blue'])
Color.average(['purple', 'green', 'blue'], space='hsl')
Color.average(['red', 'green', 'blue'], space='hsl')
```

## Averaging with Transparency

ColorAide, by default, will account for transparency when averaging colors. Colors which are more transparent will have
less of an impact on the average. This is done by premultiplying the colors before averaging.
less of an impact on the average. This is done by premultiplying the colors before averaging, essentially weighting the
color components where more opaque colors have a greater influence on the average.

```py play
for i in range(12):
Expand All @@ -57,8 +59,12 @@ for i in range(12):
)
```

If you'd like to average the channels without taking transparency into consideration, simply set `premultiplied` to
`#!py False`.
There are cases where this approach of averaging may not be desired. It may be that color averaging is desired without
considering transparency. If so, `premultiplied` can be disabled by setting it to `#!py False`. While the average of
transparency is calculated, it can be discared from the final result if desired.

It should be noted that when a color is fully transparent, its color components will be ignored, regardless of the
`premultiplied` parameter, as fully transparent colors provide no meaniful color information.

```py play
for i in range(12):
Expand All @@ -77,8 +83,8 @@ provided for averaging cylindrical colors, particularly achromatic colors.
Color.average(['white', 'color(srgb 0 0 1)'], space='hsl')
```

Implied achromatic hues are only considered undefined if `powerless` is enabled. This is similar to how interpolation
works. By default, explicitly defined hues are respected if working directly in the averaging color space.
When averaging hues in a polar space, implied achromatic hues are also treated as undefined as counting such hues would
distort the average in a non-meaniful way.

```py play
Color.average(['hsl(30 0 100)', 'hsl(240 100 50 / 1)'], space='hsl')
Expand All @@ -94,7 +100,8 @@ for i in range(12):
Color.average(['darkgreen', f'color(srgb 0 none 0 / {i / 11})', 'color(srgb 0 0 1)'])
```

When `premultiplied` is enabled, premultiplication will not be applied to a color if its `alpha` is undefined.
When `premultiplied` is enabled, premultiplication will not be applied to a color if its `alpha` is undefined as it is
unknown how to weight the color, instead the color is treated with full weight.

```py play
Color.average(['darkgreen', f'color(srgb 0 0.50196 0 / none)', 'color(srgb 0 0 1)'])
Expand Down

0 comments on commit d237102

Please sign in to comment.