Commit 6c1469d4 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Use KisFilterStrategyRegistry to access the filter strategies

* This fixes a memory leak when using the filter strategies in
scripting
* This adds a method to the Krita api to get all installed
filter strategies
* Fixes a typo on the KisFilterStrategy api

Note: in scripts, you now need to use the real id of the strategies,
and those start for no good reason at all with caps.
parent e96b768e
......@@ -186,21 +186,21 @@ KisFilterStrategyRegistry::~KisFilterStrategyRegistry()
{
Q_FOREACH (const QString &id, keys()) {
delete get(id);
}
}
dbgRegistry << "deleting KisFilterStrategyRegistry";
}
KisFilterStrategyRegistry* KisFilterStrategyRegistry::instance()
{
if (!s_instance.exists()) {
// s_instance->add(new KisHermiteFilterStrategy);
s_instance->add(new KisHermiteFilterStrategy);
s_instance->add(new KisBicubicFilterStrategy);
s_instance->add(new KisBoxFilterStrategy);
s_instance->add(new KisBilinearFilterStrategy);
// s_instance->add(new KisBellFilterStrategy);
// s_instance->add(new KisBSplineFilterStrategy);
s_instance->add(new KisBellFilterStrategy);
s_instance->add(new KisBSplineFilterStrategy);
s_instance->add(new KisLanczos3FilterStrategy);
// s_instance->add(new KisMitchellFilterStrategy);
s_instance->add(new KisMitchellFilterStrategy);
}
return s_instance;
......@@ -216,7 +216,7 @@ QList<KoID> KisFilterStrategyRegistry::listKeys() const
return answer;
}
QString KisFilterStrategyRegistry::formatedDescriptions() const
QString KisFilterStrategyRegistry::formattedDescriptions() const
{
QString formatedDescription("<html><head/><body>");
......
......@@ -31,7 +31,7 @@ class KRITAIMAGE_EXPORT KisFilterStrategy
{
public:
KisFilterStrategy(KoID id) : m_id(id) {}
virtual ~KisFilterStrategy() {}
virtual ~KisFilterStrategy() { }
QString id() {
return m_id.id();
......@@ -194,7 +194,7 @@ public:
* This function return a string formated in HTML that contains the descriptions of all objects
* (with a non empty description) stored in the registry.
*/
QString formatedDescriptions() const;
QString formattedDescriptions() const;
private:
......
......@@ -416,25 +416,9 @@ void Document::scaleImage(int w, int h, int xres, int yres, QString strategy)
rc.setWidth(w);
rc.setHeight(h);
KisFilterStrategy *actualStrategy = 0;
if (strategy == "hermite") {
actualStrategy = new KisHermiteFilterStrategy();
} else if (strategy == "bicubic") {
actualStrategy = new KisBicubicFilterStrategy();
} else if (strategy == "box") {
actualStrategy = new KisBoxFilterStrategy();
} else if (strategy == "bilinear") {
actualStrategy = new KisBilinearFilterStrategy();
} else if (strategy == "bell") {
actualStrategy = new KisBellFilterStrategy();
} else if (strategy == "bspline") {
actualStrategy = new KisBSplineFilterStrategy();
} else if (strategy == "lanczos3") {
actualStrategy = new KisLanczos3FilterStrategy();
} else if (strategy == "mitchell") {
actualStrategy = new KisMitchellFilterStrategy();
}
KisFilterStrategy *actualStrategy = KisFilterStrategyRegistry::instance()->get(strategy);
if (!actualStrategy) actualStrategy = KisFilterStrategyRegistry::instance()->get("Bicubic");
image->scaleImage(rc.size(), xres, yres, actualStrategy);
}
......
......@@ -369,15 +369,16 @@ public Q_SLOTS:
* @param xres the new xres
* @param yres the new yres
* @param strategy the scaling strategy. There's several ones amongst these that aren't available in the regular UI.
* The list of filters is extensible and can be retrieved with Krita::filter
* <ul>
* <li>hermite</li>
* <li>bicubic - Adds pixels using the color of surrounding pixels. Produces smoother tonal gradations than Bilinear.</li>
* <li>box - Replicate pixels in the image. Preserves all the original detail, but can produce jagged effects.</li>
* <li>bilinear - Adds pixels averaging the color values of surrounding pixels. Produces medium quality results when the image is scaled from half to two times the original size.</li>
* <li>bell</li>
* <li>bspline</li>
* <li>lanczos3 - Offers similar results than Bicubic, but maybe a little bit sharper. Can produce light and dark halos along strong edges.</li>
* <li>mitchell</li>
* <li>Hermite</li>
* <li>Bicubic - Adds pixels using the color of surrounding pixels. Produces smoother tonal gradations than Bilinear.</li>
* <li>Box - Replicate pixels in the image. Preserves all the original detail, but can produce jagged effects.</li>
* <li>Bilinear - Adds pixels averaging the color values of surrounding pixels. Produces medium quality results when the image is scaled from half to two times the original size.</li>
* <li>Bell</li>
* <li>BSpline</li>
* <li>Kanczos3 - Offers similar results than Bicubic, but maybe a little bit sharper. Can produce light and dark halos along strong edges.</li>
* <li>Mitchell</li>
* </ul>
*/
void scaleImage(int w, int h, int xres, int yres, QString strategy);
......
......@@ -30,6 +30,7 @@
#include <KoColorSpaceEngine.h>
#include <KoColorModelStandardIds.h>
#include <kis_filter_strategy.h>
#include <kactioncollection.h>
#include <KisPart.h>
#include <KisMainWindow.h>
......@@ -174,6 +175,11 @@ Filter *Krita::filter(const QString &name) const
return filter;
}
QStringList Krita::filterStrategies() const
{
return KisFilterStrategyRegistry::instance()->keys();
}
QStringList Krita::profiles(const QString &colorModel, const QString &colorDepth) const
{
QSet<QString> profileNames;
......
......@@ -106,6 +106,14 @@ public Q_SLOTS:
*/
Filter *filter(const QString &name) const;
/**
* @brief filterStrategies Retrieves all installed filter strategies. A filter
* strategy is used when transforming (scaling, shearing, rotating) an image to
* calculate the value of the new pixels. You can use th
* @return the id's of all available filters.
*/
QStringList filterStrategies() const;
/**
* @brief profiles creates a list with the names of all color profiles compatible
* with the given color model and color depth.
......
......@@ -28,7 +28,6 @@
#include <kis_size_group.h>
#include <klocalizedstring.h>
#include <kis_filter_strategy.h>
#include "kis_double_parse_unit_spin_box.h"
......@@ -85,7 +84,7 @@ DlgImageSize::DlgImageSize(QWidget *parent, int width, int height, double resolu
m_page->pixelHeightUnit->setCurrentText("px");
m_page->pixelFilterCmb->setIDList(KisFilterStrategyRegistry::instance()->listKeys());
m_page->pixelFilterCmb->setToolTip(KisFilterStrategyRegistry::instance()->formatedDescriptions());
m_page->pixelFilterCmb->setToolTip(KisFilterStrategyRegistry::instance()->formattedDescriptions());
m_page->pixelFilterCmb->setCurrent("Bicubic");
_printWidthUnitManager = new KisSpinBoxUnitManager(this);
......
......@@ -73,7 +73,7 @@ DlgLayerSize::DlgLayerSize(QWidget * parent, const char * name,
m_page->newHeightDouble->setValue(height);
m_page->filterCmb->setIDList(KisFilterStrategyRegistry::instance()->listKeys());
m_page->filterCmb->setToolTip(KisFilterStrategyRegistry::instance()->formatedDescriptions());
m_page->filterCmb->setToolTip(KisFilterStrategyRegistry::instance()->formattedDescriptions());
m_page->filterCmb->setCurrent("Bicubic");
m_page->newWidthUnit->setModel(_widthUnitManager);
......
......@@ -17,6 +17,7 @@ public Q_SLOTS:
QList<Document *> documents() const /Factory/;
QStringList filters() const;
Filter * filter(const QString &name) const /Factory/;
QStringList filterStrategies() const;
QStringList profiles(const QString &colorModel, const QString &ColorDepth) const;
bool addProfile(const QString &profilePath);
Notifier * notifier() const;
......
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