Code

now gamut check works!
authorJucaBlues <JucaBlues@users.sourceforge.net>
Sat, 15 Aug 2009 05:59:15 +0000 (05:59 +0000)
committerJucaBlues <JucaBlues@users.sourceforge.net>
Sat, 15 Aug 2009 05:59:15 +0000 (05:59 +0000)
src/color-profile.cpp
src/color-profile.h
src/widgets/sp-color-notebook.cpp

index de9dc6959cdff340ee30404f5a6e15eb6082b1d8..5f236444975d7bdc2bc5e12457f35cef7c480df4 100644 (file)
@@ -13,6 +13,7 @@
 #include <cstring>
 #include <string>
 #include "xml/repr.h"
+#include "color.h"
 #include "color-profile.h"
 #include "color-profile-fns.h"
 #include "attributes.h"
@@ -84,6 +85,15 @@ cmsHPROFILE ColorProfile::getSRGBProfile() {
     return _sRGBProf;
 }
 
+cmsHPROFILE ColorProfile::_NullProf = 0;
+
+cmsHPROFILE ColorProfile::getNULLProfile() {
+    if ( !_NullProf ) {
+        _NullProf = cmsCreateNULLProfile();
+    }
+    return _NullProf;
+}
+
 #endif // ENABLE_LCMS
 
 /**
@@ -144,6 +154,7 @@ void ColorProfile::init( ColorProfile *cprof )
     cprof->_profileSpace = icSigRgbData;
     cprof->_transf = 0;
     cprof->_revTransf = 0;
+    cprof->_gamutTransf = 0;
 #endif // ENABLE_LCMS
 }
 
@@ -197,6 +208,10 @@ void ColorProfile::_clearProfile()
         cmsDeleteTransform( _revTransf );
         _revTransf = 0;
     }
+    if ( _gamutTransf ) {
+        cmsDeleteTransform( _gamutTransf );
+        _gamutTransf = 0;
+    }
     if ( profHandle ) {
         cmsCloseProfile( profHandle );
         profHandle = 0;
@@ -496,6 +511,32 @@ cmsHTRANSFORM ColorProfile::getTransfFromSRGB8()
     return _revTransf;
 }
 
+cmsHTRANSFORM ColorProfile::getTransfGamutCheck()
+{
+    if ( !_gamutTransf ) {
+        _gamutTransf = cmsCreateProofingTransform(getSRGBProfile(), TYPE_RGBA_8, getNULLProfile(), TYPE_GRAY_8, profHandle, INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC, (cmsFLAGS_GAMUTCHECK|cmsFLAGS_SOFTPROOFING));
+    }
+    return _gamutTransf;
+}
+
+bool ColorProfile::GamutCheck(SPColor color){
+    BYTE outofgamut = 0;
+    
+    guint32 val = color.toRGBA32(0);
+    guchar check_color[4] = {
+        SP_RGBA32_R_U(val),
+        SP_RGBA32_G_U(val),
+        SP_RGBA32_B_U(val),
+        255};
+
+    int alarm_r, alarm_g, alarm_b;
+    cmsGetAlarmCodes(&alarm_r, &alarm_g, &alarm_b);
+    cmsSetAlarmCodes(255, 255, 255);
+    cmsDoTransform(ColorProfile::getTransfGamutCheck(), &check_color, &outofgamut, 1);
+    cmsSetAlarmCodes(alarm_r, alarm_g, alarm_b);
+    return (outofgamut == 255);
+}
+
 
 #include <io/sys.h>
 
index 2e57e7ef0221b3b813b00dca270d4df2dbabf84a..40d0d769871f89e96974493f7662ab156767695a 100644 (file)
@@ -36,11 +36,15 @@ struct ColorProfile : public SPObject {
     static std::list<Glib::ustring> getProfileDirs();
 #if ENABLE_LCMS
     static cmsHPROFILE getSRGBProfile();
+    static cmsHPROFILE getNULLProfile();
 
     icColorSpaceSignature getColorSpace() const {return _profileSpace;}
     icProfileClassSignature getProfileClass() const {return _profileClass;}
     cmsHTRANSFORM getTransfToSRGB8();
     cmsHTRANSFORM getTransfFromSRGB8();
+    cmsHTRANSFORM getTransfGamutCheck();
+    bool GamutCheck(SPColor color);
+
 #endif // ENABLE_LCMS
 
     gchar* href;
@@ -64,11 +68,13 @@ private:
     void _clearProfile();
 
     static cmsHPROFILE _sRGBProf;
+    static cmsHPROFILE _NullProf;
 
     icProfileClassSignature _profileClass;
     icColorSpaceSignature _profileSpace;
     cmsHTRANSFORM _transf;
     cmsHTRANSFORM _revTransf;
+    cmsHTRANSFORM _gamutTransf;
 #endif // ENABLE_LCMS
 };
 
index 52c78ba42af754871279493b9a8a6c034e8b6434..04a35e4ad8019efd5a5e2dc39aab1fdc089a8b09 100644 (file)
@@ -511,31 +511,9 @@ void ColorNotebook::_updateRgbaEntry( const SPColor& color, gfloat alpha )
     /* update out-of-gamut icon */
     gtk_widget_set_sensitive (_box_outofgamut, false);
     if (color.icc){
-        BYTE outofgamut = 0;
-        static cmsHPROFILE hNULL = cmsCreateNULLProfile();
-        static cmsHPROFILE hsRGB = cmsCreate_sRGBProfile();
-
         Inkscape::ColorProfile* target_profile = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str());
-        if ( target_profile ) {
-            cmsHTRANSFORM trans = cmsCreateProofingTransform(hsRGB, TYPE_RGBA_8, hNULL, TYPE_GRAY_8, target_profile->profHandle,
-             INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC, (cmsFLAGS_GAMUTCHECK|cmsFLAGS_SOFTPROOFING));
-
-            if ( trans ) {
-                guint32 val = color.toRGBA32(0);
-                guchar check_color[4] = {
-                    SP_RGBA32_R_U(val),
-                    SP_RGBA32_G_U(val),
-                    SP_RGBA32_B_U(val),
-                    255};
-
-                int alarm_r, alarm_g, alarm_b;
-                cmsGetAlarmCodes(&alarm_r, &alarm_g, &alarm_b);
-                cmsSetAlarmCodes(255, 255, 255);
-                cmsDoTransform(trans, &check_color, &outofgamut, 1);
-                cmsSetAlarmCodes(alarm_r, alarm_g, alarm_b);
-                gtk_widget_set_sensitive (_box_outofgamut, outofgamut == 255);
-            }
-        }
+        if ( target_profile )
+            gtk_widget_set_sensitive (_box_outofgamut, target_profile->GamutCheck(color));
     }