Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Canvas pixelformat

I have noticed that everyone working with the Canvas object multiply their way around the pixelbuffer by 4's (RGBA). I have worked a lot with native pixel coding (Delphi and C++) and recognize this as a normal 32bit RGBA (888-8 encoding). My question is: is there a way to detect the pixelformat of the browser? If you are running on a device supporting 16bit (565 encoding) or 24bit (888 encoding) it will be very slow if the browser has to downgrade the bitmaps for each redraw. Especially when alpha blending is involved.

Also (and this is secondary): Is it possible to create a pure 888 or 565 bitmap at all under javascript? Or what about an 8bit palette based bitmap? JS based games would benefit greatly only having to work with 8bit pixels in my view.

like image 751
Jon Lennart Aasenden Avatar asked Jul 21 '11 18:07

Jon Lennart Aasenden


2 Answers

No. There is no seeming way to downgrade the pixels of the canvas, as that is what the imageData simply is as far as the specification itself is concerned.

You can of course make a javascript game using nothing but 8-bit PNGs, which would save space and load time, but not render time.

like image 72
Simon Sarris Avatar answered Oct 07 '22 22:10

Simon Sarris


No, there is no way to specify what color space you want. Any manual hacks around this would only slow down the rendering further. In my experience, some browsers (Google Chrome) can render very complex games and still maintain a high frame rate.

like image 30
John Stimac Avatar answered Oct 08 '22 00:10

John Stimac