From 90bfc225b8f5dc87e8419d2179236ed0aad2c705 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Tue, 16 Sep 2014 00:08:31 +0200 Subject: [PATCH] When generating shaded tiles draw to pix buffer directly instead of calling Set() for each pixel. Set resize filter for generating pyramid tiles to Lanczos3 because of better visual results. --- cmd/mtseeder/pyramid.go | 2 +- common/renderer.go | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cmd/mtseeder/pyramid.go b/cmd/mtseeder/pyramid.go index 8e62860..23609d0 100644 --- a/cmd/mtseeder/pyramid.go +++ b/cmd/mtseeder/pyramid.go @@ -169,7 +169,7 @@ func fuseTile(scratch *image.RGBA, job *pyramidJob) (err error) { draw.Draw(scratch, r, img, sr.Min, draw.Src) } - resized := resize.Resize(256, 256, scratch, resize.Bicubic) + resized := resize.Resize(256, 256, scratch, resize.Lanczos3) var outFile *os.File if outFile, err = os.Create(job.dst); err != nil { diff --git a/common/renderer.go b/common/renderer.go index 34e9a68..c329bf7 100644 --- a/common/renderer.go +++ b/common/renderer.go @@ -346,11 +346,20 @@ func (r *Renderer) CreateShadedImage( stride := pw - width + istride := image.Stride + 4*width + + iofs := image.PixOffset(0, height-1) + + pix := image.Pix + for z := height - 1; z >= 0; z-- { for x := 0; x < width; x++ { colIdx := r.cBuffer[ofs] if colIdx < 0 || colIdx >= numCols { - image.Set(x, z, background) + pix[iofs] = background.R + pix[iofs+1] = background.G + pix[iofs+2] = background.B + pix[iofs+3] = 0xff } else { var y, y1, y2 int32 y = r.yBuffer[ofs] @@ -369,15 +378,16 @@ func (r *Renderer) CreateShadedImage( d = 36 } col := colors[colIdx] - image.Set(x, z, color.RGBA{ - R: safeColor(int32(col.R) + d), - G: safeColor(int32(col.G) + d), - B: safeColor(int32(col.B) + d), - A: 0xff}) + pix[iofs] = safeColor(int32(col.R) + d) + pix[iofs+1] = safeColor(int32(col.G) + d) + pix[iofs+2] = safeColor(int32(col.B) + d) + pix[iofs+3] = 0xff } + iofs += 4 ofs++ } ofs += stride + iofs -= istride } return image }