Skip to content

Commit

Permalink
New: Invert and flip commands
Browse files Browse the repository at this point in the history
  • Loading branch information
trethaller committed Aug 6, 2013
1 parent 38ebb85 commit 9155580
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
52 changes: 52 additions & 0 deletions js/app.coffee
Expand Up @@ -35,6 +35,58 @@ Commands = [
return val return val
refresh() refresh()
}, },
{
name: "Invert"
func: (doc)->
buf = doc.layer.getBuffer()
len = buf.length
`for(var i=0; i<len; ++i) {
buf[i] = -buf[i];
}
`
refresh()
},
{
name: "Flip H"
func: (doc)->
buf = doc.layer.getBuffer()
len = buf.length
height = doc.layer.height
width = doc.layer.width
halfw = Math.floor(doc.layer.width / 2.0)
maxx = doc.layer.width - 1;
tmp = 0.0
`for(var iy=0; iy<height; ++iy) {
var offset = iy * width
for(var ix=0; ix<halfw; ++ix) {
tmp = buf[offset + ix];
buf[offset + ix] = buf[offset + maxx - ix];
buf[offset + maxx - ix] = tmp;
}
}
`
refresh()
},
{
name: "Flip V"
func: (doc)->
buf = doc.layer.getBuffer()
len = buf.length
height = doc.layer.height
width = doc.layer.width
halfh = Math.floor(doc.layer.width / 2.0)
maxy = doc.layer.width - 1;
tmp = 0.0
`for(var iy=0; iy<halfh; ++iy) {
for(var ix=0; ix<width; ++ix) {
tmp = buf[iy*width + ix];
buf[iy*width + ix] = buf[(maxy - iy)*width + ix];
buf[(maxy - iy)*width + ix] = tmp;
}
}
`
refresh()
},
] ]


class DocumentView class DocumentView
Expand Down
55 changes: 55 additions & 0 deletions js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9155580

Please sign in to comment.