HTML5 setPixel32 and fillRect performance

Hi!
I’m developing an implicit function plotter, which regularly update a BitmapData (in 30-40 ms), because I want responsible UI.
Profiling the code, the native(?) getImageData is the most time consuming operation in setPixel32() functions.
If I use instead of fillRect() with 1x1 pixel rectangles it is much faster (about 100x), but fillRect() with transparent colour is strange, because it doesn’t overwrite the old colour with the new one, just blend them together - so it is useless for me.
There are any faster setPixel32 mode, like lock(), unlock() the BitmapData in flash?
Or I need to store the BitmapData in a Vector/Array and refresh the image from it?
Any idea is welcome!

private function __fillRect (rect:Rectangle, color:Int) {

        var a = (transparent) ? ((color & 0xFF000000) >>> 24) : 0xFF;
        var r = (color & 0x00FF0000) >>> 16;
        var g = (color & 0x0000FF00) >>> 8;
        var b = (color & 0x000000FF);

        __sourceContext.clearRect (rect.x, rect.y, rect.width, rect.height);
        __sourceContext.fillStyle = 'rgba(' + r + ', ' + g + ', ' + b + ', ' + (a / 255) + ')';
        __sourceContext.fillRect (rect.x, rect.y, rect.width, rect.height); 
    }

If you replace __fillRect function in BitmapData class with this code it won’t blend colors anymore…but I’m not sure if this is a proper solution so I never created pull request.

Thanks for Your reply. I found this __fillRect function in openfl-html-dom library only. And I changed it, bit nothing happened, so I think, this not the right BitmapData.hx file.
Can you be more specific?

If you are using the latest lime/openfl then the function you are looking for is in lime: https://github.com/openfl/lime/blob/master/lime/graphics/Image.hx#L349

Thanks. the BitmapData.copyPixels() function is a fairly good solution, with limited number of colours and a colorBD:BitmapData with these colours.

If you guys have patches/recommendations to improve performance in the core libraries, please share or pull request! :slight_smile: