~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to modules/cdisplay_lcms.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* GIMP - The GNU Image Manipulation Program
2
 
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
3
 
 *
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 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
#include "config.h"
20
 
 
21
 
#include <glib.h>  /* lcms.h uses the "inline" keyword */
22
 
 
23
 
#ifdef G_OS_WIN32
24
 
#define STRICT
25
 
#include <windows.h>
26
 
#define LCMS_WIN_TYPES_ALREADY_DEFINED
27
 
#endif
28
 
 
29
 
#ifdef HAVE_LCMS_LCMS_H
30
 
#include <lcms/lcms.h>
31
 
#else
32
 
#include <lcms.h>
33
 
#endif
34
 
 
35
 
#include <gtk/gtk.h>
36
 
 
37
 
#ifdef GDK_WINDOWING_QUARTZ
38
 
#include <Carbon/Carbon.h>
39
 
#include <ApplicationServices/ApplicationServices.h>
40
 
#include <CoreServices/CoreServices.h>
41
 
#endif
42
 
 
43
 
#include "libgimpcolor/gimpcolor.h"
44
 
#include "libgimpconfig/gimpconfig.h"
45
 
#include "libgimpmath/gimpmath.h"
46
 
#include "libgimpmodule/gimpmodule.h"
47
 
#include "libgimpwidgets/gimpwidgets.h"
48
 
 
49
 
#include "libgimp/libgimp-intl.h"
50
 
 
51
 
 
52
 
#define CDISPLAY_TYPE_LCMS            (cdisplay_lcms_type)
53
 
#define CDISPLAY_LCMS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_LCMS, CdisplayLcms))
54
 
#define CDISPLAY_LCMS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_LCMS, CdisplayLcmsClass))
55
 
#define CDISPLAY_IS_LCMS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_LCMS))
56
 
#define CDISPLAY_IS_LCMS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_LCMS))
57
 
 
58
 
 
59
 
typedef struct _CdisplayLcms CdisplayLcms;
60
 
typedef struct _CdisplayLcmsClass CdisplayLcmsClass;
61
 
 
62
 
struct _CdisplayLcms
63
 
{
64
 
  GimpColorDisplay  parent_instance;
65
 
 
66
 
  cmsHTRANSFORM     transform;
67
 
};
68
 
 
69
 
struct _CdisplayLcmsClass
70
 
{
71
 
  GimpColorDisplayClass parent_instance;
72
 
};
73
 
 
74
 
 
75
 
static GType     cdisplay_lcms_get_type     (GTypeModule       *module);
76
 
static void      cdisplay_lcms_class_init   (CdisplayLcmsClass *klass);
77
 
static void      cdisplay_lcms_init         (CdisplayLcms      *lcms);
78
 
static void      cdisplay_lcms_finalize     (GObject           *object);
79
 
 
80
 
static GtkWidget * cdisplay_lcms_configure  (GimpColorDisplay  *display);
81
 
static void        cdisplay_lcms_convert    (GimpColorDisplay  *display,
82
 
                                             guchar            *buf,
83
 
                                             gint               width,
84
 
                                             gint               height,
85
 
                                             gint               bpp,
86
 
                                             gint               bpl);
87
 
static void        cdisplay_lcms_changed    (GimpColorDisplay  *display);
88
 
 
89
 
static cmsHPROFILE  cdisplay_lcms_get_rgb_profile     (CdisplayLcms *lcms);
90
 
static cmsHPROFILE  cdisplay_lcms_get_display_profile (CdisplayLcms *lcms);
91
 
static cmsHPROFILE  cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms);
92
 
 
93
 
static void         cdisplay_lcms_attach_labelled (GtkTable    *table,
94
 
                                                   gint         row,
95
 
                                                   const gchar *text,
96
 
                                                   GtkWidget   *widget,
97
 
                                                   gboolean     tooltip);
98
 
static void         cdisplay_lcms_label_set_text  (GtkLabel    *label,
99
 
                                                   const gchar *text,
100
 
                                                   const gchar *tooltip);
101
 
static void         cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
102
 
                                                        const gchar  *name);
103
 
static void         cdisplay_lcms_notify_profile       (GObject      *config,
104
 
                                                        GParamSpec   *pspec,
105
 
                                                        CdisplayLcms *lcms);
106
 
 
107
 
 
108
 
static const GimpModuleInfo cdisplay_lcms_info =
109
 
{
110
 
  GIMP_MODULE_ABI_VERSION,
111
 
  N_("Color management display filter using ICC color profiles"),
112
 
  "Sven Neumann",
113
 
  "v0.3",
114
 
  "(c) 2005 - 2007, released under the GPL",
115
 
  "2005 - 2007"
116
 
};
117
 
 
118
 
static GType                  cdisplay_lcms_type = 0;
119
 
static GimpColorDisplayClass *parent_class       = NULL;
120
 
 
121
 
 
122
 
G_MODULE_EXPORT const GimpModuleInfo *
123
 
gimp_module_query (GTypeModule *module)
124
 
{
125
 
  return &cdisplay_lcms_info;
126
 
}
127
 
 
128
 
G_MODULE_EXPORT gboolean
129
 
gimp_module_register (GTypeModule *module)
130
 
{
131
 
  cdisplay_lcms_get_type (module);
132
 
 
133
 
  return TRUE;
134
 
}
135
 
 
136
 
static GType
137
 
cdisplay_lcms_get_type (GTypeModule *module)
138
 
{
139
 
  if (! cdisplay_lcms_type)
140
 
    {
141
 
      const GTypeInfo display_info =
142
 
      {
143
 
        sizeof (CdisplayLcmsClass),
144
 
        (GBaseInitFunc)     NULL,
145
 
        (GBaseFinalizeFunc) NULL,
146
 
        (GClassInitFunc) cdisplay_lcms_class_init,
147
 
        NULL,                   /* class_finalize */
148
 
        NULL,                   /* class_data     */
149
 
        sizeof (CdisplayLcms),
150
 
        0,                      /* n_preallocs    */
151
 
        (GInstanceInitFunc) cdisplay_lcms_init,
152
 
      };
153
 
 
154
 
       cdisplay_lcms_type =
155
 
        g_type_module_register_type (module, GIMP_TYPE_COLOR_DISPLAY,
156
 
                                     "CdisplayLcms", &display_info, 0);
157
 
    }
158
 
 
159
 
  return cdisplay_lcms_type;
160
 
}
161
 
 
162
 
static void
163
 
cdisplay_lcms_class_init (CdisplayLcmsClass *klass)
164
 
{
165
 
  GObjectClass          *object_class  = G_OBJECT_CLASS (klass);
166
 
  GimpColorDisplayClass *display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
167
 
 
168
 
  parent_class = g_type_class_peek_parent (klass);
169
 
 
170
 
  object_class->finalize = cdisplay_lcms_finalize;
171
 
 
172
 
  display_class->name        = _("Color Management");
173
 
  display_class->help_id     = "gimp-colordisplay-lcms";
174
 
  display_class->stock_id    = GIMP_STOCK_DISPLAY_FILTER_LCMS;
175
 
 
176
 
  display_class->configure   = cdisplay_lcms_configure;
177
 
  display_class->convert     = cdisplay_lcms_convert;
178
 
  display_class->changed     = cdisplay_lcms_changed;
179
 
 
180
 
  cmsErrorAction (LCMS_ERROR_IGNORE);
181
 
}
182
 
 
183
 
static void
184
 
cdisplay_lcms_init (CdisplayLcms *lcms)
185
 
{
186
 
  lcms->transform = NULL;
187
 
}
188
 
 
189
 
static void
190
 
cdisplay_lcms_finalize (GObject *object)
191
 
{
192
 
  CdisplayLcms *lcms = CDISPLAY_LCMS (object);
193
 
 
194
 
  if (lcms->transform)
195
 
    {
196
 
      cmsDeleteTransform (lcms->transform);
197
 
      lcms->transform = NULL;
198
 
    }
199
 
 
200
 
  G_OBJECT_CLASS (parent_class)->finalize (object);
201
 
}
202
 
 
203
 
static void
204
 
cdisplay_lcms_profile_get_info (cmsHPROFILE   profile,
205
 
                                const gchar **name,
206
 
                                const gchar **info)
207
 
{
208
 
  if (profile)
209
 
    {
210
 
      *name = cmsTakeProductDesc (profile);
211
 
 
212
 
      if (! *name)
213
 
        *name = cmsTakeProductName (profile);
214
 
 
215
 
      if (*name && ! g_utf8_validate (*name, -1, NULL))
216
 
        *name = _("(invalid UTF-8 string)");
217
 
 
218
 
      *info = cmsTakeProductInfo (profile);
219
 
      if (*name && ! g_utf8_validate (*info, -1, NULL))
220
 
        *info = NULL;
221
 
    }
222
 
  else
223
 
    {
224
 
      *name = _("None");
225
 
      *info = NULL;
226
 
    }
227
 
}
228
 
 
229
 
static GtkWidget *
230
 
cdisplay_lcms_configure (GimpColorDisplay *display)
231
 
{
232
 
  CdisplayLcms *lcms   = CDISPLAY_LCMS (display);
233
 
  GObject      *config = G_OBJECT (gimp_color_display_get_config (display));
234
 
  GtkWidget    *vbox;
235
 
  GtkWidget    *hint;
236
 
  GtkWidget    *table;
237
 
  GtkWidget    *label;
238
 
  gint          row = 0;
239
 
 
240
 
  if (! config)
241
 
    return NULL;
242
 
 
243
 
  vbox = gtk_vbox_new (FALSE, 12);
244
 
 
245
 
  hint = gimp_hint_box_new (_("This filter takes its configuration "
246
 
                              "from the Color Management section "
247
 
                              "in the Preferences dialog."));
248
 
  gtk_box_pack_start (GTK_BOX (vbox), hint, FALSE, FALSE, 0);
249
 
  gtk_widget_show (hint);
250
 
 
251
 
  table = gtk_table_new (5, 2, FALSE);
252
 
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
253
 
  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 12);
254
 
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
255
 
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
256
 
  gtk_widget_show (table);
257
 
 
258
 
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
259
 
                                 _("Mode of operation:"),
260
 
                                 gimp_prop_enum_label_new (config, "mode"),
261
 
                                 FALSE);
262
 
 
263
 
  label = gtk_label_new (NULL);
264
 
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
265
 
  g_object_set_data (G_OBJECT (lcms), "rgb-profile", label);
266
 
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
267
 
                                 _("Image profile:"),
268
 
                                 label, TRUE);
269
 
  cdisplay_lcms_update_profile_label (lcms, "rgb-profile");
270
 
 
271
 
  label = gtk_label_new (NULL);
272
 
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
273
 
  g_object_set_data (G_OBJECT (lcms), "display-profile", label);
274
 
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
275
 
                                 _("Monitor profile:"),
276
 
                                 label, TRUE);
277
 
  cdisplay_lcms_update_profile_label (lcms, "display-profile");
278
 
 
279
 
  label = gtk_label_new (NULL);
280
 
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
281
 
  g_object_set_data (G_OBJECT (lcms), "printer-profile", label);
282
 
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
283
 
                                 _("Print simulation profile:"),
284
 
                                 label, TRUE);
285
 
  cdisplay_lcms_update_profile_label (lcms, "printer-profile");
286
 
 
287
 
  g_signal_connect_object (config, "notify",
288
 
                           G_CALLBACK (cdisplay_lcms_notify_profile),
289
 
                           lcms, 0);
290
 
 
291
 
  return vbox;
292
 
}
293
 
 
294
 
static void
295
 
cdisplay_lcms_convert (GimpColorDisplay *display,
296
 
                       guchar           *buf,
297
 
                       gint              width,
298
 
                       gint              height,
299
 
                       gint              bpp,
300
 
                       gint              bpl)
301
 
{
302
 
  CdisplayLcms *lcms = CDISPLAY_LCMS (display);
303
 
  gint          y;
304
 
 
305
 
  if (bpp != 3)
306
 
    return;
307
 
 
308
 
  if (! lcms->transform)
309
 
    return;
310
 
 
311
 
  for (y = 0; y < height; y++, buf += bpl)
312
 
    cmsDoTransform (lcms->transform, buf, buf, width);
313
 
}
314
 
 
315
 
static void
316
 
cdisplay_lcms_changed (GimpColorDisplay *display)
317
 
{
318
 
  CdisplayLcms    *lcms   = CDISPLAY_LCMS (display);
319
 
  GimpColorConfig *config = gimp_color_display_get_config (display);
320
 
 
321
 
  cmsHPROFILE      src_profile   = NULL;
322
 
  cmsHPROFILE      dest_profile  = NULL;
323
 
  cmsHPROFILE      proof_profile = NULL;
324
 
  DWORD            flags         = 0;
325
 
 
326
 
  if (lcms->transform)
327
 
    {
328
 
      cmsDeleteTransform (lcms->transform);
329
 
      lcms->transform = NULL;
330
 
    }
331
 
 
332
 
  if (! config)
333
 
    return;
334
 
 
335
 
  switch (config->mode)
336
 
    {
337
 
    case GIMP_COLOR_MANAGEMENT_OFF:
338
 
      return;
339
 
 
340
 
    case GIMP_COLOR_MANAGEMENT_SOFTPROOF:
341
 
      proof_profile = cdisplay_lcms_get_printer_profile (lcms);
342
 
      /*  fallthru  */
343
 
 
344
 
    case GIMP_COLOR_MANAGEMENT_DISPLAY:
345
 
      src_profile = cdisplay_lcms_get_rgb_profile (lcms);
346
 
      dest_profile = cdisplay_lcms_get_display_profile (lcms);
347
 
      break;
348
 
    }
349
 
 
350
 
  if (config->display_intent ==
351
 
      GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC)
352
 
    {
353
 
      flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
354
 
    }
355
 
 
356
 
  if (proof_profile)
357
 
    {
358
 
      if (! src_profile)
359
 
       src_profile = cmsCreate_sRGBProfile ();
360
 
 
361
 
      if (! dest_profile)
362
 
       dest_profile = cmsCreate_sRGBProfile ();
363
 
 
364
 
      flags |= cmsFLAGS_SOFTPROOFING;
365
 
 
366
 
      if (config->simulation_gamut_check)
367
 
        {
368
 
          guchar r, g, b;
369
 
 
370
 
          flags |= cmsFLAGS_GAMUTCHECK;
371
 
 
372
 
          gimp_rgb_get_uchar (&config->out_of_gamut_color, &r, &g, &b);
373
 
 
374
 
          cmsSetAlarmCodes (r, g, b);
375
 
        }
376
 
 
377
 
      lcms->transform = cmsCreateProofingTransform (src_profile,  TYPE_RGB_8,
378
 
                                                    dest_profile, TYPE_RGB_8,
379
 
                                                    proof_profile,
380
 
                                                    config->simulation_intent,
381
 
                                                    config->display_intent,
382
 
                                                    flags);
383
 
      cmsCloseProfile (proof_profile);
384
 
    }
385
 
  else if (src_profile || dest_profile)
386
 
    {
387
 
      if (! src_profile)
388
 
       src_profile = cmsCreate_sRGBProfile ();
389
 
 
390
 
      if (! dest_profile)
391
 
       dest_profile = cmsCreate_sRGBProfile ();
392
 
 
393
 
      lcms->transform = cmsCreateTransform (src_profile,  TYPE_RGB_8,
394
 
                                            dest_profile, TYPE_RGB_8,
395
 
                                            config->display_intent,
396
 
                                            flags);
397
 
    }
398
 
 
399
 
  if (dest_profile)
400
 
    cmsCloseProfile (dest_profile);
401
 
 
402
 
  if (src_profile)
403
 
    cmsCloseProfile (src_profile);
404
 
}
405
 
 
406
 
static gboolean
407
 
cdisplay_lcms_profile_is_rgb (cmsHPROFILE profile)
408
 
{
409
 
  return (cmsGetColorSpace (profile) == icSigRgbData);
410
 
}
411
 
 
412
 
static cmsHPROFILE
413
 
cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms)
414
 
{
415
 
  GimpColorConfig  *config;
416
 
  GimpColorManaged *managed;
417
 
  cmsHPROFILE       profile = NULL;
418
 
 
419
 
  managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms));
420
 
 
421
 
  if (managed)
422
 
    {
423
 
      gsize         len;
424
 
      const guint8 *data = gimp_color_managed_get_icc_profile (managed, &len);
425
 
 
426
 
      if (data)
427
 
        profile = cmsOpenProfileFromMem ((gpointer) data, len);
428
 
 
429
 
      if (profile &&
430
 
          ! cdisplay_lcms_profile_is_rgb (profile))
431
 
        {
432
 
          cmsCloseProfile (profile);
433
 
          profile = NULL;
434
 
        }
435
 
    }
436
 
 
437
 
  if (! profile)
438
 
    {
439
 
      config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
440
 
 
441
 
      if (config->rgb_profile)
442
 
        profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
443
 
    }
444
 
 
445
 
  return profile;
446
 
}
447
 
 
448
 
static GdkScreen *
449
 
cdisplay_lcms_get_screen (CdisplayLcms *lcms,
450
 
                          gint         *monitor)
451
 
{
452
 
  GimpColorManaged *managed;
453
 
  GdkScreen        *screen;
454
 
 
455
 
  managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms));
456
 
 
457
 
  if (GTK_IS_WIDGET (managed))
458
 
    screen = gtk_widget_get_screen (GTK_WIDGET (managed));
459
 
  else
460
 
    screen = gdk_screen_get_default ();
461
 
 
462
 
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
463
 
 
464
 
  if (GTK_IS_WIDGET (managed) && GTK_WIDGET_DRAWABLE (managed))
465
 
    {
466
 
      GtkWidget *widget = GTK_WIDGET (managed);
467
 
 
468
 
      *monitor = gdk_screen_get_monitor_at_window (screen, widget->window);
469
 
    }
470
 
  else
471
 
    {
472
 
      *monitor = 0;
473
 
    }
474
 
 
475
 
  return screen;
476
 
}
477
 
 
478
 
 
479
 
#ifdef GDK_WINDOWING_QUARTZ
480
 
 
481
 
typedef struct
482
 
{
483
 
  guchar *data;
484
 
  gsize   len;
485
 
} ProfileTransfer;
486
 
 
487
 
enum
488
 
{
489
 
  openReadSpool  = 1,  /* start read data process         */
490
 
  openWriteSpool = 2,  /* start write data process        */
491
 
  readSpool      = 3,  /* read specified number of bytes  */
492
 
  writeSpool     = 4,  /* write specified number of bytes */
493
 
  closeSpool     = 5   /* complete data transfer process  */
494
 
};
495
 
 
496
 
static OSErr
497
 
lcms_cdisplay_lcms_flatten_profile (SInt32  command,
498
 
                                    SInt32 *size,
499
 
                                    void   *data,
500
 
                                    void   *refCon)
501
 
{
502
 
  ProfileTransfer *transfer = refCon;
503
 
 
504
 
  switch (command)
505
 
    {
506
 
    case openWriteSpool:
507
 
      g_return_val_if_fail (transfer->data == NULL && transfer->len == 0, -1);
508
 
      break;
509
 
 
510
 
    case writeSpool:
511
 
      transfer->data = g_realloc (transfer->data, transfer->len + *size);
512
 
      memcpy (transfer->data + transfer->len, data, *size);
513
 
      transfer->len += *size;
514
 
      break;
515
 
 
516
 
    default:
517
 
      break;
518
 
    }
519
 
 
520
 
  return 0;
521
 
}
522
 
 
523
 
#endif /* GDK_WINDOWING_QUARTZ */
524
 
 
525
 
 
526
 
static cmsHPROFILE
527
 
cdisplay_lcms_get_display_profile (CdisplayLcms *lcms)
528
 
{
529
 
  GimpColorConfig *config;
530
 
  cmsHPROFILE      profile = NULL;
531
 
 
532
 
  config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
533
 
 
534
 
#if defined GDK_WINDOWING_X11
535
 
  if (config->display_profile_from_gdk)
536
 
    {
537
 
      GdkScreen *screen;
538
 
      GdkAtom    type    = GDK_NONE;
539
 
      gint       format  = 0;
540
 
      gint       nitems  = 0;
541
 
      gint       monitor = 0;
542
 
      gchar     *atom_name;
543
 
      guchar    *data    = NULL;
544
 
 
545
 
      screen = cdisplay_lcms_get_screen (lcms, &monitor);
546
 
 
547
 
      if (monitor > 0)
548
 
        atom_name = g_strdup_printf ("_ICC_PROFILE_%d", monitor);
549
 
      else
550
 
        atom_name = g_strdup ("_ICC_PROFILE");
551
 
 
552
 
      if (gdk_property_get (gdk_screen_get_root_window (screen),
553
 
                            gdk_atom_intern (atom_name, FALSE),
554
 
                            GDK_NONE,
555
 
                            0, 64 * 1024 * 1024, FALSE,
556
 
                            &type, &format, &nitems, &data) && nitems > 0)
557
 
        {
558
 
          profile = cmsOpenProfileFromMem (data, nitems);
559
 
          g_free (data);
560
 
        }
561
 
 
562
 
      g_free (atom_name);
563
 
    }
564
 
 
565
 
#elif defined GDK_WINDOWING_QUARTZ
566
 
  if (config->display_profile_from_gdk)
567
 
    {
568
 
      CMProfileRef  prof    = NULL;
569
 
      gint          monitor = 0;
570
 
 
571
 
      cdisplay_lcms_get_screen (lcms, &monitor);
572
 
 
573
 
      CMGetProfileByAVID (monitor, &prof);
574
 
 
575
 
      if (prof)
576
 
        {
577
 
          ProfileTransfer transfer = { NULL, 0 };
578
 
          Boolean         foo;
579
 
 
580
 
          CMFlattenProfile (prof, 0,
581
 
                            lcms_cdisplay_lcms_flatten_profile, &transfer,
582
 
                            &foo);
583
 
          CMCloseProfile (prof);
584
 
 
585
 
          if (transfer.data)
586
 
            {
587
 
              profile = cmsOpenProfileFromMem (transfer.data, transfer.len);
588
 
              g_free (transfer.data);
589
 
            }
590
 
        }
591
 
    }
592
 
 
593
 
#elif defined G_OS_WIN32
594
 
  if (config->display_profile_from_gdk)
595
 
    {
596
 
      HDC hdc = GetDC (NULL);
597
 
 
598
 
      if (hdc)
599
 
        {
600
 
          gchar *path;
601
 
          gint32 len = 0;
602
 
 
603
 
          GetICMProfile (hdc, &len, NULL);
604
 
          path = g_new (gchar, len);
605
 
 
606
 
          if (GetICMProfile (hdc, &len, path))
607
 
            profile = cmsOpenProfileFromFile (path, "r");
608
 
 
609
 
          g_free (path);
610
 
          ReleaseDC (NULL, hdc);
611
 
        }
612
 
    }
613
 
#endif
614
 
 
615
 
  if (! profile && config->display_profile)
616
 
    profile = cmsOpenProfileFromFile (config->display_profile, "r");
617
 
 
618
 
  return profile;
619
 
}
620
 
 
621
 
static cmsHPROFILE
622
 
cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms)
623
 
{
624
 
  GimpColorConfig *config;
625
 
 
626
 
  config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
627
 
 
628
 
  if (config->printer_profile)
629
 
    return cmsOpenProfileFromFile (config->printer_profile, "r");
630
 
 
631
 
  return NULL;
632
 
}
633
 
 
634
 
static void
635
 
cdisplay_lcms_attach_labelled (GtkTable    *table,
636
 
                               gint         row,
637
 
                               const gchar *text,
638
 
                               GtkWidget   *widget,
639
 
                               gboolean     tooltip)
640
 
{
641
 
  GtkWidget *label;
642
 
  GtkWidget *ebox = NULL;
643
 
 
644
 
  label = g_object_new (GTK_TYPE_LABEL,
645
 
                        "label",  text,
646
 
                        "xalign", 1.0,
647
 
                        "yalign", 0.5,
648
 
                        NULL);
649
 
 
650
 
  gimp_label_set_attributes (GTK_LABEL (label),
651
 
                             PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
652
 
                             -1);
653
 
  gtk_table_attach (table, label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
654
 
  gtk_widget_show (label);
655
 
 
656
 
  if (tooltip)
657
 
    {
658
 
      ebox = gtk_event_box_new ();
659
 
      gtk_table_attach (table, ebox, 1, 2, row, row + 1,
660
 
                        GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
661
 
      gtk_widget_show (ebox);
662
 
 
663
 
      g_object_set_data (G_OBJECT (label), "tooltip-widget", ebox);
664
 
    }
665
 
 
666
 
  if (GTK_IS_LABEL (widget))
667
 
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
668
 
 
669
 
  if (ebox)
670
 
    gtk_container_add (GTK_CONTAINER (ebox), widget);
671
 
  else
672
 
    gtk_table_attach (table, widget, 1, 2, row, row + 1,
673
 
                      GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
674
 
 
675
 
  gtk_widget_show (widget);
676
 
}
677
 
 
678
 
static void
679
 
cdisplay_lcms_label_set_text (GtkLabel    *label,
680
 
                              const gchar *text,
681
 
                              const gchar *tooltip)
682
 
{
683
 
  GtkWidget *tooltip_widget;
684
 
 
685
 
  gtk_label_set_text (label, text);
686
 
 
687
 
  tooltip_widget = g_object_get_data (G_OBJECT (label), "tooltip-widget");
688
 
 
689
 
  if (tooltip_widget)
690
 
    gimp_help_set_help_data (tooltip_widget, tooltip, NULL);
691
 
}
692
 
 
693
 
static void
694
 
cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
695
 
                                    const gchar  *name)
696
 
{
697
 
  GtkWidget   *label;
698
 
  cmsHPROFILE  profile = NULL;
699
 
  const gchar *text;
700
 
  const gchar *tooltip;
701
 
 
702
 
  label = g_object_get_data (G_OBJECT (lcms), name);
703
 
 
704
 
  if (! label)
705
 
    return;
706
 
 
707
 
  if (strcmp (name, "rgb-profile") == 0)
708
 
    {
709
 
      profile = cdisplay_lcms_get_rgb_profile (lcms);
710
 
    }
711
 
  else if (g_str_has_prefix (name, "display-profile"))
712
 
    {
713
 
      profile = cdisplay_lcms_get_display_profile (lcms);
714
 
    }
715
 
  else if (strcmp (name, "printer-profile") == 0)
716
 
    {
717
 
      profile = cdisplay_lcms_get_printer_profile (lcms);
718
 
    }
719
 
  else
720
 
    {
721
 
      g_return_if_reached ();
722
 
    }
723
 
 
724
 
  cdisplay_lcms_profile_get_info (profile, &text, &tooltip);
725
 
  cdisplay_lcms_label_set_text (GTK_LABEL (label), text, tooltip);
726
 
 
727
 
  if (profile)
728
 
    cmsCloseProfile (profile);
729
 
}
730
 
 
731
 
static void
732
 
cdisplay_lcms_notify_profile (GObject      *config,
733
 
                              GParamSpec   *pspec,
734
 
                              CdisplayLcms *lcms)
735
 
{
736
 
  cdisplay_lcms_update_profile_label (lcms, pspec->name);
737
 
}