Lookup-tables for colors?

Started by
2 comments, last by CMN 23 years, 7 months ago
The current method i use for creating a color dword for direct draw is something like this: ((red/dwShadesOfRed) << dwRedBitShift) | ((green/dwShadesOfGreen) << dwGreenBitShift) | ((blue/dwShadesOfBlue) << dwBlueBitShift)) Would it be a good idea to have three pregenerated tables like Color_R[255], Color_G[255], Color_B[255], each containing the bit representation of a color component of that value. And then create colors with: (Color_R[red] | Color_G[green] | Color_B[blue]) Wich would be faster? /CMN Edited by - cmn on 9/2/00 4:16:11 AM Edited by - CMN on 9/2/00 4:17:39 AM
Advertisement
The lookup table would be faster since divisions are slow.

However, if dwShadesOfRed, dwShadesOfGreen, dwShadesOfBlue are powers of 2 (2,4,8,...) you can do the division using a shift and it might be faster than a lookup table.
Thanks for the advice.
As Micheal Abrash said, knowing what to optimize is more important than knowing how to optimize. In this case, processors these days are fast enough to handle, *gasp* divisions. It''s really up to you what you end up doing.

JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911

This topic is closed to new replies.

Advertisement