Commit baa23899 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Implement support for the alpha channel in the curves filter.

BUG: 315365
Patch by Sahil Nagpal (<nagpal.sahil01@gmail.com>)
parent c182bde9
......@@ -64,11 +64,11 @@ KisPerChannelConfigWidget::KisPerChannelConfigWidget(QWidget * parent, KisPaintD
m_activeCh = 0;
KisPerChannelFilterConfiguration::initDefaultCurves(m_curves,
m_dev->colorSpace()->colorChannelCount());
m_dev->colorSpace()->channelCount());
QList<KoChannelInfo *> colorChannels;
foreach(KoChannelInfo *channel, dev->colorSpace()->channels()) {
if (channel->channelType() == KoChannelInfo::COLOR) {
if (channel->channelType() == KoChannelInfo::COLOR || channel->channelType() == KoChannelInfo::ALPHA) {
colorChannels.append(channel);
}
}
......@@ -219,7 +219,7 @@ void KisPerChannelConfigWidget::setActiveChannel(int ch)
KisPropertiesConfiguration * KisPerChannelConfigWidget::configuration() const
{
int nCh = m_dev->colorSpace()->colorChannelCount();
int nCh = m_dev->colorSpace()->channelCount();
KisPerChannelFilterConfiguration * cfg = new KisPerChannelFilterConfiguration(nCh);
// updating current state
......@@ -245,8 +245,8 @@ void KisPerChannelConfigWidget::setConfiguration(const KisPropertiesConfiguratio
*/
KisPerChannelFilterConfiguration::initDefaultCurves(m_curves,
m_dev->colorSpace()->colorChannelCount());
} else if (cfg->curves().size() != int(m_dev->colorSpace()->colorChannelCount())) {
m_dev->colorSpace()->channelCount());
} else if (cfg->curves().size() != int(m_dev->colorSpace()->channelCount())) {
return;
} else {
for (int ch = 0; ch < cfg->curves().size(); ch++)
......@@ -271,7 +271,7 @@ KisPerChannelFilterConfiguration::~KisPerChannelFilterConfiguration()
bool KisPerChannelFilterConfiguration::isCompatible(const KisPaintDeviceSP dev) const
{
return (int)dev->colorSpace()->colorChannelCount() == m_curves.size();
return (int)dev->colorSpace()->channelCount() == m_curves.size();
}
void KisPerChannelFilterConfiguration::setCurves(QList<KisCubicCurve> &curves)
......@@ -425,7 +425,7 @@ KoColorTransformation* KisPerChannelFilter::createTransformation(const KoColorSp
const QVector<QVector<quint16> > &originalTransfers =
configBC->transfers();
if (originalTransfers.size() != int(cs->colorChannelCount())) {
if (originalTransfers.size() != int(cs->channelCount())) {
// We got an illegal number of colorchannels.KisFilter
return 0;
}
......
......@@ -25,7 +25,6 @@
#include "ui_wdgautobrush.h"
#include <kis_auto_brush.h>
class KisWidgetChooser;
class PAINTOP_EXPORT KisWdgAutobrush : public QWidget, public Ui::KisWdgAutobrush
{
Q_OBJECT
......@@ -79,7 +78,6 @@ private:
QImage m_brush;
KisBrushSP m_autoBrush;
bool m_linkFade;
KisWidgetChooser* m_sliderChooser[2];
};
......
......@@ -35,8 +35,8 @@ public:
enum enumChannelType {
COLOR, ///< The channel represents a color
ALPHA, ///< The channel represents the opacity of a pixel
SUBSTANCE, ///< The channel represents a real-world substance like pigments or medium
SUBSTRATE ///< The channel represents a real-world painting substrate like a canvas
//SUBSTANCE, ///< The channel represents a real-world substance like pigments or medium
//SUBSTRATE ///< The channel represents a real-world painting substrate like a canvas
};
/// enum to define the value of the channel
enum enumChannelValueType {
......
......@@ -85,6 +85,7 @@ class LcmsColorSpace : public KoColorSpaceAbstract<_CSTraits>, public KoLcmsInfo
{
csProfile = 0;
cmstransform = 0;
cmsAlphaTransform = 0;
profiles[0] = 0;
profiles[1] = 0;
profiles[2] = 0;
......@@ -104,22 +105,44 @@ class LcmsColorSpace : public KoColorSpaceAbstract<_CSTraits>, public KoLcmsInfo
virtual void transform(const quint8 *src, quint8 *dst, qint32 nPixels) const {
cmsDoTransform(cmstransform, const_cast<quint8 *>(src), dst, nPixels);
qreal *alpha = new qreal[nPixels];
qreal *dstalpha = new qreal[nPixels];
qint32 numPixels = nPixels;
qint32 pixelSize = m_colorSpace->pixelSize();
while (numPixels > 0) {
quint8 alpha = m_colorSpace->opacityU8(src);
m_colorSpace->setOpacity(dst, alpha, 1);
src += pixelSize;
dst += pixelSize;
numPixels--;
int index = 0;
if(cmsAlphaTransform) {
while (index < nPixels) {
alpha[index] = m_colorSpace->opacityF(src);
src += pixelSize;
index++;
}
cmsDoTransform(cmsAlphaTransform, const_cast<qreal *>(alpha), static_cast<qreal *>(dstalpha), nPixels);
for(int i = 0 ; i < numPixels ; i++) {
m_colorSpace->setOpacity(dst, dstalpha[i], 1);
dst += pixelSize;
}
delete [] alpha;
delete [] dstalpha;
}
else {
while (numPixels > 0) {
qreal alpha = m_colorSpace->opacityF(src);
m_colorSpace->setOpacity(dst, alpha, 1);
src += pixelSize;
dst += pixelSize;
numPixels--;
}
}
}
const KoColorSpace* m_colorSpace;
cmsHPROFILE csProfile;
cmsHPROFILE profiles[3];
cmsHTRANSFORM cmstransform;
cmsHTRANSFORM cmsAlphaTransform;
};
struct Private {
......@@ -346,17 +369,24 @@ public:
transferFunctions[ch] = cmsBuildTabulatedToneCurve16( 0, 256, transferValues[ch]);
}
cmsToneCurve ** alphaTransferFunctions = new cmsToneCurve*[1];
alphaTransferFunctions[0] = cmsBuildTabulatedToneCurve16( 0, 256, transferValues[this->colorChannelCount()]);
KoLcmsColorTransformation *adj = new KoLcmsColorTransformation(this);
adj->profiles[0] = cmsCreateLinearizationDeviceLink(this->colorSpaceSignature(), transferFunctions);
adj->profiles[1] = NULL;
adj->profiles[1] = cmsCreateLinearizationDeviceLink(cmsSigGrayData, alphaTransferFunctions);
adj->profiles[2] = NULL;
adj->csProfile = d->profile->lcmsProfile();
adj->cmstransform = cmsCreateTransform(adj->profiles[0], this->colorSpaceType(), NULL, this->colorSpaceType(),
KoColorConversionTransformation::AdjustmentRenderingIntent,
KoColorConversionTransformation::AdjustmentConversionFlags);
adj->cmsAlphaTransform = cmsCreateTransform(adj->profiles[1], TYPE_GRAY_DBL, NULL, TYPE_GRAY_DBL,
KoColorConversionTransformation::AdjustmentRenderingIntent,
KoColorConversionTransformation::AdjustmentConversionFlags);
delete [] transferFunctions;
delete [] alphaTransferFunctions;
return adj;
}
......
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