From: JucaBlues Date: Sat, 15 Aug 2009 05:59:15 +0000 (+0000) Subject: now gamut check works! X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=daadb3cf82c4d95f2918dd18ab7842ee434a6309;p=inkscape.git now gamut check works! --- diff --git a/src/color-profile.cpp b/src/color-profile.cpp index de9dc6959..5f2364449 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -13,6 +13,7 @@ #include #include #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 diff --git a/src/color-profile.h b/src/color-profile.h index 2e57e7ef0..40d0d7698 100644 --- a/src/color-profile.h +++ b/src/color-profile.h @@ -36,11 +36,15 @@ struct ColorProfile : public SPObject { static std::list 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 }; diff --git a/src/widgets/sp-color-notebook.cpp b/src/widgets/sp-color-notebook.cpp index 52c78ba42..04a35e4ad 100644 --- a/src/widgets/sp-color-notebook.cpp +++ b/src/widgets/sp-color-notebook.cpp @@ -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)); }