Skip to content

Commit

Permalink
Fix issues with continuous interpolations and derived interpolations (#…
Browse files Browse the repository at this point in the history
…441)

* Fix issues with continuous interpolations and derived interpolations

Continuous interpolation would sometimes apply premultiplication to a
color twice and also would apply a hue offset to a hue during fixup
twice.

Fixes #440

* Ignore lint errors we don't care about and fix conditional parenthesis

* Reference the appropriate index

* Adjust changelog phrasing
  • Loading branch information
facelessuser authored Nov 29, 2024
1 parent 6d886b3 commit 2a8b99b
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion coloraide/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,5 @@ def parse_version(ver: str) -> Version:
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(4, 0, 0, "final")
__version_info__ = Version(4, 0, 1, "final")
__version__ = __version_info__._get_canonical()
2 changes: 1 addition & 1 deletion coloraide/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def register(
cls._get_convert_chain.cache_clear()
raise TypeError(f"Cannot register plugin of type '{type(i)}'")

if p.NAME != "*" and p.NAME not in mapping or overwrite:
if p.NAME != "*" and (p.NAME not in mapping or overwrite):
mapping[p.NAME] = p
elif not silent:
if reset_convert_cache: # pragma: no cover
Expand Down
5 changes: 3 additions & 2 deletions coloraide/interpolate/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def normalize_hue(
else:
raise ValueError(f"Unknown hue adjuster '{hue}'")

c1 = color1[index] + offset
c1 = color1[index]
c2 = (color2[index] % 360) + offset

# Adjust hue, handle gaps across `NaN`s
Expand Down Expand Up @@ -156,7 +156,8 @@ def handle_undefined(self) -> None:
# Two good values, store the last good value and continue
if not a_nan and not b_nan:
if self.premultiplied and i == alpha:
self.premultiply(c1)
if x == 1:
self.premultiply(c1)
self.premultiply(c2)
last = b
continue
Expand Down
7 changes: 7 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 4.0.1

- **FIX**: Fix issue with `continuous` interpolation (and any that are derived from it, e.g., cubic spline
interpolations) that can cause bad hue fixup calculations.
- **FIX**: Fix issue with `continuous` interpolation (and any that are derived from it, e.g., cubic spline
interpolations) that can cause premultiplication to be applied to a color twice.

## 4.0

- **NEW**: Officially support Python 3.13.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/markdown/demos/3d_models.html
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ <h1>ColorAide Color Space Models</h1>
let colorSpaces = null
let colorGamuts = null
let lastModel = null
let package = 'coloraide-4.0-py3-none-any.whl'
let package = 'coloraide-4.0.1-py3-none-any.whl'
const defaultSpace = 'lab'
const defaultGamut = 'srgb'
const exceptions = new Set(['hwb', 'ryb', 'ryb-biased'])
Expand Down
2 changes: 1 addition & 1 deletion docs/src/markdown/demos/colorpicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ <h1>ColorAide Color Picker</h1>
let pyodide = null
let webspace = ''
let initial = 'oklab(0.69 0.13 -0.1 / 0.85)'
let package = 'coloraide-4.0-py3-none-any.whl'
let package = 'coloraide-4.0.1-py3-none-any.whl'

const base = `${window.location.origin}/${window.location.pathname.split('/')[1]}/playground/`
package = base + package
Expand Down
2 changes: 1 addition & 1 deletion docs/src/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ extra_css:
- assets/coloraide-extras/extra.css
extra_javascript:
- https://unpkg.com/[email protected]/dist/mermaid.min.js
- playground-config-70f29cae.js
- playground-config-4f0f586c.js
- https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js
- assets/coloraide-extras/extra-notebook.js

Expand Down
2 changes: 0 additions & 2 deletions docs/theme/assets/coloraide-extras/extra-notebook-DQWpIrCE.js

This file was deleted.

2 changes: 2 additions & 0 deletions docs/theme/assets/coloraide-extras/extra-notebook-UmZ-G8NV.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var colorNotebook = {
"playgroundWheels": ['pygments-2.17.2-py3-none-any.whl', 'coloraide-4.0-py3-none-any.whl'],
"notebookWheels": ['pyyaml', 'Markdown-3.6-py3-none-any.whl', 'pymdown_extensions-10.10.1-py3-none-any.whl', 'pygments-2.17.2-py3-none-any.whl', 'coloraide-4.0-py3-none-any.whl'],
"playgroundWheels": ['pygments-2.17.2-py3-none-any.whl', 'coloraide-4.0.1-py3-none-any.whl'],
"notebookWheels": ['pyyaml', 'Markdown-3.6-py3-none-any.whl', 'pymdown_extensions-10.10.1-py3-none-any.whl', 'pygments-2.17.2-py3-none-any.whl', 'coloraide-4.0.1-py3-none-any.whl'],
"defaultPlayground": "import coloraide\ncoloraide.__version__\nColor('red')"
}
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ extra_css:
- assets/coloraide-extras/extra-696a2734c9.css
extra_javascript:
- https://unpkg.com/[email protected]/dist/mermaid.min.js
- playground-config-70f29cae.js
- playground-config-4f0f586c.js
- https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js
- assets/coloraide-extras/extra-notebook-DQWpIrCE.js
- assets/coloraide-extras/extra-notebook-UmZ-G8NV.js

extra:
social:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ lint.ignore = [
"RUF012",
"RUF005",
"PGH004",
"RUF022",
"RUF023",
"RUF100",
"B905"
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ def test_bspline_undefined_alpha(self):
space='srgb',
method='bspline'
)(0.75),
Color('rgb(3.4932 38.425 174.66 / 0.76042)')
Color('rgb(3.4932 76.849 174.66 / 0.76042)')
)

self.assertColorEqual(
Expand Down

0 comments on commit 2a8b99b

Please sign in to comment.