+ int w = image.GetWidth() ;
+ int h = image.GetHeight();
+ bool bHasMask = image.HasMask();
+ int hotSpotX, hotSpotY;
+ GetHotSpot(image, hotSpotX, hotSpotY);
+ m_refData = new wxCursorRefData;
+ wxImage image_copy(image);
+
+ GdkDisplay* display = gdk_drawable_get_display(wxGetRootWindow()->window);
+ if (gdk_display_supports_cursor_color(display))
+ {
+ if (!image.HasAlpha())
+ {
+ // add alpha, so wxBitmap will convert to pixbuf format
+ image_copy.InitAlpha();
+ }
+ wxBitmap bitmap(image_copy);
+ wxASSERT(bitmap.HasPixbuf());
+ M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf
+ (
+ display,
+ bitmap.GetPixbuf(),
+ hotSpotX, hotSpotY
+ );
+ return;
+ }
+
+ unsigned long keyMaskColor = 0;
+ GdkPixmap* mask;
+ if (bHasMask)
+ {
+ keyMaskColor = wxImageHistogram::MakeKey(
+ image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
+ // get mask before image is modified
+ wxBitmap bitmap(image, 1);
+ mask = bitmap.GetMask()->GetBitmap();
+ g_object_ref(mask);
+ }
+ else
+ {
+ const int size = ((w + 7) / 8) * h;
+ char* bits = new char[size];
+ memset(bits, 0xff, size);
+ mask = gdk_bitmap_create_from_data(
+ wxGetRootWindow()->window, bits, w, h);
+ delete[] bits;
+ }
+
+ // modify image so wxBitmap can be used to convert to pixmap
+ image_copy.SetMask(false);
+ int i, j;
+ wxByte* data = image_copy.GetData();
+ for (j = 0; j < h; j++)
+ {
+ for (i = 0; i < w; i++, data += 3)
+ {
+ //if average value is > mid grey
+ if (int(data[0]) + data[1] + data[2] >= 3 * 128)
+ {
+ // wxBitmap only converts (255,255,255) to white
+ data[0] = 255;
+ data[1] = 255;
+ data[2] = 255;
+ }
+ }
+ }
+ wxBitmap bitmap(image_copy, 1);
+
+ // find the most frequent color(s)
+ wxImageHistogram histogram;
+ image.ComputeHistogram(histogram);
+
+ long colMostFreq = 0;
+ unsigned long nMost = 0;
+ long colNextMostFreq = 0;
+ unsigned long nNext = 0;
+ for ( wxImageHistogram::iterator entry = histogram.begin();
+ entry != histogram.end();
+ ++entry )
+ {
+ unsigned long key = entry->first;
+ if ( !bHasMask || (key != keyMaskColor) )
+ {
+ unsigned long value = entry->second.value;
+ if (value > nMost)
+ {
+ nNext = nMost;
+ colNextMostFreq = colMostFreq;
+ nMost = value;
+ colMostFreq = key;
+ }
+ else if (value > nNext)
+ {
+ nNext = value;
+ colNextMostFreq = key;
+ }
+ }
+ }
+
+ wxColour fg = wxColour ( (unsigned char)(colMostFreq >> 16),
+ (unsigned char)(colMostFreq >> 8),
+ (unsigned char)(colMostFreq) );