-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stuff Revert "Refactor out pixel.RGBA" This reverts commit d029ce8. Reworked to keep pixel.RGBA around, but an alias working on color more color work
- Loading branch information
Allen Ray
committed
Aug 15, 2024
1 parent
aacf9ae
commit 888247d
Showing
12 changed files
with
206 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package opengl | ||
|
||
import ( | ||
"image/color" | ||
|
||
"github.com/go-gl/mathgl/mgl32" | ||
) | ||
|
||
type GLColor mgl32.Vec4 | ||
|
||
func (c GLColor) RGBA() (r, g, b, a uint32) { | ||
return uint32(c[0] * 0xffff), uint32(c[1] * 0xffff), uint32(c[2] * 0xffff), uint32(c[3] * 0xffff) | ||
} | ||
|
||
func ToGLColor(col color.Color) GLColor { | ||
if c, ok := col.(GLColor); ok { | ||
return c | ||
} | ||
r, g, b, a := col.RGBA() | ||
return GLColor{ | ||
float32(r) / 0xffff, | ||
float32(g) / 0xffff, | ||
float32(b) / 0xffff, | ||
float32(a) / 0xffff, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package pixel | ||
|
||
import ( | ||
"image/color" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestColorConversions(t *testing.T) { | ||
c0 := RGBA{64, 127, 128, 255} | ||
c1 := FloatsToColor(ColorToFloats[float32](c0)) | ||
require.Equal(t, c0, c1) | ||
} | ||
|
||
func TestToRGBA(t *testing.T) { | ||
type args struct { | ||
c color.Color | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want RGBA | ||
}{ | ||
{ | ||
name: "pixel.rgba", | ||
args: args{c: RGBA{64, 127, 128, 255}}, | ||
want: RGBA{64, 127, 128, 255}, | ||
}, | ||
{ | ||
name: "color.rgba", | ||
args: args{c: color.RGBA{64, 127, 128, 255}}, | ||
want: RGBA{64, 127, 128, 255}, | ||
}, | ||
{ | ||
name: "color.nrgba", | ||
args: args{c: color.NRGBA{64, 127, 128, 255}}, | ||
want: RGBA{64, 127, 128, 255}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ToRGBA(tt.args.c); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ToRGBA() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestRGB(t *testing.T) { | ||
rgba := RGB(0.25, 0.5, 0.75) | ||
require.Equal(t, RGBA{63, 127, 191, 255}, rgba) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.