unipdf/internal/imageutil/grayscale_test.go
Jacek Kucharczyk f0646b6f1f Minor image profiling tweaks.
Fixed minor and major issues with the naming and comments.
Added licenses information to files.
2020-07-15 11:37:13 +02:00

96 lines
2.0 KiB
Go

/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
package imageutil
import (
"image/color"
"math"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMonochrome(t *testing.T) {
g, err := NewImage(10, 10, 1, 1, nil, nil, nil)
require.NoError(t, err)
c := g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(0))
g.Set(6, 6, color.White)
c = g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(math.MaxUint8))
g.Set(6, 6, color.Black)
c = g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(0))
}
func TestGray2(t *testing.T) {
g, err := NewImage(10, 10, 2, 1, nil, nil, nil)
require.NoError(t, err)
c := g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(0))
g.Set(6, 6, color.White)
c = g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(math.MaxUint8))
g.Set(6, 6, color.Black)
c = g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(0))
}
func TestGray4(t *testing.T) {
g, err := NewImage(10, 10, 4, 1, nil, nil, nil)
require.NoError(t, err)
c := g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(0))
g.Set(6, 6, color.White)
c = g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(math.MaxUint8))
g.Set(6, 6, color.Black)
c = g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(0))
}
func TestGray8(t *testing.T) {
g, err := NewImage(10, 10, 8, 1, nil, nil, nil)
require.NoError(t, err)
c := g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(0))
g.Set(6, 6, color.White)
c = g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(math.MaxUint8))
g.Set(6, 6, color.Black)
c = g.At(6, 6).(color.Gray)
assert.Equal(t, c.Y, uint8(0))
}
func TestGray16(t *testing.T) {
g, err := NewImage(10, 10, 16, 1, nil, nil, nil)
require.NoError(t, err)
c := g.At(6, 6).(color.Gray16)
assert.Equal(t, c.Y, uint16(0))
g.Set(6, 6, color.White)
c = g.At(6, 6).(color.Gray16)
assert.Equal(t, c.Y, uint16(math.MaxUint16))
g.Set(6, 6, color.Black)
c = g.At(6, 6).(color.Gray16)
assert.Equal(t, c.Y, uint16(0))
}