Thread: GetNearestPaletteIndex too slow

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    26

    GetNearestPaletteIndex too slow

    GetNearestPaletteIndex is very slow, are there any algorithms that i could implement in order to optimize these actions and get the same results as with GetNearestPaletteIndex?

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by baccardi View Post
    GetNearestPaletteIndex is very slow, are there any algorithms that i could implement in order to optimize these actions and get the same results as with GetNearestPaletteIndex?
    Depends how GetNearestPaletteIndex() is implemented, and depends on what the definition of "closest color" is. It might already be as fast as reasonably possible.

    One possible quantization algorithm if you already have a palette, is to represent the palette as an octree (a tree that branches 8 ways). This represents the 8 octants of the 3D colorspace. Each palette color is inserted into this octree by recursively subdividing the parent octant, proceeding until you reach some maximal depth. A good heuristic cutoff is the number of palette entries per leaf.

    Then, to quantize a color, you walk the octree as if you were walking a binary tree, but in this case you are branching 8 ways. When you reach a leaf, find the closest palette color in that leaf and use it.

    But I don't know what Windows does. If Windows is already doing something like this, you aren't going to improve on it that much.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    want to know how i solved the problem? Because i'm going to convert several bitmaps a second (i'm writing desktop viewer) i need to make it fat but program initialization may be slow, so i made a buffer colorTable and put all the indexes representing all the rgb values, colorTable size is 0xFFFFFF so when i need to get a color index from rgb value i just do like this:
    index = colorTable[rgb] and i managed to optimize the conversion from 1,1s to 32 miliseconds. And the program initialization takes about 32 seconds but that's not a big problem because it's done only once

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slow startup
    By Desolation in forum Tech Board
    Replies: 38
    Last Post: 12-27-2008, 07:54 AM
  2. Can someone clarify what a 'slow event' is.
    By Overworked_PhD in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-13-2008, 05:11 PM
  3. slow game
    By lambs4 in forum Game Programming
    Replies: 2
    Last Post: 08-21-2003, 02:08 PM
  4. Solutions for slow performance?
    By Hunter2 in forum Game Programming
    Replies: 52
    Last Post: 08-24-2002, 10:04 AM
  5. slow load of Cprog.com
    By Generator in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-13-2001, 06:31 AM