Code

Use neutral out of gamut warning color
[inkscape.git] / src / color-profile.cpp
3 #include "xml/repr.h"
4 #include "color-profile.h"
5 #include "color-profile-fns.h"
6 #include "attributes.h"
7 #include "inkscape.h"
8 #include "document.h"
9 #include "prefs-utils.h"
11 #include "dom/uri.h"
13 //#define DEBUG_LCMS
15 #include <glib/gstdio.h>
16 #include <sys/fcntl.h>
17 #include <gdkmm/color.h>
19 #ifdef DEBUG_LCMS
20 #include <gtk/gtkmessagedialog.h>
21 #endif // DEBUG_LCMS
23 using Inkscape::ColorProfile;
24 using Inkscape::ColorProfileClass;
26 namespace Inkscape
27 {
28 static void colorprofile_class_init( ColorProfileClass *klass );
29 static void colorprofile_init( ColorProfile *cprof );
31 static void colorprofile_release( SPObject *object );
32 static void colorprofile_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr );
33 static void colorprofile_set( SPObject *object, unsigned key, gchar const *value );
34 static Inkscape::XML::Node *colorprofile_write( SPObject *object, Inkscape::XML::Node *repr, guint flags );
36 #if ENABLE_LCMS
37 static cmsHPROFILE colorprofile_get_system_profile_handle();
38 static cmsHPROFILE colorprofile_get_proof_profile_handle();
39 #endif // ENABLE_LCMS
40 }
42 #ifdef DEBUG_LCMS
43 extern guint update_in_progress;
44 #define DEBUG_MESSAGE(key, ...) \
45 {\
46     gint dump = prefs_get_int_attribute_limited("options.scislac", #key, 0, 0, 1);\
47     gint dumpD = prefs_get_int_attribute_limited("options.scislac", #key"D", 0, 0, 1);\
48     gint dumpD2 = prefs_get_int_attribute_limited("options.scislac", #key"D2", 0, 0, 1);\
49     dumpD &= ( (update_in_progress == 0) || dumpD2 );\
50     if ( dump )\
51     {\
52         g_message( __VA_ARGS__ );\
53 \
54     }\
55     if ( dumpD )\
56     {\
57         GtkWidget *dialog = gtk_message_dialog_new(NULL,\
58                                                    GTK_DIALOG_DESTROY_WITH_PARENT, \
59                                                    GTK_MESSAGE_INFO,    \
60                                                    GTK_BUTTONS_OK,      \
61                                                    __VA_ARGS__          \
62                                                    );\
63         g_signal_connect_swapped(dialog, "response",\
64                                  G_CALLBACK(gtk_widget_destroy),        \
65                                  dialog);                               \
66         gtk_widget_show_all( dialog );\
67     }\
68 }
69 #endif // DEBUG_LCMS
71 static SPObject *cprof_parent_class;
73 /**
74  * Register ColorProfile class and return its type.
75  */
76 GType Inkscape::colorprofile_get_type()
77 {
78     static GType type = 0;
79     if (!type) {
80         GTypeInfo info = {
81             sizeof(ColorProfileClass),
82             NULL, NULL,
83             (GClassInitFunc) colorprofile_class_init,
84             NULL, NULL,
85             sizeof(ColorProfile),
86             16,
87             (GInstanceInitFunc) colorprofile_init,
88             NULL,   /* value_table */
89         };
90         type = g_type_register_static( SP_TYPE_OBJECT, "ColorProfile", &info, static_cast<GTypeFlags>(0) );
91     }
92     return type;
93 }
95 /**
96  * ColorProfile vtable initialization.
97  */
98 static void Inkscape::colorprofile_class_init( ColorProfileClass *klass )
99 {
100     SPObjectClass *sp_object_class = reinterpret_cast<SPObjectClass *>(klass);
102     cprof_parent_class = static_cast<SPObject*>(g_type_class_ref(SP_TYPE_OBJECT));
104     sp_object_class->release = colorprofile_release;
105     sp_object_class->build = colorprofile_build;
106     sp_object_class->set = colorprofile_set;
107     sp_object_class->write = colorprofile_write;
110 /**
111  * Callback for ColorProfile object initialization.
112  */
113 static void Inkscape::colorprofile_init( ColorProfile *cprof )
115     cprof->href = 0;
116     cprof->local = 0;
117     cprof->name = 0;
118     cprof->intentStr = 0;
119     cprof->rendering_intent = Inkscape::RENDERING_INTENT_UNKNOWN;
120 #if ENABLE_LCMS
121     cprof->profHandle = 0;
122 #endif // ENABLE_LCMS
125 /**
126  * Callback: free object
127  */
128 static void Inkscape::colorprofile_release( SPObject *object )
130     ColorProfile *cprof = COLORPROFILE(object);
131     if ( cprof->href ) {
132         g_free( cprof->href );
133         cprof->href = 0;
134     }
136     if ( cprof->local ) {
137         g_free( cprof->local );
138         cprof->local = 0;
139     }
141     if ( cprof->name ) {
142         g_free( cprof->name );
143         cprof->name = 0;
144     }
146     if ( cprof->intentStr ) {
147         g_free( cprof->intentStr );
148         cprof->intentStr = 0;
149     }
151 #if ENABLE_LCMS
152     if ( cprof->profHandle ) {
153         cmsCloseProfile( cprof->profHandle );
154         cprof->profHandle = 0;
155     }
156 #endif // ENABLE_LCMS
159 /**
160  * Callback: set attributes from associated repr.
161  */
162 static void Inkscape::colorprofile_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr )
164     ColorProfile *cprof = COLORPROFILE(object);
165     g_assert(cprof->href == 0);
166     g_assert(cprof->local == 0);
167     g_assert(cprof->name == 0);
168     g_assert(cprof->intentStr == 0);
170     if (((SPObjectClass *) cprof_parent_class)->build) {
171         (* ((SPObjectClass *) cprof_parent_class)->build)(object, document, repr);
172     }
173     sp_object_read_attr( object, "xlink:href" );
174     sp_object_read_attr( object, "local" );
175     sp_object_read_attr( object, "name" );
176     sp_object_read_attr( object, "rendering-intent" );
179 /**
180  * Callback: set attribute.
181  */
182 static void Inkscape::colorprofile_set( SPObject *object, unsigned key, gchar const *value )
184     ColorProfile *cprof = COLORPROFILE(object);
186     switch (key) {
187         case SP_ATTR_XLINK_HREF:
188             if ( cprof->href ) {
189                 g_free( cprof->href );
190                 cprof->href = 0;
191             }
192             if ( value ) {
193                 cprof->href = g_strdup( value );
194                 if ( *cprof->href ) {
195 #if ENABLE_LCMS
196                     cmsErrorAction( LCMS_ERROR_SHOW );
198                     // TODO open filename and URIs properly
199                     //FILE* fp = fopen_utf8name( filename, "r" );
200                     //LCMSAPI cmsHPROFILE   LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, DWORD dwSize);
202                     // Try to open relative
203                     SPDocument *doc = SP_OBJECT_DOCUMENT(object);
204                     if (!doc) {
205                         doc = SP_ACTIVE_DOCUMENT;
206                         g_warning("object has no document.  using active");
207                     }
208                     //# 1.  Get complete URI of document
209                     gchar const *docbase = SP_DOCUMENT_URI( doc );
210                     if (!docbase)
211                         {
212                         g_warning("null docbase");
213                         docbase = "";
214                         }
215                     //g_message("docbase:%s\n", docbase);
216                     org::w3c::dom::URI docUri(docbase);
217                     //# 2. Get href of icc file.  we don't care if it's rel or abs
218                     org::w3c::dom::URI hrefUri(cprof->href);
219                     //# 3.  Resolve the href according the docBase.  This follows
220                     //      the w3c specs.  All absolute and relative issues are considered
221                     org::w3c::dom::URI cprofUri = docUri.resolve(hrefUri);
222                     gchar* fullname = (gchar *)cprofUri.getNativePath().c_str();
223                     cprof->profHandle = cmsOpenProfileFromFile( fullname, "r" );
224 #ifdef DEBUG_LCMS
225                     DEBUG_MESSAGE( lcmsOne, "cmsOpenProfileFromFile( '%s'...) = %p", fullname, (void*)cprof->profHandle );
226 #endif // DEBUG_LCMS
228 #endif // ENABLE_LCMS
229                 }
230             }
231             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
232             break;
234         case SP_ATTR_LOCAL:
235             if ( cprof->local ) {
236                 g_free( cprof->local );
237                 cprof->local = 0;
238             }
239             cprof->local = g_strdup( value );
240             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
241             break;
243         case SP_ATTR_NAME:
244             if ( cprof->name ) {
245                 g_free( cprof->name );
246                 cprof->name = 0;
247             }
248             cprof->name = g_strdup( value );
249 #ifdef DEBUG_LCMS
250             DEBUG_MESSAGE( lcmsTwo, "<color-profile> name set to '%s'", cprof->name );
251 #endif // DEBUG_LCMS
252             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
253             break;
255         case SP_ATTR_RENDERING_INTENT:
256             if ( cprof->intentStr ) {
257                 g_free( cprof->intentStr );
258                 cprof->intentStr = 0;
259             }
260             cprof->intentStr = g_strdup( value );
262             if ( value ) {
263                 if ( strcmp( value, "auto" ) == 0 ) {
264                     cprof->rendering_intent = RENDERING_INTENT_AUTO;
265                 } else if ( strcmp( value, "perceptual" ) == 0 ) {
266                     cprof->rendering_intent = RENDERING_INTENT_PERCEPTUAL;
267                 } else if ( strcmp( value, "relative-colorimetric" ) == 0 ) {
268                     cprof->rendering_intent = RENDERING_INTENT_RELATIVE_COLORIMETRIC;
269                 } else if ( strcmp( value, "saturation" ) == 0 ) {
270                     cprof->rendering_intent = RENDERING_INTENT_SATURATION;
271                 } else if ( strcmp( value, "absolute-colorimetric" ) == 0 ) {
272                     cprof->rendering_intent = RENDERING_INTENT_ABSOLUTE_COLORIMETRIC;
273                 } else {
274                     cprof->rendering_intent = RENDERING_INTENT_UNKNOWN;
275                 }
276             } else {
277                 cprof->rendering_intent = RENDERING_INTENT_UNKNOWN;
278             }
280             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
281             break;
283         default:
284             if (((SPObjectClass *) cprof_parent_class)->set) {
285                 (* ((SPObjectClass *) cprof_parent_class)->set)(object, key, value);
286             }
287             break;
288     }
292 /**
293  * Callback: write attributes to associated repr.
294  */
295 static Inkscape::XML::Node* Inkscape::colorprofile_write( SPObject *object, Inkscape::XML::Node *repr, guint flags )
297     ColorProfile *cprof = COLORPROFILE(object);
299     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
300         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
301         repr = xml_doc->createElement("svg:color-profile");
302     }
304     if ( (flags & SP_OBJECT_WRITE_ALL) || cprof->href ) {
305         repr->setAttribute( "xlink:href", cprof->href );
306     }
308     if ( (flags & SP_OBJECT_WRITE_ALL) || cprof->local ) {
309         repr->setAttribute( "local", cprof->local );
310     }
312     if ( (flags & SP_OBJECT_WRITE_ALL) || cprof->name ) {
313         repr->setAttribute( "name", cprof->name );
314     }
316     if ( (flags & SP_OBJECT_WRITE_ALL) || cprof->intentStr ) {
317         repr->setAttribute( "rendering-intent", cprof->intentStr );
318     }
320     if (((SPObjectClass *) cprof_parent_class)->write) {
321         (* ((SPObjectClass *) cprof_parent_class)->write)(object, repr, flags);
322     }
324     return repr;
328 #if ENABLE_LCMS
331 static SPObject* bruteFind( SPObject* curr, gchar const* name )
333     SPObject* result = 0;
335     if ( curr ) {
336         if ( IS_COLORPROFILE(curr) ) {
337             ColorProfile* prof = COLORPROFILE(curr);
338             if ( prof ) {
339                 if ( prof->name && (strcmp(prof->name, name) == 0) ) {
340                     result = curr;
341                 }
342             }
343         } else {
344             if ( curr->hasChildren() ) {
345                 SPObject* child = curr->firstChild();
346                 while ( child && !result ) {
347                     result = bruteFind( child, name );
348                     if ( !result ) {
349                         child = child->next;
350                     }
351                 };
352             }
353         }
354     }
356     return result;
359 cmsHPROFILE Inkscape::colorprofile_get_handle( SPDocument* document, guint* intent, gchar const* name )
361     cmsHPROFILE prof = 0;
363     SPObject* root = SP_DOCUMENT_ROOT(document);
364     SPObject* thing = bruteFind( root, name );
365     if ( thing ) {
366         prof = COLORPROFILE(thing)->profHandle;
367     }
369     if ( intent ) {
370         *intent = thing ? COLORPROFILE(thing)->rendering_intent : (guint)RENDERING_INTENT_UNKNOWN;
371     }
373 #ifdef DEBUG_LCMS
374     DEBUG_MESSAGE( lcmsThree, "<color-profile> queried for profile of '%s'. Returning %p with intent of %d", name, prof, (intent? *intent:0) );
375 #endif // DEBUG_LCMS
377     return prof;
381 #include <io/sys.h>
383 class ProfileInfo
385 public:
386     ProfileInfo( cmsHPROFILE, Glib::ustring const & path );
388     Glib::ustring const& getName() {return _name;}
389     Glib::ustring const& getPath() {return _path;}
390     icColorSpaceSignature getSpace() {return _profileSpace;}
391     icProfileClassSignature getClass() {return _profileClass;}
393 private:
394     Glib::ustring _path;
395     Glib::ustring _name;
396     icColorSpaceSignature _profileSpace;
397     icProfileClassSignature _profileClass;
398 };
401 ProfileInfo::ProfileInfo( cmsHPROFILE prof, Glib::ustring const & path )
403     _path = path;
404     _name = cmsTakeProductName(prof);
405     _profileSpace = cmsGetColorSpace( prof );
406     _profileClass = cmsGetDeviceClass( prof );
411 static std::vector<ProfileInfo> knownProfiles;
413 std::vector<Glib::ustring> Inkscape::colorprofile_get_display_names()
415     std::vector<Glib::ustring> result;
417     for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
418         if ( it->getClass() == icSigDisplayClass && it->getSpace() == icSigRgbData ) {
419             result.push_back( it->getName() );
420         }
421     }
423     return result;
426 std::vector<Glib::ustring> Inkscape::colorprofile_get_softproof_names()
428     std::vector<Glib::ustring> result;
430     for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
431         if ( it->getClass() == icSigOutputClass ) {
432             result.push_back( it->getName() );
433         }
434     }
436     return result;
439 Glib::ustring Inkscape::get_path_for_profile(Glib::ustring const& name)
441     Glib::ustring result;
443     for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
444         if ( name == it->getName() ) {
445             result = it->getPath();
446             break;
447         }
448     }
450     return result;
453 static void findThings() {
454     std::list<gchar *> sources;
456     gchar* base = profile_path("XXX");
457     {
458         gchar* base2 = g_path_get_dirname(base);
459         g_free(base);
460         base = base2;
461         base2 = g_path_get_dirname(base);
462         g_free(base);
463         base = base2;
464     }
466     // first try user's local dir
467     sources.push_back( g_build_filename(g_get_user_data_dir(), "color", "icc", NULL) );
468     sources.push_back( g_build_filename(base, ".color", "icc", NULL) ); // OpenICC recommends to deprecate this
470     const gchar* const * dataDirs = g_get_system_data_dirs();
471     for ( int i = 0; dataDirs[i]; i++ ) {
472         sources.push_back(g_build_filename(dataDirs[i], "color", "icc", NULL));
473     }
475     while (!sources.empty()) {
476         gchar *dirname = sources.front();
477         if ( g_file_test( dirname, G_FILE_TEST_EXISTS ) && g_file_test( dirname, G_FILE_TEST_IS_DIR ) ) {
478             GError *err = 0;
479             GDir *dir = g_dir_open(dirname, 0, &err);
481             if (dir) {
482                 for (gchar const *file = g_dir_read_name(dir); file != NULL; file = g_dir_read_name(dir)) {
483                     gchar *filepath = g_build_filename(dirname, file, NULL);
486                     if ( g_file_test( filepath, G_FILE_TEST_IS_DIR ) ) {
487                         sources.push_back(g_strdup(filepath));
488                     } else {
489                         bool isIccFile = false;
490                         struct stat st;
491                         if ( g_stat(filepath, &st) == 0 && (st.st_size > 128) ) {
492                             //0-3 == size
493                             //36-39 == 'acsp' 0x61637370
494                             int fd = g_open( filepath, O_RDONLY, S_IRWXU);
495                             if ( fd != -1 ) {
496                                 guchar scratch[40] = {0};
497                                 size_t len = sizeof(scratch);
499                                 //size_t left = 40;
500                                 ssize_t got = read(fd, scratch, len);
501                                 if ( got != -1 ) {
502                                     size_t calcSize = (scratch[0] << 24) | (scratch[1] << 16) | (scratch[2] << 8) | scratch[3];
503                                     if ( calcSize > 128 && calcSize <= st.st_size ) {
504                                         isIccFile = (scratch[36] == 'a') && (scratch[37] == 'c') && (scratch[38] == 's') && (scratch[39] == 'p');
505                                     }
506                                 }
508                                 close(fd);
509                             }
510                         }
512                         if ( isIccFile ) {
513                             cmsHPROFILE prof = cmsOpenProfileFromFile( filepath, "r" );
514                             if ( prof ) {
515                                 ProfileInfo info( prof, Glib::filename_to_utf8( filepath ) );
516                                 cmsCloseProfile( prof );
518                                 bool sameName = false;
519                                 for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
520                                     if ( it->getName() == info.getName() ) {
521                                         sameName = true;
522                                         break;
523                                     }
524                                 }
526                                 if ( !sameName ) {
527                                     knownProfiles.push_back(info);
528                                 }
529                             }
530                         }
531                     }
533                     g_free(filepath);
534                 }
535             }
536         }
538         // toss the dirname
539         g_free(dirname);
540         sources.pop_front();
541     }
544 int errorHandlerCB(int ErrorCode, const char *ErrorText)
546     g_message("lcms: Error %d; %s", ErrorCode, ErrorText);
548     return 1;
551 static bool gamutWarn = false;
552 static Gdk::Color lastGamutColor("#808080");
553 static bool lastBPC = false;
554 #if defined(cmsFLAGS_PRESERVEBLACK)
555 static bool lastPreserveBlack = false;
556 #endif // defined(cmsFLAGS_PRESERVEBLACK)
557 static int lastIntent = INTENT_PERCEPTUAL;
558 static int lastProofIntent = INTENT_PERCEPTUAL;
559 static cmsHTRANSFORM transf = 0;
560 static cmsHPROFILE srcprof = 0;
562 cmsHPROFILE Inkscape::colorprofile_get_system_profile_handle()
564     static cmsHPROFILE theOne = 0;
565     static std::string lastURI;
567     static bool init = false;
568     if ( !init ) {
569         cmsSetErrorHandler(errorHandlerCB);
571         findThings();
572         init = true;
573     }
575     long long int which = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 );
576     gchar const * uri = prefs_get_string_attribute("options.displayprofile", "uri");
578     if ( which && uri && *uri ) {
579         if ( lastURI != std::string(uri) ) {
580             lastURI.clear();
581             if ( theOne ) {
582                 cmsCloseProfile( theOne );
583             }
584             if ( transf ) {
585                 cmsDeleteTransform( transf );
586                 transf = 0;
587             }
588             theOne = cmsOpenProfileFromFile( uri, "r" );
589             if ( theOne ) {
590                 // a display profile must have the proper stuff
591                 icColorSpaceSignature space = cmsGetColorSpace(theOne);
592                 icProfileClassSignature profClass = cmsGetDeviceClass(theOne);
594                 if ( profClass != icSigDisplayClass ) {
595                     g_warning("Not a display profile");
596                     cmsCloseProfile( theOne );
597                     theOne = 0;
598                 } else if ( space != icSigRgbData ) {
599                     g_warning("Not an RGB profile");
600                     cmsCloseProfile( theOne );
601                     theOne = 0;
602                 } else {
603                     lastURI = uri;
604                 }
605             }
606         }
607     } else if ( theOne ) {
608         cmsCloseProfile( theOne );
609         theOne = 0;
610         lastURI.clear();
611         if ( transf ) {
612             cmsDeleteTransform( transf );
613             transf = 0;
614         }
615     }
617     return theOne;
621 cmsHPROFILE Inkscape::colorprofile_get_proof_profile_handle()
623     static cmsHPROFILE theOne = 0;
624     static std::string lastURI;
626     static bool init = false;
627     if ( !init ) {
628         cmsSetErrorHandler(errorHandlerCB);
630         findThings();
631         init = true;
632     }
634     long long int which = prefs_get_int_attribute_limited( "options.softproof", "enable", 0, 0, 1 );
635     gchar const * uri = prefs_get_string_attribute("options.softproof", "uri");
637     if ( which && uri && *uri ) {
638         if ( lastURI != std::string(uri) ) {
639             lastURI.clear();
640             if ( theOne ) {
641                 cmsCloseProfile( theOne );
642             }
643             if ( transf ) {
644                 cmsDeleteTransform( transf );
645                 transf = 0;
646             }
647             theOne = cmsOpenProfileFromFile( uri, "r" );
648             if ( theOne ) {
649                 // a display profile must have the proper stuff
650                 icColorSpaceSignature space = cmsGetColorSpace(theOne);
651                 icProfileClassSignature profClass = cmsGetDeviceClass(theOne);
653                 (void)space;
654                 (void)profClass;
655 /*
656                 if ( profClass != icSigDisplayClass ) {
657                     g_warning("Not a display profile");
658                     cmsCloseProfile( theOne );
659                     theOne = 0;
660                 } else if ( space != icSigRgbData ) {
661                     g_warning("Not an RGB profile");
662                     cmsCloseProfile( theOne );
663                     theOne = 0;
664                 } else {
665 */
666                     lastURI = uri;
667 /*
668                 }
669 */
670             }
671         }
672     } else if ( theOne ) {
673         cmsCloseProfile( theOne );
674         theOne = 0;
675         lastURI.clear();
676         if ( transf ) {
677             cmsDeleteTransform( transf );
678             transf = 0;
679         }
680     }
682     return theOne;
685 cmsHTRANSFORM Inkscape::colorprofile_get_display_transform()
687     bool warn = prefs_get_int_attribute_limited( "options.softproof", "gamutwarn", 0, 0, 1 );
688     int intent = prefs_get_int_attribute_limited( "options.displayprofile", "intent", 0, 0, 3 );
689     int proofIntent = prefs_get_int_attribute_limited( "options.softproof", "intent", 0, 0, 3 );
690     bool bpc = prefs_get_int_attribute_limited( "options.softproof", "bpc", 0, 0, 1 );
691 #if defined(cmsFLAGS_PRESERVEBLACK)
692     bool preserveBlack = prefs_get_int_attribute_limited( "options.softproof", "preserveblack", 0, 0, 1 );
693 #endif //defined(cmsFLAGS_PRESERVEBLACK)
694     gchar const* colorStr = prefs_get_string_attribute("options.softproof", "gamutcolor");
695     Gdk::Color gamutColor( (colorStr && colorStr[0]) ? colorStr : "#808080");
697     if ( (warn != gamutWarn)
698          || (lastIntent != intent)
699          || (lastProofIntent != proofIntent)
700          || (bpc != lastBPC)
701 #if defined(cmsFLAGS_PRESERVEBLACK)
702          || (preserveBlack != lastPreserveBlack)
703 #endif // defined(cmsFLAGS_PRESERVEBLACK)
704          || (gamutColor != lastGamutColor)
705         ) {
706         gamutWarn = warn;
707         if ( transf ) {
708             cmsDeleteTransform(transf);
709             transf = 0;
710         }
711         lastIntent = intent;
712         lastProofIntent = proofIntent;
713         lastBPC = bpc;
714 #if defined(cmsFLAGS_PRESERVEBLACK)
715         lastPreserveBlack = preserveBlack;
716 #endif // defined(cmsFLAGS_PRESERVEBLACK)
717         lastGamutColor = gamutColor;
718     }
720     // Fecth these now, as they might clear the transform as a side effect.
721     cmsHPROFILE hprof = Inkscape::colorprofile_get_system_profile_handle();
722     cmsHPROFILE proofProf = hprof ? Inkscape::colorprofile_get_proof_profile_handle() : 0;
724     if ( !transf ) {
725         if ( !srcprof ) {
726             srcprof = cmsCreate_sRGBProfile();
727         }
728         if ( hprof && proofProf ) {
729             DWORD dwFlags = cmsFLAGS_SOFTPROOFING;
730             if ( gamutWarn ) {
731                 dwFlags |= cmsFLAGS_GAMUTCHECK;
732                 cmsSetAlarmCodes(gamutColor.get_red() >> 8, gamutColor.get_green() >> 8, gamutColor.get_blue() >> 8);
733             }
734             if ( bpc ) {
735                 dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
736             }
737 #if defined(cmsFLAGS_PRESERVEBLACK)
738             if ( preserveBlack ) {
739                 dwFlags |= cmsFLAGS_PRESERVEBLACK;
740             }
741 #endif // defined(cmsFLAGS_PRESERVEBLACK)
742             transf = cmsCreateProofingTransform( srcprof, TYPE_RGB_8, hprof, TYPE_RGB_8, proofProf, intent, proofIntent, dwFlags );
743         } else if ( hprof ) {
744             transf = cmsCreateTransform( srcprof, TYPE_RGB_8, hprof, TYPE_RGB_8, intent, 0 );
745         }
746     }
748     return transf;
751 #endif // ENABLE_LCMS
753 /*
754   Local Variables:
755   mode:c++
756   c-file-style:"stroustrup"
757   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
758   indent-tabs-mode:nil
759   fill-column:99
760   End:
761 */
762 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :