gg
gg copied to clipboard
High banding in the gradients generated by gg
The banding is really high. Is there any way to reduce this for the generated images?
@fogleman Could you help us with this? Is there anything we must do to ensure less banding in the gradients generated.
This is a great library for generating gradients since its very simple and intuitive. It's unfortunate that we get such high banding.
Can you post code and an image showing the effect? I don't see an issue in the gradient examples.
grad := gg.NewLinearGradient(0, 0, 1920, 0)
grad.AddColorStop(0, color.RGBA{0, 0, 0, 200})
grad.AddColorStop(1, color.RGBA{0, 0, 0, 128})
dc.SetFillStyle(grad)
dc.MoveTo(0, 0)
dc.LineTo(1920, 0)
dc.LineTo(1920, 1080)
dc.LineTo(0, 1080)
dc.ClosePath()
dc.Fill()
gradientOverlay := dc.Image()
imaging.Save(gradientOverlay, "out.png")
Well the only way to improve that would be to go to a 16-bit image.
Currently gg
only does 8-bit. It wouldn't be too hard to do 16-bit but might be API-breaking.
Oh alright! Is it possible to create a v2 package? I am also happy to help through PRs if you can give me an overview of the places that require changing.
It would start by changing RGBA -> NRGBA64 and Alpha -> Alpha16 throughout the code.
But it might not actually be so easy. The freetype/raster package which gg is built upon only seems to support RGBA and Alpha.
https://github.com/golang/freetype/blob/master/raster/paint.go