24#include "ui_wdgcolortoalphabase.h"
46 config->setProperty(
"targetcolor", QColor(255, 255, 255));
47 config->setProperty(
"threshold", 100);
51template<
typename channel_type,
typename composite_type>
52inline void inverseOver(
const int numChannels,
const int *channelIndex,
53 channel_type *dst,
const channel_type *baseColor,
60 for (
int i = 0; i < numChannels; i++) {
61 const int idx = channelIndex[i];
64 (
static_cast<composite_type
>(dst[idx]) - baseColor[idx]) / dstOpacity + baseColor[idx]);
68template<
typename channel_type,
typename composite_type>
73 qreal thresholdF = threshold;
74 quint8 *baseColorData_uint8 = baseColor.
data();
75 channel_type *baseColorData =
reinterpret_cast<channel_type*
>(baseColorData_uint8);
78 channel_type *dst =
reinterpret_cast<channel_type*
>(it.
rawData());
79 quint8 *dst_uint8 = it.
rawData();
81 quint8 diff = cs->
difference(baseColorData_uint8, dst_uint8);
83 qreal newOpacity = diff >= threshold ? 1.0 : diff / thresholdF;
85 if(newOpacity < cs->opacityF(dst_uint8)) {
89 inverseOver<channel_type, composite_type>(numChannels, channelIndex,
101 Q_ASSERT(device != 0);
105 QColor cTA = (config->getProperty(
"targetcolor",
value)) ?
value.value<QColor>() : QColor(255, 255, 255);
106 int threshold = (config->getProperty(
"threshold",
value)) ?
value.toInt() : 1;
118 for (
int i = 0; i < channels.size(); i++) {
127 valueType != currentValueType) {
129 warnKrita <<
"Cannot apply a Color-to-Alpha filter to a heterogeneous colorspace";
132 valueType = currentValueType;
135 channelIndex.append(i);
140 applyToIterator<quint8, qint16>(channelIndex.size(), channelIndex.data(),
145 applyToIterator<quint16, qint32>(channelIndex.size(), channelIndex.data(),
150 applyToIterator<quint32, qint64>(channelIndex.size(), channelIndex.data(),
156 applyToIterator<float, float>(channelIndex.size(), channelIndex.data(),
161 applyToIterator<double, double>(channelIndex.size(), channelIndex.data(),
168 applyToIterator<half, half>(channelIndex.size(), channelIndex.data(),
178 warnKrita <<
"Color To Alpha: Unsupported channel type:" << valueType;
float value(const T *src, size_t ch)
KisFilterConfigurationSP defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const override
KisConfigWidget * createConfigurationWidget(QWidget *parent, const KisPaintDeviceSP dev, bool useForMasks) const override
void processImpl(KisPaintDeviceSP device, const QRect &rect, const KisFilterConfigurationSP config, KoUpdater *progressUpdater) const override
void setSupportsLevelOfDetail(bool value)
const KoColorSpace * colorSpace() const
ALWAYS_INLINE quint8 * rawData()
@ COLOR
The channel represents a color.
enumChannelValueType
enum to define the value of the channel
@ UINT8
use this for an unsigned integer 8bits channel
@ UINT16
use this for an integer 16bits channel
@ OTHER
Use this if the channel is neither an integer or a float.
@ INT16
use this for an integer 16bits channel
@ INT8
use this for an integer 8bits channel
@ FLOAT32
use this for a float 32bits channel
@ FLOAT16
use this for a float 16bits channel
@ UINT32
use this for an unsigned integer 21bits channel
@ FLOAT64
use this for a float 64bits channel
enumChannelType channelType() const
enumChannelValueType channelValueType() const
static dst_compositetype clamp(dst_compositetype val)
virtual quint8 difference(const quint8 *src1, const quint8 *src2) const =0
virtual void setOpacity(quint8 *pixels, quint8 alpha, qint32 nPixels) const =0
QList< KoChannelInfo * > channels
static bool qFuzzyIsNull(half h)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
void applyToIterator(const int numChannels, const int *channelIndex, KisSequentialIteratorProgress &it, KoColor baseColor, int threshold, const KoColorSpace *cs)
void inverseOver(const int numChannels, const int *channelIndex, channel_type *dst, const channel_type *baseColor, qreal dstOpacity)
const KoID FiltersCategoryColorId("color_filters", ki18nc("The category of color transfer filters, like color to alpha. Noun.", "Colors"))
virtual KisFilterConfigurationSP factoryConfiguration(KisResourcesInterfaceSP resourcesInterface) const
void setSupportsAdjustmentLayers(bool v)
void setSupportsPainting(bool v)
void setColorSpaceIndependence(ColorSpaceIndependence v)