Code

Added display profile calibration
authorjoncruz <joncruz@users.sourceforge.net>
Wed, 26 Sep 2007 03:58:51 +0000 (03:58 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Wed, 26 Sep 2007 03:58:51 +0000 (03:58 +0000)
src/color-profile-fns.h
src/color-profile.cpp
src/display/sp-canvas.cpp
src/preferences-skeleton.h
src/ui/dialog/inkscape-preferences.cpp
src/ui/dialog/inkscape-preferences.h

index 89dcfa8f9ae701e4ad304cec16e3bbe1d30a93ce..21e6002ee58a812915acf8d0fa0541a0e043044c 100644 (file)
@@ -27,6 +27,8 @@ GType colorprofile_get_type();
 
 cmsHPROFILE colorprofile_get_handle( SPDocument* document, guint* intent, gchar const* name );
 
+cmsHPROFILE colorprofile_get_system_profile_handle();
+
 #endif
 
 } // namespace Inkscape
index a11aba6c4bf51bf59e3a511a946e38dcf86467bc..5c5303e08355a8e515e541a0a453d289da598122 100644 (file)
@@ -6,13 +6,13 @@
 #include "attributes.h"
 #include "inkscape.h"
 #include "document.h"
+#include "prefs-utils.h"
 
 #include "dom/uri.h"
 
 //#define DEBUG_LCMS
 
 #ifdef DEBUG_LCMS
-#include "prefs-utils.h"
 #include <gtk/gtkmessagedialog.h>
 #endif // DEBUG_LCMS
 
@@ -367,6 +367,36 @@ cmsHPROFILE Inkscape::colorprofile_get_handle( SPDocument* document, guint* inte
 
     return prof;
 }
+
+
+
+cmsHPROFILE Inkscape::colorprofile_get_system_profile_handle()
+{
+    static cmsHPROFILE theOne = 0;
+    static std::string lastURI;
+
+    long long int which = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 );
+    gchar const * uri = prefs_get_string_attribute("options.displayprofile", "uri");
+
+    if ( which && uri ) {
+        if ( lastURI != std::string(uri) ) {
+            if ( theOne ) {
+                cmsCloseProfile( theOne );
+            }
+            theOne = cmsOpenProfileFromFile( uri, "r" );
+            if ( theOne ) {
+                lastURI = uri;
+            }
+        }
+    } else if ( theOne ) {
+        cmsCloseProfile( theOne );
+        theOne = 0;
+        lastURI.clear();
+    }
+
+    return theOne;
+}
+
 #endif // ENABLE_LCMS
 
 /*
index 57a6ac269b4e84a089ff6cf5a70002c7e37bd6d6..1714bd454e246abcff32c90af93be9f9536588a0 100644 (file)
@@ -37,6 +37,9 @@
 #include "box3d-context.h"
 #include "inkscape.h"
 #include "sodipodi-ctrlrect.h"
+#if ENABLE_LCMS
+#include "color-profile-fns.h"
+#endif // ENABLE_LCMS
 
 // Define this to visualize the regions to be redrawn
 //#define DEBUG_REDRAW 1;
@@ -1579,12 +1582,23 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
                     | (color->green & 0xff00)
                     | (color->blue >> 8));
     buf.is_empty = true;
-      
+
     if (canvas->root->flags & SP_CANVAS_ITEM_VISIBLE) {
         SP_CANVAS_ITEM_GET_CLASS (canvas->root)->render (canvas->root, &buf);
     }
-      
+
+#if ENABLE_LCMS
+        cmsHPROFILE hprof = Inkscape::colorprofile_get_system_profile_handle();
+        cmsHPROFILE srcprof = hprof ? cmsCreate_sRGBProfile() : 0;
+        cmsHTRANSFORM transf = hprof ? cmsCreateTransform( srcprof, TYPE_RGB_8, hprof, TYPE_RGB_8, INTENT_PERCEPTUAL, 0 ) : 0;
+#endif // ENABLE_LCMS
+
     if (buf.is_empty) {
+#if ENABLE_LCMS
+        if ( transf ) {
+            cmsDoTransform( transf, &buf.bg_color, &buf.bg_color, 1 );
+        }
+#endif // ENABLE_LCMS
         gdk_rgb_gc_set_foreground (canvas->pixmap_gc, buf.bg_color);
         gdk_draw_rectangle (SP_CANVAS_WINDOW (canvas),
                             canvas->pixmap_gc,
@@ -1614,6 +1628,15 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
     cairo_surface_destroy (cst);
 */
 
+#if ENABLE_LCMS
+        if ( transf ) {
+            for ( gint yy = 0; yy < (y1 - y0); yy++ ) {
+                guchar* p = buf.buf + (sw * 3) * yy;
+                cmsDoTransform( transf, p, p, (x1 - x0) );
+            }
+        }
+#endif // ENABLE_LCMS
+
         gdk_draw_rgb_image_dithalign (SP_CANVAS_WINDOW (canvas),
                                       canvas->pixmap_gc,
                                       x0 - canvas->x0, y0 - canvas->y0,
@@ -1624,6 +1647,14 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1,
                                       x0 - canvas->x0, y0 - canvas->y0);
     }
 
+#if ENABLE_LCMS
+    if ( transf ) {
+        cmsDeleteTransform( transf );
+        transf = 0;
+    }
+#endif // ENABLE_LCMS
+
+
     if (canvas->rendermode != RENDERMODE_OUTLINE) {
         nr_pixelstore_256K_free (buf.buf);
     } else {
index dad2738cd0b0b04931df2b7ec054ed77e9c92a39..137b3f8a2937275fc06e8cbb2af91e90113cc7f0 100644 (file)
@@ -181,6 +181,10 @@ static char const preferences_skeleton[] =
 "    <group id=\"rotationsnapsperpi\" value=\"12\"/>\n"
 "    <group id=\"cursortolerance\" value=\"8.0\"/>\n"
 "    <group id=\"dragtolerance\" value=\"4.0\"/>\n"
+"    <group\n"
+"       id=\"displayprofile\""
+"       enable=\"0\"\n"
+"       uri=\"\" />\n"
 "    <group id=\"savewindowgeometry\" value=\"1\"/>\n"
 "    <group id=\"defaultoffsetwidth\" value=\"2\"/>\n"
 "    <group id=\"defaultscale\" value=\"2\"/>\n"
index 138f36c2992cdd84b358c1b74427de1e1b3ea312..7ee381bffbef91c7e85ff2769d0d4f1c8c7b6529 100644 (file)
@@ -627,14 +627,40 @@ void InkscapePreferences::initPageImportExport()
     this->AddPage(_page_importexport, _("Import/Export"), PREFS_PAGE_IMPORTEXPORT);
 }
 
+#if ENABLE_LCMS
+static void forceUpdates() {
+    std::list<SPDesktop*> tops;
+    inkscape_get_all_desktops( tops );
+    for ( std::list<SPDesktop*>::iterator it = tops.begin(); it != tops.end(); ++it ) {
+        (*it)->requestRedraw();
+    }
+}
+#endif // ENABLE_LCMS
+
 void InkscapePreferences::initPageMisc()
 {
     _misc_comment.init( _("Add label comments to printing output"), "printing.debug", "show-label-comments", false);
     _page_misc.add_line( false, "", _misc_comment, "", 
                            _("When on, a comment will be added to the raw print output, marking the rendered output for an object with its label"), true);
+
     _misc_small_toolbar.init( _("Make commands toolbar smaller"), "toolbox", "small", true);
     _page_misc.add_line( false, "", _misc_small_toolbar, "",
                            _("Make the commands toolbar use the 'secondary' toolbar size (requires restart)"), true);
+
+    _misc_cms_display.init( _("Enable display calibration"), "options.displayprofile", "enable", false);
+    _page_misc.add_line( false, "", _misc_cms_display, "",
+                           _("Enables application of the display using an ICC profile."), true);
+    _misc_cms_display_profile.init("options.displayprofile", "uri", true);
+    _page_misc.add_line( false, _("Display profile:"), _misc_cms_display_profile, "",
+            _("The ICC profile to use to calibrate display output."), true);
+#if ENABLE_LCMS
+    _misc_cms_display.signal_toggled().connect( sigc::ptr_fun(forceUpdates) );
+#else
+    // disable it, but leave it visible
+    _misc_cms_display.set_sensitive( false );
+    _misc_cms_display_profile.set_sensitive( false );
+#endif // ENABLE_LCMS
+
     _misc_recent.init("options.maxrecentdocuments", "value", 0.0, 1000.0, 1.0, 1.0, 1.0, true, false);
     _page_misc.add_line( false, _("Max recent documents:"), _misc_recent, "", 
                            _("The maximum length of the Open Recent list in the File menu"), false);
index 6798de21d40e9f8f5649fc5951a84e9bd2109582..03ed72f638a40ef04c8627feef49e104931628ae 100644 (file)
@@ -161,6 +161,10 @@ protected:
     PrefCheckButton _importexport_imp_bitmap, _misc_comment, _misc_scripts;
     PrefCheckButton _misc_small_toolbar;
     PrefCombo       _misc_overs_bitmap;
+
+    PrefCheckButton _misc_cms_display;
+    PrefEntry       _misc_cms_display_profile;
+
     PrefEntryButtonHBox _importexport_ocal_url;
     PrefEntry       _importexport_ocal_username;
     PrefEntry       _importexport_ocal_password;