[graphics/krita/krita/5.2] plugins/filters: Implement Other->Reset Transparent filter

Dmitry Kazakov null at kde.org
Tue Oct 24 08:48:11 BST 2023


Git commit a4c4e7f2515b5ff01ea2b8cda2f958096e0b8939 by Dmitry Kazakov.
Committed on 24/10/2023 at 09:48.
Pushed by dkazakov into branch 'krita/5.2'.

Implement Other->Reset Transparent filter

In Krita we have an optimization, which causes pixels under zero alpha
to have undefined color channel values. It may cause some issues with
software that expects the values under fully transparent pixels to have
exactly zero values.

To overcome this issue the user can just apply Reset Transparent
filter over his/her image and it will guarantee that all the fully
transparent pixels are zeroed.

BUG:471871
CC:kimageshop at kde.org


(cherry picked from commit a0db80d17af34454bb3244a91d9c9a47449454c2)

M  +1    -0    plugins/filters/CMakeLists.txt
A  +4    -0    plugins/filters/resettransparent/CMakeLists.txt
A  +69   -0    plugins/filters/resettransparent/KisResetTransparentFilter.cpp     [License: GPL(v2.0+)]
A  +42   -0    plugins/filters/resettransparent/KisResetTransparentFilter.h     [License: GPL(v2.0+)]
A  +9    -0    plugins/filters/resettransparent/kritaresettransparent.json

https://invent.kde.org/graphics/krita/-/commit/a4c4e7f2515b5ff01ea2b8cda2f958096e0b8939

diff --git a/plugins/filters/CMakeLists.txt b/plugins/filters/CMakeLists.txt
index 63a5de64e91..6801b7aa30c 100644
--- a/plugins/filters/CMakeLists.txt
+++ b/plugins/filters/CMakeLists.txt
@@ -30,3 +30,4 @@ add_subdirectory( edgedetection )
 add_subdirectory( convertheightnormalmap )
 add_subdirectory( asccdl )
 add_subdirectory( palettize )
+add_subdirectory( resettransparent )
diff --git a/plugins/filters/resettransparent/CMakeLists.txt b/plugins/filters/resettransparent/CMakeLists.txt
new file mode 100644
index 00000000000..2324f867939
--- /dev/null
+++ b/plugins/filters/resettransparent/CMakeLists.txt
@@ -0,0 +1,4 @@
+set(kritaresettransparent_SOURCES KisResetTransparentFilter.cpp )
+kis_add_library(kritaresettransparent MODULE ${kritaresettransparent_SOURCES})
+target_link_libraries(kritaresettransparent kritaui)
+install(TARGETS kritaresettransparent  DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
diff --git a/plugins/filters/resettransparent/KisResetTransparentFilter.cpp b/plugins/filters/resettransparent/KisResetTransparentFilter.cpp
new file mode 100644
index 00000000000..c45b1065d70
--- /dev/null
+++ b/plugins/filters/resettransparent/KisResetTransparentFilter.cpp
@@ -0,0 +1,69 @@
+/*
+ *  SPDX-FileCopyrightText: 2023 Dmitry Kazakov <dimula73 at gmail.com>
+ *
+ *  SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisResetTransparentFilter.h"
+
+#include <klocalizedstring.h>
+
+#include <kis_debug.h>
+#include <kpluginfactory.h>
+
+#include <KoUpdater.h>
+#include <KisSequentialIteratorProgress.h>
+
+#include <filter/kis_filter_category_ids.h>
+#include <filter/kis_filter_registry.h>
+
+K_PLUGIN_FACTORY_WITH_JSON(ResetTransparentFactory, "kritaresettransparent.json", registerPlugin<ResetTransparent>();)
+
+ResetTransparent::ResetTransparent(QObject *parent, const QVariantList &)
+        : QObject(parent)
+{
+    KisFilterRegistry::instance()->add(KisFilterSP(new KisResetTransparentFilter()));
+}
+
+ResetTransparent::~ResetTransparent()
+{
+}
+
+KisResetTransparentFilter::KisResetTransparentFilter()
+    : KisFilter(id(), FiltersCategoryOtherId, i18n("Reset Transparent"))
+{
+    setColorSpaceIndependence(FULLY_INDEPENDENT);
+    setSupportsPainting(false);
+    setSupportsThreading(true);
+    setSupportsLevelOfDetail(false);
+    setSupportsAdjustmentLayers(false);
+    setShowConfigurationWidget(false);
+}
+
+bool KisResetTransparentFilter::needsTransparentPixels(const KisFilterConfigurationSP config, const KoColorSpace *cs) const
+{
+    Q_UNUSED(config);
+    Q_UNUSED(cs);
+    return true;
+}
+
+void KisResetTransparentFilter::processImpl(KisPaintDeviceSP device,
+                                            const QRect &applyRect,
+                                            const KisFilterConfigurationSP config,
+                                            KoUpdater *progressUpdater) const
+{
+    Q_UNUSED(config);
+
+    const KoColorSpace *cs = device->colorSpace();
+    KoColor transparent = KoColor::createTransparent(cs);
+    const int pixelSize = cs->pixelSize();
+
+    KisSequentialIteratorProgress it(device, applyRect, progressUpdater);
+    while (it.nextPixel()) {
+        if (cs->opacityU8(it.oldRawData()) == OPACITY_TRANSPARENT_U8) {
+            memcpy(it.rawData(), transparent.data(), pixelSize);
+        }
+    }
+}
+
+#include "KisResetTransparentFilter.moc"
diff --git a/plugins/filters/resettransparent/KisResetTransparentFilter.h b/plugins/filters/resettransparent/KisResetTransparentFilter.h
new file mode 100644
index 00000000000..c0b4627a420
--- /dev/null
+++ b/plugins/filters/resettransparent/KisResetTransparentFilter.h
@@ -0,0 +1,42 @@
+/*
+ *  SPDX-FileCopyrightText: 2023 Dmitry Kazakov <dimula73 at gmail.com>
+ *
+ *  SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef RESET_TRANSPARENT_H
+#define RESET_TRANSPARENT_H
+
+#include <QObject>
+#include <QVariant>
+
+#include <kis_filter.h>
+
+class ResetTransparent : public QObject
+{
+    Q_OBJECT
+public:
+    ResetTransparent(QObject *parent, const QVariantList &);
+    ~ResetTransparent() override;
+};
+
+class KisResetTransparentFilter : public KisFilter
+{
+public:
+    KisResetTransparentFilter();
+public:
+    static inline KoID id() {
+        return KoID("resettransparent", i18n("Reset Transparent"));
+    }
+
+    bool needsTransparentPixels(const KisFilterConfigurationSP config, const KoColorSpace *cs) const override;
+
+protected:
+    void processImpl(KisPaintDeviceSP device,
+                     const QRect& applyRect,
+                     const KisFilterConfigurationSP config,
+                     KoUpdater* progressUpdater = 0 ) const override;
+
+};
+
+#endif /* RESET_TRANSPARENT_H */
diff --git a/plugins/filters/resettransparent/kritaresettransparent.json b/plugins/filters/resettransparent/kritaresettransparent.json
new file mode 100644
index 00000000000..77bcca4a65a
--- /dev/null
+++ b/plugins/filters/resettransparent/kritaresettransparent.json
@@ -0,0 +1,9 @@
+{
+    "Id": "Reset Transparent Filter",
+    "Type": "Service",
+    "X-KDE-Library": "kritaresettransparent",
+    "X-KDE-ServiceTypes": [
+        "Krita/Filter"
+    ],
+    "X-Krita-Version": "28"
+}


More information about the kimageshop mailing list