void gimp_pickable_pixel_to_srgb (GimpPickable *pickable, const Babl *format, gpointer pixel, GimpRGB *color) { GimpPickableInterface *pickable_iface; g_return_if_fail (GIMP_IS_PICKABLE (pickable)); g_return_if_fail (pixel != NULL); g_return_if_fail (color != NULL); if (! format) format = gimp_pickable_get_format (pickable); pickable_iface = GIMP_PICKABLE_GET_INTERFACE (pickable); if (pickable_iface->pixel_to_srgb) { pickable_iface->pixel_to_srgb (pickable, format, pixel, color); } else { gimp_rgba_set_pixel (color, format, pixel); } }
static void transfer_registration_color (GeglBuffer *src, GeglBuffer **dst, gint count) { GimpRGB color, test; GeglBufferIterator *gi; const Babl *src_format, *dst_format; gint i, src_bpp, dst_bpp; gdouble white; gimp_context_get_foreground (&color); white = 1.0; src_format = gegl_buffer_get_format (src); src_bpp = babl_format_get_bytes_per_pixel (src_format); dst_format = gegl_buffer_get_format (dst[0]); dst_bpp = babl_format_get_bytes_per_pixel (dst_format); gi = gegl_buffer_iterator_new (src, NULL, 0, NULL, GEGL_BUFFER_READ, GEGL_ABYSS_NONE); for (i = 0; i < count; i++) { gegl_buffer_iterator_add (gi, dst[i], NULL, 0, NULL, GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE); } while (gegl_buffer_iterator_next (gi)) { guint j, k; gpointer src_data, dst_data[MAX_EXTRACT_IMAGES]; src_data = gi->data[0]; for (j = 0; j < count; j++) dst_data[j] = gi->data[j+1]; for (k = 0; k < gi->length; k++) { gulong pos; pos = k * src_bpp; gimp_rgba_set_pixel (&test, src_format, ((guchar *)src_data) + pos); if (gimp_rgb_distance (&test, &color) < 1e-6) { for (j = 0; j < count; j++) { gpointer data; data = dst_data[j]; babl_process (babl_fish (babl_format ("Y double"), dst_format), &white, (guchar *)data + (k * dst_bpp), 1); } } } } }
gboolean gimp_pickable_get_color_at (GimpPickable *pickable, gint x, gint y, GimpRGB *color) { guchar pixel[32]; g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), FALSE); g_return_val_if_fail (color != NULL, FALSE); if (! gimp_pickable_get_pixel_at (pickable, x, y, NULL, pixel)) return FALSE; gimp_rgba_set_pixel (color, gimp_pickable_get_format (pickable), pixel); return TRUE; }
gboolean gimp_pickable_pick_color (GimpPickable *pickable, gint x, gint y, gboolean sample_average, gdouble average_radius, GimpRGB *color, gint *color_index) { const Babl *format; gdouble pixel[4]; g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), FALSE); format = babl_format ("RGBA double"); if (! gimp_pickable_get_pixel_at (pickable, x, y, format, pixel)) return FALSE; if (sample_average) { gint count = 0; gdouble color_avg[4] = { 0.0, 0.0, 0.0, 0.0 }; gint radius = (gint) average_radius; gint i, j; for (i = x - radius; i <= x + radius; i++) for (j = y - radius; j <= y + radius; j++) if (gimp_pickable_get_pixel_at (pickable, i, j, format, pixel)) { count++; color_avg[RED] += pixel[RED]; color_avg[GREEN] += pixel[GREEN]; color_avg[BLUE] += pixel[BLUE]; color_avg[ALPHA] += pixel[ALPHA]; } pixel[RED] = color_avg[RED] / count; pixel[GREEN] = color_avg[GREEN] / count; pixel[BLUE] = color_avg[BLUE] / count; pixel[ALPHA] = color_avg[ALPHA] / count; } gimp_rgba_set_pixel (color, format, pixel); if (color_index) { format = gimp_pickable_get_format (pickable); if (babl_format_is_palette (format) && ! sample_average) { guchar indexed_pixel[4]; gimp_pickable_get_pixel_at (pickable, x, y, format, indexed_pixel); *color_index = indexed_pixel[0]; } else { *color_index = -1; } } return TRUE; }