Commit 763ec734 authored by Boudewijn Rempt's avatar Boudewijn Rempt

* Better layout for separations dialog

* Add alphamask functions to the colorspace
* Move profiles to the colorspace registry, making sure we load those only one time
* Move the svg to the right place.

svn path=/trunk/koffice/; revision=445329
parent 1b64b1cb
......@@ -166,23 +166,14 @@ public:
/**
* Get a list of profiles that apply to this color space
*/
vKisProfileSP profiles() { return m_profiles; }
vKisProfileSP profiles();
/**
* Reload the profiles from disk
*/
void resetProfiles();
/**
* Return the number of profiles available for this color space
*/
Q_INT32 profileCount() const { return m_profiles.count(); }
Q_INT32 profileCount();
/**
* Return the profile associated with the given product name,
* or 0.
*/
KisProfileSP getProfileByName(const QString & name);
//================= Conversion functions ==================================//
......@@ -278,6 +269,18 @@ public:
virtual void setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nPixels);
/**
* Applies the specified 8-bit alpha mask to the pixels. We assume that there are just
* as many alpha values as pixels but we do not check this.
*/
virtual void applyAphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
/**
* Applies the inverted 8-bit alpha mask to the pixels. We assume that there are just
* as many alpha values as pixels but we do not check this.
*/
virtual void applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels);
/**
* Create an adjustment object for adjusting the brightness and contrast
* transferValues is a 256 bins array with values from 0 to 0xFFFF
......@@ -398,8 +401,8 @@ private:
KisAbstractColorSpace(const KisAbstractColorSpace&);
KisAbstractColorSpace& operator=(const KisAbstractColorSpace&);
vKisProfileSP m_profiles;
Q_UINT32 m_cachesize;
Q_UINT8 * m_conversionCache;
};
......
......@@ -16,8 +16,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <qdir.h>
#include "kdebug.h"
#include <kstandarddirs.h>
#include <kinstance.h>
#include "kis_factory.h"
#include "kis_types.h"
#include "kis_colorspace_registry.h"
#include "kis_xyz_colorspace.h"
......@@ -41,17 +47,65 @@ KisColorSpaceRegistry* KisColorSpaceRegistry::instance()
KisColorSpaceRegistry::m_singleton = new KisColorSpaceRegistry();
Q_CHECK_PTR(KisColorSpaceRegistry::m_singleton);
m_singleton->add(new KisXyzColorSpace());
m_singleton->resetProfiles();
}
return KisColorSpaceRegistry::m_singleton;
}
KisProfileSP KisColorSpaceRegistry::getProfileByName(const QString & name) const
KisProfileSP KisColorSpaceRegistry::getProfileByName(const QString & name)
{
if (m_profileMap.find(name) == m_profileMap.end()) {
return 0;
}
return m_profileMap[name];
}
vKisProfileSP KisColorSpaceRegistry::profilesFor(KisAbstractColorSpace * cs)
{
KisProfileSP profile = 0;
KisIDList keys = listKeys();
for ( KisIDList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
profile = get(*it) -> getProfileByName(name);
if (profile != 0) return profile;
vKisProfileSP profiles;
QMap<QString, KisProfileSP>::Iterator it;
for (it = m_profileMap.begin(); it != m_profileMap.end(); ++it) {
KisProfileSP profile = it.data();
if (profile->colorSpaceSignature() == cs->colorSpaceSignature()) {
profile->setColorType(cs->colorSpaceType());
profiles.push_back(profile);
}
}
return profile;
return profiles;
}
void KisColorSpaceRegistry::resetProfiles()
{
// XXX: Should find a way to make sure not all profiles are read for all color strategies
QStringList profileFilenames;
profileFilenames += KisFactory::global() -> dirs() -> findAllResources("kis_profiles", "*.icm");
profileFilenames += KisFactory::global() -> dirs() -> findAllResources("kis_profiles", "*.ICM");
profileFilenames += KisFactory::global() -> dirs() -> findAllResources("kis_profiles", "*.ICC");
profileFilenames += KisFactory::global() -> dirs() -> findAllResources("kis_profiles", "*.icc");
QDir d("/usr/share/color/icc/", "*.icc");
profileFilenames += d.entryList();
d.setCurrent("/usr/share/color/icc/");
d.setNameFilter("*.icm");
profileFilenames += d.entryList();
if (!profileFilenames.empty()) {
KisProfile * profile = 0;
for ( QStringList::Iterator it = profileFilenames.begin(); it != profileFilenames.end(); ++it ) {
profile = new KisProfile(*it);
Q_CHECK_PTR(profile);
profile -> load();
if (profile -> valid()) {
m_profileMap[profile->productName()] = profile;
}
}
}
}
......@@ -23,6 +23,7 @@
#include "kis_types.h"
#include "kis_generic_registry.h"
#include "koffice_export.h"
#include "kis_abstract_colorspace.h"
class QStringList;
......@@ -39,9 +40,27 @@ class KRITACORE_EXPORT KisColorSpaceRegistry : public KisGenericRegistry<KisAbst
public:
virtual ~KisColorSpaceRegistry();
/**
* Get the singleton instance of this registry
*/
static KisColorSpaceRegistry* instance();
/**
* Reload the profiles from disk
*/
void resetProfiles();
/**
* Return the profile associated with the given product name,
* or 0.
*/
KisProfileSP getProfileByName(const QString & name);
/**
* Return the vector of profiles for this colorspace
*/
vKisProfileSP profilesFor(KisAbstractColorSpace * cs);
KisProfileSP getProfileByName(const QString & name) const;
private:
KisColorSpaceRegistry();
......@@ -50,7 +69,7 @@ private:
private:
static KisColorSpaceRegistry *m_singleton;
QMap<QString, KisProfileSP> m_profileMap;
};
#endif // KIS_COLORSPACE_REGISTRY_H_
......
......@@ -411,7 +411,7 @@ KisImageSP KisDoc::loadImage(const QDomElement& element)
profile = 0;
}
else {
profile = cs -> getProfileByName(profileProductName);
profile = KisColorSpaceRegistry::instance()->getProfileByName(profileProductName);
}
img = new KisImage(this, width, height, cs, name);
......@@ -565,7 +565,7 @@ KisLayerSP KisDoc::loadLayer(const QDomElement& element, KisImageSP img)
KisProfileSP profile = 0;
if (!profileProductName.isNull()) {
profile = colorSpace -> getProfileByName(profileProductName);
profile = KisColorSpaceRegistry::instance()->getProfileByName(profileProductName);
}
layer = new KisLayer(img, name, opacity, colorSpace);
......
......@@ -885,21 +885,16 @@ void KisPaintDevice::clearSelection()
QRect r = m_selection -> selectedRect();
r = r.normalize();
for (Q_INT32 y = 0; y < r.height(); y++) {
KisHLineIterator devIt = createHLineIterator(r.x(), r.y() + y, r.width(), true);
KisHLineIterator selectionIt = m_selection -> createHLineIterator(r.x(), r.y() + y, r.width(), false);
while (!devIt.isDone()) {
KisPixel p = toPixel(devIt.rawData());
KisPixel s = m_selection -> toPixel(selectionIt.rawData());
// XXX: Why Q_UIN16 here? Doesn't that clash with UINT8_MULT later on?
Q_UINT16 p_alpha, s_alpha;
p_alpha = p.alpha();
s_alpha = MAX_SELECTED - s.alpha();
// XXX: Move to colorspace
p.alpha() = UINT8_MULT(p_alpha, s_alpha);
// XXX: Optimize by using stretches
m_colorStrategy->applyInverseAlphaU8Mask( devIt.rawData(), selectionIt.rawData(), 1);
++devIt;
++selectionIt;
}
......@@ -917,11 +912,8 @@ void KisPaintDevice::applySelectionMask(KisSelectionSP mask)
KisHLineIterator maskIt = mask -> createHLineIterator(r.x(), y, r.width(), false);
while (!pixelIt.isDone()) {
KisPixel pixel = toPixel(pixelIt.rawData());
KisPixel maskValue = mask -> toPixel(maskIt.rawData());
// XXX: Move to colorspace
pixel.alpha() = (pixel.alpha() * maskValue.alpha()) / MAX_SELECTED;
// XXX: Optimize by using stretches
m_colorStrategy->applyAphaU8Mask( pixelIt.rawData(), maskIt.rawData(), 1);
++pixelIt;
++maskIt;
......
......@@ -325,14 +325,14 @@ void KisSelectionManager::imgSelectionChanged(KisImageSP img)
void KisSelectionManager::cut()
{
copy();
clear();
copy();
clear();
}
void KisSelectionManager::copy()
{
KisImageSP img = m_parent -> currentImg();
if (!img) return;
KisImageSP img = m_parent -> currentImg();
if (!img) return;
KisLayerSP layer = img -> activeLayer();
if (!layer) return;
......@@ -356,6 +356,8 @@ void KisSelectionManager::copy()
clip -> setCompositeOp(COMPOSITE_OVER);
clip -> setProfile(layer -> profile());
KisAbstractColorSpace * cs = clip->colorStrategy();
// TODO if the source is linked... copy from all linked layers?!?
// Copy image data
......@@ -371,13 +373,9 @@ void KisSelectionManager::copy()
KisHLineIterator selectionIt = selection -> createHLineIterator(r.x(), r.y() + y, r.width(), false);
while (!layerIt.isDone()) {
KisPixel p = clip -> toPixel(layerIt.rawData());
KisPixel s = selection -> toPixel(selectionIt.rawData());
Q_UINT16 p_alpha, s_alpha;
p_alpha = p.alpha();
s_alpha = s.alpha();
p.alpha() = UINT8_MULT(p_alpha, s_alpha);
cs->applyAphaU8Mask( layerIt.rawData(), selectionIt.rawData(), 1 );
++layerIt;
++selectionIt;
......
......@@ -57,9 +57,8 @@ KisProfile::KisProfile(QByteArray rawData, Q_UINT32 colorType)
init();
}
KisProfile::KisProfile(const QString& file, Q_UINT32 colorType)
: super(file),
m_lcmsColorType(colorType)
KisProfile::KisProfile(const QString& file)
: super(file)
{
}
......@@ -88,10 +87,6 @@ KisProfile::~KisProfile()
bool KisProfile::load()
{
//cmsErrorAction(LCMS_ERROR_IGNORE);
//m_profile = cmsOpenProfileFromFile(filename().ascii(), "r");
// XXX this should be more efficient: we load the file twice
QFile file(filename());
file.open(IO_ReadOnly);
m_rawData = file.readAll();
......@@ -111,11 +106,33 @@ bool KisProfile::init()
m_productDescription = cmsTakeProductDesc(m_profile);
m_productInfo = cmsTakeProductInfo(m_profile);
setValid(true);
#if 0
// XX: It wasn't that easy to save a little memory: thsi gives an lcms error
// Okay, we know enough. Free the memory; we'll load it again if needed.
cmsCloseProfile(m_profile);
m_profile = 0;
#endif
return true;
}
return false;
}
cmsHPROFILE KisProfile::profile()
{
#if 0
if (m_profile = 0) {
QFile file(filename());
file.open(IO_ReadOnly);
m_rawData = file.readAll();
m_profile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD)m_rawData.size());
file.close();
}
#endif
return m_profile;
}
bool KisProfile::save()
{
return false;
......
......@@ -47,7 +47,7 @@ class KisProfile : public KisResource, public KShared {
public:
KisProfile(Q_UINT32 colorType);
KisProfile(QByteArray rawData, Q_UINT32 colorType);
KisProfile(const QString& file, Q_UINT32 colorType);
KisProfile(const QString& file);
KisProfile(const cmsHPROFILE profile, QByteArray rawData, Q_UINT32 colorType);
// Create a profile from a cms profile handle; this profile does not have associated
......@@ -67,8 +67,9 @@ public:
QString productDescription() const { return m_productDescription; }
QString productInfo() const { return m_productInfo; }
QString manufacturer() const { return m_manufacturer; }
cmsHPROFILE profile() const { return m_profile; }
Q_UINT32 colorType() { return m_lcmsColorType; }
cmsHPROFILE profile();
DWORD colorType() { return m_lcmsColorType; }
void setColorType(DWORD colorType) { m_lcmsColorType = colorType; }
KisAnnotationSP annotation() const;
public:
......@@ -85,7 +86,7 @@ private:
QString m_productDescription;
QString m_productInfo;
QString m_manufacturer;
Q_UINT32 m_lcmsColorType;
DWORD m_lcmsColorType;
QByteArray m_rawData;
};
......
......@@ -54,7 +54,7 @@ KisCmykColorSpace::KisCmykColorSpace() :
return;
}
setDefaultProfile( getProfileByName("Adobe CMYK") ); // XXX: Do not i18n -- this is from a data file
setDefaultProfile( KisColorSpaceRegistry::instance()->getProfileByName("Adobe CMYK") ); // XXX: Do not i18n -- this is from a data file
if (getDefaultProfile() == 0) {
kdDebug(DBG_AREA_CMS) << "No Adobe CMYK!\n";
if (profileCount() != 0) {
......
......@@ -100,9 +100,9 @@ void ColorSpaceConversion::slotImgColorSpaceConversion()
KisID cspace = dlgColorSpaceConversion -> m_page -> cmbColorSpaces -> currentItem();
KisAbstractColorSpace * cs = KisColorSpaceRegistry::instance() -> get(cspace);
// XXX: Should we actually set the profile here?
image -> setProfile(image -> colorStrategy() -> getProfileByName(dlgColorSpaceConversion -> m_page -> cmbSourceProfile -> currentText()));
image -> setProfile(KisColorSpaceRegistry::instance()->getProfileByName(dlgColorSpaceConversion -> m_page -> cmbSourceProfile -> currentText()));
image -> convertTo(cs,
cs -> getProfileByName(dlgColorSpaceConversion -> m_page -> cmbDestProfile -> currentText()),
KisColorSpaceRegistry::instance()->getProfileByName(dlgColorSpaceConversion -> m_page -> cmbDestProfile -> currentText()),
dlgColorSpaceConversion -> m_page -> grpIntent -> selectedId());
}
delete dlgColorSpaceConversion;
......@@ -131,9 +131,9 @@ void ColorSpaceConversion::slotLayerColorSpaceConversion()
if (dlgColorSpaceConversion -> exec() == QDialog::Accepted) {
KisID cspace = dlgColorSpaceConversion -> m_page -> cmbColorSpaces -> currentItem();
KisAbstractColorSpace * cs = KisColorSpaceRegistry::instance() -> get(cspace);
dev -> setProfile(dev -> colorStrategy() -> getProfileByName(dlgColorSpaceConversion -> m_page -> cmbSourceProfile -> currentText()));
KisColorSpaceRegistry::instance()->getProfileByName(dlgColorSpaceConversion -> m_page -> cmbSourceProfile -> currentText());
dev -> convertTo(cs,
cs -> getProfileByName(dlgColorSpaceConversion -> m_page -> cmbDestProfile -> currentText()),
KisColorSpaceRegistry::instance()->getProfileByName(dlgColorSpaceConversion -> m_page -> cmbDestProfile -> currentText()),
dlgColorSpaceConversion -> m_page -> grpIntent -> selectedId());
image -> notify();
image -> notifyLayersChanged();
......
......@@ -28,14 +28,13 @@ K_EXPORT_COMPONENT_FACTORY( kritapixelizefilter, KisPixelizeFilterPluginFactory(
KisPixelizeFilterPlugin::KisPixelizeFilterPlugin(QObject *parent, const char *name, const QStringList &)
: KParts::Plugin(parent, name)
{
setInstance(KisPixelizeFilterPluginFactory::instance());
setInstance(KisPixelizeFilterPluginFactory::instance());
kdDebug(DBG_AREA_PLUGINS) << "PixelizeFilter plugin. Class: "
kdDebug(DBG_AREA_PLUGINS) << "PixelizeFilter plugin. Class: "
<< className()
<< ", Parent: "
<< parent -> className()
<< "\n";
KisView * view;
if ( parent->inherits("KisFactory") )
{
......
......@@ -64,10 +64,8 @@ KisProfileSP KisDlgApplyProfile::profile() const
} else {
profileName = m_page -> cmbProfile -> currentText();
}
// XXX: This is bad -- hardcoded for one color model. This dialog ought to be part
// of the rgba color strategy.
KisAbstractColorSpace * cs = KisColorSpaceRegistry::instance() -> get(KisID("RGBA", ""));
return cs -> getProfileByName(profileName);
return KisColorSpaceRegistry::instance()->getProfileByName(profileName);
}
int KisDlgApplyProfile::renderIntent() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment