gint color_history_add (const GimpRGB *rgb) { gint shift_begin = -1; gint i, j; g_return_val_if_fail (rgb != NULL, 0); if (! color_history_initialized) color_history_init (); /* is the added color already there? */ for (i = 0; i < COLOR_HISTORY_SIZE; i++) { if (gimp_rgba_distance (&color_history[i], rgb) < 0.0001) { shift_begin = i; goto doit; } } /* if not, are there two equal colors? */ if (shift_begin == -1) { for (i = 0; i < COLOR_HISTORY_SIZE; i++) { for (j = i + 1; j < COLOR_HISTORY_SIZE; j++) { if (gimp_rgba_distance (&color_history[i], &color_history[j]) < 0.0001) { shift_begin = i; goto doit; } } } } /* if not, shift them all */ if (shift_begin == -1) shift_begin = COLOR_HISTORY_SIZE - 1; doit: for (i = shift_begin; i > 0; i--) color_history[i] = color_history[i - 1]; color_history[0] = *rgb; return shift_begin; }
/** * gimp_color_frame_set_color: * @frame: The #GimpColorFrame. * @sample_average: The set @color is the result of averaging * @sample_format: The format of the #GimpDrawable or #GimpImage the @color * was picked from. * @pixel: The raw pixel in @sample_format. * @color: The @color to set. * * Sets the color sample to display in the #GimpColorFrame. if * @sample_average is %TRUE, @pixel represents the sample at the * center of the average area and will not be displayed. **/ void gimp_color_frame_set_color (GimpColorFrame *frame, gboolean sample_average, const Babl *sample_format, gpointer pixel, const GimpRGB *color) { g_return_if_fail (GIMP_IS_COLOR_FRAME (frame)); g_return_if_fail (color != NULL); if (frame->sample_valid && frame->sample_average == sample_average && frame->sample_format == sample_format && gimp_rgba_distance (&frame->color, color) < 0.0001) { frame->color = *color; return; } frame->sample_valid = TRUE; frame->sample_average = sample_average; frame->sample_format = sample_format; frame->color = *color; memcpy (frame->pixel, pixel, babl_format_get_bytes_per_pixel (sample_format)); gimp_color_frame_update (frame); }
static void quick_mask_configure_callback (GtkWidget *dialog, GimpImage *image, GimpChannel *channel, GimpContext *context, const gchar *channel_name, const GimpRGB *channel_color, gboolean save_selection, gboolean channel_visible, gboolean channel_linked, GimpColorTag channel_color_tag, gboolean channel_lock_content, gboolean channel_lock_position, gpointer user_data) { GimpRGB old_color; gimp_image_get_quick_mask_color (image, &old_color); if (gimp_rgba_distance (&old_color, channel_color) > 0.0001) { gimp_image_set_quick_mask_color (image, channel_color); gimp_image_flush (image); } gtk_widget_destroy (dialog); }
static VALUE rb_gimp_rgba_distance (VALUE self, VALUE other) { gdouble result; result = gimp_rgba_distance(rb2GimpRGBPtr(self), rb2GimpRGBPtr(other)); return rb_float_new(result); }
/** * gimp_color_area_set_color: * @area: Pointer to a #GimpColorArea. * @color: Pointer to a #GimpRGB struct that defines the new color. * * Sets @area to a different @color. **/ void gimp_color_area_set_color (GimpColorArea *area, const GimpRGB *color) { g_return_if_fail (GIMP_IS_COLOR_AREA (area)); g_return_if_fail (color != NULL); if (gimp_rgba_distance (&area->color, color) < 0.000001) return; area->color = *color; area->needs_render = TRUE; gtk_widget_queue_draw (GTK_WIDGET (area)); g_object_notify (G_OBJECT (area), "color"); g_signal_emit (area, gimp_color_area_signals[COLOR_CHANGED], 0); }
static void gimp_color_panel_color_changed (GimpColorButton *button) { GimpColorPanel *panel = GIMP_COLOR_PANEL (button); GimpRGB color; if (panel->color_dialog) { GimpRGB dialog_color; gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &color); gimp_color_dialog_get_color (GIMP_COLOR_DIALOG (panel->color_dialog), &dialog_color); if (gimp_rgba_distance (&color, &dialog_color) > 0.00001 || color.a != dialog_color.a) { gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (panel->color_dialog), &color); } } }
static gint dialog (gint32 image_ID, GimpDrawable *drawable) { GtkWidget *dlg; GtkWidget *main_vbox; GtkWidget *vbox; GtkSizeGroup *group; GtkWidget *label; GtkWidget *preview; GtkWidget *button; GtkWidget *width; GtkWidget *space; GtkWidget *offset; GtkWidget *chain_button; GtkWidget *table; GimpUnit unit; gdouble xres; gdouble yres; gboolean run; g_return_val_if_fail (main_dialog == NULL, FALSE); gimp_ui_init (PLUG_IN_BINARY, TRUE); main_dialog = dlg = gimp_dialog_new (_("Grid"), PLUG_IN_ROLE, NULL, 0, gimp_standard_help_func, PLUG_IN_PROC, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gimp_window_set_transient (GTK_WINDOW (dlg)); /* Get the image resolution and unit */ gimp_image_get_resolution (image_ID, &xres, &yres); unit = gimp_image_get_unit (image_ID); main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), main_vbox, TRUE, TRUE, 0); gtk_widget_show (main_vbox); preview = gimp_drawable_preview_new (drawable, NULL); gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0); gtk_widget_show (preview); g_signal_connect (preview, "invalidated", G_CALLBACK (update_preview), drawable); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); /* The width entries */ width = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), width, FALSE, FALSE, 0); gtk_widget_show (width); /* set the unit back to pixels, since most times we will want pixels */ gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (width), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 0, 0.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 1, 0.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_row_spacing (GTK_TABLE (width), 0, 6); gtk_table_set_col_spacings (GTK_TABLE (width), 6); gtk_table_set_col_spacing (GTK_TABLE (width), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 0, grid_cfg.hwidth); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 1, grid_cfg.vwidth); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 2, grid_cfg.iwidth); /* attach labels */ gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Horizontal\nLines"), 0, 1, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Vertical\nLines"), 0, 2, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Intersection"), 0, 3, 0.0); label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Width:"), 1, 0, 0.0); group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); gtk_size_group_add_widget (group, label); g_object_unref (group); /* put a chain_button under the size_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hwidth == grid_cfg.vwidth) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (width), chain_button, 1, 3, 2, 3); gtk_widget_show (chain_button); /* connect to the 'value-changed' signal because we have to take care * of keeping the entries in sync when the chainbutton is active */ g_signal_connect (width, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (width, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* The spacing entries */ space = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), space, FALSE, FALSE, 0); gtk_widget_show (space); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (space), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 0, 1.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 1, 1.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_col_spacings (GTK_TABLE (space), 6); gtk_table_set_col_spacing (GTK_TABLE (space), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 0, grid_cfg.hspace); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 1, grid_cfg.vspace); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 2, grid_cfg.ispace); /* attach labels */ label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (space), _("Spacing:"), 1, 0, 0.0); gtk_size_group_add_widget (group, label); /* put a chain_button under the spacing_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hspace == grid_cfg.vspace) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (space), chain_button, 1, 3, 2, 3); gtk_widget_show (chain_button); /* connect to the 'value-changed' and "unit-changed" signals because * we have to take care of keeping the entries in sync when the * chainbutton is active */ g_signal_connect (space, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect (space, "unit-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (space, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* The offset entries */ offset = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), offset, FALSE, FALSE, 0); gtk_widget_show (offset); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (offset), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 0, 0.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 1, 0.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_col_spacings (GTK_TABLE (offset), 6); gtk_table_set_col_spacing (GTK_TABLE (offset), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 0, grid_cfg.hoffset); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 1, grid_cfg.voffset); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 2, grid_cfg.ioffset); /* attach labels */ label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (offset), _("Offset:"), 1, 0, 0.0); gtk_size_group_add_widget (group, label); /* this is a weird hack: we put a table into the offset table */ table = gtk_table_new (3, 3, FALSE); gtk_table_attach_defaults (GTK_TABLE (offset), table, 1, 4, 2, 3); gtk_table_set_row_spacing (GTK_TABLE (table), 0, 10); gtk_table_set_col_spacing (GTK_TABLE (table), 1, 12); /* put a chain_button under the offset_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hoffset == grid_cfg.voffset) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), chain_button, 0, 2, 0, 1); gtk_widget_show (chain_button); /* connect to the 'value-changed' and "unit-changed" signals because * we have to take care of keeping the entries in sync when the * chainbutton is active */ g_signal_connect (offset, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect (offset, "unit-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (offset, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* put a chain_button under the color_buttons */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (gimp_rgba_distance (&grid_cfg.hcolor, &grid_cfg.vcolor) < 0.0001) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), chain_button, 0, 2, 2, 3); gtk_widget_show (chain_button); /* attach color selectors */ hcolor_button = gimp_color_button_new (_("Horizontal Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.hcolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (hcolor_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), hcolor_button, 0, 1, 1, 2); gtk_widget_show (hcolor_button); g_signal_connect (hcolor_button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.hcolor); g_signal_connect (hcolor_button, "color-changed", G_CALLBACK (color_callback), chain_button); g_signal_connect_swapped (hcolor_button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); vcolor_button = gimp_color_button_new (_("Vertical Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.vcolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (vcolor_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), vcolor_button, 1, 2, 1, 2); gtk_widget_show (vcolor_button); g_signal_connect (vcolor_button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.vcolor); g_signal_connect (vcolor_button, "color-changed", G_CALLBACK (color_callback), chain_button); g_signal_connect_swapped (vcolor_button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); button = gimp_color_button_new (_("Intersection Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.icolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 1, 2); gtk_widget_show (button); g_signal_connect (button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.icolor); g_signal_connect_swapped (button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); gtk_widget_show (table); gtk_widget_show (dlg); g_object_set_data (G_OBJECT (dlg), "width", width); g_object_set_data (G_OBJECT (dlg), "space", space); g_object_set_data (G_OBJECT (dlg), "offset", offset); run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK); if (run) update_values (); gtk_widget_destroy (dlg); return run; }