+ if (!m_refData) return FALSE;
+
+ int closest = 0;
+ double d,distance = 1000.0; // max. dist is 256
+
+ wxPaletteEntry *e = M_PALETTEDATA->m_entries;
+ for (int i = 0; i < M_PALETTEDATA->m_count; i++, e++)
+ {
+ if ((d = 0.299 * abs(red - e->red) +
+ 0.587 * abs(green - e->green) +
+ 0.114 * abs(blue - e->blue)) < distance) {
+ distance = d;
+ closest = i;
+ }
+ }
+ return closest;