Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
GimpColorProfile *
gimp_image_get_builtin_color_profile (GimpImage *image)
{
  static GimpColorProfile *srgb_profile       = NULL;
  static GimpColorProfile *linear_rgb_profile = NULL;
  const  Babl             *format;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);

  if (! srgb_profile)
    {
      srgb_profile       = gimp_color_profile_new_srgb ();
      linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
    }

  format = gimp_image_get_layer_format (image, FALSE);

  if (gimp_babl_format_get_linear (format))
    {
      if (! srgb_profile)
        {
          srgb_profile = gimp_color_profile_new_srgb ();
          g_object_add_weak_pointer (G_OBJECT (srgb_profile),
                                     (gpointer) &srgb_profile);
        }

      return linear_rgb_profile;
    }
  else
    {
      if (! linear_rgb_profile)
        {
          linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
          g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
                                     (gpointer) &linear_rgb_profile);
        }

      return srgb_profile;
    }
}
Exemplo n.º 3
0
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;
}