def find_nearest_color_index(r, g, b, color_table=None, method='<STR_LIT>'):
shortest_distance = <NUM_LIT>*<NUM_LIT>*<NUM_LIT:3>  <EOL>index = <NUM_LIT:0>                      <EOL>if not color_table:<EOL><INDENT>if not color_table8:<EOL><INDENT>build_color_tables()<EOL><DEDENT>color_table = color_table8<EOL><DEDENT>for i, values in enumerate(color_table):<EOL><INDENT>rd = r - values[<NUM_LIT:0>]<EOL>gd = g - values[<NUM_LIT:1>]<EOL>bd = b - values[<NUM_LIT:2>]<EOL>this_distance = (rd * rd) + (gd * gd) + (bd * bd)<EOL>if this_distance < shortest_distance:  <EOL><INDENT>index = i<EOL>shortest_distance = this_distance<EOL><DEDENT><DEDENT>return index<EOL>
Given three integers representing R, G, and B,
        return the nearest color index.

        Arguments:
            r:    int - of range 0…255
            g:    int - of range 0…255
            b:    int - of range 0…255

        Returns:
            int, None: index, or None on error.