mirror of https://github.com/GNOME/gimp.git
libgimpcolor: return a NULL transform if cmsCreate[Proofing]Transform() fails
It doesn't really "fail", we check if an error was logged during transform creation and get rid of the transform even if lcms returned a pointer. This totally sucks but is better than crashing on a corrupt transform.
This commit is contained in:
parent
70463a74fa
commit
726552b085
|
@ -87,6 +87,28 @@ G_DEFINE_TYPE (GimpColorTransform, gimp_color_transform,
|
|||
|
||||
static guint gimp_color_transform_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static gchar *lcms_last_error = NULL;
|
||||
|
||||
|
||||
static void
|
||||
lcms_error_clear (void)
|
||||
{
|
||||
if (lcms_last_error)
|
||||
{
|
||||
g_free (lcms_last_error);
|
||||
lcms_last_error = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
lcms_error_handler (cmsContext ContextID,
|
||||
cmsUInt32Number ErrorCode,
|
||||
const gchar *text)
|
||||
{
|
||||
lcms_error_clear ();
|
||||
|
||||
lcms_last_error = g_strdup_printf ("lcms2 error %d: %s", ErrorCode, text);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_color_transform_class_init (GimpColorTransformClass *klass)
|
||||
|
@ -107,6 +129,8 @@ gimp_color_transform_class_init (GimpColorTransformClass *klass)
|
|||
G_TYPE_DOUBLE);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GimpColorTransformPrivate));
|
||||
|
||||
cmsSetLogErrorHandler (lcms_error_handler);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -195,11 +219,24 @@ gimp_color_transform_new (GimpColorProfile *src_profile,
|
|||
priv->dest_format = gimp_color_profile_get_format (dest_format,
|
||||
&lcms_dest_format);
|
||||
|
||||
lcms_error_clear ();
|
||||
|
||||
priv->transform = cmsCreateTransform (src_lcms, lcms_src_format,
|
||||
dest_lcms, lcms_dest_format,
|
||||
rendering_intent,
|
||||
flags | cmsFLAGS_NOOPTIMIZE);
|
||||
|
||||
if (lcms_last_error)
|
||||
{
|
||||
if (priv->transform)
|
||||
{
|
||||
cmsDeleteTransform (priv->transform);
|
||||
priv->transform = NULL;
|
||||
}
|
||||
|
||||
g_printerr ("%s\n", lcms_last_error);
|
||||
}
|
||||
|
||||
if (! priv->transform)
|
||||
{
|
||||
g_object_unref (transform);
|
||||
|
@ -263,6 +300,8 @@ gimp_color_transform_new_proofing (GimpColorProfile *src_profile,
|
|||
priv->dest_format = gimp_color_profile_get_format (dest_format,
|
||||
&lcms_dest_format);
|
||||
|
||||
lcms_error_clear ();
|
||||
|
||||
priv->transform = cmsCreateProofingTransform (src_lcms, lcms_src_format,
|
||||
dest_lcms, lcms_dest_format,
|
||||
proof_lcms,
|
||||
|
@ -270,6 +309,17 @@ gimp_color_transform_new_proofing (GimpColorProfile *src_profile,
|
|||
display_intent,
|
||||
flags | cmsFLAGS_SOFTPROOFING);
|
||||
|
||||
if (lcms_last_error)
|
||||
{
|
||||
if (priv->transform)
|
||||
{
|
||||
cmsDeleteTransform (priv->transform);
|
||||
priv->transform = NULL;
|
||||
}
|
||||
|
||||
g_printerr ("%s\n", lcms_last_error);
|
||||
}
|
||||
|
||||
if (! priv->transform)
|
||||
{
|
||||
g_object_unref (transform);
|
||||
|
|
Loading…
Reference in New Issue