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

Speed up Lab conversion with Srgb/LinSrgb fast path, use palette FromStr impl #55

Merged
merged 1 commit into from
Aug 2, 2023

Conversation

okaneco
Copy link
Owner

@okaneco okaneco commented Aug 2, 2023

  • Swap to using palette's FromStr implementation for colors. Now 3 or 6 digit hex colors are permitted.
  • Use the special-cased Srgb/LinSrgb conversion between u8 and f32/f64 where possible, that version uses a lookup table and approximation

Speedup gains increase as image size increases. On a 4500x3000 image, a 44% speedup was seen reducing the total time to calculate centroids from 7.8s to 4.3s after switching from into_format to using into_linear. The speedup is closer to 15-17% on smaller images (320x200) but still noticeable when measured.

Example speedups for reading in images in Rgb, converting them to Lab, and calculating the centroids. Prompted from this discussion Ogeon/palette#341 (reply in thread)

Image Size into_format into_linear
4547x3032 7.8s 4.3s
1700x2200 2.4s 1.3s
805x1000 0.48s 0.35s
320x206 0.056s 0.046s

Srgb/LinSrgb conversion between u8 and f32/f64 has been special-cased
to use a lookup table and approximation. This PR uses that
implementation where possible.

Speedup gains increase as image size increases. On a 4500x3000 image,
a 44% speedup was seen reducing the time from 7.8s to 4.3s after
switching from `into_format` to using `into_linear`. The speedup is
closer to 15-17% on smaller images (320x200) but still noticeable
when measured.

Swap to using palette's FromStr implementation for colors. Now 3 or 6
digit hex colors are permitted.
@okaneco okaneco added the optimization Improvements in performance label Aug 2, 2023
@okaneco okaneco merged commit 6bbd568 into master Aug 2, 2023
@okaneco okaneco deleted the intolinear branch August 2, 2023 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Improvements in performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant