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

Rasterization performance #47

Closed
tdewolff opened this issue May 20, 2020 · 4 comments
Closed

Rasterization performance #47

tdewolff opened this issue May 20, 2020 · 4 comments

Comments

@tdewolff
Copy link
Owner

tdewolff commented May 20, 2020

Improve rasterization performance. How does FreeType perform? Why is the vector one slow?

Make sure the new rasterizer supports both fill types: EvenOdd and NonZero (vector does not support EvenOdd).

EDIT: see the following links for some ideas.

EDIT: actually, Nigel Tao has an implementation of font-rs in Go here: https://github.com/google/font-go. It says in https://github.com/golang/image/blob/master/vector/vector.go that font-go is proof of concept, but doesn't actually import vector...?

@chmike
Copy link

chmike commented Apr 27, 2021

font-rs is using the algorithm described here http://nothings.org/gamedev/rasterize/. It is smart but support only non-zero winding (not even-odd). The vector package of Nigel Tao is using this algorithm with the optimization to use fixed point instead of floats when the image size is smaller than 500 pixel in width and height (if I understood correctly), and assembly with SIMD.

The method is fast for rasterizing but generates only a mask or gray map. Other operations like combining images are O(N²) since each pixel is processed. The method is thus good for rasterizing text which is dense and a small image size, not for general 2D graphics on big images.

The package font-go is a proof of concept of a font rasterizer using the font-rs algorithm. The rasterizer algorithm is implemented in the vector package. The x/image/font package is using the x/image/vector package.

The algorithm to flatten bézier curves in the vector package may be interesting to look at. I think it comes from FreeType. It looks simple and efficient. It may not be optimal in the number of line segments generated, but it is surely optimal to compute the number of steps of t when compared to the method described here.

@tdewolff
Copy link
Owner Author

tdewolff commented Jun 26, 2022

This library currently uses the vector implementation of Nigel Tao, which is as far as I know the fastest rasterizer in pure Go. We should improve performance when using a gamma correcting color space, as it slows down the rasterizer a lot. Additionally, we could look at rasterization at the GPU level, but for that we need tesselation, some shader work for displaying Béziers or arcs (or otherwise we need to flatten those which is what vector does), setup an OpenGL environment, render the image to a texture and retrieve it. This may be faster only for very large images I suppose...

Also see flattening: create the fewest amount of linear segments for quad/cube Béziers and arcs.

@tdewolff
Copy link
Owner Author

Flattening has been implemented which is slightly better than Nigel Tao's version. Otherwise, improving rasterization performance is a high-priority but re-implementing a rasterizer is not.

@tdewolff
Copy link
Owner Author

tdewolff commented Feb 7, 2025

This may have improved dramatically with the fix for #334. In the future we may need to implement our own rasterizer for RGBA and NRGBA (for PNGs) images, with gamma correction and subpixel rasterization for text.

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

No branches or pull requests

2 participants