开发者

Javascript Canvas pixelformat

I have noticed that everyone working with the Ca开发者_如何学Pythonnvas 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.


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.


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.


Actually you are mixing two entities: image color space and surface color space. 5-6-5 is surface color space that has no concept of transparency by definition. Image and the <canvas> are subjects of z-order rendering so must have alpha in one form or another.

So answer is 'no' because it is against requirements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜