开发者

16 bpp to 32 bpp conversion

We have a encoder library which takes 32 bpp data. We have a screen capture library which needs to support 16 bpp as well. I would like to convert a 16bpp raw data into 32bpp whenever I need to pass the new screen captures to encoder. How can it be done efficiently and are there any other alternatives ?

I dont want to change the encoder library because that will require changes开发者_C百科 upstream of encoder as well.

Thanks!


You could load the source bitmap into an HBITMAP, create a destination bitmap with the desired pixel format and then draw the source onto the destination. That would be the easiest way to do it.

If you wanted to work directly with the bits then that would be possible but it's easier to let the system worry about it for you. It's probably quicker when the system does it because it will be well optimised.


To clarify the other answers: you need to use CreateDIBSection to create bitmaps in the formats you are interested in: 16bpp and 32bpp.

The handy thing with this function is it returns a pointer to the memory buffer with the pixel data, allowing you to easily initialize the bitmap from the one source, and extract the pixel data to give to the encoder library.

The source bitmap doesn't need to be a DIBSection, it can be any kind of HBITMAP at all (as long as its compatible with the HDC you try to select it into - but the screen capture library will be giving you a screen DC compatible HBITMAP if it gives you an HBITMAP at all)

BitBlt can then be used to get the device driver to perform the format conversion.


Use BitBlt:

"If the color formats of the source and destination device contexts do not match, the BitBlt function converts the source color format to match the destination format."

http://msdn.microsoft.com/en-us/library/dd183370%28v=VS.85%29.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜