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

COLR in floating point (IVS/resolve only) #725

Merged
merged 4 commits into from
Dec 7, 2023
Merged

COLR in floating point (IVS/resolve only) #725

merged 4 commits into from
Dec 7, 2023

Conversation

dfrg
Copy link
Member

@dfrg dfrg commented Nov 29, 2023

As requested, this is the floating point refactor extracted from #697.

  • add methods to IVS to compute scalars/deltas in f32.
  • move ColrInstance from read-fonts to a private module in skrifa and update it to produce results in f32.

@drott I believe this captures what you requested as a separate, clean PR.

As requested, this is the floating point refactor extracted from #697.

* add methods to IVS to compute scalars/deltas in f32.
* move `ColrInstance` from read-fonts to a private module in skrifa and update it to produce results in f32.
skrifa/src/color/instance.rs Outdated Show resolved Hide resolved
skrifa/src/color/instance.rs Outdated Show resolved Hide resolved
@drott
Copy link
Contributor

drott commented Nov 30, 2023

Scratch my earlier comment on the offsets, I was confused by the test diffs after rebasing. #722 is now rebased on top of this.

impl<'a> ColorStops<'a> {
/// Returns an iterator yielding resolved color stops with variation deltas
/// applied.
pub fn resolve(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think given that I see some differences in the offsets in my results before and after this change, it would be useful to add a few tests for this part, just to be able to verify this one level lower down.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the intermediate 2.14 overflow and updated the IVS floating point test to check 2.14 and 16.16 deltas.

@dfrg
Copy link
Member Author

dfrg commented Nov 30, 2023

Since #722 is already rebased on this, would you like me to address your comments in a follow up after that lands or fix them here? Either works for me.

@drott
Copy link
Contributor

drott commented Nov 30, 2023

after that lands or fix them here? Either works for me.

I'd say let's fix them here first, shouldn't be hard to rebase again.

@dfrg
Copy link
Member Author

dfrg commented Dec 1, 2023

Scratch my earlier comment on the offsets, I was confused by the test diffs after rebasing. #722 is now rebased on top of this.

There actually is an issue here. Some of the intermediate 2.14 deltas in the test font overflow a signed 16-bit integer so they were wrapping negative. The values are such that your stop offset normalization will correct them. I’m not sure if this is in spec but I have a patch that avoids the overflow.

- update resolve_paint comment to specify that we're returning values in floating point
- make use of UfWord delta type for radial gradient radii
- avoid overflow of intermediate deltas for 2.14 values and update floating point IVS test to make sure they work
@drott
Copy link
Contributor

drott commented Dec 1, 2023

I noticed that my variable clipbox test fails with this (including the latest 2257849 commit).

---- color::colrv1_traversal::tests::clipbox_test stdout ----
thread 'color::colrv1_traversal::tests::clipbox_test' panicked at skrifa/src/color/colrv1_traversal.rs:512:13:
Clip boxes do not match. Actual: BoundingBox { x_min: 200.0122, y_min: 500.0, x_max: 500.0, y_max: 1000.0 }, expected: BoundingBox { x_min: 200.0, y_min: 500.0, x_max: 500.0, y_max: 1000.0 }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Clip boxes are 16bit FWORD types with the same size of a delta - represented in float, I think the first shifted x_min should not be fractional but amount to 200 precisely.

@dfrg
Copy link
Member Author

dfrg commented Dec 1, 2023

I’ll dig into this to make sure but I suspect it is working as intended. We’re no longer rounding/truncating after applying deltas to FWORD values and I think this is desired behavior for other properties (specifically, gradient parameters). If we want to special case clip boxes by rounding (or better, floor/ceil the min/max values), that seems reasonable to me. We can also add a snap_to_grid() method on BoundingBox<f32> that does the appropriate thing and pass this choice to the consumer.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a drive-by from me, but this looks great

read-fonts/src/tables/variations.rs Outdated Show resolved Hide resolved
read-fonts/src/tables/variations.rs Outdated Show resolved Hide resolved
skrifa/src/color/instance.rs Outdated Show resolved Hide resolved
skrifa/src/color/instance.rs Outdated Show resolved Hide resolved
dfrg added 2 commits December 1, 2023 13:54
* Maybe better API for floating point IVS

Make use of the type system to appropriately apply floating point deltas to target values.
@drott
Copy link
Contributor

drott commented Dec 7, 2023

FYI, rebased #722 on top of this and the JSON colrv1 graph dump tests still pass. I did not observe any differences in values.

@dfrg dfrg merged commit de233da into main Dec 7, 2023
9 checks passed
@dfrg dfrg deleted the float-colr branch December 7, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants