From 701d1ab638b23c24877fc41824add66232446676 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Thu, 2 Feb 2017 09:32:00 -0500 Subject: Updating server dependancies (#5249) --- .../github.com/disintegration/imaging/effects.go | 30 ++++++++------- .../disintegration/imaging/effects_test.go | 14 +++---- .../github.com/disintegration/imaging/histogram.go | 43 ++++++++++++++++++++++ .../disintegration/imaging/histogram_test.go | 42 +++++++++++++++++++++ vendor/github.com/disintegration/imaging/resize.go | 38 ++++++++++--------- .../disintegration/imaging/resize_test.go | 18 ++++----- 6 files changed, 137 insertions(+), 48 deletions(-) create mode 100644 vendor/github.com/disintegration/imaging/histogram.go create mode 100644 vendor/github.com/disintegration/imaging/histogram_test.go (limited to 'vendor/github.com/disintegration') diff --git a/vendor/github.com/disintegration/imaging/effects.go b/vendor/github.com/disintegration/imaging/effects.go index fe92e10a2..19d6e405e 100644 --- a/vendor/github.com/disintegration/imaging/effects.go +++ b/vendor/github.com/disintegration/imaging/effects.go @@ -67,15 +67,16 @@ func blurHorizontal(src *image.NRGBA, kernel []float64) *image.NRGBA { for ix := start; ix <= end; ix++ { weight := kernel[absint(x-ix)] i := y*src.Stride + ix*4 - r += float64(src.Pix[i+0]) * weight - g += float64(src.Pix[i+1]) * weight - b += float64(src.Pix[i+2]) * weight - a += float64(src.Pix[i+3]) * weight + wa := float64(src.Pix[i+3]) * weight + r += float64(src.Pix[i+0]) * wa + g += float64(src.Pix[i+1]) * wa + b += float64(src.Pix[i+2]) * wa + a += wa } - r = math.Min(math.Max(r/weightSum, 0.0), 255.0) - g = math.Min(math.Max(g/weightSum, 0.0), 255.0) - b = math.Min(math.Max(b/weightSum, 0.0), 255.0) + r = math.Min(math.Max(r/a, 0.0), 255.0) + g = math.Min(math.Max(g/a, 0.0), 255.0) + b = math.Min(math.Max(b/a, 0.0), 255.0) a = math.Min(math.Max(a/weightSum, 0.0), 255.0) j := y*dst.Stride + x*4 @@ -121,15 +122,16 @@ func blurVertical(src *image.NRGBA, kernel []float64) *image.NRGBA { for iy := start; iy <= end; iy++ { weight := kernel[absint(y-iy)] i := iy*src.Stride + x*4 - r += float64(src.Pix[i+0]) * weight - g += float64(src.Pix[i+1]) * weight - b += float64(src.Pix[i+2]) * weight - a += float64(src.Pix[i+3]) * weight + wa := float64(src.Pix[i+3]) * weight + r += float64(src.Pix[i+0]) * wa + g += float64(src.Pix[i+1]) * wa + b += float64(src.Pix[i+2]) * wa + a += wa } - r = math.Min(math.Max(r/weightSum, 0.0), 255.0) - g = math.Min(math.Max(g/weightSum, 0.0), 255.0) - b = math.Min(math.Max(b/weightSum, 0.0), 255.0) + r = math.Min(math.Max(r/a, 0.0), 255.0) + g = math.Min(math.Max(g/a, 0.0), 255.0) + b = math.Min(math.Max(b/a, 0.0), 255.0) a = math.Min(math.Max(a/weightSum, 0.0), 255.0) j := y*dst.Stride + x*4 diff --git a/vendor/github.com/disintegration/imaging/effects_test.go b/vendor/github.com/disintegration/imaging/effects_test.go index a7e8cfffe..998ffe399 100644 --- a/vendor/github.com/disintegration/imaging/effects_test.go +++ b/vendor/github.com/disintegration/imaging/effects_test.go @@ -50,9 +50,9 @@ func TestBlur(t *testing.T) { Rect: image.Rect(0, 0, 3, 3), Stride: 3 * 4, Pix: []uint8{ - 0x01, 0x02, 0x04, 0x04, 0x0a, 0x10, 0x18, 0x18, 0x01, 0x02, 0x04, 0x04, - 0x09, 0x10, 0x18, 0x18, 0x3f, 0x69, 0x9e, 0x9e, 0x09, 0x10, 0x18, 0x18, - 0x01, 0x02, 0x04, 0x04, 0x0a, 0x10, 0x18, 0x18, 0x01, 0x02, 0x04, 0x04, + 0x66, 0xaa, 0xff, 0x04, 0x66, 0xaa, 0xff, 0x18, 0x66, 0xaa, 0xff, 0x04, + 0x66, 0xaa, 0xff, 0x18, 0x66, 0xaa, 0xff, 0x9e, 0x66, 0xaa, 0xff, 0x18, + 0x66, 0xaa, 0xff, 0x04, 0x66, 0xaa, 0xff, 0x18, 0x66, 0xaa, 0xff, 0x04, }, }, }, @@ -72,9 +72,9 @@ func TestBlur(t *testing.T) { Rect: image.Rect(0, 0, 3, 3), Stride: 3 * 4, Pix: []uint8{ - 0x0b, 0x13, 0x1c, 0x1c, 0x0b, 0x13, 0x1c, 0x1c, 0x0b, 0x13, 0x1c, 0x1c, - 0x0b, 0x13, 0x1c, 0x1c, 0x0b, 0x13, 0x1c, 0x1c, 0x0b, 0x13, 0x1c, 0x1c, - 0x0b, 0x13, 0x1c, 0x1c, 0x0b, 0x13, 0x1c, 0x1c, 0x0b, 0x13, 0x1c, 0x1c, + 0x66, 0xaa, 0xff, 0x1c, 0x66, 0xaa, 0xff, 0x1c, 0x66, 0xaa, 0xff, 0x1c, + 0x66, 0xaa, 0xff, 0x1c, 0x66, 0xaa, 0xff, 0x1c, 0x66, 0xaa, 0xff, 0x1c, + 0x66, 0xaa, 0xff, 0x1c, 0x66, 0xaa, 0xff, 0x1c, 0x66, 0xaa, 0xff, 0x1c, }, }, }, @@ -134,7 +134,7 @@ func TestSharpen(t *testing.T) { Stride: 3 * 4, Pix: []uint8{ 0x66, 0x66, 0x66, 0x66, 0x64, 0x64, 0x64, 0x64, 0x66, 0x66, 0x66, 0x66, - 0x64, 0x64, 0x64, 0x64, 0x7e, 0x7e, 0x7e, 0x7e, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x7d, 0x7d, 0x7d, 0x7e, 0x64, 0x64, 0x64, 0x64, 0x66, 0x66, 0x66, 0x66, 0x64, 0x64, 0x64, 0x64, 0x66, 0x66, 0x66, 0x66, }, }, diff --git a/vendor/github.com/disintegration/imaging/histogram.go b/vendor/github.com/disintegration/imaging/histogram.go new file mode 100644 index 000000000..aef333822 --- /dev/null +++ b/vendor/github.com/disintegration/imaging/histogram.go @@ -0,0 +1,43 @@ +package imaging + +import ( + "image" +) + +// Histogram returns a normalized histogram of an image. +// +// Resulting histogram is represented as an array of 256 floats, where +// histogram[i] is a probability of a pixel being of a particular luminance i. +func Histogram(img image.Image) [256]float64 { + src := toNRGBA(img) + width := src.Bounds().Max.X + height := src.Bounds().Max.Y + + var histogram [256]float64 + var total float64 + + if width == 0 || height == 0 { + return histogram + } + + for y := 0; y < height; y++ { + for x := 0; x < width; x++ { + i := y*src.Stride + x*4 + + r := src.Pix[i+0] + g := src.Pix[i+1] + b := src.Pix[i+2] + + var y float32 = 0.299*float32(r) + 0.587*float32(g) + 0.114*float32(b) + + histogram[int(y+0.5)]++ + total++ + } + } + + for i := 0; i < 256; i++ { + histogram[i] = histogram[i] / total + } + + return histogram +} diff --git a/vendor/github.com/disintegration/imaging/histogram_test.go b/vendor/github.com/disintegration/imaging/histogram_test.go new file mode 100644 index 000000000..0bcf82588 --- /dev/null +++ b/vendor/github.com/disintegration/imaging/histogram_test.go @@ -0,0 +1,42 @@ +package imaging + +import ( + "image" + "image/color" + "testing" +) + +func TestHistogram(t *testing.T) { + b := image.Rectangle{image.Point{0, 0}, image.Point{2, 2}} + + i1 := image.NewRGBA(b) + i1.Set(0, 0, image.Black) + i1.Set(1, 0, image.White) + i1.Set(1, 1, image.White) + i1.Set(0, 1, color.Gray{123}) + + h := Histogram(i1) + if h[0] != 0.25 || h[123] != 0.25 || h[255] != 0.5 { + t.Errorf("Incorrect histogram for image i1") + } + + i2 := image.NewRGBA(b) + i2.Set(0, 0, color.Gray{51}) + i2.Set(0, 1, color.Gray{14}) + i2.Set(1, 0, color.Gray{14}) + + h = Histogram(i2) + if h[14] != 0.5 || h[51] != 0.25 || h[0] != 0.25 { + t.Errorf("Incorrect histogram for image i2") + } + + b = image.Rectangle{image.Point{0, 0}, image.Point{0, 0}} + i3 := image.NewRGBA(b) + h = Histogram(i3) + for _, val := range h { + if val != 0 { + t.Errorf("Histogram for an empty image should be a zero histogram.") + return + } + } +} diff --git a/vendor/github.com/disintegration/imaging/resize.go b/vendor/github.com/disintegration/imaging/resize.go index 3c792e904..b21eed544 100644 --- a/vendor/github.com/disintegration/imaging/resize.go +++ b/vendor/github.com/disintegration/imaging/resize.go @@ -128,20 +128,21 @@ func resizeHorizontal(src *image.NRGBA, width int, filter ResampleFilter) *image parallel(dstH, func(partStart, partEnd int) { for dstY := partStart; dstY < partEnd; dstY++ { for dstX := 0; dstX < dstW; dstX++ { - var c [4]int32 + var c [4]int64 for _, iw := range weights[dstX].iwpairs { i := dstY*src.Stride + iw.i*4 - c[0] += int32(src.Pix[i+0]) * iw.w - c[1] += int32(src.Pix[i+1]) * iw.w - c[2] += int32(src.Pix[i+2]) * iw.w - c[3] += int32(src.Pix[i+3]) * iw.w + a := int64(src.Pix[i+3]) * int64(iw.w) + c[0] += int64(src.Pix[i+0]) * a + c[1] += int64(src.Pix[i+1]) * a + c[2] += int64(src.Pix[i+2]) * a + c[3] += a } j := dstY*dst.Stride + dstX*4 sum := weights[dstX].wsum - dst.Pix[j+0] = clampint32(int32(float32(c[0])/float32(sum) + 0.5)) - dst.Pix[j+1] = clampint32(int32(float32(c[1])/float32(sum) + 0.5)) - dst.Pix[j+2] = clampint32(int32(float32(c[2])/float32(sum) + 0.5)) - dst.Pix[j+3] = clampint32(int32(float32(c[3])/float32(sum) + 0.5)) + dst.Pix[j+0] = clampint32(int32(float64(c[0])/float64(c[3]) + 0.5)) + dst.Pix[j+1] = clampint32(int32(float64(c[1])/float64(c[3]) + 0.5)) + dst.Pix[j+2] = clampint32(int32(float64(c[2])/float64(c[3]) + 0.5)) + dst.Pix[j+3] = clampint32(int32(float64(c[3])/float64(sum) + 0.5)) } } }) @@ -165,20 +166,21 @@ func resizeVertical(src *image.NRGBA, height int, filter ResampleFilter) *image. for dstX := partStart; dstX < partEnd; dstX++ { for dstY := 0; dstY < dstH; dstY++ { - var c [4]int32 + var c [4]int64 for _, iw := range weights[dstY].iwpairs { i := iw.i*src.Stride + dstX*4 - c[0] += int32(src.Pix[i+0]) * iw.w - c[1] += int32(src.Pix[i+1]) * iw.w - c[2] += int32(src.Pix[i+2]) * iw.w - c[3] += int32(src.Pix[i+3]) * iw.w + a := int64(src.Pix[i+3]) * int64(iw.w) + c[0] += int64(src.Pix[i+0]) * a + c[1] += int64(src.Pix[i+1]) * a + c[2] += int64(src.Pix[i+2]) * a + c[3] += a } j := dstY*dst.Stride + dstX*4 sum := weights[dstY].wsum - dst.Pix[j+0] = clampint32(int32(float32(c[0])/float32(sum) + 0.5)) - dst.Pix[j+1] = clampint32(int32(float32(c[1])/float32(sum) + 0.5)) - dst.Pix[j+2] = clampint32(int32(float32(c[2])/float32(sum) + 0.5)) - dst.Pix[j+3] = clampint32(int32(float32(c[3])/float32(sum) + 0.5)) + dst.Pix[j+0] = clampint32(int32(float64(c[0])/float64(c[3]) + 0.5)) + dst.Pix[j+1] = clampint32(int32(float64(c[1])/float64(c[3]) + 0.5)) + dst.Pix[j+2] = clampint32(int32(float64(c[2])/float64(c[3]) + 0.5)) + dst.Pix[j+3] = clampint32(int32(float64(c[3])/float64(sum) + 0.5)) } } diff --git a/vendor/github.com/disintegration/imaging/resize_test.go b/vendor/github.com/disintegration/imaging/resize_test.go index 08d7f2d85..927f92512 100644 --- a/vendor/github.com/disintegration/imaging/resize_test.go +++ b/vendor/github.com/disintegration/imaging/resize_test.go @@ -28,7 +28,7 @@ func TestResize(t *testing.T) { &image.NRGBA{ Rect: image.Rect(0, 0, 1, 1), Stride: 1 * 4, - Pix: []uint8{0x40, 0x40, 0x40, 0xc0}, + Pix: []uint8{0x55, 0x55, 0x55, 0xc0}, }, }, { @@ -108,10 +108,10 @@ func TestResize(t *testing.T) { Rect: image.Rect(0, 0, 4, 4), Stride: 4 * 4, Pix: []uint8{ - 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0xbf, 0x00, 0x00, 0xbf, 0xff, 0x00, 0x00, 0xff, - 0x00, 0x40, 0x00, 0x40, 0x30, 0x30, 0x10, 0x70, 0x8f, 0x10, 0x30, 0xcf, 0xbf, 0x00, 0x40, 0xff, - 0x00, 0xbf, 0x00, 0xbf, 0x10, 0x8f, 0x30, 0xcf, 0x30, 0x30, 0x8f, 0xef, 0x40, 0x00, 0xbf, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xbf, 0x40, 0xff, 0x00, 0x40, 0xbf, 0xff, 0x00, 0x00, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xff, + 0x00, 0xff, 0x00, 0x3f, 0x6d, 0x6e, 0x24, 0x6f, 0xb1, 0x13, 0x3a, 0xd0, 0xc0, 0x00, 0x3f, 0xff, + 0x00, 0xff, 0x00, 0xc0, 0x13, 0xb2, 0x3a, 0xcf, 0x33, 0x32, 0x9a, 0xef, 0x3f, 0x00, 0xc0, 0xff, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x3f, 0xff, 0x00, 0x3f, 0xc0, 0xff, 0x00, 0x00, 0xff, 0xff, }, }, }, @@ -224,7 +224,7 @@ func TestFit(t *testing.T) { &image.NRGBA{ Rect: image.Rect(0, 0, 1, 1), Stride: 1 * 4, - Pix: []uint8{0x40, 0x40, 0x40, 0xc0}, + Pix: []uint8{0x55, 0x55, 0x55, 0xc0}, }, }, { @@ -242,7 +242,7 @@ func TestFit(t *testing.T) { &image.NRGBA{ Rect: image.Rect(0, 0, 1, 1), Stride: 1 * 4, - Pix: []uint8{0x40, 0x40, 0x40, 0xc0}, + Pix: []uint8{0x55, 0x55, 0x55, 0xc0}, }, }, { @@ -512,7 +512,7 @@ func TestThumbnail(t *testing.T) { &image.NRGBA{ Rect: image.Rect(0, 0, 1, 1), Stride: 1 * 4, - Pix: []uint8{0x40, 0x40, 0x40, 0xc0}, + Pix: []uint8{0x55, 0x55, 0x55, 0xc0}, }, }, { @@ -534,7 +534,7 @@ func TestThumbnail(t *testing.T) { &image.NRGBA{ Rect: image.Rect(0, 0, 1, 1), Stride: 1 * 4, - Pix: []uint8{0x40, 0x40, 0x40, 0xc0}, + Pix: []uint8{0x55, 0x55, 0x55, 0xc0}, }, }, { -- cgit v1.2.3-1-g7c22