Code

NR::Maybe => boost::optional
[inkscape.git] / src / widgets / sp-color-icc-selector.cpp
index 957bafbb1f250001e5b0252fa0d88ff43c382f3f..43a2a3cbe7ef7a573aef17ab06cb22e5442976b3 100644 (file)
@@ -2,6 +2,8 @@
 # include "config.h"
 #endif
 #include <math.h>
+#include <gtk/gtkbutton.h>
+#include <gtk/gtkcombobox.h>
 #include <gtk/gtksignal.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtktable.h>
@@ -11,7 +13,9 @@
 #include "sp-color-icc-selector.h"
 #include "sp-color-scales.h"
 #include "svg/svg-icc-color.h"
+#include "document.h"
 #include "inkscape.h"
+#include "profile-manager.h"
 
 #define noDEBUG_LCMS
 
@@ -123,10 +127,12 @@ sp_color_icc_selector_class_init (SPColorICCSelectorClass *klass)
     widget_class->hide_all = sp_color_icc_selector_hide_all;
 }
 
+
 ColorICCSelector::ColorICCSelector( SPColorSelector* csel )
     : ColorSelector( csel ),
       _updating( FALSE ),
       _dragging( FALSE ),
+      _fixupNeeded(0),
       _fooCount(0),
       _fooScales(0),
       _fooAdj(0),
@@ -141,13 +147,9 @@ ColorICCSelector::ColorICCSelector( SPColorSelector* csel )
 #if ENABLE_LCMS
     ,
       _profileName(""),
-      _profIntent(Inkscape::RENDERING_INTENT_UNKNOWN),
-      _profileSpace(icSigRgbData),
-      _profileClass(icSigInputClass),
-      _prof(0),
-      _destProf(0),
-      _transf(0),
-      _profChannelCount(0)
+      _prof(),
+      _profChannelCount(0),
+      _profChangedID(0)
 #endif // ENABLE_LCMS
 {
 }
@@ -180,6 +182,7 @@ icSigCmyData
 #define SPACE_ID_CMYK 2
 
 
+#if ENABLE_LCMS
 static icUInt16Number* getScratch() {
     // bytes per pixel * input channels * width
     static icUInt16Number* scritch = static_cast<icUInt16Number*>(g_new(icUInt16Number, 4 * 1024));
@@ -192,8 +195,7 @@ struct MapMap {
     DWORD inForm;
 };
 
-void getThings( DWORD space, gchar const**& namers, gchar const**& tippies, bool const*& trickies, guint const*& scalies, DWORD& inputFormat ) {
-
+void getThings( DWORD space, gchar const**& namers, gchar const**& tippies, guint const*& scalies ) {
     MapMap possible[] = {
         {icSigXYZData,   TYPE_XYZ_16},
         {icSigLabData,   TYPE_Lab_16},
@@ -236,20 +238,6 @@ void getThings( DWORD space, gchar const**& namers, gchar const**& tippies, bool
         {_("Cyan"), _("Magenta"), _("Yellow"), "", "", ""},
     };
 
-    static bool tricksies[][6] = {
-        {false, false, false, false, false, false}, // XYZ       0~2, 0~1, 0~2
-        {false, true,  true,  false, false, false}, // Lab       0~100, -128~128, -128~128
-        // Luv 0~100, -128~128, -128~128
-        {false, true,  true,  false, false, false}, // YCbCr     ?
-        {false, true,  true,  false, false, false}, // Yxy       0~1, 0~1, 0~1
-        {false, false, false, false, false, false}, // RGB       0~1, 0~1, 0~1
-        {false, false, false, false, false, false}, // Gray      0~1
-        {true,  false, false, false, false, false}, // HSV       0~360, 0~1, 0~1
-        {true,  false, false, false, false, false}, // HLS       0~360, 0~1, 0~1
-        {false, false, false, false, false, false}, // CMYK      0~1, 0~1, 0~1, 0~1
-        {false, false, false, false, false, false}, // CMY
-    };
-
     static guint scales[][6] = {
         {2, 1, 2, 1, 1, 1},
         {100, 256, 256, 1, 1, 1},
@@ -272,12 +260,11 @@ void getThings( DWORD space, gchar const**& namers, gchar const**& tippies, bool
         }
     }
 
-    inputFormat = possible[index].inForm;
     namers = names[index];
     tippies = tips[index];
-    trickies = tricksies[index];
     scalies = scales[index];
 }
+#endif // ENABLE_LCMS
 
 
 void ColorICCSelector::init()
@@ -294,18 +281,41 @@ void ColorICCSelector::init()
     gtk_widget_show (t);
     gtk_box_pack_start (GTK_BOX (_csel), t, TRUE, TRUE, 0);
 
-    DWORD inputFormat = TYPE_RGB_16;
+#if ENABLE_LCMS
     //guint partCount = _cmsChannelsOf( icSigRgbData );
     gchar const** names = 0;
     gchar const** tips = 0;
-    bool const* tricky = 0;
-    getThings( icSigRgbData, names, tips, tricky, _fooScales, inputFormat );
-
+    getThings( icSigRgbData, names, tips, _fooScales );
+#endif // ENABLE_LCMS
 
     /* Create components */
     row = 0;
 
 
+    _fixupBtn = gtk_button_new_with_label(_("Fix"));
+    g_signal_connect( G_OBJECT(_fixupBtn), "clicked", G_CALLBACK(_fixupHit), (gpointer)this );
+    gtk_widget_set_sensitive( _fixupBtn, FALSE );
+    gtk_tooltips_set_tip( _tt, _fixupBtn, _("Fix RGB fallback to match icc-color() value."), NULL );
+    //gtk_misc_set_alignment( GTK_MISC (_fixupBtn), 1.0, 0.5 );
+    gtk_widget_show( _fixupBtn );
+    gtk_table_attach( GTK_TABLE (t), _fixupBtn, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD );
+
+
+    _profileSel = gtk_combo_box_new_text();
+    gtk_combo_box_append_text( GTK_COMBO_BOX(_profileSel), "<none>" );
+    gtk_widget_show( _profileSel );
+    gtk_combo_box_set_active( GTK_COMBO_BOX(_profileSel), 0 );
+    gtk_table_attach( GTK_TABLE(t), _profileSel, 1, 2, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD );
+
+#if ENABLE_LCMS
+    _profChangedID = g_signal_connect( G_OBJECT(_profileSel), "changed", G_CALLBACK(_profileSelected), (gpointer)this );
+#else
+    gtk_widget_set_sensitive( _profileSel, false );
+#endif // ENABLE_LCMS
+
+
+    row++;
+
     _fooCount = 4;
     _fooAdj = new GtkAdjustment*[_fooCount];
     _fooSlider = new GtkWidget*[_fooCount];
@@ -315,7 +325,11 @@ void ColorICCSelector::init()
 
     for ( guint i = 0; i < _fooCount; i++ ) {
         /* Label */
+#if ENABLE_LCMS
         _fooLabel[i] = gtk_label_new_with_mnemonic( names[i] );
+#else
+        _fooLabel[i] = gtk_label_new_with_mnemonic( "." );
+#endif // ENABLE_LCMS
         gtk_misc_set_alignment( GTK_MISC (_fooLabel[i]), 1.0, 0.5 );
         gtk_widget_show( _fooLabel[i] );
         gtk_table_attach( GTK_TABLE (t), _fooLabel[i], 0, 1, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD );
@@ -328,12 +342,20 @@ void ColorICCSelector::init()
 
         /* Slider */
         _fooSlider[i] = sp_color_slider_new( _fooAdj[i] );
+#if ENABLE_LCMS
         gtk_tooltips_set_tip( _tt, _fooSlider[i], tips[i], NULL );
+#else
+        gtk_tooltips_set_tip( _tt, _fooSlider[i], ".", NULL );
+#endif // ENABLE_LCMS
         gtk_widget_show( _fooSlider[i] );
         gtk_table_attach( GTK_TABLE (t), _fooSlider[i], 1, 2, row, row + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)GTK_FILL, XPAD, YPAD );
 
         _fooBtn[i] = gtk_spin_button_new( _fooAdj[i], step, digits );
+#if ENABLE_LCMS
         gtk_tooltips_set_tip( _tt, _fooBtn[i], tips[i], NULL );
+#else
+        gtk_tooltips_set_tip( _tt, _fooBtn[i], ".", NULL );
+#endif // ENABLE_LCMS
         sp_dialog_defocus_on_enter( _fooBtn[i] );
         gtk_label_set_mnemonic_widget( GTK_LABEL(_fooLabel[i]), _fooBtn[i] );
         gtk_widget_show( _fooBtn[i] );
@@ -423,30 +445,211 @@ sp_color_icc_selector_new (void)
     return GTK_WIDGET (csel);
 }
 
+
+void ColorICCSelector::_fixupHit( GtkWidget* /*src*/, gpointer data )
+{
+    ColorICCSelector* self = reinterpret_cast<ColorICCSelector*>(data);
+    gtk_widget_set_sensitive( self->_fixupBtn, FALSE );
+    self->_adjustmentChanged( self->_fooAdj[0], SP_COLOR_ICC_SELECTOR(self->_csel) );
+}
+
+#if ENABLE_LCMS
+void ColorICCSelector::_profileSelected( GtkWidget* /*src*/, gpointer data )
+{
+    ColorICCSelector* self = reinterpret_cast<ColorICCSelector*>(data);
+    gint activeIndex = gtk_combo_box_get_active( GTK_COMBO_BOX(self->_profileSel) );
+    gchar* name = (activeIndex != 0) ? gtk_combo_box_get_active_text( GTK_COMBO_BOX(self->_profileSel) ) : 0;
+    self->_switchToProfile( name );
+    if ( name ) {
+        g_free( name );
+    }
+}
+#endif // ENABLE_LCMS
+
+#ifdef ENABLE_LCMS
+void ColorICCSelector::_switchToProfile( gchar const* name )
+{
+    bool dirty = false;
+    SPColor tmp( _color );
+
+    if ( name ) {
+        if ( tmp.icc && tmp.icc->colorProfile == name ) {
+#ifdef DEBUG_LCMS
+             g_message("Already at name [%s]", name );
+#endif // DEBUG_LCMS
+        } else {
+#ifdef DEBUG_LCMS
+             g_message("Need to switch to profile [%s]", name );
+#endif // DEBUG_LCMS
+            if ( tmp.icc ) {
+                tmp.icc->colors.clear();
+            } else {
+                tmp.icc = new SVGICCColor();
+            }
+            tmp.icc->colorProfile = name;
+            Inkscape::ColorProfile* newProf = SP_ACTIVE_DOCUMENT->profileManager->find(name);
+            if ( newProf ) {
+                cmsHTRANSFORM trans = newProf->getTransfFromSRGB8();
+                if ( trans ) {
+                    guint32 val = _color.toRGBA32(0);
+                    guchar pre[4] = {
+                        SP_RGBA32_R_U(val),
+                        SP_RGBA32_G_U(val),
+                        SP_RGBA32_B_U(val),
+                        255};
+#ifdef DEBUG_LCMS
+                    g_message("Shoving in [%02x] [%02x] [%02x]", pre[0], pre[1], pre[2]);
+#endif // DEBUG_LCMS
+                    icUInt16Number post[4] = {0,0,0,0};
+                    cmsDoTransform( trans, pre, post, 1 );
+#ifdef DEBUG_LCMS
+                    g_message("got on out [%04x] [%04x] [%04x] [%04x]", post[0], post[1], post[2], post[3]);
+#endif // DEBUG_LCMS
+                    guint count = _cmsChannelsOf( newProf->getColorSpace() );
+
+                    gchar const** names = 0;
+                    gchar const** tips = 0;
+                    guint const* scales = 0;
+                    getThings( newProf->getColorSpace(), names, tips, scales );
+
+                    for ( guint i = 0; i < count; i++ ) {
+                        gdouble val = (((gdouble)post[i])/65535.0) * (gdouble)scales[i];
+#ifdef DEBUG_LCMS
+                        g_message("     scaled %d by %d to be %f", i, scales[i], val);
+#endif // DEBUG_LCMS
+                        tmp.icc->colors.push_back(val);
+                    }
+                    cmsHTRANSFORM retrans = newProf->getTransfToSRGB8();
+                    if ( retrans ) {
+                        cmsDoTransform( retrans, post, pre, 1 );
+#ifdef DEBUG_LCMS
+                        g_message("  back out [%02x] [%02x] [%02x]", pre[0], pre[1], pre[2]);
+#endif // DEBUG_LCMS
+                        tmp.set(SP_RGBA32_U_COMPOSE(pre[0], pre[1], pre[2], 0xff));
+                    }
+                }
+            }
+            dirty = true;
+        }
+    } else {
+#ifdef DEBUG_LCMS
+         g_message("NUKE THE ICC");
+#endif // DEBUG_LCMS
+        if ( tmp.icc ) {
+            delete tmp.icc;
+            tmp.icc = 0;
+            dirty = true;
+            _fixupHit( 0, this );
+        } else {
+#ifdef DEBUG_LCMS
+             g_message("No icc to nuke");
+#endif // DEBUG_LCMS
+        }
+    }
+
+    if ( dirty ) {
+#ifdef DEBUG_LCMS
+        g_message("+----------------");
+        g_message("+   new color is [%s]", tmp.toString().c_str());
+#endif // DEBUG_LCMS
+        _setProfile( tmp.icc );
+        //_adjustmentChanged( _fooAdj[0], SP_COLOR_ICC_SELECTOR(_csel) );
+        setColorAlpha( tmp, _alpha, true );
+#ifdef DEBUG_LCMS
+        g_message("+_________________");
+#endif // DEBUG_LCMS
+    }
+}
+#endif // ENABLE_LCMS
+
+void ColorICCSelector::_profilesChanged( std::string const & name )
+{
+#ifdef ENABLE_LCMS
+    GtkComboBox* combo = GTK_COMBO_BOX(_profileSel);
+
+    g_signal_handler_block( G_OBJECT(_profileSel), _profChangedID );
+
+    GtkTreeModel* model = gtk_combo_box_get_model( combo );
+    GtkTreeIter iter;
+    while ( gtk_tree_model_get_iter_first( model, &iter ) ) {
+        gtk_combo_box_remove_text( combo, 0 );
+    }
+
+    gtk_combo_box_append_text( combo, "<none>");
+
+    gtk_combo_box_set_active( combo, 0 );
+
+    int index = 1;
+    const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" );
+    while ( current ) {
+        SPObject* obj = SP_OBJECT(current->data);
+        Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
+        gtk_combo_box_append_text( combo, prof->name );
+        if ( name == prof->name ) {
+            gtk_combo_box_set_active( combo, index );
+        }
+
+        index++;
+        current = g_slist_next(current);
+    }
+
+    g_signal_handler_unblock( G_OBJECT(_profileSel), _profChangedID );
+#endif // ENABLE_LCMS
+}
+
 /* Helpers for setting color value */
 
-void ColorICCSelector::_colorChanged( const SPColor& color, gfloat alpha )
+void ColorICCSelector::_colorChanged()
 {
     _updating = TRUE;
 //     sp_color_icc_set_color( SP_COLOR_ICC( _icc ), &color );
 
 #ifdef DEBUG_LCMS
     g_message( "/^^^^^^^^^  %p::_colorChanged(%08x:%s)", this,
-               color.toRGBA32(alpha), ( (color.icc) ? color.icc->colorProfile.c_str(): "<null>" )
+               _color.toRGBA32(_alpha), ( (_color.icc) ? _color.icc->colorProfile.c_str(): "<null>" )
                );
 #endif // DEBUG_LCMS
 
 #ifdef DEBUG_LCMS
-    g_message("FLIPPIES!!!!     %p   '%s'", color.icc, (color.icc?color.icc->colorProfile.c_str():"<null>"));
+    g_message("FLIPPIES!!!!     %p   '%s'", _color.icc, (_color.icc ? _color.icc->colorProfile.c_str():"<null>"));
 #endif // DEBUG_LCMS
 
-    ColorScales::setScaled( _adj, alpha );
+    _profilesChanged( (_color.icc) ? _color.icc->colorProfile : std::string("") );
+    ColorScales::setScaled( _adj, _alpha );
 
 #if ENABLE_LCMS
-    _setProfile( color.icc );
-
+    _setProfile( _color.icc );
+    _fixupNeeded = 0;
+    gtk_widget_set_sensitive( _fixupBtn, FALSE );
+
+    if ( _prof && _prof->getTransfToSRGB8() ) {
+        icUInt16Number tmp[4];
+        for ( guint i = 0; i < _profChannelCount; i++ ) {
+            gdouble val = 0.0;
+            if ( _color.icc->colors.size() > i ) {
+                if ( _fooScales[i] == 256 ) {
+                    val = (_color.icc->colors[i] + 128.0) / static_cast<gdouble>(_fooScales[i]);
+                } else {
+                    val = _color.icc->colors[i] / static_cast<gdouble>(_fooScales[i]);
+                }
+            }
+            tmp[i] = val * 0x0ffff;
+        }
+        guchar post[4] = {0,0,0,0};
+        cmsDoTransform( _prof->getTransfToSRGB8(), tmp, post, 1 );
+        guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255 );
+        if ( other != _color.toRGBA32(255) ) {
+            _fixupNeeded = other;
+            gtk_widget_set_sensitive( _fixupBtn, TRUE );
+#ifdef DEBUG_LCMS
+            g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8 );
+#endif // DEBUG_LCMS
+        }
+    }
+#else
+    //(void)color;
 #endif // ENABLE_LCMS
-    _updateSliders();
+    _updateSliders( -1 );
 
 
     _updating = FALSE;
@@ -463,142 +666,103 @@ void ColorICCSelector::_setProfile( SVGICCColor* profile )
                ( (profile) ? profile->colorProfile.c_str() : "<null>")
                );
 #endif // DEBUG_LCMS
+    bool profChanged = false;
     if ( _prof && (!profile || (_profileName != profile->colorProfile) ) ) {
         // Need to clear out the prior one
+        profChanged = true;
         _profileName.clear();
-        _profIntent = Inkscape::RENDERING_INTENT_UNKNOWN;
-        _profileSpace = icSigRgbData;
-        _profileClass = icSigInputClass;
         _prof = 0;
-        if ( _transf ) {
-            cmsDeleteTransform( _transf );
-            _transf = 0;
-        }
-        if ( _destProf ) {
-            cmsCloseProfile( _destProf );
-            _destProf = 0;
-        }
         _profChannelCount = 0;
+    } else if ( profile && !_prof ) {
+        profChanged = true;
+    }
+
+    for ( guint i = 0; i < _fooCount; i++ ) {
+        gtk_widget_hide( _fooLabel[i] );
+        gtk_widget_hide( _fooSlider[i] );
+        gtk_widget_hide( _fooBtn[i] );
     }
 
     if ( profile ) {
-        _prof = Inkscape::colorprofile_get_handle( inkscape_active_document(),//SP_OBJECT_DOCUMENT( object ),
-                                                   &_profIntent,
-                                                   profile->colorProfile.c_str() );
-        if ( _prof ) {
-            _profileSpace = cmsGetColorSpace( _prof );
-            _profileClass = cmsGetDeviceClass( _prof );
-            if ( _profileClass != icSigNamedColorClass ) {
-                int intent = INTENT_PERCEPTUAL;
-                switch ( _profIntent ) {
-                    case Inkscape::RENDERING_INTENT_RELATIVE_COLORIMETRIC:
-                        intent = INTENT_RELATIVE_COLORIMETRIC;
-                        break;
-                    case Inkscape::RENDERING_INTENT_SATURATION:
-                        intent = INTENT_SATURATION;
-                        break;
-                    case Inkscape::RENDERING_INTENT_ABSOLUTE_COLORIMETRIC:
-                        intent = INTENT_ABSOLUTE_COLORIMETRIC;
-                        break;
-                    case Inkscape::RENDERING_INTENT_PERCEPTUAL:
-                    case Inkscape::RENDERING_INTENT_UNKNOWN:
-                    case Inkscape::RENDERING_INTENT_AUTO:
-                    default:
-                        intent = INTENT_PERCEPTUAL;
-                }
-                _destProf = cmsCreate_sRGBProfile();
+        _prof = SP_ACTIVE_DOCUMENT->profileManager->find(profile->colorProfile.c_str());
+        if ( _prof && _prof->getProfileClass() != icSigNamedColorClass ) {
+            _profChannelCount = _cmsChannelsOf( _prof->getColorSpace() );
 
-                _profChannelCount = _cmsChannelsOf( _profileSpace );
+            gchar const** names = 0;
+            gchar const** tips = 0;
+            getThings( _prof->getColorSpace(), names, tips, _fooScales );
 
-                DWORD inputFormat = TYPE_RGB_16;
-                gchar const** names = 0;
-                gchar const** tips = 0;
-                bool const* tricky = 0;
-                getThings( _profileSpace, names, tips, tricky, _fooScales, inputFormat );
+            if ( profChanged ) {
+                for ( guint i = 0; i < _profChannelCount; i++ ) {
+                    gtk_label_set_text_with_mnemonic( GTK_LABEL(_fooLabel[i]), names[i]);
 
-                _transf = cmsCreateTransform( _prof, inputFormat, _destProf, TYPE_RGBA_8, intent, 0 );
-                (void)names;
-                (void)tips;
-                (void)tricky;
+                    gtk_tooltips_set_tip( _tt, _fooSlider[i], tips[i], NULL );
+                    gtk_tooltips_set_tip( _tt, _fooBtn[i], tips[i], NULL );
 
+                    sp_color_slider_set_colors( SP_COLOR_SLIDER(_fooSlider[i]),
+                                                SPColor(0.0, 0.0, 0.0).toRGBA32(0xff),
+                                                SPColor(0.5, 0.5, 0.5).toRGBA32(0xff),
+                                                SPColor(1.0, 1.0, 1.0).toRGBA32(0xff) );
+/*
+                    _fooAdj[i] = GTK_ADJUSTMENT( gtk_adjustment_new( val, 0.0, _fooScales[i],  step, page, page ) );
+                    gtk_signal_connect( GTK_OBJECT( _fooAdj[i] ), "value_changed", GTK_SIGNAL_FUNC( _adjustmentChanged ), _csel );
 
-            } else {
-                // Give up for now on named colors
-                _prof = 0;
+                    sp_color_slider_set_adjustment( SP_COLOR_SLIDER(_fooSlider[i]), _fooAdj[i] );
+                    gtk_spin_button_set_adjustment( GTK_SPIN_BUTTON(_fooBtn[i]), _fooAdj[i] );
+                    gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_fooBtn[i]), digits );
+*/
+                    gtk_widget_show( _fooLabel[i] );
+                    gtk_widget_show( _fooSlider[i] );
+                    gtk_widget_show( _fooBtn[i] );
+                    //gtk_adjustment_set_value( _fooAdj[i], 0.0 );
+                    //gtk_adjustment_set_value( _fooAdj[i], val );
+                }
+                for ( guint i = _profChannelCount; i < _fooCount; i++ ) {
+                    gtk_widget_hide( _fooLabel[i] );
+                    gtk_widget_hide( _fooSlider[i] );
+                    gtk_widget_hide( _fooBtn[i] );
+                }
             }
+        } else {
+            // Give up for now on named colors
+            _prof = 0;
         }
     }
+
 #ifdef DEBUG_LCMS
     g_message( "\\_________  %p::_setProfile()", this );
 #endif // DEBUG_LCMS
 }
 #endif // ENABLE_LCMS
 
-void ColorICCSelector::_updateSliders()
+void ColorICCSelector::_updateSliders( gint ignore )
 {
 #ifdef ENABLE_LCMS
     if ( _color.icc )
     {
-        DWORD inputFormat = TYPE_RGB_16;
-        gchar const** names = 0;
-        gchar const** tips = 0;
-        bool const* tricky = 0;
-        getThings( _profileSpace, names, tips, tricky, _fooScales, inputFormat );
-
-        for ( guint i = 0; i < _fooCount; i++ ) {
-            gtk_label_set_text_with_mnemonic( GTK_LABEL(_fooLabel[i]), names[i]);
-
-            gtk_tooltips_set_tip( _tt, _fooSlider[i], tips[i], NULL );
-            gtk_tooltips_set_tip( _tt, _fooBtn[i], tips[i], NULL );
-
-            sp_color_slider_set_colors( SP_COLOR_SLIDER(_fooSlider[i]),
-                                        SPColor(0.0, 0.0, 0.0).toRGBA32(0xff),
-                                        SPColor(0.5, 0.5, 0.5).toRGBA32(0xff),
-                                        SPColor(1.0, 1.0, 1.0).toRGBA32(0xff) );
-
-            if ( i < _profChannelCount ) {
-/*
-                gdouble step = static_cast<gdouble>(_fooScales[i]) / 100.0;
-                gdouble page = static_cast<gdouble>(_fooScales[i]) / 10.0;
-                gint digits = (step > 0.9) ? 0 : 2;
-*/
-                gdouble val = (_color.icc->colors.size() > i) ? (_color.icc->colors[i] / static_cast<gdouble>(_fooScales[i])) : 0.0;
-
-/*
-                _fooAdj[i] = GTK_ADJUSTMENT( gtk_adjustment_new( val, 0.0, _fooScales[i],  step, page, page ) );
-                gtk_signal_connect( GTK_OBJECT( _fooAdj[i] ), "value_changed", GTK_SIGNAL_FUNC( _adjustmentChanged ), _csel );
-
-                sp_color_slider_set_adjustment( SP_COLOR_SLIDER(_fooSlider[i]), _fooAdj[i] );
-                gtk_spin_button_set_adjustment( GTK_SPIN_BUTTON(_fooBtn[i]), _fooAdj[i] );
-                gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_fooBtn[i]), digits );
-*/
-                gtk_widget_show( _fooLabel[i] );
-                gtk_widget_show( _fooSlider[i] );
-                gtk_widget_show( _fooBtn[i] );
-                gtk_adjustment_set_value( _fooAdj[i], val );
-            } else {
-                gtk_widget_hide( _fooLabel[i] );
-                gtk_widget_hide( _fooSlider[i] );
-                gtk_widget_hide( _fooBtn[i] );
-                gtk_adjustment_set_value( _fooAdj[i], 0.0 );
+        for ( guint i = 0; i < _profChannelCount; i++ ) {
+            gdouble val = 0.0;
+            if ( _color.icc->colors.size() > i ) {
+                if ( _fooScales[i] == 256 ) {
+                    val = (_color.icc->colors[i] + 128.0) / static_cast<gdouble>(_fooScales[i]);
+                } else {
+                    val = _color.icc->colors[i] / static_cast<gdouble>(_fooScales[i]);
+                }
             }
-
+            gtk_adjustment_set_value( _fooAdj[i], val );
         }
 
-        if ( _transf ) {
+        if ( _prof->getTransfToSRGB8() ) {
             for ( guint i = 0; i < _profChannelCount; i++ ) {
-                if ( tricky[i] ) {
+                if ( static_cast<gint>(i) != ignore ) {
                     icUInt16Number* scratch = getScratch();
                     icUInt16Number filler[4] = {0, 0, 0, 0};
                     for ( guint j = 0; j < _profChannelCount; j++ ) {
-                        filler[j] = 0x0ffff * ColorScales::getScaled( _fooAdj[i] );
+                        filler[j] = 0x0ffff * ColorScales::getScaled( _fooAdj[j] );
                     }
 
                     icUInt16Number* p = scratch;
                     for ( guint x = 0; x < 1024; x++ ) {
-                        if ( _profileSpace == icSigLabData && (i == 1 || i == 2) ) {
-                            p = scratch + 3 * ( (x + 512) % 1024);
-                        }
                         for ( guint j = 0; j < _profChannelCount; j++ ) {
                             if ( j == i ) {
                                 *p++ = x * 0x0ffff / 1024;
@@ -608,38 +772,14 @@ void ColorICCSelector::_updateSliders()
                         }
                     }
 
-                    cmsDoTransform( _transf, scratch, _fooMap[i], 1024 );
+                    cmsDoTransform( _prof->getTransfToSRGB8(), scratch, _fooMap[i], 1024 );
                     sp_color_slider_set_map( SP_COLOR_SLIDER(_fooSlider[i]), _fooMap[i] );
-                } else {
-                    icUInt16Number tmp[4];
-                    for ( guint j = 0; j < _profChannelCount; j++ ) {
-                        tmp[j] = ColorScales::getScaled( _fooAdj[j] ) * 0x0ffff;
-                    }
-                    tmp[i] = 0;
-                    guchar post[4] = {0,0,0,0};
-                    cmsDoTransform( _transf, tmp, post, 1 );
-                    guint32 lowColor = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255);
-
-                    tmp[i] = 0x0ffff/2;
-                    cmsDoTransform( _transf, tmp, post, 1 );
-                    guint32 midColor = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255);
-
-                    tmp[i] = 0x0ffff;
-                    cmsDoTransform( _transf, tmp, post, 1 );
-                    guint32 highColor = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255);
-
-                    sp_color_slider_set_colors( SP_COLOR_SLIDER(_fooSlider[i]), lowColor, midColor, highColor );
                 }
             }
         }
-    } else {
-        for ( guint i = 0; i < _fooCount; i++ ) {
-            gtk_widget_hide( _fooLabel[i] );
-            gtk_widget_hide( _fooSlider[i] );
-            gtk_widget_hide( _fooBtn[i] );
-            gtk_adjustment_set_value( _fooAdj[i], 0.0 );
-        }
     }
+#else
+    (void)ignore;
 #endif // ENABLE_LCMS
 
     guint32 start = _color.toRGBA32( 0x00 );
@@ -670,6 +810,8 @@ void ColorICCSelector::_adjustmentChanged( GtkAdjustment *adjustment, SPColorICC
 
      iccSelector->_updating = TRUE;
 
+     gint match = -1;
+
      SPColor newColor( iccSelector->_color );
      gfloat scaled = ColorScales::getScaled( iccSelector->_adj );
      if ( iccSelector->_adj == adjustment ) {
@@ -677,7 +819,7 @@ void ColorICCSelector::_adjustmentChanged( GtkAdjustment *adjustment, SPColorICC
          g_message("ALPHA");
 #endif // DEBUG_LCMS
      } else {
-         gint match = -1;
+#if ENABLE_LCMS
          for ( guint i = 0; i < iccSelector->_fooCount; i++ ) {
              if ( iccSelector->_fooAdj[i] == adjustment ) {
                  match = i;
@@ -697,7 +839,7 @@ void ColorICCSelector::_adjustmentChanged( GtkAdjustment *adjustment, SPColorICC
          }
          guchar post[4] = {0,0,0,0};
 
-         cmsDoTransform( iccSelector->_transf, tmp, post, 1 );
+         cmsDoTransform( iccSelector->_prof->getTransfToSRGB8(), tmp, post, 1 );
 
          SPColor other( SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255) );
          other.icc = new SVGICCColor();
@@ -719,14 +861,17 @@ void ColorICCSelector::_adjustmentChanged( GtkAdjustment *adjustment, SPColorICC
                  gdouble val = ColorScales::getScaled( iccSelector->_fooAdj[i] );
                  if ( iccSelector->_fooScales ) {
                      val *= iccSelector->_fooScales[i];
+                     if ( iccSelector->_fooScales[i] == 256 ) {
+                         val -= 128;
+                     }
                  }
                  newColor.icc->colors.push_back( val );
              }
          }
-
+#endif // ENABLE_LCMS
      }
      iccSelector->_updateInternals( newColor, scaled, iccSelector->_dragging );
-     iccSelector->_updateSliders();
+     iccSelector->_updateSliders( match );
 
      iccSelector->_updating = FALSE;
 #ifdef DEBUG_LCMS
@@ -734,10 +879,8 @@ void ColorICCSelector::_adjustmentChanged( GtkAdjustment *adjustment, SPColorICC
 #endif // DEBUG_LCMS
 }
 
-void ColorICCSelector::_sliderGrabbed( SPColorSlider *slider, SPColorICCSelector *cs )
+void ColorICCSelector::_sliderGrabbed( SPColorSlider */*slider*/, SPColorICCSelector */*cs*/ )
 {
-    (void)slider;
-    (void)cs;
 //    ColorICCSelector* iccSelector = (ColorICCSelector*)(SP_COLOR_SELECTOR(cs)->base);
 //     if (!iccSelector->_dragging) {
 //         iccSelector->_dragging = TRUE;
@@ -746,10 +889,8 @@ void ColorICCSelector::_sliderGrabbed( SPColorSlider *slider, SPColorICCSelector
 //     }
 }
 
-void ColorICCSelector::_sliderReleased( SPColorSlider *slider, SPColorICCSelector *cs )
+void ColorICCSelector::_sliderReleased( SPColorSlider */*slider*/, SPColorICCSelector */*cs*/ )
 {
-    (void)slider;
-    (void)cs;
 //     ColorICCSelector* iccSelector = (ColorICCSelector*)(SP_COLOR_SELECTOR(cs)->base);
 //     if (iccSelector->_dragging) {
 //         iccSelector->_dragging = FALSE;
@@ -758,10 +899,12 @@ void ColorICCSelector::_sliderReleased( SPColorSlider *slider, SPColorICCSelecto
 //     }
 }
 
+#ifdef DEBUG_LCMS
 void ColorICCSelector::_sliderChanged( SPColorSlider *slider, SPColorICCSelector *cs )
+#else
+void ColorICCSelector::_sliderChanged( SPColorSlider */*slider*/, SPColorICCSelector */*cs*/ )
+#endif // DEBUG_LCMS
 {
-    (void)slider;
-    (void)cs;
 #ifdef DEBUG_LCMS
     g_message("Changed  %p and %p", slider, cs );
 #endif // DEBUG_LCMS