static void gimp_view_renderer_class_init (GimpViewRendererClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); renderer_signals[UPDATE] = g_signal_new ("update", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GimpViewRendererClass, update), NULL, NULL, gimp_marshal_VOID__VOID, G_TYPE_NONE, 0); object_class->dispose = gimp_view_renderer_dispose; object_class->finalize = gimp_view_renderer_finalize; klass->update = NULL; klass->set_context = gimp_view_renderer_real_set_context; klass->invalidate = gimp_view_renderer_real_invalidate; klass->draw = gimp_view_renderer_real_draw; klass->render = gimp_view_renderer_real_render; klass->frame = NULL; klass->frame_left = 0; klass->frame_right = 0; klass->frame_top = 0; klass->frame_bottom = 0; gimp_rgba_set (&black_color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); gimp_rgba_set (&white_color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); gimp_rgba_set (&green_color, 0.0, 0.94, 0.0, GIMP_OPACITY_OPAQUE); gimp_rgba_set (&red_color, 1.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); }
static void gimp_color_button_use_color (GtkAction *action, GimpColorButton *button) { const gchar *name; GimpRGB color; name = gtk_action_get_name (action); gimp_color_button_get_color (button, &color); if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_FG)) { if (_gimp_get_foreground_func) _gimp_get_foreground_func (&color); else gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); } else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BG)) { if (_gimp_get_background_func) _gimp_get_background_func (&color); else gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0); } else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BLACK)) { gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); } else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_WHITE)) { gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0); } gimp_color_button_set_color (button, &color); }
void gimp_foreground_select_options_get_mask_color (GimpForegroundSelectOptions *options, GimpRGB *color) { g_return_if_fail (GIMP_IS_FOREGROUND_SELECT_OPTIONS (options)); g_return_if_fail (color != NULL); switch (options->mask_color) { case GIMP_RED_CHANNEL: gimp_rgba_set (color, 1, 0, 0, 0.7); break; case GIMP_GREEN_CHANNEL: gimp_rgba_set (color, 0, 1, 0, 0.7); break; case GIMP_BLUE_CHANNEL: gimp_rgba_set (color, 0, 0, 1, 0.7); break; case GIMP_GRAY_CHANNEL: gimp_rgba_set (color, 1, 1, 1, 0.7); break; default: g_warn_if_reached (); break; } }
static gboolean gimp_color_panel_button_press (GtkWidget *widget, GdkEventButton *bevent) { if (gdk_event_triggers_context_menu ((GdkEvent *) bevent)) { GimpColorButton *color_button; GimpColorPanel *color_panel; GtkUIManager *ui_manager; GtkActionGroup *group; GtkAction *action; GimpRGB color; color_button = GIMP_COLOR_BUTTON (widget); color_panel = GIMP_COLOR_PANEL (widget); ui_manager = GTK_UI_MANAGER (color_button->popup_menu); group = gtk_ui_manager_get_action_groups (ui_manager)->data; action = gtk_action_group_get_action (group, "color-button-use-foreground"); gtk_action_set_visible (action, color_panel->context != NULL); action = gtk_action_group_get_action (group, "color-button-use-background"); gtk_action_set_visible (action, color_panel->context != NULL); if (color_panel->context) { action = gtk_action_group_get_action (group, "color-button-use-foreground"); gimp_context_get_foreground (color_panel->context, &color); g_object_set (action, "color", &color, NULL); action = gtk_action_group_get_action (group, "color-button-use-background"); gimp_context_get_background (color_panel->context, &color); g_object_set (action, "color", &color, NULL); } action = gtk_action_group_get_action (group, "color-button-use-black"); gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); g_object_set (action, "color", &color, NULL); action = gtk_action_group_get_action (group, "color-button-use-white"); gimp_rgba_set (&color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); g_object_set (action, "color", &color, NULL); } if (GTK_WIDGET_CLASS (parent_class)->button_press_event) return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent); return FALSE; }
gboolean gimp_get_fill_params (GimpContext *context, GimpFillType fill_type, GimpRGB *color, GimpPattern **pattern, GError **error) { g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE); g_return_val_if_fail (color != NULL, FALSE); g_return_val_if_fail (pattern != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); *pattern = NULL; switch (fill_type) { case GIMP_FILL_FOREGROUND: gimp_context_get_foreground (context, color); break; case GIMP_FILL_BACKGROUND: gimp_context_get_background (context, color); break; case GIMP_FILL_WHITE: gimp_rgba_set (color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); break; case GIMP_FILL_TRANSPARENT: gimp_rgba_set (color, 0.0, 0.0, 0.0, GIMP_OPACITY_TRANSPARENT); break; case GIMP_FILL_PATTERN: *pattern = gimp_context_get_pattern (context); if (! *pattern) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("No patterns available for this operation.")); return FALSE; } break; default: g_warning ("%s: invalid fill_type %d", G_STRFUNC, fill_type); return FALSE; } return TRUE; }
static void gimp_color_area_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time) { GimpColorArea *area = GIMP_COLOR_AREA (widget); GimpRGB color; guint16 *vals; if (selection_data->length < 0) return; if ((selection_data->format != 16) || (selection_data->length != 8)) { g_warning ("Received invalid color data"); return; } vals = (guint16 *)selection_data->data; gimp_rgba_set (&color, (gdouble) vals[0] / 0xffff, (gdouble) vals[1] / 0xffff, (gdouble) vals[2] / 0xffff, (gdouble) vals[3] / 0xffff); gimp_color_area_set_color (area, &color); }
static void gimp_color_area_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time) { GimpColorArea *area = GIMP_COLOR_AREA (widget); const guint16 *vals; GimpRGB color; if (gtk_selection_data_get_length (selection_data) != 8 || gtk_selection_data_get_format (selection_data) != 16) { g_warning ("%s: received invalid color data", G_STRFUNC); return; } vals = (const guint16 *) gtk_selection_data_get_data (selection_data); gimp_rgba_set (&color, (gdouble) vals[0] / 0xffff, (gdouble) vals[1] / 0xffff, (gdouble) vals[2] / 0xffff, (gdouble) vals[3] / 0xffff); gimp_color_area_set_color (area, &color); }
gint image_setup (GimpDrawable *drawable, gint interactive) { /* Set the tile cache size */ /* ======================= */ gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width() - 1) / gimp_tile_width ()); /* Get some useful info on the input drawable */ /* ========================================== */ input_drawable = drawable; output_drawable = drawable; if (! gimp_drawable_mask_intersect (drawable->drawable_id, &border_x, &border_y, &border_w, &border_h)) return FALSE; width = input_drawable->width; height = input_drawable->height; gimp_pixel_rgn_init (&source_region, input_drawable, 0, 0, width, height, FALSE, FALSE); maxcounter = (glong) width * (glong) height; if (mapvals.transparent_background == TRUE) { gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0); } else { gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 1.0); } /* Assume at least RGB */ /* =================== */ in_channels = 3; if (gimp_drawable_has_alpha (input_drawable->drawable_id) == TRUE) in_channels++; if (interactive == TRUE) { preview_rgb_stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, PREVIEW_WIDTH); preview_rgb_data = g_new0 (guchar, preview_rgb_stride * PREVIEW_HEIGHT); preview_surface = cairo_image_surface_create_for_data (preview_rgb_data, CAIRO_FORMAT_RGB24, PREVIEW_WIDTH, PREVIEW_HEIGHT, preview_rgb_stride); } return TRUE; }
static void gimp_container_grid_view_class_init (GimpContainerGridViewClass *klass) { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkBindingSet *binding_set; binding_set = gtk_binding_set_by_class (klass); widget_class->focus = gimp_container_grid_view_focus; widget_class->popup_menu = gimp_container_grid_view_popup_menu; klass->move_cursor = gimp_container_grid_view_move_cursor; grid_view_signals[MOVE_CURSOR] = g_signal_new ("move-cursor", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GimpContainerGridViewClass, move_cursor), NULL, NULL, gimp_marshal_BOOLEAN__ENUM_INT, G_TYPE_BOOLEAN, 2, GTK_TYPE_MOVEMENT_STEP, G_TYPE_INT); gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0, "move-cursor", 2, G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS, G_TYPE_INT, -1); gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0, "move-cursor", 2, G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS, G_TYPE_INT, 1); gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Up, 0, "move-cursor", 2, G_TYPE_ENUM, GTK_MOVEMENT_PAGES, G_TYPE_INT, -1); gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Down, 0, "move-cursor", 2, G_TYPE_ENUM, GTK_MOVEMENT_PAGES, G_TYPE_INT, 1); gimp_rgba_set (&white_color, 1.0, 1.0, 1.0, 1.0); gimp_rgba_set (&black_color, 0.0, 0.0, 0.0, 1.0); }
static void color_history_init (void) { gint i; for (i = 0; i < COLOR_HISTORY_SIZE; i++) gimp_rgba_set (&color_history[i], 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); color_history_initialized = TRUE; }
static void gimp_palette_view_drag_color (GtkWidget *widget, GimpRGB *color, gpointer data) { GimpPaletteView *view = GIMP_PALETTE_VIEW (data); if (view->dnd_entry) *color = view->dnd_entry->color; else gimp_rgba_set (color, 0.0, 0.0, 0.0, 1.0); }
void gimp_value_get_rgb (const GValue *value, GimpRGB *rgb) { g_return_if_fail (GIMP_VALUE_HOLDS_RGB (value)); g_return_if_fail (rgb != NULL); if (value->data[0].v_pointer) *rgb = *((GimpRGB *) value->data[0].v_pointer); else gimp_rgba_set (rgb, 0.0, 0.0, 0.0, 1.0); }
gint image_setup (GimpDrawable *drawable, gint interactive) { /* Set the tile cache size */ /* ======================= */ gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width() - 1) / gimp_tile_width ()); /* Get some useful info on the input drawable */ /* ========================================== */ input_drawable = drawable; output_drawable = drawable; gimp_drawable_mask_bounds (drawable->drawable_id, &border_x1, &border_y1, &border_x2, &border_y2); width = input_drawable->width; height = input_drawable->height; gimp_pixel_rgn_init (&source_region, input_drawable, 0, 0, width, height, FALSE, FALSE); maxcounter = (glong) width * (glong) height; if (mapvals.transparent_background == TRUE) { gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0); } else { gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 1.0); } /* Assume at least RGB */ /* =================== */ in_channels = 3; if (gimp_drawable_has_alpha (input_drawable->drawable_id) == TRUE) in_channels++; if (interactive == TRUE) { preview_rgb_data = g_new0 (guchar, PREVIEW_HEIGHT * PREVIEW_WIDTH * 3); } return TRUE; }
static void set_default_settings (void) { gint i; gimp_vector3_set (&mapvals.viewpoint, 0.5, 0.5, 2.0); gimp_vector3_set (&mapvals.firstaxis, 1.0, 0.0, 0.0); gimp_vector3_set (&mapvals.secondaxis, 0.0, 1.0, 0.0); gimp_vector3_set (&mapvals.normal, 0.0, 0.0, 1.0); gimp_vector3_set (&mapvals.position, 0.5, 0.5, 0.0); gimp_vector3_set (&mapvals.lightsource.position, -0.5, -0.5, 2.0); gimp_vector3_set (&mapvals.lightsource.direction, -1.0, -1.0, 1.0); gimp_vector3_set (&mapvals.scale, 0.5, 0.5, 0.5); mapvals.maptype = MAP_PLANE; mapvals.pixeltreshold = 0.25; mapvals.alpha = 0.0; mapvals.beta = 0.0; mapvals.gamma = 0.0; mapvals.maxdepth = 3.0; mapvals.radius = 0.25; mapvals.cylinder_radius = 0.25; mapvals.cylinder_length = 1.0; mapvals.zoom = 1.0; mapvals.lightsource.type = POINT_LIGHT; mapvals.antialiasing = TRUE; mapvals.create_new_image = FALSE; mapvals.create_new_layer = FALSE; mapvals.transparent_background = FALSE; mapvals.tiled = FALSE; mapvals.livepreview = FALSE; mapvals.showgrid = TRUE; mapvals.lightsource.intensity = 1.0; gimp_rgba_set (&mapvals.lightsource.color, 1.0, 1.0, 1.0, 1.0); mapvals.material.ambient_int = 0.3; mapvals.material.diffuse_int = 1.0; mapvals.material.diffuse_ref = 0.5; mapvals.material.specular_ref = 0.5; mapvals.material.highlight = 27.0; for (i = 0; i < 6; i++) mapvals.boxmap_id[i] = -1; for (i = 0; i < 2; i++) mapvals.cylindermap_id[i] = -1; }
static void gimp_color_selector_init (GimpColorSelector *selector) { selector->toggles_visible = TRUE; selector->toggles_sensitive = TRUE; selector->show_alpha = TRUE; gtk_orientable_set_orientation (GTK_ORIENTABLE (selector), GTK_ORIENTATION_VERTICAL); gimp_rgba_set (&selector->rgb, 0.0, 0.0, 0.0, 1.0); gimp_rgb_to_hsv (&selector->rgb, &selector->hsv); selector->channel = GIMP_COLOR_SELECTOR_HUE; }
static void gimp_action_class_init (GimpActionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkActionClass *action_class = GTK_ACTION_CLASS (klass); GimpRGB black; object_class->constructed = gimp_action_constructed; object_class->finalize = gimp_action_finalize; object_class->set_property = gimp_action_set_property; object_class->get_property = gimp_action_get_property; action_class->connect_proxy = gimp_action_connect_proxy; gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); g_object_class_install_property (object_class, PROP_CONTEXT, g_param_spec_object ("context", NULL, NULL, GIMP_TYPE_CONTEXT, GIMP_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_COLOR, gimp_param_spec_rgb ("color", NULL, NULL, TRUE, &black, GIMP_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_VIEWABLE, g_param_spec_object ("viewable", NULL, NULL, GIMP_TYPE_VIEWABLE, GIMP_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_ELLIPSIZE, g_param_spec_enum ("ellipsize", NULL, NULL, PANGO_TYPE_ELLIPSIZE_MODE, PANGO_ELLIPSIZE_NONE, GIMP_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_MAX_WIDTH_CHARS, g_param_spec_int ("max-width-chars", NULL, NULL, -1, G_MAXINT, -1, GIMP_PARAM_READWRITE)); }
static VALUE rb_gimp_rgba_set (VALUE self, VALUE r, VALUE g, VALUE b, VALUE a) { Get_TypedStruct(self, GimpRGB, color); gimp_rgba_set(color, (gdouble)NUM2DBL(r), (gdouble)NUM2DBL(g), (gdouble)NUM2DBL(b), (gdouble)NUM2DBL(a)); return rb_ary_new3(4, r, g, b, a); }
void set_background_callback (GimpColorButton *button, gpointer data) { GimpRGB color2; Style *current_style; if (gfig_context->debug_styles) g_printerr ("Setting background color from color selector\n"); current_style = gfig_context_get_current_style (); gimp_color_button_get_color (button, &color2); gimp_rgba_set (¤t_style->background, color2.r, color2.g, color2.b, color2.a); gfig_paint_callback (); }
static void gimp_text_style_editor_set_color (GimpTextStyleEditor *editor, GtkTextTag *color_tag) { GimpRGB color; gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); if (color_tag) gimp_text_tag_get_color (color_tag, &color); g_signal_handlers_block_by_func (editor->color_button, gimp_text_style_editor_color_changed, editor); gimp_color_button_set_color (GIMP_COLOR_BUTTON (editor->color_button), &color); g_signal_handlers_unblock_by_func (editor->color_button, gimp_text_style_editor_color_changed, editor); }
static void gimp_text_style_editor_init (GimpTextStyleEditor *editor) { GtkWidget *image; GimpRGB color; gtk_orientable_set_orientation (GTK_ORIENTABLE (editor), GTK_ORIENTATION_VERTICAL); gtk_box_set_spacing (GTK_BOX (editor), 2); /* upper row */ editor->upper_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); gtk_box_pack_start (GTK_BOX (editor), editor->upper_hbox, FALSE, FALSE, 0); gtk_widget_show (editor->upper_hbox); editor->font_entry = gimp_container_entry_new (NULL, NULL, GIMP_VIEW_SIZE_SMALL, 1); gtk_box_pack_start (GTK_BOX (editor->upper_hbox), editor->font_entry, FALSE, FALSE, 0); gtk_widget_show (editor->font_entry); gimp_help_set_help_data (editor->font_entry, _("Change font of selected text"), NULL); editor->size_entry = gimp_size_entry_new (1, 0, "%a", TRUE, FALSE, FALSE, 10, GIMP_SIZE_ENTRY_UPDATE_SIZE); gtk_table_set_col_spacing (GTK_TABLE (editor->size_entry), 1, 0); gtk_box_pack_start (GTK_BOX (editor->upper_hbox), editor->size_entry, FALSE, FALSE, 0); gtk_widget_show (editor->size_entry); gimp_help_set_help_data (editor->size_entry, _("Change size of selected text"), NULL); g_signal_connect (editor->size_entry, "value-changed", G_CALLBACK (gimp_text_style_editor_size_changed), editor); /* lower row */ editor->lower_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); gtk_box_pack_start (GTK_BOX (editor), editor->lower_hbox, FALSE, FALSE, 0); gtk_widget_show (editor->lower_hbox); editor->clear_button = gtk_button_new (); gtk_widget_set_can_focus (editor->clear_button, FALSE); gtk_box_pack_start (GTK_BOX (editor->lower_hbox), editor->clear_button, FALSE, FALSE, 0); gtk_widget_show (editor->clear_button); gimp_help_set_help_data (editor->clear_button, _("Clear style of selected text"), NULL); g_signal_connect (editor->clear_button, "clicked", G_CALLBACK (gimp_text_style_editor_clear_tags), editor); image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU); gtk_container_add (GTK_CONTAINER (editor->clear_button), image); gtk_widget_show (image); gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); editor->color_button = gimp_color_panel_new (_("Change color of selected text"), &color, GIMP_COLOR_AREA_FLAT, 20, 20); gtk_box_pack_end (GTK_BOX (editor->lower_hbox), editor->color_button, FALSE, FALSE, 0); gtk_widget_show (editor->color_button); gimp_help_set_help_data (editor->color_button, _("Change color of selected text"), NULL); g_signal_connect (editor->color_button, "color-changed", G_CALLBACK (gimp_text_style_editor_color_changed), editor); editor->kerning_adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -1000.0, 1000.0, 1.0, 10.0, 0.0)); editor->kerning_spinbutton = gtk_spin_button_new (editor->kerning_adjustment, 1.0, 1); gtk_entry_set_width_chars (GTK_ENTRY (editor->kerning_spinbutton), 5); gtk_box_pack_end (GTK_BOX (editor->lower_hbox), editor->kerning_spinbutton, FALSE, FALSE, 0); gtk_widget_show (editor->kerning_spinbutton); gimp_help_set_help_data (editor->kerning_spinbutton, _("Change kerning of selected text"), NULL); g_signal_connect (editor->kerning_adjustment, "value-changed", G_CALLBACK (gimp_text_style_editor_kerning_changed), editor); editor->baseline_adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -1000.0, 1000.0, 1.0, 10.0, 0.0)); editor->baseline_spinbutton = gtk_spin_button_new (editor->baseline_adjustment, 1.0, 1); gtk_entry_set_width_chars (GTK_ENTRY (editor->baseline_spinbutton), 5); gtk_box_pack_end (GTK_BOX (editor->lower_hbox), editor->baseline_spinbutton, FALSE, FALSE, 0); gtk_widget_show (editor->baseline_spinbutton); gimp_help_set_help_data (editor->baseline_spinbutton, _("Change baseline of selected text"), NULL); g_signal_connect (editor->baseline_adjustment, "value-changed", G_CALLBACK (gimp_text_style_editor_baseline_changed), editor); }
static void gimp_color_frame_init (GimpColorFrame *frame) { GtkWidget *vbox; GtkWidget *vbox2; gint i; frame->sample_valid = FALSE; frame->sample_format = babl_format ("R'G'B' u8"); gimp_rgba_set (&frame->color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); frame->menu = gimp_enum_combo_box_new (GIMP_TYPE_COLOR_FRAME_MODE); gtk_frame_set_label_widget (GTK_FRAME (frame), frame->menu); gtk_widget_show (frame->menu); g_signal_connect (frame->menu, "changed", G_CALLBACK (gimp_color_frame_menu_callback), frame); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); frame->color_area = g_object_new (GIMP_TYPE_COLOR_AREA, "color", &frame->color, "type", GIMP_COLOR_AREA_SMALL_CHECKS, "drag-mask", GDK_BUTTON1_MASK, "draw-border", TRUE, "height-request", 20, NULL); gtk_box_pack_start (GTK_BOX (vbox), frame->color_area, FALSE, FALSE, 0); vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_box_set_homogeneous (GTK_BOX (vbox2), TRUE); gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0); gtk_widget_show (vbox2); for (i = 0; i < GIMP_COLOR_FRAME_ROWS; i++) { GtkWidget *hbox; hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); frame->name_labels[i] = gtk_label_new (" "); gtk_label_set_xalign (GTK_LABEL (frame->name_labels[i]), 0.0); gtk_box_pack_start (GTK_BOX (hbox), frame->name_labels[i], FALSE, FALSE, 0); gtk_widget_show (frame->name_labels[i]); frame->value_labels[i] = gtk_label_new (" "); gtk_label_set_selectable (GTK_LABEL (frame->value_labels[i]), TRUE); gtk_label_set_xalign (GTK_LABEL (frame->value_labels[i]), 1.0); gtk_box_pack_end (GTK_BOX (hbox), frame->value_labels[i], FALSE, FALSE, 0); gtk_widget_show (frame->value_labels[i]); } }
GeglBuffer * gimp_drawable_transform_buffer_flip (GimpDrawable *drawable, GimpContext *context, GeglBuffer *orig_buffer, gint orig_offset_x, gint orig_offset_y, GimpOrientationType flip_type, gdouble axis, gboolean clip_result, GimpColorProfile **buffer_profile, gint *new_offset_x, gint *new_offset_y) { const Babl *format; GeglBuffer *new_buffer; GeglBufferIterator *iter; GeglRectangle src_rect; GeglRectangle dest_rect; gint bpp; gint orig_x, orig_y; gint orig_width, orig_height; gint new_x, new_y; gint new_width, new_height; gint x, y; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GEGL_IS_BUFFER (orig_buffer), NULL); g_return_val_if_fail (buffer_profile != NULL, NULL); g_return_val_if_fail (new_offset_x != NULL, NULL); g_return_val_if_fail (new_offset_y != NULL, NULL); *buffer_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (drawable)); orig_x = orig_offset_x; orig_y = orig_offset_y; orig_width = gegl_buffer_get_width (orig_buffer); orig_height = gegl_buffer_get_height (orig_buffer); new_x = orig_x; new_y = orig_y; new_width = orig_width; new_height = orig_height; switch (flip_type) { case GIMP_ORIENTATION_HORIZONTAL: new_x = RINT (-((gdouble) orig_x + (gdouble) orig_width - axis) + axis); break; case GIMP_ORIENTATION_VERTICAL: new_y = RINT (-((gdouble) orig_y + (gdouble) orig_height - axis) + axis); break; case GIMP_ORIENTATION_UNKNOWN: g_return_val_if_reached (NULL); break; } format = gegl_buffer_get_format (orig_buffer); bpp = babl_format_get_bytes_per_pixel (format); new_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, new_width, new_height), format); if (clip_result && (new_x != orig_x || new_y != orig_y)) { GimpRGB bg; GeglColor *color; gint clip_x, clip_y; gint clip_width, clip_height; *new_offset_x = orig_x; *new_offset_y = orig_y; /* Use transparency, rather than the bg color, as the "outside" color of * channels, and drawables with an alpha channel. */ if (GIMP_IS_CHANNEL (drawable) || babl_format_has_alpha (format)) { gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0); } else { gimp_context_get_background (context, &bg); gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable), &bg, &bg); } color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable)); gegl_buffer_set_color (new_buffer, NULL, color); g_object_unref (color); if (gimp_rectangle_intersect (orig_x, orig_y, orig_width, orig_height, new_x, new_y, new_width, new_height, &clip_x, &clip_y, &clip_width, &clip_height)) { orig_x = new_x = clip_x - orig_x; orig_y = new_y = clip_y - orig_y; } orig_width = new_width = clip_width; orig_height = new_height = clip_height; } else { *new_offset_x = new_x; *new_offset_y = new_y; orig_x = 0; orig_y = 0; new_x = 0; new_y = 0; } if (new_width == 0 && new_height == 0) return new_buffer; dest_rect.x = new_x; dest_rect.y = new_y; dest_rect.width = new_width; dest_rect.height = new_height; iter = gegl_buffer_iterator_new (new_buffer, &dest_rect, 0, NULL, GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE, 1); switch (flip_type) { case GIMP_ORIENTATION_HORIZONTAL: while (gegl_buffer_iterator_next (iter)) { gint stride = iter->items[0].roi.width * bpp; src_rect = iter->items[0].roi; src_rect.x = (orig_x + orig_width) - (iter->items[0].roi.x - dest_rect.x) - iter->items[0].roi.width; gegl_buffer_get (orig_buffer, &src_rect, 1.0, NULL, iter->items[0].data, stride, GEGL_ABYSS_NONE); for (y = 0; y < iter->items[0].roi.height; y++) { guint8 *left = iter->items[0].data; guint8 *right = iter->items[0].data; left += y * stride; right += y * stride + (iter->items[0].roi.width - 1) * bpp; for (x = 0; x < iter->items[0].roi.width / 2; x++) { guint8 temp[bpp]; memcpy (temp, left, bpp); memcpy (left, right, bpp); memcpy (right, temp, bpp); left += bpp; right -= bpp; } } } break; case GIMP_ORIENTATION_VERTICAL: while (gegl_buffer_iterator_next (iter)) { gint stride = iter->items[0].roi.width * bpp; src_rect = iter->items[0].roi; src_rect.y = (orig_y + orig_height) - (iter->items[0].roi.y - dest_rect.y) - iter->items[0].roi.height; gegl_buffer_get (orig_buffer, &src_rect, 1.0, NULL, iter->items[0].data, stride, GEGL_ABYSS_NONE); for (x = 0; x < iter->items[0].roi.width; x++) { guint8 *top = iter->items[0].data; guint8 *bottom = iter->items[0].data; top += x * bpp; bottom += x * bpp + (iter->items[0].roi.height - 1) * stride; for (y = 0; y < iter->items[0].roi.height / 2; y++) { guint8 temp[bpp]; memcpy (temp, top, bpp); memcpy (top, bottom, bpp); memcpy (bottom, temp, bpp); top += stride; bottom -= stride; } } } break; case GIMP_ORIENTATION_UNKNOWN: gegl_buffer_iterator_stop (iter); break; } return new_buffer; }
static void gimp_text_class_init (GimpTextClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass); GimpRGB black; GimpMatrix2 identity; gchar *language; text_signals[CHANGED] = g_signal_new ("changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GimpTextClass, changed), NULL, NULL, gimp_marshal_VOID__VOID, G_TYPE_NONE, 0); object_class->finalize = gimp_text_finalize; object_class->get_property = gimp_text_get_property; object_class->set_property = gimp_text_set_property; object_class->dispatch_properties_changed = gimp_text_dispatch_properties_changed; gimp_object_class->get_memsize = gimp_text_get_memsize; gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); gimp_matrix2_identity (&identity); GIMP_CONFIG_PROP_STRING (object_class, PROP_TEXT, "text", NULL, NULL, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_STRING (object_class, PROP_MARKUP, "markup", NULL, NULL, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_STRING (object_class, PROP_FONT, "font", NULL, NULL, "Sans-serif", GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_FONT_SIZE, "font-size", NULL, NULL, 0.0, 8192.0, 24.0, GIMP_PARAM_STATIC_STRINGS); /* We use the name "font-size-unit" for backward compatibility. * The unit is also used for other sizes in the text object. */ GIMP_CONFIG_PROP_UNIT (object_class, PROP_UNIT, "font-size-unit", NULL, NULL, TRUE, FALSE, GIMP_UNIT_PIXEL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_ANTIALIAS, "antialias", NULL, NULL, TRUE, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_HINT_STYLE, "hint-style", NULL, NULL, GIMP_TYPE_TEXT_HINT_STYLE, GIMP_TEXT_HINT_STYLE_MEDIUM, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_KERNING, "kerning", NULL, NULL, FALSE, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); language = gimp_get_default_language (NULL); GIMP_CONFIG_PROP_STRING (object_class, PROP_LANGUAGE, "language", NULL, NULL, language, GIMP_PARAM_STATIC_STRINGS); g_free (language); GIMP_CONFIG_PROP_ENUM (object_class, PROP_BASE_DIR, "base-direction", NULL, NULL, GIMP_TYPE_TEXT_DIRECTION, GIMP_TEXT_DIRECTION_LTR, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_RGB (object_class, PROP_COLOR, "color", NULL, NULL, FALSE, &black, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_OUTLINE, "outline", NULL, NULL, GIMP_TYPE_TEXT_OUTLINE, GIMP_TEXT_OUTLINE_NONE, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_JUSTIFICATION, "justify", NULL, NULL, GIMP_TYPE_TEXT_JUSTIFICATION, GIMP_TEXT_JUSTIFY_LEFT, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_INDENTATION, "indent", NULL, NULL, -8192.0, 8192.0, 0.0, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_LINE_SPACING, "line-spacing", NULL, NULL, -8192.0, 8192.0, 0.0, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_LETTER_SPACING, "letter-spacing", NULL, NULL, -8192.0, 8192.0, 0.0, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_BOX_MODE, "box-mode", NULL, NULL, GIMP_TYPE_TEXT_BOX_MODE, GIMP_TEXT_BOX_DYNAMIC, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BOX_WIDTH, "box-width", NULL, NULL, 0.0, GIMP_MAX_IMAGE_SIZE, 0.0, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_BOX_HEIGHT, "box-height", NULL, NULL, 0.0, GIMP_MAX_IMAGE_SIZE, 0.0, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_UNIT (object_class, PROP_BOX_UNIT, "box-unit", NULL, NULL, TRUE, FALSE, GIMP_UNIT_PIXEL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_MATRIX2 (object_class, PROP_TRANSFORMATION, "transformation", NULL, NULL, &identity, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_OFFSET_X, "offset-x", NULL, NULL, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_OFFSET_Y, "offset-y", NULL, NULL, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_DEFAULTS); /* border does only exist to implement the old text API */ g_object_class_install_property (object_class, PROP_BORDER, g_param_spec_int ("border", NULL, NULL, 0, GIMP_MAX_IMAGE_SIZE, 0, G_PARAM_CONSTRUCT | GIMP_PARAM_WRITABLE)); /* the old hinting options have been replaced by 'hint-style' */ GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_HINTING, "hinting", NULL, NULL, TRUE, GIMP_PARAM_STATIC_STRINGS); }
GeglBuffer * gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, GimpContext *context, GeglBuffer *orig_buffer, gint orig_offset_x, gint orig_offset_y, GimpRotationType rotate_type, gdouble center_x, gdouble center_y, gboolean clip_result, GimpColorProfile **buffer_profile, gint *new_offset_x, gint *new_offset_y) { const Babl *format; GeglBuffer *new_buffer; GeglRectangle src_rect; GeglRectangle dest_rect; gint orig_x, orig_y; gint orig_width, orig_height; gint orig_bpp; gint new_x, new_y; gint new_width, new_height; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GEGL_IS_BUFFER (orig_buffer), NULL); g_return_val_if_fail (buffer_profile != NULL, NULL); g_return_val_if_fail (new_offset_x != NULL, NULL); g_return_val_if_fail (new_offset_y != NULL, NULL); *buffer_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (drawable)); orig_x = orig_offset_x; orig_y = orig_offset_y; orig_width = gegl_buffer_get_width (orig_buffer); orig_height = gegl_buffer_get_height (orig_buffer); orig_bpp = babl_format_get_bytes_per_pixel (gegl_buffer_get_format (orig_buffer)); switch (rotate_type) { case GIMP_ROTATE_90: gimp_drawable_transform_rotate_point (orig_x, orig_y + orig_height, rotate_type, center_x, center_y, &new_x, &new_y); new_width = orig_height; new_height = orig_width; break; case GIMP_ROTATE_180: gimp_drawable_transform_rotate_point (orig_x + orig_width, orig_y + orig_height, rotate_type, center_x, center_y, &new_x, &new_y); new_width = orig_width; new_height = orig_height; break; case GIMP_ROTATE_270: gimp_drawable_transform_rotate_point (orig_x + orig_width, orig_y, rotate_type, center_x, center_y, &new_x, &new_y); new_width = orig_height; new_height = orig_width; break; default: g_return_val_if_reached (NULL); break; } format = gegl_buffer_get_format (orig_buffer); if (clip_result && (new_x != orig_x || new_y != orig_y || new_width != orig_width || new_height != orig_height)) { GimpRGB bg; GeglColor *color; gint clip_x, clip_y; gint clip_width, clip_height; new_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, orig_width, orig_height), format); *new_offset_x = orig_x; *new_offset_y = orig_y; /* Use transparency, rather than the bg color, as the "outside" color of * channels, and drawables with an alpha channel. */ if (GIMP_IS_CHANNEL (drawable) || babl_format_has_alpha (format)) { gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0); } else { gimp_context_get_background (context, &bg); gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable), &bg, &bg); } color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable)); gegl_buffer_set_color (new_buffer, NULL, color); g_object_unref (color); if (gimp_rectangle_intersect (orig_x, orig_y, orig_width, orig_height, new_x, new_y, new_width, new_height, &clip_x, &clip_y, &clip_width, &clip_height)) { gint saved_orig_x = orig_x; gint saved_orig_y = orig_y; new_x = clip_x - orig_x; new_y = clip_y - orig_y; switch (rotate_type) { case GIMP_ROTATE_90: gimp_drawable_transform_rotate_point (clip_x + clip_width, clip_y, GIMP_ROTATE_270, center_x, center_y, &orig_x, &orig_y); orig_x -= saved_orig_x; orig_y -= saved_orig_y; orig_width = clip_height; orig_height = clip_width; break; case GIMP_ROTATE_180: orig_x = clip_x - orig_x; orig_y = clip_y - orig_y; orig_width = clip_width; orig_height = clip_height; break; case GIMP_ROTATE_270: gimp_drawable_transform_rotate_point (clip_x, clip_y + clip_height, GIMP_ROTATE_90, center_x, center_y, &orig_x, &orig_y); orig_x -= saved_orig_x; orig_y -= saved_orig_y; orig_width = clip_height; orig_height = clip_width; break; } new_width = clip_width; new_height = clip_height; } else { new_width = 0; new_height = 0; } } else { new_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, new_width, new_height), format); *new_offset_x = new_x; *new_offset_y = new_y; orig_x = 0; orig_y = 0; new_x = 0; new_y = 0; } if (new_width < 1 || new_height < 1) return new_buffer; src_rect.x = orig_x; src_rect.y = orig_y; src_rect.width = orig_width; src_rect.height = orig_height; dest_rect.x = new_x; dest_rect.y = new_y; dest_rect.width = new_width; dest_rect.height = new_height; switch (rotate_type) { case GIMP_ROTATE_90: { guchar *buf = g_new (guchar, new_height * orig_bpp); gint i; /* Not cool, we leak memory if we return, but anyway that is * never supposed to happen. If we see this warning, a bug has * to be fixed! */ g_return_val_if_fail (new_height == orig_width, NULL); src_rect.y = orig_y + orig_height - 1; src_rect.height = 1; dest_rect.x = new_x; dest_rect.width = 1; for (i = 0; i < orig_height; i++) { src_rect.y = orig_y + orig_height - 1 - i; dest_rect.x = new_x + i; gegl_buffer_get (orig_buffer, &src_rect, 1.0, NULL, buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); gegl_buffer_set (new_buffer, &dest_rect, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE); } g_free (buf); } break; case GIMP_ROTATE_180: { guchar *buf = g_new (guchar, new_width * orig_bpp); gint i, j, k; /* Not cool, we leak memory if we return, but anyway that is * never supposed to happen. If we see this warning, a bug has * to be fixed! */ g_return_val_if_fail (new_width == orig_width, NULL); src_rect.y = orig_y + orig_height - 1; src_rect.height = 1; dest_rect.y = new_y; dest_rect.height = 1; for (i = 0; i < orig_height; i++) { src_rect.y = orig_y + orig_height - 1 - i; dest_rect.y = new_y + i; gegl_buffer_get (orig_buffer, &src_rect, 1.0, NULL, buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); for (j = 0; j < orig_width / 2; j++) { guchar *left = buf + j * orig_bpp; guchar *right = buf + (orig_width - 1 - j) * orig_bpp; for (k = 0; k < orig_bpp; k++) { guchar tmp = left[k]; left[k] = right[k]; right[k] = tmp; } } gegl_buffer_set (new_buffer, &dest_rect, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE); } g_free (buf); } break; case GIMP_ROTATE_270: { guchar *buf = g_new (guchar, new_width * orig_bpp); gint i; /* Not cool, we leak memory if we return, but anyway that is * never supposed to happen. If we see this warning, a bug has * to be fixed! */ g_return_val_if_fail (new_width == orig_height, NULL); src_rect.x = orig_x + orig_width - 1; src_rect.width = 1; dest_rect.y = new_y; dest_rect.height = 1; for (i = 0; i < orig_width; i++) { src_rect.x = orig_x + orig_width - 1 - i; dest_rect.y = new_y + i; gegl_buffer_get (orig_buffer, &src_rect, 1.0, NULL, buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); gegl_buffer_set (new_buffer, &dest_rect, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE); } g_free (buf); } break; } return new_buffer; }
static void gimp_color_button_class_init (GimpColorButtonClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass); GimpRGB color; parent_class = g_type_class_peek_parent (klass); gimp_color_button_signals[COLOR_CHANGED] = g_signal_new ("color-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GimpColorButtonClass, color_changed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); object_class->finalize = gimp_color_button_finalize; object_class->dispose = gimp_color_button_dispose; object_class->get_property = gimp_color_button_get_property; object_class->set_property = gimp_color_button_set_property; widget_class->button_press_event = gimp_color_button_button_press; widget_class->state_changed = gimp_color_button_state_changed; button_class->clicked = gimp_color_button_clicked; klass->color_changed = NULL; klass->get_action_type = gimp_color_button_get_action_type; gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); /** * GimpColorButton:title: * * The title to be used for the color selection dialog. * * Since: GIMP 2.4 */ g_object_class_install_property (object_class, PROP_TITLE, g_param_spec_string ("title", NULL, NULL, NULL, GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); /** * GimpColorButton:color: * * The color displayed in the button's color area. * * Since: GIMP 2.4 */ g_object_class_install_property (object_class, PROP_COLOR, gimp_param_spec_rgb ("color", NULL, NULL, TRUE, &color, GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT)); /** * GimpColorButton:type: * * The type of the button's color area. * * Since: GIMP 2.4 */ g_object_class_install_property (object_class, PROP_TYPE, g_param_spec_enum ("type", NULL, NULL, GIMP_TYPE_COLOR_AREA_TYPE, GIMP_COLOR_AREA_FLAT, GIMP_PARAM_READWRITE | G_PARAM_CONSTRUCT)); /** * GimpColorButton:continuous-update: * * The update policy of the color button. * * Since: GIMP 2.4 */ g_object_class_install_property (object_class, PROP_UPDATE, g_param_spec_boolean ("continuous-update", NULL, NULL, FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); /** * GimpColorButton:area-width: * * The minimum width of the button's #GimpColorArea. * * Since: GIMP 2.8 */ g_object_class_install_property (object_class, PROP_AREA_WIDTH, g_param_spec_int ("area-width", NULL, NULL, 1, G_MAXINT, 16, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); /** * GimpColorButton:area-height: * * The minimum height of the button's #GimpColorArea. * * Since: GIMP 2.8 */ g_object_class_install_property (object_class, PROP_AREA_HEIGHT, g_param_spec_int ("area-height", NULL, NULL, 1, G_MAXINT, 16, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); }
GeglBuffer * gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable, GimpContext *context, GeglBuffer *orig_buffer, gint orig_offset_x, gint orig_offset_y, GimpRotationType rotate_type, gdouble center_x, gdouble center_y, gboolean clip_result, gint *new_offset_x, gint *new_offset_y) { GeglBuffer *new_buffer; GeglRectangle src_rect; GeglRectangle dest_rect; gint orig_x, orig_y; gint orig_width, orig_height; gint orig_bpp; gint new_x, new_y; gint new_width, new_height; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GEGL_IS_BUFFER (orig_buffer), NULL); orig_x = orig_offset_x; orig_y = orig_offset_y; orig_width = gegl_buffer_get_width (orig_buffer); orig_height = gegl_buffer_get_height (orig_buffer); orig_bpp = babl_format_get_bytes_per_pixel (gegl_buffer_get_format (orig_buffer)); switch (rotate_type) { case GIMP_ROTATE_90: gimp_drawable_transform_rotate_point (orig_x, orig_y + orig_height, rotate_type, center_x, center_y, &new_x, &new_y); new_width = orig_height; new_height = orig_width; break; case GIMP_ROTATE_180: gimp_drawable_transform_rotate_point (orig_x + orig_width, orig_y + orig_height, rotate_type, center_x, center_y, &new_x, &new_y); new_width = orig_width; new_height = orig_height; break; case GIMP_ROTATE_270: gimp_drawable_transform_rotate_point (orig_x + orig_width, orig_y, rotate_type, center_x, center_y, &new_x, &new_y); new_width = orig_height; new_height = orig_width; break; default: g_return_val_if_reached (NULL); break; } if (clip_result && (new_x != orig_x || new_y != orig_y || new_width != orig_width || new_height != orig_height)) { GimpRGB bg; GeglColor *color; gint clip_x, clip_y; gint clip_width, clip_height; new_buffer = gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0, orig_width, orig_height), gegl_buffer_get_format (orig_buffer)); *new_offset_x = orig_x; *new_offset_y = orig_y; /* "Outside" a channel is transparency, not the bg color */ if (GIMP_IS_CHANNEL (drawable)) gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0); else gimp_context_get_background (context, &bg); color = gimp_gegl_color_new (&bg); gegl_buffer_set_color (new_buffer, NULL, color); g_object_unref (color); if (gimp_rectangle_intersect (orig_x, orig_y, orig_width, orig_height, new_x, new_y, new_width, new_height, &clip_x, &clip_y, &clip_width, &clip_height)) { gint saved_orig_x = orig_x; gint saved_orig_y = orig_y; new_x = clip_x - orig_x; new_y = clip_y - orig_y; switch (rotate_type) { case GIMP_ROTATE_90: gimp_drawable_transform_rotate_point (clip_x + clip_width, clip_y, GIMP_ROTATE_270, center_x, center_y, &orig_x, &orig_y); orig_x -= saved_orig_x; orig_y -= saved_orig_y; orig_width = clip_height; orig_height = clip_width; break; case GIMP_ROTATE_180: orig_x = clip_x - orig_x; orig_y = clip_y - orig_y; orig_width = clip_width; orig_height = clip_height; break; case GIMP_ROTATE_270: gimp_drawable_transform_rotate_point (clip_x, clip_y + clip_height, GIMP_ROTATE_90, center_x, center_y, &orig_x, &orig_y); orig_x -= saved_orig_x; orig_y -= saved_orig_y; orig_width = clip_height; orig_height = clip_width; break; } new_width = clip_width; new_height = clip_height; } else { new_width = 0; new_height = 0; } } else { new_buffer = gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0, new_width, new_height), gegl_buffer_get_format (orig_buffer)); *new_offset_x = new_x; *new_offset_y = new_y; orig_x = 0; orig_y = 0; new_x = 0; new_y = 0; } if (new_width < 1 || new_height < 1) return new_buffer; src_rect.x = orig_x; src_rect.y = orig_y; src_rect.width = orig_width; src_rect.height = orig_height; dest_rect.x = new_x; dest_rect.y = new_y; dest_rect.width = new_width; dest_rect.height = new_height; switch (rotate_type) { case GIMP_ROTATE_90: { guchar *buf = g_new (guchar, new_height * orig_bpp); gint i; g_assert (new_height == orig_width); src_rect.y = orig_y + orig_height - 1; src_rect.height = 1; dest_rect.x = new_x; dest_rect.width = 1; for (i = 0; i < orig_height; i++) { src_rect.y = orig_y + orig_height - 1 - i; dest_rect.x = new_x + i; gegl_buffer_get (orig_buffer, &src_rect, 1.0, NULL, buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); gegl_buffer_set (new_buffer, &dest_rect, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE); } g_free (buf); } break; case GIMP_ROTATE_180: { guchar *buf = g_new (guchar, new_width * orig_bpp); gint i, j, k; g_assert (new_width == orig_width); src_rect.y = orig_y + orig_height - 1; src_rect.height = 1; dest_rect.y = new_y; dest_rect.height = 1; for (i = 0; i < orig_height; i++) { src_rect.y = orig_y + orig_height - 1 - i; dest_rect.y = new_y + i; gegl_buffer_get (orig_buffer, &src_rect, 1.0, NULL, buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); for (j = 0; j < orig_width / 2; j++) { guchar *left = buf + j * orig_bpp; guchar *right = buf + (orig_width - 1 - j) * orig_bpp; for (k = 0; k < orig_bpp; k++) { guchar tmp = left[k]; left[k] = right[k]; right[k] = tmp; } } gegl_buffer_set (new_buffer, &dest_rect, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE); } g_free (buf); } break; case GIMP_ROTATE_270: { guchar *buf = g_new (guchar, new_width * orig_bpp); gint i; g_assert (new_width == orig_height); src_rect.x = orig_x + orig_width - 1; src_rect.width = 1; dest_rect.y = new_y; dest_rect.height = 1; for (i = 0; i < orig_width; i++) { src_rect.x = orig_x + orig_width - 1 - i; dest_rect.y = new_y + i; gegl_buffer_get (orig_buffer, &src_rect, 1.0, NULL, buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); gegl_buffer_set (new_buffer, &dest_rect, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE); } g_free (buf); } break; } return new_buffer; }
gboolean gimp_operation_color_erase_mode_process_pixels (gfloat *in, gfloat *layer, gfloat *mask, gfloat *out, gdouble opacity, glong samples, const GeglRectangle *roi, gint level) { const gboolean has_mask = mask != NULL; while (samples--) { gfloat layer_alpha; GimpRGB bgcolor, color, alpha; layer_alpha = layer[ALPHA] * opacity; if (has_mask) layer_alpha *= *mask; gimp_rgba_set (&color, in[0], in[1], in[2], in[3]); gimp_rgba_set (&bgcolor, layer[0], layer[1], layer[2], layer_alpha); /* start of helper function copied from legacy 8-bit blending code */ alpha.a = color.a; if (bgcolor.r < 0.0001) alpha.r = color.r; else if ( color.r > bgcolor.r ) alpha.r = (color.r - bgcolor.r) / (1.0 - bgcolor.r); else if (color.r < bgcolor.r) alpha.r = (bgcolor.r - color.r) / bgcolor.r; else alpha.r = 0.0; if (bgcolor.g < 0.0001) alpha.g = color.g; else if ( color.g > bgcolor.g ) alpha.g = (color.g - bgcolor.g) / (1.0 - bgcolor.g); else if ( color.g < bgcolor.g ) alpha.g = (bgcolor.g - color.g) / (bgcolor.g); else alpha.g = 0.0; if (bgcolor.b < 0.0001) alpha.b = color.b; else if ( color.b > bgcolor.b ) alpha.b = (color.b - bgcolor.b) / (1.0 - bgcolor.b); else if ( color.b < bgcolor.b ) alpha.b = (bgcolor.b - color.b) / (bgcolor.b); else alpha.b = 0.0; if ( alpha.r > alpha.g ) { if ( alpha.r > alpha.b ) { color.a = alpha.r; } else { color.a = alpha.b; } } else if ( alpha.g > alpha.b ) { color.a = alpha.g; } else { color.a = alpha.b; } color.a = (1.0 - bgcolor.a) + (color.a * bgcolor.a); if (color.a > 0.0001) { color.r = (color.r - bgcolor.r) / color.a + bgcolor.r; color.g = (color.g - bgcolor.g) / color.a + bgcolor.g; color.b = (color.b - bgcolor.b) / color.a + bgcolor.b; color.a *= alpha.a; } /* end of helper function */ out[0] = color.r; out[1] = color.g; out[2] = color.b; out[3] = color.a; in += 4; layer += 4; out += 4; if (has_mask) mask++; } return TRUE; }
GList * gimp_palette_load_aco (const gchar *filename, GError **error) { GimpPalette *palette; gchar *palette_name; gint fd; gint format_version; gint number_of_colors; gint i; gchar header[4]; gchar color_info[10]; gchar format2_preamble[4]; gint status; g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (g_path_is_absolute (filename), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); fd = g_open (filename, O_RDONLY | _O_BINARY, 0); if (! fd) { g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), _("Could not open '%s' for reading: %s"), gimp_filename_to_utf8 (filename), g_strerror (errno)); return NULL; } palette_name = g_filename_display_basename (filename); palette = GIMP_PALETTE (gimp_palette_new (palette_name)); g_free (palette_name); status = read(fd, header, sizeof (header)); if (status < 0) { close(fd); return g_list_prepend (NULL, palette); } format_version = header[1] + (header[0] << 8); number_of_colors = header[3] + (header[2] << 8); for (i = 0; i < number_of_colors; i++) { gint color_space; gint w, x, y, z; gboolean color_ok = FALSE; GimpRGB color; read (fd, color_info, sizeof (color_info)); color_space = color_info[1] + (color_info[0] << 8); w = (guchar) color_info[3] + ((guchar) color_info[2] << 8); x = (guchar) color_info[5] + ((guchar) color_info[4] << 8); y = (guchar) color_info[7] + ((guchar) color_info[6] << 8); z = (guchar) color_info[9] + ((guchar) color_info[8] << 8); if (color_space == 0) /* RGB */ { gdouble R = ((gdouble) w) / 65536.0; gdouble G = ((gdouble) x) / 65536.0; gdouble B = ((gdouble) y) / 65536.0; gimp_rgba_set (&color, R, G, B, 1.0); color_ok = TRUE; } else if (color_space == 1) /* HSV */ { GimpHSV hsv; gdouble H = ((gdouble) w) / 65536.0; gdouble S = ((gdouble) x) / 65536.0; gdouble V = ((gdouble) y) / 65536.0; gimp_hsva_set (&hsv, H, S, V, 1.0); gimp_hsv_to_rgb (&hsv, &color); color_ok = TRUE; } else if (color_space == 2) /* CMYK */ { GimpCMYK cmyk; gdouble C = 1.0 - (((gdouble) w) / 65536.0); gdouble M = 1.0 - (((gdouble) x) / 65536.0); gdouble Y = 1.0 - (((gdouble) y) / 65536.0); gdouble K = 1.0 - (((gdouble) z) / 65536.0); gimp_cmyka_set (&cmyk, C, M, Y, K, 1.0); gimp_cmyk_to_rgb (&cmyk, &color); color_ok = TRUE; } else if (color_space == 8) /* Grayscale */ { gdouble K = 1.0 - (((gdouble) w) / 10000.0); gimp_rgba_set (&color, K, K, K, 1.0); color_ok = TRUE; } else if (color_space == 9) /* Wide? CMYK */ { GimpCMYK cmyk; gdouble C = 1.0 - (((gdouble) w) / 10000.0); gdouble M = 1.0 - (((gdouble) x) / 10000.0); gdouble Y = 1.0 - (((gdouble) y) / 10000.0); gdouble K = 1.0 - (((gdouble) z) / 10000.0); gimp_cmyka_set (&cmyk, C, M, Y, K, 1.0); gimp_cmyk_to_rgb (&cmyk, &color); color_ok = TRUE; } else { g_printerr ("Unsupported color space (%d) in ACO file %s\n", color_space, gimp_filename_to_utf8 (filename)); } if (format_version == 2) { gint number_of_chars; read (fd, format2_preamble, sizeof (format2_preamble)); number_of_chars = format2_preamble[3] + (format2_preamble[2] << 8); lseek (fd, number_of_chars * 2, SEEK_SET); } if (color_ok) gimp_palette_add_entry (palette, -1, NULL, &color); } close(fd); return g_list_prepend (NULL, palette); }
/** * gimp_scanner_parse_color: * @scanner: A #GScanner created by gimp_scanner_new_file() or * gimp_scanner_new_string() * @dest: Pointer to a color to store the result * * Return value: %TRUE on success * * Since: 2.4 **/ gboolean gimp_scanner_parse_color (GScanner *scanner, GimpRGB *dest) { guint scope_id; guint old_scope_id; GTokenType token; GimpRGB color = { 0.0, 0.0, 0.0, 1.0 }; scope_id = g_quark_from_static_string ("gimp_scanner_parse_color"); old_scope_id = g_scanner_set_scope (scanner, scope_id); if (! g_scanner_scope_lookup_symbol (scanner, scope_id, "color-rgb")) { g_scanner_scope_add_symbol (scanner, scope_id, "color-rgb", GINT_TO_POINTER (COLOR_RGB)); g_scanner_scope_add_symbol (scanner, scope_id, "color-rgba", GINT_TO_POINTER (COLOR_RGBA)); g_scanner_scope_add_symbol (scanner, scope_id, "color-hsv", GINT_TO_POINTER (COLOR_HSV)); g_scanner_scope_add_symbol (scanner, scope_id, "color-hsva", GINT_TO_POINTER (COLOR_HSVA)); } token = G_TOKEN_LEFT_PAREN; while (g_scanner_peek_next_token (scanner) == token) { token = g_scanner_get_next_token (scanner); switch (token) { case G_TOKEN_LEFT_PAREN: token = G_TOKEN_SYMBOL; break; case G_TOKEN_SYMBOL: { gdouble col[4] = { 0.0, 0.0, 0.0, 1.0 }; gint n_channels = 4; gboolean is_hsv = FALSE; gint i; switch (GPOINTER_TO_INT (scanner->value.v_symbol)) { case COLOR_RGB: n_channels = 3; /* fallthrough */ case COLOR_RGBA: break; case COLOR_HSV: n_channels = 3; /* fallthrough */ case COLOR_HSVA: is_hsv = TRUE; break; } token = G_TOKEN_FLOAT; for (i = 0; i < n_channels; i++) { gboolean negate = FALSE; if (g_scanner_peek_next_token (scanner) == '-') { negate = TRUE; g_scanner_get_next_token (scanner); } if (! gimp_scanner_parse_float (scanner, &col[i])) goto finish; if (negate) col[i] = - col[i]; } if (is_hsv) { GimpHSV hsv; gimp_hsva_set (&hsv, col[0], col[1], col[2], col[3]); gimp_hsv_clamp (&hsv); gimp_hsv_to_rgb (&hsv, &color); } else { gimp_rgba_set (&color, col[0], col[1], col[2], col[3]); gimp_rgb_clamp (&color); } token = G_TOKEN_RIGHT_PAREN; } break; case G_TOKEN_RIGHT_PAREN: token = G_TOKEN_NONE; /* indicates success */ goto finish; default: /* do nothing */ break; } } finish: if (token != G_TOKEN_NONE) { g_scanner_get_next_token (scanner); g_scanner_unexp_token (scanner, token, NULL, NULL, NULL, _("fatal parse error"), TRUE); } else { *dest = color; } g_scanner_set_scope (scanner, old_scope_id); return (token == G_TOKEN_NONE); }
GeglBuffer * gimp_drawable_transform_buffer_flip (GimpDrawable *drawable, GimpContext *context, GeglBuffer *orig_buffer, gint orig_offset_x, gint orig_offset_y, GimpOrientationType flip_type, gdouble axis, gboolean clip_result, gint *new_offset_x, gint *new_offset_y) { GeglBuffer *new_buffer; GeglRectangle src_rect; GeglRectangle dest_rect; gint orig_x, orig_y; gint orig_width, orig_height; gint new_x, new_y; gint new_width, new_height; gint i; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GEGL_IS_BUFFER (orig_buffer), NULL); orig_x = orig_offset_x; orig_y = orig_offset_y; orig_width = gegl_buffer_get_width (orig_buffer); orig_height = gegl_buffer_get_height (orig_buffer); new_x = orig_x; new_y = orig_y; new_width = orig_width; new_height = orig_height; switch (flip_type) { case GIMP_ORIENTATION_HORIZONTAL: new_x = RINT (-((gdouble) orig_x + (gdouble) orig_width - axis) + axis); break; case GIMP_ORIENTATION_VERTICAL: new_y = RINT (-((gdouble) orig_y + (gdouble) orig_height - axis) + axis); break; case GIMP_ORIENTATION_UNKNOWN: g_return_val_if_reached (NULL); break; } new_buffer = gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0, new_width, new_height), gegl_buffer_get_format (orig_buffer)); if (clip_result && (new_x != orig_x || new_y != orig_y)) { GimpRGB bg; GeglColor *color; gint clip_x, clip_y; gint clip_width, clip_height; *new_offset_x = orig_x; *new_offset_y = orig_y; /* "Outside" a channel is transparency, not the bg color */ if (GIMP_IS_CHANNEL (drawable)) gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0); else gimp_context_get_background (context, &bg); color = gimp_gegl_color_new (&bg); gegl_buffer_set_color (new_buffer, NULL, color); g_object_unref (color); if (gimp_rectangle_intersect (orig_x, orig_y, orig_width, orig_height, new_x, new_y, new_width, new_height, &clip_x, &clip_y, &clip_width, &clip_height)) { orig_x = new_x = clip_x - orig_x; orig_y = new_y = clip_y - orig_y; } orig_width = new_width = clip_width; orig_height = new_height = clip_height; } else { *new_offset_x = new_x; *new_offset_y = new_y; orig_x = 0; orig_y = 0; new_x = 0; new_y = 0; } if (new_width == 0 && new_height == 0) return new_buffer; switch (flip_type) { case GIMP_ORIENTATION_HORIZONTAL: src_rect.x = orig_x; src_rect.y = orig_y; src_rect.width = 1; src_rect.height = orig_height; dest_rect.x = new_x + new_width - 1; dest_rect.y = new_y; dest_rect.width = 1; dest_rect.height = new_height; for (i = 0; i < orig_width; i++) { src_rect.x = i + orig_x; dest_rect.x = new_x + new_width - i - 1; gegl_buffer_copy (orig_buffer, &src_rect, new_buffer, &dest_rect); } break; case GIMP_ORIENTATION_VERTICAL: src_rect.x = orig_x; src_rect.y = orig_y; src_rect.width = orig_width; src_rect.height = 1; dest_rect.x = new_x; dest_rect.y = new_y + new_height - 1; dest_rect.width = new_width; dest_rect.height = 1; for (i = 0; i < orig_height; i++) { src_rect.y = i + orig_y; dest_rect.y = new_y + new_height - i - 1; gegl_buffer_copy (orig_buffer, &src_rect, new_buffer, &dest_rect); } break; case GIMP_ORIENTATION_UNKNOWN: break; } return new_buffer; }