Commit a920450b authored by Dmitry Kazakov's avatar Dmitry Kazakov

Synced with trunk again =)


Fetched patches for Brightness/Contrast filter and paint device
See r991514 and r991523 for details


svn path=/branches/work/koffice-feature-tiles-ng/; revision=991524
parent e26d2d84
......@@ -507,32 +507,33 @@ KisPaintDeviceSP KisPaintDevice::createThumbnailDevice(qint32 w, qint32 h) const
KisPaintDeviceSP thumbnail = new KisPaintDevice(colorSpace());
thumbnail->clear();
int srcw, srch;
int srcWidth, srcHeight;
int srcX0, srcY0;
const QRect e = extent();
srcw = e.width();
srch = e.height();
e.getRect(&srcX0, &srcY0, &srcWidth, &srcHeight);
if (w > srcw) {
w = srcw;
h = qint32(double(srcw) / w * h);
if (w > srcWidth) {
w = srcWidth;
h = qint32(double(srcWidth) / w * h);
}
if (h > srch) {
h = srch;
w = qint32(double(srch) / h * w);
if (h > srcHeight) {
h = srcHeight;
w = qint32(double(srcHeight) / h * w);
}
if (srcw > srch)
h = qint32(double(srch) / srcw * w);
else if (srch > srcw)
w = qint32(double(srcw) / srch * h);
if (srcWidth > srcHeight)
h = qint32(double(srcHeight) / srcWidth * w);
else if (srcHeight > srcWidth)
w = qint32(double(srcWidth) / srcHeight * h);
KisRandomConstAccessorPixel iter = createRandomConstAccessor(0, 0);
KisRandomAccessorPixel dstIter = thumbnail->createRandomAccessor( 0, 0 );
for (qint32 y = 0; y < h; ++y) {
qint32 iY = (y * srch) / h;
qint32 iY = srcY0 + (y * srcHeight) / h;
for (qint32 x = 0; x < w; ++x) {
qint32 iX = (x * srcw) / w;
qint32 iX = srcX0 + (x * srcWidth) / w;
iter.moveTo(iX, iY);
dstIter.moveTo(x, y );
memcpy( dstIter.rawData(), iter.rawData(), m_d->pixelSize );
......
......@@ -152,11 +152,11 @@ void KisAutoContrast::process(KisConstProcessingInformation srcInfo,
KisBrightnessContrastFilterConfiguration * cfg = new KisBrightnessContrastFilterConfiguration();
for (int i = 0; i < 255; i++)
cfg->transfer[i] = 0xFFFF;
cfg->m_transfer[i] = 0xFFFF;
if (diff != 0) {
for (int i = 0; i < minvalue; i++)
cfg->transfer[i] = 0x0;
cfg->m_transfer[i] = 0x0;
for (int i = minvalue; i < maxvalue; i++) {
qint32 val = (i - minvalue) / diff;
......@@ -166,10 +166,10 @@ void KisAutoContrast::process(KisConstProcessingInformation srcInfo,
if (val < 0)
val = 0;
cfg->transfer[i] = val;
cfg->m_transfer[i] = val;
}
for (int i = maxvalue; i < 256; i++)
cfg->transfer[i] = 0xFFFF;
cfg->m_transfer[i] = 0xFFFF;
}
KisSelectionSP dstSel;
......@@ -181,7 +181,7 @@ void KisAutoContrast::process(KisConstProcessingInformation srcInfo,
}
// apply
KoColorTransformation *adj = src->colorSpace()->createBrightnessContrastAdjustment(cfg->transfer);
KoColorTransformation *adj = src->colorSpace()->createBrightnessContrastAdjustment(cfg->m_transfer);
KisRectIteratorPixel iter = dst->createRectIterator(dstTopLeft.x(), dstTopLeft.y(), size.width(), size.height(), dstInfo.selection());
......
......@@ -54,90 +54,142 @@ KisBrightnessContrastFilterConfiguration::KisBrightnessContrastFilterConfigurati
: KisFilterConfiguration("brightnesscontrast", 1)
{
for (quint32 i = 0; i < 256; ++i) {
transfer[i] = i * 257;
m_transfer[i] = i * 257;
}
QPointF p;
p.rx() = 0.0; p.ry() = 0.0;
curve.append(p);
m_curve.append(p);
p.rx() = 1.0; p.ry() = 1.0;
curve.append(p);
m_curve.append(p);
}
KisBrightnessContrastFilterConfiguration::~KisBrightnessContrastFilterConfiguration()
{
}
void KisBrightnessContrastFilterConfiguration::fromXML(const QString& s)
void KisBrightnessContrastFilterConfiguration::fromLegacyXML(const QDomElement& root)
{
QDomDocument doc;
doc.setContent(s);
QDomElement e = doc.documentElement();
QDomNode n = e.firstChild();
while (!n.isNull()) {
e = n.toElement();
if (!e.isNull()) {
if (e.attribute("name") == "transfer") { // ### 1.6 needs .tagName("name") here!
QStringList data = e.text().split(',');
QStringList::Iterator start = data.begin();
QStringList::Iterator end = data.end();
int i = 0;
for (QStringList::Iterator it = start; it != end && i < 256; ++it) {
QString s = *it;
transfer[i] = s.toUShort();
i++;
}
} else if (e.attribute("name") == "curve") { // ### 1.6 needs .tagName("name") here!
QStringList data = e.text().split(';');
curve.clear();
foreach(const QString & pair, data) {
if (pair.indexOf(',') > -1) {
QPointF p;
p.rx() = pair.section(',', 0, 0).toDouble();
p.ry() = pair.section(',', 1, 1).toDouble();
curve.append(p);
fromXML(root);
}
void KisBrightnessContrastFilterConfiguration::fromXML(const QDomElement& root)
{
KisCurve curve;
quint16 numTransfers=0;
int version;
version = root.attribute("version").toInt();
QDomElement e = root.firstChild().toElement();
QString attributeName;
while (!e.isNull()) {
if ((attributeName = e.attribute("name")) == "nTransfers") {
numTransfers = e.text().toUShort();
}
else {
QRegExp rx("curve(\\d+)");
if (rx.indexIn(attributeName, 0) != -1) {
quint16 index = rx.cap(1).toUShort();
if(index == 0 && !e.text().isEmpty()) {
/**
* We are going to use first curve only
*/
QStringList data = e.text().split(';');
foreach(const QString & pair, data) {
if (pair.indexOf(',') > -1) {
QPointF p;
p.rx() = pair.section(',', 0, 0).toDouble();
p.ry() = pair.section(',', 1, 1).toDouble();
curve.append(p);
}
}
}
}
}
n = n.nextSibling();
}
e=e.nextSiblingElement();
}
if(curve.isEmpty())
return;
setVersion(version);
setCurve(curve);
updateTransfers();
}
QString KisBrightnessContrastFilterConfiguration::toString()
void KisBrightnessContrastFilterConfiguration::setCurve(KisCurve &curve)
{
QDomDocument doc = QDomDocument("filterconfig");
QDomElement root = doc.createElement("filterconfig");
root.setAttribute("name", name());
root.setAttribute("version", version());
m_curve.clear();
m_curve=curve;
}
doc.appendChild(root);
#define bounds(x,a,b) (x<a ? a : (x>b ? b :x))
QDomElement e = doc.createElement("transfer");
QString sTransfer;
for (uint i = 0; i < 256 ; ++i) {
sTransfer += QString::number(transfer[i]);
sTransfer += ',';
void KisBrightnessContrastFilterConfiguration::updateTransfers()
{
qint32 val;
for (int i = 0; i < 256; ++i) {
/* Direct uncached version */
val = int(0xFFFF * KisCurveWidget::getCurveValue(m_curve, i / 255.0));
val = bounds(val, 0, 0xFFFF);
m_transfer[i] = val;
}
QDomText text = doc.createCDATASection(sTransfer);
e.appendChild(text);
root.appendChild(e);
}
/**
* Inherited from KisPropertiesConfiguration
*/
//void KisPerChannelFilterConfiguration::fromXML(const QString& s)
void KisBrightnessContrastFilterConfiguration::toLegacyXML(QDomDocument& doc, QDomElement& root) const
{
toXML(doc,root);
}
void KisBrightnessContrastFilterConfiguration::toXML(QDomDocument& doc, QDomElement& root) const
{
/**
* <params version=1>
* <param name="nTransfers">1</param>
* <param name="curve0">0,0;0.5,0.5;1,1;</param>
* </params>
*/
/* This is a constant for Brightness/Contranst filter */
const qint32 numTransfers = 1;
root.setAttribute("version", version());
QDomElement t = doc.createElement("param");
QDomText text = doc.createTextNode(QString::number(numTransfers));
t.setAttribute("name", "nTransfers");
t.appendChild(text);
root.appendChild(t);
t = doc.createElement("param");
t.setAttribute("name", "curve0");
e = doc.createElement("curve");
QString sCurve;
foreach(const QPointF & pair, curve) {
foreach(const QPointF & pair, m_curve) {
sCurve += QString::number(pair.x());
sCurve += ',';
sCurve += QString::number(pair.y());
sCurve += ';';
}
text = doc.createCDATASection(sCurve);
e.appendChild(text);
root.appendChild(e);
return doc.toString();
text = doc.createTextNode(sCurve);
t.appendChild(text);
root.appendChild(t);
}
/**
* Inherited from KisPropertiesConfiguration
*/
//QString KisPerChannelFilterConfiguration::toXML()
KisBrightnessContrastFilter::KisBrightnessContrastFilter()
: KisColorTransformationFilter(id(), categoryAdjust(), i18n("&Brightness/Contrast curve..."))
{
......@@ -170,7 +222,7 @@ KoColorTransformation* KisBrightnessContrastFilter::createTransformation(const K
const KisBrightnessContrastFilterConfiguration* configBC = dynamic_cast<const KisBrightnessContrastFilterConfiguration*>( config );
if(!configBC) return 0;
KoColorTransformation * adjustment = cs->createBrightnessContrastAdjustment(configBC->transfer);
KoColorTransformation * adjustment = cs->createBrightnessContrastAdjustment(configBC->m_transfer);
}
KisBrightnessContrastConfigWidget::KisBrightnessContrastConfigWidget(QWidget * parent, KisPaintDeviceSP dev, Qt::WFlags f)
......@@ -252,9 +304,9 @@ KisBrightnessContrastFilterConfiguration * KisBrightnessContrastConfigWidget::co
if (val < 0)
val = 0;
cfg->transfer[i] = val;
cfg->m_transfer[i] = val;
}
cfg->curve = m_page->curveWidget->getCurve();
cfg->m_curve = m_page->curveWidget->getCurve();
return cfg;
}
......@@ -262,7 +314,7 @@ void KisBrightnessContrastConfigWidget::setConfiguration(const KisPropertiesConf
{
const KisBrightnessContrastFilterConfiguration * cfg = dynamic_cast<const KisBrightnessContrastFilterConfiguration *>(config);
Q_ASSERT(cfg);
m_page->curveWidget->setCurve(cfg->curve);
m_page->curveWidget->setCurve(cfg->m_curve);
}
#include "kis_brightness_contrast_filter.moc"
......
......@@ -35,6 +35,8 @@
class QWidget;
class KoColorTransformation;
typedef QList<QPointF> KisCurve;
class WdgBrightnessContrast : public QWidget, public Ui::WdgBrightnessContrast
{
Q_OBJECT
......@@ -50,15 +52,26 @@ class KisBrightnessContrastFilterConfiguration : public KisFilterConfiguration
public:
using KisFilterConfiguration::fromXML;
using KisFilterConfiguration::toXML;
using KisFilterConfiguration::toLegacyXML;
using KisFilterConfiguration::fromLegacyXML;
virtual void fromLegacyXML(const QDomElement& root);
virtual void toLegacyXML(QDomDocument& doc, QDomElement& root) const;
virtual void fromXML(const QDomElement& e);
virtual void toXML(QDomDocument& doc, QDomElement& root) const;
KisBrightnessContrastFilterConfiguration();
virtual ~KisBrightnessContrastFilterConfiguration();
virtual void fromXML(const QString&);
virtual QString toString();
public:
quint16 transfer[256];
QList<QPointF> curve;
quint16 m_transfer[256];
KisCurve m_curve;
protected:
void setCurve(KisCurve &curve);
void updateTransfers();
};
/**
......@@ -82,9 +95,6 @@ public:
virtual KisFilterConfiguration* factoryConfiguration(const KisPaintDeviceSP) const;
virtual KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, const KisImageSP image = 0) const;
virtual KisPropertiesConfiguration * configuration() {
return new KisBrightnessContrastFilterConfiguration();
}
virtual bool workWith(const KoColorSpace* cs) const;
};
......
......@@ -339,8 +339,8 @@ void KisPerChannelFilterConfiguration::updateTransfersCached(KisCurveWidget &cac
for (int i = 0; i < 256; ++i) {
/* Cached version of the cycle */
val = int(0xFFFF * cacheCurveWidget.getCurveValue(i / 255.0));
val = bounds(val, 0, 0xFFFF);
m_transfers[ch][i] = val;
val = bounds(val, 0, 0xFFFF);
m_transfers[ch][i] = val;
}
}
}
......@@ -423,10 +423,6 @@ void KisPerChannelFilterConfiguration::toXML(QDomDocument& doc, QDomElement& roo
root.setAttribute("version", version());
QDomElement c = doc.createElement("curves");
c.setAttribute("number", m_nTransfers);
c.setAttribute("name", "curves");
QDomElement t = doc.createElement("param");
QDomText text = doc.createTextNode(QString::number(m_nTransfers));
t.setAttribute("name", "nTransfers");
......@@ -458,7 +454,7 @@ void KisPerChannelFilterConfiguration::toXML(QDomDocument& doc, QDomElement& roo
/**
* Inherited from KisPropertiesConfiguration
*/
//void KisPerChannelFilterConfiguration::toXML()
//QString KisPerChannelFilterConfiguration::toXML()
KisPerChannelFilter::KisPerChannelFilter() : KisColorTransformationFilter(id(), categoryAdjust(), i18n("&Color Adjustment curves..."))
......
......@@ -100,7 +100,6 @@ private:
class KisPerChannelConfigWidget : public KisConfigWidget
{
Q_OBJECT
public:
......@@ -130,8 +129,6 @@ private:
// scales for displaying color numbers
double m_scale;
double m_shift;
};
#endif
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