|
|
@@ -105,14 +105,14 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
|
|
|
switch input := img.(type) {
|
|
|
case *image.RGBA:
|
|
|
// 8-bit precision
|
|
|
- temp := image.NewRGBA(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
|
|
|
- result := image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
|
|
|
+ temp := image.NewNRGBA(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
|
|
|
+ result := image.NewNRGBA(image.Rect(0, 0, int(width), int(height)))
|
|
|
|
|
|
// horizontal filter, results in transposed temporary image
|
|
|
coeffs, offset, filterLength := createWeights8(temp.Bounds().Dy(), taps, blur, scaleX, kernel)
|
|
|
wg.Add(cpus)
|
|
|
for i := 0; i < cpus; i++ {
|
|
|
- slice := makeSlice(temp, i, cpus).(*image.RGBA)
|
|
|
+ slice := makeSlice(temp, i, cpus).(*image.NRGBA)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
resizeRGBA(input, slice, scaleX, coeffs, offset, filterLength)
|
|
|
@@ -124,14 +124,44 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
|
|
|
coeffs, offset, filterLength = createWeights8(result.Bounds().Dy(), taps, blur, scaleY, kernel)
|
|
|
wg.Add(cpus)
|
|
|
for i := 0; i < cpus; i++ {
|
|
|
- slice := makeSlice(result, i, cpus).(*image.RGBA)
|
|
|
+ slice := makeSlice(result, i, cpus).(*image.NRGBA)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ resizeNRGBA(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ return result
|
|
|
+ case *image.NRGBA:
|
|
|
+ // 8-bit precision
|
|
|
+ temp := image.NewNRGBA(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
|
|
|
+ result := image.NewNRGBA(image.Rect(0, 0, int(width), int(height)))
|
|
|
+
|
|
|
+ // horizontal filter, results in transposed temporary image
|
|
|
+ coeffs, offset, filterLength := createWeights8(temp.Bounds().Dy(), taps, blur, scaleX, kernel)
|
|
|
+ wg.Add(cpus)
|
|
|
+ for i := 0; i < cpus; i++ {
|
|
|
+ slice := makeSlice(temp, i, cpus).(*image.NRGBA)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ resizeNRGBA(input, slice, scaleX, coeffs, offset, filterLength)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+
|
|
|
+ // horizontal filter on transposed image, result is not transposed
|
|
|
+ coeffs, offset, filterLength = createWeights8(result.Bounds().Dy(), taps, blur, scaleY, kernel)
|
|
|
+ wg.Add(cpus)
|
|
|
+ for i := 0; i < cpus; i++ {
|
|
|
+ slice := makeSlice(result, i, cpus).(*image.NRGBA)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
- resizeRGBA(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
+ resizeNRGBA(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
}()
|
|
|
}
|
|
|
wg.Wait()
|
|
|
return result
|
|
|
+
|
|
|
case *image.YCbCr:
|
|
|
// 8-bit precision
|
|
|
// accessing the YCbCr arrays in a tight loop is slow.
|
|
|
@@ -164,14 +194,14 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
|
|
|
return result.YCbCr()
|
|
|
case *image.RGBA64:
|
|
|
// 16-bit precision
|
|
|
- temp := image.NewRGBA64(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
|
|
|
- result := image.NewRGBA64(image.Rect(0, 0, int(width), int(height)))
|
|
|
+ temp := image.NewNRGBA64(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
|
|
|
+ result := image.NewNRGBA64(image.Rect(0, 0, int(width), int(height)))
|
|
|
|
|
|
// horizontal filter, results in transposed temporary image
|
|
|
coeffs, offset, filterLength := createWeights16(temp.Bounds().Dy(), taps, blur, scaleX, kernel)
|
|
|
wg.Add(cpus)
|
|
|
for i := 0; i < cpus; i++ {
|
|
|
- slice := makeSlice(temp, i, cpus).(*image.RGBA64)
|
|
|
+ slice := makeSlice(temp, i, cpus).(*image.NRGBA64)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
resizeRGBA64(input, slice, scaleX, coeffs, offset, filterLength)
|
|
|
@@ -183,10 +213,39 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
|
|
|
coeffs, offset, filterLength = createWeights16(result.Bounds().Dy(), taps, blur, scaleY, kernel)
|
|
|
wg.Add(cpus)
|
|
|
for i := 0; i < cpus; i++ {
|
|
|
- slice := makeSlice(result, i, cpus).(*image.RGBA64)
|
|
|
+ slice := makeSlice(result, i, cpus).(*image.NRGBA64)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ resizeNRGBA64(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ return result
|
|
|
+ case *image.NRGBA64:
|
|
|
+ // 16-bit precision
|
|
|
+ temp := image.NewNRGBA64(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
|
|
|
+ result := image.NewNRGBA64(image.Rect(0, 0, int(width), int(height)))
|
|
|
+
|
|
|
+ // horizontal filter, results in transposed temporary image
|
|
|
+ coeffs, offset, filterLength := createWeights16(temp.Bounds().Dy(), taps, blur, scaleX, kernel)
|
|
|
+ wg.Add(cpus)
|
|
|
+ for i := 0; i < cpus; i++ {
|
|
|
+ slice := makeSlice(temp, i, cpus).(*image.NRGBA64)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ resizeNRGBA64(input, slice, scaleX, coeffs, offset, filterLength)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+
|
|
|
+ // horizontal filter on transposed image, result is not transposed
|
|
|
+ coeffs, offset, filterLength = createWeights16(result.Bounds().Dy(), taps, blur, scaleY, kernel)
|
|
|
+ wg.Add(cpus)
|
|
|
+ for i := 0; i < cpus; i++ {
|
|
|
+ slice := makeSlice(result, i, cpus).(*image.NRGBA64)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
- resizeGeneric(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
+ resizeNRGBA64(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
}()
|
|
|
}
|
|
|
wg.Wait()
|
|
|
@@ -251,14 +310,14 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
|
|
|
return result
|
|
|
default:
|
|
|
// 16-bit precision
|
|
|
- temp := image.NewRGBA64(image.Rect(0, 0, img.Bounds().Dy(), int(width)))
|
|
|
- result := image.NewRGBA64(image.Rect(0, 0, int(width), int(height)))
|
|
|
+ temp := image.NewNRGBA64(image.Rect(0, 0, img.Bounds().Dy(), int(width)))
|
|
|
+ result := image.NewNRGBA64(image.Rect(0, 0, int(width), int(height)))
|
|
|
|
|
|
// horizontal filter, results in transposed temporary image
|
|
|
coeffs, offset, filterLength := createWeights16(temp.Bounds().Dy(), taps, blur, scaleX, kernel)
|
|
|
wg.Add(cpus)
|
|
|
for i := 0; i < cpus; i++ {
|
|
|
- slice := makeSlice(temp, i, cpus).(*image.RGBA64)
|
|
|
+ slice := makeSlice(temp, i, cpus).(*image.NRGBA64)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
resizeGeneric(img, slice, scaleX, coeffs, offset, filterLength)
|
|
|
@@ -270,10 +329,10 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
|
|
|
coeffs, offset, filterLength = createWeights16(result.Bounds().Dy(), taps, blur, scaleY, kernel)
|
|
|
wg.Add(cpus)
|
|
|
for i := 0; i < cpus; i++ {
|
|
|
- slice := makeSlice(result, i, cpus).(*image.RGBA64)
|
|
|
+ slice := makeSlice(result, i, cpus).(*image.NRGBA64)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
- resizeRGBA64(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
+ resizeNRGBA64(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
}()
|
|
|
}
|
|
|
wg.Wait()
|
|
|
@@ -316,6 +375,35 @@ func resizeNearest(width, height uint, scaleX, scaleY float64, img image.Image,
|
|
|
}
|
|
|
wg.Wait()
|
|
|
return result
|
|
|
+ case *image.NRGBA:
|
|
|
+ // 8-bit precision
|
|
|
+ temp := image.NewNRGBA(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
|
|
|
+ result := image.NewNRGBA(image.Rect(0, 0, int(width), int(height)))
|
|
|
+
|
|
|
+ // horizontal filter, results in transposed temporary image
|
|
|
+ coeffs, offset, filterLength := createWeightsNearest(temp.Bounds().Dy(), taps, blur, scaleX)
|
|
|
+ wg.Add(cpus)
|
|
|
+ for i := 0; i < cpus; i++ {
|
|
|
+ slice := makeSlice(temp, i, cpus).(*image.NRGBA)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ nearestNRGBA(input, slice, scaleX, coeffs, offset, filterLength)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+
|
|
|
+ // horizontal filter on transposed image, result is not transposed
|
|
|
+ coeffs, offset, filterLength = createWeightsNearest(result.Bounds().Dy(), taps, blur, scaleY)
|
|
|
+ wg.Add(cpus)
|
|
|
+ for i := 0; i < cpus; i++ {
|
|
|
+ slice := makeSlice(result, i, cpus).(*image.NRGBA)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ nearestNRGBA(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ return result
|
|
|
case *image.YCbCr:
|
|
|
// 8-bit precision
|
|
|
// accessing the YCbCr arrays in a tight loop is slow.
|
|
|
@@ -370,7 +458,36 @@ func resizeNearest(width, height uint, scaleX, scaleY float64, img image.Image,
|
|
|
slice := makeSlice(result, i, cpus).(*image.RGBA64)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
- nearestGeneric(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
+ nearestRGBA64(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ return result
|
|
|
+ case *image.NRGBA64:
|
|
|
+ // 16-bit precision
|
|
|
+ temp := image.NewNRGBA64(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
|
|
|
+ result := image.NewNRGBA64(image.Rect(0, 0, int(width), int(height)))
|
|
|
+
|
|
|
+ // horizontal filter, results in transposed temporary image
|
|
|
+ coeffs, offset, filterLength := createWeightsNearest(temp.Bounds().Dy(), taps, blur, scaleX)
|
|
|
+ wg.Add(cpus)
|
|
|
+ for i := 0; i < cpus; i++ {
|
|
|
+ slice := makeSlice(temp, i, cpus).(*image.NRGBA64)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ nearestNRGBA64(input, slice, scaleX, coeffs, offset, filterLength)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+
|
|
|
+ // horizontal filter on transposed image, result is not transposed
|
|
|
+ coeffs, offset, filterLength = createWeightsNearest(result.Bounds().Dy(), taps, blur, scaleY)
|
|
|
+ wg.Add(cpus)
|
|
|
+ for i := 0; i < cpus; i++ {
|
|
|
+ slice := makeSlice(result, i, cpus).(*image.NRGBA64)
|
|
|
+ go func() {
|
|
|
+ defer wg.Done()
|
|
|
+ nearestNRGBA64(temp, slice, scaleY, coeffs, offset, filterLength)
|
|
|
}()
|
|
|
}
|
|
|
wg.Wait()
|