Beispiel #1
0
static GimpValueArray *
image_convert_color_profile_invoker (GimpProcedure         *procedure,
                                     Gimp                  *gimp,
                                     GimpContext           *context,
                                     GimpProgress          *progress,
                                     const GimpValueArray  *args,
                                     GError               **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  gint32 num_bytes;
  const guint8 *color_profile;
  gint32 intent;
  gboolean bpc;

  image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
  num_bytes = g_value_get_int (gimp_value_array_index (args, 1));
  color_profile = gimp_value_get_int8array (gimp_value_array_index (args, 2));
  intent = g_value_get_enum (gimp_value_array_index (args, 3));
  bpc = g_value_get_boolean (gimp_value_array_index (args, 4));

  if (success)
    {
      if (color_profile)
        {
          GimpColorProfile *profile;

          profile = gimp_color_profile_new_from_icc_profile (color_profile,
                                                             num_bytes,
                                                             error);

          if (profile)
            {
              success = gimp_image_convert_color_profile (image, profile,
                                                          intent, bpc,
                                                          progress, error);
              g_object_unref (profile);
            }
          else
            success = FALSE;
        }
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}
Beispiel #2
0
static GimpValueArray *
image_convert_color_profile_from_file_invoker (GimpProcedure         *procedure,
                                               Gimp                  *gimp,
                                               GimpContext           *context,
                                               GimpProgress          *progress,
                                               const GimpValueArray  *args,
                                               GError               **error)
{
  gboolean success = TRUE;
  GimpImage *image;
  const gchar *uri;
  gint32 intent;
  gboolean bpc;

  image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
  uri = g_value_get_string (gimp_value_array_index (args, 1));
  intent = g_value_get_enum (gimp_value_array_index (args, 2));
  bpc = g_value_get_boolean (gimp_value_array_index (args, 3));

  if (success)
    {
      if (uri)
        {
          GFile            *file = g_file_new_for_uri (uri);
          GimpColorProfile *profile;

          profile = gimp_color_profile_new_from_file (file, error);

          if (profile)
            {
              success = gimp_image_convert_color_profile (image, profile,
                                                          intent, bpc,
                                                          progress, error);
              g_object_unref (profile);
            }
          else
            success = FALSE;

          g_object_unref (file);
        }
      else
        success = FALSE;
    }

  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}
void
gimp_image_import_color_profile (GimpImage    *image,
                                 GimpContext  *context,
                                 GimpProgress *progress,
                                 gboolean      interactive)
{
  GimpColorConfig *config = image->gimp->config->color_management;

  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (GIMP_IS_CONTEXT (context));
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));

  config = image->gimp->config->color_management;

  if (gimp_image_get_base_type (image) == GIMP_GRAY)
    return;

  if (config->mode == GIMP_COLOR_MANAGEMENT_OFF)
    return;

  if (gimp_image_get_color_profile (image))
    {
      GimpColorProfilePolicy  policy;
      GimpColorProfile       *dest_profile = NULL;

      policy = image->gimp->config->color_profile_policy;

      if (policy == GIMP_COLOR_PROFILE_POLICY_ASK)
        {
          if (interactive)
            {
              gboolean dont_ask = FALSE;

              policy = gimp_query_profile_policy (image->gimp, image, context,
                                                  &dest_profile, &dont_ask);

              if (dont_ask)
                {
                  g_object_set (G_OBJECT (image->gimp->config),
                                "color-profile-policy", policy,
                                NULL);
                }
            }
          else
            {
              policy = GIMP_COLOR_PROFILE_POLICY_KEEP;
            }
        }

      if (policy == GIMP_COLOR_PROFILE_POLICY_CONVERT)
        {
          GimpColorRenderingIntent  intent;
          gboolean                  bpc;

          if (! dest_profile)
            {
              dest_profile = gimp_image_get_builtin_color_profile (image);
              g_object_ref (dest_profile);
            }

          intent = config->display_intent;
          bpc    = (intent == GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC);

          gimp_image_undo_disable (image);

          gimp_image_convert_color_profile (image, dest_profile,
                                            intent, bpc,
                                            progress, NULL);

          gimp_image_clean_all (image);
          gimp_image_undo_enable (image);

          g_object_unref (dest_profile);
        }
    }
}
Beispiel #4
0
static void
color_profile_dialog_response (GtkWidget     *widget,
                               gint           response_id,
                               ProfileDialog *dialog)
{
  gboolean  success = TRUE;
  GError   *error   = NULL;

  if (response_id == GTK_RESPONSE_OK)
    {
      GimpColorProfile *dest_profile = NULL;
      GFile            *file;

      file = gimp_color_profile_combo_box_get_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (dialog->combo));

      if (file)
        {
          dest_profile = gimp_color_profile_new_from_file (file, &error);

          if (! dest_profile)
            success = FALSE;

          g_object_unref (file);
        }
      else
        {
          dest_profile = g_object_ref (dialog->builtin_profile);
        }

      if (success)
        {
          switch (dialog->dialog_type)
            {
            case COLOR_PROFILE_DIALOG_ASSIGN_PROFILE:
              {
                gimp_image_undo_group_start (dialog->image,
                                             GIMP_UNDO_GROUP_PARASITE_ATTACH,
                                             _("Assign color profile"));

                success = gimp_image_set_color_profile (dialog->image,
                                                        dest_profile,
                                                        &error);

                if (success)
                  {
                    gimp_image_set_is_color_managed (dialog->image, TRUE, TRUE);

                    /*  omg...  */
                    gimp_image_parasite_detach (dialog->image,
                                                "icc-profile-name");
                  }

                gimp_image_undo_group_end (dialog->image);

                if (! success)
                  gimp_image_undo (dialog->image);
              }
              break;

            case COLOR_PROFILE_DIALOG_CONVERT_TO_PROFILE:
              {
                GimpProgress *progress;
                const gchar  *label;

                label = gimp_color_profile_get_label (dest_profile);

                progress = gimp_progress_start (dialog->progress, FALSE,
                                                _("Converting to '%s'"), label);

                success = gimp_image_convert_color_profile (dialog->image,
                                                            dest_profile,
                                                            dialog->intent,
                                                            dialog->bpc,
                                                            progress,
                                                            &error);

                if (progress)
                  gimp_progress_end (progress);

                if (success)
                  {
                    saved_intent = dialog->intent;
                    saved_bpc    = dialog->bpc;
                  }
              }
              break;

            case COLOR_PROFILE_DIALOG_CONVERT_TO_RGB:
              {
                GimpProgress *progress;
                const gchar  *label;

                label = gimp_color_profile_get_label (dest_profile);

                progress = gimp_progress_start (dialog->progress, FALSE,
                                                _("Converting to RGB (%s)"),
                                                label);

                success = gimp_image_convert_type (dialog->image,
                                                   GIMP_RGB,
                                                   dest_profile,
                                                   progress,
                                                   &error);

                if (progress)
                  gimp_progress_end (progress);
              }
              break;

            case COLOR_PROFILE_DIALOG_CONVERT_TO_GRAY:
              {
                GimpProgress *progress;
                const gchar  *label;

                label = gimp_color_profile_get_label (dest_profile);

                progress = gimp_progress_start (dialog->progress, FALSE,
                                                _("Converting to grayscale (%s)"),
                                                label);

                success = gimp_image_convert_type (dialog->image,
                                                   GIMP_GRAY,
                                                   dest_profile,
                                                   progress,
                                                   &error);

                if (progress)
                  gimp_progress_end (progress);
              }
              break;
            }

          if (success)
            gimp_image_flush (dialog->image);

          g_object_unref (dest_profile);
        }
    }

  if (success)
    {
      gtk_widget_destroy (dialog->dialog);
    }
  else
    {
      gimp_message (dialog->image->gimp, G_OBJECT (dialog->dialog),
                    GIMP_MESSAGE_ERROR,
                    "%s", error->message);
      g_clear_error (&error);
    }
}