variable number of images to blend (shitcode)
This commit is contained in:
37
blend.go
37
blend.go
@ -82,20 +82,50 @@ func (p *blendWorkerPool) SetImageWorker(newImage *image.RGBA) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *blendWorkerPool) BlendImages(img1 image.Image, img2 image.Image) {
|
||||
func (p *blendWorkerPool) BlendImagesMain() {
|
||||
log.Println("Blending the images...")
|
||||
|
||||
// dimensions := getMaxDimensions(img1, img2)
|
||||
p.InitWorkerPool()
|
||||
|
||||
// output image, ready to receive pixel values
|
||||
dimensions := dimensionsToRectangle(ConfigRegister.OutputWidth, ConfigRegister.OutputHeight)
|
||||
outImg := image.NewRGBA(dimensions)
|
||||
|
||||
for i := 1; i < ConfigRegister.Amount; i++ {
|
||||
// get two random images and load them
|
||||
var img1 image.Image
|
||||
if ConfigRegister.BaseImage != "" && i == 1 {
|
||||
img1 = loadImage(ConfigRegister.BaseImage)
|
||||
} else {
|
||||
if i != 1 {
|
||||
img1 = loadImage("output.jpg")
|
||||
} else {
|
||||
img1 = loadImage(getRandomImage())
|
||||
}
|
||||
}
|
||||
|
||||
img2 := loadImage(getRandomImage())
|
||||
|
||||
// pool of workers unionizing, ready to blend a new picture using the power of friendship
|
||||
var pool blendWorkerPool
|
||||
pool.InitWorkerPool()
|
||||
|
||||
// main blending routine
|
||||
pool.BlendImages(img1, img2, outImg)
|
||||
|
||||
encodeImage(outImg)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *blendWorkerPool) BlendImages(img1 image.Image, img2 image.Image, out *image.RGBA) {
|
||||
dimensions := dimensionsToRectangle(ConfigRegister.OutputWidth, ConfigRegister.OutputHeight)
|
||||
|
||||
// TODO: use a worker pool for those operations ?
|
||||
// resize image
|
||||
img1Resized := resize(img1)
|
||||
img2Resized := resize(img2)
|
||||
|
||||
p.RunWorkers(outImg)
|
||||
p.RunWorkers(out)
|
||||
|
||||
p.SendBlendJobs(dimensions, img1Resized, img2Resized)
|
||||
|
||||
@ -105,7 +135,6 @@ func (p *blendWorkerPool) BlendImages(img1 image.Image, img2 image.Image) {
|
||||
|
||||
// second waitgroup to ensure the encoding doesn't start before the goroutines are done
|
||||
p.ConsumerWG.Wait()
|
||||
encodeImage(outImg)
|
||||
}
|
||||
|
||||
// encode the image
|
||||
|
||||
Reference in New Issue
Block a user