Skip to content

Commit

Permalink
fix SurfaceArray.blitArray(); change Surface.getImageData() semantics
Browse files Browse the repository at this point in the history
there is a distinction between ImageData class and the actual image data,
which is contained in that class as property `data`. I confused those.

Browsers accepted the raw data as ImageData but were throwing errors.
  • Loading branch information
oberhamsi committed Nov 23, 2011
1 parent 3575f5d commit 197c3aa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/gamejs.js
Expand Up @@ -720,11 +720,11 @@ Surface.prototype.setAlpha = function(alpha) {
* starting with the top left, with each pixel's red, green, blue, and alpha components
* being given in that order for each pixel.
* @see http://dev.w3.org/html5/2dcontext/#canvaspixelarray
* @returns {Array} the pixel image data (the canvas pixel array in html speak)
* @returns {ImageData} an object holding the pixel image data {data, width, height}
*/
Surface.prototype.getImageData = function() {
var size = this.getSize();
return this.context.getImageData(0, 0, size[0], size[1]).data;
return this.context.getImageData(0, 0, size[0], size[1]);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/gamejs/mask.js
Expand Up @@ -15,7 +15,7 @@ var objects = require('./utils/objects');
*/
exports.fromSurface = function(surface, threshold) {
threshold = threshold && (255 - threshold) || 255;
var imgData = surface.getImageData();
var imgData = surface.getImageData().data;
var dims = surface.getSize();
var mask = new Mask(dims);
for (var i=0;i<imgData.length;i += 4) {
Expand Down
3 changes: 2 additions & 1 deletion lib/gamejs/surfacearray.js
Expand Up @@ -123,7 +123,8 @@ var SurfaceArray = exports.SurfaceArray = function(surfaceOrDimensions) {
data = imageData.data;
} else {
size = surfaceOrDimensions.getSize();
data = imageData = surfaceOrDimensions.getImageData(0, 0, size[0], size[1]);
imageData = surfaceOrDimensions.getImageData(0, 0, size[0], size[1]);
data = imageData.data;
}
return this;
};

0 comments on commit 197c3aa

Please sign in to comment.