github.com/df-mc/dragonfly@v0.9.13/server/internal/nbtconv/colour.go (about)

     1  package nbtconv
     2  
     3  import (
     4  	"encoding/binary"
     5  	"image/color"
     6  )
     7  
     8  // Int32FromRGBA converts a color.RGBA into an int32. These int32s are present in, for example, signs.
     9  func Int32FromRGBA(x color.RGBA) int32 {
    10  	if x.R == 0 && x.G == 0 && x.B == 0 {
    11  		// Default to black colour. The default (0x000000) is a transparent colour. Text with this colour will not show
    12  		// up on the sign.
    13  		return int32(-0x1000000)
    14  	}
    15  	return int32(binary.BigEndian.Uint32([]byte{x.A, x.R, x.G, x.B}))
    16  }
    17  
    18  // RGBAFromInt32 converts an int32 into a color.RGBA. These int32s are present in, for example, signs.
    19  func RGBAFromInt32(x int32) color.RGBA {
    20  	b := make([]byte, 4)
    21  	binary.BigEndian.PutUint32(b, uint32(x))
    22  
    23  	return color.RGBA{A: b[0], R: b[1], G: b[2], B: b[3]}
    24  }