- unsigned long keyMaskColor = 0;
- GdkPixmap *maskRaw;
- if (bHasMask)
- {
- keyMaskColor = wxImageHistogram::MakeKey(
- image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
- // get mask before image is modified
- wxBitmap bitmap(image, 1);
- maskRaw = bitmap.GetMask()->GetBitmap();
- g_object_ref(maskRaw);
- }
- else
- {
- const int size = ((w + 7) / 8) * h;
- char* bits = new char[size];
- memset(bits, 0xff, size);
- maskRaw = gdk_bitmap_create_from_data(
- gtk_widget_get_window(wxGetRootWindow()), bits, w, h);
- delete[] bits;
- }
-
- // assign the raw pointer to wxGtkObject to ensure it is unref'd later
- wxGtkObject<GdkPixmap> mask(maskRaw);
-
- // modify image so wxBitmap can be used to convert to pixmap
- image_copy.SetMask(false);
- wxByte* data = image_copy.GetData();
- for (int j = 0; j < h; j++)
- {
- for (int i = 0; i < w; i++, data += 3)
- {
- // if average value of the pixel is > mid grey, convert it to
- // background (0), otherwise to foreground (255, using wxBitmap
- // convention)
- data[0] =
- data[1] =
- data[2] = int(data[0]) + data[1] + data[2] >= 3 * 128 ? 0 : 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 )