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

RGBA() does not return the right values #29

Closed
billy4479 opened this issue Dec 28, 2024 · 0 comments · Fixed by #30
Closed

RGBA() does not return the right values #29

billy4479 opened this issue Dec 28, 2024 · 0 comments · Fixed by #30

Comments

@billy4479
Copy link
Contributor

billy4479 commented Dec 28, 2024

Right now the color.RBGA() function is implemented as

// RGBA implements color.Color
func (c Color) RGBA() (r uint32, g uint32, b uint32, a uint32) {
	return c.RGB[0], c.RGB[1], c.RGB[2], 1
}

therefore the values returned are in the interval [0,0xff].

This behavior is different from the one of image.color.RGBA.RGBA() which (as of go 1.23) implements it as

func (c RGBA) RGBA() (r, g, b, a uint32) {
	r = uint32(c.R)
	r |= r << 8
	g = uint32(c.G)
	g |= g << 8
	b = uint32(c.B)
	b |= b << 8
	a = uint32(c.A)
	a |= a << 8
	return
}

Indeed the image.color.Color interface is defined as

type Color interface {
	// RGBA returns the alpha-premultiplied red, green, blue and alpha values
	// for the color. Each value ranges within [0, 0xffff], but is represented
	// by a uint32 so that multiplying by a blend factor up to 0xffff will not
	// overflow.
	//
	// An alpha-premultiplied color component c has been scaled by alpha (a),
	// so has valid values 0 <= c <= a.
	RGBA() (r, g, b, a uint32)
}

therefore it expects that RGBA() returns a value in [0, 0xffff].

Even though we should implement the interface correctly, I still think it would be useful to be able to access the uint8 values, maybe with a RGBA8() function?

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 a pull request may close this issue.

1 participant