Code

Enabled custom 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("#00ff00");
553 static bool lastBPC = false;
554 static bool lastPreserveBlack = false;
555 static int lastIntent = INTENT_PERCEPTUAL;
556 static int lastProofIntent = INTENT_PERCEPTUAL;
557 static cmsHTRANSFORM transf = 0;
558 static cmsHPROFILE srcprof = 0;
560 cmsHPROFILE Inkscape::colorprofile_get_system_profile_handle()
562     static cmsHPROFILE theOne = 0;
563     static std::string lastURI;
565     static bool init = false;
566     if ( !init ) {
567         cmsSetErrorHandler(errorHandlerCB);
569         findThings();
570         init = true;
571     }
573     long long int which = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 );
574     gchar const * uri = prefs_get_string_attribute("options.displayprofile", "uri");
576     if ( which && uri && *uri ) {
577         if ( lastURI != std::string(uri) ) {
578             lastURI.clear();
579             if ( theOne ) {
580                 cmsCloseProfile( theOne );
581             }
582             if ( transf ) {
583                 cmsDeleteTransform( transf );
584                 transf = 0;
585             }
586             theOne = cmsOpenProfileFromFile( uri, "r" );
587             if ( theOne ) {
588                 // a display profile must have the proper stuff
589                 icColorSpaceSignature space = cmsGetColorSpace(theOne);
590                 icProfileClassSignature profClass = cmsGetDeviceClass(theOne);
592                 if ( profClass != icSigDisplayClass ) {
593                     g_warning("Not a display profile");
594                     cmsCloseProfile( theOne );
595                     theOne = 0;
596                 } else if ( space != icSigRgbData ) {
597                     g_warning("Not an RGB profile");
598                     cmsCloseProfile( theOne );
599                     theOne = 0;
600                 } else {
601                     lastURI = uri;
602                 }
603             }
604         }
605     } else if ( theOne ) {
606         cmsCloseProfile( theOne );
607         theOne = 0;
608         lastURI.clear();
609         if ( transf ) {
610             cmsDeleteTransform( transf );
611             transf = 0;
612         }
613     }
615     return theOne;
619 cmsHPROFILE Inkscape::colorprofile_get_proof_profile_handle()
621     static cmsHPROFILE theOne = 0;
622     static std::string lastURI;
624     static bool init = false;
625     if ( !init ) {
626         cmsSetErrorHandler(errorHandlerCB);
628         findThings();
629         init = true;
630     }
632     long long int which = prefs_get_int_attribute_limited( "options.softproof", "enable", 0, 0, 1 );
633     gchar const * uri = prefs_get_string_attribute("options.softproof", "uri");
635     if ( which && uri && *uri ) {
636         if ( lastURI != std::string(uri) ) {
637             lastURI.clear();
638             if ( theOne ) {
639                 cmsCloseProfile( theOne );
640             }
641             if ( transf ) {
642                 cmsDeleteTransform( transf );
643                 transf = 0;
644             }
645             theOne = cmsOpenProfileFromFile( uri, "r" );
646             if ( theOne ) {
647                 // a display profile must have the proper stuff
648                 icColorSpaceSignature space = cmsGetColorSpace(theOne);
649                 icProfileClassSignature profClass = cmsGetDeviceClass(theOne);
651                 (void)space;
652                 (void)profClass;
653 /*
654                 if ( profClass != icSigDisplayClass ) {
655                     g_warning("Not a display profile");
656                     cmsCloseProfile( theOne );
657                     theOne = 0;
658                 } else if ( space != icSigRgbData ) {
659                     g_warning("Not an RGB profile");
660                     cmsCloseProfile( theOne );
661                     theOne = 0;
662                 } else {
663 */
664                     lastURI = uri;
665 /*
666                 }
667 */
668             }
669         }
670     } else if ( theOne ) {
671         cmsCloseProfile( theOne );
672         theOne = 0;
673         lastURI.clear();
674         if ( transf ) {
675             cmsDeleteTransform( transf );
676             transf = 0;
677         }
678     }
680     return theOne;
683 cmsHTRANSFORM Inkscape::colorprofile_get_display_transform()
685     bool warn = prefs_get_int_attribute_limited( "options.softproof", "gamutwarn", 0, 0, 1 );
686     int intent = prefs_get_int_attribute_limited( "options.displayprofile", "intent", 0, 0, 3 );
687     int proofIntent = prefs_get_int_attribute_limited( "options.softproof", "intent", 0, 0, 3 );
688     bool bpc = prefs_get_int_attribute_limited( "options.softproof", "bpc", 0, 0, 1 );
689     bool preserveBlack = prefs_get_int_attribute_limited( "options.softproof", "preserveblack", 0, 0, 1 );
690     gchar const* colorStr = prefs_get_string_attribute("options.softproof", "gamutcolor");
691     Gdk::Color gamutColor( (colorStr && colorStr[0]) ? colorStr : "#00ff00");
693     if ( (warn != gamutWarn)
694          || (lastIntent != intent)
695          || (lastProofIntent != proofIntent)
696          || (bpc != lastBPC)
697          || (preserveBlack != lastPreserveBlack)
698          || (gamutColor != lastGamutColor)
699         ) {
700         gamutWarn = warn;
701         if ( transf ) {
702             cmsDeleteTransform(transf);
703             transf = 0;
704         }
705         lastIntent = intent;
706         lastProofIntent = proofIntent;
707         lastBPC = bpc;
708         lastPreserveBlack = preserveBlack;
709         lastGamutColor = gamutColor;
710     }
712     // Fecth these now, as they might clear the transform as a side effect.
713     cmsHPROFILE hprof = Inkscape::colorprofile_get_system_profile_handle();
714     cmsHPROFILE proofProf = hprof ? Inkscape::colorprofile_get_proof_profile_handle() : 0;
716     if ( !transf ) {
717         if ( !srcprof ) {
718             srcprof = cmsCreate_sRGBProfile();
719         }
720         if ( hprof && proofProf ) {
721             DWORD dwFlags = cmsFLAGS_SOFTPROOFING;
722             if ( gamutWarn ) {
723                 dwFlags |= cmsFLAGS_GAMUTCHECK;
724                 cmsSetAlarmCodes(gamutColor.get_red() >> 8, gamutColor.get_green() >> 8, gamutColor.get_blue() >> 8);
725             }
726             if ( bpc ) {
727                 dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
728             }
729             if ( preserveBlack ) {
730                 dwFlags |= cmsFLAGS_PRESERVEBLACK;
731             }
732             transf = cmsCreateProofingTransform( srcprof, TYPE_RGB_8, hprof, TYPE_RGB_8, proofProf, intent, proofIntent, dwFlags );
733         } else if ( hprof ) {
734             transf = cmsCreateTransform( srcprof, TYPE_RGB_8, hprof, TYPE_RGB_8, intent, 0 );
735         }
736     }
738     return transf;
741 #endif // ENABLE_LCMS
743 /*
744   Local Variables:
745   mode:c++
746   c-file-style:"stroustrup"
747   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
748   indent-tabs-mode:nil
749   fill-column:99
750   End:
751 */
752 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :