+ return -1;
+
+ long bestdiff = 3 * 256 ;
+ long bestpos = 0 ;
+ long currentdiff ;
+
+ for ( int i = 0 ; i < M_PALETTEDATA->m_count ; ++i )
+ {
+ const wxColour& col = &M_PALETTEDATA->m_palette[i] ;
+ currentdiff = abs ( col.Red() - red ) + abs( col.Green() - green ) + abs ( col.Blue() - blue ) ;
+ if ( currentdiff < bestdiff )
+ {
+ bestdiff = currentdiff ;
+ bestpos = i ;
+ if ( bestdiff == 0 )
+ break ;
+ }
+ }
+
+ return bestpos;