Description added

Describe filterModel interface,
Extract bool-to-int method
This commit is contained in:
jst 2012-12-11 20:18:23 +01:00
parent 2d6edc049a
commit bf006ca38d

View File

@ -22,8 +22,7 @@ import (
"math" "math"
) )
// restrict an input float32 to the // restrict an input float32 to the range of uint16 values
// range of uint16 values
func clampToUint16(x float32) (y uint16) { func clampToUint16(x float32) (y uint16) {
y = uint16(x) y = uint16(x)
if x < 0 { if x < 0 {
@ -35,10 +34,29 @@ func clampToUint16(x float32) (y uint16) {
return return
} }
func boolToUint(b bool) (i uint) {
if b {
i = 0
} else {
i = 1
}
return
}
// describe a resampling filter
type filterModel struct { type filterModel struct {
// for optimized access to image points
converter converter
// instead of blurring an image before downscaling to avoid aliasing,
// to filter is scaled by a factor which leads to a similar effect
factor [2]float32 factor [2]float32
// resampling is done by convolution with a (scaled) kernel
kernel func(float32) float32 kernel func(float32) float32
// temporaries used by Interpolate
tempRow, tempCol []colorArray tempRow, tempCol []colorArray
} }
@ -47,12 +65,7 @@ func (f *filterModel) convolution1d(x float32, p []colorArray, isRow bool) color
var sum float32 = 0 var sum float32 = 0
c := colorArray{0.0, 0.0, 0.0, 0.0} c := colorArray{0.0, 0.0, 0.0, 0.0}
var index uint index := boolToUint(isRow)
if isRow {
index = 0
} else {
index = 1
}
for j := range p { for j := range p {
k = f.kernel((x - float32(j)) / f.factor[index]) k = f.kernel((x - float32(j)) / f.factor[index])