app, libgimpcolor: refactor GimpColorManaged::get_color_profile()

to not return a reference that has to be dropped. Also allow NULL to
be returned if the managed cannot have a profile. If it can have one,
get_color_profile() still always returns a profile (either the
assigned one, or a generated built-in one).
This commit is contained in:
Michael Natterer 2015-09-03 01:36:02 +02:00
parent 7c95676f88
commit b45d31072b
19 changed files with 93 additions and 102 deletions

View File

@ -609,14 +609,13 @@ gimp_edit_extract (GimpImage *image,
offset_x, offset_y, FALSE);
g_object_unref (buffer);
if (GIMP_IS_LAYER (pickable) ||
GIMP_IS_IMAGE (pickable))
if (GIMP_IS_COLOR_MANAGED (pickable))
{
GimpColorProfile *profile =
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (pickable));
gimp_buffer_set_color_profile (gimp_buffer, profile);
g_object_unref (profile);
if (profile)
gimp_buffer_set_color_profile (gimp_buffer, profile);
}
return gimp_buffer;

View File

@ -358,11 +358,8 @@ gimp_image_convert_color_profile (GimpImage *image,
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 (! src_profile || gimp_color_profile_is_equal (src_profile, dest_profile))
return TRUE;
if (progress)
gimp_progress_start (progress, FALSE,
@ -402,8 +399,6 @@ gimp_image_convert_color_profile (GimpImage *image,
if (progress)
gimp_progress_end (progress);
g_object_unref (src_profile);
return TRUE;
}

View File

@ -1390,10 +1390,10 @@ gimp_image_color_managed_get_color_profile (GimpColorManaged *managed)
profile = gimp_image_get_color_profile (image);
if (! profile)
if (! profile && gimp_image_get_base_type (image) != GIMP_INDEXED)
profile = gimp_image_get_builtin_color_profile (image);
return g_object_ref (profile);
return profile;
}
static void

View File

@ -234,28 +234,23 @@ gimp_layer_new_convert_buffer (GimpLayer *layer,
GeglBuffer *dest_buffer = gimp_drawable_get_buffer (drawable);
GimpColorProfile *dest_profile;
if (! src_profile)
{
gegl_buffer_copy (src_buffer, NULL, GEGL_ABYSS_NONE, dest_buffer, NULL);
return;
}
/* FIXME: this is the wrong check, need something like file import
* conversion config
*/
if (config->mode == GIMP_COLOR_MANAGEMENT_OFF)
{
gegl_buffer_copy (src_buffer, NULL, GEGL_ABYSS_NONE, dest_buffer, NULL);
return;
}
dest_profile =
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (layer));
if (! src_profile ||
! dest_profile ||
/* FIXME: this is the wrong check, need something like file import
* conversion config
*/
config->mode == GIMP_COLOR_MANAGEMENT_OFF)
{
gegl_buffer_copy (src_buffer, NULL, GEGL_ABYSS_NONE, dest_buffer, NULL);
return;
}
gimp_gegl_convert_color_profile (src_buffer, NULL, src_profile,
dest_buffer, NULL, dest_profile,
GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
TRUE);
g_object_unref (dest_profile);
}

View File

@ -1052,9 +1052,11 @@ gimp_layer_convert_type (GimpDrawable *drawable,
gboolean convert_profile,
gboolean push_undo)
{
GimpLayer *layer = GIMP_LAYER (drawable);
GeglBuffer *src_buffer;
GeglBuffer *dest_buffer;
GimpLayer *layer = GIMP_LAYER (drawable);
GeglBuffer *src_buffer;
GeglBuffer *dest_buffer;
GimpColorProfile *src_profile = NULL;
GimpColorProfile *dest_profile = NULL;
if (layer_dither_type == 0)
{
@ -1086,23 +1088,19 @@ gimp_layer_convert_type (GimpDrawable *drawable,
if (convert_profile)
{
GimpImage *src_image = gimp_item_get_image (GIMP_ITEM (layer));
GimpColorProfile *src_profile;
GimpColorProfile *dest_profile;
src_profile =
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (src_image));
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (layer));
dest_profile =
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (dest_image));
}
if (src_profile && dest_profile)
{
gimp_gegl_convert_color_profile (src_buffer, NULL, src_profile,
dest_buffer, NULL, dest_profile,
GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
TRUE);
g_object_unref (src_profile);
g_object_unref (dest_profile);
}
else
{

View File

@ -221,8 +221,6 @@ color_profile_dialog_new (GimpImage *image,
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_widget_show (label);
g_object_unref (src_profile);
frame = gimp_frame_new (convert ? _("Convert to") : _("Assign"));
gtk_box_pack_start (GTK_BOX (dialog->main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);

View File

@ -88,6 +88,9 @@ gimp_display_shell_profile_update (GimpDisplayShell *shell)
src_profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (shell));
if (! src_profile)
return;
src_format = gimp_babl_format (GIMP_RGB,
gimp_image_get_precision (image),
TRUE);

View File

@ -366,6 +366,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break;
}
/* else fallthru */
case 'w': /* width in pixels */
i += print (title, title_len, i, "%d",
gimp_image_get_width (image));
@ -388,6 +389,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break;
}
/* else fallthru */
case 'h': /* height in pixels */
i += print (title, title_len, i, "%d",
gimp_image_get_height (image));
@ -421,6 +423,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break;
}
/* else fallthru */
case 'x': /* drawable width in pixels */
if (drawable)
i += print (title, title_len, i, "%d",
@ -445,6 +448,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break;
}
/* else fallthru */
case 'y': /* drawable height in pixels */
if (drawable)
i += print (title, title_len, i, "%d",
@ -458,28 +462,29 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
profile = gimp_color_managed_get_color_profile (managed);
i += print (title, title_len, i, "%s",
gimp_color_profile_get_label (profile));
g_object_unref (profile);
if (profile)
i += print (title, title_len, i, "%s",
gimp_color_profile_get_label (profile));
}
break;
case 'e': /* display's offsets in pixels */
{
gdouble scale = gimp_zoom_model_get_factor (shell->zoom);
gdouble scale = gimp_zoom_model_get_factor (shell->zoom);
gdouble offset_x = shell->offset_x / scale;
gdouble offset_y = shell->offset_y / scale;
i += print (title, title_len, i,
scale >= 0.15 ? "%.0fx%.0f" : "%.2fx%.2f", offset_x, offset_y);
scale >= 0.15 ? "%.0fx%.0f" : "%.2fx%.2f",
offset_x, offset_y);
}
break;
break;
case 'r': /* view rotation angle in degrees */
{
i += print (title, title_len, i, "%.1f", shell->rotate_angle);
}
break;
break;
case '\xc3': /* utf-8 extended char */
{

View File

@ -1147,8 +1147,7 @@ gimp_display_shell_get_color_profile (GimpColorManaged *managed)
if (image)
return gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
/* never return a NULL profile */
return gimp_color_profile_new_srgb ();
return NULL;
}
static void

View File

@ -107,17 +107,19 @@ image_get_effective_color_profile_invoker (GimpProcedure *procedure,
if (success)
{
GimpColorProfile *profile;
const guint8 *data;
gsize length;
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
data = gimp_color_profile_get_icc_profile (profile, &length);
if (profile)
{
const guint8 *data;
gsize length;
profile_data = g_memdup (data, length);
num_bytes = length;
data = gimp_color_profile_get_icc_profile (profile, &length);
g_object_unref (profile);
profile_data = g_memdup (data, length);
num_bytes = length;
}
}
return_vals = gimp_procedure_get_return_values (procedure, success,
@ -366,7 +368,7 @@ register_image_color_profile_procs (GimpPDB *pdb)
gimp_procedure_set_static_strings (procedure,
"gimp-image-get-effective-color-profile",
"Returns the color profile that is used for the image",
"This procedure returns the color profile that is actually used for this image, which is the profile returned by 'gimp-image-get-color-profile' if the image has a profile assigned, or the default RGB profile from preferences if no profile is assigned to the image. If there is no default RGB profile configured in preferences either, a generated default RGB profile is returned.",
"This procedure returns the color profile that is actually used for this image, which is the profile returned by 'gimp-image-get-color-profile' if the image has a profile assigned, or a generated default RGB profile. If the image is not RGB or INDEXED, NULL is returned.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2015",

View File

@ -183,8 +183,6 @@ layer_new_from_visible_invoker (GimpProcedure *procedure,
GIMP_OPACITY_OPAQUE,
GIMP_NORMAL_MODE,
profile);
g_object_unref (profile);
}
return_vals = gimp_procedure_get_return_values (procedure, success,

View File

@ -1888,12 +1888,12 @@ plug_in_icc_profile_info_invoker (GimpProcedure *procedure,
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
profile_name = g_strdup (gimp_color_profile_get_model (profile));
profile_desc = g_strdup (gimp_color_profile_get_description (profile));
profile_info = g_strdup (gimp_color_profile_get_summary (profile));
g_object_unref (profile);
if (profile)
{
profile_name = g_strdup (gimp_color_profile_get_model (profile));
profile_desc = g_strdup (gimp_color_profile_get_description (profile));
profile_info = g_strdup (gimp_color_profile_get_summary (profile));
}
}
return_vals = gimp_procedure_get_return_values (procedure, success,

View File

@ -111,6 +111,4 @@ gimp_image_profile_view_update (GimpImageParasiteView *view)
profile = gimp_color_managed_get_color_profile (managed);
gimp_color_profile_view_set_profile (profile_view->profile_view, profile);
g_object_unref (profile);
}

View File

@ -90,9 +90,8 @@ _gimp_image_get_color_profile (gint32 image_ID,
* This procedure returns the color profile that is actually used for
* this image, which is the profile returned by
* gimp_image_get_color_profile() if the image has a profile assigned,
* or the default RGB profile from preferences if no profile is
* assigned to the image. If there is no default RGB profile configured
* in preferences either, a generated default RGB profile is returned.
* or a generated default RGB profile. If the image is not RGB or
* INDEXED, NULL is returned.
*
* Returns: The image's serialized color profile. The returned value
* must be freed with g_free().

View File

@ -153,8 +153,7 @@ gimp_color_managed_get_color_profile (GimpColorManaged *managed)
if (iface->get_color_profile)
return iface->get_color_profile (managed);
/* never return a NULL profile */
return gimp_color_profile_new_srgb ();
return NULL;
}
/**

View File

@ -278,15 +278,16 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
src_profile = gimp_color_managed_get_color_profile (managed);
lcms->src_format = babl_format ("R'G'B'A float");
lcms->dest_format = babl_format ("R'G'B'A float");
if (src_profile)
{
lcms->src_format = babl_format ("R'G'B'A float");
lcms->dest_format = babl_format ("R'G'B'A float");
lcms->transform = gimp_widget_get_color_transform (widget,
config, src_profile,
&lcms->src_format,
&lcms->dest_format);
g_object_unref (src_profile);
lcms->transform = gimp_widget_get_color_transform (widget,
config, src_profile,
&lcms->src_format,
&lcms->dest_format);
}
}
static GimpColorProfile *
@ -362,6 +363,9 @@ cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
if (strcmp (name, "rgb-profile") == 0)
{
profile = gimp_color_managed_get_color_profile (managed);
if (profile)
g_object_ref (profile);
}
else if (g_str_has_prefix (name, "display-profile"))
{

View File

@ -67,9 +67,8 @@ sub image_get_effective_color_profile {
This procedure returns the color profile that is actually used for
this image, which is the profile returned by
gimp_image_get_color_profile() if the image has a profile assigned, or
the default RGB profile from preferences if no profile is assigned to
the image. If there is no default RGB profile configured in
preferences either, a generated default RGB profile is returned.
a generated default RGB profile. If the image is not RGB or INDEXED,
NULL is returned.
HELP
&mitch_pdb_misc('2015', '2.10');
@ -90,17 +89,19 @@ HELP
code => <<'CODE'
{
GimpColorProfile *profile;
const guint8 *data;
gsize length;
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
data = gimp_color_profile_get_icc_profile (profile, &length);
if (profile)
{
const guint8 *data;
gsize length;
profile_data = g_memdup (data, length);
num_bytes = length;
data = gimp_color_profile_get_icc_profile (profile, &length);
g_object_unref (profile);
profile_data = g_memdup (data, length);
num_bytes = length;
}
}
CODE
);

View File

@ -157,8 +157,6 @@ HELP
GIMP_OPACITY_OPAQUE,
GIMP_NORMAL_MODE,
profile);
g_object_unref (profile);
}
CODE
);

View File

@ -1784,12 +1784,12 @@ HELP
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
profile_name = g_strdup (gimp_color_profile_get_model (profile));
profile_desc = g_strdup (gimp_color_profile_get_description (profile));
profile_info = g_strdup (gimp_color_profile_get_summary (profile));
g_object_unref (profile);
if (profile)
{
profile_name = g_strdup (gimp_color_profile_get_model (profile));
profile_desc = g_strdup (gimp_color_profile_get_description (profile));
profile_info = g_strdup (gimp_color_profile_get_summary (profile));
}
}
CODE
);