Used fix point arithmetic in scaler.

This commit is contained in:
Sascha L. Teichmann 2014-09-16 15:49:14 +02:00
parent c67739fd77
commit 48819a42a9

View File

@ -24,25 +24,23 @@ import (
func blowUp(src image.Image) *image.RGBA { func blowUp(src image.Image) *image.RGBA {
// TODO: Use fix point arithmetic, fast path for image.RGBA // TODO: Fast path for image.RGBA
dst := image.NewRGBA(image.Rect(0, 0, 256, 256)) dst := image.NewRGBA(image.Rect(0, 0, 256, 256))
sw, sh := src.Bounds().Dx(), src.Bounds().Dy() // fix point numbers x:8
dx, dy := src.Bounds().Dx(), src.Bounds().Dy()
dx := float32(sw) / float32(256) bx, by := src.Bounds().Min.X<<8, src.Bounds().Min.Y<<8
dy := float32(sh) / float32(256)
bx, by := src.Bounds().Min.X, src.Bounds().Min.Y py := by
py := float32(by)
for y := 0; y < 256; y++ { for y := 0; y < 256; y++ {
sy := int(py) sy := (py >> 8) & 0xff
ox := -1 ox := -1
px := float32(bx) px := bx
var col color.Color var col color.Color
for x := 0; x < 256; x++ { for x := 0; x < 256; x++ {
sx := int(px) sx := (px >> 8) & 0xff
if sx != ox { // Minimize interface indirection access. if sx != ox { // Minimize interface indirection access.
ox = sx ox = sx
col = src.At(sx, sy) col = src.At(sx, sy)