Permalink
Browse files

Make drawing xbrowser

  • Loading branch information...
1 parent 82f250a commit d446527ec1e3de2b88505827d235f317ad94cc42 @trethaller committed Aug 25, 2013
Showing with 49 additions and 11 deletions.
  1. +23 −0 Gruntfile.coffee
  2. +12 −5 out/js/teztura-renderers.js
  3. +2 −1 package.json
  4. +7 −4 src/renderers/gamma-renderer.js
  5. +5 −1 src/renderers/gradient-renderer.js
View
@@ -18,11 +18,34 @@ module.exports = (grunt)->
dist:
src: ['src/renderers/*.js'],
dest: 'out/js/teztura-renderers.js',
+
+ watch:
+ coffee:
+ files: ['src/core/*.coffee', 'src/*.coffee']
+ tasks: ['coffee']
+ options:
+ livereload: true
+
+ concat:
+ files: ['src/renderers/*.js']
+ tasks: ['concat']
+ options:
+ livereload: true
+
+ connect:
+ site:
+ options:
+ port: 8000
+ base: 'out'
+
}
+ grunt.loadNpmTasks('grunt-contrib-connect')
grunt.loadNpmTasks('grunt-contrib-coffee')
grunt.loadNpmTasks('grunt-contrib-concat')
+ grunt.loadNpmTasks('grunt-contrib-watch')
# Default task(s).
grunt.registerTask('default', ['coffee', 'concat'])
+ grunt.registerTask('live', ['connect', 'watch'])
@@ -1,13 +1,13 @@
GammaRenderer = (function() {
-
+
var properties = {
gamma: 1.0
};
function renderLayer (layer, view, rects) {
var width = layer.width;
var height = layer.height;
- var destBuffer = new Uint32Array(view.imageData.data.buffer);
+ var imgData = view.imageData.data;
var fb = layer.getBuffer();
var gamma = properties.gamma;
for(var ri in rects) {
@@ -22,8 +22,11 @@ GammaRenderer = (function() {
var fval = fb[offset + ix];
fval = fval > 1.0 ? 1.0 : (fval < -1.0 ? -1.0 : fval);
var val = Math.round(Math.pow((fval + 1.0) * 0.5, gamma) * 255.0);
- destBuffer[offset + ix] =
- (val) | (val << 8) | (val << 16) | 0xff000000;
+ var off = (offset + ix) << 2;
+ imgData[off] = val;
+ imgData[off+1] = val;
+ imgData[off+2] = val;
+ imgData[off+3] = 0xff;
}
}
view.context.putImageData(view.imageData, 0, 0, r.x, r.y, r.width+1, r.height+1);
@@ -73,7 +76,11 @@ GradientRenderer = (function() {
)
)
];
- destBuffer[offset + ix] = lookup;
+ var off = (offset + ix) << 2;
+ imgData[off] = lookup & 0xff;
+ imgData[off+1] = (lookup >> 8) & 0xff;
+ imgData[off+2] = (lookup >> 16) & 0xff;
+ imgData[off+3] = 0xff;
}
}
view.context.putImageData(view.imageData, 0, 0, r.x, r.y, r.width+1, r.height+1);
View
@@ -23,6 +23,7 @@
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-sass": "~0.5.0",
- "grunt-contrib-watch": "~0.5.2"
+ "grunt-contrib-watch": "~0.5.2",
+ "grunt-contrib-connect": "~0.3.0"
}
}
@@ -1,13 +1,13 @@
GammaRenderer = (function() {
-
+
var properties = {
gamma: 1.0
};
function renderLayer (layer, view, rects) {
var width = layer.width;
var height = layer.height;
- var destBuffer = new Uint32Array(view.imageData.data.buffer);
+ var imgData = view.imageData.data;
var fb = layer.getBuffer();
var gamma = properties.gamma;
for(var ri in rects) {
@@ -22,8 +22,11 @@ GammaRenderer = (function() {
var fval = fb[offset + ix];
fval = fval > 1.0 ? 1.0 : (fval < -1.0 ? -1.0 : fval);
var val = Math.round(Math.pow((fval + 1.0) * 0.5, gamma) * 255.0);
- destBuffer[offset + ix] =
- (val) | (val << 8) | (val << 16) | 0xff000000;
+ var off = (offset + ix) << 2;
+ imgData[off] = val;
+ imgData[off+1] = val;
+ imgData[off+2] = val;
+ imgData[off+3] = 0xff;
}
}
view.context.putImageData(view.imageData, 0, 0, r.x, r.y, r.width+1, r.height+1);
@@ -33,7 +33,11 @@ GradientRenderer = (function() {
)
)
];
- destBuffer[offset + ix] = lookup;
+ var off = (offset + ix) << 2;
+ imgData[off] = lookup & 0xff;
+ imgData[off+1] = (lookup >> 8) & 0xff;
+ imgData[off+2] = (lookup >> 16) & 0xff;
+ imgData[off+3] = 0xff;
}
}
view.context.putImageData(view.imageData, 0, 0, r.x, r.y, r.width+1, r.height+1);

0 comments on commit d446527

Please sign in to comment.