|
|
|
@ -24,6 +24,13 @@ type filter struct {
|
|
|
|
|
val int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type col struct {
|
|
|
|
|
red filter
|
|
|
|
|
green filter
|
|
|
|
|
blue filter
|
|
|
|
|
alpha filter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type filterState struct {
|
|
|
|
|
red filter
|
|
|
|
|
green filter
|
|
|
|
@ -31,6 +38,7 @@ type filterState struct {
|
|
|
|
|
alpha filter
|
|
|
|
|
location point
|
|
|
|
|
mode filter
|
|
|
|
|
sample col
|
|
|
|
|
}
|
|
|
|
|
var variables = map[string]int{}
|
|
|
|
|
var tree parser.AST
|
|
|
|
@ -82,6 +90,12 @@ func filterImage(path, fname string) {
|
|
|
|
|
filter{255, 0,255},
|
|
|
|
|
point{0,0,imSize.X,imSize.Y},
|
|
|
|
|
filter{3,0,0},
|
|
|
|
|
col{
|
|
|
|
|
filter{255, 0, 255},
|
|
|
|
|
filter{255, 0, 255},
|
|
|
|
|
filter{255, 0, 255},
|
|
|
|
|
filter{255, 0, 255},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Print("Filtering image... ")
|
|
|
|
@ -163,7 +177,7 @@ func procedure(p parser.Procedure) {
|
|
|
|
|
updateRegister(p.Kind, p.Expressions[0])
|
|
|
|
|
}
|
|
|
|
|
case "APY":
|
|
|
|
|
applyToImage(p.Expressions)
|
|
|
|
|
applyToImage(p.Expressions, false)
|
|
|
|
|
case "RED":
|
|
|
|
|
if len(p.Expressions) >= 1 {
|
|
|
|
|
fil.red.update(p.Expressions[0])
|
|
|
|
@ -187,21 +201,38 @@ func procedure(p parser.Procedure) {
|
|
|
|
|
fil.blue.update(p.Expressions[2])
|
|
|
|
|
fil.alpha.update(p.Expressions[3])
|
|
|
|
|
}
|
|
|
|
|
case "GET":
|
|
|
|
|
fil.sample.update()
|
|
|
|
|
case "PUT":
|
|
|
|
|
applyToImage(p.Expressions, true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func applyToImage(exps []parser.Expression) {
|
|
|
|
|
func applyToImage(exps []parser.Expression, useSample bool) {
|
|
|
|
|
var err error
|
|
|
|
|
if len(exps) == 0 {
|
|
|
|
|
im.SetRGBA(
|
|
|
|
|
fil.location.x,
|
|
|
|
|
fil.location.y,
|
|
|
|
|
color.RGBA{
|
|
|
|
|
uint8(fil.red.val),
|
|
|
|
|
uint8(fil.green.val),
|
|
|
|
|
uint8(fil.blue.val),
|
|
|
|
|
uint8(fil.alpha.val),
|
|
|
|
|
})
|
|
|
|
|
if useSample {
|
|
|
|
|
im.SetRGBA(
|
|
|
|
|
fil.location.x,
|
|
|
|
|
fil.location.y,
|
|
|
|
|
color.RGBA{
|
|
|
|
|
uint8(fil.sample.red.val),
|
|
|
|
|
uint8(fil.sample.green.val),
|
|
|
|
|
uint8(fil.sample.blue.val),
|
|
|
|
|
uint8(fil.sample.alpha.val),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
im.SetRGBA(
|
|
|
|
|
fil.location.x,
|
|
|
|
|
fil.location.y,
|
|
|
|
|
color.RGBA{
|
|
|
|
|
uint8(fil.red.val),
|
|
|
|
|
uint8(fil.green.val),
|
|
|
|
|
uint8(fil.blue.val),
|
|
|
|
|
uint8(fil.alpha.val),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} else if len(exps) == 2 {
|
|
|
|
|
endX := exps[0].Opperand
|
|
|
|
|
endY := exps[1].Opperand
|
|
|
|
@ -225,10 +256,17 @@ func applyToImage(exps []parser.Expression) {
|
|
|
|
|
var col color.RGBA
|
|
|
|
|
for y := fil.location.y; y <= endY; y++ {
|
|
|
|
|
for x := fil.location.x; x <= endX; x++ {
|
|
|
|
|
r = fil.red.val
|
|
|
|
|
g = fil.green.val
|
|
|
|
|
b = fil.blue.val
|
|
|
|
|
a = fil.alpha.val
|
|
|
|
|
if useSample {
|
|
|
|
|
r = fil.sample.red.val
|
|
|
|
|
g = fil.sample.green.val
|
|
|
|
|
b = fil.sample.blue.val
|
|
|
|
|
a = fil.sample.alpha.val
|
|
|
|
|
} else {
|
|
|
|
|
r = fil.red.val
|
|
|
|
|
g = fil.green.val
|
|
|
|
|
b = fil.blue.val
|
|
|
|
|
a = fil.alpha.val
|
|
|
|
|
}
|
|
|
|
|
if fil.mode.val != 0 {
|
|
|
|
|
col = im.RGBAAt(x, y)
|
|
|
|
|
// fmt.Printf("Orig: %d, New: %d, Avg: %d\n", col.R, r, avgColor(int(col.R), r))
|
|
|
|
|