1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-29 22:56:07 -04:00

Merge pull request #1091 from gucio321/data-encoder-dat

d2pl2: added RGBA and SetRGBA methods
This commit is contained in:
gravestench 2021-03-11 22:24:29 -08:00 committed by GitHub
commit 536233ffee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View File

@ -1,5 +1,14 @@
package d2pl2
const (
bitShift0 = 8 * iota
bitShift8
bitShift16
bitShift24
mask = 0xff
)
// PL2Color represents an RGBA color
type PL2Color struct {
R uint8
@ -7,3 +16,30 @@ type PL2Color struct {
B uint8
_ uint8
}
// RGBA returns RGBA values of PL2Color
func (p *PL2Color) RGBA() uint32 {
return toComposite(p.R, p.G, p.B, mask)
}
// SetRGBA sets PL2Color's value to rgba given
func (p *PL2Color) SetRGBA(rgba uint32) {
p.R, p.G, p.B = toComponent(rgba)
}
func toComposite(w, x, y, z uint8) uint32 {
composite := uint32(w) << bitShift24
composite += uint32(x) << bitShift16
composite += uint32(y) << bitShift8
composite += uint32(z) << bitShift0
return composite
}
func toComponent(wxyz uint32) (w, x, y uint8) {
w = uint8(wxyz >> bitShift24 & mask)
x = uint8(wxyz >> bitShift16 & mask)
y = uint8(wxyz >> bitShift8 & mask)
return w, x, y
}

View File

@ -6,3 +6,13 @@ type PL2Color24Bits struct {
G uint8
B uint8
}
// RGBA returns RGBA values of PL2Color
func (p *PL2Color24Bits) RGBA() uint32 {
return toComposite(p.R, p.G, p.B, mask)
}
// SetRGBA sets PL2Color's value to rgba given
func (p *PL2Color24Bits) SetRGBA(rgba uint32) {
p.R, p.G, p.B = toComponent(rgba)
}