Permalink
Browse files

New: Invert and flip commands

  • Loading branch information...
1 parent 38ebb85 commit 9155580bd5e5d3f7d8daac686bd4d9a56c1d3f14 @trethaller committed Aug 6, 2013
Showing with 107 additions and 0 deletions.
  1. +52 −0 js/app.coffee
  2. +55 −0 js/app.js
View
@@ -35,6 +35,58 @@ Commands = [
return val
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
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 9155580

Please sign in to comment.