Sign in to follow this  

Reading texture data

This topic is 2349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all,

I have troubles understanding how to read data from a locked texture. What im trying todo is to parse through an image of b/w texels to retrieve some informations. For testing that i created a 3x1 bmp file containing 2 black and 1 white (b,b,w) texel.(RGB, 8bit channels, 24bit depth)

So what i'm doing here is to create a texture out of that file and lock it. For my tests i directly access the pBits area of the locked rect. Yet they are not as expected.
As far as i know each texel will be represented by 4 bytes (b,g,r,a) on the locked memory area.

By that I would have expected a result like this:

First two black:
pbits[0] = 0
pbits[1] = 0
pbits[2] = 0
pbits[3] = 255
pbits[4] = 0
pbits[5] = 0
pbits[6] = 0
pbits[7] = 255

Last white:
pbits[8] = 255
pbits[9] = 255
pbits[10] = 255
pbits[11] = 255


Yet i receive something like this:
pbits[0] = 43
pbits[1] = 43
pbits[2] = 43
pbits[3] = 0
pbits[4] = 0
pbits[5] = 0
pbits[6] = 0
pbits[7] = 0
pbits[8] = 96
pbits[9] = 96
pbits[10] = 96
pbits[11] = 0


When i have only two pixel using black and white it does work however. Can someone help me finding out what i'm doing wrong here ? The pitch should not be important here as i only test the first 3 pixels, right ?!


Here a code snipped without all the checking stuff around:
[code]
IDirect3DTexture9* tex;
D3DXCreateTextureFromFile(g_device, "pixelTest.bmp", &tex);
D3DLOCKED_RECT lRect;
ZeroMemory(&lRect, sizeof(D3DLOCKED_RECT));

tex->LockRect(0, &lRect, NULL, NULL);
int iPitch = lRect.Pitch;
BYTE* pPBits = static_cast<BYTE*>(lRect.pBits);
[/code]


Any help would be highly appreciated - this thing costs me some hours already :unsure:


Thanks alot,
Oliver

Share this post


Link to post
Share on other sites
ok, it does work when using D3DXCreateTextureFromFileEx. Even with a very default'ish one...

[code]
D3DXCreateTextureFromFileEx(g_device, "pixelTest.bmp", NULL, NULL, NULL, NULL, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, NULL, NULL, NULL, &tex);
[/code]

The default Filter parameter D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER was the reason for the color adjustments during the load.


Thanks anyway!

Share this post


Link to post
Share on other sites

This topic is 2349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this