mirror of
https://github.com/talgo-cloud/talgo-libwebp.git
synced 2026-03-07 21:48:16 -08:00
Move rgb image tests into webp package.
This commit is contained in:
parent
b8bf24acf4
commit
efeb6327b3
2 changed files with 64 additions and 58 deletions
64
webp/rgb_image_test.go
Normal file
64
webp/rgb_image_test.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package webp
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConvertFromRGBA(t *testing.T) {
|
||||
rgba := color.RGBA{0x11, 0x22, 0x33, 0xFF}
|
||||
expect := RGB{0x11, 0x22, 0x33}
|
||||
if got := RGBModel.Convert(rgba); got != expect {
|
||||
t.Errorf("got: %v, expect: %v", got, expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertFromRGB(t *testing.T) {
|
||||
c := RGB{0x11, 0x22, 0x33}
|
||||
if got := RGBModel.Convert(c); got != c {
|
||||
t.Errorf("got: %v, expect: %v", got, c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestColorRGBA(t *testing.T) {
|
||||
c := RGB{0x11, 0x22, 0x33}
|
||||
r, g, b, a := uint32(0x1111), uint32(0x2222), uint32(0x3333), uint32(0xFFFF)
|
||||
|
||||
gotR, gotG, gotB, gotA := c.RGBA()
|
||||
if gotR != r {
|
||||
t.Errorf("got R: %v, expect R: %v", gotR, r)
|
||||
}
|
||||
if gotG != g {
|
||||
t.Errorf("got G: %v, expect G: %v", gotG, g)
|
||||
}
|
||||
if gotB != b {
|
||||
t.Errorf("got B: %v, expect B: %v", gotB, b)
|
||||
}
|
||||
if gotA != a {
|
||||
t.Errorf("got A: %v, expect A: %v", gotA, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageInterface(t *testing.T) {
|
||||
rect := image.Rect(0, 0, 100, 100)
|
||||
img := NewRGBImage(rect)
|
||||
|
||||
if got := img.ColorModel(); got != RGBModel {
|
||||
t.Errorf("ColorModel() should return rgb.ColorModel, got: %v", got)
|
||||
}
|
||||
|
||||
if got := img.Bounds(); got != rect {
|
||||
t.Errorf("Bounds() should return %v, got: %v", rect, got)
|
||||
}
|
||||
|
||||
black := color.RGBA{0x00, 0x00, 0x00, 0xFF}
|
||||
if got := img.At(0, 0); got != black {
|
||||
t.Errorf("At(0, 0) should return %v, got: %v", black, got)
|
||||
}
|
||||
|
||||
blank := color.RGBA{}
|
||||
if got := img.At(-1, -1); got != blank {
|
||||
t.Errorf("At(0, 0) should return %v, got: %v", blank, got)
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/harukasan/go-libwebp/test/util"
|
||||
"github.com/harukasan/go-libwebp/webp"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
|
@ -221,60 +220,3 @@ func TestEncodeYUVA(t *testing.T) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageInterface(t *testing.T) {
|
||||
rect := image.Rect(0, 0, 100, 100)
|
||||
img := webp.NewRGBImage(rect)
|
||||
|
||||
if got := img.ColorModel(); got != webp.RGBModel {
|
||||
t.Errorf("ColorModel() should return rgb.ColorModel, got: %v", got)
|
||||
}
|
||||
|
||||
if got := img.Bounds(); got != rect {
|
||||
t.Errorf("Bounds() should return %v, got: %v", rect, got)
|
||||
}
|
||||
|
||||
black := color.RGBA{0x00, 0x00, 0x00, 0xFF}
|
||||
if got := img.At(0, 0); got != black {
|
||||
t.Errorf("At(0, 0) should return %v, got: %v", black, got)
|
||||
}
|
||||
|
||||
blank := color.RGBA{}
|
||||
if got := img.At(-1, -1); got != blank {
|
||||
t.Errorf("At(0, 0) should return %v, got: %v", blank, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertFromRGBA(t *testing.T) {
|
||||
rgba := color.RGBA{0x11, 0x22, 0x33, 0xFF}
|
||||
expect := webp.RGB{0x11, 0x22, 0x33}
|
||||
if got := webp.RGBModel.Convert(rgba); got != expect {
|
||||
t.Errorf("got: %v, expect: %v", got, expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertFromRGB(t *testing.T) {
|
||||
c := webp.RGB{0x11, 0x22, 0x33}
|
||||
if got := webp.RGBModel.Convert(c); got != c {
|
||||
t.Errorf("got: %v, expect: %v", got, c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestColorRGBA(t *testing.T) {
|
||||
c := webp.RGB{0x11, 0x22, 0x33}
|
||||
r, g, b, a := uint32(0x1111), uint32(0x2222), uint32(0x3333), uint32(0xFFFF)
|
||||
|
||||
gotR, gotG, gotB, gotA := c.RGBA()
|
||||
if gotR != r {
|
||||
t.Errorf("got R: %v, expect R: %v", gotR, r)
|
||||
}
|
||||
if gotG != g {
|
||||
t.Errorf("got G: %v, expect G: %v", gotG, g)
|
||||
}
|
||||
if gotB != b {
|
||||
t.Errorf("got B: %v, expect B: %v", gotB, b)
|
||||
}
|
||||
if gotA != a {
|
||||
t.Errorf("got A: %v, expect A: %v", gotA, a)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue