Skip to content

Instantly share code, notes, and snippets.

@esdrasbeleza
Last active August 29, 2015 14:20
Show Gist options
  • Save esdrasbeleza/05c6806b7f780b66db16 to your computer and use it in GitHub Desktop.
Save esdrasbeleza/05c6806b7f780b66db16 to your computer and use it in GitHub Desktop.
func (c LightestOperation) Result(images []containers.ImageContainer) (image.Image, error) {
if len(images) == 0 {
return nil, nil
} else if len(images) == 1 {
return images[0].GetImage(), nil
}
firstImage := images[0].GetImage()
bounds := firstImage.Bounds()
lightest := image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
draw.Draw(lightest, bounds, firstImage, bounds.Min, draw.Src)
for _, currentImageContainer := range images[1:] {
currentImage := currentImageContainer.GetImage()
if currentImage.Bounds() != bounds {
return nil, errors.New("The images have different size!")
}
imageToCompare := image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
draw.Draw(imageToCompare, bounds, currentImage, bounds.Min, draw.Src)
c.getLightestImageBetweenTwo(lightest, imageToCompare)
}
return lightest, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment