static void colorsel_cmyk_adj_update (GtkAdjustment *adj, ColorselCmyk *module) { GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module); gint i; gdouble value; for (i = 0; i < 4; i++) if (module->adj[i] == adj) break; value = gtk_adjustment_get_value (adj) / 100.0; switch (i) { case 0: module->cmyk.c = value; break; case 1: module->cmyk.m = value; break; case 2: module->cmyk.y = value; break; case 3: module->cmyk.k = value; break; default: return; } if (module->cmyk2rgb) { gdouble cmyk_values[4]; gdouble rgb_values[3]; cmyk_values[0] = module->cmyk.c * 100.0; cmyk_values[1] = module->cmyk.m * 100.0; cmyk_values[2] = module->cmyk.y * 100.0; cmyk_values[3] = module->cmyk.k * 100.0; cmsDoTransform (module->cmyk2rgb, cmyk_values, rgb_values, 1); selector->rgb.r = rgb_values[0]; selector->rgb.g = rgb_values[1]; selector->rgb.b = rgb_values[2]; } else { gimp_cmyk_to_rgb (&module->cmyk, &selector->rgb); } gimp_rgb_to_hsv (&selector->rgb, &selector->hsv); gimp_color_selector_color_changed (selector); }
static VALUE rb_gimp_cmyk_to_rgb (VALUE self, VALUE cmyk) { GimpRGB rgb; gimp_cmyk_to_rgb(rb2GimpCMYKPtr(cmyk), &rgb); return GimpRGB2rb(&rgb); }
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); }
GList * gimp_palette_load_aco (GimpContext *context, GFile *file, GInputStream *input, GError **error) { GimpPalette *palette; gchar *palette_name; gint format_version; gint number_of_colors; gint i; gchar header[4]; 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); if (! g_input_stream_read_all (input, header, sizeof (header), &bytes_read, NULL, error) || bytes_read != sizeof (header)) { g_prefix_error (error, _("Could not read header from palette file '%s': "), gimp_file_get_utf8_name (file)); return 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); format_version = header[1] + (header[0] << 8); number_of_colors = header[3] + (header[2] << 8); for (i = 0; i < number_of_colors; i++) { gchar color_info[10]; gint color_space; gint w, x, y, z; gboolean color_ok = FALSE; GimpRGB color; GError *my_error = NULL; if (! g_input_stream_read_all (input, color_info, sizeof (color_info), &bytes_read, NULL, &my_error) || bytes_read != sizeof (color_info)) { if (palette->colors) { 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 ? my_error->message : _("Premature end of file.")); g_clear_error (&my_error); break; } g_propagate_error (error, my_error); g_object_unref (palette); return NULL; } 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_file_get_utf8_name (file)); } if (format_version == 2) { gchar format2_preamble[4]; gint number_of_chars; if (! g_input_stream_read_all (input, format2_preamble, sizeof (format2_preamble), &bytes_read, NULL, error) || bytes_read != sizeof (format2_preamble)) { g_object_unref (palette); return NULL; } number_of_chars = format2_preamble[3] + (format2_preamble[2] << 8); if (! g_seekable_seek (G_SEEKABLE (input), number_of_chars * 2, G_SEEK_SET, NULL, error)) { g_object_unref (palette); return NULL; } } if (color_ok) gimp_palette_add_entry (palette, -1, NULL, &color); } return g_list_prepend (NULL, palette); }