Fix parallel computation.

This commit is contained in:
jst 2014-08-20 21:12:39 +02:00
parent e950449c49
commit 581d15cb53
3 changed files with 22 additions and 22 deletions

View File

@ -48,7 +48,7 @@ func resizeGeneric(in image.Image, out *image.RGBA64, scale float64, coeffs []in
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]int64
var sum int64
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
coeff := coeffs[ci+i]
@ -91,11 +91,11 @@ func resizeRGBA(in *image.RGBA, out *image.RGBA, scale float64, coeffs []int16,
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]int32
var sum int32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
coeff := coeffs[ci+i]
@ -131,11 +131,11 @@ func resizeRGBA64(in *image.RGBA64, out *image.RGBA64, scale float64, coeffs []i
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]int64
var sum int64
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
coeff := coeffs[ci+i]
@ -183,7 +183,7 @@ func resizeGray(in *image.Gray, out *image.Gray, scale float64, coeffs []int16,
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var gray int32
var sum int32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
coeff := coeffs[ci+i]
@ -211,11 +211,11 @@ func resizeGray16(in *image.Gray16, out *image.Gray16, scale float64, coeffs []i
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var gray int64
var sum int64
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
coeff := coeffs[ci+i]
@ -247,11 +247,11 @@ func resizeYCbCr(in *ycc, out *ycc, scale float64, coeffs []int16, offset []int,
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var p [3]int32
var sum int32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
coeff := coeffs[ci+i]
@ -285,11 +285,11 @@ func nearestYCbCr(in *ycc, out *ycc, scale float64, coeffs []bool, offset []int,
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var p [3]float32
var sum float32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
if coeffs[ci+i] {

View File

@ -42,7 +42,7 @@ func nearestGeneric(in image.Image, out *image.RGBA64, scale float64, coeffs []b
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]float32
var sum float32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
if coeffs[ci+i] {
@ -84,11 +84,11 @@ func nearestRGBA(in *image.RGBA, out *image.RGBA, scale float64, coeffs []bool,
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]float32
var sum float32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
if coeffs[ci+i] {
@ -123,11 +123,11 @@ func nearestRGBA64(in *image.RGBA64, out *image.RGBA64, scale float64, coeffs []
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var rgba [4]float32
var sum float32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
if coeffs[ci+i] {
@ -170,11 +170,11 @@ func nearestGray(in *image.Gray, out *image.Gray, scale float64, coeffs []bool,
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var gray float32
var sum float32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
if coeffs[ci+i] {
@ -201,11 +201,11 @@ func nearestGray16(in *image.Gray16, out *image.Gray16, scale float64, coeffs []
maxX := in.Bounds().Dx() - 1
for x := newBounds.Min.X; x < newBounds.Max.X; x++ {
row := in.Pix[(x-newBounds.Min.X)*in.Stride:]
row := in.Pix[x*in.Stride:]
for y := newBounds.Min.Y; y < newBounds.Max.Y; y++ {
var gray float32
var sum float32
start := offset[y-newBounds.Min.Y]
start := offset[y]
ci := (y - newBounds.Min.Y) * filterLength
for i := 0; i < filterLength; i++ {
if coeffs[ci+i] {

View File

@ -91,7 +91,7 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
}
taps, kernel := interp.kernel()
cpus := 1 //runtime.NumCPU() TODO
cpus := runtime.NumCPU()
wg := sync.WaitGroup{}
// Generic access to image.Image is slow in tight loops.