logging each steps

This commit is contained in:
Ali Gator 2022-05-01 09:07:46 +02:00
parent 09b64a7fad
commit b7053c68aa
4 changed files with 14 additions and 8 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.jpg
*.png

View File

@ -5,6 +5,7 @@ import (
"image" "image"
"image/color" "image/color"
"image/jpeg" "image/jpeg"
"log"
"math" "math"
"os" "os"
"runtime" "runtime"
@ -13,10 +14,10 @@ import (
// job passed to goroutines. blend color from img1 and img2 at position (x, y) // job passed to goroutines. blend color from img1 and img2 at position (x, y)
type blendColorJob struct { type blendColorJob struct {
X int X int
Y int Y int
Img1 image.Image Img1 image.Image
Img2 image.Image Img2 image.Image
} }
// new color after blend, to apply at position (x, y) // new color after blend, to apply at position (x, y)
@ -82,6 +83,8 @@ func (p *blendWorkerPool) SetImageWorker(newImage *image.RGBA) {
} }
func (p *blendWorkerPool) BlendImages(img1 image.Image, img2 image.Image) { func (p *blendWorkerPool) BlendImages(img1 image.Image, img2 image.Image) {
log.Println("Blending the images...")
dimensions := getDimensions(img1, img2) dimensions := getDimensions(img1, img2)
// output image, ready to receive pixel values // output image, ready to receive pixel values
outImg := image.NewRGBA(dimensions) outImg := image.NewRGBA(dimensions)
@ -103,9 +106,9 @@ func encodeImage(imgData *image.RGBA) {
outputFile := fmt.Sprintf("%s/%s", ConfigRegister.OutputDir, "output.jpg") outputFile := fmt.Sprintf("%s/%s", ConfigRegister.OutputDir, "output.jpg")
out, _ := os.Create(outputFile) out, _ := os.Create(outputFile)
defer out.Close() defer out.Close()
fmt.Print("Encoding the image...") log.Println("Encoding the new image...")
jpeg.Encode(out, imgData, nil) jpeg.Encode(out, imgData, nil)
fmt.Println(" Done.") log.Println("Done.")
} }
// convert RGBA pixel to grayscale // convert RGBA pixel to grayscale

3
fs.go
View File

@ -23,13 +23,14 @@ func loadImage(filename string) image.Image {
log.Fatal(err) log.Fatal(err)
} }
log.Println("Loading :", filename)
return imgData return imgData
} }
// Walk through a folder recursively and returns a list of image paths // Walk through a folder recursively and returns a list of image paths
func getImagesList(path string) []string { func getImagesList(path string) []string {
var imgs []string var imgs []string
err := filepath.Walk(path, err := filepath.Walk(path,
func(path string, info os.FileInfo, err error) error { func(path string, info os.FileInfo, err error) error {
ext := strings.ToLower(filepath.Ext(path)) ext := strings.ToLower(filepath.Ext(path))

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"testing" "testing"
) )
func TestMain(t *testing.T) { func TestMain(t *testing.T) {