From 08b124d5410280a603feb315029cd942c5ca392f Mon Sep 17 00:00:00 2001 From: Charlie Vieth Date: Tue, 12 Aug 2014 16:11:25 -0400 Subject: [PATCH] Fix bound out of range panic. --- converter.go | 14 +++++++------- nearest.go | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/converter.go b/converter.go index bab59ef..df35cea 100644 --- a/converter.go +++ b/converter.go @@ -41,7 +41,7 @@ func clampUint16(in int64) uint16 { } func resizeGeneric(in image.Image, out *image.RGBA64, scale float64, coeffs []int32, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Bounds().Dx(), in.Bounds().Dy()) newBounds := out.Bounds() for x := newBounds.Min.X; x < newBounds.Max.X; x++ { @@ -89,7 +89,7 @@ func resizeGeneric(in image.Image, out *image.RGBA64, scale float64, coeffs []in } func resizeRGBA(in *image.RGBA, out *image.RGBA, scale float64, coeffs []int16, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X * 4 maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) * 4 @@ -131,7 +131,7 @@ func resizeRGBA(in *image.RGBA, out *image.RGBA, scale float64, coeffs []int16, } func resizeRGBA64(in *image.RGBA64, out *image.RGBA64, scale float64, coeffs []int32, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X * 8 maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) * 8 @@ -181,7 +181,7 @@ func resizeRGBA64(in *image.RGBA64, out *image.RGBA64, scale float64, coeffs []i } func resizeGray(in *image.Gray, out *image.Gray, scale float64, coeffs []int16, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) @@ -217,7 +217,7 @@ func resizeGray(in *image.Gray, out *image.Gray, scale float64, coeffs []int16, } func resizeGray16(in *image.Gray16, out *image.Gray16, scale float64, coeffs []int32, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X * 2 maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) * 2 @@ -255,7 +255,7 @@ func resizeGray16(in *image.Gray16, out *image.Gray16, scale float64, coeffs []i } func resizeYCbCr(in *ycc, out *ycc, scale float64, coeffs []int16, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X * 3 maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) * 3 @@ -295,7 +295,7 @@ func resizeYCbCr(in *ycc, out *ycc, scale float64, coeffs []int16, offset []int, } func nearestYCbCr(in *ycc, out *ycc, scale float64, coeffs []bool, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X * 3 maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) * 3 diff --git a/nearest.go b/nearest.go index 6ff22f6..69421f1 100644 --- a/nearest.go +++ b/nearest.go @@ -35,7 +35,7 @@ func floatToUint16(x float32) uint16 { } func nearestGeneric(in image.Image, out *image.RGBA64, scale float64, coeffs []bool, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Bounds().Dx(), in.Bounds().Dy()) newBounds := out.Bounds() for x := newBounds.Min.X; x < newBounds.Max.X; x++ { @@ -82,7 +82,7 @@ func nearestGeneric(in image.Image, out *image.RGBA64, scale float64, coeffs []b } func nearestRGBA(in *image.RGBA, out *image.RGBA, scale float64, coeffs []bool, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X * 4 maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) * 4 @@ -123,7 +123,7 @@ func nearestRGBA(in *image.RGBA, out *image.RGBA, scale float64, coeffs []bool, } func nearestRGBA64(in *image.RGBA64, out *image.RGBA64, scale float64, coeffs []bool, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X * 8 maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) * 8 @@ -172,7 +172,7 @@ func nearestRGBA64(in *image.RGBA64, out *image.RGBA64, scale float64, coeffs [] } func nearestGray(in *image.Gray, out *image.Gray, scale float64, coeffs []bool, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) @@ -207,7 +207,7 @@ func nearestGray(in *image.Gray, out *image.Gray, scale float64, coeffs []bool, } func nearestGray16(in *image.Gray16, out *image.Gray16, scale float64, coeffs []bool, offset []int, filterLength int) { - oldBounds := in.Bounds() + oldBounds := image.Rect(0, 0, in.Rect.Dx(), in.Rect.Dy()) newBounds := out.Bounds() minX := oldBounds.Min.X * 2 maxX := (oldBounds.Max.X - oldBounds.Min.X - 1) * 2