chore: added logger and closes #33
This commit is contained in:
73
logic/models/test.go
Normal file
73
logic/models/test.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
_ "image/png"
|
||||
"os"
|
||||
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
||||
)
|
||||
|
||||
func testImgForModel(c *Context, model *BaseModel, path string) (result bool) {
|
||||
result = false
|
||||
|
||||
infile, err := os.Open(path)
|
||||
if err != nil {
|
||||
c.Logger.Errorf("Failed to read image for model with id %s\nErr:%s", model.Id, err)
|
||||
return
|
||||
}
|
||||
defer infile.Close()
|
||||
|
||||
src, format, err := image.Decode(infile)
|
||||
if err != nil {
|
||||
c.Logger.Errorf("Failed to decode image for model with id %s\nErr:%s", model.Id, err)
|
||||
return
|
||||
}
|
||||
if format != "png" {
|
||||
c.Logger.Errorf("Found unkown format '%s' while testing an image\n", format)
|
||||
return
|
||||
}
|
||||
|
||||
var model_color string
|
||||
|
||||
bounds := src.Bounds()
|
||||
width, height := bounds.Max.X, bounds.Max.Y
|
||||
|
||||
switch src.ColorModel() {
|
||||
case color.Gray16Model:
|
||||
fallthrough
|
||||
case color.GrayModel:
|
||||
model_color = "greyscale"
|
||||
default:
|
||||
c.Logger.Error("Do not know how to handle this color model")
|
||||
|
||||
if src.ColorModel() == color.RGBA64Model {
|
||||
c.Logger.Info("Color is rgb")
|
||||
} else if src.ColorModel() == color.NRGBAModel {
|
||||
c.Logger.Info("Color is nrgb")
|
||||
} else if src.ColorModel() == color.YCbCrModel {
|
||||
c.Logger.Info("Color is ycbcr")
|
||||
} else if src.ColorModel() == color.AlphaModel {
|
||||
c.Logger.Info("Color is alpha")
|
||||
} else if src.ColorModel() == color.CMYKModel {
|
||||
c.Logger.Info("Color is cmyk")
|
||||
} else {
|
||||
c.Logger.Info("Other so assuming color")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (StringToImageMode(model_color) != model.ImageMode) {
|
||||
c.Logger.Warn("Color Mode does not match with model color mode", model_color, model.ImageMode)
|
||||
return
|
||||
}
|
||||
|
||||
if height != model.Height || width != model.Width {
|
||||
c.Logger.Warn("Image size does not match model size", width, height, model.Width, model.Height)
|
||||
return
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user