From 1d1fdab9933218f4d59b390ac74392fbc2caaf7b Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 17 Oct 2010 23:37:36 -0700 Subject: Unified and cleaned up locating icc profiles, including adding missing OS X location. Fixes bug 494932, bug 494940 and bug 551162. Fixed bugs: - https://launchpad.net/bugs/494932 - https://launchpad.net/bugs/494940 - https://launchpad.net/bugs/551162 (bzr r9834) --- src/color-profile.cpp | 147 +++++++++++++++++++++++++++++++------------------- 1 file changed, 92 insertions(+), 55 deletions(-) (limited to 'src/color-profile.cpp') diff --git a/src/color-profile.cpp b/src/color-profile.cpp index a8238556c..1352e4e14 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef DEBUG_LCMS #include @@ -630,7 +631,14 @@ Glib::ustring Inkscape::get_path_for_profile(Glib::ustring const& name) } #endif // ENABLE_LCMS -std::list ColorProfile::getProfileDirs() { +std::list ColorProfile::getBaseProfileDirs() { +#if ENABLE_LCMS + static bool warnSet = false; + if (!warnSet) { + cmsErrorAction( LCMS_ERROR_SHOW ); + warnSet = true; + } +#endif // ENABLE_LCMS std::list sources; gchar* base = profile_path("XXX"); @@ -655,17 +663,26 @@ std::list ColorProfile::getProfileDirs() { } // On OS X: - if ( g_file_test("/Library/ColorSync/Profiles", G_FILE_TEST_EXISTS) && g_file_test("/Library/ColorSync/Profiles", G_FILE_TEST_IS_DIR) ) { - sources.push_back("/Library/ColorSync/Profiles"); - - gchar* path = g_build_filename(g_get_home_dir(), "Library", "ColorSync", "Profiles", NULL); - if ( g_file_test(path, G_FILE_TEST_EXISTS) && g_file_test(path, G_FILE_TEST_IS_DIR) ) { - sources.push_back(path); + { + bool onOSX = false; + std::list possible; + possible.push_back("/System/Library/ColorSync/Profiles"); + possible.push_back("/Library/ColorSync/Profiles"); + for ( std::list::const_iterator it = possible.begin(); it != possible.end(); ++it ) { + if ( g_file_test(it->c_str(), G_FILE_TEST_EXISTS) && g_file_test(it->c_str(), G_FILE_TEST_IS_DIR) ) { + sources.push_back(it->c_str()); + onOSX = true; + } + } + if ( onOSX ) { + gchar* path = g_build_filename(g_get_home_dir(), "Library", "ColorSync", "Profiles", NULL); + if ( g_file_test(path, G_FILE_TEST_EXISTS) && g_file_test(path, G_FILE_TEST_IS_DIR) ) { + sources.push_back(path); + } + g_free(path); } - g_free(path); } - #ifdef WIN32 wchar_t pathBuf[MAX_PATH + 1]; pathBuf[0] = 0; @@ -685,10 +702,38 @@ std::list ColorProfile::getProfileDirs() { return sources; } -#if ENABLE_LCMS -static void findThings() { - std::list sources = ColorProfile::getProfileDirs(); +static bool isIccFile( gchar const *filepath ) +{ + bool isIccFile = false; + struct stat st; + if ( g_stat(filepath, &st) == 0 && (st.st_size > 128) ) { + //0-3 == size + //36-39 == 'acsp' 0x61637370 + int fd = g_open( filepath, O_RDONLY, S_IRWXU); + if ( fd != -1 ) { + guchar scratch[40] = {0}; + size_t len = sizeof(scratch); + + //size_t left = 40; + ssize_t got = read(fd, scratch, len); + if ( got != -1 ) { + size_t calcSize = (scratch[0] << 24) | (scratch[1] << 16) | (scratch[2] << 8) | scratch[3]; + if ( calcSize > 128 && calcSize <= static_cast(st.st_size) ) { + isIccFile = (scratch[36] == 'a') && (scratch[37] == 'c') && (scratch[38] == 's') && (scratch[39] == 'p'); + } + } + + close(fd); + } + } + return isIccFile; +} +std::list ColorProfile::getProfileFiles() +{ + std::list files; + + std::list sources = ColorProfile::getBaseProfileDirs(); for ( std::list::const_iterator it = sources.begin(); it != sources.end(); ++it ) { if ( g_file_test( it->c_str(), G_FILE_TEST_EXISTS ) && g_file_test( it->c_str(), G_FILE_TEST_IS_DIR ) ) { GError *err = 0; @@ -697,57 +742,49 @@ static void findThings() { if (dir) { for (gchar const *file = g_dir_read_name(dir); file != NULL; file = g_dir_read_name(dir)) { gchar *filepath = g_build_filename(it->c_str(), file, NULL); - - if ( g_file_test( filepath, G_FILE_TEST_IS_DIR ) ) { sources.push_back(g_strdup(filepath)); } else { - bool isIccFile = false; - struct stat st; - if ( g_stat(filepath, &st) == 0 && (st.st_size > 128) ) { - //0-3 == size - //36-39 == 'acsp' 0x61637370 - int fd = g_open( filepath, O_RDONLY, S_IRWXU); - if ( fd != -1 ) { - guchar scratch[40] = {0}; - size_t len = sizeof(scratch); - - //size_t left = 40; - ssize_t got = read(fd, scratch, len); - if ( got != -1 ) { - size_t calcSize = (scratch[0] << 24) | (scratch[1] << 16) | (scratch[2] << 8) | scratch[3]; - if ( calcSize > 128 && calcSize <= static_cast(st.st_size) ) { - isIccFile = (scratch[36] == 'a') && (scratch[37] == 'c') && (scratch[38] == 's') && (scratch[39] == 'p'); - } - } - - close(fd); - } - } - - if ( isIccFile ) { - cmsHPROFILE prof = cmsOpenProfileFromFile( filepath, "r" ); - if ( prof ) { - ProfileInfo info( prof, Glib::filename_to_utf8( filepath ) ); - cmsCloseProfile( prof ); - - bool sameName = false; - for ( std::vector::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) { - if ( it->getName() == info.getName() ) { - sameName = true; - break; - } - } - - if ( !sameName ) { - knownProfiles.push_back(info); - } - } + if ( isIccFile( filepath ) ) { + files.push_back( filepath ); } } g_free(filepath); } + g_dir_close(dir); + dir = 0; + } else { + gchar *safeDir = Inkscape::IO::sanitizeString(it->c_str()); + g_warning(_("Color profiles directory (%s) is unavailable."), safeDir); + g_free(safeDir); + } + } + } + + return files; +} + +#if ENABLE_LCMS +static void findThings() { + std::list files = ColorProfile::getProfileFiles(); + + for ( std::list::const_iterator it = files.begin(); it != files.end(); ++it ) { + cmsHPROFILE prof = cmsOpenProfileFromFile( it->c_str(), "r" ); + if ( prof ) { + ProfileInfo info( prof, Glib::filename_to_utf8( it->c_str() ) ); + cmsCloseProfile( prof ); + + bool sameName = false; + for ( std::vector::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) { + if ( it->getName() == info.getName() ) { + sameName = true; + break; + } + } + + if ( !sameName ) { + knownProfiles.push_back(info); } } } -- cgit v1.2.3 From 993a9ffee4f0c47c254ebe13e8ada07338587735 Mon Sep 17 00:00:00 2001 From: Marcin Floryan Date: Sun, 14 Nov 2010 17:20:59 +0000 Subject: Fixed include to ensure file compiles with lcms disabled (bzr r9892) --- src/color-profile.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/color-profile.cpp') diff --git a/src/color-profile.cpp b/src/color-profile.cpp index 1352e4e14..c42cd42ea 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -15,6 +15,7 @@ #include #include +#include #ifdef WIN32 #ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. Required for correctly including icm.h @@ -557,9 +558,6 @@ bool ColorProfile::GamutCheck(SPColor color){ return (outofgamut == 255); } - -#include - class ProfileInfo { public: -- cgit v1.2.3 From 144819c918dc761641c3cb5a490205fb73194ee3 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Wed, 17 Nov 2010 13:12:56 +1100 Subject: Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in all 1074 Vim modelines. The reason for this is that (a) setting the encoding isn't nice, and (b) Vim 7.3 (with modeline enabled) disallows it and pops up an error whenever you open any file with it ("invalid modeline"). Also corrected five deviant modestrings: * src/ui/widget/dock.cpp and src/ui/widget/dock.h: missing colon at the end * src/ui/dialog/tile.cpp: removed gratuitous second colon at the end * src/helper/units-test.h: removed gratuitous space before a colon * share/extensions/export_gimp_palette.py: missing textwidth=99 That's my geekiest commit yet. (bzr r9900) --- src/color-profile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/color-profile.cpp') diff --git a/src/color-profile.cpp b/src/color-profile.cpp index c42cd42ea..1189a7c29 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -1180,4 +1180,4 @@ cmsHTRANSFORM Inkscape::colorprofile_get_display_per( Glib::ustring const& id ) fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3