static gboolean gimp_color_profile_can_gegl_copy (GimpColorProfile *src_profile, GimpColorProfile *dest_profile) { static GimpColorProfile *srgb_profile = NULL; static GimpColorProfile *linear_rgb_profile = NULL; if (gimp_color_profile_is_equal (src_profile, dest_profile)) return TRUE; if (! srgb_profile) { srgb_profile = gimp_color_profile_new_srgb (); linear_rgb_profile = gimp_color_profile_new_linear_rgb (); } if ((gimp_color_profile_is_equal (src_profile, srgb_profile) || gimp_color_profile_is_equal (src_profile, linear_rgb_profile)) && (gimp_color_profile_is_equal (dest_profile, srgb_profile) || gimp_color_profile_is_equal (dest_profile, linear_rgb_profile))) return TRUE; return FALSE; }
static gboolean profiles_equal (GimpColorProfile *profile1, GimpColorProfile *profile2) { return ((profile1 == NULL && profile2 == NULL) || (profile1 != NULL && profile2 != NULL && gimp_color_profile_is_equal (profile1, profile2))); }
/** * gimp_color_transform_can_gegl_copy: * @src_format: src profile * @dest_format: dest profile * * This function checks if a GimpColorTransform is needed at all. * * Return value: %TRUE if pixels can be correctly converted between * @src_profile and @dest_profile by simply using * gegl_buffer_copy(), babl_process() or similar. * * Since: 2.10 **/ gboolean gimp_color_transform_can_gegl_copy (GimpColorProfile *src_profile, GimpColorProfile *dest_profile) { static GimpColorProfile *srgb_profile = NULL; static GimpColorProfile *srgb_linear_profile = NULL; static GimpColorProfile *gray_profile = NULL; static GimpColorProfile *gray_linear_profile = NULL; g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (src_profile), FALSE); g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (dest_profile), FALSE); if (gimp_color_profile_is_equal (src_profile, dest_profile)) return TRUE; if (! srgb_profile) { srgb_profile = gimp_color_profile_new_rgb_srgb (); srgb_linear_profile = gimp_color_profile_new_rgb_srgb_linear (); gray_profile = gimp_color_profile_new_d65_gray_srgb_trc (); gray_linear_profile = gimp_color_profile_new_d65_gray_linear (); } if ((gimp_color_profile_is_equal (src_profile, srgb_profile) || gimp_color_profile_is_equal (src_profile, srgb_linear_profile) || gimp_color_profile_is_equal (src_profile, gray_profile) || gimp_color_profile_is_equal (src_profile, gray_linear_profile)) && (gimp_color_profile_is_equal (dest_profile, srgb_profile) || gimp_color_profile_is_equal (dest_profile, srgb_linear_profile) || gimp_color_profile_is_equal (dest_profile, gray_profile) || gimp_color_profile_is_equal (dest_profile, gray_linear_profile))) { return TRUE; } return FALSE; }
gboolean gimp_image_validate_color_profile (GimpImage *image, GimpColorProfile *profile, gboolean *is_builtin, GError **error) { g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (gimp_image_get_base_type (image) == GIMP_GRAY) { if (! gimp_color_profile_is_gray (profile)) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("ICC profile validation failed: " "Color profile is not for GRAY color space")); return FALSE; } } else { if (! gimp_color_profile_is_rgb (profile)) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("ICC profile validation failed: " "Color profile is not for RGB color space")); return FALSE; } } if (is_builtin) { GimpColorProfile *builtin; builtin = gimp_image_get_builtin_color_profile (image); *is_builtin = gimp_color_profile_is_equal (profile, builtin); } return TRUE; }
gboolean gimp_image_convert_color_profile (GimpImage *image, GimpColorProfile *dest_profile, GimpColorRenderingIntent intent, gboolean bpc, GimpProgress *progress, GError **error) { GimpColorProfile *src_profile; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (dest_profile != NULL, FALSE); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (! gimp_image_validate_color_profile (image, dest_profile, NULL, error)) return FALSE; src_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image)); if (! src_profile || gimp_color_profile_is_equal (src_profile, dest_profile)) return TRUE; if (progress) gimp_progress_start (progress, FALSE, _("Converting from '%s' to '%s'"), gimp_color_profile_get_label (src_profile), gimp_color_profile_get_label (dest_profile)); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT, _("Color profile conversion")); gimp_image_set_color_profile (image, dest_profile, NULL); /* omg... */ gimp_image_parasite_detach (image, "icc-profile-name"); switch (gimp_image_get_base_type (image)) { case GIMP_RGB: gimp_image_convert_profile_rgb (image, src_profile, dest_profile, intent, bpc, progress); break; case GIMP_GRAY: break; case GIMP_INDEXED: gimp_image_convert_profile_indexed (image, src_profile, dest_profile, intent, bpc, progress); break; } gimp_image_undo_group_end (image); if (progress) gimp_progress_end (progress); return TRUE; }
GimpColorTransform gimp_widget_get_color_transform (GtkWidget *widget, GimpColorConfig *config, GimpColorProfile *src_profile, const Babl **src_format, const Babl **dest_format) { GimpColorTransform transform = NULL; GimpColorProfile *dest_profile = NULL; GimpColorProfile *proof_profile = NULL; cmsHPROFILE src_lcms; cmsHPROFILE dest_lcms; cmsUInt32Number lcms_src_format; cmsUInt32Number lcms_dest_format; cmsUInt16Number alarmCodes[cmsMAXCHANNELS] = { 0, }; g_return_val_if_fail (widget == NULL || GTK_IS_WIDGET (widget), NULL); g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (src_profile), NULL); g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL); g_return_val_if_fail (src_format != NULL, NULL); g_return_val_if_fail (dest_format != NULL, NULL); switch (config->mode) { case GIMP_COLOR_MANAGEMENT_OFF: return NULL; case GIMP_COLOR_MANAGEMENT_SOFTPROOF: proof_profile = gimp_color_config_get_printer_color_profile (config, NULL); /* fallthru */ case GIMP_COLOR_MANAGEMENT_DISPLAY: dest_profile = get_display_profile (widget, config); break; } src_lcms = gimp_color_profile_get_lcms_profile (src_profile); dest_lcms = gimp_color_profile_get_lcms_profile (dest_profile); *src_format = gimp_color_profile_get_format (*src_format, &lcms_src_format); *dest_format = gimp_color_profile_get_format (*dest_format, &lcms_dest_format); if (proof_profile) { cmsHPROFILE proof_lcms; cmsUInt32Number softproof_flags = cmsFLAGS_SOFTPROOFING; proof_lcms = gimp_color_profile_get_lcms_profile (proof_profile); if (config->simulation_use_black_point_compensation) { softproof_flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } if (config->simulation_gamut_check) { guchar r, g, b; softproof_flags |= cmsFLAGS_GAMUTCHECK; gimp_rgb_get_uchar (&config->out_of_gamut_color, &r, &g, &b); alarmCodes[0] = (cmsUInt16Number) r * 256; alarmCodes[1] = (cmsUInt16Number) g * 256; alarmCodes[2] = (cmsUInt16Number) b * 256; cmsSetAlarmCodes (alarmCodes); } transform = cmsCreateProofingTransform (src_lcms, lcms_src_format, dest_lcms, lcms_dest_format, proof_lcms, config->simulation_intent, config->display_intent, softproof_flags); g_object_unref (proof_profile); } else if (! gimp_color_profile_is_equal (src_profile, dest_profile)) { cmsUInt32Number display_flags = 0; if (config->display_use_black_point_compensation) { display_flags |= cmsFLAGS_BLACKPOINTCOMPENSATION; } transform = cmsCreateTransform (src_lcms, lcms_src_format, dest_lcms, lcms_dest_format, config->display_intent, display_flags); } g_object_unref (dest_profile); return transform; }
GimpColorTransform * gimp_widget_get_color_transform (GtkWidget *widget, GimpColorConfig *config, GimpColorProfile *src_profile, const Babl *src_format, const Babl *dest_format) { static gboolean initialized = FALSE; GimpColorProfile *dest_profile = NULL; GimpColorProfile *proof_profile = NULL; TransformCache *cache; g_return_val_if_fail (widget == NULL || GTK_IS_WIDGET (widget), NULL); g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL); g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (src_profile), NULL); g_return_val_if_fail (src_format != NULL, NULL); g_return_val_if_fail (dest_format != NULL, NULL); if (G_UNLIKELY (! initialized)) { initialized = TRUE; debug_cache = g_getenv ("GIMP_DEBUG_TRANSFORM_CACHE") != NULL; } switch (gimp_color_config_get_mode (config)) { case GIMP_COLOR_MANAGEMENT_OFF: return NULL; case GIMP_COLOR_MANAGEMENT_SOFTPROOF: proof_profile = gimp_color_config_get_simulation_color_profile (config, NULL); /* fallthru */ case GIMP_COLOR_MANAGEMENT_DISPLAY: dest_profile = get_display_profile (widget, config); break; } cache = transform_cache_get (config, src_profile, src_format, dest_profile, dest_format, proof_profile); if (cache) { g_object_unref (dest_profile); if (proof_profile) g_object_unref (proof_profile); if (cache->transform) return g_object_ref (cache->transform); return NULL; } if (! proof_profile && gimp_color_profile_is_equal (src_profile, dest_profile)) { g_object_unref (dest_profile); return NULL; } cache = g_new0 (TransformCache, 1); if (debug_cache) g_printerr ("creating cache %p\n", cache); cache->config = g_object_ref (config); cache->src_profile = g_object_ref (src_profile); cache->src_format = src_format; cache->dest_profile = dest_profile; cache->dest_format = dest_format; cache->proof_profile = proof_profile; cache->notify_id = g_signal_connect (cache->config, "notify", G_CALLBACK (transform_cache_config_notify), cache); transform_caches = g_list_prepend (transform_caches, cache); if (cache->proof_profile) { GimpColorTransformFlags flags = 0; if (gimp_color_config_get_simulation_bpc (config)) flags |= GIMP_COLOR_TRANSFORM_FLAGS_BLACK_POINT_COMPENSATION; if (! gimp_color_config_get_simulation_optimize (config)) flags |= GIMP_COLOR_TRANSFORM_FLAGS_NOOPTIMIZE; if (gimp_color_config_get_simulation_gamut_check (config)) { cmsUInt16Number alarmCodes[cmsMAXCHANNELS] = { 0, }; guchar r, g, b; flags |= GIMP_COLOR_TRANSFORM_FLAGS_GAMUT_CHECK; gimp_rgb_get_uchar (&config->out_of_gamut_color, &r, &g, &b); alarmCodes[0] = (cmsUInt16Number) r * 256; alarmCodes[1] = (cmsUInt16Number) g * 256; alarmCodes[2] = (cmsUInt16Number) b * 256; cmsSetAlarmCodes (alarmCodes); } cache->transform = gimp_color_transform_new_proofing (cache->src_profile, cache->src_format, cache->dest_profile, cache->dest_format, cache->proof_profile, gimp_color_config_get_simulation_intent (config), gimp_color_config_get_display_intent (config), flags); } else { GimpColorTransformFlags flags = 0; if (gimp_color_config_get_display_bpc (config)) flags |= GIMP_COLOR_TRANSFORM_FLAGS_BLACK_POINT_COMPENSATION; if (! gimp_color_config_get_display_optimize (config)) flags |= GIMP_COLOR_TRANSFORM_FLAGS_NOOPTIMIZE; cache->transform = gimp_color_transform_new (cache->src_profile, cache->src_format, cache->dest_profile, cache->dest_format, gimp_color_config_get_display_intent (config), flags); } if (cache->transform) return g_object_ref (cache->transform); return NULL; }
gboolean gimp_image_convert_color_profile (GimpImage *image, GimpColorProfile *dest_profile, GimpColorRenderingIntent intent, gboolean bpc, GimpProgress *progress, GError **error) { GimpColorProfile *src_profile; GimpColorProfile *builtin_profile; const Babl *layer_format; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (dest_profile != NULL, FALSE); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (! gimp_image_validate_color_profile (image, dest_profile, error)) return FALSE; src_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image)); if (gimp_color_profile_is_equal (src_profile, dest_profile)) { g_object_unref (src_profile); return TRUE; } if (progress) gimp_progress_start (progress, FALSE, _("Converting from '%s' to '%s'"), gimp_color_profile_get_label (src_profile), gimp_color_profile_get_label (dest_profile)); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT, _("Color profile conversion")); layer_format = gimp_image_get_layer_format (image, FALSE); if (gimp_babl_format_get_linear (layer_format)) builtin_profile = gimp_color_profile_new_linear_rgb (); else builtin_profile = gimp_color_profile_new_srgb (); if (gimp_color_profile_is_equal (dest_profile, builtin_profile)) { /* don't tag the image with the built-in profile */ gimp_image_set_color_profile (image, NULL, NULL); } else { gimp_image_set_color_profile (image, dest_profile, NULL); } g_object_unref (builtin_profile); /* omg... */ gimp_image_parasite_detach (image, "icc-profile-name"); switch (gimp_image_get_base_type (image)) { case GIMP_RGB: gimp_image_convert_profile_rgb (image, src_profile, dest_profile, intent, bpc, progress); break; case GIMP_GRAY: break; case GIMP_INDEXED: gimp_image_convert_profile_indexed (image, src_profile, dest_profile, intent, bpc, progress); break; } gimp_image_undo_group_end (image); if (progress) gimp_progress_end (progress); g_object_unref (src_profile); return TRUE; }