Code

Adding profile manager and user-visible drop-down in CMS picker
[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     // Unregister ourselves
131     SPDocument* document = SP_OBJECT_DOCUMENT(object);
132     if ( document ) {
133         sp_document_remove_resource (SP_OBJECT_DOCUMENT (object), "iccprofile", SP_OBJECT (object));
134     }
136     ColorProfile *cprof = COLORPROFILE(object);
137     if ( cprof->href ) {
138         g_free( cprof->href );
139         cprof->href = 0;
140     }
142     if ( cprof->local ) {
143         g_free( cprof->local );
144         cprof->local = 0;
145     }
147     if ( cprof->name ) {
148         g_free( cprof->name );
149         cprof->name = 0;
150     }
152     if ( cprof->intentStr ) {
153         g_free( cprof->intentStr );
154         cprof->intentStr = 0;
155     }
157 #if ENABLE_LCMS
158     if ( cprof->profHandle ) {
159         cmsCloseProfile( cprof->profHandle );
160         cprof->profHandle = 0;
161     }
162 #endif // ENABLE_LCMS
165 /**
166  * Callback: set attributes from associated repr.
167  */
168 static void Inkscape::colorprofile_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr )
170     ColorProfile *cprof = COLORPROFILE(object);
171     g_assert(cprof->href == 0);
172     g_assert(cprof->local == 0);
173     g_assert(cprof->name == 0);
174     g_assert(cprof->intentStr == 0);
176     if (((SPObjectClass *) cprof_parent_class)->build) {
177         (* ((SPObjectClass *) cprof_parent_class)->build)(object, document, repr);
178     }
179     sp_object_read_attr( object, "xlink:href" );
180     sp_object_read_attr( object, "local" );
181     sp_object_read_attr( object, "name" );
182     sp_object_read_attr( object, "rendering-intent" );
184     // Register
185     if ( document ) {
186         sp_document_add_resource( document, "iccprofile", object );
187     }
190 /**
191  * Callback: set attribute.
192  */
193 static void Inkscape::colorprofile_set( SPObject *object, unsigned key, gchar const *value )
195     ColorProfile *cprof = COLORPROFILE(object);
197     switch (key) {
198         case SP_ATTR_XLINK_HREF:
199             if ( cprof->href ) {
200                 g_free( cprof->href );
201                 cprof->href = 0;
202             }
203             if ( value ) {
204                 cprof->href = g_strdup( value );
205                 if ( *cprof->href ) {
206 #if ENABLE_LCMS
207                     cmsErrorAction( LCMS_ERROR_SHOW );
209                     // TODO open filename and URIs properly
210                     //FILE* fp = fopen_utf8name( filename, "r" );
211                     //LCMSAPI cmsHPROFILE   LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, DWORD dwSize);
213                     // Try to open relative
214                     SPDocument *doc = SP_OBJECT_DOCUMENT(object);
215                     if (!doc) {
216                         doc = SP_ACTIVE_DOCUMENT;
217                         g_warning("object has no document.  using active");
218                     }
219                     //# 1.  Get complete URI of document
220                     gchar const *docbase = SP_DOCUMENT_URI( doc );
221                     if (!docbase)
222                         {
223                         g_warning("null docbase");
224                         docbase = "";
225                         }
226                     //g_message("docbase:%s\n", docbase);
227                     org::w3c::dom::URI docUri(docbase);
228                     //# 2. Get href of icc file.  we don't care if it's rel or abs
229                     org::w3c::dom::URI hrefUri(cprof->href);
230                     //# 3.  Resolve the href according the docBase.  This follows
231                     //      the w3c specs.  All absolute and relative issues are considered
232                     org::w3c::dom::URI cprofUri = docUri.resolve(hrefUri);
233                     gchar* fullname = (gchar *)cprofUri.getNativePath().c_str();
234                     cprof->profHandle = cmsOpenProfileFromFile( fullname, "r" );
235 #ifdef DEBUG_LCMS
236                     DEBUG_MESSAGE( lcmsOne, "cmsOpenProfileFromFile( '%s'...) = %p", fullname, (void*)cprof->profHandle );
237 #endif // DEBUG_LCMS
239 #endif // ENABLE_LCMS
240                 }
241             }
242             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
243             break;
245         case SP_ATTR_LOCAL:
246             if ( cprof->local ) {
247                 g_free( cprof->local );
248                 cprof->local = 0;
249             }
250             cprof->local = g_strdup( value );
251             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
252             break;
254         case SP_ATTR_NAME:
255             if ( cprof->name ) {
256                 g_free( cprof->name );
257                 cprof->name = 0;
258             }
259             cprof->name = g_strdup( value );
260 #ifdef DEBUG_LCMS
261             DEBUG_MESSAGE( lcmsTwo, "<color-profile> name set to '%s'", cprof->name );
262 #endif // DEBUG_LCMS
263             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
264             break;
266         case SP_ATTR_RENDERING_INTENT:
267             if ( cprof->intentStr ) {
268                 g_free( cprof->intentStr );
269                 cprof->intentStr = 0;
270             }
271             cprof->intentStr = g_strdup( value );
273             if ( value ) {
274                 if ( strcmp( value, "auto" ) == 0 ) {
275                     cprof->rendering_intent = RENDERING_INTENT_AUTO;
276                 } else if ( strcmp( value, "perceptual" ) == 0 ) {
277                     cprof->rendering_intent = RENDERING_INTENT_PERCEPTUAL;
278                 } else if ( strcmp( value, "relative-colorimetric" ) == 0 ) {
279                     cprof->rendering_intent = RENDERING_INTENT_RELATIVE_COLORIMETRIC;
280                 } else if ( strcmp( value, "saturation" ) == 0 ) {
281                     cprof->rendering_intent = RENDERING_INTENT_SATURATION;
282                 } else if ( strcmp( value, "absolute-colorimetric" ) == 0 ) {
283                     cprof->rendering_intent = RENDERING_INTENT_ABSOLUTE_COLORIMETRIC;
284                 } else {
285                     cprof->rendering_intent = RENDERING_INTENT_UNKNOWN;
286                 }
287             } else {
288                 cprof->rendering_intent = RENDERING_INTENT_UNKNOWN;
289             }
291             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
292             break;
294         default:
295             if (((SPObjectClass *) cprof_parent_class)->set) {
296                 (* ((SPObjectClass *) cprof_parent_class)->set)(object, key, value);
297             }
298             break;
299     }
303 /**
304  * Callback: write attributes to associated repr.
305  */
306 static Inkscape::XML::Node* Inkscape::colorprofile_write( SPObject *object, Inkscape::XML::Node *repr, guint flags )
308     ColorProfile *cprof = COLORPROFILE(object);
310     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
311         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
312         repr = xml_doc->createElement("svg:color-profile");
313     }
315     if ( (flags & SP_OBJECT_WRITE_ALL) || cprof->href ) {
316         repr->setAttribute( "xlink:href", cprof->href );
317     }
319     if ( (flags & SP_OBJECT_WRITE_ALL) || cprof->local ) {
320         repr->setAttribute( "local", cprof->local );
321     }
323     if ( (flags & SP_OBJECT_WRITE_ALL) || cprof->name ) {
324         repr->setAttribute( "name", cprof->name );
325     }
327     if ( (flags & SP_OBJECT_WRITE_ALL) || cprof->intentStr ) {
328         repr->setAttribute( "rendering-intent", cprof->intentStr );
329     }
331     if (((SPObjectClass *) cprof_parent_class)->write) {
332         (* ((SPObjectClass *) cprof_parent_class)->write)(object, repr, flags);
333     }
335     return repr;
339 #if ENABLE_LCMS
342 static SPObject* bruteFind( SPDocument* document, gchar const* name )
344     SPObject* result = 0;
345     const GSList * current = sp_document_get_resource_list(document, "iccprofile");
346     while ( current && !result ) {
347         if ( IS_COLORPROFILE(current->data) ) {
348             ColorProfile* prof = COLORPROFILE(current->data);
349             if ( prof ) {
350                 if ( prof->name && (strcmp(prof->name, name) == 0) ) {
351                     result = SP_OBJECT(current->data);
352                     break;
353                 }
354             }
355         }
356         current = g_slist_next(current);
357     }
359     return result;
362 cmsHPROFILE Inkscape::colorprofile_get_handle( SPDocument* document, guint* intent, gchar const* name )
364     cmsHPROFILE prof = 0;
366     SPObject* thing = bruteFind( document, name );
367     if ( thing ) {
368         prof = COLORPROFILE(thing)->profHandle;
369     }
371     if ( intent ) {
372         *intent = thing ? COLORPROFILE(thing)->rendering_intent : (guint)RENDERING_INTENT_UNKNOWN;
373     }
375 #ifdef DEBUG_LCMS
376     DEBUG_MESSAGE( lcmsThree, "<color-profile> queried for profile of '%s'. Returning %p with intent of %d", name, prof, (intent? *intent:0) );
377 #endif // DEBUG_LCMS
379     return prof;
383 #include <io/sys.h>
385 class ProfileInfo
387 public:
388     ProfileInfo( cmsHPROFILE, Glib::ustring const & path );
390     Glib::ustring const& getName() {return _name;}
391     Glib::ustring const& getPath() {return _path;}
392     icColorSpaceSignature getSpace() {return _profileSpace;}
393     icProfileClassSignature getClass() {return _profileClass;}
395 private:
396     Glib::ustring _path;
397     Glib::ustring _name;
398     icColorSpaceSignature _profileSpace;
399     icProfileClassSignature _profileClass;
400 };
403 ProfileInfo::ProfileInfo( cmsHPROFILE prof, Glib::ustring const & path )
405     _path = path;
406     _name = cmsTakeProductDesc(prof);
407     _profileSpace = cmsGetColorSpace( prof );
408     _profileClass = cmsGetDeviceClass( prof );
413 static std::vector<ProfileInfo> knownProfiles;
415 std::vector<Glib::ustring> Inkscape::colorprofile_get_display_names()
417     std::vector<Glib::ustring> result;
419     for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
420         if ( it->getClass() == icSigDisplayClass && it->getSpace() == icSigRgbData ) {
421             result.push_back( it->getName() );
422         }
423     }
425     return result;
428 std::vector<Glib::ustring> Inkscape::colorprofile_get_softproof_names()
430     std::vector<Glib::ustring> result;
432     for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
433         if ( it->getClass() == icSigOutputClass ) {
434             result.push_back( it->getName() );
435         }
436     }
438     return result;
441 Glib::ustring Inkscape::get_path_for_profile(Glib::ustring const& name)
443     Glib::ustring result;
445     for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
446         if ( name == it->getName() ) {
447             result = it->getPath();
448             break;
449         }
450     }
452     return result;
455 static void findThings() {
456     std::list<gchar *> sources;
458     gchar* base = profile_path("XXX");
459     {
460         gchar* base2 = g_path_get_dirname(base);
461         g_free(base);
462         base = base2;
463         base2 = g_path_get_dirname(base);
464         g_free(base);
465         base = base2;
466     }
468     // first try user's local dir
469     sources.push_back( g_build_filename(g_get_user_data_dir(), "color", "icc", NULL) );
470     sources.push_back( g_build_filename(base, ".color", "icc", NULL) ); // OpenICC recommends to deprecate this
472     const gchar* const * dataDirs = g_get_system_data_dirs();
473     for ( int i = 0; dataDirs[i]; i++ ) {
474         sources.push_back(g_build_filename(dataDirs[i], "color", "icc", NULL));
475     }
477     while (!sources.empty()) {
478         gchar *dirname = sources.front();
479         if ( g_file_test( dirname, G_FILE_TEST_EXISTS ) && g_file_test( dirname, G_FILE_TEST_IS_DIR ) ) {
480             GError *err = 0;
481             GDir *dir = g_dir_open(dirname, 0, &err);
483             if (dir) {
484                 for (gchar const *file = g_dir_read_name(dir); file != NULL; file = g_dir_read_name(dir)) {
485                     gchar *filepath = g_build_filename(dirname, file, NULL);
488                     if ( g_file_test( filepath, G_FILE_TEST_IS_DIR ) ) {
489                         sources.push_back(g_strdup(filepath));
490                     } else {
491                         bool isIccFile = false;
492                         struct stat st;
493                         if ( g_stat(filepath, &st) == 0 && (st.st_size > 128) ) {
494                             //0-3 == size
495                             //36-39 == 'acsp' 0x61637370
496                             int fd = g_open( filepath, O_RDONLY, S_IRWXU);
497                             if ( fd != -1 ) {
498                                 guchar scratch[40] = {0};
499                                 size_t len = sizeof(scratch);
501                                 //size_t left = 40;
502                                 ssize_t got = read(fd, scratch, len);
503                                 if ( got != -1 ) {
504                                     size_t calcSize = (scratch[0] << 24) | (scratch[1] << 16) | (scratch[2] << 8) | scratch[3];
505                                     if ( calcSize > 128 && calcSize <= st.st_size ) {
506                                         isIccFile = (scratch[36] == 'a') && (scratch[37] == 'c') && (scratch[38] == 's') && (scratch[39] == 'p');
507                                     }
508                                 }
510                                 close(fd);
511                             }
512                         }
514                         if ( isIccFile ) {
515                             cmsHPROFILE prof = cmsOpenProfileFromFile( filepath, "r" );
516                             if ( prof ) {
517                                 ProfileInfo info( prof, Glib::filename_to_utf8( filepath ) );
518                                 cmsCloseProfile( prof );
520                                 bool sameName = false;
521                                 for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
522                                     if ( it->getName() == info.getName() ) {
523                                         sameName = true;
524                                         break;
525                                     }
526                                 }
528                                 if ( !sameName ) {
529                                     knownProfiles.push_back(info);
530                                 }
531                             }
532                         }
533                     }
535                     g_free(filepath);
536                 }
537             }
538         }
540         // toss the dirname
541         g_free(dirname);
542         sources.pop_front();
543     }
546 int errorHandlerCB(int ErrorCode, const char *ErrorText)
548     g_message("lcms: Error %d; %s", ErrorCode, ErrorText);
550     return 1;
553 static bool gamutWarn = false;
554 static Gdk::Color lastGamutColor("#808080");
555 static bool lastBPC = false;
556 #if defined(cmsFLAGS_PRESERVEBLACK)
557 static bool lastPreserveBlack = false;
558 #endif // defined(cmsFLAGS_PRESERVEBLACK)
559 static int lastIntent = INTENT_PERCEPTUAL;
560 static int lastProofIntent = INTENT_PERCEPTUAL;
561 static cmsHTRANSFORM transf = 0;
562 static cmsHPROFILE srcprof = 0;
564 cmsHPROFILE Inkscape::colorprofile_get_system_profile_handle()
566     static cmsHPROFILE theOne = 0;
567     static std::string lastURI;
569     static bool init = false;
570     if ( !init ) {
571         cmsSetErrorHandler(errorHandlerCB);
573         findThings();
574         init = true;
575     }
577     long long int which = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 );
578     gchar const * uri = prefs_get_string_attribute("options.displayprofile", "uri");
580     if ( which && uri && *uri ) {
581         if ( lastURI != std::string(uri) ) {
582             lastURI.clear();
583             if ( theOne ) {
584                 cmsCloseProfile( theOne );
585             }
586             if ( transf ) {
587                 cmsDeleteTransform( transf );
588                 transf = 0;
589             }
590             theOne = cmsOpenProfileFromFile( uri, "r" );
591             if ( theOne ) {
592                 // a display profile must have the proper stuff
593                 icColorSpaceSignature space = cmsGetColorSpace(theOne);
594                 icProfileClassSignature profClass = cmsGetDeviceClass(theOne);
596                 if ( profClass != icSigDisplayClass ) {
597                     g_warning("Not a display profile");
598                     cmsCloseProfile( theOne );
599                     theOne = 0;
600                 } else if ( space != icSigRgbData ) {
601                     g_warning("Not an RGB profile");
602                     cmsCloseProfile( theOne );
603                     theOne = 0;
604                 } else {
605                     lastURI = uri;
606                 }
607             }
608         }
609     } else if ( theOne ) {
610         cmsCloseProfile( theOne );
611         theOne = 0;
612         lastURI.clear();
613         if ( transf ) {
614             cmsDeleteTransform( transf );
615             transf = 0;
616         }
617     }
619     return theOne;
623 cmsHPROFILE Inkscape::colorprofile_get_proof_profile_handle()
625     static cmsHPROFILE theOne = 0;
626     static std::string lastURI;
628     static bool init = false;
629     if ( !init ) {
630         cmsSetErrorHandler(errorHandlerCB);
632         findThings();
633         init = true;
634     }
636     long long int which = prefs_get_int_attribute_limited( "options.softproof", "enable", 0, 0, 1 );
637     gchar const * uri = prefs_get_string_attribute("options.softproof", "uri");
639     if ( which && uri && *uri ) {
640         if ( lastURI != std::string(uri) ) {
641             lastURI.clear();
642             if ( theOne ) {
643                 cmsCloseProfile( theOne );
644             }
645             if ( transf ) {
646                 cmsDeleteTransform( transf );
647                 transf = 0;
648             }
649             theOne = cmsOpenProfileFromFile( uri, "r" );
650             if ( theOne ) {
651                 // a display profile must have the proper stuff
652                 icColorSpaceSignature space = cmsGetColorSpace(theOne);
653                 icProfileClassSignature profClass = cmsGetDeviceClass(theOne);
655                 (void)space;
656                 (void)profClass;
657 /*
658                 if ( profClass != icSigDisplayClass ) {
659                     g_warning("Not a display profile");
660                     cmsCloseProfile( theOne );
661                     theOne = 0;
662                 } else if ( space != icSigRgbData ) {
663                     g_warning("Not an RGB profile");
664                     cmsCloseProfile( theOne );
665                     theOne = 0;
666                 } else {
667 */
668                     lastURI = uri;
669 /*
670                 }
671 */
672             }
673         }
674     } else if ( theOne ) {
675         cmsCloseProfile( theOne );
676         theOne = 0;
677         lastURI.clear();
678         if ( transf ) {
679             cmsDeleteTransform( transf );
680             transf = 0;
681         }
682     }
684     return theOne;
687 cmsHTRANSFORM Inkscape::colorprofile_get_display_transform()
689     bool warn = prefs_get_int_attribute_limited( "options.softproof", "gamutwarn", 0, 0, 1 );
690     int intent = prefs_get_int_attribute_limited( "options.displayprofile", "intent", 0, 0, 3 );
691     int proofIntent = prefs_get_int_attribute_limited( "options.softproof", "intent", 0, 0, 3 );
692     bool bpc = prefs_get_int_attribute_limited( "options.softproof", "bpc", 0, 0, 1 );
693 #if defined(cmsFLAGS_PRESERVEBLACK)
694     bool preserveBlack = prefs_get_int_attribute_limited( "options.softproof", "preserveblack", 0, 0, 1 );
695 #endif //defined(cmsFLAGS_PRESERVEBLACK)
696     gchar const* colorStr = prefs_get_string_attribute("options.softproof", "gamutcolor");
697     Gdk::Color gamutColor( (colorStr && colorStr[0]) ? colorStr : "#808080");
699     if ( (warn != gamutWarn)
700          || (lastIntent != intent)
701          || (lastProofIntent != proofIntent)
702          || (bpc != lastBPC)
703 #if defined(cmsFLAGS_PRESERVEBLACK)
704          || (preserveBlack != lastPreserveBlack)
705 #endif // defined(cmsFLAGS_PRESERVEBLACK)
706          || (gamutColor != lastGamutColor)
707         ) {
708         gamutWarn = warn;
709         if ( transf ) {
710             cmsDeleteTransform(transf);
711             transf = 0;
712         }
713         lastIntent = intent;
714         lastProofIntent = proofIntent;
715         lastBPC = bpc;
716 #if defined(cmsFLAGS_PRESERVEBLACK)
717         lastPreserveBlack = preserveBlack;
718 #endif // defined(cmsFLAGS_PRESERVEBLACK)
719         lastGamutColor = gamutColor;
720     }
722     // Fecth these now, as they might clear the transform as a side effect.
723     cmsHPROFILE hprof = Inkscape::colorprofile_get_system_profile_handle();
724     cmsHPROFILE proofProf = hprof ? Inkscape::colorprofile_get_proof_profile_handle() : 0;
726     if ( !transf ) {
727         if ( !srcprof ) {
728             srcprof = cmsCreate_sRGBProfile();
729         }
730         if ( hprof && proofProf ) {
731             DWORD dwFlags = cmsFLAGS_SOFTPROOFING;
732             if ( gamutWarn ) {
733                 dwFlags |= cmsFLAGS_GAMUTCHECK;
734                 cmsSetAlarmCodes(gamutColor.get_red() >> 8, gamutColor.get_green() >> 8, gamutColor.get_blue() >> 8);
735             }
736             if ( bpc ) {
737                 dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
738             }
739 #if defined(cmsFLAGS_PRESERVEBLACK)
740             if ( preserveBlack ) {
741                 dwFlags |= cmsFLAGS_PRESERVEBLACK;
742             }
743 #endif // defined(cmsFLAGS_PRESERVEBLACK)
744             transf = cmsCreateProofingTransform( srcprof, TYPE_RGB_8, hprof, TYPE_RGB_8, proofProf, intent, proofIntent, dwFlags );
745         } else if ( hprof ) {
746             transf = cmsCreateTransform( srcprof, TYPE_RGB_8, hprof, TYPE_RGB_8, intent, 0 );
747         }
748     }
750     return transf;
753 #endif // ENABLE_LCMS
755 /*
756   Local Variables:
757   mode:c++
758   c-file-style:"stroustrup"
759   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
760   indent-tabs-mode:nil
761   fill-column:99
762   End:
763 */
764 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :