How to get 16it floats out of a bmap... pixel_for_vec dont work!

Posted By: EvilSOB

How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/03/11 22:41

Hiya all.

Im trying to use a 16bit DDS image to store heightmaps.
Creating the image, and loading it as a BMAP is fine.

BUT, I cant get individual pixel data out of it using pixel_for_bmap and pixel_for_vec
because (according to manual) pixel_for_vec can only manage to handle
"...the pixel format: 88, 565, 888, 1555, 4444, or 8888". And it doesnt even complain
when I try to force it to use pixel format "16""12"...

Any ideas on how I can extract this info (on a pixel by pixel basis) anyone?

Thanks guys...

Posted By: Superku

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/03/11 22:45

Have a look here:
http://www.conitec.net/beta/abmap_lock.htm
Posted By: EvilSOB

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/03/11 23:14

Sorry, but Im already doing that to get the pixel format of the image.

PS: Ive fixed a TYPO in my main post regarding the format number...
Posted By: Slin

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/03/11 23:18

Assuming, that your dds contains texture data compressed with an algorithm, youŽve got hardware support for, the problem is, that the compressed data is never really decompressed. And to actually give you access o the pixels it would have to do this. So the best choice for you is probably just some tga file with losless compression, which is then anyway decompressed on loading.
Posted By: EvilSOB

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/04/11 00:11

No can do. I NEED a 16bit value per pixel.
And I cant get TGA to go 16bit. But Im no 'photoshop guru'...
Posted By: Joey

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/05/11 01:01

256*b+g?
Posted By: bart_the_13th

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/05/11 02:36

Originally Posted By: pixel_for_bmap
Only normal 16, 24, or 32 bit bmaps can be read from. Accessing compressed DDS bmaps, or bmaps used as render target will also cause a crash error.

Your 12 bit DDS bmap is not normal grin
[EDIT]
I assume that you must read the pixel first with pixel_for_bmap before using pixel_for_vec
Posted By: EvilSOB

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/05/11 09:05

Joey: No good dude. I need the actual 16bit data as saved by 'photoshop'.

Bart: Re-read my top post regarding number of bits. I am actually working
with a 16bit float DDS file. The "12" in my top post is the "pixel type number"
that gamestudio returns from bmap_lock. Read the manual under bmap_lock and
check the type 12 entry. Thats me...

And yes I am using pixel_for_bmap first. I also tried looking at the raw
'pixel' data as stored in the var returned by pixel_for_bmp, BEFORE using it in
pixel_to_vec but could make no sense of it or use for it.

I wish I knew how to get inside GS's pixel format, because I suspect the 16bit
data IS being retrieved by pixel_for_bmap, its just that pixel_to_vect doesnt
know how to process it...
Posted By: Slin

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/05/11 10:35

Do you use any compression? What pixel format are you saving with? It is a dds file? Is it loaded correctly? Can you display it in a panel or something? What exactly is supposed to be in the texture?

I think that gamestudio uses some directx function to load dds files, which should support many different formats, but the bmap functions only support a small number of formats, so if your texture is really uncompressed, it could be that you canŽt really use gamestudios functions to get the pixels, but it should then at least be possible to directly access the texture data.
Posted By: EvilSOB

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/05/11 12:22

Its a 16bit float (one color channel) DDS, so I assume it to be compressed. All DDS files are I BELIEVE (noob to DDS).
I only went DDS cause it was one of the few formats that could carry a single 16bit 'color'.

GS DOES load the image, as I am able to display the image with DEBUG_BMAP.
It is a strange washed-out cyan color, but it is recognisably the image in question.

Its not a 'texture', its a heightmap. That I want to never 'display', but I want to
read through it on a pixel-by-pixel basis and save into a custom-structure data file.
This datafile is my (currently in proof-of-concept testing) way of storing the heightmap of 'the entire world'.
So as you can imagine, its BIG, really BIG, you wont believe how vastly, hugely, mind-bogglingly
big it is, you might think its a long way down the street to the chemist, but thats just peanuts to ....
[REDUCTED]

So, with all this known, I feel IF I had some ideas how to start, I could access the texture via the
bmap.finalbits or even the bmap.d3dtex pointers.
But I dont where to start with 16bit floats... Floats are an unknown country to me...

I was HOPING for an easier way, but it looks like I may have no choise.
This is only a TOOL anyway, so speed is not so essential...
Posted By: Slin

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/05/11 12:46

dds is just a container format which can store all kind of texture data, compressed and uncompressed and so on. So this really depends on how you save it. But I guess that there is no basic format for compressed 16bit fp textures, because of that IŽd assume that your texture is uncompressed.
On bmap_lock, what format is returned?

Edit: Also, you should probably go with 32bit instead of 16, as otherwize things get quite tricky, because there is no corresponding datatype.

Something like this could then work:
Code:
#include <d3d9.h>

/* DX Lock flags */
#define D3DLOCK_READONLY 0x00000010L
#define D3DLOCK_DISCARD 0x00002000L
#define D3DLOCK_NOOVERWRITE 0x00001000L
#define D3DLOCK_NOSYSLOCK 0x00000800L
#define D3DLOCK_DONOTWAIT 0x00004000L                  
#define D3DLOCK_NO_DIRTY_UPDATE 0x00008000L

void ReadPixels(float **pixels, BMAP* rbmap)
{
	LPDIRECT3DTEXTURE9 dxtex = rbmap->d3dtex;
	D3DLOCKED_RECT dxrect;
	unsigned char *bmp;
	
	bmap_preload(rbmap);
	dxtex->LockRect(0, &dxrect, NULL, D3DLOCK_READONLY);
	bmp = dxrect.pBits;
	
	var width = bmap_width(rbmap);
	var height = bmap_height(rbmap);
	
	*pixels = sys_malloc(width*height*sizeof(float));
	
	var x, y;
	for(y = 0; y < height; y++)
	{
		memcpy(pixels[y*width], bmp[y*dxrect.Pitch], sizeof(float*width));
	}
	
	dxtex->UnlockRect(0);
}


Posted By: EvilSOB

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/05/11 15:56

Compile error dude ...pBits is not a member of "VOID"

Im digging for it now, but no luck so far...
Posted By: EvilSOB

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/16/11 02:56

Klaatu ... Verada ... Nictu !!!
Thread Resurrection time!

OK, Ive finally gotten to the pixel data via the BMAP.finalbits pointer.
Luckily the data is actually uncompressed. Purely by luck.

BUT, Im able to pull the RAW 16-bit floats out of the DX-data, but
am having a lot of difficulty converting them to 32-bit lite-c floats.
(my pointer maths is still severely rusty still...)

So, any suggestions on how to convert these 16bit floats to 32bit floats?
And / or ultimately to lite-c (scaled?) 'long's or 'short's?


Thanks again guys.
Posted By: rojart

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/16/11 13:30

Originally Posted By: EvilSOB
...So, any suggestions on how to convert these 16bit floats to 32bit floats?...

Use D3DXFloat16To32Array and consult the SDK help for more details.
Posted By: EvilSOB

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/16/11 14:00

Been there, tried that, and failed...

Looks to be another obscure D3D function that conitec didnt bother
to fully implement in their d3d9.h header.

And I dont know D3D well enough to perform a manual override on it.
Tried and failed...
Posted By: EvilSOB

Re: How to get 16it floats out of a bmap... pixel_for_vec dont work! - 10/17/11 05:24

Ive finally come up with my own converter.

Here it is in case anyone else is interested...


Code:
//-----------------------------------------------
// Convert (D3D) float16 to (acknex) float32
//-----------------------------------------------
float	float16to32(short num)
{	long	z = (num & 0x8000) <<16;
	z = z | (((num & 0x7C00) >>10 ) +0x70) <<23;
	z = z |   (num & 0x03ff) <<13;
	return(*((float*)&z));								}
//-----------------------------------------------


© 2024 lite-C Forums