Commit c6a8935d authored by Carl Schwan's avatar Carl Schwan Committed by Dmitry Kazakov

FEATURE: Palettize Filter

Filter to match colours to selected palette and
optionally apply some simple dithering.

Differential Revision: https://phabricator.kde.org/D21682
parent 20aba306
......@@ -21,6 +21,7 @@
#define KIS_ICONWIDGET_H_
#include <kis_popup_button.h>
#include <kritaui_export.h>
class KoResource;
......@@ -28,7 +29,7 @@ class KoResource;
* The icon widget is used in the control box where the current color and brush
* are shown.
*/
class KisIconWidget : public KisPopupButton
class KRITAUI_EXPORT KisIconWidget : public KisPopupButton
{
Q_OBJECT
......
......@@ -20,6 +20,7 @@
#include "KoResourceItemDelegate.h"
#include <resources/KoAbstractGradient.h>
#include <resources/KoColorSet.h>
#include <QPainter>
KoResourceItemDelegate::KoResourceItemDelegate( QObject * parent )
......@@ -44,6 +45,7 @@ void KoResourceItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
QRect innerRect = option.rect.adjusted( 2, 1, -2, -1 );
KoAbstractGradient * gradient = dynamic_cast<KoAbstractGradient*>( resource );
KoColorSet * palette = dynamic_cast<KoColorSet*>( resource );
if (gradient) {
QGradient * g = gradient->toQGradient();
......@@ -57,6 +59,11 @@ void KoResourceItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
delete g;
}
else if (palette) {
QImage thumbnail = index.data( Qt::DecorationRole ).value<QImage>();
painter->setRenderHint(QPainter::SmoothPixmapTransform, thumbnail.width() > innerRect.width() || thumbnail.height() > innerRect.height());
painter->drawImage(innerRect, thumbnail);
}
else {
QImage thumbnail = index.data( Qt::DecorationRole ).value<QImage>();
......
......@@ -29,3 +29,4 @@ add_subdirectory( halftone )
add_subdirectory( edgedetection )
add_subdirectory( convertheightnormalmap )
add_subdirectory( asccdl )
add_subdirectory( palettize )
set(kritapalettize_SOURCES palettize.cpp)
add_library(kritapalettize MODULE ${kritapalettize_SOURCES})
target_link_libraries(kritapalettize kritaui)
install(TARGETS kritapalettize DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
{
"Id": "Palettize Filter",
"Type": "Service",
"X-KDE-Library": "kritapalettize",
"X-KDE-ServiceTypes": [
"Krita/Filter"
],
"X-Krita-Version": "30"
}
This diff is collapsed.
/*
* This file is part of the KDE project
*
* Copyright (c) 2019 Carl Olsson <carl.olsson@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 PALETTIZE_H
#define PALETTIZE_H
#include <kis_filter.h>
#include <kis_config_widget.h>
#include <kis_filter_configuration.h>
#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/register/point.hpp>
class KoColorSet;
class KoResourceItemChooser;
class QGroupBox;
class KoPattern;
class QCheckBox;
class QLineEdit;
class QButtonGroup;
class KisDoubleWidget;
class Palettize : public QObject
{
public:
Palettize(QObject *parent, const QVariantList &);
};
class KisPalettizeWidget : public KisConfigWidget
{
public:
KisPalettizeWidget(QWidget* parent = 0);
void setConfiguration(const KisPropertiesConfigurationSP) override;
KisPropertiesConfigurationSP configuration() const override;
private:
KoResourceItemChooser* m_paletteWidget;
QGroupBox* m_ditherGroupBox;
QButtonGroup* m_ditherModeGroup;
KoResourceItemChooser* m_ditherPatternWidget;
QCheckBox* m_ditherPatternUseAlphaCheckBox;
QLineEdit* m_ditherNoiseSeedWidget;
KisDoubleWidget* m_ditherWeightWidget;
};
class KisFilterPalettize : public KisFilter
{
public:
enum DitherMode {
Pattern,
Noise
};
KisFilterPalettize();
static inline KoID id() { return KoID("palettize", i18n("Palettize")); }
KisConfigWidget* createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool useForMasks) const override;
KisFilterConfigurationSP factoryConfiguration() const override;
void processImpl(KisPaintDeviceSP device, const QRect &applyRect, const KisFilterConfigurationSP config, KoUpdater *progressUpdater) const override;
};
#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