示例#1
0
文件: lcms.c 项目: DevMaggio/gimp
static gboolean
lcms_image_set_profile (gint32       image,
                        cmsHPROFILE  profile,
                        const gchar *filename,
                        gboolean     undo_group)
{
  g_return_val_if_fail (image != -1, FALSE);

  if (filename)
    {
      GimpParasite *parasite;
      GMappedFile  *file;
      GError       *error = NULL;

      file = g_mapped_file_new (filename, FALSE, &error);

      if (! file)
        {
          g_message ("%s", error->message);
          g_error_free (error);

          return FALSE;
        }

      /* check that this file is actually an ICC profile */
      if (! profile)
        {
          profile = cmsOpenProfileFromMem (g_mapped_file_get_contents (file),
                                           g_mapped_file_get_length (file));

          if (profile)
            {
              cmsCloseProfile (profile);
            }
          else
            {
              g_message (_("'%s' does not appear to be an ICC color profile"),
                         gimp_filename_to_utf8 (filename));
              return FALSE;
            }
        }

      if (undo_group)
        gimp_image_undo_group_start (image);

      parasite = gimp_parasite_new ("icc-profile",
                                    GIMP_PARASITE_PERSISTENT |
                                    GIMP_PARASITE_UNDOABLE,
                                    g_mapped_file_get_length (file),
                                    g_mapped_file_get_contents (file));

      g_mapped_file_unref (file);

      gimp_image_attach_parasite (image, parasite);
      gimp_parasite_free (parasite);
    }
  else
    {
      if (undo_group)
        gimp_image_undo_group_start (image);

      gimp_image_detach_parasite (image, "icc-profile");
    }

  gimp_image_detach_parasite (image, "icc-profile-name");

  if (undo_group)
    gimp_image_undo_group_end (image);

  return TRUE;
}
示例#2
0
/**
 * gimp_image_parasite_detach:
 * @image_ID: The image.
 * @name: The name of the parasite to detach from an image.
 *
 * Deprecated: Use gimp_image_detach_parasite() instead.
 *
 * Returns: TRUE on success.
 **/
gboolean
gimp_image_parasite_detach (gint32       image_ID,
                            const gchar *name)
{
  return gimp_image_detach_parasite (image_ID, name);
}
示例#3
0
文件: lcms.c 项目: K-Sonoda/gimp
static gboolean
lcms_image_set_profile (gint32       image,
                        cmsHPROFILE  profile,
                        GFile       *file)
{
  g_return_val_if_fail (image != -1, FALSE);

  if (file)
    {
      cmsHPROFILE   file_profile;
      GimpParasite *parasite;
      guint8       *profile_data;
      gsize         profile_length;
      GError       *error = NULL;

      /* check that this file is actually an ICC profile */
      file_profile = gimp_lcms_profile_open_from_file (file, &error);

      if (! file_profile)
        {
          g_message ("%s", error->message);
          g_clear_error (&error);

          return FALSE;
        }

      profile_data = gimp_lcms_profile_save_to_data (file_profile,
                                                     &profile_length,
                                                     &error);
      cmsCloseProfile (file_profile);

      if (! profile_data)
        {
          g_message ("%s", error->message);
          g_clear_error (&error);

          return FALSE;
        }

      gimp_image_undo_group_start (image);

      parasite = gimp_parasite_new ("icc-profile",
                                    GIMP_PARASITE_PERSISTENT |
                                    GIMP_PARASITE_UNDOABLE,
                                    profile_length, profile_data);

      g_free (profile_data);

      gimp_image_attach_parasite (image, parasite);
      gimp_parasite_free (parasite);
    }
  else
    {
      gimp_image_undo_group_start (image);

      gimp_image_detach_parasite (image, "icc-profile");
    }

  gimp_image_detach_parasite (image, "icc-profile-name");

  gimp_image_undo_group_end (image);

  return TRUE;
}