void threshold_image( Glib::RefPtr<Gdk::Pixbuf>& img, color low, color high, color replace_false, color replace_true, COLOR_SPACE space) { Gdk::Colorspace cspace = img->get_colorspace(); guint8 * pixels = img->get_pixels(); int bits_per_sample = img->get_bits_per_sample(); int n_channels = img->get_n_channels(); bool has_alpha = img->get_has_alpha(); int width = img->get_width(); int height = img->get_height(); int rowstride = img->get_rowstride(); assert(bits_per_sample == 8); assert(cspace == Gdk::COLORSPACE_RGB); //the above should be true for any image... //right now 24/32 bit RGB/RGBA is the only supported color space //todo: make this more pretty! wrapper? guint8 * row = pixels; for (int i = 0; i < height; i++) { guint8 * p = row; for (int j = 0; j < width; j++) { if (is_in_range(p, low, high, space)) { set_color(p, replace_true); } else { set_color(p, replace_false); } p += n_channels; //should be n_channels * bits_per_sample/8 } row += rowstride; } }