From a468741a2479d8d63e384ef7e97cd4fcb48b72c2 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Tue, 16 Sep 2014 01:13:12 +0200 Subject: [PATCH] Moved PNG loading to common. --- cmd/mtseeder/pyramid.go | 21 +++------------------ common/image.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cmd/mtseeder/pyramid.go b/cmd/mtseeder/pyramid.go index 23609d0..0f48bdf 100644 --- a/cmd/mtseeder/pyramid.go +++ b/cmd/mtseeder/pyramid.go @@ -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]) diff --git a/common/image.go b/common/image.go index 42760b7..533d2a8 100644 --- a/common/image.go +++ b/common/image.go @@ -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 +}