command line argument and a config register
This commit is contained in:
49
blend.go
49
blend.go
@ -11,13 +11,15 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// job passed to goroutines. blend color from img1 and img2 at position (x, y)
|
||||
type blendColorJob struct {
|
||||
X int
|
||||
Y int
|
||||
Img1 image.Image
|
||||
Img2 image.Image
|
||||
X int
|
||||
Y int
|
||||
Img1 image.Image
|
||||
Img2 image.Image
|
||||
}
|
||||
|
||||
// new color after blend, to apply at position (x, y)
|
||||
type blendColorResult struct {
|
||||
X int
|
||||
Y int
|
||||
@ -98,7 +100,8 @@ func (p *blendWorkerPool) BlendImages(img1 image.Image, img2 image.Image) {
|
||||
|
||||
// encode the image
|
||||
func encodeImage(imgData *image.RGBA) {
|
||||
out, _ := os.Create("output.jpg")
|
||||
outputFile := fmt.Sprintf("%s/%s", ConfigRegister.OutputDir, "output.jpg")
|
||||
out, _ := os.Create(outputFile)
|
||||
defer out.Close()
|
||||
fmt.Print("Encoding the image...")
|
||||
jpeg.Encode(out, imgData, nil)
|
||||
@ -117,19 +120,33 @@ func grayscale(pixel color.Color) color.Color {
|
||||
}
|
||||
}
|
||||
|
||||
// alpha blending RGBA pixels
|
||||
func blend(fc uint8, bc uint8, fa uint8, ba uint8) float64 {
|
||||
// fc : foreground color
|
||||
// bc : background color
|
||||
// fa : foreground alpha
|
||||
// ba : background alpha
|
||||
// all values are alpha-premultiplied
|
||||
|
||||
// darken only
|
||||
func darken(fc uint8, bc uint8, fa uint8) float64 {
|
||||
return math.Min(float64(fc), float64(bc))
|
||||
}
|
||||
|
||||
// fucky fucky fun
|
||||
// return float64((fc * fa) + (bc * (fa * 2)))
|
||||
func lighten(fc uint8, bc uint8, fa uint8) float64 {
|
||||
return math.Max(float64(fc), float64(bc))
|
||||
}
|
||||
|
||||
// produce absolute garbage
|
||||
func fuckyfun(fc uint8, bc uint8, fa uint8) float64 {
|
||||
return float64((fc * fa) + (bc * (fa * 2)))
|
||||
}
|
||||
|
||||
// get the blending method from the config register
|
||||
func blend(fc uint8, bc uint8, fa uint8, ba uint8) float64 {
|
||||
var newValue float64
|
||||
switch ConfigRegister.Method {
|
||||
case "darken":
|
||||
newValue = darken(fc, bc, fa)
|
||||
case "ligten":
|
||||
newValue = lighten(fc, bc, fa)
|
||||
case "fuckyfun":
|
||||
newValue = fuckyfun(fc, bc, fa)
|
||||
default:
|
||||
newValue = darken(fc, bc, fa)
|
||||
}
|
||||
return newValue
|
||||
}
|
||||
|
||||
// blend two RGBA colors/pixels and returns a new one
|
||||
|
||||
Reference in New Issue
Block a user