mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
parent
ce9d420472
commit
343a423e9f
@ -255,7 +255,7 @@ pub trait ColorEncode {
|
|||||||
impl ColorEncode for ColorSpace {
|
impl ColorEncode for ColorSpace {
|
||||||
fn encode(&self, color: Color) -> [f32; 4] {
|
fn encode(&self, color: Color) -> [f32; 4] {
|
||||||
match self {
|
match self {
|
||||||
ColorSpace::Oklab => {
|
ColorSpace::Oklab | ColorSpace::Oklch => {
|
||||||
let [l, c, h, alpha] = color.to_oklch().to_vec4();
|
let [l, c, h, alpha] = color.to_oklch().to_vec4();
|
||||||
// Clamp on Oklch's chroma, not Oklab's a\* and b\* as to not distort hue.
|
// Clamp on Oklch's chroma, not Oklab's a\* and b\* as to not distort hue.
|
||||||
let c = c.clamp(0.0, 0.5);
|
let c = c.clamp(0.0, 0.5);
|
||||||
@ -272,9 +272,6 @@ impl ColorEncode for ColorSpace {
|
|||||||
let [h, s, v, _] = color.to_hsv().to_vec4();
|
let [h, s, v, _] = color.to_hsv().to_vec4();
|
||||||
[h / 360.0, s, v, 0.0]
|
[h / 360.0, s, v, 0.0]
|
||||||
}
|
}
|
||||||
ColorSpace::Oklch => {
|
|
||||||
unimplemented!("Oklch is always converted to Oklab first")
|
|
||||||
}
|
|
||||||
_ => color.to_vec4(),
|
_ => color.to_vec4(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
tests/typ/bugs/2902-gradient-oklch-panic.typ
Normal file
20
tests/typ/bugs/2902-gradient-oklch-panic.typ
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Minimal reproduction of #2902
|
||||||
|
// Ref: false
|
||||||
|
|
||||||
|
---
|
||||||
|
#set page(width: 15cm, height: auto, margin: 1em)
|
||||||
|
#set block(width: 100%, height: 1cm, above: 2pt)
|
||||||
|
|
||||||
|
// Oklch
|
||||||
|
#block(fill: gradient.linear(red, purple, space: oklch))
|
||||||
|
#block(fill: gradient.linear(..color.map.rainbow, space: oklch))
|
||||||
|
#block(fill: gradient.linear(..color.map.plasma, space: oklch))
|
||||||
|
|
||||||
|
---
|
||||||
|
#set page(width: 15cm, height: auto, margin: 1em)
|
||||||
|
#set block(width: 100%, height: 1cm, above: 2pt)
|
||||||
|
|
||||||
|
// Oklab
|
||||||
|
#block(fill: gradient.linear(red, purple, space: oklab))
|
||||||
|
#block(fill: gradient.linear(..color.map.rainbow, space: oklab))
|
||||||
|
#block(fill: gradient.linear(..color.map.plasma, space: oklab))
|
Loading…
x
Reference in New Issue
Block a user