🔒 Locked
16 bit format
Advertisement
Original Post
Hi I'm looking for a tutorial that uses 16-bit pixels. I'm new at DirectX and can only find 32-bit examples. I have an array like this: USHORT arrIn[512*512] and I have to fill it with a grayscale from 0 to 2^16 and plot the pixels to the screen. (index 0 = x=0,y=0) Sorry if I didn't explained it well.
Quote:
Original post by Brocketino
If it's ddraw you're using this and this
I gues he's not looking for 16-bit RGB , but 16-bit grayscale as used in scientific, medical and sometimes engineering applications.
majak: The DDS file format can be used to store such textures. Check out the supported formats and select the one that suits your needs. The Direct3DX utility library provides a number of functions to create, save and load DDS files so you don't have to do that manually.
Good luck!
Pat.
Quote:
Original post by Brocketino
If it's ddraw you're using this and this
It's not DirectDraw I'm using, I just took a tutorial from DirectX Samples that shows how to view pixels onto the screen, but thats 32 bit pixels and I don't know how to do this with 16 bit, that's way I need a tutorial or two.
About the file thing, I will be needing to store my picture, but that's far in the future =)
At the moment I just have the picture in an array (the intensities, in bits) and want to view it in grayscale.
The two links above is good to undestand how to deal with the bits, thanks =)
At this time I'm using the struct:
struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The transformed position for the vertex
DWORD color;
};
and #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
My color should be a unsigned short because I only want to use 16 bit colors, how do I implement that instead of 32 bit?
It gets wierd if I just write unsigned short instead of DWORD..
struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The transformed position for the vertex
DWORD color;
};
and #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
My color should be a unsigned short because I only want to use 16 bit colors, how do I implement that instead of 32 bit?
It gets wierd if I just write unsigned short instead of DWORD..
Another question.. At the moment I'm making an array of 512*512 pixels and my screen is 512*512. I'm clearing my backbuffer to a color, but that seems like overkill when I can't see it anyway.. Are there a way to make my array (image) the backbuffer?
Actually, my array is not 512*512, it is supposed to, but I get overflow exception??
Actually, my array is not 512*512, it is supposed to, but I get overflow exception??
Your vertex structure should still take a 32-bit value, as should all your other functions. The only time you care what format a surface is in, is if you need to lock the surface.
All colour calculations in D3D are done in 32-bit mode, and then converted to 16-bit when you come to plot the pixel I believe.
As for info on writing 16-bit values, you just need to make sure you pack your values in properly. E.g. if you're using D3DFMT_R5G6B5, you'd do this for each pixel:
That is, you extract the lowest portion of the intensities (For green you have 6 bits, which is 00111111 in binary, which is 0x1f in hex), then shift it to correct position in the 16-bit value (For red, you want it to be 11 bits to the left, since you have 6 bits of green, and 5 bits of blue, hence 6+5 = 11).
All colour calculations in D3D are done in 32-bit mode, and then converted to 16-bit when you come to plot the pixel I believe.
As for info on writing 16-bit values, you just need to make sure you pack your values in properly. E.g. if you're using D3DFMT_R5G6B5, you'd do this for each pixel:
WORD wVal;wVal = ((b&0x1f) << 0);wVal |= ((g&0x3f) << 5);wVal |= ((r&0x1f) << 11);That is, you extract the lowest portion of the intensities (For green you have 6 bits, which is 00111111 in binary, which is 0x1f in hex), then shift it to correct position in the 16-bit value (For red, you want it to be 11 bits to the left, since you have 6 bits of green, and 5 bits of blue, hence 6+5 = 11).
Quote:Yup, you can fill a texture with your image, then render the texture to a backbuffer using an orthogonal projection matrix. E.g.
Original post by majak
Another question.. At the moment I'm making an array of 512*512 pixels and my screen is 512*512. I'm clearing my backbuffer to a color, but that seems like overkill when I can't see it anyway.. Are there a way to make my array (image) the backbuffer?
D3DXMATRIX matProj;D3DXMatrixOrthoLH(&matProj,512,512,0.0f,1.0f);m_pDevice->SetTransform(D3DTS_PROJECTION,&matProj);m_pDevice->SetTexture(0,pTexture);// Render a quad from (-256.5f,-256.5f) to (255.5f,255.5f)Quote:How do you allocate your array? And can we see some code where you fill the array?
Original post by majak
Actually, my array is not 512*512, it is supposed to, but I get overflow exception??
I just use for loops.. and drawing a straight line from 0,0 to 511,511.
for(int række = 0; række < hight; række++){ //vores forløkke der skal sørge for at y kommer på rette plads
_y=række; //y stiger med én hver gang x er gået fra 0 til 511
for(int kolonne = 0; kolonne < width; kolonne++){ //vores forløkke der sørger for x og index
_x=kolonne; //x stiger med 1 indtil 511 og starter forfra
if(_x == _y){ //sætter intensiteterne ,så billedet består af en skrå linie
arrIn[index]=lightInt; //rimlig lys intensitet
}//end if
else(arrIn[index] = darkInt); //intensitet sort
index++; //index stiger hele tiden med én uanset pixelværdi
}//end for
}//end for
How do I put it in a white box like your code?
for(int række = 0; række < hight; række++){ //vores forløkke der skal sørge for at y kommer på rette plads
_y=række; //y stiger med én hver gang x er gået fra 0 til 511
for(int kolonne = 0; kolonne < width; kolonne++){ //vores forløkke der sørger for x og index
_x=kolonne; //x stiger med 1 indtil 511 og starter forfra
if(_x == _y){ //sætter intensiteterne ,så billedet består af en skrå linie
arrIn[index]=lightInt; //rimlig lys intensitet
}//end if
else(arrIn[index] = darkInt); //intensitet sort
index++; //index stiger hele tiden med én uanset pixelværdi
}//end for
}//end for
How do I put it in a white box like your code?
Hmm, that code looks fine to me. Do you have any idea what x and y arewhen you get the array out of bounds error (using the debugger)?
[ source ]
source code here
[ /source ]
But without the spaces around the square brackets. You can also go to edit my post to see exactly what I wrote (It'll let you view it, but not submit changes)
Quote:
Original post by majak
How do I put it in a white box like your code?
[ source ]
source code here
[ /source ]
But without the spaces around the square brackets. You can also go to edit my post to see exactly what I wrote (It'll let you view it, but not submit changes)
Quote:
Yup, you can fill a texture with your image, then render the texture to a backbuffer using an orthogonal projection matrix. E.g.
*** Source Snippet Removed ***
Later in my project, I will get the intensities (should only be grayscale) realtime, so to fill a texture and render that, wouldn't it take longer time than render it directly?
Quote:If you already have the data in a texture then there's no need to copy it into another texture. My point was that there's no way to give Clear() an array of values or anything to fill the backbuffer with, and you really don't want to be locking the backbuffer to fill it that way (That'll lead to really poor performance).
Original post by majak
Later in my project, I will get the intensities (should only be grayscale) realtime, so to fill a texture and render that, wouldn't it take longer time than render it directly?
Quote:Have you tried adding debug statements (a printf(), or OutputDebugString() or something whenever you loop)? The reason I'm asking this is that if you go out of bounds at e.g. exactly halfway, then that gives us a clue (incremening 32 bits instead of 16, or something like that).
Original post by majak
no..
I don't know when I get the error..
Also, is index actually initialized to something?
Quote:
Original post by Evil Steve
If you already have the data in a texture then there's no need to copy it into another texture. My point was that there's no way to give Clear() an array of values or anything to fill the backbuffer with, and you really don't want to be locking the backbuffer to fill it that way (That'll lead to really poor performance).
I don't have it in a texture, just in an array. When the time comes, I will be getting the data (intensities in unsigned short format (16 bit..)) realtime from outside the program and that's when I'm thinking if there's a way to fill the the backbuffer directly and show it. Instead of filling an array with the data and then show it on top of the backbuffer..
Quote:
Have you tried adding debug statements (a printf(), or OutputDebugString() or something whenever you loop)? The reason I'm asking this is that if you go out of bounds at e.g. exactly halfway, then that gives us a clue (incremening 32 bits instead of 16, or something like that).
Also, is index actually initialized to something?
I don't know how to test where it goes wrong, but I have a output test like this:
char testBuffer[ 1024 ];for( int i = 0; i < index; ++i ){ // index is what you used for reading from the file if(Vertices.color == 65535){ _snprintf( testBuffer, 1023, "Vertex %d: x=%g, y=%g, z=%g, rhw=%g\n", i, Vertices[ i ].x, Vertices[ i ].y, Vertices.z, Vertices.rhw ); OutputDebugString( testBuffer ); }}and that looks fine, don't know where the stack overflow kicks in.. When it does (have tried with 512*512bbp) I get this:
Unhandled exception at 0x00426a25 in Vertices.exe: 0xC00000FD: Stack overflow.
A breakpoint points at:
test dword ptr [ecx],eax ; ...probe it
in the document chkstk.asm
My index is initialized.
[Edited by - majak on March 22, 2005 5:48:44 AM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement