javascript - How can I speed up this slow canvas DrawImage operation? WebGL? Webworkers? -
i combining 2 high resolution images html5 canvas element.
the first image jpeg , contains color data, , second image alpha mask png file.
i combine 2 produce single rgba canvas.
the app dealing 2048x2048 resolution images, need maintain alpha channel. therefore using method ooposed using png's, have reduced average filesize around 2-3mb 50-130kb plus 10kb png alpha mask.
the method use follows:
context.drawimage(alpha_mask_png, 0, 0, w, h); context.globalcompositeoperation = 'source-in'; context.drawimage(main_image_jpeg, 0, 0, w, h);
unfortunately operation takes around 100-120ms. , carried out once each pair of images loaded. while wouldn't issue, in case animation being rendered main visible canvas (of these high res images source art for) suffers noticable 100ms judder (mostly perceptible in firefox) whenever new source art streamed in, loaded, , combined.
what looking way reduce this.
here have tried far:
- implemented webp google chrome, removing need combine jpeg , png alpha mask altogether. perfect in chrome need solution firefox (ie 10/11 seems perform operation far quicker)
- i have tried loading images in webworker , decoding them both, followed combining them. in pure javascript. works far slow of use.
- i have tried using webp polyfills. weppy fast , when ran in webworker not effect main loop. not support alpha transparency of no use real shame method close. libwebpjs works okay within webworker manual decoding of jpeg/png, far slow.
edit: further clarify. have tried transferring data webworkers using transferrable objects , have tried turning result blob , creating objecturl can loaded main thread. although there no lag in main thread more, images take far long decode.
this leaves me webgl. have literally no understanding of how webgl works other realise need load both jpeg , png seperate textures combine them shader. wouldn't know begin.
i have spent time playing code following link:
but no avail. , honest concerned loading images textures might take longer original method anyway.
so summarise, looking way of speeding operation on high resolution images. (1920x1080 - 2048x2048) use of webgl or indeed other method.
any or suggestions appreciated.
Comments
Post a Comment