app: add _gimp_image_update_color_profile() to update the cached profile

and call it when an "icc-profile" parssite is attached or detached.
This removes code duplication and creates a place to conveniently
update more cached profiles and transforms, such as from/to sRGB for
color picking and applying.
This commit is contained in:
Michael Natterer 2015-08-26 19:16:17 +02:00
parent a66d867da9
commit 05add456bb
4 changed files with 44 additions and 49 deletions

View file

@ -613,3 +613,29 @@ gimp_image_convert_profile_indexed (GimpImage *image,
g_free (cmap);
}
/* internal API */
void
_gimp_image_update_color_profile (GimpImage *image,
const GimpParasite *icc_parasite)
{
GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
if (private->color_profile)
{
g_object_unref (private->color_profile);
private->color_profile = NULL;
}
if (icc_parasite)
{
private->color_profile =
gimp_color_profile_new_from_icc_profile (gimp_parasite_data (icc_parasite),
gimp_parasite_data_size (icc_parasite),
NULL);
}
gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
}

View file

@ -57,17 +57,23 @@ gboolean gimp_image_set_color_profile (GimpImage *ima
GimpColorProfile * gimp_image_get_builtin_color_profile
(GimpImage *image);
gboolean gimp_image_convert_color_profile (GimpImage *image,
GimpColorProfile *dest_profile,
gboolean gimp_image_convert_color_profile (GimpImage *image,
GimpColorProfile *dest_profile,
GimpColorRenderingIntent intent,
gboolean bpc,
GimpProgress *progress,
GError **error);
gboolean bpc,
GimpProgress *progress,
GError **error);
void gimp_image_import_color_profile (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
gboolean interactive);
void gimp_image_import_color_profile (GimpImage *image,
GimpContext *context,
GimpProgress *progress,
gboolean interactive);
/* internal API, to be called only from the icc-profile parasite setters */
void _gimp_image_update_color_profile (GimpImage *image,
const GimpParasite *icc_parasite);
#endif /* __GIMP_IMAGE_COLOR_PROFILE_H__ */

View file

@ -3367,19 +3367,7 @@ gimp_image_parasite_attach (GimpImage *image,
gimp_parasite_name (parasite));
if (strcmp (gimp_parasite_name (parasite), GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
{
GimpColorProfile *profile =
gimp_color_profile_new_from_icc_profile (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite),
NULL);
if (private->color_profile)
g_object_unref (private->color_profile);
private->color_profile = profile;
gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
}
_gimp_image_update_color_profile (image, parasite);
}
void
@ -3408,15 +3396,7 @@ gimp_image_parasite_detach (GimpImage *image,
name);
if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
{
if (private->color_profile)
{
g_object_unref (private->color_profile);
private->color_profile = NULL;
}
gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
}
_gimp_image_update_color_profile (image, NULL);
}

View file

@ -24,7 +24,6 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h"
@ -489,23 +488,7 @@ gimp_image_undo_pop (GimpUndo *undo,
name = parasite ? parasite->name : image_undo->parasite_name;
if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
{
if (private->color_profile)
{
g_object_unref (private->color_profile);
private->color_profile = NULL;
}
if (parasite)
{
private->color_profile =
gimp_color_profile_new_from_icc_profile (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite),
NULL);
}
gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
}
_gimp_image_update_color_profile (image, parasite);
if (parasite)
gimp_parasite_free (parasite);