Fixes and simplifies pixel sampling. Removes put command, fixes LOX and LOY
This commit is contained in:
parent
784a473fa1
commit
d2f325b432
81
main.go
81
main.go
|
@ -38,7 +38,6 @@ type filterState struct {
|
|||
alpha filter
|
||||
location point
|
||||
mode filter
|
||||
sample col
|
||||
}
|
||||
var variables = map[string]int{}
|
||||
var tree parser.AST
|
||||
|
@ -90,12 +89,6 @@ 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... ")
|
||||
|
@ -168,6 +161,19 @@ func procedure(p parser.Procedure) {
|
|||
if len(p.Expressions) == 2 {
|
||||
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":
|
||||
if len(p.Expressions) >= 1 {
|
||||
fil.mode.update(p.Expressions[0])
|
||||
|
@ -177,7 +183,7 @@ func procedure(p parser.Procedure) {
|
|||
updateRegister(p.Kind, p.Expressions[0])
|
||||
}
|
||||
case "APY":
|
||||
applyToImage(p.Expressions, false)
|
||||
applyToImage(p.Expressions)
|
||||
case "RED":
|
||||
if len(p.Expressions) >= 1 {
|
||||
fil.red.update(p.Expressions[0])
|
||||
|
@ -202,37 +208,36 @@ func procedure(p parser.Procedure) {
|
|||
fil.alpha.update(p.Expressions[3])
|
||||
}
|
||||
case "GET":
|
||||
fil.sample.update()
|
||||
case "PUT":
|
||||
applyToImage(p.Expressions, true)
|
||||
fil.getColors()
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
if len(exps) == 0 {
|
||||
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),
|
||||
})
|
||||
r = fil.red.val
|
||||
g = fil.green.val
|
||||
b = fil.blue.val
|
||||
a = fil.alpha.val
|
||||
if fil.mode.val != 0 {
|
||||
col = im.RGBAAt(fil.location.x, fil.location.y)
|
||||
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(
|
||||
fil.location.x,
|
||||
fil.location.y,
|
||||
color.RGBA{
|
||||
uint8(r),
|
||||
uint8(g),
|
||||
uint8(b),
|
||||
uint8(a),
|
||||
})
|
||||
} else if len(exps) == 2 {
|
||||
endX := exps[0].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)
|
||||
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 x := fil.location.x; x <= endX; x++ {
|
||||
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))
|
||||
r = avgColor(int(col.R), r)
|
||||
g = avgColor(int(col.G), g)
|
||||
b = avgColor(int(col.B), b)
|
||||
|
|
|
@ -221,7 +221,7 @@ func (p *Parser) Parse() AST {
|
|||
|
||||
func isValidProcedure(p string) bool {
|
||||
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":
|
||||
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)
|
||||
fil.sample.red.val = int(imCol.R)
|
||||
fil.sample.blue.val = int(imCol.B)
|
||||
fil.sample.green.val = int(imCol.B)
|
||||
fil.sample.alpha.val = int(imCol.A)
|
||||
|
||||
f.red.val = int(imCol.R)
|
||||
f.blue.val = int(imCol.B)
|
||||
f.green.val = int(imCol.B)
|
||||
f.alpha.val = int(imCol.A)
|
||||
}
|
||||
|
|
|
@ -1,39 +1,75 @@
|
|||
# This will test image sampling
|
||||
|
||||
MOD 0
|
||||
|
||||
RG1 WID
|
||||
RG1 /2
|
||||
RG2 HIG
|
||||
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
|
||||
|
||||
|
||||
# Create vertical lines throughout
|
||||
MOD 0
|
||||
|
||||
BEG 50
|
||||
LOC +50:*73
|
||||
BEG 2
|
||||
LOC +1:+0
|
||||
GET
|
||||
PUT +0:+RG2
|
||||
APY +0:+RG2
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
# Create transparent red bar at top
|
||||
MOD 1
|
||||
|
||||
LOC 0:0
|
||||
COL 240:50:50:240
|
||||
RG1 HIG
|
||||
RG1 /10
|
||||
APY +WID:+RG1
|
||||
|
||||
LOC +5:+1
|
||||
|
||||
# Create noise underneath red bar
|
||||
MOD 0
|
||||
|
||||
LOC +5:+1
|
||||
|
||||
BEG 50
|
||||
LOC *9:+2
|
||||
GET
|
||||
LOC +0:+RG1
|
||||
BEG 50
|
||||
LOC +37:+0
|
||||
PUT +1:+1
|
||||
APY +1:+1
|
||||
END
|
||||
LOC +0:-RG1
|
||||
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