Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be explicit about CPAL color space #763

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions vello/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod bitmap;
use std::sync::Arc;

use peniko::{
color::{palette, DynamicColor, Srgb},
color::{palette, AlphaColor, DynamicColor, Srgb},
kurbo::{Affine, BezPath, Point, Rect, Shape, Stroke, Vec2},
BlendMode, Blob, Brush, BrushRef, Color, ColorStop, ColorStops, ColorStopsSource, Compose,
Extend, Fill, Font, Gradient, Image, Mix, StyleRef,
Expand Down Expand Up @@ -979,7 +979,9 @@ fn conv_brush(
}
}

fn color_index(cpal: &'_ Cpal<'_>, palette_index: u16) -> Option<Color> {
// The OpenType color palette is defined to be using the sRGB color space.
// <https://learn.microsoft.com/en-us/typography/opentype/spec/cpal#palette-entries-and-color-records>
fn color_index(cpal: &'_ Cpal<'_>, palette_index: u16) -> Option<AlphaColor<Srgb>> {
// The "application determined" foreground color should be used
// This will be handled by the caller
if palette_index == 0xFFFF {
Expand All @@ -988,7 +990,7 @@ fn color_index(cpal: &'_ Cpal<'_>, palette_index: u16) -> Option<Color> {
let actual_colors = cpal.color_records_array().unwrap().unwrap();
// TODO: Error reporting in the `None` case
let color = actual_colors.get(usize::from(palette_index))?;
Some(Color::from_rgba8(
Some(AlphaColor::<Srgb>::from_rgba8(
color.red,
color.green,
color.blue,
Expand Down
Loading