123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984 |
- package imaging
- import (
- "image"
- "image/color"
- "testing"
- )
- func TestGrayscale(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "Grayscale 3x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x3d, 0x3d, 0x3d, 0x01, 0x78, 0x78, 0x78, 0x02, 0x17, 0x17, 0x17, 0x03,
- 0x1f, 0x1f, 0x1f, 0xff, 0x25, 0x25, 0x25, 0xff, 0x66, 0x66, 0x66, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := Grayscale(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkGrayscale(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- Grayscale(testdataBranchesJPG)
- }
- }
- func TestInvert(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- want *image.NRGBA
- }{
- {
- "Invert 3x3",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x33, 0xff, 0xff, 0x01, 0xff, 0x33, 0xff, 0x02, 0xff, 0xff, 0x33, 0x03,
- 0xee, 0xdd, 0xcc, 0xff, 0xcc, 0xdd, 0xee, 0xff, 0x55, 0xcc, 0x44, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0xff, 0x00, 0x00, 0x00, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := Invert(tc.src)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkInvert(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- Invert(testdataBranchesJPG)
- }
- }
- func TestAdjustSaturation(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- p float64
- want *image.NRGBA
- }{
- {
- "AdjustSaturation 3x3 10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 10,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x0f, 0x22, 0x35, 0xff, 0x35, 0x22, 0x0f, 0xff, 0xaf, 0x2c, 0xc2, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustSaturation 3x3 100",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 100,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x00, 0x22, 0x44, 0xff, 0x44, 0x22, 0x00, 0xff, 0xd0, 0x00, 0xee, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustSaturation 3x3 -10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- -10,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xc2, 0x0a, 0x0a, 0x01, 0x0a, 0xc2, 0x0a, 0x02, 0x0a, 0x0a, 0xc2, 0x03,
- 0x13, 0x22, 0x31, 0xff, 0x31, 0x22, 0x13, 0xff, 0xa5, 0x3a, 0xb4, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustSaturation 3x3 -100",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- -100,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x66, 0x66, 0x66, 0x01, 0x66, 0x66, 0x66, 0x02, 0x66, 0x66, 0x66, 0x03,
- 0x22, 0x22, 0x22, 0xff, 0x22, 0x22, 0x22, 0xff, 0x77, 0x77, 0x77, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustSaturation 3x3 0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := AdjustSaturation(tc.src, tc.p)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func TestAdjustSaturationGolden(t *testing.T) {
- for name, p := range map[string]float64{
- "out_saturation_m30.png": -30,
- "out_saturation_p30.png": 30,
- } {
- got := AdjustSaturation(testdataFlowersSmallPNG, p)
- want, err := Open("testdata/" + name)
- if err != nil {
- t.Fatalf("failed to open image: %v", err)
- }
- if !compareNRGBAGolden(got, toNRGBA(want)) {
- t.Errorf("resulting image differs from golden: %s", name)
- }
- }
- }
- func BenchmarkAdjustSaturation(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- AdjustSaturation(testdataBranchesJPG, 10)
- }
- }
- func TestAdjustHue(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- p float64
- want *image.NRGBA
- }{
- {
- "AdjustHue 3x3 -10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- -10,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x22, 0x01, 0x22, 0xcc, 0x00, 0x02, 0x00, 0x22, 0xcc, 0x03,
- 0x11, 0x28, 0x33, 0xff, 0x33, 0x1c, 0x11, 0xff, 0x93, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustHue 3x3 -180",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- -180,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x00, 0xcc, 0xcc, 0x01, 0xcc, 0x00, 0xcc, 0x02, 0xcc, 0xcc, 0x00, 0x03,
- 0x33, 0x22, 0x11, 0xff, 0x11, 0x22, 0x33, 0xff, 0x44, 0xbb, 0x33, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustHue 3x3 10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 10,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x22, 0x00, 0x01, 0x00, 0xcc, 0x22, 0x02, 0x22, 0x00, 0xcc, 0x03,
- 0x11, 0x1c, 0x33, 0xff, 0x33, 0x28, 0x11, 0xff, 0xbb, 0x33, 0xb5, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustHue 3x3 180",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 180,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x00, 0xcc, 0xcc, 0x01, 0xcc, 0x00, 0xcc, 0x02, 0xcc, 0xcc, 0x00, 0x03,
- 0x33, 0x22, 0x11, 0xff, 0x11, 0x22, 0x33, 0xff, 0x44, 0xbb, 0x33, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustHue 3x3 0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := AdjustHue(tc.src, tc.p)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func TestAdjustHueGolden(t *testing.T) {
- for name, p := range map[string]float64{
- "out_hue_m120.png": -120,
- "out_hue_m60.png": -60,
- "out_hue_p60.png": 60,
- "out_hue_p120.png": 120,
- } {
- got := AdjustHue(testdataFlowersSmallPNG, p)
- want, err := Open("testdata/" + name)
- if err != nil {
- t.Fatalf("failed to open image: %v", err)
- }
- if !compareNRGBAGolden(got, toNRGBA(want)) {
- t.Errorf("resulting image differs from golden: %s", name)
- }
- }
- }
- func BenchmarkAdjustHue(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- AdjustHue(testdataBranchesJPG, 10)
- }
- }
- func TestAdjustContrast(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- p float64
- want *image.NRGBA
- }{
- {
- "AdjustContrast 3x3 10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 10,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xd5, 0x00, 0x00, 0x01, 0x00, 0xd5, 0x00, 0x02, 0x00, 0x00, 0xd5, 0x03,
- 0x05, 0x18, 0x2b, 0xff, 0x2b, 0x18, 0x05, 0xff, 0xaf, 0x2b, 0xc2, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x2b, 0x2b, 0x2b, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustContrast 3x3 100",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 100,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xff, 0x00, 0x00, 0x01, 0x00, 0xff, 0x00, 0x02, 0x00, 0x00, 0xff, 0x03,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustContrast 3x3 -10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- -10,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xc4, 0x0d, 0x0d, 0x01, 0x0d, 0xc4, 0x0d, 0x02, 0x0d, 0x0d, 0xc4, 0x03,
- 0x1c, 0x2b, 0x3b, 0xff, 0x3b, 0x2b, 0x1c, 0xff, 0xa6, 0x3b, 0xb5, 0xff,
- 0x0d, 0x0d, 0x0d, 0xff, 0x3b, 0x3b, 0x3b, 0xff, 0xf2, 0xf2, 0xf2, 0xff,
- },
- },
- },
- {
- "AdjustContrast 3x3 -100",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- -100,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x03,
- 0x80, 0x80, 0x80, 0xff, 0x80, 0x80, 0x80, 0xff, 0x80, 0x80, 0x80, 0xff,
- 0x80, 0x80, 0x80, 0xff, 0x80, 0x80, 0x80, 0xff, 0x80, 0x80, 0x80, 0xff,
- },
- },
- },
- {
- "AdjustContrast 3x3 0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := AdjustContrast(tc.src, tc.p)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func TestAdjustContrastGolden(t *testing.T) {
- for name, p := range map[string]float64{
- "out_contrast_m15.png": -15,
- "out_contrast_p15.png": 15,
- } {
- got := AdjustContrast(testdataFlowersSmallPNG, p)
- want, err := Open("testdata/" + name)
- if err != nil {
- t.Fatalf("failed to open image: %v", err)
- }
- if !compareNRGBAGolden(got, toNRGBA(want)) {
- t.Fatalf("resulting image differs from golden: %s", name)
- }
- }
- }
- func BenchmarkAdjustContrast(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- AdjustContrast(testdataBranchesJPG, 10)
- }
- }
- func TestAdjustBrightness(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- p float64
- want *image.NRGBA
- }{
- {
- "AdjustBrightness 3x3 10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 10,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xe6, 0x1a, 0x1a, 0x01, 0x1a, 0xe6, 0x1a, 0x02, 0x1a, 0x1a, 0xe6, 0x03,
- 0x2b, 0x3c, 0x4d, 0xff, 0x4d, 0x3c, 0x2b, 0xff, 0xc4, 0x4d, 0xd5, 0xff,
- 0x1a, 0x1a, 0x1a, 0xff, 0x4d, 0x4d, 0x4d, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustBrightness 3x3 100",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 100,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x02, 0xff, 0xff, 0xff, 0x03,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustBrightness 3x3 -10",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- -10,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xb3, 0x00, 0x00, 0x01, 0x00, 0xb3, 0x00, 0x02, 0x00, 0x00, 0xb3, 0x03,
- 0x00, 0x09, 0x1a, 0xff, 0x1a, 0x09, 0x00, 0xff, 0x91, 0x1a, 0xa2, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x1a, 0x1a, 0x1a, 0xff, 0xe6, 0xe6, 0xe6, 0xff,
- },
- },
- },
- {
- "AdjustBrightness 3x3 -100",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- -100,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "AdjustBrightness 3x3 0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := AdjustBrightness(tc.src, tc.p)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func TestAdjustBrightnessGolden(t *testing.T) {
- for name, p := range map[string]float64{
- "out_brightness_m10.png": -10,
- "out_brightness_p10.png": 10,
- } {
- got := AdjustBrightness(testdataFlowersSmallPNG, p)
- want, err := Open("testdata/" + name)
- if err != nil {
- t.Fatalf("failed to open image: %v", err)
- }
- if !compareNRGBAGolden(got, toNRGBA(want)) {
- t.Fatalf("resulting image differs from golden: %s", name)
- }
- }
- }
- func BenchmarkAdjustBrightness(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- AdjustBrightness(testdataBranchesJPG, 10)
- }
- }
- func TestAdjustGamma(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- p float64
- want *image.NRGBA
- }{
- {
- "AdjustGamma 3x3 0.75",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0.75,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xbd, 0x00, 0x00, 0x01, 0x00, 0xbd, 0x00, 0x02, 0x00, 0x00, 0xbd, 0x03,
- 0x07, 0x11, 0x1e, 0xff, 0x1e, 0x11, 0x07, 0xff, 0x95, 0x1e, 0xa9, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x1e, 0x1e, 0x1e, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustGamma 3x3 1.5",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 1.5,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xdc, 0x00, 0x00, 0x01, 0x00, 0xdc, 0x00, 0x02, 0x00, 0x00, 0xdc, 0x03,
- 0x2a, 0x43, 0x57, 0xff, 0x57, 0x43, 0x2a, 0xff, 0xc3, 0x57, 0xcf, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x57, 0x57, 0x57, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustGamma 3x3 1.0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 1.0,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := AdjustGamma(tc.src, tc.p)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func TestAdjustGammaGolden(t *testing.T) {
- for name, g := range map[string]float64{
- "out_gamma_0.75.png": 0.75,
- "out_gamma_1.25.png": 1.25,
- } {
- got := AdjustGamma(testdataFlowersSmallPNG, g)
- want, err := Open("testdata/" + name)
- if err != nil {
- t.Fatalf("failed to open image: %v", err)
- }
- if !compareNRGBAGolden(got, toNRGBA(want)) {
- t.Fatalf("resulting image differs from golden: %s", name)
- }
- }
- }
- func BenchmarkAdjustGamma(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- AdjustGamma(testdataBranchesJPG, 1.5)
- }
- }
- func TestAdjustSigmoid(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- m float64
- p float64
- want *image.NRGBA
- }{
- {
- "AdjustSigmoid 3x3 0.5 3.0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0.5,
- 3.0,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xd4, 0x00, 0x00, 0x01, 0x00, 0xd4, 0x00, 0x02, 0x00, 0x00, 0xd4, 0x03,
- 0x0d, 0x1b, 0x2b, 0xff, 0x2b, 0x1b, 0x0d, 0xff, 0xb1, 0x2b, 0xc3, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x2b, 0x2b, 0x2b, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustSigmoid 3x3 0.5 -3.0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0.5,
- -3.0,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xc4, 0x00, 0x00, 0x01, 0x00, 0xc4, 0x00, 0x02, 0x00, 0x00, 0xc4, 0x03,
- 0x16, 0x2a, 0x3b, 0xff, 0x3b, 0x2a, 0x16, 0xff, 0xa4, 0x3b, 0xb3, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x3b, 0x3b, 0x3b, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- {
- "AdjustSigmoid 3x3 0.5 0.0",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- 0.5,
- 0.0,
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := AdjustSigmoid(tc.src, tc.m, tc.p)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkAdjustSigmoid(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- AdjustSigmoid(testdataBranchesJPG, 0.5, 3.0)
- }
- }
- func TestAdjustFunc(t *testing.T) {
- testCases := []struct {
- name string
- src image.Image
- fn func(c color.NRGBA) color.NRGBA
- want *image.NRGBA
- }{
- {
- "invert",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- func(c color.NRGBA) color.NRGBA {
- return color.NRGBA{255 - c.R, 255 - c.G, 255 - c.B, c.A}
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x33, 0xff, 0xff, 0x01, 0xff, 0x33, 0xff, 0x02, 0xff, 0xff, 0x33, 0x03,
- 0xee, 0xdd, 0xcc, 0xff, 0xcc, 0xdd, 0xee, 0xff, 0x55, 0xcc, 0x44, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0xff, 0x00, 0x00, 0x00, 0xff,
- },
- },
- },
- {
- "threshold",
- &image.NRGBA{
- Rect: image.Rect(-1, -1, 2, 2),
- Stride: 3 * 4,
- Pix: []uint8{
- 0xcc, 0x00, 0x00, 0x01, 0x00, 0xcc, 0x00, 0x02, 0x00, 0x00, 0xcc, 0x03,
- 0x11, 0x22, 0x33, 0xff, 0x33, 0x22, 0x11, 0xff, 0xaa, 0x33, 0xbb, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x33, 0x33, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- func(c color.NRGBA) color.NRGBA {
- y := 0.299*float64(c.R) + 0.587*float64(c.G) + 0.114*float64(c.B)
- if y > 0x55 {
- return color.NRGBA{0xff, 0xff, 0xff, c.A}
- }
- return color.NRGBA{0x00, 0x00, 0x00, c.A}
- },
- &image.NRGBA{
- Rect: image.Rect(0, 0, 3, 3),
- Stride: 3 * 4,
- Pix: []uint8{
- 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x03,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
- },
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- got := AdjustFunc(tc.src, tc.fn)
- if !compareNRGBA(got, tc.want, 0) {
- t.Fatalf("got result %#v want %#v", got, tc.want)
- }
- })
- }
- }
- func BenchmarkAdjustFunc(b *testing.B) {
- b.ReportAllocs()
- for i := 0; i < b.N; i++ {
- AdjustFunc(testdataBranchesJPG, func(c color.NRGBA) color.NRGBA {
- return color.NRGBA{c.B, c.G, c.R, c.A}
- })
- }
- }
|