From 82ab8b977c4e9246aaa629de809ef15cb562d0ae Mon Sep 17 00:00:00 2001 From: jst Date: Thu, 13 Dec 2012 22:13:37 +0100 Subject: [PATCH] Make kernel the only dependency of convolution1d --- filters.go | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/filters.go b/filters.go index 53ce1b3..33f12d7 100644 --- a/filters.go +++ b/filters.go @@ -35,23 +35,13 @@ func clampToUint16(x float32) (y uint16) { return } -func boolToUint(b bool) (i uint) { - if b { - i = 1 - } else { - i = 0 - } - - return -} - // describe a resampling filter type filterModel struct { // resampling is done by convolution with a (scaled) kernel kernel func(float32) float32 // instead of blurring an image before downscaling to avoid aliasing, - // to filter is scaled by a factor which leads to a similar effect + // the filter is scaled by a factor which leads to a similar effect factor [2]float32 // for optimized access to image points @@ -61,15 +51,13 @@ type filterModel struct { tempRow, tempCol []colorArray } -func (f *filterModel) convolution1d(x float32, p []colorArray, isCol bool) colorArray { +func (f *filterModel) convolution1d(x float32, p []colorArray, factor float32) colorArray { var k float32 var sum float32 = 0 c := colorArray{0.0, 0.0, 0.0, 0.0} - index := boolToUint(isCol) - for j := range p { - k = f.kernel((x - float32(j)) / f.factor[index]) + k = f.kernel((x - float32(j)) / factor) sum += k for i := range c { c[i] += p[j][i] * k @@ -94,10 +82,10 @@ func (f *filterModel) Interpolate(x, y float32) color.RGBA64 { f.tempRow[j] = f.at(xf+j, yf+i) } - f.tempCol[i] = f.convolution1d(x, f.tempRow, false) + f.tempCol[i] = f.convolution1d(x, f.tempRow, f.factor[0]) } - c := f.convolution1d(y, f.tempCol, true) + c := f.convolution1d(y, f.tempCol, f.factor[1]) return color.RGBA64{ clampToUint16(c[0]), clampToUint16(c[1]),