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 65 of file kis_color_to_alpha.cpp.

68{
69 qreal thresholdF = threshold;
70 quint8 *baseColorData_uint8 = baseColor.data();
71 channel_type *baseColorData = reinterpret_cast<channel_type*>(baseColorData_uint8);
72
73 while (it.nextPixel()) {
74 channel_type *dst = reinterpret_cast<channel_type*>(it.rawData());
75 quint8 *dst_uint8 = it.rawData();
76
77 quint8 diff = cs->difference(baseColorData_uint8, dst_uint8);
78
79 qreal newOpacity = diff >= threshold ? 1.0 : diff / thresholdF;
80
81 if(newOpacity < cs->opacityF(dst_uint8)) {
82 cs->setOpacity(dst_uint8, newOpacity, 1);
83 }
84
85 inverseOver<channel_type, composite_type>(numChannels, channelIndex,
86 dst, baseColorData,
87 newOpacity);
88 }
89}
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 for (int i = 0; i < numChannels; i++) {
57 const int idx = channelIndex[i];
58 dst[idx] =
60 (static_cast<composite_type>(dst[idx]) - baseColor[idx]) / dstOpacity + baseColor[idx]);
61 }
62}
static dst_compositetype clamp(dst_compositetype val)

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