Archived

This topic is now archived and is closed to further replies.

BoRReL

Getting rgb from 16BPP DXSurface

Recommended Posts

Hey, How can I get the r, g, b values from a 16bpp surface in directx? Is it 5-6-5? (rrrrrggggggbbbbb) It''s probably faster reading a DWORD from the surface (2 pixels) Then extracting both pixels and then getting the rgb for both. Can someone tell me how? Thanks in advance! Gr, BoRReL

Share this post


Link to post
Share on other sites
It depends on the pixel format of the surface!!

it could be 0555, 565, 4444, 1555 and it could be BGRA, RGB, XRGB etc.

You need to get the pixel format for the surface, this then contains masks for each element (A,R,G,B).
If you want to separate out the elements properly (into separate R,G,B where each is in the range 0-255), you''ll need to:

a. work out how many bits there are for each element (ie. 5 for R, 6 for G...)

b. work out where in the word each element is.

c. using a&b, mask out and shift each element, including extra shift to make sure the final elements have the same magnitude (you need to shift each element so that its highest bit is in bit 7 of the destination).



And yes, DWORD access can help

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Thanks!

It the format was 565.
Is this format hardware dependant?
So when I run my code on another computer, the format
could be different?
Or is this the default directx 16bpp approach?

Tnx again,
BoRReL

Share this post


Link to post
Share on other sites
Most hardware uses 565, but that''s not a standard, there could be hardware that does it differently. For example, 1555 is also popular (with one bit for alpha). You need to be aware of this...


War Worlds - A 3D Real-Time Strategy game in development.

Share this post


Link to post
Share on other sites