diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-26 00:41:16 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-26 00:41:16 +0000 |
commit | 698569f8428ca088f764d704034a1330517b98c0 (patch) | |
tree | bf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/plugins/filters/levelfilter | |
parent | 2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff) | |
download | koffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz koffice-698569f8428ca088f764d704034a1330517b98c0.zip |
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/plugins/filters/levelfilter')
-rw-r--r-- | chalk/plugins/filters/levelfilter/Makefile.am | 25 | ||||
-rw-r--r-- | chalk/plugins/filters/levelfilter/chalklevelfilter.desktop | 73 | ||||
-rw-r--r-- | chalk/plugins/filters/levelfilter/kgradientslider.cc | 338 | ||||
-rw-r--r-- | chalk/plugins/filters/levelfilter/kgradientslider.h | 85 | ||||
-rw-r--r-- | chalk/plugins/filters/levelfilter/kis_level_filter.cc | 324 | ||||
-rw-r--r-- | chalk/plugins/filters/levelfilter/kis_level_filter.h | 94 | ||||
-rw-r--r-- | chalk/plugins/filters/levelfilter/levelfilter.cc | 67 | ||||
-rw-r--r-- | chalk/plugins/filters/levelfilter/levelfilter.h | 35 | ||||
-rw-r--r-- | chalk/plugins/filters/levelfilter/wdg_level.ui | 331 |
9 files changed, 1372 insertions, 0 deletions
diff --git a/chalk/plugins/filters/levelfilter/Makefile.am b/chalk/plugins/filters/levelfilter/Makefile.am new file mode 100644 index 000000000..2f6fb4597 --- /dev/null +++ b/chalk/plugins/filters/levelfilter/Makefile.am @@ -0,0 +1,25 @@ +kde_services_DATA = chalklevelfilter.desktop + +INCLUDES = -I$(srcdir)/../../../sdk \ + -I$(srcdir)/../../../core \ + -I$(srcdir)/../../../chalkcolor/ \ + -I$(srcdir)/../../../ui \ + $(KOFFICE_INCLUDES) \ + $(all_includes) + +chalklevelfilter_la_SOURCES = levelfilter.cc \ + wdg_level.ui \ + kis_level_filter.cc \ + kgradientslider.cc + +noinst_HEADERS = levelfilter.h \ + kis_level_filter.h \ + kgradientslider.h + +chalklevelfilter_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_QT) -lkdecore -lkdeui -lkjs -lkdefx -lkio -lkparts -L../../../../chalk/chalkcolor/.libs -lchalkcolor -L../../../../chalk/core/.libs -lchalkimage \ + -L../../../../chalk/ui/.libs -lchalkui +chalklevelfilter_la_LIBADD = ../../../libchalkcommon.la + +kde_module_LTLIBRARIES = chalklevelfilter.la + +chalklevelfilter_la_METASOURCES = AUTO diff --git a/chalk/plugins/filters/levelfilter/chalklevelfilter.desktop b/chalk/plugins/filters/levelfilter/chalklevelfilter.desktop new file mode 100644 index 000000000..8426b08d6 --- /dev/null +++ b/chalk/plugins/filters/levelfilter/chalklevelfilter.desktop @@ -0,0 +1,73 @@ +[Desktop Entry] +Name=Levels +Name[bg]=Нива +Name[br]=Liveoù +Name[ca]=Nivells +Name[da]=Niveauer +Name[de]=Stufen +Name[el]=Επίπεδα +Name[eo]=Niveloj +Name[es]=Niveles +Name[et]=Tasemed +Name[fa]=سطوح +Name[fy]=Nivo's +Name[hr]=Razine +Name[hu]=Szintek +Name[it]=Livelli +Name[ja]=レベル +Name[km]=កម្រិត +Name[lt]=Lygiai +Name[nb]=Nivåer +Name[nds]=Stopen +Name[ne]=स्तर +Name[nl]=Niveaus +Name[pl]=Poziomy +Name[pt]=Níveis +Name[pt_BR]=Níveis +Name[ru]=Уровни +Name[se]=Dásit +Name[sk]=Úrovne +Name[sl]=Ravni +Name[sr]=Нивои +Name[sr@Latn]=Nivoi +Name[sv]=Nivåer +Name[uk]=Рівні +Name[zh_TW]=等級 +Comment=Levels +Comment[bg]=Нива +Comment[br]=Liveoù +Comment[ca]=Nivells +Comment[da]=Niveauer +Comment[de]=Stufen +Comment[el]=Επίπεδα +Comment[eo]=Niveloj +Comment[es]=Niveles +Comment[et]=Tasemed +Comment[fa]=سطوح +Comment[fy]=Nivo's +Comment[hr]=Razine +Comment[hu]=Szintek +Comment[it]=Livelli +Comment[ja]=レベル +Comment[km]=កម្រិត +Comment[lt]=Lygiai +Comment[nb]=Nivåer +Comment[nds]=Stopen +Comment[ne]=स्तर +Comment[nl]=Niveaus +Comment[pl]=Poziomy +Comment[pt]=Níveis +Comment[pt_BR]=Níveis +Comment[ru]=Уровни +Comment[se]=Dásit +Comment[sk]=Úrovne +Comment[sl]=Ravni +Comment[sr]=Нивои +Comment[sr@Latn]=Nivoi +Comment[sv]=Nivåer +Comment[uk]=Рівні +Comment[zh_TW]=等級 +ServiceTypes=Chalk/Filter +Type=Service +X-KDE-Library=chalklevelfilter +X-Chalk-Version=2 diff --git a/chalk/plugins/filters/levelfilter/kgradientslider.cc b/chalk/plugins/filters/levelfilter/kgradientslider.cc new file mode 100644 index 000000000..104ef3758 --- /dev/null +++ b/chalk/plugins/filters/levelfilter/kgradientslider.cc @@ -0,0 +1,338 @@ +/* + * This file is part of Chalk + * + * Copyright (c) 2006 Frederic Coiffier <fcoiffie@gmail.com> + * + * 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +// C++ includes. + +#include <cmath> +#include <cstdlib> + +// TQt includes. + +#include <tqpixmap.h> +#include <tqpainter.h> +#include <tqpoint.h> +#include <tqpen.h> + +// Local includes. + +#include "kgradientslider.h" + +KGradientSlider::KGradientSlider(TQWidget *tqparent, const char *name, WFlags f) + : TQWidget(tqparent, name, f) +{ + m_dragging = false; + + setMouseTracking(true); + setPaletteBackgroundColor(TQt::NoBackground); + setMaximumSize(255, 28); + + m_blackcursor = 0; + m_whitecursor = 255; + m_gamma = 1.0; + m_gammaEnabled = false; + setFocusPolicy(TQ_StrongFocus); +} + +KGradientSlider::~KGradientSlider() +{ +} + +void KGradientSlider::paintEvent(TQPaintEvent *) +{ + int x, y; + int wWidth = width(); + int wHeight = height(); + + int gradientHeight = (wHeight / 3); + + // A TQPixmap is used for enable the double buffering. + /*if (!m_dragging) {*/ + TQPixmap pm(size()); + TQPainter p1; + p1.tqbegin(TQT_TQPAINTDEVICE(&pm), this); + + pm.fill(); + + // Draw first gradient + y = 0; + p1.setPen(TQPen::TQPen(TQColor(0,0,0),1, TQt::SolidLine)); + for( x=0; x<255; ++x ) + { + int gray = (255 * x) / wWidth; + p1.setPen(TQColor(gray, gray, gray)); + p1.drawLine(x, y, x, y + gradientHeight - 1); + } + + // Draw second gradient + y = (wHeight / 3); + if (m_blackcursor > 0) { + p1.fillRect(0, y, (int)m_blackcursor, gradientHeight, TQBrush(TQt::black)); + } + if (m_whitecursor < 255) { + p1.fillRect((int)m_whitecursor, y, 255, gradientHeight, TQBrush(TQt::white)); + } + for(x = (int)m_blackcursor; x < (int)m_whitecursor; ++x ) + { + double inten = (double)(x - m_blackcursor) / (double)(m_whitecursor - m_blackcursor); + inten = pow (inten, (1.0 / m_gamma)); + int gray = (int)(255 * inten); + p1.setPen(TQColor(gray, gray, gray)); + p1.drawLine(x, y, x, y + gradientHeight - 1); + } + + // Draw cursors + y = (2 * wHeight / 3); + TQPointArray *a = new TQPointArray(3); + p1.setPen(TQt::black); + + a->setPoint(0, m_blackcursor, y); + a->setPoint(1, m_blackcursor + 3, wHeight - 1); + a->setPoint(2, m_blackcursor - 3, wHeight - 1); + p1.setBrush(TQt::black); + p1.drawPolygon(*a); + + if (m_gammaEnabled) { + a->setPoint(0, m_gammacursor, y); + a->setPoint(1, m_gammacursor + 3, wHeight - 1); + a->setPoint(2, m_gammacursor - 3, wHeight - 1); + p1.setBrush(TQt::gray); + p1.drawPolygon(*a); + } + + a->setPoint(0, m_whitecursor, y); + a->setPoint(1, m_whitecursor + 3, wHeight - 1); + a->setPoint(2, m_whitecursor - 3, wHeight - 1); + p1.setBrush(TQt::white); + p1.drawPolygon(*a); + + p1.end(); + bitBlt(this, 0, 0, &pm); +} + +void KGradientSlider::mousePressEvent ( TQMouseEvent * e ) +{ + eCursor closest_cursor; + int distance; + + if (e->button() != Qt::LeftButton) + return; + + unsigned int x = e->pos().x(); + + distance = 1000; // just a big number + + if (abs((int)(x - m_blackcursor)) < distance) + { + distance = abs((int)(x - m_blackcursor)); + closest_cursor = BlackCursor; + } + + if (abs((int)(x - m_whitecursor)) < distance) + { + distance = abs((int)(x - m_whitecursor)); + closest_cursor = WhiteCursor; + } + + if (m_gammaEnabled && (abs((int)(x - m_gammacursor)) < distance)) + { + distance = abs((int)(x - m_gammacursor)); + closest_cursor = GammaCursor; + } + + if (distance > 20) + { + return; + } + + + m_dragging = true; + + // Determine cursor values and the leftmost and rightmost points. + + switch (closest_cursor) { + case BlackCursor: + m_blackcursor = x; + m_grab_cursor = closest_cursor; + m_leftmost = 0; + m_rightmost = m_whitecursor; + if (m_gammaEnabled) { + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = log10 (1.0 / m_gamma); + m_gammacursor = (unsigned int)tqRound(mid + delta * tmp); + } + break; + case WhiteCursor: + m_whitecursor = x; + m_grab_cursor = closest_cursor; + m_leftmost = m_blackcursor; + m_rightmost = 255; + if (m_gammaEnabled) { + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = log10 (1.0 / m_gamma); + m_gammacursor = (unsigned int)tqRound(mid + delta * tmp); + } + break; + case GammaCursor: + m_gammacursor = x; + m_grab_cursor = closest_cursor; + m_leftmost = m_blackcursor; + m_rightmost = m_whitecursor; + + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = (x - mid) / delta; + m_gamma = 1.0 / pow (10, tmp); + break; + } + tqrepaint(false); +} + +void KGradientSlider::mouseReleaseEvent ( TQMouseEvent * e ) +{ + if (e->button() != Qt::LeftButton) + return; + + m_dragging = false; + tqrepaint(false); + + switch (m_grab_cursor) { + case BlackCursor: + emit modifiedBlack(m_blackcursor); + break; + case WhiteCursor: + emit modifiedWhite(m_whitecursor); + break; + case GammaCursor: + emit modifiedGamma(m_gamma); + break; + } +} + +void KGradientSlider::mouseMoveEvent ( TQMouseEvent * e ) +{ + unsigned int x = abs(e->pos().x()); + + if (m_dragging == true) // Else, drag the selected point + { + if (x <= m_leftmost) + x = m_leftmost; + + if(x >= m_rightmost) + x = m_rightmost; + + /*if(x > 255) + x = 255; + + if(x < 0) + x = 0;*/ + + switch (m_grab_cursor) { + case BlackCursor: + if (m_blackcursor != x) + { + m_blackcursor = x; + if (m_gammaEnabled) { + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = log10 (1.0 / m_gamma); + m_gammacursor = (unsigned int)tqRound(mid + delta * tmp); + } + } + break; + case WhiteCursor: + if (m_whitecursor != x) + { + m_whitecursor = x; + if (m_gammaEnabled) { + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = log10 (1.0 / m_gamma); + m_gammacursor = (unsigned int)tqRound(mid + delta * tmp); + } + } + break; + case GammaCursor: + if (m_gammacursor != x) + { + m_gammacursor = x; + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = (x - mid) / delta; + m_gamma = 1.0 / pow (10, tmp); + } + break; + } + } + + tqrepaint(false); +} + +void KGradientSlider::leaveEvent( TQEvent * ) +{ +} + + +void KGradientSlider::enableGamma(bool b) +{ + m_gammaEnabled = b; + tqrepaint(false); +} + +double KGradientSlider::getGamma(void) +{ + return m_gamma; +} + +void KGradientSlider::modifyBlack(int v) { + if (v >= 0 && v <= (int)m_whitecursor) { + m_blackcursor = (unsigned int)v; + if (m_gammaEnabled) { + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = log10 (1.0 / m_gamma); + m_gammacursor = (unsigned int)tqRound(mid + delta * tmp); + } + tqrepaint(false); + } +} +void KGradientSlider::modifyWhite(int v) { + if (v >= (int)m_blackcursor && v <= 255) { + m_whitecursor = (unsigned int)v; + if (m_gammaEnabled) { + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = log10 (1.0 / m_gamma); + m_gammacursor = (unsigned int)tqRound(mid + delta * tmp); + } + tqrepaint(false); + } +} +void KGradientSlider::modifyGamma(double v) { + m_gamma = v; + double delta = (double) (m_whitecursor - m_blackcursor) / 2.0; + double mid = (double)m_blackcursor + delta; + double tmp = log10 (1.0 / m_gamma); + m_gammacursor = (unsigned int)tqRound(mid + delta * tmp); + tqrepaint(false); +} + +#include "kgradientslider.moc" diff --git a/chalk/plugins/filters/levelfilter/kgradientslider.h b/chalk/plugins/filters/levelfilter/kgradientslider.h new file mode 100644 index 000000000..c8990c805 --- /dev/null +++ b/chalk/plugins/filters/levelfilter/kgradientslider.h @@ -0,0 +1,85 @@ +/* + * This file is part of Chalk + * + * Copyright (c) 2006 Frederic Coiffier <fcoiffie@gmail.com> + * + * 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KGRADIENTSLIDER_H +#define KGRADIENTSLIDER_H + +// TQt includes. + +#include <tqwidget.h> +#include <tqcolor.h> +#include <tqptrlist.h> +#include <tqpair.h> + +class KGradientSlider : public TQWidget +{ +Q_OBJECT + TQ_OBJECT + + typedef enum { + BlackCursor, + GammaCursor, + WhiteCursor + } eCursor; + +public: + KGradientSlider(TQWidget *tqparent = 0, const char *name = 0, WFlags f = 0); + + virtual ~KGradientSlider(); + +public slots: + void modifyBlack(int); + void modifyWhite(int); + void modifyGamma(double); + +signals: + + void modifiedBlack(int); + void modifiedWhite(int); + void modifiedGamma(double); + +protected: + void paintEvent(TQPaintEvent *); + void mousePressEvent (TQMouseEvent * e); + void mouseReleaseEvent ( TQMouseEvent * e ); + void mouseMoveEvent ( TQMouseEvent * e ); + void leaveEvent ( TQEvent * ); + +public: + void enableGamma(bool b); + double getGamma(void); + +private: + unsigned int m_leftmost; + unsigned int m_rightmost; + eCursor m_grab_cursor; + unsigned int m_grab_index; + bool m_dragging; + + unsigned int m_blackcursor; + unsigned int m_whitecursor; + unsigned int m_gammacursor; + + bool m_gammaEnabled; + double m_gamma; +}; + + +#endif /* KGRADIENTSLIDER_H */ diff --git a/chalk/plugins/filters/levelfilter/kis_level_filter.cc b/chalk/plugins/filters/levelfilter/kis_level_filter.cc new file mode 100644 index 000000000..6b8dd6a09 --- /dev/null +++ b/chalk/plugins/filters/levelfilter/kis_level_filter.cc @@ -0,0 +1,324 @@ +/* + * This file is part of Chalk + * + * Copyright (c) 2006 Frederic Coiffier <fcoiffie@gmail.com> + * + * 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <math.h> + +#include <klocale.h> + +#include <tqlayout.h> +#include <tqpixmap.h> +#include <tqpainter.h> +#include <tqlabel.h> +#include <tqspinbox.h> + +#include "kis_filter_config_widget.h" +#include "kis_level_filter.h" +#include "wdg_level.h" +#include "kis_colorspace.h" +#include "kis_paint_device.h" +#include "kis_iterators_pixel.h" +#include "kis_iterator.h" +#include "kis_histogram.h" +#include "kis_basic_histogram_producers.h" +#include "kis_painter.h" +#include "kgradientslider.h" + +KisLevelFilterConfiguration::KisLevelFilterConfiguration() + : KisFilterConfiguration( "levels", 1 ) +{ + whitevalue = 255; + blackvalue = 0; + gammavalue = 1.0; + + outwhitevalue = 0xFFFF; + outblackvalue = 0; + + m_adjustment = 0; +} + +KisLevelFilterConfiguration::~KisLevelFilterConfiguration() +{ + delete m_adjustment; +} + +void KisLevelFilterConfiguration::fromXML( const TQString& s ) +{ + KisFilterConfiguration::fromXML(s); + blackvalue = getInt( "blackvalue" ); + whitevalue = getInt( "whitevalue" ); + gammavalue = getDouble( "gammavalue" ); + outblackvalue = getInt( "outblackvalue" ); + outwhitevalue = getInt( "outwhitevalue" ); +} + +TQString KisLevelFilterConfiguration::toString() +{ + m_properties.clear(); + setProperty("blackvalue", blackvalue); + setProperty("whitevalue", whitevalue); + setProperty("gammavalue", gammavalue); + setProperty("outblackvalue", outblackvalue); + setProperty("outwhitevalue", outwhitevalue); + + return KisFilterConfiguration::toString(); +} + +KisLevelFilter::KisLevelFilter() + : KisFilter( id(), "adjust", i18n("&Levels")) +{ + +} + +KisFilterConfigWidget * KisLevelFilter::createConfigurationWidget(TQWidget *tqparent, KisPaintDeviceSP dev) +{ + return new KisLevelConfigWidget(tqparent, dev); +} + +KisFilterConfiguration* KisLevelFilter::configuration(TQWidget *nwidget) +{ + KisLevelConfigWidget* widget = (KisLevelConfigWidget*)nwidget; + + if ( widget == 0 ) + { + return new KisLevelFilterConfiguration(); + } else { + return widget->config(); + } +} + +std::list<KisFilterConfiguration*> KisLevelFilter::listOfExamplesConfiguration(KisPaintDeviceSP /*dev*/) +{ + //XXX should really come up with a list of configurations + std::list<KisFilterConfiguration*> list; + list.insert(list.begin(), new KisLevelFilterConfiguration( )); + return list; +} + +bool KisLevelFilter::workWith(KisColorSpace* cs) +{ + return (cs->getProfile() != 0); +} + + +void KisLevelFilter::process(KisPaintDeviceSP src, KisPaintDeviceSP dst, KisFilterConfiguration* config, const TQRect& rect) +{ + + if (!config) { + kdWarning() << "No configuration object for level filter\n"; + return; + } + + KisLevelFilterConfiguration* configBC = (KisLevelFilterConfiguration*) config; + Q_ASSERT(config); + + if (src!=dst) { + KisPainter gc(dst); + gc.bitBlt(rect.x(), rect.y(), COMPOSITE_COPY, src, rect.x(), rect.y(), rect.width(), rect.height()); + gc.end(); + } + + if (configBC->m_adjustment == 0) { + TQ_UINT16 transfer[256]; + for (int i = 0; i < 256; i++) { + if (i <= configBC->blackvalue) + transfer[i] = configBC->outblackvalue; + else if (i < configBC->whitevalue) + { + double a = (double)(i - configBC->blackvalue) / (double)(configBC->whitevalue - configBC->blackvalue); + a = (double)(configBC->outwhitevalue - configBC->outblackvalue) * pow (a, (1.0 / configBC->gammavalue)); + transfer[i] = int(configBC->outblackvalue + a); + } + else + transfer[i] = configBC->outwhitevalue; + } + configBC->m_adjustment = src->colorSpace()->createBrightnessContrastAdjustment(transfer); + } + + KisRectIteratorPixel iter = dst->createRectIterator(rect.x(), rect.y(), rect.width(), rect.height(), true ); + + setProgressTotalSteps(rect.width() * rect.height()); + TQ_INT32 pixelsProcessed = 0; + + while( ! iter.isDone() && !cancelRequested()) + { + TQ_UINT32 npix=0, maxpix = iter.nConseqPixels(); + TQ_UINT8 selectedness = iter.selectedness(); + // The idea here is to handle stretches of completely selected and completely unselected pixels. + // Partially selected pixels are handled one pixel at a time. + switch(selectedness) + { + case MIN_SELECTED: + while(iter.selectedness()==MIN_SELECTED && maxpix) + { + --maxpix; + ++iter; + ++npix; + } + pixelsProcessed += npix; + break; + + case MAX_SELECTED: + { + TQ_UINT8 *firstPixel = iter.rawData(); + while(iter.selectedness()==MAX_SELECTED && maxpix) + { + --maxpix; + if (maxpix != 0) + ++iter; + ++npix; + } + // adjust + src->colorSpace()->applyAdjustment(firstPixel, firstPixel, configBC->m_adjustment, npix); + pixelsProcessed += npix; + ++iter; + break; + } + + default: + // adjust, but since it's partially selected we also only partially adjust + src->colorSpace()->applyAdjustment(iter.oldRawData(), iter.rawData(), configBC->m_adjustment, 1); + const TQ_UINT8 *pixels[2] = {iter.oldRawData(), iter.rawData()}; + TQ_UINT8 weights[2] = {MAX_SELECTED - selectedness, selectedness}; + src->colorSpace()->mixColors(pixels, weights, 2, iter.rawData()); + ++iter; + pixelsProcessed++; + break; + } + setProgress(pixelsProcessed); + } + + setProgressDone(); +} + +KisLevelConfigWidget::KisLevelConfigWidget(TQWidget * tqparent, KisPaintDeviceSP dev, const char * name, WFlags f) + : KisFilterConfigWidget(tqparent, name, f) +{ + m_page = new WdgLevel(this); + histogram = NULL; + + m_page->ingradient->enableGamma(true); + m_page->blackspin->setValue(0); + m_page->whitespin->setValue(255); + m_page->gammaspin->setNum(1.0); + m_page->ingradient->modifyGamma(1.0); + m_page->outblackspin->setValue(0); + m_page->outwhitespin->setValue(255); + + TQHBoxLayout * l = new TQHBoxLayout(this); + Q_CHECK_PTR(l); + l->addWidget(m_page, 0, TQt::AlignTop); + + connect( m_page->blackspin, TQT_SIGNAL(valueChanged(int)), TQT_SIGNAL(sigPleaseUpdatePreview())); + connect( m_page->whitespin, TQT_SIGNAL(valueChanged(int)), TQT_SIGNAL(sigPleaseUpdatePreview())); + connect( m_page->ingradient, TQT_SIGNAL(modifiedGamma(double)), TQT_SIGNAL(sigPleaseUpdatePreview())); + + connect( m_page->blackspin, TQT_SIGNAL(valueChanged(int)), m_page->ingradient, TQT_SLOT(modifyBlack(int))); + connect( m_page->whitespin, TQT_SIGNAL(valueChanged(int)), m_page->ingradient, TQT_SLOT(modifyWhite(int))); + //connect( m_page->whitespin, TQT_SIGNAL(valueChanged(int)), m_page->ingradient, TQT_SLOT(modifyGamma())); + + connect( m_page->ingradient, TQT_SIGNAL(modifiedBlack(int)), m_page->blackspin, TQT_SLOT(setValue(int))); + connect( m_page->ingradient, TQT_SIGNAL(modifiedWhite(int)), m_page->whitespin, TQT_SLOT(setValue(int))); + connect( m_page->ingradient, TQT_SIGNAL(modifiedGamma(double)), m_page->gammaspin, TQT_SLOT(setNum(double))); + + + connect( m_page->outblackspin, TQT_SIGNAL(valueChanged(int)), TQT_SIGNAL(sigPleaseUpdatePreview())); + connect( m_page->outwhitespin, TQT_SIGNAL(valueChanged(int)), TQT_SIGNAL(sigPleaseUpdatePreview())); + + connect( m_page->outblackspin, TQT_SIGNAL(valueChanged(int)), m_page->outgradient, TQT_SLOT(modifyBlack(int))); + connect( m_page->outwhitespin, TQT_SIGNAL(valueChanged(int)), m_page->outgradient, TQT_SLOT(modifyWhite(int))); + + connect( m_page->outgradient, TQT_SIGNAL(modifiedBlack(int)), m_page->outblackspin, TQT_SLOT(setValue(int))); + connect( m_page->outgradient, TQT_SIGNAL(modifiedWhite(int)), m_page->outwhitespin, TQT_SLOT(setValue(int))); + + connect( (TQObject*)(m_page->chkLogarithmic), TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(drawHistogram(bool))); + + KisHistogramProducerSP producer = new KisGenericLabHistogramProducer(); + histogram = new KisHistogram(dev, producer, LINEAR); + m_histlog = false; + drawHistogram(); + +} + +KisLevelConfigWidget::~KisLevelConfigWidget() +{ + delete histogram; +} + +void KisLevelConfigWidget::drawHistogram(bool logarithmic) +{ + int height = 256; + + if (m_histlog != logarithmic) { + // Update the histogram + if (logarithmic) + histogram->setHistogramType(LOGARITHMIC); + else + histogram->setHistogramType(LINEAR); + m_histlog = logarithmic; + } + + TQPixmap pix(256, height); + pix.fill(); + TQPainter p(&pix); + p.setPen(TQPen::TQPen(TQt::gray,1, TQt::SolidLine)); + + double highest = (double)histogram->calculations().getHighest(); + TQ_INT32 bins = histogram->producer()->numberOfBins(); + + if (histogram->getHistogramType() == LINEAR) { + double factor = (double)height / highest; + for( int i=0; i<bins; ++i ) { + p.drawLine(i, height, i, height - int(histogram->getValue(i) * factor)); + } + } else { + double factor = (double)height / (double)log(highest); + for( int i = 0; i < bins; ++i ) { + p.drawLine(i, height, i, height - int(log((double)histogram->getValue(i)) * factor)); + } + } + + m_page->histview->setPixmap(pix); +} + +KisLevelFilterConfiguration * KisLevelConfigWidget::config() +{ + KisLevelFilterConfiguration * cfg = new KisLevelFilterConfiguration(); + + cfg->blackvalue = m_page->blackspin->value(); + cfg->whitevalue = m_page->whitespin->value(); + cfg->gammavalue = m_page->ingradient->getGamma(); + + cfg->outblackvalue = m_page->outblackspin->value() * 255; + cfg->outwhitevalue = m_page->outwhitespin->value() * 255; + + return cfg; +} + +void KisLevelConfigWidget::setConfiguration( KisFilterConfiguration * config ) +{ + KisLevelFilterConfiguration * cfg = dynamic_cast<KisLevelFilterConfiguration *>(config); + m_page->blackspin->setValue(cfg->blackvalue); + m_page->whitespin->setValue(cfg->whitevalue); + m_page->ingradient->modifyGamma(cfg->gammavalue); + + m_page->outblackspin->setValue(cfg->outblackvalue / 255); + m_page->outwhitespin->setValue(cfg->outwhitevalue / 255); +} + diff --git a/chalk/plugins/filters/levelfilter/kis_level_filter.h b/chalk/plugins/filters/levelfilter/kis_level_filter.h new file mode 100644 index 000000000..8f3d3591b --- /dev/null +++ b/chalk/plugins/filters/levelfilter/kis_level_filter.h @@ -0,0 +1,94 @@ +/* + * This file is part of Chalk + * + * Copyright (c) 2006 Frederic Coiffier <fcoiffie@gmail.com> + * + * 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _KIS_LEVEL_FILTER_H_ +#define _KIS_LEVEL_FILTER_H_ + +#include "kis_filter.h" +#include "kis_filter_config_widget.h" + +class WdgLevel; +class TQWidget; +class KisColorAdjustment; +class KisHistogram; + +class KisLevelFilterConfiguration : public KisFilterConfiguration { + +public: + + KisLevelFilterConfiguration(); + virtual ~KisLevelFilterConfiguration(); + virtual void fromXML( const TQString& ); + virtual TQString toString(); + +public: + TQ_UINT8 blackvalue, whitevalue; + double gammavalue; + TQ_UINT16 outblackvalue, outwhitevalue; + KisColorAdjustment * m_adjustment; +}; + +/** + * This class affect Intensity Y of the image + */ +class KisLevelFilter : public KisFilter +{ + +public: + + KisLevelFilter(); + +public: + + virtual KisFilterConfigWidget * createConfigurationWidget(TQWidget* tqparent, KisPaintDeviceSP dev); + virtual KisFilterConfiguration * configuration(TQWidget *); + virtual KisFilterConfiguration * configuration() { return new KisLevelFilterConfiguration(); }; + virtual void process(KisPaintDeviceSP, KisPaintDeviceSP, KisFilterConfiguration* , const TQRect&); + static inline KisID id() { return KisID("levels", i18n("Levels")); }; + virtual bool supportsPainting() { return true; } + virtual bool supportsPreview() { return true; } + virtual bool supportsIncrementalPainting() { return false; } + virtual std::list<KisFilterConfiguration*> listOfExamplesConfiguration(KisPaintDeviceSP dev); + + virtual ColorSpaceIndependence colorSpaceIndependence() { return TO_LAB16; }; + virtual bool workWith(KisColorSpace* cs); +}; + + +class KisLevelConfigWidget : public KisFilterConfigWidget { +Q_OBJECT + TQ_OBJECT +public: + KisLevelConfigWidget(TQWidget * tqparent, KisPaintDeviceSP dev, const char * name = 0, WFlags f = 0 ); + virtual ~KisLevelConfigWidget(); + + KisLevelFilterConfiguration * config(); + void setConfiguration( KisFilterConfiguration * config ); + WdgLevel * m_page; + +protected slots: + void drawHistogram(bool logarithmic = false); + +protected: + KisHistogram *histogram; + bool m_histlog; +}; + +#endif diff --git a/chalk/plugins/filters/levelfilter/levelfilter.cc b/chalk/plugins/filters/levelfilter/levelfilter.cc new file mode 100644 index 000000000..669775fbc --- /dev/null +++ b/chalk/plugins/filters/levelfilter/levelfilter.cc @@ -0,0 +1,67 @@ +/* + * This file is part of Chalk + * + * Copyright (c) 2006 Frederic Coiffier <fcoiffie@gmail.com> + * + * 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <math.h> + +#include <stdlib.h> +#include <string.h> + +#include <tqslider.h> +#include <tqpoint.h> +#include <tqcolor.h> + +#include <klocale.h> +#include <kiconloader.h> +#include <kinstance.h> +#include <kmessagebox.h> +#include <kstandarddirs.h> +#include <ktempfile.h> +#include <kdebug.h> +#include <kgenericfactory.h> + +#include <kis_doc.h> +#include <kis_image.h> +#include <kis_layer.h> +#include <kis_global.h> +#include <kis_types.h> +#include <kis_iterators_pixel.h> +#include <kis_colorspace.h> +#include <kis_painter.h> +#include <kis_selection.h> +#include "levelfilter.h" +#include "kis_level_filter.h" + +typedef KGenericFactory<LevelFilter> LevelFilterFactory; +K_EXPORT_COMPONENT_FACTORY( chalklevelfilter, LevelFilterFactory( "chalk" ) ) + +LevelFilter::LevelFilter(TQObject *tqparent, const char *name, const TQStringList &) + : KParts::Plugin(tqparent, name) +{ + setInstance(LevelFilterFactory::instance()); + + if (tqparent->inherits("KisFilterRegistry")) { + KisFilterRegistry * manager = dynamic_cast<KisFilterRegistry *>(tqparent); + manager->add(new KisLevelFilter()); + } +} + +LevelFilter::~LevelFilter() +{ +} diff --git a/chalk/plugins/filters/levelfilter/levelfilter.h b/chalk/plugins/filters/levelfilter/levelfilter.h new file mode 100644 index 000000000..69627ff7f --- /dev/null +++ b/chalk/plugins/filters/levelfilter/levelfilter.h @@ -0,0 +1,35 @@ +/* + * This file is part of Chalk + * + * Copyright (c) 2006 Frederic Coiffier <fcoiffie@gmail.com> + * + * 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef LEVEL_H +#define LEVEL_H + +#include <kparts/plugin.h> + +class KisColorSpace; +class KisColorAdjustment; + +class LevelFilter : public KParts::Plugin +{ + public: + LevelFilter(TQObject *tqparent, const char *name, const TQStringList &); + virtual ~LevelFilter(); +}; + +#endif diff --git a/chalk/plugins/filters/levelfilter/wdg_level.ui b/chalk/plugins/filters/levelfilter/wdg_level.ui new file mode 100644 index 000000000..0db94640c --- /dev/null +++ b/chalk/plugins/filters/levelfilter/wdg_level.ui @@ -0,0 +1,331 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>WdgLevel</class> +<widget class="TQWidget"> + <property name="name"> + <cstring>WdgLevel</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>269</width> + <height>479</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="tqminimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="tqmaximumSize"> + <size> + <width>32767</width> + <height>32767</height> + </size> + </property> + <property name="caption"> + <string>Levels</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="TQCheckBox" row="0" column="0"> + <property name="name"> + <cstring>chkLogarithmic</cstring> + </property> + <property name="text"> + <string>Logarithmic</string> + </property> + </widget> + <widget class="TQLabel" row="1" column="0"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string><b>Input levels</b></string> + </property> + </widget> + <widget class="TQLayoutWidget" row="2" column="0"> + <property name="name"> + <cstring>tqlayout7</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLabel"> + <property name="name"> + <cstring>histview</cstring> + </property> + <property name="tqminimumSize"> + <size> + <width>256</width> + <height>256</height> + </size> + </property> + <property name="tqmaximumSize"> + <size> + <width>256</width> + <height>256</height> + </size> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>tqlayout5</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KGradientSlider"> + <property name="name"> + <cstring>ingradient</cstring> + </property> + <property name="tqminimumSize"> + <size> + <width>256</width> + <height>20</height> + </size> + </property> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>tqlayout5</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQSpinBox"> + <property name="name"> + <cstring>blackspin</cstring> + </property> + <property name="buttonSymbols"> + <enum>PlusMinus</enum> + </property> + <property name="maxValue"> + <number>255</number> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer5</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>MinimumExpanding</enum> + </property> + <property name="tqsizeHint"> + <size> + <width>25</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQLabel"> + <property name="name"> + <cstring>gammaspin</cstring> + </property> + <property name="text"> + <string>1.0</string> + </property> + <property name="tqalignment"> + <set>AlignCenter</set> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer6</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>MinimumExpanding</enum> + </property> + <property name="tqsizeHint"> + <size> + <width>25</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQSpinBox"> + <property name="name"> + <cstring>whitespin</cstring> + </property> + <property name="buttonSymbols"> + <enum>PlusMinus</enum> + </property> + <property name="maxValue"> + <number>255</number> + </property> + </widget> + </hbox> + </widget> + </vbox> + </widget> + <widget class="TQLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string><b>Output levels</b></string> + </property> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>tqlayout6</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KGradientSlider"> + <property name="name"> + <cstring>outgradient</cstring> + </property> + <property name="tqminimumSize"> + <size> + <width>256</width> + <height>20</height> + </size> + </property> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>tqlayout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQSpinBox"> + <property name="name"> + <cstring>outblackspin</cstring> + </property> + <property name="buttonSymbols"> + <enum>PlusMinus</enum> + </property> + <property name="maxValue"> + <number>255</number> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>MinimumExpanding</enum> + </property> + <property name="tqsizeHint"> + <size> + <width>50</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="TQSpinBox"> + <property name="name"> + <cstring>outwhitespin</cstring> + </property> + <property name="buttonSymbols"> + <enum>PlusMinus</enum> + </property> + <property name="maxValue"> + <number>255</number> + </property> + </widget> + </hbox> + </widget> + </vbox> + </widget> + </vbox> + </widget> + <spacer row="2" column="1"> + <property name="name"> + <cstring>spacer5_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="tqsizeHint"> + <size> + <width>21</width> + <height>20</height> + </size> + </property> + </spacer> + <spacer row="3" column="0"> + <property name="name"> + <cstring>spacer6_2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="tqsizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> +</widget> +<customwidgets> + <customwidget> + <class>KGradientSlider</class> + <header location="local">kgradientslider.h</header> + <sizehint> + <width>-1</width> + <height>-1</height> + </sizehint> + <container>0</container> + <sizepolicy> + <hordata>0</hordata> + <verdata>0</verdata> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + <pixmap>image0</pixmap> + </customwidget> +</customwidgets> +<images> + <image name="image0"> + <data format="PNG" length="1002">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000003b149444154388dad945f4c5b551cc73fe7dc4b7b4bcba0762d45c43114323599ee6192609c51d883892ce083f1718b3ebb185f8dc91e972cf39d2d2a2f1af664b6f1e0fe3863a0718969700eb0c52142da0242a1bd6d696f7bcff101585203ceb8fd9ece39f99dcff9fe7edf939f88c562ec465f5f9fe609442c161362173c3e3eae7b7a7ac8e7f36432196cdbfe4f907c3e4f2291201e8fe338cec3737357e9e8e828aded1e229d650e1f2d51754b082110124c13a4dc5ea341eb9dc284c0558a853f3ce8cb0677ef500fde7d39d2596679e326597b8e9abb85d7a770ab16ab6983ec5a05b487a70e36f0f4e10afe408d6a558310980108478dba4a1e8233990c5d474b64ed39aa3a8fe5f3317fbf81dbd70bccfeb205947632fd74f6589c1c6ea2f70d03a58ba0c1f2c9bdc1b66de3b8256a6e11cbe7e3ee1d181b590124fe2693aeee08d223c82c3a2c24b7b874bec8f26288774f7bd054504aef0dde6e99c0eb83f9fb266323cb80a27fb0958141836044605a2ee5523393371cc646fee2da37195aa35d0c0c5b4859ac03d7e91712dcaac5adab3650a3ff9d08ef7dd8404bb48869e5d958b5b87dadc4c9a1464e9f0d0326df7ebd86bd2e310cb1bf62d384d59441f2d70a070e1c60e09489929b988681bdd9cc97170bcc4c65595f71f8e0e3301337fc24a7732467831875a47f289652b0be5e4151e6d07316c1b0c0340d8ab92023e76d66a6b2840e36d2fb7a13fee632475e6edc367ea98a90fb98b7dd6310ca0328a44761582e1bab41befabcc0ec940d28bc5e93b68e064cab84e1d9beaeb48934eac1f53b01c1b000fca496aa54b61a99fcde61662a4b4b4b23d1680be9d426173e4df3602a48ea411989a4fd590f52a8fd156b05ed9d350e3defe3cfdf4b4c7ce770ea7d3fb9f520afbe1620daeee5c26735d20b9b9cfb6811a754a439e4e5c5639a4caa1e5caf586bfc0197b78702005cb9b4cae4cd3267ce8638fe964bd72b393e39d74928d242617303a756a37f284447770dcdbffc6384a05a85de1306e9a52057c7527c7131c3c42d3f475eb2303c82d4fc3276d6811db37efeb148723082d9b08f79f97c1e5729109a9a28307cc622d2d6cdf52b2b24efe548dedb00142009862cfa879ee1a71f6cec928353511472fbf4389148b0b0e0c108081412458dfe21c9f11351e67e7358595468246d1d1e5e38a6e9e851bc39d84ab502a669331dafec0d8ec7e3e8cb06e1a881d727d1ae40180a434a8c9db129a54126ad48a7358c2b4c5352c8c374bcccdab2bb37d8719cba79fab8211f9df218e0582c261e95f8bfc04f1a1e8bc5c4dfe0a190172af6a9690000000049454e44ae426082</data> + </image> +</images> +<tqlayoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kgradientslider.h</includehint> + <includehint>kgradientslider.h</includehint> +</includehints> +</UI> |