Fixed average mode
This commit is contained in:
parent
42bf437f07
commit
7d70006d2d
39
main.go
39
main.go
|
@ -73,11 +73,14 @@ func filterImage(path, fname string) {
|
||||||
variables["WID"] = imSize.X
|
variables["WID"] = imSize.X
|
||||||
variables["HIG"] = imSize.Y
|
variables["HIG"] = imSize.Y
|
||||||
variables["REG"] = 0
|
variables["REG"] = 0
|
||||||
|
fil.location.maxX = imSize.X
|
||||||
|
fil.location.maxY = imSize.Y
|
||||||
|
|
||||||
fil = filterState{
|
fil = filterState{
|
||||||
filter{255, 255, 255},
|
filter{255, 0, 255},
|
||||||
filter{255,255,255},
|
filter{255, 0,255},
|
||||||
filter{255,255,255},
|
filter{255, 0,255},
|
||||||
filter{255,255,255},
|
filter{255, 0,255},
|
||||||
point{0,0,imSize.X,imSize.Y},
|
point{0,0,imSize.X,imSize.Y},
|
||||||
filter{3,0,0},
|
filter{3,0,0},
|
||||||
}
|
}
|
||||||
|
@ -92,6 +95,7 @@ func filterImage(path, fname string) {
|
||||||
}
|
}
|
||||||
fmt.Print("Saving image \n")
|
fmt.Print("Saving image \n")
|
||||||
saveImage(path, fname, imFormat, im)
|
saveImage(path, fname, imFormat, im)
|
||||||
|
fmt.Print("Image saved. Done. \n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateRegister(exp parser.Expression) {
|
func updateRegister(exp parser.Expression) {
|
||||||
|
@ -179,18 +183,35 @@ func applyToImage(exps []parser.Expression) {
|
||||||
if exps[1].Variable != "" {
|
if exps[1].Variable != "" {
|
||||||
endY = variables[exps[1].Variable]
|
endY = variables[exps[1].Variable]
|
||||||
}
|
}
|
||||||
|
|
||||||
endX = getBoxBound(fil.location.x, endX, variables["WID"], exps[0].Opperator)
|
endX = getBoxBound(fil.location.x, endX, variables["WID"], exps[0].Opperator)
|
||||||
endY = getBoxBound(fil.location.y, endY, variables["HIG"], exps[0].Opperator)
|
endY = getBoxBound(fil.location.y, endY, variables["HIG"], exps[1].Opperator)
|
||||||
|
|
||||||
|
var r,g,b,a int
|
||||||
|
var col color.RGBA
|
||||||
for y := fil.location.y; y <= endY; y++ {
|
for y := fil.location.y; y <= endY; y++ {
|
||||||
for x := fil.location.x; x <= endX; x++ {
|
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 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))
|
||||||
|
r = avgColor(int(col.R), r)
|
||||||
|
g = avgColor(int(col.G), g)
|
||||||
|
b = avgColor(int(col.B), b)
|
||||||
|
a = avgColor(int(col.A), a)
|
||||||
|
}
|
||||||
|
|
||||||
im.SetRGBA(
|
im.SetRGBA(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
color.RGBA{
|
color.RGBA{
|
||||||
uint8(fil.red.val),
|
uint8(r),
|
||||||
uint8(fil.green.val),
|
uint8(g),
|
||||||
uint8(fil.blue.val),
|
uint8(b),
|
||||||
uint8(fil.alpha.val),
|
uint8(a),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
MOD 1
|
||||||
|
|
||||||
|
BEG 25
|
||||||
|
COL 255:0:0:200
|
||||||
|
APY +10:+HIG
|
||||||
|
LOC +20:+0
|
||||||
|
END
|
21
test.frs
21
test.frs
|
@ -4,14 +4,19 @@ APH 255
|
||||||
RED 100
|
RED 100
|
||||||
BLU 100
|
BLU 100
|
||||||
GRN 100
|
GRN 100
|
||||||
# This loop should create a bunch of vertical lines
|
REG WID
|
||||||
BEG 50
|
REG /20
|
||||||
RED +23
|
REG /4
|
||||||
BLU -81
|
LOC +1:+1
|
||||||
GRN *27
|
|
||||||
APH -5
|
BEG 100
|
||||||
APY +5:HIG
|
COL +23:-81:*27:-0
|
||||||
LOC +20:+0
|
APY +3:+3
|
||||||
|
APY +1:+HIG
|
||||||
|
LOC +0:+4
|
||||||
|
APY +WID:+0
|
||||||
|
LOC +0:-4
|
||||||
|
LOC +REG:*24
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue