1 decade ago by Heiko
Hi
Saw stats on using canvas imagedata.data vs saving reference to imagedata.data
and then just using that reference to access the pixel data.
Apparently its faster if you use the reference. I assume if you call imagedata.data there is a com interface call involved.
Section A uses imagedata.data vs Section B that uses reference to imagedata.data
thus only 1 interface call.
Haven't tested this myself, but maybe someone else has tried this.
.H
Saw stats on using canvas imagedata.data vs saving reference to imagedata.data
and then just using that reference to access the pixel data.
Apparently its faster if you use the reference. I assume if you call imagedata.data there is a com interface call involved.
Section A uses imagedata.data vs Section B that uses reference to imagedata.data
thus only 1 interface call.
Haven't tested this myself, but maybe someone else has tried this.
====> SECTION A <=====
var scaled = ig.$new('canvas');
scaled.width = widthScaled;
scaled.height = heightScaled;
var scaledCtx = scaled.getContext('2d');
var scaledPixels = scaledCtx.getImageData( 0, 0, widthScaled, heightScaled );
for( var y = 0; y < heightScaled; y++ ) {
for( var x = 0; x < widthScaled; x++ ) {
...
...
scaledPixels.data[ indexScaled ] = origPixels.data[ index ];
scaledPixels.data[ indexScaled+1 ] = origPixels.data[ index+1 ];
scaledPixels.data[ indexScaled+2 ] = origPixels.data[ index+2 ];
scaledPixels.data[ indexScaled+3 ] = origPixels.data[ index+3 ];
}
}
====> SECTION B <=====
var scaled = ig.$new('canvas');
scaled.width = widthScaled;
scaled.height = heightScaled;
var scaledCtx = scaled.getContext('2d');
var scaledPixels = scaledCtx.getImageData( 0, 0, widthScaled, heightScaled );
var scaledPixelData = scaledPixels.data;
for( var y = 0; y < heightScaled; y++ ) {
for( var x = 0; x < widthScaled; x++ ) {
...
...
scaledPixelData[ indexScaled ] = origPixelData[ index ];
scaledPixelData[ indexScaled+1 ] = origPixelData[ index+1 ];
scaledPixelData[ indexScaled+2 ] = origPixelData[ index+2 ];
scaledPixelData[ indexScaled+3 ] = origPixelData[ index+3 ];
}
}
.H