Esempio n. 1
0
static void
gimp_color_config_set_printer_profile (GimpColorConfig  *config,
                                       const gchar      *filename,
                                       GError          **error)
{
  gboolean success = TRUE;

  if (filename)
    {
      GimpColorProfile *profile;
      GFile            *file = g_file_new_for_path (filename);

      profile = gimp_color_profile_new_from_file (file, error);

      if (profile)
        {
          g_object_unref (profile);
        }
      else
        {
          success = FALSE;
        }

      g_object_unref (file);
    }

  if (success)
    {
      g_free (config->printer_profile);
      config->printer_profile = g_strdup (filename);
    }
}
Esempio n. 2
0
static void
color_profile_dest_changed (GtkWidget     *combo,
                            ProfileDialog *dialog)
{
  GimpColorProfile *dest_profile = NULL;
  GFile            *file;
  GError           *error        = NULL;

  file = gimp_color_profile_combo_box_get_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo));

  if (file)
    {
      dest_profile = gimp_color_profile_new_from_file (file, &error);
      g_object_unref (file);
    }
  else
    {
      dest_profile = g_object_ref (dialog->builtin_profile);
    }

  if (! dest_profile)
    {
      gimp_color_profile_view_set_error (GIMP_COLOR_PROFILE_VIEW (dialog->dest_view),
                                         error->message);
      g_clear_error (&error);
    }
  else
    {
      gimp_color_profile_view_set_profile (GIMP_COLOR_PROFILE_VIEW (dialog->dest_view),
                                           dest_profile);
      g_object_unref (dest_profile);
    }
}
Esempio n. 3
0
GimpColorProfile *
gimp_color_config_get_cmyk_color_profile (GimpColorConfig  *config,
                                          GError          **error)
{
  GimpColorProfile *profile = NULL;

  g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (config->cmyk_profile)
    {
      GFile *file = g_file_new_for_path (config->cmyk_profile);

      profile = gimp_color_profile_new_from_file (file, error);

      if (profile && ! gimp_color_profile_is_cmyk (profile))
        {
          g_object_unref (profile);
          profile = NULL;

          g_set_error (error, GIMP_CONFIG_ERROR, 0,
                       _("Color profile '%s' is not for CMYK color space."),
                       gimp_file_get_utf8_name (file));
        }

      g_object_unref (file);
    }

  return profile;
}
Esempio n. 4
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);
}
Esempio n. 5
0
GimpColorProfile *
gimp_color_config_get_printer_color_profile (GimpColorConfig  *config,
                                             GError          **error)
{
  GimpColorProfile *profile = NULL;

  g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (config->printer_profile)
    {
      GFile *file = g_file_new_for_path (config->printer_profile);

      profile = gimp_color_profile_new_from_file (file, error);
      g_object_unref (file);
    }

  return profile;
}
Esempio n. 6
0
static void
gimp_color_config_set_cmyk_profile (GimpColorConfig  *config,
                                    const gchar      *filename,
                                    GError          **error)
{
  gboolean success = TRUE;

  if (filename)
    {
      GimpColorProfile *profile;
      GFile            *file = g_file_new_for_path (filename);

      profile = gimp_color_profile_new_from_file (file, error);

      if (profile)
        {
          if (! gimp_color_profile_is_cmyk (profile))
            {
              g_set_error (error, GIMP_CONFIG_ERROR, 0,
                           _("Color profile '%s' is not for CMYK color space."),
                           gimp_file_get_utf8_name (file));
              success = FALSE;
            }

          g_object_unref (profile);
        }
      else
        {
          success = FALSE;
        }

      g_object_unref (file);
    }

  if (success)
    {
      g_free (config->cmyk_profile);
      config->cmyk_profile = g_strdup (filename);
    }
}
/**
 * gimp_color_profile_combo_box_set_active:
 * @combo:    a #GimpColorProfileComboBox
 * @filename: filename of the profile to select
 * @label:    label to use when adding a new entry (can be %NULL)
 *
 * Selects a color profile from the @combo and makes it the active
 * item.  If the profile is not listed in the @combo, then it is added
 * with the given @label (or @filename in case that @label is %NULL).
 *
 * Since: 2.4
 **/
void
gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
                                         const gchar              *filename,
                                         const gchar              *label)
{
  GtkTreeModel *model;
  GtkTreeIter   iter;

  g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));

  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));

  if (filename && ! (label && *label))
    {
      GFile            *file;
      GimpColorProfile *profile;
      GError           *error = NULL;

      file = g_file_new_for_path (filename);
      profile = gimp_color_profile_new_from_file (file, &error);
      g_object_unref (file);

      if (! profile)
        {
          g_message ("%s", error->message);
          g_clear_error (&error);
        }
      else
        {
          label = gimp_color_profile_get_label (profile);
          g_object_unref (profile);
        }
    }

  if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model),
                                             filename, label, &iter))
    {
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
    }
}
Esempio n. 8
0
GimpColorProfile *
gimp_widget_get_color_profile (GtkWidget *widget)
{
    GimpColorProfile *profile = NULL;
    GdkScreen        *screen;
    gint              monitor;

    g_return_val_if_fail (widget == NULL || GTK_IS_WIDGET (widget), NULL);

    if (widget)
    {
        screen  = gtk_widget_get_screen (widget);
        monitor = gimp_widget_get_monitor (widget);
    }
    else
    {
        screen  = gdk_screen_get_default ();
        monitor = 0;
    }

#if defined GDK_WINDOWING_X11
    {
        GdkAtom  type    = GDK_NONE;
        gint     format  = 0;
        gint     nitems  = 0;
        gchar   *atom_name;
        guchar  *data    = NULL;

        if (monitor > 0)
            atom_name = g_strdup_printf ("_ICC_PROFILE_%d", monitor);
        else
            atom_name = g_strdup ("_ICC_PROFILE");

        if (gdk_property_get (gdk_screen_get_root_window (screen),
                              gdk_atom_intern (atom_name, FALSE),
                              GDK_NONE,
                              0, 64 * 1024 * 1024, FALSE,
                              &type, &format, &nitems, &data) && nitems > 0)
        {
            profile = gimp_color_profile_new_from_icc_profile (data, nitems,
                      NULL);
            g_free (data);
        }

        g_free (atom_name);
    }
#elif defined GDK_WINDOWING_QUARTZ
    {
        CMProfileRef prof = NULL;

        CMGetProfileByAVID (monitor, &prof);

        if (prof)
        {
            CFDataRef data;

            data = CMProfileCopyICCData (NULL, prof);
            CMCloseProfile (prof);

            if (data)
            {
                UInt8 *buffer = g_malloc (CFDataGetLength (data));

                /* We cannot use CFDataGetBytesPtr(), because that returns
                 * a const pointer where cmsOpenProfileFromMem wants a
                 * non-const pointer.
                 */
                CFDataGetBytes (data, CFRangeMake (0, CFDataGetLength (data)),
                                buffer);

                profile = gimp_color_profile_new_from_icc_profile (data,
                          CFDataGetLength (data),
                          NULL);

                g_free (buffer);
                CFRelease (data);
            }
        }
    }
#elif defined G_OS_WIN32
    {
        HDC hdc = GetDC (NULL);

        if (hdc)
        {
            gchar  *path;
            gint32  len = 0;

            GetICMProfile (hdc, &len, NULL);
            path = g_new (gchar, len);

            if (GetICMProfile (hdc, &len, path))
            {
                GFile *file = g_file_new_for_path (path);

                profile = gimp_color_profile_new_from_file (file, NULL);
                g_object_unref (file);
            }

            g_free (path);
            ReleaseDC (NULL, hdc);
        }
    }
#endif

    return profile;
}
Esempio n. 9
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);
    }
}
Esempio n. 10
0
/**
 * gimp_monitor_get_color_profile:
 * @monitor: a #GdkMonitor
 *
 * This function returns the #GimpColorProfile of @monitor
 * or %NULL if there is no profile configured.
 *
 * Since: 3.0
 *
 * Return value: the monitor's #GimpColorProfile, or %NULL.
 **/
GimpColorProfile *
gimp_monitor_get_color_profile (GdkMonitor *monitor)
{
  GdkDisplay       *display;
  GdkScreen        *screen;
  GimpColorProfile *profile = NULL;

  g_return_val_if_fail (GDK_IS_MONITOR (monitor), NULL);

  display = gdk_monitor_get_display (monitor);

#if defined GDK_WINDOWING_X11
  {
    GdkAtom  type    = GDK_NONE;
    gint     format  = 0;
    gint     nitems  = 0;
    gint     number;
    gchar   *atom_name;
    guchar  *data    = NULL;

    number = monitor_number (monitor);

    if (number > 0)
      atom_name = g_strdup_printf ("_ICC_PROFILE_%d", number);
    else
      atom_name = g_strdup ("_ICC_PROFILE");

    screen = gdk_display_get_default_screen (display);

    if (gdk_property_get (gdk_screen_get_root_window (screen),
                          gdk_atom_intern (atom_name, FALSE),
                          GDK_NONE,
                          0, 64 * 1024 * 1024, FALSE,
                          &type, &format, &nitems, &data) && nitems > 0)
      {
        profile = gimp_color_profile_new_from_icc_profile (data, nitems,
                                                           NULL);
        g_free (data);
      }

    g_free (atom_name);
  }
#elif defined GDK_WINDOWING_QUARTZ
  {
    CGColorSpaceRef space = NULL;

    space = CGDisplayCopyColorSpace (monitor_number (monitor));

    if (space)
      {
        CFDataRef data;

        data = CGColorSpaceCopyICCData (space);

        if (data)
          {
            UInt8 *buffer = g_malloc (CFDataGetLength (data));

            /* We cannot use CFDataGetBytesPtr(), because that returns
             * a const pointer where cmsOpenProfileFromMem wants a
             * non-const pointer.
             */
            CFDataGetBytes (data, CFRangeMake (0, CFDataGetLength (data)),
                            buffer);

            profile = gimp_color_profile_new_from_icc_profile (buffer,
                                                               CFDataGetLength (data),
                                                               NULL);

            g_free (buffer);
            CFRelease (data);
          }

        CFRelease (space);
      }
  }
#elif defined G_OS_WIN32
  {
    HDC hdc = GetDC (NULL);

    if (hdc)
      {
        gchar  *path;
        gint32  len = 0;

        GetICMProfile (hdc, (LPDWORD) &len, NULL);
        path = g_new (gchar, len);

        if (GetICMProfile (hdc, (LPDWORD) &len, path))
          {
            GFile *file = g_file_new_for_path (path);

            profile = gimp_color_profile_new_from_file (file, NULL);
            g_object_unref (file);
          }

        g_free (path);
        ReleaseDC (NULL, hdc);
      }
  }
#endif

  return profile;
}