Fixes and simplifies pixel sampling. Removes put command, fixes LOX and LOY
This commit is contained in:
parent
784a473fa1
commit
d2f325b432
89
main.go
89
main.go
|
@ -38,7 +38,6 @@ type filterState struct {
|
||||||
alpha filter
|
alpha filter
|
||||||
location point
|
location point
|
||||||
mode filter
|
mode filter
|
||||||
sample col
|
|
||||||
}
|
}
|
||||||
var variables = map[string]int{}
|
var variables = map[string]int{}
|
||||||
var tree parser.AST
|
var tree parser.AST
|
||||||
|
@ -90,12 +89,6 @@ func filterImage(path, fname string) {
|
||||||
filter{255, 0,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},
|
||||||
col{
|
|
||||||
filter{255, 0, 255},
|
|
||||||
filter{255, 0, 255},
|
|
||||||
filter{255, 0, 255},
|
|
||||||
filter{255, 0, 255},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("Filtering image... ")
|
fmt.Print("Filtering image... ")
|
||||||
|
@ -168,6 +161,19 @@ func procedure(p parser.Procedure) {
|
||||||
if len(p.Expressions) == 2 {
|
if len(p.Expressions) == 2 {
|
||||||
fil.location.update(p.Expressions)
|
fil.location.update(p.Expressions)
|
||||||
}
|
}
|
||||||
|
case "LOX":
|
||||||
|
if len(p.Expressions) == 1 {
|
||||||
|
y := parser.Expression{Opperator: '+', Opperand: 0, Variable: ""}
|
||||||
|
p.Expressions = append(p.Expressions, y)
|
||||||
|
fil.location.update(p.Expressions)
|
||||||
|
}
|
||||||
|
case "LOY":
|
||||||
|
if len(p.Expressions) == 1 {
|
||||||
|
x := parser.Expression{Opperator: '+', Opperand: 0, Variable: ""}
|
||||||
|
exps := make([]parser.Expression,2,2)
|
||||||
|
exps = append(p.Expressions, x, p.Expressions[0])
|
||||||
|
fil.location.update(exps)
|
||||||
|
}
|
||||||
case "MOD":
|
case "MOD":
|
||||||
if len(p.Expressions) >= 1 {
|
if len(p.Expressions) >= 1 {
|
||||||
fil.mode.update(p.Expressions[0])
|
fil.mode.update(p.Expressions[0])
|
||||||
|
@ -177,7 +183,7 @@ func procedure(p parser.Procedure) {
|
||||||
updateRegister(p.Kind, p.Expressions[0])
|
updateRegister(p.Kind, p.Expressions[0])
|
||||||
}
|
}
|
||||||
case "APY":
|
case "APY":
|
||||||
applyToImage(p.Expressions, false)
|
applyToImage(p.Expressions)
|
||||||
case "RED":
|
case "RED":
|
||||||
if len(p.Expressions) >= 1 {
|
if len(p.Expressions) >= 1 {
|
||||||
fil.red.update(p.Expressions[0])
|
fil.red.update(p.Expressions[0])
|
||||||
|
@ -202,37 +208,36 @@ func procedure(p parser.Procedure) {
|
||||||
fil.alpha.update(p.Expressions[3])
|
fil.alpha.update(p.Expressions[3])
|
||||||
}
|
}
|
||||||
case "GET":
|
case "GET":
|
||||||
fil.sample.update()
|
fil.getColors()
|
||||||
case "PUT":
|
|
||||||
applyToImage(p.Expressions, true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyToImage(exps []parser.Expression, useSample bool) {
|
func applyToImage(exps []parser.Expression) {
|
||||||
|
var r,g,b,a int
|
||||||
|
var col color.RGBA
|
||||||
var err error
|
var err error
|
||||||
if len(exps) == 0 {
|
if len(exps) == 0 {
|
||||||
if useSample {
|
r = fil.red.val
|
||||||
im.SetRGBA(
|
g = fil.green.val
|
||||||
fil.location.x,
|
b = fil.blue.val
|
||||||
fil.location.y,
|
a = fil.alpha.val
|
||||||
color.RGBA{
|
if fil.mode.val != 0 {
|
||||||
uint8(fil.sample.red.val),
|
col = im.RGBAAt(fil.location.x, fil.location.y)
|
||||||
uint8(fil.sample.green.val),
|
r = avgColor(int(col.R), r)
|
||||||
uint8(fil.sample.blue.val),
|
g = avgColor(int(col.G), g)
|
||||||
uint8(fil.sample.alpha.val),
|
b = avgColor(int(col.B), b)
|
||||||
})
|
a = avgColor(int(col.A), a)
|
||||||
|
|
||||||
} 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),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
im.SetRGBA(
|
||||||
|
fil.location.x,
|
||||||
|
fil.location.y,
|
||||||
|
color.RGBA{
|
||||||
|
uint8(r),
|
||||||
|
uint8(g),
|
||||||
|
uint8(b),
|
||||||
|
uint8(a),
|
||||||
|
})
|
||||||
} else if len(exps) == 2 {
|
} else if len(exps) == 2 {
|
||||||
endX := exps[0].Opperand
|
endX := exps[0].Opperand
|
||||||
endY := exps[1].Opperand
|
endY := exps[1].Opperand
|
||||||
|
@ -252,24 +257,14 @@ func applyToImage(exps []parser.Expression, useSample bool) {
|
||||||
endX = getBoxBound(fil.location.x, endX, fil.location.maxX, exps[0].Opperator)
|
endX = getBoxBound(fil.location.x, endX, fil.location.maxX, exps[0].Opperator)
|
||||||
endY = getBoxBound(fil.location.y, endY, fil.location.maxY, exps[1].Opperator)
|
endY = getBoxBound(fil.location.y, endY, fil.location.maxY, 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++ {
|
||||||
if useSample {
|
r = fil.red.val
|
||||||
r = fil.sample.red.val
|
g = fil.green.val
|
||||||
g = fil.sample.green.val
|
b = fil.blue.val
|
||||||
b = fil.sample.blue.val
|
a = fil.alpha.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 {
|
if fil.mode.val != 0 {
|
||||||
col = im.RGBAAt(x, y)
|
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)
|
r = avgColor(int(col.R), r)
|
||||||
g = avgColor(int(col.G), g)
|
g = avgColor(int(col.G), g)
|
||||||
b = avgColor(int(col.B), b)
|
b = avgColor(int(col.B), b)
|
||||||
|
|
|
@ -221,7 +221,7 @@ func (p *Parser) Parse() AST {
|
||||||
|
|
||||||
func isValidProcedure(p string) bool {
|
func isValidProcedure(p string) bool {
|
||||||
switch p {
|
switch p {
|
||||||
case "RG1", "RG2", "LOC", "BEG", "END", "RED", "GET", "PUT",
|
case "RG1", "RG2", "LOC", "BEG", "END", "RED", "GET",
|
||||||
"GRN", "BLU", "APH", "COL", "APY", "MOD", "LOX", "LOY":
|
"GRN", "BLU", "APH", "COL", "APY", "MOD", "LOX", "LOY":
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
11
receivers.go
11
receivers.go
|
@ -108,11 +108,10 @@ func (p *point) update(change []parser.Expression) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *col) update() {
|
func (f *filterState) getColors() {
|
||||||
imCol := im.RGBAAt(fil.location.x, fil.location.y)
|
imCol := im.RGBAAt(fil.location.x, fil.location.y)
|
||||||
fil.sample.red.val = int(imCol.R)
|
f.red.val = int(imCol.R)
|
||||||
fil.sample.blue.val = int(imCol.B)
|
f.blue.val = int(imCol.B)
|
||||||
fil.sample.green.val = int(imCol.B)
|
f.green.val = int(imCol.B)
|
||||||
fil.sample.alpha.val = int(imCol.A)
|
f.alpha.val = int(imCol.A)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,75 @@
|
||||||
# This will test image sampling
|
# This will test image sampling
|
||||||
|
|
||||||
MOD 0
|
RG1 WID
|
||||||
|
RG1 /2
|
||||||
RG2 HIG
|
RG2 HIG
|
||||||
RG2 /2
|
RG2 /2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Create sample in paralellagram shape
|
||||||
|
LOC RG1:RG2
|
||||||
|
LOC +50:-50
|
||||||
|
BEG 100
|
||||||
|
LOC -129:+1
|
||||||
|
BEG 130
|
||||||
|
GET
|
||||||
|
LOC +150:+150
|
||||||
|
APY
|
||||||
|
LOC -150:-150
|
||||||
|
LOC +1:+0
|
||||||
|
END
|
||||||
|
END
|
||||||
LOC 50:37
|
LOC 50:37
|
||||||
|
|
||||||
|
|
||||||
|
# Create vertical lines throughout
|
||||||
|
MOD 0
|
||||||
|
|
||||||
BEG 50
|
BEG 50
|
||||||
LOC +50:*73
|
LOC +50:*73
|
||||||
BEG 2
|
BEG 2
|
||||||
LOC +1:+0
|
LOC +1:+0
|
||||||
GET
|
GET
|
||||||
PUT +0:+RG2
|
APY +0:+RG2
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
||||||
|
# Create transparent red bar at top
|
||||||
MOD 1
|
MOD 1
|
||||||
|
|
||||||
LOC 0:0
|
LOC 0:0
|
||||||
COL 240:50:50:240
|
COL 240:50:50:240
|
||||||
RG1 HIG
|
RG1 HIG
|
||||||
RG1 /10
|
RG1 /10
|
||||||
APY +WID:+RG1
|
APY +WID:+RG1
|
||||||
|
|
||||||
LOC +5:+1
|
|
||||||
|
# Create noise underneath red bar
|
||||||
MOD 0
|
MOD 0
|
||||||
|
|
||||||
|
LOC +5:+1
|
||||||
|
|
||||||
BEG 50
|
BEG 50
|
||||||
LOC *9:+2
|
LOC *9:+2
|
||||||
GET
|
GET
|
||||||
LOC +0:+RG1
|
LOC +0:+RG1
|
||||||
BEG 50
|
BEG 50
|
||||||
LOC +37:+0
|
LOC +37:+0
|
||||||
PUT +1:+1
|
APY +1:+1
|
||||||
END
|
END
|
||||||
LOC +0:-RG1
|
LOC +0:-RG1
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
||||||
|
#Add dark bars
|
||||||
|
LOC 0:0
|
||||||
|
MOD 1
|
||||||
|
COL 0:0:0:240
|
||||||
|
RG1 7
|
||||||
|
BEG 5
|
||||||
|
LOC +0:+113
|
||||||
|
APY +WID:+RG1
|
||||||
|
RG1 *2
|
||||||
|
END
|
||||||
|
|
Loading…
Reference in New Issue