From 1dec520cc2d39cea31661d4a8fa1cad67facb255 Mon Sep 17 00:00:00 2001 From: joncruz Date: Wed, 26 Sep 2007 03:58:51 +0000 Subject: [PATCH] Added display profile calibration --- src/color-profile-fns.h | 2 ++ src/color-profile.cpp | 32 ++++++++++++++++++++++- src/display/sp-canvas.cpp | 35 ++++++++++++++++++++++++-- src/preferences-skeleton.h | 4 +++ src/ui/dialog/inkscape-preferences.cpp | 26 +++++++++++++++++++ src/ui/dialog/inkscape-preferences.h | 4 +++ 6 files changed, 100 insertions(+), 3 deletions(-) diff --git a/src/color-profile-fns.h b/src/color-profile-fns.h index 89dcfa8f9..21e6002ee 100644 --- a/src/color-profile-fns.h +++ b/src/color-profile-fns.h @@ -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 diff --git a/src/color-profile.cpp b/src/color-profile.cpp index a11aba6c4..5c5303e08 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -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 #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 /* diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 57a6ac269..1714bd454 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -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 { diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index dad2738cd..137b3f8a2 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -181,6 +181,10 @@ static char const preferences_skeleton[] = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 138f36c29..7ee381bff 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -627,14 +627,40 @@ void InkscapePreferences::initPageImportExport() this->AddPage(_page_importexport, _("Import/Export"), PREFS_PAGE_IMPORTEXPORT); } +#if ENABLE_LCMS +static void forceUpdates() { + std::list tops; + inkscape_get_all_desktops( tops ); + for ( std::list::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); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 6798de21d..03ed72f63 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -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; -- 2.30.2