~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/color-profile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "attributes.h"
19
19
#include "inkscape.h"
20
20
#include "document.h"
21
 
#include "prefs-utils.h"
 
21
#include "preferences.h"
22
22
 
23
23
#include "dom/uri.h"
24
24
#include "dom/util/digest.h"
38
38
extern guint update_in_progress;
39
39
#define DEBUG_MESSAGE(key, ...) \
40
40
{\
41
 
    gint dump = prefs_get_int_attribute_limited("options.scislac", #key, 0, 0, 1);\
42
 
    gint dumpD = prefs_get_int_attribute_limited("options.scislac", #key"D", 0, 0, 1);\
43
 
    gint dumpD2 = prefs_get_int_attribute_limited("options.scislac", #key"D2", 0, 0, 1);\
 
41
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();\
 
42
    bool dump = prefs->getBool(Glib::ustring("/options/scislac/") + #key);\
 
43
    bool dumpD = prefs->getBool(Glib::ustring("/options/scislac/") + #key"D");\
 
44
    bool dumpD2 = prefs->getBool(Glib::ustring("/options/scislac/") + #key"D2");\
44
45
    dumpD &= ( (update_in_progress == 0) || dumpD2 );\
45
46
    if ( dump )\
46
47
    {\
253
254
                    //# 1.  Get complete URI of document
254
255
                    gchar const *docbase = SP_DOCUMENT_URI( doc );
255
256
                    if (!docbase)
256
 
                        {
257
 
                        g_warning("null docbase");
 
257
                    {
 
258
                        // Normal for files that have not yet been saved.
258
259
                        docbase = "";
259
 
                        }
 
260
                    }
260
261
                    //g_message("docbase:%s\n", docbase);
261
262
                    org::w3c::dom::URI docUri(docbase);
262
263
                    //# 2. Get href of icc file.  we don't care if it's rel or abs
264
265
                    //# 3.  Resolve the href according the docBase.  This follows
265
266
                    //      the w3c specs.  All absolute and relative issues are considered
266
267
                    org::w3c::dom::URI cprofUri = docUri.resolve(hrefUri);
267
 
                    gchar* fullname = (gchar *)cprofUri.getNativePath().c_str();
 
268
                    gchar* fullname = g_strdup((gchar *)cprofUri.getNativePath().c_str());
268
269
                    cprof->_clearProfile();
269
270
                    cprof->profHandle = cmsOpenProfileFromFile( fullname, "r" );
270
271
                    if ( cprof->profHandle ) {
274
275
#ifdef DEBUG_LCMS
275
276
                    DEBUG_MESSAGE( lcmsOne, "cmsOpenProfileFromFile( '%s'...) = %p", fullname, (void*)cprof->profHandle );
276
277
#endif // DEBUG_LCMS
277
 
 
 
278
                    g_free(fullname);
278
279
#endif // ENABLE_LCMS
279
280
                }
280
281
            }
342
343
/**
343
344
 * Callback: write attributes to associated repr.
344
345
 */
345
 
Inkscape::XML::Node* ColorProfile::write( SPObject *object, Inkscape::XML::Node *repr, guint flags )
 
346
Inkscape::XML::Node* ColorProfile::write( SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags )
346
347
{
347
348
    ColorProfile *cprof = COLORPROFILE(object);
348
349
 
349
350
    if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
350
 
        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
351
351
        repr = xml_doc->createElement("svg:color-profile");
352
352
    }
353
353
 
368
368
    }
369
369
 
370
370
    if (cprof_parent_class->write) {
371
 
        (* cprof_parent_class->write)(object, repr, flags);
 
371
        (* cprof_parent_class->write)(object, xml_doc, repr, flags);
372
372
    }
373
373
 
374
374
    return repr;
561
561
 
562
562
    return result;
563
563
}
 
564
#endif // ENABLE_LCMS
564
565
 
565
 
static void findThings() {
566
 
    std::list<gchar *> sources;
 
566
std::list<Glib::ustring> ColorProfile::getProfileDirs() {
 
567
    std::list<Glib::ustring> sources;
567
568
 
568
569
    gchar* base = profile_path("XXX");
569
570
    {
584
585
        sources.push_back(g_build_filename(dataDirs[i], "color", "icc", NULL));
585
586
    }
586
587
 
587
 
    while (!sources.empty()) {
588
 
        gchar *dirname = sources.front();
589
 
        if ( g_file_test( dirname, G_FILE_TEST_EXISTS ) && g_file_test( dirname, G_FILE_TEST_IS_DIR ) ) {
 
588
    return sources;
 
589
}
 
590
 
 
591
#if ENABLE_LCMS
 
592
static void findThings() {
 
593
    std::list<Glib::ustring> sources = ColorProfile::getProfileDirs();
 
594
 
 
595
    for ( std::list<Glib::ustring>::const_iterator it = sources.begin(); it != sources.end(); ++it ) {
 
596
        if ( g_file_test( it->c_str(), G_FILE_TEST_EXISTS ) && g_file_test( it->c_str(), G_FILE_TEST_IS_DIR ) ) {
590
597
            GError *err = 0;
591
 
            GDir *dir = g_dir_open(dirname, 0, &err);
 
598
            GDir *dir = g_dir_open(it->c_str(), 0, &err);
592
599
 
593
600
            if (dir) {
594
601
                for (gchar const *file = g_dir_read_name(dir); file != NULL; file = g_dir_read_name(dir)) {
595
 
                    gchar *filepath = g_build_filename(dirname, file, NULL);
 
602
                    gchar *filepath = g_build_filename(it->c_str(), file, NULL);
596
603
 
597
604
 
598
605
                    if ( g_file_test( filepath, G_FILE_TEST_IS_DIR ) ) {
612
619
                                ssize_t got = read(fd, scratch, len);
613
620
                                if ( got != -1 ) {
614
621
                                    size_t calcSize = (scratch[0] << 24) | (scratch[1] << 16) | (scratch[2] << 8) | scratch[3];
615
 
                                    if ( calcSize > 128 && calcSize <= st.st_size ) {
 
622
                                    if ( calcSize > 128 && calcSize <= static_cast<size_t>(st.st_size) ) {
616
623
                                        isIccFile = (scratch[36] == 'a') && (scratch[37] == 'c') && (scratch[38] == 's') && (scratch[39] == 'p');
617
624
                                    }
618
625
                                }
646
653
                }
647
654
            }
648
655
        }
649
 
 
650
 
        // toss the dirname
651
 
        g_free(dirname);
652
 
        sources.pop_front();
653
656
    }
654
657
}
655
658
 
673
676
cmsHPROFILE Inkscape::colorprofile_get_system_profile_handle()
674
677
{
675
678
    static cmsHPROFILE theOne = 0;
676
 
    static std::string lastURI;
 
679
    static Glib::ustring lastURI;
677
680
 
678
681
    static bool init = false;
679
682
    if ( !init ) {
683
686
        init = true;
684
687
    }
685
688
 
686
 
    gchar const * uri = prefs_get_string_attribute("options.displayprofile", "uri");
 
689
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
690
    Glib::ustring uri = prefs->getString("/options/displayprofile/uri");
687
691
 
688
 
    if ( uri && *uri ) {
689
 
        if ( lastURI != std::string(uri) ) {
 
692
    if ( !uri.empty() ) {
 
693
        if ( uri != lastURI ) {
690
694
            lastURI.clear();
691
695
            if ( theOne ) {
692
696
                cmsCloseProfile( theOne );
695
699
                cmsDeleteTransform( transf );
696
700
                transf = 0;
697
701
            }
698
 
            theOne = cmsOpenProfileFromFile( uri, "r" );
 
702
            theOne = cmsOpenProfileFromFile( uri.data(), "r" );
699
703
            if ( theOne ) {
700
704
                // a display profile must have the proper stuff
701
705
                icColorSpaceSignature space = cmsGetColorSpace(theOne);
731
735
cmsHPROFILE Inkscape::colorprofile_get_proof_profile_handle()
732
736
{
733
737
    static cmsHPROFILE theOne = 0;
734
 
    static std::string lastURI;
 
738
    static Glib::ustring lastURI;
735
739
 
736
740
    static bool init = false;
737
741
    if ( !init ) {
741
745
        init = true;
742
746
    }
743
747
 
744
 
    long long int which = prefs_get_int_attribute_limited( "options.softproof", "enable", 0, 0, 1 );
745
 
    gchar const * uri = prefs_get_string_attribute("options.softproof", "uri");
 
748
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
749
    bool which = prefs->getBool( "/options/softproof/enable");
 
750
    Glib::ustring uri = prefs->getString("/options/softproof/uri");
746
751
 
747
 
    if ( which && uri && *uri ) {
748
 
        if ( lastURI != std::string(uri) ) {
 
752
    if ( which && !uri.empty() ) {
 
753
        if ( lastURI != uri ) {
749
754
            lastURI.clear();
750
755
            if ( theOne ) {
751
756
                cmsCloseProfile( theOne );
754
759
                cmsDeleteTransform( transf );
755
760
                transf = 0;
756
761
            }
757
 
            theOne = cmsOpenProfileFromFile( uri, "r" );
 
762
            theOne = cmsOpenProfileFromFile( uri.data(), "r" );
758
763
            if ( theOne ) {
759
764
                // a display profile must have the proper stuff
760
765
                icColorSpaceSignature space = cmsGetColorSpace(theOne);
796
801
 
797
802
cmsHTRANSFORM Inkscape::colorprofile_get_display_transform()
798
803
{
799
 
    long long int fromDisplay = prefs_get_int_attribute_limited( "options.displayprofile", "from_display", 0, 0, 1 );
 
804
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
805
    bool fromDisplay = prefs->getBool( "/options/displayprofile/from_display");
800
806
    if ( fromDisplay ) {
801
807
        if ( transf ) {
802
808
            cmsDeleteTransform(transf);
805
811
        return 0;
806
812
    }
807
813
 
808
 
    bool warn = prefs_get_int_attribute_limited( "options.softproof", "gamutwarn", 0, 0, 1 );
809
 
    int intent = prefs_get_int_attribute_limited( "options.displayprofile", "intent", 0, 0, 3 );
810
 
    int proofIntent = prefs_get_int_attribute_limited( "options.softproof", "intent", 0, 0, 3 );
811
 
    bool bpc = prefs_get_int_attribute_limited( "options.softproof", "bpc", 0, 0, 1 );
 
814
    bool warn = prefs->getBool( "/options/softproof/gamutwarn");
 
815
    int intent = prefs->getIntLimited( "/options/displayprofile/intent", 0, 0, 3 );
 
816
    int proofIntent = prefs->getIntLimited( "/options/softproof/intent", 0, 0, 3 );
 
817
    bool bpc = prefs->getBool( "/options/softproof/bpc");
812
818
#if defined(cmsFLAGS_PRESERVEBLACK)
813
 
    bool preserveBlack = prefs_get_int_attribute_limited( "options.softproof", "preserveblack", 0, 0, 1 );
 
819
    bool preserveBlack = prefs->getBool( "/options/softproof/preserveblack");
814
820
#endif //defined(cmsFLAGS_PRESERVEBLACK)
815
 
    gchar const* colorStr = prefs_get_string_attribute("options.softproof", "gamutcolor");
816
 
    Gdk::Color gamutColor( (colorStr && colorStr[0]) ? colorStr : "#808080");
 
821
    Glib::ustring colorStr = prefs->getString("/options/softproof/gamutcolor");
 
822
    Gdk::Color gamutColor( colorStr.empty() ? "#808080" : colorStr );
817
823
 
818
824
    if ( (warn != gamutWarn)
819
825
         || (lastIntent != intent)
854
860
                dwFlags |= cmsFLAGS_PRESERVEBLACK;
855
861
            }
856
862
#endif // defined(cmsFLAGS_PRESERVEBLACK)
857
 
            transf = cmsCreateProofingTransform( ColorProfile::getSRGBProfile(), TYPE_RGB_8, hprof, TYPE_RGB_8, proofProf, intent, proofIntent, dwFlags );
 
863
            transf = cmsCreateProofingTransform( ColorProfile::getSRGBProfile(), TYPE_RGBA_8, hprof, TYPE_RGBA_8, proofProf, intent, proofIntent, dwFlags );
858
864
        } else if ( hprof ) {
859
 
            transf = cmsCreateTransform( ColorProfile::getSRGBProfile(), TYPE_RGB_8, hprof, TYPE_RGB_8, intent, 0 );
 
865
            transf = cmsCreateTransform( ColorProfile::getSRGBProfile(), TYPE_RGBA_8, hprof, TYPE_RGBA_8, intent, 0 );
860
866
        }
861
867
    }
862
868
 
941
947
    id.clear();
942
948
 
943
949
    if ( buf && bufLen ) {
944
 
        Md5Digest digest;
945
 
        if ( buf && bufLen ) {
946
 
            digest.append(reinterpret_cast<unsigned char*>(buf), bufLen);
947
 
        }
948
 
        id = digest.finishHex();
 
950
        id = Digest::hashHex(Digest::HASH_MD5,
 
951
                   reinterpret_cast<unsigned char*>(buf), bufLen);
949
952
 
950
953
        // Note: if this is not a valid profile, item.hprof will be set to null.
951
954
        item.hprof = cmsOpenProfileFromMem(buf, bufLen);
962
965
        return 0;
963
966
    }
964
967
 
 
968
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
965
969
    bool found = false;
966
970
    for ( std::vector< std::vector<MemProfile> >::iterator it = perMonitorProfiles.begin(); it != perMonitorProfiles.end() && !found; ++it ) {
967
971
        for ( std::vector<MemProfile>::iterator it2 = it->begin(); it2 != it->end() && !found; ++it2 ) {
968
972
            if ( id == it2->id ) {
969
973
                MemProfile& item = *it2;
970
974
 
971
 
                bool warn = prefs_get_int_attribute_limited( "options.softproof", "gamutwarn", 0, 0, 1 );
972
 
                int intent = prefs_get_int_attribute_limited( "options.displayprofile", "intent", 0, 0, 3 );
973
 
                int proofIntent = prefs_get_int_attribute_limited( "options.softproof", "intent", 0, 0, 3 );
974
 
                bool bpc = prefs_get_int_attribute_limited( "options.softproof", "bpc", 0, 0, 1 );
 
975
                bool warn = prefs->getBool( "/options/softproof/gamutwarn");
 
976
                int intent = prefs->getIntLimited( "/options/displayprofile/intent", 0, 0, 3 );
 
977
                int proofIntent = prefs->getIntLimited( "/options/softproof/intent", 0, 0, 3 );
 
978
                bool bpc = prefs->getBool( "/options/softproof/bpc");
975
979
#if defined(cmsFLAGS_PRESERVEBLACK)
976
 
                bool preserveBlack = prefs_get_int_attribute_limited( "options.softproof", "preserveblack", 0, 0, 1 );
 
980
                bool preserveBlack = prefs->getBool( "/options/softproof/preserveblack");
977
981
#endif //defined(cmsFLAGS_PRESERVEBLACK)
978
 
                gchar const* colorStr = prefs_get_string_attribute("options.softproof", "gamutcolor");
979
 
                Gdk::Color gamutColor( (colorStr && colorStr[0]) ? colorStr : "#808080");
 
982
                Glib::ustring colorStr = prefs->getString("/options/softproof/gamutcolor");
 
983
                Gdk::Color gamutColor( colorStr.empty() ? "#808080" : colorStr );
980
984
 
981
985
                if ( (warn != gamutWarn)
982
986
                     || (lastIntent != intent)
1016
1020
                            dwFlags |= cmsFLAGS_PRESERVEBLACK;
1017
1021
                        }
1018
1022
#endif // defined(cmsFLAGS_PRESERVEBLACK)
1019
 
                        item.transf = cmsCreateProofingTransform( ColorProfile::getSRGBProfile(), TYPE_RGB_8, item.hprof, TYPE_RGB_8, proofProf, intent, proofIntent, dwFlags );
 
1023
                        item.transf = cmsCreateProofingTransform( ColorProfile::getSRGBProfile(), TYPE_RGBA_8, item.hprof, TYPE_RGBA_8, proofProf, intent, proofIntent, dwFlags );
1020
1024
                    } else if ( item.hprof ) {
1021
 
                        item.transf = cmsCreateTransform( ColorProfile::getSRGBProfile(), TYPE_RGB_8, item.hprof, TYPE_RGB_8, intent, 0 );
 
1025
                        item.transf = cmsCreateTransform( ColorProfile::getSRGBProfile(), TYPE_RGBA_8, item.hprof, TYPE_RGBA_8, intent, 0 );
1022
1026
                    }
1023
1027
                }
1024
1028