~ubuntu-branches/ubuntu/intrepid/gimp/intrepid-updates

« back to all changes in this revision

Viewing changes to modules/cdisplay_lcms.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-11-21 17:39:07 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20071121173907-od54p9hdtvn5frl0
Tags: 2.4.1-1ubuntu1
* Merge from Debian unstable.
* Remaining Ubuntu changes:
  - 02_help-message.patch, 03_gimp.desktop.in.in.patch: Distro changes.
  - Weave i18n magic in the rules file.
  - Munge Maintainer field as per spec.
* Ubuntu changes dropped:
  - Apply patch from upstream (SVN r23659) that corrects the image
    disappearing for large images at 150% zoom.
  - Symlink doc directories to avoid duplicate files, CDBS does this for
    us.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include <gtk/gtk.h>
36
36
 
 
37
#ifdef GDK_WINDOWING_QUARTZ
 
38
#include <Carbon/Carbon.h>
 
39
#include <ApplicationServices/ApplicationServices.h>
 
40
#include <CoreServices/CoreServices.h>
 
41
#endif
 
42
 
37
43
#include "libgimpcolor/gimpcolor.h"
38
44
#include "libgimpconfig/gimpconfig.h"
39
45
#include "libgimpmath/gimpmath.h"
104
110
  GIMP_MODULE_ABI_VERSION,
105
111
  N_("Color management display filter using ICC color profiles"),
106
112
  "Sven Neumann",
107
 
  "v0.2",
 
113
  "v0.3",
108
114
  "(c) 2005 - 2007, released under the GPL",
109
115
  "2005 - 2007"
110
116
};
201
207
{
202
208
  if (profile)
203
209
    {
204
 
      *name = cmsTakeProductName (profile);
205
 
      if (! g_utf8_validate (*name, -1, NULL))
 
210
      *name = cmsTakeProductDesc (profile);
 
211
 
 
212
      if (! *name)
 
213
        *name = cmsTakeProductName (profile);
 
214
 
 
215
      if (*name && ! g_utf8_validate (*name, -1, NULL))
206
216
        *name = _("(invalid UTF-8 string)");
207
217
 
208
218
      *info = cmsTakeProductInfo (profile);
209
 
      if (! g_utf8_validate (*info, -1, NULL))
 
219
      if (*name && ! g_utf8_validate (*info, -1, NULL))
210
220
        *info = NULL;
211
221
    }
212
222
  else
251
261
                                 FALSE);
252
262
 
253
263
  label = gtk_label_new (NULL);
 
264
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
254
265
  g_object_set_data (G_OBJECT (lcms), "rgb-profile", label);
255
266
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
256
267
                                 _("Image profile:"),
258
269
  cdisplay_lcms_update_profile_label (lcms, "rgb-profile");
259
270
 
260
271
  label = gtk_label_new (NULL);
 
272
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
261
273
  g_object_set_data (G_OBJECT (lcms), "display-profile", label);
262
274
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
263
275
                                 _("Monitor profile:"),
265
277
  cdisplay_lcms_update_profile_label (lcms, "display-profile");
266
278
 
267
279
  label = gtk_label_new (NULL);
 
280
  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
268
281
  g_object_set_data (G_OBJECT (lcms), "printer-profile", label);
269
282
  cdisplay_lcms_attach_labelled (GTK_TABLE (table), row++,
270
283
                                 _("Print simulation profile:"),
308
321
  cmsHPROFILE      src_profile   = NULL;
309
322
  cmsHPROFILE      dest_profile  = NULL;
310
323
  cmsHPROFILE      proof_profile = NULL;
 
324
  DWORD            flags         = 0;
311
325
 
312
326
  if (lcms->transform)
313
327
    {
333
347
      break;
334
348
    }
335
349
 
 
350
  if (config->display_intent ==
 
351
      GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC)
 
352
    {
 
353
      flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
 
354
    }
 
355
 
336
356
  if (proof_profile)
337
357
    {
338
358
      if (! src_profile)
341
361
      if (! dest_profile)
342
362
       dest_profile = cmsCreate_sRGBProfile ();
343
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
 
344
377
      lcms->transform = cmsCreateProofingTransform (src_profile,  TYPE_RGB_8,
345
378
                                                    dest_profile, TYPE_RGB_8,
346
379
                                                    proof_profile,
347
380
                                                    config->simulation_intent,
348
381
                                                    config->display_intent,
349
 
                                                    cmsFLAGS_SOFTPROOFING);
 
382
                                                    flags);
350
383
      cmsCloseProfile (proof_profile);
351
384
    }
352
385
  else if (src_profile || dest_profile)
360
393
      lcms->transform = cmsCreateTransform (src_profile,  TYPE_RGB_8,
361
394
                                            dest_profile, TYPE_RGB_8,
362
395
                                            config->display_intent,
363
 
                                            0);
 
396
                                            flags);
364
397
    }
365
398
 
366
399
  if (dest_profile)
412
445
  return profile;
413
446
}
414
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
 
415
526
static cmsHPROFILE
416
527
cdisplay_lcms_get_display_profile (CdisplayLcms *lcms)
417
528
{
420
531
 
421
532
  config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
422
533
 
423
 
#if defined (GDK_WINDOWING_X11)
 
534
#if defined GDK_WINDOWING_X11
424
535
  if (config->display_profile_from_gdk)
425
536
    {
426
 
      GimpColorManaged *managed;
427
 
      GdkScreen        *screen;
428
 
      GdkAtom           type   = GDK_NONE;
429
 
      gint              format = 0;
430
 
      gint              nitems = 0;
431
 
      guchar           *data   = NULL;
432
 
 
433
 
      managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms));
434
 
 
435
 
      if (GTK_IS_WIDGET (managed))
436
 
        screen = gtk_widget_get_screen (GTK_WIDGET (managed));
 
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);
437
549
      else
438
 
        screen = gdk_screen_get_default ();
439
 
 
440
 
      g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
 
550
        atom_name = g_strdup ("_ICC_PROFILE");
441
551
 
442
552
      if (gdk_property_get (gdk_screen_get_root_window (screen),
443
 
                            gdk_atom_intern ("_ICC_PROFILE", FALSE),
 
553
                            gdk_atom_intern (atom_name, FALSE),
444
554
                            GDK_NONE,
445
555
                            0, 64 * 1024 * 1024, FALSE,
446
556
                            &type, &format, &nitems, &data) && nitems > 0)
448
558
          profile = cmsOpenProfileFromMem (data, nitems);
449
559
          g_free (data);
450
560
        }
451
 
    }
 
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
 
452
593
#elif defined G_OS_WIN32
453
594
  if (config->display_profile_from_gdk)
454
595
    {
499
640
{
500
641
  GtkWidget *label;
501
642
  GtkWidget *ebox = NULL;
502
 
  GtkWidget *hbox;
503
643
 
504
644
  label = g_object_new (GTK_TYPE_LABEL,
505
645
                        "label",  text,
510
650
  gimp_label_set_attributes (GTK_LABEL (label),
511
651
                             PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
512
652
                             -1);
513
 
  gtk_table_attach (table, label, 0, 1, row, row + 1,
514
 
                    GTK_FILL, GTK_FILL, 0, 0);
 
653
  gtk_table_attach (table, label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
515
654
  gtk_widget_show (label);
516
655
 
517
656
  if (tooltip)
524
663
      g_object_set_data (G_OBJECT (label), "tooltip-widget", ebox);
525
664
    }
526
665
 
527
 
  hbox = gtk_hbox_new (FALSE, 0);
 
666
  if (GTK_IS_LABEL (widget))
 
667
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
528
668
 
529
669
  if (ebox)
530
 
    gtk_container_add (GTK_CONTAINER (ebox), hbox);
 
670
    gtk_container_add (GTK_CONTAINER (ebox), widget);
531
671
  else
532
 
    gtk_table_attach (table, hbox, 1, 2, row, row + 1,
 
672
    gtk_table_attach (table, widget, 1, 2, row, row + 1,
533
673
                      GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
534
674
 
535
 
  gtk_widget_show (hbox);
536
 
 
537
 
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
538
675
  gtk_widget_show (widget);
539
676
}
540
677