Thread: Lookup table with different spacing between entries

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    125

    Lookup table with different spacing between entries

    Here's my problem: I'm trying to write a program to modify gamma corrected images, but the gamma correction (which involves an RGB value, an unsigned char, to the power 2.5, or a gamma corrected value, a double, to the power 0.4) is currently taking most of the time, so I want to patch in a lookup table to speed things up. For exponentiating an unsigned char this is easy because there's only 256 possible values. Converting back can use the same table, but the best I can come up with is looping through the entire table, comparing the input with the values in the table to check what integer value is the correct answer. (luckily it's a monotonously increasing function)
    What would be a quick way to go about this? Is there perhaps a container in the STL that can do something like this?
    Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    It's monotonic, so the data is sorted; why not do binary search?

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    Oops, probably should've figured that out myself...
    Got it to work now, thanks!
    Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick log lookup table
    By R.Stiltskin in forum C++ Programming
    Replies: 19
    Last Post: 12-04-2008, 12:39 PM
  2. search file for values in lookup table
    By sixstringsgaret in forum C Programming
    Replies: 12
    Last Post: 03-04-2008, 04:23 PM
  3. using a shared lookup table
    By zxcv in forum C Programming
    Replies: 1
    Last Post: 02-21-2008, 12:10 AM
  4. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  5. Lookup Table Reference???
    By gvector1 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2003, 05:03 PM