gg icon indicating copy to clipboard operation
gg copied to clipboard

High banding in the gradients generated by gg

Open tariq1890 opened this issue 7 years ago • 6 comments

The banding is really high. Is there any way to reduce this for the generated images?

tariq1890 avatar Aug 24 '17 00:08 tariq1890

@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.

tariq1890 avatar Aug 25 '17 22:08 tariq1890

Can you post code and an image showing the effect? I don't see an issue in the gradient examples.

fogleman avatar Aug 26 '17 00:08 fogleman

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")

out

tariq1890 avatar Aug 26 '17 00:08 tariq1890

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.

fogleman avatar Aug 26 '17 00:08 fogleman

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.

tariq1890 avatar Aug 26 '17 00:08 tariq1890

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

fogleman avatar Aug 26 '17 01:08 fogleman