--- gimp-2.6.8.orig/app/config/gimpdisplayconfig.h 2009-07-21 05:20:50 +0900 +++ gimp-2.6.8/app/config/gimpdisplayconfig.h 2010-03-15 09:22:36 +0900 @@ -27,7 +27,7 @@ #include "config/gimpcoreconfig.h" -#define GIMP_CONFIG_DEFAULT_IMAGE_TITLE_FORMAT "%D*%f-%p.%i (%t, %L) %wx%h" +#define GIMP_CONFIG_DEFAULT_IMAGE_TITLE_FORMAT "%D*%f-%p.%i (%t[%c], %L) %wx%h" #define GIMP_CONFIG_DEFAULT_IMAGE_STATUS_FORMAT "%n (%m)" --- gimp-2.6.8.orig/app/core/gimpimage-convert.c 2009-07-21 05:46:25 +0900 +++ gimp-2.6.8/app/core/gimpimage-convert.c 2010-03-16 11:07:15 +0900 @@ -1068,6 +1068,27 @@ break; } + + /* TODO: attach or remove the ICC profile */ + switch (new_type) + { + case GIMP_RGB: + case GIMP_INDEXED: + if (gimp_image_parasite_find (image, "icc-profile") && old_type == GIMP_GRAY) + gimp_image_parasite_detach (image, "icc-profile"); + else + gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image)); + break; + case GIMP_GRAY: + if (gimp_image_parasite_find (image, "icc-profile")) + gimp_image_parasite_detach (image, "icc-profile"); + else + gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image)); + break; + default: + break; + } + /* Delete the quantizer object, if there is one */ if (quantobj) quantobj->delete_func (quantobj); --- gimp-2.6.8.orig/app/core/gimpimage.c 2009-07-21 05:20:50 +0900 +++ gimp-2.6.8/app/core/gimpimage.c 2010-03-15 09:22:36 +0900 @@ -194,6 +194,7 @@ static const guint8 * gimp_image_get_icc_profile (GimpColorManaged *managed, gsize *len); +static GimpImageBaseType gimp_image_get_base_type (GimpColorManaged *managed); static const gint valid_combinations[][MAX_CHANNELS + 1] = @@ -581,6 +582,7 @@ gimp_color_managed_iface_init (GimpColorManagedInterface *iface) { iface->get_icc_profile = gimp_image_get_icc_profile; + iface->get_base_type = gimp_image_base_type; } static void --- gimp-2.6.8.orig/app/dialogs/preferences-dialog.c 2009-07-21 05:20:50 +0900 +++ gimp-2.6.8/app/dialogs/preferences-dialog.c 2010-03-15 17:49:15 +0900 @@ -2439,13 +2439,15 @@ profiles[] = { { N_("_RGB profile:"), - N_("Select RGB Color Profile"), "rgb-profile" }, + N_("Select RGB Color Profile"), "rgb-profile" }, + { N_("_Grayscale profile:"), + N_("Select Grayscale Color Profile"), "gray-profile" }, { N_("_CMYK profile:"), - N_("Select CMYK Color Profile"), "cmyk-profile" }, + N_("Select CMYK Color Profile"), "cmyk-profile" }, { N_("_Monitor profile:"), - N_("Select Monitor Color Profile"), "display-profile" }, + N_("Select Monitor Color Profile"), "display-profile" }, { N_("_Print simulation profile:"), - N_("Select Printer Color Profile"), "printer-profile" } + N_("Select Printer Color Profile"), "printer-profile" } }; GObject *color_config; --- gimp-2.6.8.orig/app/display/gimpdisplayshell-title.c 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/app/display/gimpdisplayshell-title.c 2010-03-15 17:20:31 +0900 @@ -188,6 +188,53 @@ title[i++] = '%'; break; + case 'c': /* attached color profile */ + { + GimpParasite *p; + + p = gimp_image_parasite_find (image, "icc-profile"); + + if (shell->icc_profile != p) + { + g_free (shell->profile_desc); + shell->profile_desc = NULL; + + if (p) + { + GError *error = NULL; + + if (plug_in_icc_profile_info (image, + gimp_get_user_context (image->gimp), + NULL, + NULL, &shell->profile_desc, NULL, + &error)) + { + gchar *tmp; + GRegex *regex = g_regex_new ("%", 0, 0, NULL); + + tmp = g_regex_replace (regex, shell->profile_desc, -1, 0, "%%", 0, NULL); + + if (tmp) + { + g_free (shell->profile_desc); + shell->profile_desc = tmp; + } + + g_regex_unref (regex); + } + else + shell->profile_desc = g_strdup (_("Unknown")); + } + else + shell->profile_desc = g_strdup (_("No profiles embedded")); + + shell->icc_profile = p; + } + + i += print (title, title_len, i, shell->profile_desc); + } + break; + case 'f': /* pruned filename */ { const gchar *uri = gimp_image_get_uri (image); --- gimp-2.6.8.orig/app/display/gimpdisplayshell.c 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/app/display/gimpdisplayshell.c 2010-03-15 09:22:36 +0900 @@ -141,6 +141,8 @@ static const guint8 * gimp_display_shell_get_icc_profile (GimpColorManaged *managed, gsize *len); +static GimpImageBaseType gimp_display_shell_get_base_type + (GimpColorManaged *managed); G_DEFINE_TYPE_WITH_CODE (GimpDisplayShell, gimp_display_shell, GIMP_TYPE_WINDOW, @@ -353,6 +355,9 @@ shell->last_motion_distance = 0.0; shell->last_motion_delta_time = 0.0; + shell->icc_profile = NULL; + shell->profile_desc = g_strdup (_("No profiles embedded")); + gtk_window_set_role (GTK_WINDOW (shell), "gimp-image-window"); gtk_window_set_resizable (GTK_WINDOW (shell), TRUE); @@ -389,6 +394,7 @@ gimp_color_managed_iface_init (GimpColorManagedInterface *iface) { iface->get_icc_profile = gimp_display_shell_get_icc_profile; + iface->get_base_type = gimp_display_shell_get_base_type; } static void @@ -407,6 +413,8 @@ if (shell->no_image_options) g_object_unref (shell->no_image_options); + g_free (shell->profile_desc); + G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -764,6 +772,18 @@ return NULL; } +static GimpImageBaseType +gimp_display_shell_get_base_type (GimpColorManaged *managed) +{ + GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (managed); + GimpImage *image = shell->display->image; + + if (image) + return gimp_color_managed_get_base_type (GIMP_COLOR_MANAGED (image)); + + return GIMP_RGB; +} + static void gimp_display_shell_zoom_button_callback (GimpDisplayShell *shell, GtkWidget *zoom_button) --- gimp-2.6.8.orig/app/display/gimpdisplayshell.h 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/app/display/gimpdisplayshell.h 2010-03-15 09:22:36 +0900 @@ -198,6 +198,8 @@ gdouble last_motion_delta_y; gdouble last_motion_distance; + GimpParasite *icc_profile; + gchar *profile_desc; }; struct _GimpDisplayShellClass --- gimp-2.6.8.orig/docs/gimprc.5.in 2009-08-14 04:36:18 +0900 +++ gimp-2.6.8/docs/gimprc.5.in 2010-03-16 11:38:32 +0900 @@ -418,7 +418,7 @@ paint tool. Possible values are yes and no. .TP -(image-title-format "%D*%f-%p.%i (%t, %L) %wx%h") +(image-title-format "%D*%f-%p.%i (%t[%c], %L) %wx%h") Sets the text to appear in image window titles. This is a format string; certain % character sequences are recognised and expanded as follows: @@ -473,6 +473,8 @@ .br %U unit abbreviation .br +%c attached color profile +.br .br --- gimp-2.6.8.orig/etc/gimprc 2009-08-14 04:36:18 +0900 +++ gimp-2.6.8/etc/gimprc 2010-03-16 11:52:10 +0900 @@ -367,9 +367,10 @@ # %H image height in real-world units # %u unit symbol # %U unit abbreviation +# %c attached color profile # # -# (image-title-format "%D*%f-%p.%i (%t, %L) %wx%h") +# (image-title-format "%D*%f-%p.%i (%t[%c], %L) %wx%h") # Sets the text to appear in image window status bars. This is a format # string; certain % character sequences are recognised and expanded as @@ -399,6 +400,7 @@ # %H image height in real-world units # %u unit symbol # %U unit abbreviation +# %c attached color profile # # # (image-status-format "%n (%m)") --- gimp-2.6.8.orig/libgimpcolor/gimpcolor.def 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/libgimpcolor/gimpcolor.def 2010-03-15 10:08:39 +0900 @@ -17,6 +17,7 @@ gimp_cmyka_set gimp_cmyka_set_uchar gimp_color_managed_get_icc_profile + gimp_color_managed_get_base_type gimp_color_managed_interface_get_type gimp_color_managed_profile_changed gimp_hsl_get_type --- gimp-2.6.8.orig/libgimpcolor/gimpcolormanaged.c 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/libgimpcolor/gimpcolormanaged.c 2010-03-15 09:25:42 +0900 @@ -120,6 +120,29 @@ } /** + * gimp_color_managed_get_base_type: + * @managed: an object the implements the #GimpColorManaged interface + * + * Return value: Base type of GimpImage. + * + * Since: GIMP 2.6 + **/ +GimpImageBaseType +gimp_color_managed_get_base_type (GimpColorManaged *managed) +{ + GimpColorManagedInterface *iface; + + g_return_val_if_fail (GIMP_IS_COLOR_MANAGED (managed), 0); + + iface = GIMP_COLOR_MANAGED_GET_INTERFACE (managed); + + if (iface->get_base_type) + return iface->get_base_type (managed); + + return 0; +} + +/** * gimp_color_managed_profile_changed: * @managed: an object the implements the #GimpColorManaged interface * --- gimp-2.6.8.orig/libgimpcolor/gimpcolormanaged.h 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/libgimpcolor/gimpcolormanaged.h 2010-03-15 09:22:30 +0900 @@ -23,6 +23,8 @@ #ifndef __GIMP_COLOR_MANAGED_H__ #define __GIMP_COLOR_MANAGED_H__ +#include + G_BEGIN_DECLS /* For information look into the C source or the html documentation */ @@ -41,19 +43,21 @@ GTypeInterface base_iface; /* virtual functions */ - const guint8 * (* get_icc_profile) (GimpColorManaged *managed, - gsize *len); + const guint8 * (* get_icc_profile) (GimpColorManaged *managed, + gsize *len); + GimpImageBaseType (* get_base_type) (GimpColorManaged *managed); /* signals */ - void (* profile_changed) (GimpColorManaged *managed); + void (* profile_changed) (GimpColorManaged *managed); }; -GType gimp_color_managed_interface_get_type (void) G_GNUC_CONST; +GType gimp_color_managed_interface_get_type (void) G_GNUC_CONST; -const guint8 * gimp_color_managed_get_icc_profile (GimpColorManaged *managed, - gsize *len); -void gimp_color_managed_profile_changed (GimpColorManaged *managed); +const guint8 * gimp_color_managed_get_icc_profile (GimpColorManaged *managed, + gsize *len); +GimpImageBaseType gimp_color_managed_get_base_type (GimpColorManaged *managed); +void gimp_color_managed_profile_changed (GimpColorManaged *managed); G_END_DECLS --- gimp-2.6.8.orig/libgimpconfig/gimpcolorconfig.c 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/libgimpconfig/gimpcolorconfig.c 2010-03-15 17:49:15 +0900 @@ -48,6 +48,8 @@ "used as a fallback.") #define RGB_PROFILE_BLURB \ N_("The default RGB working space color profile.") +#define GRAY_PROFILE_BLURB \ + N_("The default Grayscale working space color profile.") #define CMYK_PROFILE_BLURB \ N_("The CMYK color profile used to convert between RGB and CMYK.") #define PRINTER_PROFILE_BLURB \ @@ -69,6 +71,7 @@ PROP_0, PROP_MODE, PROP_RGB_PROFILE, + PROP_GRAY_PROFILE, PROP_CMYK_PROFILE, PROP_DISPLAY_PROFILE, PROP_DISPLAY_PROFILE_FROM_GDK, @@ -121,6 +124,10 @@ "rgb-profile", RGB_PROFILE_BLURB, GIMP_CONFIG_PATH_FILE, NULL, GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_GRAY_PROFILE, + "gray-profile", GRAY_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, @@ -180,6 +187,9 @@ if (color_config->rgb_profile) g_free (color_config->rgb_profile); + if (color_config->gray_profile) + g_free (color_config->gray_profile); + if (color_config->cmyk_profile) g_free (color_config->cmyk_profile); @@ -212,6 +222,10 @@ g_free (color_config->rgb_profile); color_config->rgb_profile = g_value_dup_string (value); break; + case PROP_GRAY_PROFILE: + g_free (color_config->gray_profile); + color_config->gray_profile = g_value_dup_string (value); + break; case PROP_CMYK_PROFILE: g_free (color_config->cmyk_profile); color_config->cmyk_profile = g_value_dup_string (value); @@ -266,6 +280,9 @@ case PROP_RGB_PROFILE: g_value_set_string (value, color_config->rgb_profile); break; + case PROP_GRAY_PROFILE: + g_value_set_string (value, color_config->gray_profile); + break; case PROP_CMYK_PROFILE: g_value_set_string (value, color_config->cmyk_profile); break; --- gimp-2.6.8.orig/libgimpconfig/gimpcolorconfig.h 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/libgimpconfig/gimpcolorconfig.h 2010-03-15 17:49:15 +0900 @@ -40,6 +40,7 @@ /*< public >*/ GimpColorManagementMode mode; gchar *rgb_profile; + gchar *gray_profile; gchar *cmyk_profile; gchar *display_profile; gboolean display_profile_from_gdk; --- gimp-2.6.8.orig/modules/display-filter-lcms.c 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/modules/display-filter-lcms.c 2010-03-16 04:01:30 +0900 @@ -81,29 +81,31 @@ gint bpl); static void cdisplay_lcms_changed (GimpColorDisplay *display); -static cmsHPROFILE cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms); -static cmsHPROFILE cdisplay_lcms_get_display_profile (CdisplayLcms *lcms); -static cmsHPROFILE cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms); - -static void cdisplay_lcms_attach_labelled (GtkTable *table, - gint row, - const gchar *text, - GtkWidget *widget); -static void cdisplay_lcms_update_profile_label (CdisplayLcms *lcms, - const gchar *name); -static void cdisplay_lcms_notify_profile (GObject *config, - GParamSpec *pspec, - CdisplayLcms *lcms); +static cmsHPROFILE cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms); +static cmsHPROFILE cdisplay_lcms_get_gray_profile (CdisplayLcms *lcms); +static cmsHPROFILE cdisplay_lcms_create_gray22_profile (void); +static cmsHPROFILE cdisplay_lcms_get_display_profile (CdisplayLcms *lcms); +static cmsHPROFILE cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms); + +static void cdisplay_lcms_attach_labelled (GtkTable *table, + gint row, + const gchar *text, + GtkWidget *widget); +static void cdisplay_lcms_update_profile_label (CdisplayLcms *lcms, + const gchar *name); +static void cdisplay_lcms_notify_profile (GObject *config, + GParamSpec *pspec, + CdisplayLcms *lcms); static const GimpModuleInfo cdisplay_lcms_info = { GIMP_MODULE_ABI_VERSION, N_("Color management display filter using ICC color profiles"), - "Sven Neumann", - "v0.3", - "(c) 2005 - 2007, released under the GPL", - "2005 - 2007" + "Sven Neumann, Yoshinori Yamakawa", + "v0.3.1", + "(c) 2005 - 2010, released under the GPL", + "2005 - 2010" }; G_DEFINE_DYNAMIC_TYPE (CdisplayLcms, cdisplay_lcms, @@ -172,6 +174,7 @@ const gchar **name, const gchar **info) { + /* You should free name and info after use */ if (profile) { *name = cmsTakeProductDesc (profile); @@ -179,16 +182,16 @@ if (! *name) *name = cmsTakeProductName (profile); - if (*name && ! g_utf8_validate (*name, -1, NULL)) - *name = _("(invalid UTF-8 string)"); + if (*name) + *name = gimp_any_to_utf8 (*name, -1, NULL); *info = cmsTakeProductInfo (profile); - if (*name && ! g_utf8_validate (*info, -1, NULL)) - *info = NULL; + if (*info) + *info = gimp_any_to_utf8 (*info, -1, NULL); } else { - *name = _("None"); + *name = g_strdup (_("None")); *info = NULL; } } @@ -229,10 +232,12 @@ label = gtk_label_new (NULL); gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); g_object_set_data (G_OBJECT (lcms), "rgb-profile", label); + g_object_set_data (G_OBJECT (lcms), "gray-profile", label); cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++, _("Image profile:"), label); cdisplay_lcms_update_profile_label (lcms, "rgb-profile"); + cdisplay_lcms_update_profile_label (lcms, "gray-profile"); label = gtk_label_new (NULL); gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); @@ -281,13 +286,17 @@ static void cdisplay_lcms_changed (GimpColorDisplay *display) { - CdisplayLcms *lcms = CDISPLAY_LCMS (display); - GimpColorConfig *config = gimp_color_display_get_config (display); + CdisplayLcms *lcms = CDISPLAY_LCMS (display); + GimpColorManaged *managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms)); + GimpColorConfig *config = gimp_color_display_get_config (display); + + cmsHPROFILE src_profile = NULL; + cmsHPROFILE dest_profile = NULL; + cmsHPROFILE proof_profile = NULL; + DWORD flags = 0; + DWORD src_format; - cmsHPROFILE src_profile = NULL; - cmsHPROFILE dest_profile = NULL; - cmsHPROFILE proof_profile = NULL; - DWORD flags = 0; + GimpImageBaseType base_type = gimp_color_managed_get_base_type (managed); if (lcms->transform) { @@ -308,7 +317,7 @@ /* fallthru */ case GIMP_COLOR_MANAGEMENT_DISPLAY: - src_profile = cdisplay_lcms_get_rgb_profile (lcms); + src_profile = base_type == GIMP_GRAY ? cdisplay_lcms_get_gray_profile (lcms) : cdisplay_lcms_get_rgb_profile (lcms); dest_profile = cdisplay_lcms_get_display_profile (lcms); break; } @@ -319,10 +328,13 @@ flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } + src_format = base_type == GIMP_GRAY ? + COLORSPACE_SH (PT_GRAY) | EXTRA_SH (2) | CHANNELS_SH (1) | BYTES_SH (1) : TYPE_RGB_8; + if (proof_profile) { if (! src_profile) - src_profile = cmsCreate_sRGBProfile (); + src_profile = base_type == GIMP_GRAY ? cdisplay_lcms_create_gray22_profile () : cmsCreate_sRGBProfile (); if (! dest_profile) dest_profile = cmsCreate_sRGBProfile (); @@ -340,7 +352,7 @@ cmsSetAlarmCodes (r, g, b); } - lcms->transform = cmsCreateProofingTransform (src_profile, TYPE_RGB_8, + lcms->transform = cmsCreateProofingTransform (src_profile, src_format, dest_profile, TYPE_RGB_8, proof_profile, config->simulation_intent, @@ -351,12 +363,12 @@ else if (src_profile || dest_profile) { if (! src_profile) - src_profile = cmsCreate_sRGBProfile (); + src_profile = base_type == GIMP_GRAY ? cdisplay_lcms_create_gray22_profile () : cmsCreate_sRGBProfile (); if (! dest_profile) dest_profile = cmsCreate_sRGBProfile (); - lcms->transform = cmsCreateTransform (src_profile, TYPE_RGB_8, + lcms->transform = cmsCreateTransform (src_profile, src_format, dest_profile, TYPE_RGB_8, config->display_intent, flags); @@ -375,6 +387,12 @@ return (cmsGetColorSpace (profile) == icSigRgbData); } +static gboolean +cdisplay_lcms_profile_is_gray (cmsHPROFILE profile) +{ + return (cmsGetColorSpace (profile) == icSigGrayData); +} + static cmsHPROFILE cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms) { @@ -405,9 +423,79 @@ config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms)); if (config->rgb_profile) - profile = cmsOpenProfileFromFile (config->rgb_profile, "r"); + { + profile = cmsOpenProfileFromFile (config->rgb_profile, "r"); + + if (! cdisplay_lcms_profile_is_rgb (profile)) + { + cmsCloseProfile (profile); + profile = NULL; + } + } + } + + return profile; +} + +static cmsHPROFILE +cdisplay_lcms_get_gray_profile (CdisplayLcms *lcms) +{ + GimpColorConfig *config; + GimpColorManaged *managed; + cmsHPROFILE profile = NULL; + + managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms)); + + if (managed) + { + gsize len; + const guint8 *data = gimp_color_managed_get_icc_profile (managed, &len); + + if (data) + profile = cmsOpenProfileFromMem ((gpointer) data, len); + + if (profile && + ! cdisplay_lcms_profile_is_gray (profile)) + { + cmsCloseProfile (profile); + profile = NULL; + } } + if (! profile) + { + config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms)); + + if (config->gray_profile) + { + profile = cmsOpenProfileFromFile (config->gray_profile, "r"); + + if (! cdisplay_lcms_profile_is_gray (profile)) + { + cmsCloseProfile (profile); + profile = NULL; + } + + } + } + + return profile; +} + +static cmsHPROFILE +cdisplay_lcms_create_gray22_profile (void) +{ + cmsCIExyY wp = { 0.312705, 0.328990, 1.0 }; + LPGAMMATABLE transfer_func; + cmsHPROFILE profile; + + transfer_func = cmsBuildGamma (256, 2.2); + + profile = cmsCreateGrayProfile (&wp, transfer_func); + cmsAddTag (profile, icSigProfileDescriptionTag, "Gray Gamma 2.2"); + + cmsFreeGamma (transfer_func); + return profile; } @@ -631,17 +719,27 @@ { GtkWidget *label; cmsHPROFILE profile = NULL; - const gchar *text; - const gchar *tooltip; + gchar *text; + gchar *tooltip; + + GimpImageBaseType base_type; label = g_object_get_data (G_OBJECT (lcms), name); if (! label) return; + base_type = gimp_color_managed_get_base_type (gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms))); + if (strcmp (name, "rgb-profile") == 0) { - profile = cdisplay_lcms_get_rgb_profile (lcms); + if (base_type == GIMP_RGB || base_type == GIMP_INDEXED) + profile = cdisplay_lcms_get_rgb_profile (lcms); + } + else if (strcmp (name, "gray-profile") == 0) + { + if (base_type == GIMP_GRAY) + profile = cdisplay_lcms_get_gray_profile (lcms); } else if (g_str_has_prefix (name, "display-profile")) { @@ -661,6 +759,9 @@ gtk_label_set_text (GTK_LABEL (label), text); gimp_help_set_help_data (label, tooltip, NULL); + g_free (text); + g_free (tooltip); + if (profile) cmsCloseProfile (profile); } --- gimp-2.6.8.orig/plug-ins/common/lcms.c 2009-07-21 05:20:51 +0900 +++ gimp-2.6.8/plug-ins/common/lcms.c 2010-03-17 17:32:28 +0900 @@ -37,6 +37,7 @@ #define PLUG_IN_PROC_SET "plug-in-icc-profile-set" #define PLUG_IN_PROC_SET_RGB "plug-in-icc-profile-set-rgb" +#define PLUG_IN_PROC_SET_GRAY "plug-in-icc-profile-set-gray" #define PLUG_IN_PROC_APPLY "plug-in-icc-profile-apply" #define PLUG_IN_PROC_APPLY_RGB "plug-in-icc-profile-apply-rgb" @@ -58,6 +59,7 @@ { PROC_SET, PROC_SET_RGB, + PROC_SET_GRAY, PROC_APPLY, PROC_APPLY_RGB, PROC_INFO, @@ -77,6 +79,12 @@ gboolean bpc; } LcmsValues; +static gchar *gimp_image_base_type_name[] = +{ + N_("RGB"), + N_("Grayscale"), + N_("RGB") +}; static void query (void); static void run (const gchar *name, @@ -107,7 +115,9 @@ static cmsHPROFILE lcms_image_get_profile (GimpColorConfig *config, gint32 image, - guchar *checksum); + guchar *checksum, + gboolean *embedded); +static cmsHPROFILE lcms_create_gray22_profile (void); static gboolean lcms_image_set_profile (gint32 image, cmsHPROFILE profile, const gchar *filename, @@ -160,6 +170,11 @@ { GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" }, { GIMP_PDB_IMAGE, "image", "Input image" }, }; +static const GimpParamDef set_gray_args[] = +{ + { GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" }, + { GIMP_PDB_IMAGE, "image", "Input image" }, +}; static const GimpParamDef apply_args[] = { { GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" }, @@ -186,8 +201,9 @@ static const Procedure procedures[] = { - { PLUG_IN_PROC_SET, 2 }, + { PLUG_IN_PROC_SET, 1 }, { PLUG_IN_PROC_SET_RGB, 2 }, + { PLUG_IN_PROC_SET_GRAY, 1 }, { PLUG_IN_PROC_APPLY, 2 }, { PLUG_IN_PROC_APPLY_RGB, 2 }, { PLUG_IN_PROC_INFO, 1 }, @@ -223,7 +239,7 @@ "Sven Neumann", "2006, 2007", N_("_Assign Color Profile..."), - "RGB*, INDEXED*", + "*", GIMP_PLUGIN, G_N_ELEMENTS (set_args), 0, set_args, NULL); @@ -244,6 +260,22 @@ G_N_ELEMENTS (set_rgb_args), 0, set_rgb_args, NULL); + gimp_install_procedure (PLUG_IN_PROC_SET_GRAY, + "Set the default Grayscale color profile on the image", + "This procedure sets the user-configured Grayscale " + "profile on an image using the 'icc-profile' " + "parasite. If no Grayscale profile is configured, Gamma 2.2 " + "is assumed and the parasite is unset. This " + "procedure does not do any color conversion.", + "Sven Neumann", + "Sven Neumann", + "2006, 2007", + N_("Assign default Grayscale Profile"), + "GRAY*", + GIMP_PLUGIN, + G_N_ELEMENTS (set_gray_args), 0, + set_gray_args, NULL); + gimp_install_procedure (PLUG_IN_PROC_APPLY, _("Apply a color profile on the image"), "This procedure transform from the image's color " @@ -382,6 +414,7 @@ break; case PROC_SET_RGB: + case PROC_SET_GRAY: run_mode = param[0].data.d_int32; image = param[1].data.d_image; break; @@ -434,6 +467,7 @@ { case PROC_SET: case PROC_SET_RGB: + case PROC_SET_GRAY: status = lcms_icc_set (config, image, filename); break; @@ -517,6 +551,28 @@ return (cmsGetColorSpace (profile) == icSigRgbData); } +static gboolean +lcms_icc_profile_is_gray (cmsHPROFILE profile) +{ + return (cmsGetColorSpace (profile) == icSigGrayData); +} + +static gboolean +lcms_icc_profile_check_colorspace (cmsHPROFILE profile, + GimpImageBaseType base_type) +{ + switch (base_type) + { + case GIMP_RGB: + case GIMP_INDEXED: + return (cmsGetColorSpace (profile) == icSigRgbData); + case GIMP_GRAY: + return (cmsGetColorSpace (profile) == icSigGrayData); + default: + return FALSE; + } +} + static GimpPDBStatusType lcms_icc_set (GimpColorConfig *config, gint32 image, @@ -529,11 +585,29 @@ if (filename) { - success = lcms_image_set_profile (image, NULL, filename, TRUE); + /* remove profile if filename is empty */ + success = lcms_image_set_profile (image, NULL, filename[0] ? filename : NULL, TRUE); } else { - success = lcms_image_set_profile (image, NULL, config->rgb_profile, TRUE); + cmsHPROFILE profile; + + switch (gimp_image_base_type (image)) + { + case GIMP_GRAY: + filename = config->gray_profile; + profile = lcms_create_gray22_profile (); + break; + case GIMP_RGB: + case GIMP_INDEXED: + default: + filename = config->rgb_profile; + profile = cmsCreate_sRGBProfile (); + } + + success = lcms_image_set_profile (image, profile, filename, TRUE); + + cmsCloseProfile (profile); } return success ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR; @@ -577,7 +651,7 @@ } } - src_profile = lcms_image_get_profile (config, image, src_md5); + src_profile = lcms_image_get_profile (config, image, src_md5, NULL); if (src_profile && ! lcms_icc_profile_is_rgb (src_profile)) { @@ -648,35 +722,82 @@ gchar **desc, gchar **info) { - cmsHPROFILE profile; + cmsHPROFILE profile; + gboolean embedded; + GimpImageBaseType base_type; g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (image != -1, GIMP_PDB_CALLING_ERROR); - profile = lcms_image_get_profile (config, image, NULL); + base_type = gimp_image_base_type (image); + profile = lcms_image_get_profile (config, image, NULL, &embedded); - if (profile && ! lcms_icc_profile_is_rgb (profile)) + if (profile) { - g_printerr ("lcms: attached color profile is not for RGB color space " - "(skipping)\n"); + if (embedded) + { + if (name) *name = lcms_icc_profile_get_name (profile); + if (desc) *desc = lcms_icc_profile_get_desc (profile); + if (info) + { + if (base_type == GIMP_GRAY) + { + if (lcms_icc_profile_is_gray (profile)) + *info = lcms_icc_profile_get_info (profile); + else + { + gchar *tmp = lcms_icc_profile_get_info (profile); - cmsCloseProfile (profile); - profile = NULL; - } + *info = g_strdup_printf (_("%s\n\nWarning : this profile is not Grayscale colorspace!"), tmp); - if (profile) - { - if (name) *name = lcms_icc_profile_get_name (profile); - if (desc) *desc = lcms_icc_profile_get_desc (profile); - if (info) *info = lcms_icc_profile_get_info (profile); + g_free (tmp); + } + } + else + { + if (lcms_icc_profile_is_rgb (profile)) + *info = lcms_icc_profile_get_info (profile); + else + { + gchar *tmp = lcms_icc_profile_get_info (profile); + + *info = g_strdup_printf (_("%s\n\nWarning : this profile is not RGB colorspace!"), tmp); + + g_free (tmp); + } + } + } + } + else + { + if (name) *name = g_strdup (_("No profiles embedded")); + if (desc) *desc = g_strdup (_("No profiles embedded")); + if (info) + { + gchar *tmp = lcms_icc_profile_get_desc (profile); + + if ((base_type == GIMP_GRAY && ! lcms_icc_profile_is_gray (profile)) || + ((base_type == GIMP_RGB || base_type == GIMP_INDEXED) && ! lcms_icc_profile_is_rgb (profile))) + { + *info = g_strdup_printf (_("Warning : current workspace is \"%s\", but it doesn't match the document mode!"), tmp); + } + else + *info = g_strdup_printf (_("GIMP assumes that \"%s\" (workspace profile) is embedded."), tmp); + + g_free (tmp); + } + } cmsCloseProfile (profile); } else { - if (name) *name = g_strdup ("sRGB"); - if (desc) *desc = g_strdup ("sRGB built-in"); - if (info) *info = g_strdup (_("Default RGB working space")); + if (name) *name = g_strdup (_("No profiles embedded")); + if (desc) *desc = g_strdup (_("No profiles embedded")); + + if (info) *info = g_strdup_printf ( + _("GIMP assumes that \"%s\" (built-in workspace) is embedded."), + base_type == GIMP_GRAY ? "Gray Gamma 2.2" : "sRGB (lcms)"); } return GIMP_PDB_SUCCESS; @@ -750,10 +871,13 @@ static cmsHPROFILE lcms_image_get_profile (GimpColorConfig *config, gint32 image, - guchar *checksum) + guchar *checksum, + gboolean *embedded) { - GimpParasite *parasite; - cmsHPROFILE profile = NULL; + GimpParasite *parasite; + cmsHPROFILE profile = NULL; + gboolean _embedded = TRUE; + GimpImageBaseType base_type = gimp_image_base_type (image); g_return_val_if_fail (image != -1, NULL); @@ -778,11 +902,36 @@ gimp_parasite_free (parasite); } - else if (config->rgb_profile) + else { - profile = lcms_load_profile (config->rgb_profile, checksum); + gchar *profile_path = base_type == GIMP_GRAY ? config->gray_profile : config->rgb_profile; + + _embedded = FALSE; + + if (profile_path) + profile = lcms_load_profile (profile_path, checksum); } + if (embedded) + *embedded = _embedded; + + return profile; +} + +static cmsHPROFILE +lcms_create_gray22_profile (void) +{ + cmsCIExyY wp = { 0.312705, 0.328990, 1.0 }; + LPGAMMATABLE transfer_func; + cmsHPROFILE profile; + + transfer_func = cmsBuildGamma (256, 2.2); + + profile = cmsCreateGrayProfile (&wp, transfer_func); + cmsAddTag (profile, icSigProfileDescriptionTag, "Gray Gamma 2.2"); + + cmsFreeGamma (transfer_func); + return profile; } @@ -792,12 +941,53 @@ const gchar *filename, gboolean undo_group) { + GimpParasite *parasite; + GimpImageBaseType base_type; + g_return_val_if_fail (image != -1, FALSE); - if (filename) + base_type = gimp_image_base_type (image); + + if (profile && ! filename) + { + gsize len; + gchar *buf; + + if (! lcms_icc_profile_check_colorspace (profile, base_type)) + { + g_message (_("'%s' is not %s colorspace profile"), + cmsTakeProductDesc (profile), + _(gimp_image_base_type_name[base_type])); + return FALSE; + } + + _cmsSaveProfileToMem (profile, NULL, &len); + buf = g_malloc (len); + + if (_cmsSaveProfileToMem (profile, buf, &len)) + { + if (undo_group) + gimp_image_undo_group_start (image); + + parasite = gimp_parasite_new ("icc-profile", + GIMP_PARASITE_PERSISTENT | + GIMP_PARASITE_UNDOABLE, + len, buf); + + gimp_image_parasite_attach (image, parasite); + gimp_parasite_free (parasite); + } + else + { + g_free (buf); + return FALSE; + } + + g_free (buf); + } + else if (filename) { - GimpParasite *parasite; - GMappedFile *file; + GMappedFile *file = NULL; GError *error = NULL; file = g_mapped_file_new (filename, FALSE, &error); @@ -818,6 +1008,14 @@ if (profile) { + if (! lcms_icc_profile_check_colorspace (profile, base_type)) + { + g_message (_("'%s' is not %s colorspace profile"), + gimp_filename_to_utf8 (filename), + _(gimp_image_base_type_name[base_type])); + return FALSE; + } + cmsCloseProfile (profile); } else @@ -1367,14 +1565,16 @@ } static GtkWidget * -lcms_icc_combo_box_new (GimpColorConfig *config, - const gchar *filename) +lcms_icc_combo_box_new (GimpColorConfig *config, + GimpImageBaseType base_type, + const gchar *filename) { GtkWidget *combo; GtkWidget *dialog; gchar *history; gchar *label; gchar *name; + gchar *workspace_filename; cmsHPROFILE profile; dialog = lcms_icc_file_chooser_dialog_new (); @@ -1388,10 +1588,23 @@ G_CALLBACK (lcms_icc_file_chooser_dialog_response), combo); - if (config->rgb_profile) - profile = lcms_load_profile (config->rgb_profile, NULL); - else - profile = cmsCreate_sRGBProfile (); + switch (base_type) + { + case GIMP_GRAY: + if ((workspace_filename = config->gray_profile)) + profile = lcms_load_profile (config->gray_profile, NULL); + else + profile = lcms_create_gray22_profile (); + + break; + case GIMP_RGB: + case GIMP_INDEXED: + default: + if ((workspace_filename = config->rgb_profile)) + profile = lcms_load_profile (config->rgb_profile, NULL); + else + profile = cmsCreate_sRGBProfile (); + } name = lcms_icc_profile_get_desc (profile); if (! name) @@ -1399,11 +1612,11 @@ cmsCloseProfile (profile); - label = g_strdup_printf (_("RGB workspace (%s)"), name); + label = g_strdup_printf (_("%s workspace (%s)"), _(gimp_image_base_type_name[base_type]), name); g_free (name); gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (combo), - config->rgb_profile, label); + workspace_filename, label); g_free (label); if (filename) @@ -1431,20 +1644,22 @@ gchar *name; gboolean success = FALSE; gboolean run; + GimpImageBaseType base_type = gimp_image_base_type (image); - src_profile = lcms_image_get_profile (config, image, NULL); + src_profile = lcms_image_get_profile (config, image, NULL, NULL); - if (src_profile && ! lcms_icc_profile_is_rgb (src_profile)) + if (src_profile && ! lcms_icc_profile_check_colorspace (src_profile, base_type)) { - g_printerr ("lcms: attached color profile is not for RGB color space " - "(skipping)\n"); + g_printerr ("lcms: attached color profile is not for %s color space " + "(skipping)\n", _(gimp_image_base_type_name[base_type])); cmsCloseProfile (src_profile); src_profile = NULL; } + /* FIXME : use user-specified workspace profile instead of built-in profile */ if (! src_profile) - src_profile = cmsCreate_sRGBProfile (); + src_profile = base_type == GIMP_GRAY ? lcms_create_gray22_profile () : cmsCreate_sRGBProfile (); gimp_ui_init (PLUG_IN_BINARY, FALSE); @@ -1494,7 +1709,7 @@ gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); - combo = lcms_icc_combo_box_new (config, NULL); + combo = lcms_icc_combo_box_new (config, base_type, NULL); gtk_container_add (GTK_CONTAINER (frame), combo); gtk_widget_show (combo); @@ -1539,6 +1754,10 @@ G_CALLBACK (gimp_toggle_button_update), &values->bpc); } + else + gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (box), + NULL, _("None")); + while ((run = gimp_dialog_run (GIMP_DIALOG (dialog))) == GTK_RESPONSE_OK) { @@ -1547,36 +1766,37 @@ gtk_widget_set_sensitive (dialog, FALSE); - if (filename) + if (apply) { - dest_profile = lcms_load_profile (filename, NULL); - } - else - { - dest_profile = cmsCreate_sRGBProfile (); - } + if (filename) + dest_profile = lcms_load_profile (filename, NULL); + else + dest_profile = base_type == GIMP_GRAY ? lcms_create_gray22_profile () : cmsCreate_sRGBProfile (); - if (dest_profile) - { - if (lcms_icc_profile_is_rgb (dest_profile)) + if (dest_profile) { - if (apply) - success = lcms_image_apply_profile (image, - src_profile, dest_profile, - filename, - values->intent, - values->bpc); + if (lcms_icc_profile_check_colorspace (dest_profile, base_type)) + { + success = lcms_image_apply_profile (image, + src_profile, dest_profile, + filename, + values->intent, + values->bpc); + } else - success = lcms_image_set_profile (image, - dest_profile, filename, TRUE); - } - else - { - gimp_message (_("Destination profile is not for RGB color space.")); - } + { + gchar *msg = g_strdup_printf (_("Destination profile is not for %s color space."), + _(gimp_image_base_type_name[base_type])); + gimp_message (msg); - cmsCloseProfile (dest_profile); + g_free (msg); + } + + cmsCloseProfile (dest_profile); + } } + else + success = lcms_image_set_profile (image, NULL, filename, TRUE); if (success) break;