Moved PNG loading to common.

This commit is contained in:
Sascha L. Teichmann 2014-09-16 01:13:12 +02:00
parent 90bfc225b8
commit a468741a24
2 changed files with 21 additions and 18 deletions

View File

@ -19,6 +19,8 @@ import (
"strings"
"sync"
"bitbucket.org/s_l_teichmann/mtredisalize/common"
"github.com/nfnt/resize"
)
@ -134,23 +136,6 @@ func createParentLevel(oldDir string, jobs chan pyramidJob) (newDir string, err
return
}
func loadImage(path string) image.Image {
var err error
var file *os.File
if file, err = os.Open(path); err != nil {
//log.Printf("WARN: %s", err)
return image.White
}
defer file.Close()
reader := bufio.NewReader(file)
var img image.Image
if img, err = png.Decode(reader); err != nil {
log.Printf("WARN: %s", err)
return image.White
}
return img
}
var dps = [4]image.Point{
image.Pt(0, 256),
image.Pt(0, 0),
@ -161,7 +146,7 @@ func fuseTile(scratch *image.RGBA, job *pyramidJob) (err error) {
for i, path := range job.src {
img := loadImage(path)
img := common.LoadPNG(path)
sr := img.Bounds()
r := sr.Sub(sr.Min).Add(dps[i])

View File

@ -8,6 +8,7 @@ import (
"bufio"
"image"
"image/png"
"log"
"os"
)
@ -22,3 +23,20 @@ func SaveAsPNG(path string, img image.Image) (err error) {
file.Close()
return
}
func LoadPNG(path string) image.Image {
var err error
var file *os.File
if file, err = os.Open(path); err != nil {
//log.Printf("WARN: %s", err)
return image.White
}
defer file.Close()
reader := bufio.NewReader(file)
var img image.Image
if img, err = png.Decode(reader); err != nil {
log.Printf("WARN: %s", err)
return image.White
}
return img
}