display-filter-lcms.c 20.7 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20 21
#include <glib.h>  /* lcms.h uses the "inline" keyword */

22 23
#include <string.h>

24
#ifdef G_OS_WIN32
25
#define STRICT
26
#include <windows.h>
27
#define LCMS_WIN_TYPES_ALREADY_DEFINED
28 29
#endif

30
#include <lcms2.h>
31

32
#include <gegl.h>
33 34
#include <gtk/gtk.h>

35 36 37 38 39 40
#ifdef GDK_WINDOWING_QUARTZ
#include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>
#include <CoreServices/CoreServices.h>
#endif

41
#include "libgimpbase/gimpbase.h"
42
#include "libgimpcolor/gimpcolor.h"
43 44 45 46 47 48 49 50
#include "libgimpconfig/gimpconfig.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpmodule/gimpmodule.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "libgimp/libgimp-intl.h"


51
#define CDISPLAY_TYPE_LCMS            (cdisplay_lcms_get_type ())
52 53 54 55 56 57
#define CDISPLAY_LCMS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_LCMS, CdisplayLcms))
#define CDISPLAY_LCMS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_LCMS, CdisplayLcmsClass))
#define CDISPLAY_IS_LCMS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_LCMS))
#define CDISPLAY_IS_LCMS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_LCMS))


58
typedef struct _CdisplayLcms      CdisplayLcms;
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
typedef struct _CdisplayLcmsClass CdisplayLcmsClass;

struct _CdisplayLcms
{
  GimpColorDisplay  parent_instance;

  cmsHTRANSFORM     transform;
};

struct _CdisplayLcmsClass
{
  GimpColorDisplayClass parent_instance;
};


74
GType               cdisplay_lcms_get_type             (void);
75

76
static void         cdisplay_lcms_finalize             (GObject           *object);
77

78 79 80 81
static GtkWidget  * cdisplay_lcms_configure            (GimpColorDisplay  *display);
static void         cdisplay_lcms_convert_surface      (GimpColorDisplay  *display,
                                                        cairo_surface_t   *surface);
static void         cdisplay_lcms_changed              (GimpColorDisplay  *display);
82

83 84 85
static cmsHPROFILE  cdisplay_lcms_get_rgb_profile      (CdisplayLcms      *lcms);
static cmsHPROFILE  cdisplay_lcms_get_display_profile  (CdisplayLcms      *lcms);
static cmsHPROFILE  cdisplay_lcms_get_printer_profile  (CdisplayLcms      *lcms);
86

87 88 89 90 91 92 93 94 95
static void         cdisplay_lcms_attach_labelled      (GtkTable          *table,
                                                        gint               row,
                                                        const gchar       *text,
                                                        GtkWidget         *widget);
static void         cdisplay_lcms_update_profile_label (CdisplayLcms      *lcms,
                                                        const gchar       *name);
static void         cdisplay_lcms_notify_profile       (GObject           *config,
                                                        GParamSpec        *pspec,
                                                        CdisplayLcms      *lcms);
96

97 98 99 100 101 102

static const GimpModuleInfo cdisplay_lcms_info =
{
  GIMP_MODULE_ABI_VERSION,
  N_("Color management display filter using ICC color profiles"),
  "Sven Neumann",
103
  "v0.3",
104 105
  "(c) 2005 - 2007, released under the GPL",
  "2005 - 2007"
106 107
};

108 109
G_DEFINE_DYNAMIC_TYPE (CdisplayLcms, cdisplay_lcms,
                       GIMP_TYPE_COLOR_DISPLAY)
110 111 112 113 114 115 116 117 118 119

G_MODULE_EXPORT const GimpModuleInfo *
gimp_module_query (GTypeModule *module)
{
  return &cdisplay_lcms_info;
}

G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module)
{
120
  cdisplay_lcms_register_type (module);
121 122 123 124 125 126 127 128 129 130

  return TRUE;
}

static void
cdisplay_lcms_class_init (CdisplayLcmsClass *klass)
{
  GObjectClass          *object_class  = G_OBJECT_CLASS (klass);
  GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass);

131
  object_class->finalize         = cdisplay_lcms_finalize;
132

133 134 135
  display_class->name            = _("Color Management");
  display_class->help_id         = "gimp-colordisplay-lcms";
  display_class->stock_id        = GIMP_STOCK_DISPLAY_FILTER_LCMS;
136

137 138 139
  display_class->configure       = cdisplay_lcms_configure;
  display_class->convert_surface = cdisplay_lcms_convert_surface;
  display_class->changed         = cdisplay_lcms_changed;
140 141
}

142 143 144 145 146
static void
cdisplay_lcms_class_finalize (CdisplayLcmsClass *klass)
{
}

147 148 149 150 151 152 153
static void
cdisplay_lcms_init (CdisplayLcms *lcms)
{
  lcms->transform = NULL;
}

static void
154
cdisplay_lcms_finalize (GObject *object)
155 156 157
{
  CdisplayLcms *lcms = CDISPLAY_LCMS (object);

158
  if (lcms->transform)
159
    {
160 161
      cmsDeleteTransform (lcms->transform);
      lcms->transform = NULL;
162 163
    }

164
  G_OBJECT_CLASS (cdisplay_lcms_parent_class)->finalize (object);
165 166
}

167 168
static void
cdisplay_lcms_profile_get_info (cmsHPROFILE   profile,
169 170
                                gchar       **name,
                                gchar       **info)
171 172 173
{
  if (profile)
    {
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
      cmsUInt32Number  descSize;
      gchar           *descData;

      descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
                                         "en", "US", NULL, 0);
      if (descSize > 0)
        {
          descData = g_new (gchar, descSize + 1);
          descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
                                             "en", "US", descData, descSize);
          if (descSize > 0)
            *name = descData;
          else
            g_free (descData);
        }
189 190

      if (! *name)
191 192 193 194 195 196 197 198 199 200 201 202 203 204
        {
          descSize = cmsGetProfileInfoASCII (profile, cmsInfoModel,
                                             "en", "US", NULL, 0);
          if (descSize > 0)
            {
              descData = g_new (gchar, descSize + 1);
              descSize = cmsGetProfileInfoASCII(profile, cmsInfoModel,
                                                "en", "US", descData, descSize);
              if (descSize > 0)
                *name = descData;
              else
                g_free (descData);
            }
        }
205 206

      if (*name && ! g_utf8_validate (*name, -1, NULL))
207 208 209 210 211
        {
          g_free (*name);
          *name = g_strdup (_("(invalid UTF-8 string)"));
        }

212
      if (! *name)
213 214 215 216
	{
	  /* a color profile without a name */
	  *name = g_strdup (_("(unnamed profile)"));
	}
217

218 219 220 221 222 223 224 225 226 227 228 229
      descSize = cmsGetProfileInfoASCII (profile, cmsInfoManufacturer,
                                         "en", "US", NULL, 0);
      if (descSize > 0)
        {
          descData = g_new (gchar, descSize + 1);
          descSize = cmsGetProfileInfoASCII (profile, cmsInfoManufacturer,
                                             "en", "US", descData, descSize);
          if (descSize > 0)
            *info = descData;
          else
            g_free (descData);
        }
230

231 232 233 234 235
      if (*info && ! g_utf8_validate (*info, -1, NULL))
        {
          g_free (*info);
          *info = NULL;
        }
236 237 238
    }
  else
    {
239
      *name = g_strdup (_("None"));
240
      *info = NULL;
241 242 243
    }
}

244 245 246
static GtkWidget *
cdisplay_lcms_configure (GimpColorDisplay *display)
{
247
  CdisplayLcms *lcms   = CDISPLAY_LCMS (display);
248
  GObject      *config = G_OBJECT (gimp_color_display_get_config (display));
249
  GtkWidget    *vbox;
250
  GtkWidget    *hint;
251
  GtkWidget    *table;
252
  GtkWidget    *label;
253 254
  gint          row = 0;

255 256 257
  if (! config)
    return NULL;

258
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
259

260 261 262 263 264
  hint = gimp_hint_box_new (_("This filter takes its configuration "
                              "from the Color Management section "
                              "in the Preferences dialog."));
  gtk_box_pack_start (GTK_BOX (vbox), hint, FALSE, FALSE, 0);
  gtk_widget_show (hint);
265

266
  table = gtk_table_new (5, 2, FALSE);
267
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
268
  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 12);
269 270 271 272
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
  gtk_widget_show (table);

273 274
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
                                 _("Mode of operation:"),
275
                                 gimp_prop_enum_label_new (config, "mode"));
276

277
  label = gtk_label_new (NULL);
278
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
279
  g_object_set_data (G_OBJECT (lcms), "rgb-profile", label);
280
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
281
                                 _("Image profile:"),
282
                                 label);
283
  cdisplay_lcms_update_profile_label (lcms, "rgb-profile");
284

285
  label = gtk_label_new (NULL);
286
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
287
  g_object_set_data (G_OBJECT (lcms), "display-profile", label);
288 289
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
                                 _("Monitor profile:"),
290
                                 label);
291
  cdisplay_lcms_update_profile_label (lcms, "display-profile");
292

293
  label = gtk_label_new (NULL);
294
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
295
  g_object_set_data (G_OBJECT (lcms), "printer-profile", label);
296 297
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
                                 _("Print simulation profile:"),
298
                                 label);
299 300 301 302 303
  cdisplay_lcms_update_profile_label (lcms, "printer-profile");

  g_signal_connect_object (config, "notify",
                           G_CALLBACK (cdisplay_lcms_notify_profile),
                           lcms, 0);
304 305

  return vbox;
306 307
}

308
static void
309 310
cdisplay_lcms_convert_surface (GimpColorDisplay *display,
                               cairo_surface_t  *surface)
311
{
312 313 314 315 316 317 318 319 320 321 322
  CdisplayLcms   *lcms   = CDISPLAY_LCMS (display);
  gint            width  = cairo_image_surface_get_width (surface);
  gint            height = cairo_image_surface_get_height (surface);
  gint            stride = cairo_image_surface_get_stride (surface);
  guchar         *buf    = cairo_image_surface_get_data (surface);
  cairo_format_t  fmt    = cairo_image_surface_get_format (surface);
  guchar         *rowbuf;
  gint            x, y;
  guchar          r, g, b, a;

  if (fmt != CAIRO_FORMAT_ARGB32)
323 324 325 326 327
    return;

  if (! lcms->transform)
    return;

328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
  rowbuf = g_malloc (stride);

  for (y = 0; y < height; y++, buf += stride)
    {
      /* Switch buf from ARGB premul to ARGB non-premul, since lcms ignores the
       * alpha channel.  The macro takes care of byte order.
       */
      for (x = 0; x < width; x++)
        {
          GIMP_CAIRO_ARGB32_GET_PIXEL (buf + 4*x, r, g, b, a);
          rowbuf[4*x+0] = a;
          rowbuf[4*x+1] = r;
          rowbuf[4*x+2] = g;
          rowbuf[4*x+3] = b;
        }

      cmsDoTransform (lcms->transform, rowbuf, rowbuf, width);

      /* And back to ARGB premul */
      for (x = 0; x < width; x++)
        {
          a = rowbuf[4*x+0];
          r = rowbuf[4*x+1];
          g = rowbuf[4*x+2];
          b = rowbuf[4*x+3];
          GIMP_CAIRO_ARGB32_SET_PIXEL (buf + 4*x, r, g, b, a);
        }
    }

  g_free (rowbuf);
358 359 360 361 362 363
}

static void
cdisplay_lcms_changed (GimpColorDisplay *display)
{
  CdisplayLcms    *lcms   = CDISPLAY_LCMS (display);
364
  GimpColorConfig *config = gimp_color_display_get_config (display);
365 366 367 368

  cmsHPROFILE      src_profile   = NULL;
  cmsHPROFILE      dest_profile  = NULL;
  cmsHPROFILE      proof_profile = NULL;
369
  cmsUInt32Number  flags         = 0;
370
  cmsUInt16Number  alarmCodes[cmsMAXCHANNELS] = { 0, };
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386

  if (lcms->transform)
    {
      cmsDeleteTransform (lcms->transform);
      lcms->transform = NULL;
    }

  if (! config)
    return;

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

    case GIMP_COLOR_MANAGEMENT_SOFTPROOF:
387
      proof_profile = cdisplay_lcms_get_printer_profile (lcms);
388 389 390
      /*  fallthru  */

    case GIMP_COLOR_MANAGEMENT_DISPLAY:
391 392
      src_profile = cdisplay_lcms_get_rgb_profile (lcms);
      dest_profile = cdisplay_lcms_get_display_profile (lcms);
393 394 395
      break;
    }

396 397 398
  if (config->display_intent ==
      GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC)
    {
399
      flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
400 401
    }

402 403
  if (proof_profile)
    {
404
      if (! src_profile)
405
        src_profile = cmsCreate_sRGBProfile ();
406 407

      if (! dest_profile)
408
        dest_profile = cmsCreate_sRGBProfile ();
409

410 411
      flags |= cmsFLAGS_SOFTPROOFING;

412 413 414 415 416 417 418 419
      if (config->simulation_gamut_check)
        {
          guchar r, g, b;

          flags |= cmsFLAGS_GAMUTCHECK;

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

420 421 422
          alarmCodes[0] = (cmsUInt16Number) r * 256;
          alarmCodes[1] = (cmsUInt16Number) g * 256;
          alarmCodes[2] = (cmsUInt16Number) b * 256;
423 424

          cmsSetAlarmCodes (alarmCodes);
425 426
        }

427 428
      lcms->transform = cmsCreateProofingTransform (src_profile, TYPE_ARGB_8,
                                                    dest_profile, TYPE_ARGB_8,
429 430
                                                    proof_profile,
                                                    config->simulation_intent,
431
                                                    config->display_intent,
432
                                                    flags);
433 434
      cmsCloseProfile (proof_profile);
    }
435
  else if (src_profile || dest_profile)
436
    {
437
      if (! src_profile)
438
        src_profile = cmsCreate_sRGBProfile ();
439 440

      if (! dest_profile)
441
        dest_profile = cmsCreate_sRGBProfile ();
442

443 444
      lcms->transform = cmsCreateTransform (src_profile, TYPE_ARGB_8,
                                            dest_profile, TYPE_ARGB_8,
445
                                            config->display_intent,
446
                                            flags);
447 448 449 450 451
    }

  if (dest_profile)
    cmsCloseProfile (dest_profile);

452 453
  if (src_profile)
    cmsCloseProfile (src_profile);
454 455
}

456 457
static gboolean
cdisplay_lcms_profile_is_rgb (cmsHPROFILE profile)
458
{
459
  return (cmsGetColorSpace (profile) == cmsSigRgbData);
460
}
461

462 463 464 465 466 467
static cmsHPROFILE
cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms)
{
  GimpColorConfig  *config;
  GimpColorManaged *managed;
  cmsHPROFILE       profile = NULL;
468

469
  managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms));
470

471
  if (managed)
472
    {
473 474
      gsize         len;
      const guint8 *data = gimp_color_managed_get_icc_profile (managed, &len);
475

476 477
      if (data)
        profile = cmsOpenProfileFromMem ((gpointer) data, len);
478

479 480
      if (profile &&
          ! cdisplay_lcms_profile_is_rgb (profile))
481 482 483 484 485
        {
          cmsCloseProfile (profile);
          profile = NULL;
        }
    }
486

487 488 489
  if (! profile)
    {
      config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
490

491 492 493
      if (config->rgb_profile)
        profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
    }
494

495
  return profile;
496
}
497

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
static GdkScreen *
cdisplay_lcms_get_screen (CdisplayLcms *lcms,
                          gint         *monitor)
{
  GimpColorManaged *managed;
  GdkScreen        *screen;

  managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms));

  if (GTK_IS_WIDGET (managed))
    screen = gtk_widget_get_screen (GTK_WIDGET (managed));
  else
    screen = gdk_screen_get_default ();

  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);

514
  if (GTK_IS_WIDGET (managed) && gtk_widget_is_drawable (GTK_WIDGET (managed)))
515 516 517
    {
      GtkWidget *widget = GTK_WIDGET (managed);

518 519
      *monitor = gdk_screen_get_monitor_at_window (screen,
                                                   gtk_widget_get_window (widget));
520 521 522 523 524 525 526 527 528
    }
  else
    {
      *monitor = 0;
    }

  return screen;
}

529

530
static cmsHPROFILE
531
cdisplay_lcms_get_display_profile (CdisplayLcms *lcms)
532
{
533 534 535 536
  GimpColorConfig *config;
  cmsHPROFILE      profile = NULL;

  config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
537

538
#if defined GDK_WINDOWING_X11
539 540
  if (config->display_profile_from_gdk)
    {
541 542 543 544 545 546 547
      GdkScreen *screen;
      GdkAtom    type    = GDK_NONE;
      gint       format  = 0;
      gint       nitems  = 0;
      gint       monitor = 0;
      gchar     *atom_name;
      guchar    *data    = NULL;
548

549
      screen = cdisplay_lcms_get_screen (lcms, &monitor);
550

551 552 553 554
      if (monitor > 0)
        atom_name = g_strdup_printf ("_ICC_PROFILE_%d", monitor);
      else
        atom_name = g_strdup ("_ICC_PROFILE");
555

556
      if (gdk_property_get (gdk_screen_get_root_window (screen),
557
                            gdk_atom_intern (atom_name, FALSE),
558 559 560
                            GDK_NONE,
                            0, 64 * 1024 * 1024, FALSE,
                            &type, &format, &nitems, &data) && nitems > 0)
561
        {
562
          profile = cmsOpenProfileFromMem (data, nitems);
563 564
          g_free (data);
        }
565 566

      g_free (atom_name);
567
    }
568 569 570 571

#elif defined GDK_WINDOWING_QUARTZ
  if (config->display_profile_from_gdk)
    {
572 573 574 575 576 577 578 579 580
      CMProfileRef  prof    = NULL;
      gint          monitor = 0;

      cdisplay_lcms_get_screen (lcms, &monitor);

      CMGetProfileByAVID (monitor, &prof);

      if (prof)
        {
581
          CFDataRef data;
582

583
          data = CMProfileCopyICCData (NULL, prof);
584 585
          CMCloseProfile (prof);

586
          if (data)
587
            {
588 589 590 591 592 593 594 595 596 597 598 599 600
              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 = cmsOpenProfileFromMem (buffer, CFDataGetLength (data));

              g_free (buffer);
              CFRelease (data);
601 602
            }
        }
603 604
    }

605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
#elif defined G_OS_WIN32
  if (config->display_profile_from_gdk)
    {
      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))
            profile = cmsOpenProfileFromFile (path, "r");

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

627
  if (! profile && config->display_profile)
628
    profile = cmsOpenProfileFromFile (config->display_profile, "r");
629

630
  return profile;
631
}
632 633 634 635

static cmsHPROFILE
cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms)
{
636 637 638
  GimpColorConfig *config;

  config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
639 640 641 642 643 644

  if (config->printer_profile)
    return cmsOpenProfileFromFile (config->printer_profile, "r");

  return NULL;
}
645 646 647 648 649

static void
cdisplay_lcms_attach_labelled (GtkTable    *table,
                               gint         row,
                               const gchar *text,
650
                               GtkWidget   *widget)
651
{
652
  GtkWidget *label;
653

654 655 656 657 658 659 660 661 662
  label = g_object_new (GTK_TYPE_LABEL,
                        "label",  text,
                        "xalign", 1.0,
                        "yalign", 0.5,
                        NULL);

  gimp_label_set_attributes (GTK_LABEL (label),
                             PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
                             -1);
663
  gtk_table_attach (table, label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
664
  gtk_widget_show (label);
665

666 667
  if (GTK_IS_LABEL (widget))
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
668

669 670
  gtk_table_attach (table, widget, 1, 2, row, row + 1,
                    GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
671 672
  gtk_widget_show (widget);
}
673 674 675 676 677 678 679

static void
cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
                                    const gchar  *name)
{
  GtkWidget   *label;
  cmsHPROFILE  profile = NULL;
680 681
  gchar       *text    = NULL;
  gchar       *tooltip = NULL;
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705

  label = g_object_get_data (G_OBJECT (lcms), name);

  if (! label)
    return;

  if (strcmp (name, "rgb-profile") == 0)
    {
      profile = cdisplay_lcms_get_rgb_profile (lcms);
    }
  else if (g_str_has_prefix (name, "display-profile"))
    {
      profile = cdisplay_lcms_get_display_profile (lcms);
    }
  else if (strcmp (name, "printer-profile") == 0)
    {
      profile = cdisplay_lcms_get_printer_profile (lcms);
    }
  else
    {
      g_return_if_reached ();
    }

  cdisplay_lcms_profile_get_info (profile, &text, &tooltip);
706 707 708

  gtk_label_set_text (GTK_LABEL (label), text);
  gimp_help_set_help_data (label, tooltip, NULL);
709

710 711 712
  g_free (text);
  g_free (tooltip);

713 714 715 716 717 718 719 720 721 722 723
  if (profile)
    cmsCloseProfile (profile);
}

static void
cdisplay_lcms_notify_profile (GObject      *config,
                              GParamSpec   *pspec,
                              CdisplayLcms *lcms)
{
  cdisplay_lcms_update_profile_label (lcms, pspec->name);
}