Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit dfb2eae4 authored by Casper Boemann's avatar Casper Boemann

A worldclass brigthness/contrast dialog with an interactive curve for

fine control
Still needs some eyecandy here and there, but it works now


svn path=/trunk/koffice/; revision=442510
parent 50d7df61
......@@ -160,13 +160,6 @@ bool KisStrategyColorSpace::convertPixelsTo(const Q_UINT8 * src, KisProfileSP sr
KisColorAdjustment *KisStrategyColorSpace::createBrightnessContrastAdjustment(Q_UINT16 *transferValues)
{
LPGAMMATABLE transferFunctions[3];
transferFunctions[0] = cmsBuildGamma(256, 1.0);
transferFunctions[1] = cmsBuildGamma(256, 1.0);
transferFunctions[2] = cmsBuildGamma(256, 1.0);
for(int i =0; i < 256; i++)
transferFunctions[0]->GammaTable[i] = transferValues[i];
return NULL;
}
......
......@@ -55,6 +55,18 @@ KisStrategyColorSpaceRGB::KisStrategyColorSpaceRGB() :
setDefaultProfile( new KisProfile(hProfile, TYPE_BGRA_8) );
}
struct KisColorAdjustment
{
~KisColorAdjustment() { cmsDeleteTransform(transform);
cmsCloseProfile(profiles[0]);
cmsCloseProfile(profiles[1]);
cmsCloseProfile(profiles[2]);
}
cmsHPROFILE profiles[3];
cmsHTRANSFORM transform;
};
KisStrategyColorSpaceRGB::~KisStrategyColorSpaceRGB()
{
}
......@@ -276,36 +288,30 @@ QImage KisStrategyColorSpaceRGB::convertToQImage(const Q_UINT8 *data, Q_INT32 wi
return img;
}
void KisStrategyColorSpaceRGB::adjustBrightnessContrast(const Q_UINT8 *src, Q_UINT8 *dst, Q_INT8 brightness, Q_INT8 contrast, Q_INT32 nPixels) const
KisColorAdjustment *KisStrategyColorSpaceRGB::createBrightnessContrastAdjustment(Q_UINT16 *transferValues)
{
static cmsHPROFILE profiles[3];
static cmsHTRANSFORM transform=0;
static Q_INT8 oldb=0;
static Q_INT8 oldc=0;
LPGAMMATABLE transferFunctions[3];
transferFunctions[0] = cmsBuildGamma(256, 1.0);
transferFunctions[1] = cmsBuildGamma(256, 1.0);
transferFunctions[2] = cmsBuildGamma(256, 1.0);
for(int i =0; i < 256; i++)
transferFunctions[0]->GammaTable[i] = transferValues[i];
KisColorAdjustment *adj = new KisColorAdjustment;
adj->profiles[1] = cmsCreateLinearizationDeviceLink(icSigLabData, transferFunctions);
cmsSetDeviceClass(adj->profiles[1], icSigAbstractClass);
if((oldb != brightness || oldc != contrast) && transform!=0)
{
cmsDeleteTransform(transform);
cmsCloseProfile(profiles[0]);
cmsCloseProfile(profiles[1]);
cmsCloseProfile(profiles[2]);
transform=0;
}
adj->profiles[0] = cmsCreate_sRGBProfile();
adj->profiles[2] = cmsCreate_sRGBProfile();
adj->transform = cmsCreateMultiprofileTransform(adj->profiles, 3, TYPE_BGRA_8, TYPE_BGRA_8, INTENT_PERCEPTUAL, 0);
if(transform==0)
{
double a,b;
a=contrast/100.0+1.0;
a *= a;
b= 50 -50*a + brightness;
profiles[0] = cmsCreate_sRGBProfile();
profiles[1] = cmsCreateBCHSWabstractProfile(30, b, a, 0, 0, 6504, 6504);
profiles[2] = cmsCreate_sRGBProfile();
transform = cmsCreateMultiprofileTransform(profiles, 3, TYPE_BGRA_8, TYPE_BGRA_8, INTENT_PERCEPTUAL, 0);
oldb=brightness;
oldc=contrast;
}
cmsDoTransform(transform, const_cast<Q_UINT8 *>(src), dst, nPixels);
return adj;
}
void KisStrategyColorSpaceRGB::applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *adj, Q_INT32 nPixels)
{
cmsDoTransform(adj->transform, const_cast<Q_UINT8 *>(src), dst, nPixels);
}
void KisStrategyColorSpaceRGB::darken(const Q_UINT8 * src, Q_UINT8 * dst, Q_INT32 shade, bool compensate, double compensation, Q_INT32 nPixels) const
......
......@@ -73,7 +73,10 @@ public:
virtual KisCompositeOpList userVisiblecompositeOps() const;
virtual void adjustBrightnessContrast(const Q_UINT8 *src, Q_UINT8 *dst, Q_INT8 brightness, Q_INT8 contrast, Q_INT32 nPixels) const;
virtual KisColorAdjustment *createBrightnessContrastAdjustment(Q_UINT16 *transferValues);
virtual void applyAdjustment(const Q_UINT8 *src, Q_UINT8 *dst, KisColorAdjustment *, Q_INT32 nPixels);
/**
* Darken all color channels with the given amount. If compensate is true,
......@@ -83,7 +86,7 @@ public:
*/
virtual void darken(const Q_UINT8 * src, Q_UINT8 * dst, Q_INT32 shade, bool compensate, double compensation, Q_INT32 nPixels) const;
Q_UINT8 intensity8(const Q_UINT8 * src) const;
virtual Q_UINT8 intensity8(const Q_UINT8 * src) const;
protected:
......
......@@ -2,7 +2,8 @@
* This file is part of Krita
*
* Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
*
* Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
......@@ -28,50 +29,40 @@
#include "kis_paint_device.h"
#include "kis_iterators_pixel.h"
#include "tiles/kis_iterator.h"
#include "kcurve.h"
KisBrightnessContrastFilterConfiguration::KisBrightnessContrastFilterConfiguration(Q_INT32 nbrightness, Q_INT32 ncontrast) :
m_brightness(nbrightness),
m_contrast(ncontrast)
KisBrightnessContrastFilterConfiguration::KisBrightnessContrastFilterConfiguration()
{
}
KisBrightnessContrastFilter::KisBrightnessContrastFilter()
: KisFilter( id(), "adjust", "&Brightness/contrast...")
{
}
Q_UINT16 KisBrightnessContrastFilterConfiguration::transferValue(Q_UINT8 i)
{
return (i << 8) | i;
}
KisFilterConfigWidget * KisBrightnessContrastFilter::createConfigurationWidget(QWidget* parent, KisPaintDeviceSP)
KisFilterConfigWidget * KisBrightnessContrastFilter::createConfigurationWidget(QWidget *parent, KisPaintDeviceSP)
{
KisFilterConfigWidget * w = new KisFilterConfigWidget(parent);
QHBoxLayout * l = new QHBoxLayout(w);
l->setAutoAdd(true);
WdgBrightnessContrast * wbc = new WdgBrightnessContrast(w);
return w;
return new KisBrightnessContrastConfigWidget(parent);
}
KisFilterConfiguration* KisBrightnessContrastFilter::configuration(QWidget* nwidget, KisPaintDeviceSP)
KisFilterConfiguration* KisBrightnessContrastFilter::configuration(QWidget *nwidget, KisPaintDeviceSP)
{
WdgBrightnessContrast* widget = (WdgBrightnessContrast*) nwidget;
KisBrightnessContrastConfigWidget* widget = (KisBrightnessContrastConfigWidget*)nwidget;
if ( widget == 0 )
{
return new KisBrightnessContrastFilterConfiguration( 0, 0 );
return new KisBrightnessContrastFilterConfiguration();
} else {
return new KisBrightnessContrastFilterConfiguration( 1, 1 );
return widget->config();
}
}
std::list<KisFilterConfiguration*> KisBrightnessContrastFilter::listOfExamplesConfiguration(KisPaintDeviceSP dev)
{
//XXX should really come up with a list of configurations
std::list<KisFilterConfiguration*> list;
list.insert(list.begin(), new KisBrightnessContrastFilterConfiguration( 0, 1 ));
list.insert(list.begin(), new KisBrightnessContrastFilterConfiguration( 1, 0 ));
list.insert(list.begin(), new KisBrightnessContrastFilterConfiguration( ));
return list;
}
......@@ -80,11 +71,7 @@ void KisBrightnessContrastFilter::process(KisPaintDeviceSP src, KisPaintDeviceSP
{
KisBrightnessContrastFilterConfiguration* configBC = (KisBrightnessContrastFilterConfiguration*) config;
Q_UINT16 transfer[256];
for(int i=0; i <256; i++)
transfer[i] = configBC->transferValue(i);
KisColorAdjustment *adj = src->colorStrategy()->createBrightnessContrastAdjustment(transfer);
KisColorAdjustment *adj = src->colorStrategy()->createBrightnessContrastAdjustment(configBC->transfer);
KisRectIteratorPixel dstIt = dst->createRectIterator(rect.x(), rect.y(), rect.width(), rect.height(), true );
KisRectIteratorPixel srcIt = src->createRectIterator(rect.x(), rect.y(), rect.width(), rect.height(), false);
......@@ -106,3 +93,34 @@ void KisBrightnessContrastFilter::process(KisPaintDeviceSP src, KisPaintDeviceSP
setProgressDone();
}
KisBrightnessContrastConfigWidget::KisBrightnessContrastConfigWidget(QWidget * parent, const char * name, WFlags f)
: KisFilterConfigWidget(parent, name, f)
{
m_page = new WdgBrightnessContrast(this);
QHBoxLayout * l = new QHBoxLayout(this);
Q_CHECK_PTR(l);
l -> add(m_page);
connect( m_page->kCurve, SIGNAL(modified()), SIGNAL(sigPleaseUpdatePreview()));
}
KisBrightnessContrastFilterConfiguration * KisBrightnessContrastConfigWidget::config()
{
KisBrightnessContrastFilterConfiguration * cfg = new KisBrightnessContrastFilterConfiguration();
for(int i=0; i <256; i++)
{
Q_INT32 val;
val = int(0xFFFF * m_page->kCurve->getCurveValue( i / 255.0));
if(val >0xFFFF)
val=0xFFFF;
if(val <0)
val = 0;
cfg->transfer[i] = val;
}
return cfg;
}
......@@ -21,19 +21,17 @@
#ifndef _KIS_BRIGHTNESS_CONTRAST_FILTER_H_
#define _KIS_BRIGHTNESS_CONTRAST_FILTER_H_
#include <qwidget.h>
#include "kis_filter.h"
#include <kdebug.h>
#include "wdg_brightness_contrast.h"
class KisBrightnessContrastFilterConfiguration : public KisFilterConfiguration {
public:
KisBrightnessContrastFilterConfiguration(Q_INT32 nbrightness, Q_INT32 ncontrast);
KisBrightnessContrastFilterConfiguration();
public:
inline Q_INT32 brightness() { return m_brightness; };
inline Q_INT32 contrast() { return m_contrast; };
Q_UINT16 transferValue(Q_UINT8 i);
private:
Q_INT32 m_brightness;
Q_INT32 m_contrast;
Q_UINT16 transfer[256];
};
/**
......@@ -49,7 +47,7 @@ public:
public:
virtual KisFilterConfigWidget * createConfigurationWidget(QWidget* parent, KisPaintDeviceSP dev);
virtual KisFilterConfiguration* configuration(QWidget*, KisPaintDeviceSP dev);
virtual KisFilterConfiguration* configuration(QWidget *, KisPaintDeviceSP dev);
virtual void process(KisPaintDeviceSP, KisPaintDeviceSP, KisFilterConfiguration* , const QRect&);
static inline KisID id() { return KisID("brightnesscontrast", i18n("Brightness / Contrast")); };
virtual bool supportsPainting() { return true; }
......@@ -58,4 +56,15 @@ public:
};
class KisBrightnessContrastConfigWidget : public KisFilterConfigWidget {
public:
KisBrightnessContrastConfigWidget(QWidget * parent, const char * name = 0, WFlags f = 0 );
virtual ~KisBrightnessContrastConfigWidget() {};
KisBrightnessContrastFilterConfiguration * config();
WdgBrightnessContrast * m_page;
};
#endif
......@@ -85,7 +85,7 @@
</property>
<widget class="KCurve">
<property name="name">
<cstring>kCurve2</cstring>
<cstring>kCurve</cstring>
</property>
</widget>
</hbox>
......@@ -242,7 +242,7 @@
<customwidgets>
<customwidget>
<class>KCurve</class>
<header location="local">../../ui/widgets/kcurve.h</header>
<header location="local">/home/cbr/kdesvn/koffice/krita/ui/widgets/kcurve.h</header>
<sizehint>
<width>33</width>
<height>23</height>
......
......@@ -247,7 +247,7 @@ void KCurve::mouseReleaseEvent ( QMouseEvent * e )
setCursor( KCursor::arrowCursor() );
m_dragging = false;
repaint(false);
emit signalCurvesChanged();
emit modified();
}
void KCurve::mouseMoveEvent ( QMouseEvent * e )
......@@ -301,7 +301,7 @@ void KCurve::mouseMoveEvent ( QMouseEvent * e )
m_grab_point->x = x;
m_grab_point->y = y;
emit signalCurvesChanged();
emit modified();
}
repaint(false);
......
......@@ -40,7 +40,7 @@ public:
signals:
void signalCurvesChanged(void);
void modified(void);
protected:
......
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