Jump to content
  • Advertisement

Archived

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

Guest Anonymous Poster

More DX 16bit queries ... ;)

This topic is 6782 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

Take a look at my homepage......in the article

32,24,16 and 8 bit.....that should explain it all........at least,.....most of it.

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

Share this post


Link to post
Share on other sites
Advertisement
Depending on application, one way you could do this is by creating an index of 0-255 values for Red, Green and Blue. I do this like so:

unsigned short rgb_index[256][3];

Then fill the structure with colour information. The first array index points to the colour amount, the second to the colour itself (R G or B, I use R = 0 G = 1 B = 2, but you could change that if you wanted to). Now, when you want to get a finished colour, you simply say:

color = rgb_index[r_color][0] | rgb_index[g_color][1] | rgb_index[b_color][2];

As I said, there will be situations where you won't want to use this because of the way it works. However, it is one way of doing things that you might want to take a look at.

Good luck

Starfall

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks a lot to you both - You've been a lot of help.

Thanks again,

James

Share this post


Link to post
Share on other sites
Starfall......You should've explained it further how to make the LUT.

Look at

code:
DWORD* Create16bppLUT(DWORD bitMask)
{

DWORD * p_lut = new DWORD[256];
if (p_lut == NULL) return NULL;
for (__int64 i = 0; i < 256; i++)
{

p_lut[i] = DWORD((( i * __int64(bitMask)) / 255) & bitMask);

}
return p_lut;

}


And call this function like:

DWORD *Red;
Red = Create16bppLUT(ddsd.ddpfPixelFormat.dwRBitMask);

after that you can use what you said

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi Cj,

Thanks for the extra code... a couple of things I don't get however Could you explain why you use '__int64' variable type (not sure what this is exactly). Also, why do you malloc the memory at runtime, is this faster than using a play array of say:
WORD r_LUT[256];
?

Anyway, thanks for your help,

James

Share this post


Link to post
Share on other sites
Okay......well.....i use an __int64 for 2 reasons, reason 1 is to have it working on different systems, since an int can be different on every computer. Reason 2 is because of the DWORD the function receives. A DWORD is a 32 bit unsigned integer. So...the values will range exactly the same as __int64. Makes sense? to me it does......I might've been wrong though. Haven't tried it different yet.

And about the memory allocation on run-time. I always do that. It's kinda my behavior. And I find it easier to use a pointer to something instead......

More questions?

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

Share this post


Link to post
Share on other sites
And I find it easier to use a pointer to something instead......

Come again? How's an array like he suggested any different? It's still a pointer, just preallocated for you. In fact, for all intents and purposes exactly the same as using malloc, but with less hassle. I find it far easier to allocate fixed size memory like that, anyway.

Regards

Starfall

Share this post


Link to post
Share on other sites
Above where CJ used a __int64 thats a no-no. The problem is that an int64 is a microsoft specific way to hold a 64 bit integer.... which is completely unnecessary when we deal with 16 bit colors (and probably slow too since intel machines are 32 bit.) Also, I'm not sure that the array produced would be what you desire, although I haven't looked into that very much.

Share this post


Link to post
Share on other sites
To clear some things up. First, your best bet is to use an int, not an __int64. Like someone previously noted, __int64's are a no-no. Definately not ANSI C++ standard. For large integers, an int/long is absolutely fine. However, in this case, if memory serves form looking at that code, our values are ranging from 0 to 255. Use a char.
Second thing...this:

int MyArray[256];

and this:

int *MyArray = (int *)malloc(256 * sizeof(int));
OR
int *MyArray = new int[256];

The last two do exactly the same thing. They are just different versions of each other. However, a pre-allocated array only uses the stack to store the array. Once it's out of scope, the array no longer exists. Using malloc() or new dynamically allocates it, and the memory is available until you call free() or delete[]. Therefore, they are not the same thing.

Share this post


Link to post
Share on other sites
Everybody has another style of coding, and after examining what you said. I agree......

I will always use new and delete functions. Everybody his liking. And......you are right about the __int64 thingy.....just an int works just fine too...........

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!