Commit 596d2381 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Fix filled shape bug Thomas pointed out to me -- and some more little

baby-steps towards colorspace independence.

svn path=/trunk/koffice/; revision=449704
parent f60237e5
......@@ -248,14 +248,21 @@ void KisAbstractColorSpace::setAlpha(Q_UINT8 * pixels, Q_UINT8 alpha, Q_INT32 nP
}
}
void KisAbstractColorSpace::applyAphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels)
KisPixelOp * KisAbstractColorSpace::getPixelOp(const KisID & id)
{
return 0;
}
void KisAbstractColorSpace::applyAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 * alpha, Q_INT32 nPixels)
{
Q_INT32 psize = pixelSize();
while (nPixels--) {
// XXX: Take care -- in u16 or higher, we should upcast the alpha value!
UINT8_MULT(*(pixels + m_alphaPos), *alpha);
pixels[m_alphaPos] = UINT8_MULT(*(pixels + m_alphaPos) , *alpha);
pixels += psize;
++alpha;
......@@ -269,11 +276,14 @@ void KisAbstractColorSpace::applyInverseAlphaU8Mask(Q_UINT8 * pixels, Q_UINT8 *
while(--nPixels) {
Q_UINT16 p_alpha, s_alpha;
p_alpha = *pixels + m_alphaPos;
p_alpha = *(pixels + m_alphaPos);
s_alpha = MAX_SELECTED - *alpha;
kdDebug() << "p_alpha: " << p_alpha << ", s_alpha " << s_alpha << "\n";
// XXX: Take care -- in u16 or higher, we should upcast the alpha value!
*(pixels + m_alphaPos) = UINT8_MULT(p_alpha, MAX_SELECTED - s_alpha);
pixels[m_alphaPos] = UINT8_MULT(p_alpha, s_alpha);
pixels += psize;
++alpha;
......
......@@ -32,11 +32,13 @@
#include "kis_profile.h"
#include "kis_id.h"
#include "kis_composite_op.h"
#include "koffice_export.h"
class QPainter;
class KisIteratorPixel;
class KisPixel;
class KisPixelOp;
class KisPixelRO;
......@@ -273,12 +275,17 @@ public:
Q_UINT8 scaleToU16(const Q_UINT8 * srcPixel, Q_INT32 channelPos);
//============================== Manipulation fucntions ==========================//
KisPixelOp * getPixelOp(const KisID & id);
//
// The manipulation functions have default implementations that _convert_ the pixel
// to a QColor and back. Reimplement these methods in your color strategy!
//
/**
* Set the alpha channel to the given value.
*
......@@ -295,7 +302,7 @@ public:
* 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);
virtual void applyAlphaU8Mask(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
......
......@@ -27,6 +27,7 @@
#include "kis_types.h"
#include "kis_xyz_colorspace.h"
#include "kis_colorspace_registry.h"
#include "kis_pixel_op.h"
KisColorSpaceRegistry *KisColorSpaceRegistry::m_singleton = 0;
......@@ -110,4 +111,27 @@ void KisColorSpaceRegistry::resetProfiles()
}
\ No newline at end of file
void KisColorSpaceRegistry::addFallbackPixelOp(KisPixelOp * pixelop)
{
if (!pixelop) {
return;
}
if (!pixelop->isValid()) {
kdDebug() << "Cannot add invalid pixel operation " << pixelop->id().id() << "\n";
return;
}
m_defaultPixelOps[pixelop->id()] = pixelop;
}
KisPixelOp * KisColorSpaceRegistry::getFallbackPixelOp(KisID pixelop)
{
if (m_defaultPixelOps.find(pixelop) != m_defaultPixelOps.end()) {
return m_defaultPixelOps[pixelop];
}
return 0;
}
......@@ -33,6 +33,7 @@ class QStringList;
* This class contains:
* - a registry of singleton color strategies.
* - a registry of icc profiles
* - a registry of default pixel operations
*/
class KRITACORE_EXPORT KisColorSpaceRegistry : public KisGenericRegistry<KisAbstractColorSpace *> {
......@@ -60,6 +61,21 @@ public:
*/
vKisProfileSP profilesFor(KisAbstractColorSpace * cs);
/**
* Add a new pixel op to the relevant color strategy.
* @param pixelop the pixel operation
* @param cs color model. If empty, then the pixel op will be added to the list of default pixel ops
*/
void addFallbackPixelOp(KisPixelOp * pixelop);
/**
* Return a pixel from the list of default pixelops. If
* the specified pixelop doesn't exist, then 0 will be
* returned.
*/
KisPixelOp * getFallbackPixelOp(KisID pixelop);
private:
KisColorSpaceRegistry();
KisColorSpaceRegistry(const KisColorSpaceRegistry&);
......@@ -68,6 +84,7 @@ private:
private:
static KisColorSpaceRegistry *m_singleton;
QMap<QString, KisProfileSP> m_profileMap;
QMap<KisID, KisPixelOp*> m_defaultPixelOps;
};
#endif // KIS_COLORSPACE_REGISTRY_H_
......
......@@ -34,8 +34,10 @@ class KisF32BaseColorSpace : public KisAbstractColorSpace {
public:
KisF32BaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature)
: KisAbstractColorSpace(id, cmType, colorSpaceSignature) {};
: KisAbstractColorSpace(id, cmType, colorSpaceSignature)
{
m_alphaSize = sizeof(float);
};
};
......
......@@ -38,7 +38,10 @@ public:
public:
KisU16BaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature)
: KisAbstractColorSpace(id, cmType, colorSpaceSignature) {};
: KisAbstractColorSpace(id, cmType, colorSpaceSignature)
{
m_alphaSize = sizeof(Q_UINT16);
};
};
......
......@@ -34,7 +34,10 @@ class KisU8BaseColorSpace : public KisAbstractColorSpace {
public:
KisU8BaseColorSpace(const KisID & id, DWORD cmType, icColorSpaceSignature colorSpaceSignature)
: KisAbstractColorSpace(id, cmType, colorSpaceSignature) {};
: KisAbstractColorSpace(id, cmType, colorSpaceSignature)
{
m_alphaSize = sizeof(Q_UINT8);
};
};
......
......@@ -900,6 +900,7 @@ void KisPaintDevice::clearSelection()
void KisPaintDevice::applySelectionMask(KisSelectionSP mask)
{
kdDebug() << "KisPaintDevice::applySelectionMask: " << m_name << "\n";
QRect r = mask -> extent();
crop(r);
......@@ -910,7 +911,8 @@ void KisPaintDevice::applySelectionMask(KisSelectionSP mask)
while (!pixelIt.isDone()) {
// XXX: Optimize by using stretches
m_colorStrategy->applyAphaU8Mask( pixelIt.rawData(), maskIt.rawData(), 1);
m_colorStrategy->applyAlphaU8Mask( pixelIt.rawData(), maskIt.rawData(), 1);
++pixelIt;
++maskIt;
......
......@@ -374,7 +374,7 @@ void KisSelectionManager::copy()
while (!layerIt.isDone()) {
cs->applyAphaU8Mask( layerIt.rawData(), selectionIt.rawData(), 1 );
cs->applyAlphaU8Mask( layerIt.rawData(), selectionIt.rawData(), 1 );
++layerIt;
......
......@@ -87,6 +87,7 @@ KisCmykColorSpace::KisCmykColorSpace() :
m_qcolordata = new Q_UINT8[3];
Q_CHECK_PTR(m_qcolordata);
m_alphaPos = PIXEL_CMYK_ALPHA;
}
KisCmykColorSpace::~KisCmykColorSpace()
......
......@@ -58,6 +58,7 @@ KisGrayColorSpace::KisGrayColorSpace() :
setDefaultProfile( new KisProfile(hProfile, TYPE_GRAYA_8) );
m_alphaPos = PIXEL_GRAY_ALPHA;
}
......
......@@ -74,6 +74,8 @@ KisF32RgbColorSpace::KisF32RgbColorSpace() :
cmsHPROFILE hProfile = cmsCreate_sRGBProfile();
setDefaultProfile( new KisProfile(hProfile, F32_LCMS_TYPE) );
m_alphaPos = PIXEL_ALPHA * sizeof(float);
}
KisF32RgbColorSpace::~KisF32RgbColorSpace()
......
......@@ -54,6 +54,8 @@ KisRgbU16ColorSpace::KisRgbU16ColorSpace() :
cmsHPROFILE hProfile = cmsCreate_sRGBProfile();
setDefaultProfile( new KisProfile(hProfile, TYPE_BGRA_16) );
m_alphaPos = PIXEL_ALPHA * sizeof(Q_UINT16);
}
KisRgbU16ColorSpace::~KisRgbU16ColorSpace()
......
......@@ -54,6 +54,7 @@ KisRgbColorSpace::KisRgbColorSpace() :
cmsHPROFILE hProfile = cmsCreate_sRGBProfile();
setDefaultProfile( new KisProfile(hProfile, TYPE_BGRA_8) );
m_alphaPos = PIXEL_ALPHA;
}
struct KisColorAdjustment
......
......@@ -45,10 +45,13 @@ struct testcspixel
KisTestColorSpace::KisTestColorSpace() :
KisAbstractColorSpace(KisID("test", i18n("TestCS/Alpha")), 0, icMaxEnumData)
{
m_channels.push_back(new KisChannelInfo(i18n("red"), 2, COLOR));
m_channels.push_back(new KisChannelInfo(i18n("green"), 1, COLOR));
m_channels.push_back(new KisChannelInfo(i18n("blue+green"), 0, COLOR, sizeof(Q_UINT16)));
m_channels.push_back(new KisChannelInfo(i18n("green"), 1, COLOR));
m_channels.push_back(new KisChannelInfo(i18n("red"), 2, COLOR));
m_channels.push_back(new KisChannelInfo(i18n("alpha"), 3, ALPHA));
m_alphaPos = 3;
}
KisTestColorSpace::~KisTestColorSpace()
......
......@@ -85,6 +85,8 @@ KisWetStickyColorSpace::KisWetStickyColorSpace() :
m_channels.push_back(new KisChannelInfo(i18n("Absorbancy"), ++pos, SUBSTRATE, 1));
m_channels.push_back(new KisChannelInfo(i18n("Paint Volume"), ++pos, SUBSTANCE, 1));
m_alphaPos = 3;
#ifdef WSDEBUG
vKisChannelInfoSP_it it;
int i = 0;
......
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