color-profile.cpp revision 721c5003ed11901975b6b0c9e49cbc67a4cf0782
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#define noDEBUG_LCMS
#if WITH_GTKMM_3_0
#else
#endif
#include <glibmm/checksum.h>
#include <fcntl.h>
#ifdef DEBUG_LCMS
#endif // DEBUG_LCMS
#include <unistd.h>
#include <cstring>
#include <string>
#ifdef WIN32
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. Required for correctly including icm.h
#define _WIN32_WINDOWS 0x0410
#endif
#include <windows.h>
#endif
#if HAVE_LIBLCMS2
# include <lcms2.h>
# include <lcms.h>
#endif // HAVE_LIBLCMS2
#include "color.h"
#include "color-profile.h"
#include "cms-system.h"
#include "color-profile-cms-fns.h"
#include "attributes.h"
#include "inkscape.h"
#include "document.h"
#include "preferences.h"
#include "uri.h"
#ifdef WIN32
#include <icm.h>
#endif // WIN32
using Inkscape::ColorProfile;
using Inkscape::ColorProfileImpl;
namespace
{
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
void loadProfiles();
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
}
#ifdef DEBUG_LCMS
extern guint update_in_progress;
#define DEBUG_MESSAGE_SCISLAC(key, ...) \
{\
if ( dump )\
{\
g_message( __VA_ARGS__ );\
\
}\
if ( dumpD )\
{\
);\
dialog); \
}\
}
#define DEBUG_MESSAGE(key, ...)\
{\
g_message( __VA_ARGS__ );\
}
#else
#define DEBUG_MESSAGE_SCISLAC(key, ...)
#define DEBUG_MESSAGE(key, ...)
#endif // DEBUG_LCMS
namespace Inkscape {
class ColorProfileImpl {
public:
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
static cmsHPROFILE _sRGBProf;
static cmsHPROFILE _NullProf;
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
static cmsHPROFILE getNULLProfile();
static cmsHPROFILE getSRGBProfile();
void _clearProfile();
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
};
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
{
return ColorSpaceSigWrapper(sig);
}
{
return ColorProfileClassSigWrapper(sig);
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
} // namespace Inkscape
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
:
_profHandle(0),
_transf(0),
_revTransf(0),
_gamutTransf(0)
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
{
}
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
if ( !_sRGBProf ) {
}
return ColorProfileImpl::_sRGBProf;
}
if ( !_NullProf ) {
}
return _NullProf;
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
this->impl = new ColorProfileImpl();
this->href = 0;
this->local = 0;
this->name = 0;
this->intentStr = 0;
}
ColorProfile::~ColorProfile() {
}
/**
* Callback: free object
*/
void ColorProfile::release() {
// Unregister ourselves
if ( this->document ) {
}
if ( this->href ) {
this->href = 0;
}
if ( this->local ) {
this->local = 0;
}
if ( this->name ) {
this->name = 0;
}
if ( this->intentStr ) {
this->intentStr = 0;
}
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
this->impl->_clearProfile();
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
delete this->impl;
this->impl = 0;
}
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
void ColorProfileImpl::_clearProfile()
{
if ( _transf ) {
_transf = 0;
}
if ( _revTransf ) {
_revTransf = 0;
}
if ( _gamutTransf ) {
_gamutTransf = 0;
}
if ( _profHandle ) {
_profHandle = 0;
}
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
/**
* Callback: set attributes from associated repr.
*/
this->readAttr( "xlink:href" );
this->readAttr( "local" );
this->readAttr( "name" );
this->readAttr( "rendering-intent" );
// Register
if ( document ) {
}
}
/**
* Callback: set attribute.
*/
switch (key) {
case SP_ATTR_XLINK_HREF:
if ( this->href ) {
this->href = 0;
}
if ( value ) {
if ( *this->href ) {
#if HAVE_LIBLCMS1
#endif
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
// TODO open filename and URIs properly
//FILE* fp = fopen_utf8name( filename, "r" );
//LCMSAPI cmsHPROFILE LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, cmsUInt32Number dwSize);
// Try to open relative
if (!doc) {
g_warning("this has no document. using active");
}
//# 1. Get complete URI of document
//g_message("docbase:%s\n", docbase);
//org::w3c::dom::URI docUri(docbase);
if (docbase) { // The file has already been saved
}
//# 2. Get href of icc file. we don't care if it's rel or abs
//org::w3c::dom::URI hrefUri(escaped);
//# 3. Resolve the href according the docBase. This follows
// the w3c specs. All absolute and relative issues are considered
this->impl->_clearProfile();
if ( this->impl->_profHandle ) {
}
DEBUG_MESSAGE( lcmsOne, "cmsOpenProfileFromFile( '%s'...) = %p", fullname, (void*)this->impl->_profHandle );
escaped = 0;
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
}
}
break;
case SP_ATTR_LOCAL:
if ( this->local ) {
this->local = 0;
}
break;
case SP_ATTR_NAME:
if ( this->name ) {
this->name = 0;
}
break;
case SP_ATTR_RENDERING_INTENT:
if ( this->intentStr ) {
this->intentStr = 0;
}
if ( value ) {
this->rendering_intent = RENDERING_INTENT_AUTO;
} else {
this->rendering_intent = RENDERING_INTENT_UNKNOWN;
}
} else {
this->rendering_intent = RENDERING_INTENT_UNKNOWN;
}
break;
default:
break;
}
}
/**
* Callback: write attributes to associated repr.
*/
Inkscape::XML::Node* ColorProfile::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
}
}
}
}
}
return repr;
}
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
struct MapMap {
};
{
//cmsSigLuvData
};
int index = 0;
index = i;
break;
}
}
}
{
int intent = INTENT_PERCEPTUAL;
switch ( svgIntent ) {
break;
break;
break;
case Inkscape::RENDERING_INTENT_UNKNOWN:
case Inkscape::RENDERING_INTENT_AUTO:
default:
}
return intent;
}
{
if ( prof ) {
break;
}
}
}
}
return result;
}
cmsHPROFILE Inkscape::CMSSystem::getHandle( SPDocument* document, guint* intent, gchar const* name )
{
cmsHPROFILE prof = 0;
if ( thing ) {
}
if ( intent ) {
}
DEBUG_MESSAGE( lcmsThree, "<color-profile> queried for profile of '%s'. Returning %p with intent of %d", name, prof, (intent? *intent:0) );
return prof;
}
}
}
{
impl->_transf = cmsCreateTransform( impl->_profHandle, ColorProfileImpl::_getInputFormat(impl->_profileSpace), ColorProfileImpl::getSRGBProfile(), TYPE_RGBA_8, intent, 0 );
}
}
{
impl->_revTransf = cmsCreateTransform( ColorProfileImpl::getSRGBProfile(), TYPE_RGBA_8, impl->_profHandle, ColorProfileImpl::_getInputFormat(impl->_profileSpace), intent, 0 );
}
return impl->_revTransf;
}
{
if ( !impl->_gamutTransf ) {
}
return impl->_gamutTransf;
}
{
#if HAVE_LIBLCMS1
int alarm_r = 0;
int alarm_g = 0;
int alarm_b = 0;
newAlarmCodes[0] = ~0;
#endif // HAVE_LIBLCMS1
cmsUInt8Number outofgamut = 0;
255};
#if HAVE_LIBLCMS1
#endif // HAVE_LIBLCMS1
return (outofgamut != 0);
}
class ProfileInfo
{
public:
private:
};
#include <iostream>
{
}
{
loadProfiles();
for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
}
}
return result;
}
{
loadProfiles();
for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
}
}
return result;
}
{
loadProfiles();
for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
break;
}
}
return result;
}
void Inkscape::CMSSystem::doTransform(cmsHTRANSFORM transform, void *inBuf, void *outBuf, unsigned int size)
{
}
{
bool isPrint = false;
if ( profile ) {
}
return isPrint;
}
{
if ( profile ) {
#if HAVE_LIBLCMS1
#endif
}
return count;
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
static bool warnSet = false;
if (!warnSet) {
#if HAVE_LIBLCMS1
#endif
warnSet = true;
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
// first try user's local dir
for ( int i = 0; dataDirs[i]; i++ ) {
}
// On OS X:
{
bool onOSX = false;
for ( std::vector<Glib::ustring>::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) ) {
onOSX = true;
}
}
if ( onOSX ) {
}
}
}
#ifdef WIN32
pathBuf[0] = 0;
g_warning( "GetColorDirectoryW() resulted in invalid UTF-8" );
} else {
}
}
#endif // WIN32
return sources;
}
{
bool isIccFile = false;
//0-3 == size
//36-39 == 'acsp' 0x61637370
if ( fd != -1 ) {
//size_t left = 40;
if ( got != -1 ) {
isIccFile = (scratch[36] == 'a') && (scratch[37] == 'c') && (scratch[38] == 's') && (scratch[39] == 'p');
}
}
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
if (isIccFile) {
if ( prof ) {
if ( profClass == cmsSigNamedColorClass ) {
isIccFile = false; // Ignore named color profiles for now.
}
cmsCloseProfile( prof );
}
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
}
}
return isIccFile;
}
{
{
}
if ( g_file_test( it->c_str(), G_FILE_TEST_EXISTS ) && g_file_test( it->c_str(), G_FILE_TEST_IS_DIR ) ) {
if (dir) {
} else {
}
}
}
dir = 0;
} else {
}
}
}
return files;
}
{
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
if ( hProfile ) {
}
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
return result;
}
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
#if HAVE_LIBLCMS1
{
return 1;
}
{
//g_message("lcms: Error %d; %s", errorCode, errorText);
}
#endif
namespace
{
{
if ( profile ) {
#if HAVE_LIBLCMS1
if ( !name ) {
}
name = _("(invalid UTF-8 string)");
}
if (byteLen > 0) {
// TODO investigate wchar_t and cmsGetProfileInfo()
"en", "US",
}
}
nameStr = _("(invalid UTF-8 string)");
}
#endif
}
return nameStr;
}
/**
* This function loads or refreshes data in knownProfiles.
* Call it at the start of every call that requires this data.
*/
void loadProfiles()
{
static bool error_handler_set = false;
if (!error_handler_set) {
#if HAVE_LIBLCMS1
//cmsSetLogErrorHandler(errorHandlerCB);
//g_message("LCMS error handler set");
#endif
error_handler_set = true;
}
static bool profiles_searched = false;
if ( !profiles_searched ) {
if ( prof ) {
cmsCloseProfile( prof );
prof = 0;
bool sameName = false;
for ( std::vector<ProfileInfo>::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) {
sameName = true;
break;
}
}
if ( !sameName ) {
}
}
}
profiles_searched = true;
}
}
} // namespace
static bool gamutWarn = false;
#if WITH_GTKMM_3_0
#else
#endif
static bool lastBPC = false;
#if defined(cmsFLAGS_PRESERVEBLACK)
static bool lastPreserveBlack = false;
#endif // defined(cmsFLAGS_PRESERVEBLACK)
static int lastIntent = INTENT_PERCEPTUAL;
static int lastProofIntent = INTENT_PERCEPTUAL;
static cmsHTRANSFORM transf = 0;
namespace {
{
static cmsHPROFILE theOne = 0;
loadProfiles();
if ( theOne ) {
}
if ( transf ) {
transf = 0;
}
if ( theOne ) {
// a display profile must have the proper stuff
if ( profClass != cmsSigDisplayClass ) {
g_warning("Not a display profile");
theOne = 0;
} else if ( space != cmsSigRgbData ) {
g_warning("Not an RGB profile");
theOne = 0;
} else {
}
}
}
} else if ( theOne ) {
theOne = 0;
if ( transf ) {
transf = 0;
}
}
return theOne;
}
{
static cmsHPROFILE theOne = 0;
loadProfiles();
if ( theOne ) {
}
if ( transf ) {
transf = 0;
}
if ( theOne ) {
// a display profile must have the proper stuff
(void)space;
(void)profClass;
/*
if ( profClass != cmsSigDisplayClass ) {
g_warning("Not a display profile");
cmsCloseProfile( theOne );
theOne = 0;
} else if ( space != cmsSigRgbData ) {
g_warning("Not an RGB profile");
cmsCloseProfile( theOne );
theOne = 0;
} else {
*/
/*
}
*/
}
}
} else if ( theOne ) {
theOne = 0;
if ( transf ) {
transf = 0;
}
}
return theOne;
}
} // namespace
static void free_transforms();
{
if ( fromDisplay ) {
if ( transf ) {
transf = 0;
}
return 0;
}
#if defined(cmsFLAGS_PRESERVEBLACK)
#endif //defined(cmsFLAGS_PRESERVEBLACK)
#if WITH_GTKMM_3_0
#else
#endif
|| (lastIntent != intent)
|| (lastProofIntent != proofIntent)
#if defined(cmsFLAGS_PRESERVEBLACK)
|| (preserveBlack != lastPreserveBlack)
#endif // defined(cmsFLAGS_PRESERVEBLACK)
|| (gamutColor != lastGamutColor)
) {
lastIntent = intent;
#if defined(cmsFLAGS_PRESERVEBLACK)
#endif // defined(cmsFLAGS_PRESERVEBLACK)
}
// Fetch these now, as they might clear the transform as a side effect.
if ( !transf ) {
if ( gamutWarn ) {
#if WITH_GTKMM_3_0
#else
#endif
#if HAVE_LIBLCMS1
newAlarmCodes[0] = gamutColor_r;
newAlarmCodes[3] = ~0;
#endif
}
if ( bpc ) {
}
#if defined(cmsFLAGS_PRESERVEBLACK)
if ( preserveBlack ) {
}
#endif // defined(cmsFLAGS_PRESERVEBLACK)
transf = cmsCreateProofingTransform( ColorProfileImpl::getSRGBProfile(), TYPE_BGRA_8, hprof, TYPE_BGRA_8, proofProf, intent, proofIntent, dwFlags );
} else if ( hprof ) {
transf = cmsCreateTransform( ColorProfileImpl::getSRGBProfile(), TYPE_BGRA_8, hprof, TYPE_BGRA_8, intent, 0 );
}
}
return transf;
}
class MemProfile {
public:
MemProfile();
~MemProfile();
};
MemProfile::MemProfile() :
id(),
hprof(0),
transf(0)
{
}
MemProfile::~MemProfile()
{
}
void free_transforms()
{
if ( transf ) {
transf = 0;
}
for ( std::vector< std::vector<MemProfile> >::iterator it = perMonitorProfiles.begin(); it != perMonitorProfiles.end(); ++it ) {
}
}
}
}
{
}
}
return id;
}
Glib::ustring Inkscape::CMSSystem::setDisplayPer( gpointer buf, guint bufLen, int screen, int monitor )
{
}
}
}
// Note: if this is not a valid profile, item.hprof will be set to null.
}
return id;
}
{
cmsHTRANSFORM result = 0;
return 0;
}
bool found = false;
for ( std::vector< std::vector<MemProfile> >::iterator it = perMonitorProfiles.begin(); it != perMonitorProfiles.end() && !found; ++it ) {
#if defined(cmsFLAGS_PRESERVEBLACK)
#endif //defined(cmsFLAGS_PRESERVEBLACK)
#if WITH_GTKMM_3_0
#else
#endif
|| (lastIntent != intent)
|| (lastProofIntent != proofIntent)
#if defined(cmsFLAGS_PRESERVEBLACK)
|| (preserveBlack != lastPreserveBlack)
#endif // defined(cmsFLAGS_PRESERVEBLACK)
|| (gamutColor != lastGamutColor)
) {
lastIntent = intent;
#if defined(cmsFLAGS_PRESERVEBLACK)
#endif // defined(cmsFLAGS_PRESERVEBLACK)
}
// Fetch these now, as they might clear the transform as a side effect.
if ( gamutWarn ) {
#if WITH_GTKMM_3_0
#else
#endif
#if HAVE_LIBLCMS1
newAlarmCodes[0] = gamutColor_r;
newAlarmCodes[3] = ~0;
#endif
}
if ( bpc ) {
}
#if defined(cmsFLAGS_PRESERVEBLACK)
if ( preserveBlack ) {
}
#endif // defined(cmsFLAGS_PRESERVEBLACK)
item.transf = cmsCreateProofingTransform( ColorProfileImpl::getSRGBProfile(), TYPE_BGRA_8, item.hprof, TYPE_BGRA_8, proofProf, intent, proofIntent, dwFlags );
item.transf = cmsCreateTransform( ColorProfileImpl::getSRGBProfile(), TYPE_BGRA_8, item.hprof, TYPE_BGRA_8, intent, 0 );
}
}
found = true;
}
}
}
return result;
}
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :