static void gimp_pick_button_pick (GdkScreen *screen, gint x_root, gint y_root, GimpPickButton *button) { GdkWindow *root_window = gdk_screen_get_root_window (screen); cairo_surface_t *image; cairo_t *cr; guchar *data; guchar color[3]; GimpRGB rgb; image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1); cr = cairo_create (image); gdk_cairo_set_source_window (cr, root_window, -x_root, -y_root); cairo_paint (cr); cairo_destroy (cr); data = cairo_image_surface_get_data (image); GIMP_CAIRO_RGB24_GET_PIXEL (data, color[0], color[1], color[2]); cairo_surface_destroy (image); gimp_rgba_set_uchar (&rgb, color[0], color[1], color[2], 1.0); g_signal_emit (button, pick_button_signals[COLOR_PICKED], 0, &rgb); }
static void to_alpha_func (const guchar *src, guchar *dest, gint bpp, gpointer data) { GimpRGB color; if (bpp == 3) gimp_rgba_set_uchar (&color, src[0], src[1], src[2], 255); else gimp_rgba_set_uchar (&color, src[0], src[1], src[2], src[3]); color_to_alpha (&color, &pvals.color); gimp_rgba_get_uchar (&color, &dest[0], &dest[1], &dest[2], &dest[3]); }
GList * gimp_palette_load_act (GimpContext *context, GFile *file, GInputStream *input, GError **error) { GimpPalette *palette; gchar *palette_name; guchar color_bytes[3]; gsize bytes_read; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); palette_name = g_path_get_basename (gimp_file_get_utf8_name (file)); palette = GIMP_PALETTE (gimp_palette_new (context, palette_name)); g_free (palette_name); while (g_input_stream_read_all (input, color_bytes, sizeof (color_bytes), &bytes_read, NULL, NULL) && bytes_read == sizeof (color_bytes)) { GimpRGB color; gimp_rgba_set_uchar (&color, color_bytes[0], color_bytes[1], color_bytes[2], 255); gimp_palette_add_entry (palette, -1, NULL, &color); } return g_list_prepend (NULL, palette); }
void colormap_edit_color_cmd_callback (GtkAction *action, gpointer data) { GimpColormapEditor *editor; GimpImage *image; const guchar *colormap; GimpRGB color; gchar *desc; return_if_no_image (image, data); editor = GIMP_COLORMAP_EDITOR (data); colormap = gimp_image_get_colormap (image); gimp_rgba_set_uchar (&color, colormap[editor->col_index * 3], colormap[editor->col_index * 3 + 1], colormap[editor->col_index * 3 + 2], OPAQUE_OPACITY); desc = g_strdup_printf (_("Edit colormap entry #%d"), editor->col_index); if (! editor->color_dialog) { editor->color_dialog = gimp_color_dialog_new (GIMP_VIEWABLE (image), action_data_get_context (data), _("Edit Colormap Entry"), GIMP_STOCK_COLORMAP, desc, GTK_WIDGET (editor), gimp_dialog_factory_from_name ("toplevel"), "gimp-colormap-editor-color-dialog", (const GimpRGB *) &color, FALSE, FALSE); g_signal_connect (editor->color_dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &editor->color_dialog); g_signal_connect (editor->color_dialog, "update", G_CALLBACK (colormap_edit_color_update), editor); } else { gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog), GIMP_VIEWABLE (image), action_data_get_context (data)); g_object_set (editor->color_dialog, "description", desc, NULL); gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog), &color); } g_free (desc); gtk_window_present (GTK_WINDOW (editor->color_dialog)); }
static guchar* rgb_to_hsl (GimpDrawable *drawable, LICEffectChannel effect_channel) { guchar *themap, data[4]; gint x, y; GimpRGB color; GimpHSL color_hsl; gdouble val = 0.0; glong maxc, index = 0; GimpPixelRgn region; GRand *gr; gr = g_rand_new (); maxc = drawable->width * drawable->height; gimp_pixel_rgn_init (®ion, drawable, border_x, border_y, border_w, border_h, FALSE, FALSE); themap = g_new (guchar, maxc); for (y = 0; y < region.h; y++) { for (x = 0; x < region.w; x++) { data[3] = 255; gimp_pixel_rgn_get_pixel (®ion, data, x, y); gimp_rgba_set_uchar (&color, data[0], data[1], data[2], data[3]); gimp_rgb_to_hsl (&color, &color_hsl); switch (effect_channel) { case LIC_HUE: val = color_hsl.h * 255; break; case LIC_SATURATION: val = color_hsl.s * 255; break; case LIC_BRIGHTNESS: val = color_hsl.l * 255; break; } /* add some random to avoid unstructured areas. */ val += g_rand_double_range (gr, -1.0, 1.0); themap[index++] = (guchar) CLAMP0255 (RINT (val)); } } g_rand_free (gr); return themap; }
/* --------------------------------- * gap_colordiff_guchar * --------------------------------- * returns difference of 2 colors as gdouble value * in range 0.0 (exact match) to 1.0 (maximal difference) * Note: * this procedure uses the same HSV colormodel based * Algorithm as the HSV specific procedures. */ gdouble gap_colordiff_guchar(guchar *aPixelPtr , guchar *bPixelPtr , gdouble colorSensitivity , gboolean debugPrint ) { GimpRGB aRgb; GimpRGB bRgb; gimp_rgba_set_uchar (&aRgb, aPixelPtr[0], aPixelPtr[1], aPixelPtr[2], 255); gimp_rgba_set_uchar (&bRgb, bPixelPtr[0], bPixelPtr[1], bPixelPtr[2], 255); return (gap_colordiff_GimpRGB(&aRgb , &bRgb , colorSensitivity , debugPrint )); } /* end gap_colordiff_guchar */
static void peek (GimpPixelRgn *src_rgn, gint x, gint y, GimpRGB *color) { static guchar data[4] = { 0, }; gimp_pixel_rgn_get_pixel (src_rgn, data, x, y); gimp_rgba_set_uchar (color, data[0], data[1], data[2], data[3]); }
/* -------------------------- * p_create_corpus_layer * -------------------------- * create the corpus layer that builds the reference pattern * for the resynthesizer call. The reference pattern is built * as duplicate of the original image reduced to the area around the current selection. * (grown by corpus_border_radius) * Note that the duplicate image has a selection, that includes the gorwn area * around the orignal selection, but EXCLUDES the original selection * (that is the area holding the object that has to be replaced * by pattern of the surrounding area) * returns the layer_id of the reference pattern. */ static gint32 p_create_corpus_layer(gint32 image_id, gint32 drawable_id, TransValues *val_ptr) { gint32 dup_image_id; gint32 channel_id; gint32 channel_2_id; GimpRGB bck_color; GimpRGB white_opaque_color; /* gboolean has_selection; */ gboolean non_empty; gint x1, y1, x2, y2; gint32 active_layer_stackposition; gint32 active_dup_layer_id; active_layer_stackposition = gap_layer_get_stackposition(image_id, drawable_id); dup_image_id = gimp_image_duplicate(image_id); channel_id = gimp_selection_save(dup_image_id); gimp_selection_grow(dup_image_id, val_ptr->corpus_border_radius); gimp_selection_invert(dup_image_id); gimp_context_get_background(&bck_color); channel_2_id = gimp_selection_save(dup_image_id); gimp_image_select_item(dup_image_id, GIMP_CHANNEL_OP_REPLACE, channel_id); gimp_rgba_set_uchar (&white_opaque_color, 255, 255, 255, 255); gimp_context_set_background(&white_opaque_color); gimp_edit_clear(channel_2_id); gimp_context_set_background(&bck_color); /* restore original background color */ gimp_selection_load(channel_2_id); gimp_selection_invert(dup_image_id); /* has_selection = */ gimp_selection_bounds(dup_image_id, &non_empty, &x1, &y1, &x2, &y2); gimp_image_crop(dup_image_id, (x2 - x1), (y2 - y1), x1, y1); gimp_selection_invert(dup_image_id); active_dup_layer_id = gap_layer_get_id_by_stackposition(dup_image_id, active_layer_stackposition); if (1==0) { /* debug code shows the duplicate image by adding a display */ gimp_display_new(dup_image_id); } return (active_dup_layer_id); } /* end p_create_corpus_layer */
/* --------------------------------- * gap_colordiff_hvmax_guchar * --------------------------------- * returns difference of 2 colors as gdouble value * in range 0.0 (exact match) to 1.0 (maximal difference) * Note: * this procedure uses an HSV colormodel based * Algorithm and calculates difference as max HSV difference. * * DEPRECATED * */ gdouble gap_colordiff_hvmax_guchar(guchar *aPixelPtr , guchar *bPixelPtr , gboolean debugPrint ) { GimpRGB aRgb; GimpRGB bRgb; GimpHSV aHsv; GimpHSV bHsv; gimp_rgba_set_uchar (&aRgb, aPixelPtr[0], aPixelPtr[1], aPixelPtr[2], 255); gimp_rgba_set_uchar (&bRgb, bPixelPtr[0], bPixelPtr[1], bPixelPtr[2], 255); gimp_rgb_to_hsv(&aRgb, &aHsv); gimp_rgb_to_hsv(&bRgb, &bHsv); return (gap_colordiff_hvmax_GimpHSV(&aHsv , &bHsv , debugPrint )); } /* end gap_colordiff_hvmax_guchar */
void gimp_image_get_colormap_entry (GimpImage *image, gint color_index, GimpRGB *color) { g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (image->colormap != NULL); g_return_if_fail (color_index >= 0 && color_index < image->n_colors); g_return_if_fail (color != NULL); gimp_rgba_set_uchar (color, image->colormap[color_index * 3], image->colormap[color_index * 3 + 1], image->colormap[color_index * 3 + 2], OPAQUE_OPACITY); }
static VALUE rb_gimp_rgba_set_uchar (VALUE self, VALUE r, VALUE g, VALUE b, VALUE a) { Get_TypedStruct(self, GimpRGB, color); gimp_rgba_set_uchar(color, (guchar)NUM2INT(r), (guchar)NUM2INT(g), (guchar)NUM2INT(b), (guchar)NUM2INT(a)); return rb_ary_new3(4, r, g, b, a); }
/* --------------------------------- * gap_colordiff_guchar_GimpHSV * --------------------------------- * returns difference of 2 colors as gdouble value * in range 0.0 (exact match) to 1.0 (maximal difference) */ gdouble gap_colordiff_guchar_GimpHSV(GimpHSV *aHsvPtr , guchar *pixel , gdouble colorSensitivity , gboolean debugPrint) { GimpRGB bRgb; GimpHSV bHsv; gdouble colordiff; gimp_rgba_set_uchar (&bRgb, pixel[0], pixel[1], pixel[2], 255); gimp_rgb_to_hsv(&bRgb, &bHsv); colordiff = gap_colordiff_GimpHSV(aHsvPtr, &bHsv, colorSensitivity, debugPrint); return (colordiff); } /* end gap_colordiff_guchar_GimpHSV */
GList * gimp_palette_load_riff (const gchar *filename, GError **error) { GimpPalette *palette; gchar *palette_name; gint fd; guchar color_bytes[4]; 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); lseek (fd, 28, SEEK_SET); while (read (fd, color_bytes, sizeof (color_bytes)) == sizeof (color_bytes)) { GimpRGB color; gimp_rgba_set_uchar (&color, color_bytes[0], color_bytes[1], color_bytes[2], 255); gimp_palette_add_entry (palette, -1, NULL, &color); } close (fd); return g_list_prepend (NULL, palette); }
gboolean gimp_pickable_get_color_at (GimpPickable *pickable, gint x, gint y, GimpRGB *color) { guchar pixel[4]; guchar col[4]; 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, pixel)) return FALSE; gimp_image_get_color (gimp_pickable_get_image (pickable), gimp_pickable_get_image_type (pickable), pixel, col); gimp_rgba_set_uchar (color, col[0], col[1], col[2], col[3]); return TRUE; }
GList * gimp_palette_load_psp (const gchar *filename, GError **error) { GimpPalette *palette; gchar *palette_name; gint fd; guchar color_bytes[4]; gint number_of_colors; gint data_size; gint i, j; gboolean color_ok; gchar buffer[4096]; /*Maximum valid file size: 256 * 4 * 3 + 256 * 2 ~= 3650 bytes */ gchar **lines; gchar **ascii_colors; 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); lseek (fd, 16, SEEK_SET); data_size = read (fd, buffer, sizeof (buffer) - 1); buffer[data_size] = '\0'; lines = g_strsplit (buffer, "\x0d\x0a", -1); number_of_colors = atoi (lines[0]); for (i = 0; i < number_of_colors; i++) { if (lines[i + 1] == NULL) { g_printerr ("Premature end of file reading %s.", gimp_filename_to_utf8 (filename)); break; } ascii_colors = g_strsplit (lines[i + 1], " ", 3); color_ok = TRUE; for (j = 0 ; j < 3; j++) { if (ascii_colors[j] == NULL) { g_printerr ("Corrupted palette file %s.", gimp_filename_to_utf8 (filename)); color_ok = FALSE; break; } color_bytes[j] = atoi (ascii_colors[j]); } if (color_ok) { GimpRGB color; gimp_rgba_set_uchar (&color, color_bytes[0], color_bytes[1], color_bytes[2], 255); gimp_palette_add_entry (palette, -1, NULL, &color); } g_strfreev (ascii_colors); } g_strfreev (lines); close (fd); return g_list_prepend (NULL, palette); }
GList * gimp_palette_load (const gchar *filename, GError **error) { GimpPalette *palette; GimpPaletteEntry *entry; gchar str[1024]; gchar *tok; FILE *file; gint r, g, b; gint linenum; 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); r = g = b = 0; file = g_fopen (filename, "rb"); if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, _("Could not open '%s' for reading: %s"), gimp_filename_to_utf8 (filename), g_strerror (errno)); return NULL; } linenum = 1; if (! fgets (str, sizeof (str), file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); fclose (file); return NULL; } if (! g_str_has_prefix (str, "GIMP Palette")) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Missing magic header."), gimp_filename_to_utf8 (filename)); fclose (file); return NULL; } palette = g_object_new (GIMP_TYPE_PALETTE, "mime-type", "application/x-gimp-palette", NULL); linenum++; if (! fgets (str, sizeof (str), file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); fclose (file); g_object_unref (palette); return NULL; } if (g_str_has_prefix (str, "Name: ")) { gchar *utf8; utf8 = gimp_any_to_utf8 (g_strstrip (str + strlen ("Name: ")), -1, _("Invalid UTF-8 string in palette file '%s'"), gimp_filename_to_utf8 (filename)); gimp_object_take_name (GIMP_OBJECT (palette), utf8); linenum++; if (! fgets (str, sizeof (str), file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); fclose (file); g_object_unref (palette); return NULL; } if (g_str_has_prefix (str, "Columns: ")) { gint columns; columns = atoi (g_strstrip (str + strlen ("Columns: "))); if (columns < 0 || columns > 256) { g_message (_("Reading palette file '%s': " "Invalid number of columns in line %d. " "Using default value."), gimp_filename_to_utf8 (filename), linenum); columns = 0; } palette->n_columns = columns; linenum++; if (! fgets (str, sizeof (str), file)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); fclose (file); g_object_unref (palette); return NULL; } } } else /* old palette format */ { gimp_object_take_name (GIMP_OBJECT (palette), g_filename_display_basename (filename)); } while (! feof (file)) { if (str[0] != '#' && str[0] != '\n') { tok = strtok (str, " \t"); if (tok) r = atoi (tok); else g_message (_("Reading palette file '%s': " "Missing RED component in line %d."), gimp_filename_to_utf8 (filename), linenum); tok = strtok (NULL, " \t"); if (tok) g = atoi (tok); else g_message (_("Reading palette file '%s': " "Missing GREEN component in line %d."), gimp_filename_to_utf8 (filename), linenum); tok = strtok (NULL, " \t"); if (tok) b = atoi (tok); else g_message (_("Reading palette file '%s': " "Missing BLUE component in line %d."), gimp_filename_to_utf8 (filename), linenum); /* optional name */ tok = strtok (NULL, "\n"); if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) g_message (_("Reading palette file '%s': " "RGB value out of range in line %d."), gimp_filename_to_utf8 (filename), linenum); /* don't call gimp_palette_add_entry here, it's rather inefficient */ entry = g_slice_new0 (GimpPaletteEntry); gimp_rgba_set_uchar (&entry->color, (guchar) r, (guchar) g, (guchar) b, 255); entry->name = g_strdup (tok ? tok : _("Untitled")); entry->position = palette->n_colors; palette->colors = g_list_prepend (palette->colors, entry); palette->n_colors++; } linenum++; if (! fgets (str, sizeof (str), file)) { if (feof (file)) break; g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Fatal parse error in palette file '%s': " "Read error in line %d."), gimp_filename_to_utf8 (filename), linenum); fclose (file); g_object_unref (palette); return NULL; } } fclose (file); palette->colors = g_list_reverse (palette->colors); return g_list_prepend (NULL, palette); }
static void gimp_color_config_class_init (GimpColorConfigClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpRGB color; gimp_rgba_set_uchar (&color, 0x80, 0x80, 0x80, 0xff); object_class->finalize = gimp_color_config_finalize; object_class->set_property = gimp_color_config_set_property; object_class->get_property = gimp_color_config_get_property; GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_MODE, "mode", COLOR_MANAGEMENT_MODE_BLURB, GIMP_TYPE_COLOR_MANAGEMENT_MODE, GIMP_COLOR_MANAGEMENT_DISPLAY, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_RGB_PROFILE, "rgb-profile", RGB_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_CMYK_PROFILE, "cmyk-profile", CMYK_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_DISPLAY_PROFILE, "display-profile", DISPLAY_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_DISPLAY_PROFILE_FROM_GDK, "display-profile-from-gdk", DISPLAY_PROFILE_FROM_GDK_BLURB, FALSE, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_PRINTER_PROFILE, "printer-profile", PRINTER_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_DISPLAY_RENDERING_INTENT, "display-rendering-intent", DISPLAY_RENDERING_INTENT_BLURB, GIMP_TYPE_COLOR_RENDERING_INTENT, GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_SIMULATION_RENDERING_INTENT, "simulation-rendering-intent", SIMULATION_RENDERING_INTENT_BLURB, GIMP_TYPE_COLOR_RENDERING_INTENT, GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_SIMULATION_GAMUT_CHECK, "simulation-gamut-check", SIMULATION_GAMUT_CHECK_BLURB, FALSE, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_RGB (object_class, PROP_OUT_OF_GAMUT_COLOR, "out-of-gamut-color", OUT_OF_GAMUT_COLOR_BLURB, FALSE, &color, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_DISPLAY_MODULE, "display-module", NULL, "CdisplayLcms", GIMP_PARAM_STATIC_STRINGS); }
static void gimp_pick_button_pick (GimpPickButton *button, GdkEvent *event) { GdkScreen *screen = gdk_event_get_screen (event); GimpColorProfile *monitor_profile; GdkMonitor *monitor; GimpRGB rgb; gint x_root; gint y_root; gdouble x_win; gdouble y_win; gdk_window_get_origin (gdk_event_get_window (event), &x_root, &y_root); gdk_event_get_coords (event, &x_win, &y_win); x_root += x_win; y_root += y_win; #ifdef G_OS_WIN32 { HDC hdc; RECT rect; COLORREF win32_color; /* For MS Windows, use native GDI functions to get the pixel, as * cairo does not handle the case where you have multiple monitors * with a monitor on the left or above the primary monitor. That * scenario create a cairo primary surface with negative extent, * which is not handled properly (bug 740634). */ hdc = GetDC (HWND_DESKTOP); GetClipBox (hdc, &rect); win32_color = GetPixel (hdc, x_root + rect.left, y_root + rect.top); ReleaseDC (HWND_DESKTOP, hdc); gimp_rgba_set_uchar (&rgb, GetRValue (win32_color), GetGValue (win32_color), GetBValue (win32_color), 255); } #else { GdkWindow *window; gint x_window; gint y_window; cairo_surface_t *image; cairo_t *cr; guchar *data; guchar color[3]; /* we try to pick from the local window under the cursor, and fall * back to picking from the root window if this fails (i.e., if * the cursor is not under a local window). on wayland, picking * from the root window is not supported, so this at least allows * us to pick from local windows. see bug #780375. */ window = gdk_device_get_window_at_position (gdk_event_get_device (event), &x_window, &y_window); if (! window) { window = gdk_screen_get_root_window (screen); x_window = x_root; y_window = y_root; } image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1); cr = cairo_create (image); gdk_cairo_set_source_window (cr, window, -x_window, -y_window); cairo_paint (cr); cairo_destroy (cr); data = cairo_image_surface_get_data (image); GIMP_CAIRO_RGB24_GET_PIXEL (data, color[0], color[1], color[2]); cairo_surface_destroy (image); gimp_rgba_set_uchar (&rgb, color[0], color[1], color[2], 255); } #endif monitor = gdk_display_get_monitor_at_point (gdk_screen_get_display (screen), x_root, y_root); monitor_profile = gimp_monitor_get_color_profile (monitor); if (monitor_profile) { GimpColorProfile *srgb_profile; GimpColorTransform *transform; const Babl *format; GimpColorTransformFlags flags = 0; format = babl_format ("R'G'B'A double"); flags |= GIMP_COLOR_TRANSFORM_FLAGS_NOOPTIMIZE; flags |= GIMP_COLOR_TRANSFORM_FLAGS_BLACK_POINT_COMPENSATION; srgb_profile = gimp_color_profile_new_rgb_srgb (); transform = gimp_color_transform_new (monitor_profile, format, srgb_profile, format, GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL, flags); g_object_unref (srgb_profile); if (transform) { gimp_color_transform_process_pixels (transform, format, &rgb, format, &rgb, 1); gimp_rgb_clamp (&rgb); g_object_unref (transform); } } g_signal_emit_by_name (button, "color-picked", &rgb); }
gint32 xjpg_load_channel (const char *filename, gint32 image_id, gint32 drawable_id, char *channel_name, gdouble channel_opacity, guchar red, guchar green, guchar blue) { GimpPixelRgn l_pixel_rgn; GimpDrawable *l_drawable; gint32 l_drawable_id; struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; FILE *infile; guchar *l_buf; guchar **l_rowbuf; int l_tile_height; int l_scanlines; int l_idx, l_start, l_end; GimpRGB l_color; gimp_rgba_set_uchar (&l_color, red, green, blue, 255); /* We set up the normal JPEG error routines. */ cinfo.err = jpeg_std_error (&jerr.pub); jerr.pub.error_exit = my_error_exit; if ((infile = g_fopen (filename, "rb")) == NULL) { g_warning ("can't open \"%s\"\n", filename); return -1; } /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp (jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. * We need to clean up the JPEG object, close the input file, and return. */ jpeg_destroy_decompress (&cinfo); if (infile) fclose (infile); g_printerr ("XJT: JPEG load error\n"); return -1; } /* Now we can initialize the JPEG decompression object. */ jpeg_create_decompress (&cinfo); /* Step 2: specify data source (eg, a file) */ jpeg_stdio_src (&cinfo, infile); /* Step 3: read file parameters with jpeg_read_header() */ (void) jpeg_read_header (&cinfo, TRUE); /* We can ignore the return value from jpeg_read_header since * (a) suspension is not possible with the stdio data source, and * (b) we passed TRUE to reject a tables-only JPEG file as an error. * See libjpeg.doc for more info. */ /* Step 4: set parameters for decompression */ /* In this example, we don't need to change any of the defaults set by * jpeg_read_header(), so we do nothing here. */ /* Step 5: Start decompressor */ jpeg_start_decompress (&cinfo); /* We may need to do some setup of our own at this point before reading * the data. After jpeg_start_decompress() we have the correct scaled * output image dimensions available, as well as the output colormap * if we asked for color quantization. * In this example, we need to make an output work buffer of the right size. */ /* temporary buffer */ l_tile_height = gimp_tile_height (); l_buf = g_new (guchar, l_tile_height * cinfo.output_width * cinfo.output_components); l_rowbuf = g_new (guchar*, l_tile_height); for (l_idx = 0; l_idx < l_tile_height; l_idx++) { l_rowbuf[l_idx] = l_buf + cinfo.output_width * cinfo.output_components * l_idx; } /* Check if jpeg file has one component (a channel cant have more than one) */ if(cinfo.output_components != 1) { g_printerr ("XJT: cant load RGB layer %s into GRAY Image\n", filename); fclose (infile); return -1; } if(drawable_id < 0) { l_drawable_id = gimp_channel_new (image_id, channel_name, cinfo.output_width, cinfo.output_height, channel_opacity, &l_color); if(l_drawable_id < 0) { g_printerr ("XJT: cant create new channel\n"); fclose (infile); return -1; } } else { l_drawable_id = drawable_id; /* overwrite the given drawable */ } l_drawable = gimp_drawable_get (l_drawable_id); if((l_drawable->width != cinfo.output_width) || (l_drawable->height != cinfo.output_height) || (l_drawable->bpp != cinfo.output_components) ) { g_printerr ("XJT: cant load-overwrite drawable (size missmatch)\n"); fclose (infile); return -1; } gimp_pixel_rgn_init (&l_pixel_rgn, l_drawable, 0, 0, l_drawable->width, l_drawable->height, TRUE, FALSE); /* Step 6: while (scan lines remain to be read) */ /* jpeg_read_scanlines(...); */ /* Here we use the library's state variable cinfo.output_scanline as the * loop counter, so that we don't have to keep track ourselves. */ while (cinfo.output_scanline < cinfo.output_height) { l_start = cinfo.output_scanline; l_end = cinfo.output_scanline + l_tile_height; l_end = MIN (l_end, cinfo.output_height); l_scanlines = l_end - l_start; for (l_idx = 0; l_idx < l_scanlines; l_idx++) { jpeg_read_scanlines (&cinfo, (JSAMPARRAY) &l_rowbuf[l_idx], 1); } gimp_pixel_rgn_set_rect (&l_pixel_rgn, l_buf, 0, l_start, l_drawable->width, l_scanlines); gimp_progress_update ((double) cinfo.output_scanline / (double) cinfo.output_height); } gimp_progress_update (1.0); /* Step 7: Finish decompression */ jpeg_finish_decompress (&cinfo); /* We can ignore the return value since suspension is not possible * with the stdio data source. */ /* Step 8: Release JPEG decompression object */ /* This is an important step since it will release a good deal of memory. */ jpeg_destroy_decompress (&cinfo); /* free up the temporary buffers */ g_free (l_rowbuf); g_free (l_buf); /* After finish_decompress, we can close the input file. * Here we postpone it until after no more JPEG errors are possible, * so as to simplify the setjmp error logic above. (Actually, I don't * think that jpeg_destroy can do an error exit, but why assume anything...) */ fclose (infile); /* At this point you may want to check to see whether any corrupt-data * warnings occurred (test whether jerr.num_warnings is nonzero). */ /* Tell GIMP to display the image. */ /* gimp_drawable_flush (l_drawable); */ return (l_drawable_id); } /* end xjpg_load_channel */
GimpParam * pygimp_param_from_tuple(PyObject *args, const GimpParamDef *ptype, int nparams) { PyObject *tuple, *item, *r, *g, *b, *x, *y, *w, *h; GimpParam *ret; int i, j, len; gint32 *i32a; gint16 *i16a; guint8 *i8a; gdouble *fa; gchar **sa; if (nparams == 0) tuple = PyTuple_New(0); else if (!PyTuple_Check(args) && nparams == 1) tuple = Py_BuildValue("(O)", args); else { Py_INCREF(args); tuple = args; } if (!PyTuple_Check(tuple)) { PyErr_SetString(PyExc_TypeError, "wrong type of parameter"); Py_DECREF(tuple); return NULL; } if (PyTuple_Size(tuple) != nparams) { PyErr_SetString(PyExc_TypeError, "wrong number of parameters"); Py_DECREF(tuple); return NULL; } ret = g_new(GimpParam, nparams+1); for (i = 0; i <= nparams; i++) ret[i].type = GIMP_PDB_STATUS; #define check(expr) if (expr) { \ PyErr_SetString(PyExc_TypeError, "wrong parameter type"); \ Py_DECREF(tuple); \ gimp_destroy_params(ret, nparams); \ return NULL; \ } #define arraycheck(expr, ar) if (expr) { \ PyErr_SetString(PyExc_TypeError, "subscript of wrong type"); \ Py_DECREF(tuple); \ gimp_destroy_params(ret, nparams); \ g_free(ar); \ return NULL; \ } for (i = 1; i <= nparams; i++) { item = PyTuple_GetItem(tuple, i-1); switch (ptype[i-1].type) { case GIMP_PDB_INT32: check((x = PyNumber_Int(item)) == NULL); ret[i].data.d_int32 = (gint32)PyInt_AsLong(x); Py_DECREF(x); break; case GIMP_PDB_INT16: check((x = PyNumber_Int(item)) == NULL); ret[i].data.d_int16 = (gint16)PyInt_AsLong(x); Py_DECREF(x); break; case GIMP_PDB_INT8: check((x = PyNumber_Int(item)) == NULL); ret[i].data.d_int8 = (guint8)PyInt_AsLong(x); Py_DECREF(x); break; case GIMP_PDB_FLOAT: check((x = PyNumber_Float(item)) == NULL); ret[i].data.d_float = PyFloat_AsDouble(x); Py_DECREF(x); break; case GIMP_PDB_STRING: if (item == Py_None) { ret[i].data.d_string = NULL; break; } check((x = PyObject_Str(item)) == NULL); ret[i].data.d_string = g_strdup(PyString_AsString(x)); Py_DECREF(x); break; case GIMP_PDB_INT32ARRAY: check(!PySequence_Check(item)); len = PySequence_Length(item); i32a = g_new(gint32, len); for (j = 0; j < len; j++) { x = PySequence_GetItem(item, j); arraycheck((y=PyNumber_Int(x))==NULL, i32a); i32a[j] = PyInt_AsLong(y); Py_DECREF(y); } ret[i].data.d_int32array = i32a; break; case GIMP_PDB_INT16ARRAY: check(!PySequence_Check(item)); len = PySequence_Length(item); i16a = g_new(gint16, len); for (j = 0; j < len; j++) { x = PySequence_GetItem(item, j); arraycheck((y=PyNumber_Int(x))==NULL, i16a); i16a[j] = PyInt_AsLong(y); Py_DECREF(y); } ret[i].data.d_int16array = i16a; break; case GIMP_PDB_INT8ARRAY: check(!PySequence_Check(item)); len = PySequence_Length(item); i8a = g_new(guint8, len); for (j = 0; j < len; j++) { x = PySequence_GetItem(item, j); arraycheck((y=PyNumber_Int(x))==NULL, i8a); i8a[j] = PyInt_AsLong(y); Py_DECREF(y); } ret[i].data.d_int8array = i8a; break; case GIMP_PDB_FLOATARRAY: check(!PySequence_Check(item)); len = PySequence_Length(item); fa = g_new(gdouble, len); for (j = 0; j < len; j++) { x = PySequence_GetItem(item, j); arraycheck((y=PyNumber_Float(x))==NULL, fa); fa[j] = PyFloat_AsDouble(y); Py_DECREF(y); } ret[i].data.d_floatarray = fa; break; case GIMP_PDB_STRINGARRAY: check(!PySequence_Check(item)); len = PySequence_Length(item); sa = g_new(gchar *, len); for (j = 0; j < len; j++) { x = PySequence_GetItem(item, j); if (x == Py_None) { sa[j] = NULL; continue; } arraycheck((y=PyObject_Str(x))==NULL, sa); sa[j] = g_strdup(PyString_AsString(y)); Py_DECREF(y); } ret[i].data.d_stringarray = sa; break; case GIMP_PDB_COLOR: { GimpRGB *rgb, tmprgb; if (!pygimp_rgb_check(item)) { check(!PySequence_Check(item) || PySequence_Length(item) < 3); r = PySequence_GetItem(item, 0); g = PySequence_GetItem(item, 1); b = PySequence_GetItem(item, 2); check(!PyInt_Check(r) || !PyInt_Check(g) || !PyInt_Check(b)); gimp_rgba_set_uchar(&tmprgb, PyInt_AsLong(r), PyInt_AsLong(g), PyInt_AsLong(b), 255); rgb = &tmprgb; } else { rgb = pyg_boxed_get(item, GimpRGB); } ret[i].data.d_color = *rgb; } break; case GIMP_PDB_REGION: check(!PySequence_Check(item) || PySequence_Length(item) < 4); x = PySequence_GetItem(item, 0); y = PySequence_GetItem(item, 1); w = PySequence_GetItem(item, 2); h = PySequence_GetItem(item, 3); check(!PyInt_Check(x) || !PyInt_Check(y) || !PyInt_Check(w) || !PyInt_Check(h)); ret[i].data.d_region.x = PyInt_AsLong(x); ret[i].data.d_region.y = PyInt_AsLong(y); ret[i].data.d_region.width = PyInt_AsLong(w); ret[i].data.d_region.height = PyInt_AsLong(h); break; case GIMP_PDB_DISPLAY: check(!pygimp_display_check(item)); ret[i].data.d_display = ((PyGimpDisplay *)item)->ID; break; case GIMP_PDB_IMAGE: if (item == Py_None) { ret[i].data.d_image = -1; break; } check(!pygimp_image_check(item)); ret[i].data.d_image = ((PyGimpImage *)item)->ID; break; case GIMP_PDB_LAYER: if (item == Py_None) { ret[i].data.d_layer = -1; break; } check(!pygimp_layer_check(item)); ret[i].data.d_layer = ((PyGimpLayer *)item)->ID; break; case GIMP_PDB_CHANNEL: if (item == Py_None) { ret[i].data.d_channel = -1; break; } check(!pygimp_channel_check(item)); ret[i].data.d_channel = ((PyGimpChannel *)item)->ID; break; case GIMP_PDB_DRAWABLE: if (item == Py_None) { ret[i].data.d_channel = -1; break; } check(!pygimp_drawable_check(item)); ret[i].data.d_channel = ((PyGimpDrawable *)item)->ID; break; case GIMP_PDB_SELECTION: check(!pygimp_layer_check(item)); ret[i].data.d_selection = ((PyGimpLayer *)item)->ID; break; case GIMP_PDB_BOUNDARY: check(!PyInt_Check(item)); ret[i].data.d_boundary = PyInt_AsLong(item); break; case GIMP_PDB_VECTORS: check(!pygimp_vectors_check(item)); ret[i].data.d_vectors = ((PyGimpVectors *)item)->ID; break; case GIMP_PDB_PARASITE: /* can't do anything, since size of GimpParasite is not known */ break; case GIMP_PDB_STATUS: check(!PyInt_Check(item)); ret[i].data.d_status = PyInt_AsLong(item); break; case GIMP_PDB_END: break; } #undef check #undef arraycheck ret[i].type = ptype[i-1].type; } Py_DECREF(tuple); return ret; }
static void set_values (const gchar *key, const gchar *val) { if (!strcmp (key, "desc")) parse_desc (val, presetdesc, sizeof (presetdesc)); else if (!strcmp (key, "orientnum")) pcvals.orient_num = atoi (val); else if (!strcmp (key, "orientfirst")) pcvals.orient_first = g_ascii_strtod (val, NULL); else if (!strcmp (key, "orientlast")) pcvals.orient_last = g_ascii_strtod (val, NULL); else if (!strcmp (key, "orienttype")) pcvals.orient_type = orientation_type_input (atoi (val)); else if (!strcmp (key, "sizenum")) pcvals.size_num = atoi (val); else if (!strcmp (key, "sizefirst")) pcvals.size_first = g_ascii_strtod (val, NULL); else if (!strcmp (key, "sizelast")) pcvals.size_last = g_ascii_strtod (val, NULL); else if (!strcmp (key, "sizetype")) pcvals.size_type = size_type_input (atoi (val)); else if (!strcmp (key, "brushrelief")) pcvals.brush_relief = g_ascii_strtod (val, NULL); else if (!strcmp (key, "brushscale")) { /* For compatibility */ pcvals.size_num = 1; pcvals.size_first = pcvals.size_last = g_ascii_strtod (val, NULL); } else if (!strcmp (key, "brushdensity")) pcvals.brush_density = g_ascii_strtod (val, NULL); else if (!strcmp (key, "brushgamma")) pcvals.brushgamma = g_ascii_strtod (val, NULL); else if (!strcmp (key, "brushaspect")) pcvals.brush_aspect = g_ascii_strtod (val, NULL); else if (!strcmp (key, "generalbgtype")) pcvals.general_background_type = general_bg_type_input (atoi (val)); else if (!strcmp (key, "generaldarkedge")) pcvals.general_dark_edge = g_ascii_strtod (val, NULL); else if (!strcmp (key, "generalpaintedges")) pcvals.general_paint_edges = atoi (val); else if (!strcmp (key, "generaltileable")) pcvals.general_tileable = atoi (val); else if (!strcmp (key, "generaldropshadow")) pcvals.general_drop_shadow = atoi (val); else if (!strcmp (key, "generalshadowdarkness")) pcvals.general_shadow_darkness = g_ascii_strtod (val, NULL); else if (!strcmp (key, "generalshadowdepth")) pcvals.general_shadow_depth = atoi (val); else if (!strcmp (key, "generalshadowblur")) pcvals.general_shadow_blur = atoi (val); else if (!strcmp (key, "devthresh")) pcvals.devthresh = g_ascii_strtod (val, NULL); else if (!strcmp (key, "paperrelief")) pcvals.paper_relief = g_ascii_strtod (val, NULL); else if (!strcmp (key, "paperscale")) pcvals.paper_scale = g_ascii_strtod (val, NULL); else if (!strcmp (key, "paperinvert")) pcvals.paper_invert = atoi (val); else if (!strcmp (key, "paperoverlay")) pcvals.paper_overlay = atoi (val); else if (!strcmp (key, "placetype")) pcvals.place_type = place_type_input (atoi (val)); else if (!strcmp (key, "placecenter")) pcvals.placement_center = atoi (val); else if (!strcmp (key, "selectedbrush")) g_strlcpy (pcvals.selected_brush, val, sizeof (pcvals.selected_brush)); else if (!strcmp (key, "selectedpaper")) g_strlcpy (pcvals.selected_paper, val, sizeof (pcvals.selected_paper)); else if (!strcmp (key, "color")) { char *c = parse_rgb_string (val); gimp_rgba_set_uchar (&pcvals.color, c[0], c[1], c[2], 255); } else if (!strcmp (key, "numorientvector")) pcvals.num_orient_vectors = atoi (val); else if (!strcmp (key, "orientvector")) set_orient_vector (val); else if (!strcmp (key, "orientangoff")) pcvals.orient_angle_offset = g_ascii_strtod (val, NULL); else if (!strcmp (key, "orientstrexp")) pcvals.orient_strength_exponent = g_ascii_strtod (val, NULL); else if (!strcmp (key, "orientvoronoi")) pcvals.orient_voronoi = atoi (val); else if (!strcmp (key, "numsizevector")) pcvals.num_size_vectors = atoi (val); else if (!strcmp (key, "sizevector")) set_size_vector (val); else if (!strcmp (key, "sizestrexp")) pcvals.size_strength_exponent = g_ascii_strtod (val, NULL); else if (!strcmp (key, "sizevoronoi")) pcvals.size_voronoi = atoi (val); else if (!strcmp (key, "colortype")) pcvals.color_type = color_type_input (atoi (val)); else if (!strcmp (key, "colornoise")) pcvals.color_noise = g_ascii_strtod (val, NULL); }
static void gimp_color_config_class_init (GimpColorConfigClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpRGB color; gimp_rgba_set_uchar (&color, 0x80, 0x80, 0x80, 0xff); object_class->finalize = gimp_color_config_finalize; object_class->set_property = gimp_color_config_set_property; object_class->get_property = gimp_color_config_get_property; GIMP_CONFIG_PROP_ENUM (object_class, PROP_MODE, "mode", _("Mode of operation"), COLOR_MANAGEMENT_MODE_BLURB, GIMP_TYPE_COLOR_MANAGEMENT_MODE, GIMP_COLOR_MANAGEMENT_DISPLAY, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_PATH (object_class, PROP_RGB_PROFILE, "rgb-profile", _("Preferred RGB profile"), RGB_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_PATH (object_class, PROP_GRAY_PROFILE, "gray-profile", _("Preferred grayscale profile"), GRAY_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_PATH (object_class, PROP_CMYK_PROFILE, "cmyk-profile", _("CMYK profile"), CMYK_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_PATH (object_class, PROP_DISPLAY_PROFILE, "display-profile", _("Monitor profile"), DISPLAY_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_DISPLAY_PROFILE_FROM_GDK, "display-profile-from-gdk", _("Use the system monitor profile"), DISPLAY_PROFILE_FROM_GDK_BLURB, FALSE, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_PATH (object_class, PROP_PRINTER_PROFILE, "printer-profile", _("Print simulation profile"), PRINTER_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_DISPLAY_RENDERING_INTENT, "display-rendering-intent", _("Display rendering intent"), DISPLAY_RENDERING_INTENT_BLURB, GIMP_TYPE_COLOR_RENDERING_INTENT, GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_DISPLAY_USE_BPC, "display-use-black-point-compensation", _("Use black point compensation for the display"), DISPLAY_USE_BPC_BLURB, TRUE, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_ENUM (object_class, PROP_SIMULATION_RENDERING_INTENT, "simulation-rendering-intent", _("Softproof rendering intent"), SIMULATION_RENDERING_INTENT_BLURB, GIMP_TYPE_COLOR_RENDERING_INTENT, GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SIMULATION_USE_BPC, "simulation-use-black-point-compensation", _("Use black point compensation for softproofing"), SIMULATION_USE_BPC_BLURB, FALSE, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SIMULATION_GAMUT_CHECK, "simulation-gamut-check", _("Mark out of gamut colors"), SIMULATION_GAMUT_CHECK_BLURB, FALSE, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_RGB (object_class, PROP_OUT_OF_GAMUT_COLOR, "out-of-gamut-color", _("Out of gammut warning color"), OUT_OF_GAMUT_COLOR_BLURB, FALSE, &color, GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_PROP_STRING (object_class, PROP_DISPLAY_MODULE, "display-module", NULL, NULL, "CdisplayLcms", GIMP_PARAM_STATIC_STRINGS); }
gboolean gimp_pickable_pick_color (GimpPickable *pickable, gint x, gint y, gboolean sample_average, gdouble average_radius, GimpRGB *color, gint *color_index) { GimpImage *image; GimpImageType type; guchar pixel[4]; guchar col[4]; g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), FALSE); if (! gimp_pickable_get_pixel_at (pickable, x, y, pixel)) return FALSE; image = gimp_pickable_get_image (pickable); type = gimp_pickable_get_image_type (pickable); if (sample_average) { gint count = 0; gint color_avg[4] = { 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, pixel)) { count++; gimp_image_get_color (image, type, pixel, col); color_avg[RED] += col[RED]; color_avg[GREEN] += col[GREEN]; color_avg[BLUE] += col[BLUE]; color_avg[ALPHA] += col[ALPHA]; } col[RED] = (guchar) ((color_avg[RED] + count / 2) / count); col[GREEN] = (guchar) ((color_avg[GREEN] + count / 2) / count); col[BLUE] = (guchar) ((color_avg[BLUE] + count / 2) / count); col[ALPHA] = (guchar) ((color_avg[ALPHA] + count / 2) / count); } else { gimp_image_get_color (image, type, pixel, col); } gimp_rgba_set_uchar (color, col[RED], col[GREEN], col[BLUE], col[ALPHA]); if (color_index) { if (GIMP_IMAGE_TYPE_IS_INDEXED (type) && ! sample_average) *color_index = pixel[0]; else *color_index = -1; } return TRUE; }
GList * gimp_palette_load_psp (GimpContext *context, GFile *file, GInputStream *input, GError **error) { GimpPalette *palette; gchar *palette_name; guchar color_bytes[4]; gint number_of_colors; gsize bytes_read; gint i, j; gboolean color_ok; gchar buffer[4096]; /*Maximum valid file size: 256 * 4 * 3 + 256 * 2 ~= 3650 bytes */ gchar **lines; gchar **ascii_colors; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); palette_name = g_path_get_basename (gimp_file_get_utf8_name (file)); palette = GIMP_PALETTE (gimp_palette_new (context, palette_name)); g_free (palette_name); if (! g_seekable_seek (G_SEEKABLE (input), 16, G_SEEK_SET, NULL, error)) { g_object_unref (palette); return NULL; } if (! g_input_stream_read_all (input, buffer, sizeof (buffer) - 1, &bytes_read, NULL, error)) { g_object_unref (palette); return NULL; } buffer[bytes_read] = '\0'; lines = g_strsplit (buffer, "\x0d\x0a", -1); number_of_colors = atoi (lines[0]); for (i = 0; i < number_of_colors; i++) { if (lines[i + 1] == NULL) { g_printerr ("Premature end of file reading %s.", gimp_file_get_utf8_name (file)); break; } ascii_colors = g_strsplit (lines[i + 1], " ", 3); color_ok = TRUE; for (j = 0 ; j < 3; j++) { if (ascii_colors[j] == NULL) { g_printerr ("Corrupted palette file %s.", gimp_file_get_utf8_name (file)); color_ok = FALSE; break; } color_bytes[j] = atoi (ascii_colors[j]); } if (color_ok) { GimpRGB color; gimp_rgba_set_uchar (&color, color_bytes[0], color_bytes[1], color_bytes[2], 255); gimp_palette_add_entry (palette, -1, NULL, &color); } g_strfreev (ascii_colors); } g_strfreev (lines); return g_list_prepend (NULL, palette); }
GList * gimp_palette_load (GimpContext *context, GFile *file, GInputStream *input, GError **error) { GimpPalette *palette = NULL; GimpPaletteEntry *entry; GDataInputStream *data_input; gchar *str; gsize str_len; gchar *tok; gint r, g, b; gint linenum; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); data_input = g_data_input_stream_new (input); r = g = b = 0; linenum = 1; str_len = 1024; str = gimp_data_input_stream_read_line_always (data_input, &str_len, NULL, error); if (! str) goto failed; if (! g_str_has_prefix (str, "GIMP Palette")) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Missing magic header.")); g_free (str); goto failed; } g_free (str); palette = g_object_new (GIMP_TYPE_PALETTE, "mime-type", "application/x-gimp-palette", NULL); linenum++; str_len = 1024; str = gimp_data_input_stream_read_line_always (data_input, &str_len, NULL, error); if (! str) goto failed; if (g_str_has_prefix (str, "Name: ")) { gchar *utf8; utf8 = gimp_any_to_utf8 (g_strstrip (str + strlen ("Name: ")), -1, _("Invalid UTF-8 string in palette file '%s'"), gimp_file_get_utf8_name (file)); gimp_object_take_name (GIMP_OBJECT (palette), utf8); g_free (str); linenum++; str_len = 1024; str = gimp_data_input_stream_read_line_always (data_input, &str_len, NULL, error); if (! str) goto failed; if (g_str_has_prefix (str, "Columns: ")) { gint columns; if (! gimp_ascii_strtoi (g_strstrip (str + strlen ("Columns: ")), NULL, 10, &columns)) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, _("Invalid column count.")); g_free (str); goto failed; } if (columns < 0 || columns > 256) { g_message (_("Reading palette file '%s': " "Invalid number of columns in line %d. " "Using default value."), gimp_file_get_utf8_name (file), linenum); columns = 0; } gimp_palette_set_columns (palette, columns); g_free (str); linenum++; str_len = 1024; str = gimp_data_input_stream_read_line_always (data_input, &str_len, NULL, error); if (! str) goto failed; } } else /* old palette format */ { gimp_object_take_name (GIMP_OBJECT (palette), g_path_get_basename (gimp_file_get_utf8_name (file))); } while (str) { GError *my_error = NULL; if (str[0] != '#' && str[0] != '\0') { tok = strtok (str, " \t"); if (tok) r = atoi (tok); else g_message (_("Reading palette file '%s': " "Missing RED component in line %d."), gimp_file_get_utf8_name (file), linenum); tok = strtok (NULL, " \t"); if (tok) g = atoi (tok); else g_message (_("Reading palette file '%s': " "Missing GREEN component in line %d."), gimp_file_get_utf8_name (file), linenum); tok = strtok (NULL, " \t"); if (tok) b = atoi (tok); else g_message (_("Reading palette file '%s': " "Missing BLUE component in line %d."), gimp_file_get_utf8_name (file), linenum); /* optional name */ tok = strtok (NULL, "\n"); if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) g_message (_("Reading palette file '%s': " "RGB value out of range in line %d."), gimp_file_get_utf8_name (file), linenum); /* don't call gimp_palette_add_entry here, it's rather inefficient */ entry = g_slice_new0 (GimpPaletteEntry); gimp_rgba_set_uchar (&entry->color, (guchar) r, (guchar) g, (guchar) b, 255); entry->name = g_strdup (tok ? tok : _("Untitled")); entry->position = gimp_palette_get_n_colors (palette); palette->colors = g_list_prepend (palette->colors, entry); palette->n_colors++; } g_free (str); linenum++; str_len = 1024; str = g_data_input_stream_read_line (data_input, &str_len, NULL, &my_error); if (! str && my_error) { g_message (_("Reading palette file '%s': " "Read %d colors from truncated file: %s"), gimp_file_get_utf8_name (file), g_list_length (palette->colors), my_error->message); g_clear_error (&my_error); } } palette->colors = g_list_reverse (palette->colors); g_object_unref (data_input); return g_list_prepend (NULL, palette); failed: g_object_unref (data_input); if (palette) g_object_unref (palette); g_prefix_error (error, _("In line %d of palette file: "), linenum); return NULL; }