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,
56 for (
int i = 0; i < numChannels; i++) {
57 const int idx = channelIndex[i];
60 (
static_cast<composite_type
>(dst[idx]) - baseColor[idx]) / dstOpacity + baseColor[idx]);
64template<
typename channel_type,
typename composite_type>
69 qreal thresholdF = threshold;
70 quint8 *baseColorData_uint8 = baseColor.
data();
71 channel_type *baseColorData =
reinterpret_cast<channel_type*
>(baseColorData_uint8);
74 channel_type *dst =
reinterpret_cast<channel_type*
>(it.
rawData());
75 quint8 *dst_uint8 = it.
rawData();
77 quint8 diff = cs->
difference(baseColorData_uint8, dst_uint8);
79 qreal newOpacity = diff >= threshold ? 1.0 : diff / thresholdF;
81 if(newOpacity < cs->opacityF(dst_uint8)) {
85 inverseOver<channel_type, composite_type>(numChannels, channelIndex,
97 Q_ASSERT(device != 0);
101 QColor cTA = (config->getProperty(
"targetcolor",
value)) ?
value.value<QColor>() : QColor(255, 255, 255);
102 int threshold = (config->getProperty(
"threshold",
value)) ?
value.toInt() : 1;
114 for (
int i = 0; i < channels.size(); i++) {
123 valueType != currentValueType) {
125 warnKrita <<
"Cannot apply a Color-to-Alpha filter to a heterogeneous colorspace";
128 valueType = currentValueType;
131 channelIndex.append(i);
136 applyToIterator<quint8, qint16>(channelIndex.size(), channelIndex.data(),
141 applyToIterator<quint16, qint32>(channelIndex.size(), channelIndex.data(),
146 applyToIterator<quint32, qint64>(channelIndex.size(), channelIndex.data(),
152 applyToIterator<float, float>(channelIndex.size(), channelIndex.data(),
157 applyToIterator<double, double>(channelIndex.size(), channelIndex.data(),
164 applyToIterator<half, half>(channelIndex.size(), channelIndex.data(),
174 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
#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)