Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_color_to_alpha.cpp File Reference
#include "kis_color_to_alpha.h"
#include <QCheckBox>
#include <QSpinBox>
#include <KoColorSpaceMaths.h>
#include <KoConfig.h>
#include <KoUpdater.h>
#include "kis_progress_update_helper.h"
#include <kis_paint_device.h>
#include <kis_selection.h>
#include <filter/kis_filter_category_ids.h>
#include <filter/kis_filter_configuration.h>
#include <kis_processing_information.h>
#include "ui_wdgcolortoalphabase.h"
#include "kis_wdg_color_to_alpha.h"
#include <kis_iterator_ng.h>
#include <KisSequentialIteratorProgress.h>

Go to the source code of this file.

Functions

template<typename channel_type , typename composite_type >
void applyToIterator (const int numChannels, const int *channelIndex, KisSequentialIteratorProgress &it, KoColor baseColor, int threshold, const KoColorSpace *cs)
 
template<typename channel_type , typename composite_type >
void inverseOver (const int numChannels, const int *channelIndex, channel_type *dst, const channel_type *baseColor, qreal dstOpacity)
 

Function Documentation

◆ applyToIterator()

template<typename channel_type , typename composite_type >
void applyToIterator ( const int numChannels,
const int * channelIndex,
KisSequentialIteratorProgress & it,
KoColor baseColor,
int threshold,
const KoColorSpace * cs )

Definition at line 69 of file kis_color_to_alpha.cpp.

72{
73 qreal thresholdF = threshold;
74 quint8 *baseColorData_uint8 = baseColor.data();
75 channel_type *baseColorData = reinterpret_cast<channel_type*>(baseColorData_uint8);
76
77 while (it.nextPixel()) {
78 channel_type *dst = reinterpret_cast<channel_type*>(it.rawData());
79 quint8 *dst_uint8 = it.rawData();
80
81 quint8 diff = cs->difference(baseColorData_uint8, dst_uint8);
82
83 qreal newOpacity = diff >= threshold ? 1.0 : diff / thresholdF;
84
85 if(newOpacity < cs->opacityF(dst_uint8)) {
86 cs->setOpacity(dst_uint8, newOpacity, 1);
87 }
88
89 inverseOver<channel_type, composite_type>(numChannels, channelIndex,
90 dst, baseColorData,
91 newOpacity);
92 }
93}
ALWAYS_INLINE quint8 * rawData()
virtual quint8 difference(const quint8 *src1, const quint8 *src2) const =0
virtual void setOpacity(quint8 *pixels, quint8 alpha, qint32 nPixels) const =0
quint8 * data()
Definition KoColor.h:144

References KoColor::data(), KoColorSpace::difference(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), and KoColorSpace::setOpacity().

◆ inverseOver()

template<typename channel_type , typename composite_type >
void inverseOver ( const int numChannels,
const int * channelIndex,
channel_type * dst,
const channel_type * baseColor,
qreal dstOpacity )
inline

Definition at line 52 of file kis_color_to_alpha.cpp.

55{
56 if (qFuzzyIsNull(dstOpacity)) {
57 return;
58 }
59
60 for (int i = 0; i < numChannels; i++) {
61 const int idx = channelIndex[i];
62 dst[idx] =
64 (static_cast<composite_type>(dst[idx]) - baseColor[idx]) / dstOpacity + baseColor[idx]);
65 }
66}
static dst_compositetype clamp(dst_compositetype val)
static bool qFuzzyIsNull(half h)

References KoColorSpaceMaths< _T, _Tdst >::clamp(), and qFuzzyIsNull().