static void
gimp_image_convert_profile_rgb (GimpImage                *image,
                                GimpColorProfile         *src_profile,
                                GimpColorProfile         *dest_profile,
                                GimpColorRenderingIntent  intent,
                                gboolean                  bpc,
                                GimpProgress             *progress)
{
  GList *layers;
  GList *list;
  gint   n_drawables;
  gint   nth_drawable;

  layers = gimp_image_get_layer_list (image);

  n_drawables = g_list_length (layers);

  for (list = layers, nth_drawable = 0;
       list;
       list = g_list_next (list), nth_drawable++)
    {
      GimpDrawable    *drawable = list->data;
      cmsHPROFILE      src_lcms;
      cmsHPROFILE      dest_lcms;
      const Babl      *iter_format;
      cmsUInt32Number  lcms_format;
      cmsUInt32Number  flags;
      cmsHTRANSFORM    transform;

      if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
        continue;

      src_lcms  = gimp_color_profile_get_lcms_profile (src_profile);
      dest_lcms = gimp_color_profile_get_lcms_profile (dest_profile);

      iter_format =
        gimp_color_profile_get_format (gimp_drawable_get_format (drawable),
                                       &lcms_format);

      flags = cmsFLAGS_NOOPTIMIZE;

      if (bpc)
        flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;

      transform = cmsCreateTransform (src_lcms,  lcms_format,
                                      dest_lcms, lcms_format,
                                      intent, flags);

      if (transform)
        {
          GeglBuffer         *buffer;
          GeglBufferIterator *iter;

          buffer = gimp_drawable_get_buffer (drawable);

          gimp_drawable_push_undo (drawable, NULL, NULL,
                                   0, 0,
                                   gegl_buffer_get_width  (buffer),
                                   gegl_buffer_get_height (buffer));

          iter = gegl_buffer_iterator_new (buffer, NULL, 0,
                                           iter_format,
                                           GEGL_ACCESS_READWRITE,
                                           GEGL_ABYSS_NONE);

          while (gegl_buffer_iterator_next (iter))
            {
              cmsDoTransform (transform,
                              iter->data[0], iter->data[0], iter->length);
            }

          gimp_drawable_update (drawable, 0, 0,
                                gegl_buffer_get_width  (buffer),
                                gegl_buffer_get_height (buffer));

          cmsDeleteTransform (transform);
        }

      if (progress)
        gimp_progress_set_value (progress,
                                 (gdouble) nth_drawable / (gdouble) n_drawables);
    }

  g_list_free (layers);
}
Example #2
0
GimpColorTransform
gimp_widget_get_color_transform (GtkWidget         *widget,
                                 GimpColorConfig   *config,
                                 GimpColorProfile  *src_profile,
                                 const Babl       **src_format,
                                 const Babl       **dest_format)
{
    GimpColorTransform  transform     = NULL;
    GimpColorProfile   *dest_profile  = NULL;
    GimpColorProfile   *proof_profile = NULL;
    cmsHPROFILE         src_lcms;
    cmsHPROFILE         dest_lcms;
    cmsUInt32Number     lcms_src_format;
    cmsUInt32Number     lcms_dest_format;
    cmsUInt16Number     alarmCodes[cmsMAXCHANNELS] = { 0, };

    g_return_val_if_fail (widget == NULL || GTK_IS_WIDGET (widget), NULL);
    g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (src_profile), NULL);
    g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
    g_return_val_if_fail (src_format != NULL, NULL);
    g_return_val_if_fail (dest_format != NULL, NULL);

    switch (config->mode)
    {
    case GIMP_COLOR_MANAGEMENT_OFF:
        return NULL;

    case GIMP_COLOR_MANAGEMENT_SOFTPROOF:
        proof_profile = gimp_color_config_get_printer_color_profile (config, NULL);
    /*  fallthru  */

    case GIMP_COLOR_MANAGEMENT_DISPLAY:
        dest_profile = get_display_profile (widget, config);
        break;
    }

    src_lcms  = gimp_color_profile_get_lcms_profile (src_profile);
    dest_lcms = gimp_color_profile_get_lcms_profile (dest_profile);

    *src_format  = gimp_color_profile_get_format (*src_format,  &lcms_src_format);
    *dest_format = gimp_color_profile_get_format (*dest_format, &lcms_dest_format);

    if (proof_profile)
    {
        cmsHPROFILE     proof_lcms;
        cmsUInt32Number softproof_flags = cmsFLAGS_SOFTPROOFING;

        proof_lcms = gimp_color_profile_get_lcms_profile (proof_profile);

        if (config->simulation_use_black_point_compensation)
        {
            softproof_flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
        }

        if (config->simulation_gamut_check)
        {
            guchar r, g, b;

            softproof_flags |= cmsFLAGS_GAMUTCHECK;

            gimp_rgb_get_uchar (&config->out_of_gamut_color, &r, &g, &b);

            alarmCodes[0] = (cmsUInt16Number) r * 256;
            alarmCodes[1] = (cmsUInt16Number) g * 256;
            alarmCodes[2] = (cmsUInt16Number) b * 256;

            cmsSetAlarmCodes (alarmCodes);
        }

        transform = cmsCreateProofingTransform (src_lcms,  lcms_src_format,
                                                dest_lcms, lcms_dest_format,
                                                proof_lcms,
                                                config->simulation_intent,
                                                config->display_intent,
                                                softproof_flags);

        g_object_unref (proof_profile);
    }
    else if (! gimp_color_profile_is_equal (src_profile, dest_profile))
    {
        cmsUInt32Number display_flags = 0;

        if (config->display_use_black_point_compensation)
        {
            display_flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
        }

        transform = cmsCreateTransform (src_lcms,  lcms_src_format,
                                        dest_lcms, lcms_dest_format,
                                        config->display_intent,
                                        display_flags);
    }

    g_object_unref (dest_profile);

    return transform;
}
Example #3
0
void
gimp_gegl_convert_color_profile (GeglBuffer               *src_buffer,
                                 const GeglRectangle      *src_rect,
                                 GimpColorProfile         *src_profile,
                                 GeglBuffer               *dest_buffer,
                                 const GeglRectangle      *dest_rect,
                                 GimpColorProfile         *dest_profile,
                                 GimpColorRenderingIntent  intent,
                                 gboolean                  bpc)
{
  const Babl       *src_format;
  const Babl       *dest_format;
  cmsHPROFILE       src_lcms;
  cmsHPROFILE       dest_lcms;
  cmsUInt32Number   lcms_src_format;
  cmsUInt32Number   lcms_dest_format;
  cmsUInt32Number   flags;
  cmsHTRANSFORM     transform;

  /*  FIXME: we need the unconditional full copy only in two cases:
   *  - if we return without doing anything
   *  - if there is an alpha channel, because lcms doesn't copy it
   */
  gegl_buffer_copy (src_buffer,  src_rect, GEGL_ABYSS_NONE,
                    dest_buffer, dest_rect);

  src_format  = gegl_buffer_get_format (src_buffer);
  dest_format = gegl_buffer_get_format (dest_buffer);

  if ((gimp_babl_format_get_base_type (src_format)  != GIMP_RGB) ||
      (gimp_babl_format_get_base_type (dest_format) != GIMP_RGB))
    return;

  if (gimp_color_profile_can_gegl_copy (src_profile, dest_profile))
    return;

  src_lcms  = gimp_color_profile_get_lcms_profile (src_profile);
  dest_lcms = gimp_color_profile_get_lcms_profile (dest_profile);

  src_format  = gimp_color_profile_get_format (src_format,  &lcms_src_format);
  dest_format = gimp_color_profile_get_format (dest_format, &lcms_dest_format);

  flags = cmsFLAGS_NOOPTIMIZE;

  if (bpc)
    flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;

  transform = cmsCreateTransform (src_lcms,  lcms_src_format,
                                  dest_lcms, lcms_dest_format,
                                  intent, flags);

  if (transform)
    {
      GeglBufferIterator *iter;

      iter = gegl_buffer_iterator_new (src_buffer, src_rect, 0,
                                       src_format,
                                       GEGL_ACCESS_READ,
                                       GEGL_ABYSS_NONE);

      gegl_buffer_iterator_add (iter, dest_buffer, dest_rect, 0,
                                dest_format,
                                GEGL_ACCESS_WRITE,
                                GEGL_ABYSS_NONE);

      while (gegl_buffer_iterator_next (iter))
        {
          cmsDoTransform (transform,
                          iter->data[0], iter->data[1], iter->length);
        }

      cmsDeleteTransform (transform);
    }
}
Example #4
0
/**
 * gimp_color_transform_new_proofing:
 * @src_profile:
 * @src_format:
 * @desr_profile:
 * @dest_format:
 * @proof_profile:
 * @proof_intent:
 * @display_intent:
 * @flags:
 *
 * This function creates a simulation / proofing color transform.
 *
 * Return value: the #GimpColorTransform, or %NULL.
 *
 * Since: 2.10
 **/
GimpColorTransform *
gimp_color_transform_new_proofing (GimpColorProfile         *src_profile,
                                   const Babl               *src_format,
                                   GimpColorProfile         *dest_profile,
                                   const Babl               *dest_format,
                                   GimpColorProfile         *proof_profile,
                                   GimpColorRenderingIntent  proof_intent,
                                   GimpColorRenderingIntent  display_intent,
                                   GimpColorTransformFlags   flags)
{
  GimpColorTransform        *transform;
  GimpColorTransformPrivate *priv;
  cmsHPROFILE                src_lcms;
  cmsHPROFILE                dest_lcms;
  cmsHPROFILE                proof_lcms;
  cmsUInt32Number            lcms_src_format;
  cmsUInt32Number            lcms_dest_format;

  g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (src_profile), NULL);
  g_return_val_if_fail (src_format != NULL, NULL);
  g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (dest_profile), NULL);
  g_return_val_if_fail (dest_format != NULL, NULL);
  g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (proof_profile), NULL);

  transform = g_object_new (GIMP_TYPE_COLOR_TRANSFORM, NULL);

  priv = transform->priv;

  src_lcms   = gimp_color_profile_get_lcms_profile (src_profile);
  dest_lcms  = gimp_color_profile_get_lcms_profile (dest_profile);
  proof_lcms = gimp_color_profile_get_lcms_profile (proof_profile);

  priv->src_format  = gimp_color_profile_get_format (src_format,
                                                     &lcms_src_format);
  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,
                                                proof_intent,
                                                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);
      transform = NULL;
    }

  return transform;
}
Example #5
0
void
gimp_gegl_convert_color_profile (GeglBuffer               *src_buffer,
                                 const GeglRectangle      *src_rect,
                                 GimpColorProfile         *src_profile,
                                 GeglBuffer               *dest_buffer,
                                 const GeglRectangle      *dest_rect,
                                 GimpColorProfile         *dest_profile,
                                 GimpColorRenderingIntent  intent,
                                 gboolean                  bpc,
                                 GimpProgress             *progress)
{
  const Babl       *src_format;
  const Babl       *dest_format;
  cmsHPROFILE       src_lcms;
  cmsHPROFILE       dest_lcms;
  cmsUInt32Number   lcms_src_format;
  cmsUInt32Number   lcms_dest_format;
  cmsUInt32Number   flags;
  cmsHTRANSFORM     transform;

  src_format  = gegl_buffer_get_format (src_buffer);
  dest_format = gegl_buffer_get_format (dest_buffer);

  if (gimp_color_profile_can_gegl_copy (src_profile, dest_profile))
    {
      gegl_buffer_copy (src_buffer,  src_rect, GEGL_ABYSS_NONE,
                        dest_buffer, dest_rect);
      return;
    }

  src_lcms  = gimp_color_profile_get_lcms_profile (src_profile);
  dest_lcms = gimp_color_profile_get_lcms_profile (dest_profile);

  src_format  = gimp_color_profile_get_format (src_format,  &lcms_src_format);
  dest_format = gimp_color_profile_get_format (dest_format, &lcms_dest_format);

  flags = cmsFLAGS_NOOPTIMIZE;

  if (bpc)
    flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;

  transform = cmsCreateTransform (src_lcms,  lcms_src_format,
                                  dest_lcms, lcms_dest_format,
                                  intent, flags);

  if (transform)
    {
      gimp_gegl_convert_color_transform (src_buffer,  src_rect,  src_format,
                                         dest_buffer, dest_rect, dest_format,
                                         transform, progress);

      cmsDeleteTransform (transform);
    }
  else
    {
      /* FIXME: no idea if this ever happens */
      gegl_buffer_copy (src_buffer,  src_rect, GEGL_ABYSS_NONE,
                        dest_buffer, dest_rect);

      if (progress)
        gimp_progress_set_value (progress, 1.0);
    }
}