Closed deathcap closed 9 years ago
Trying this:
- getPixels(this.atlas.canvas.toDataURL(), function(err, array) {
- if (err) return cb(err);
+ var context = atlas.canvas.getContext('2d');
+ var s = this.atlasSize;
+ console.log(atlas.canvas.toDataURL());
+ var pixels = context.getImageData(0, 0, s, s);
+ var array = ndarray(new Uint8Array(pixels.data), [s, s, 4], [4, 4*s, 1], 0);
+
+ getPixels(atlas.canvas.toDataURL(), function(err, array2) {
+ console.log(array)
+ console.log(array2)
but all the textures are wrong:
for some reason the ndarray strides differ:
View3duint8 {data: Uint8Array[16777216], _shape0: 2048, _shape1: 2048, _shape2: 4, _stride0: 4…} stitch.js:219 View3duint8 {data: Uint8Array[16777216], _shape0: 2048, _shape1: 2048, _shape2: 4, _stride0: 8192…}
update: found it, get-pixels 2.0.0 to 3.0.0 changed from rows/cols to width/height: https://github.com/scijs/get-pixels/commit/352b7115663fcd0de2edd071ab0e9ef059ecc772 - voxel-stitch was using get-pixels 1.0.1 (≈1.1.3)
is too slow, bottlenecked on the regex to parse the data URL to determine the filename "extension" (there isn't one) to infer the file type (not needed):
get-pixels could be optimized to not examine the extension if not needed, after all it does accept an optional type parameter (not used here), but I'm not sure why I'm using this roundabout method to get at the canvas pixel data to begin with. get-pixels just writes the data to a canvas! then reads it: