Krita Source Code Documentation
Loading...
Searching...
No Matches
KisLsUtils::Private Namespace Reference

Classes

struct  JitterGradientIndex
 
struct  LinearGradientIndex
 

Functions

void applyGradient (KisPaintDeviceSP device, KisPixelSelectionSP selection, const QRect &applyRect, const QVector< KoColor > &table, bool edgeHidden, int jitter, const KisLayerStyleFilterEnvironment *env)
 
template<class IndexFetcher >
void applyGradientImpl (KisPaintDeviceSP device, KisPixelSelectionSP selection, const QRect &applyRect, const QVector< KoColor > &table, bool edgeHidden, IndexFetcher &indexFetcher)
 
void getGradientTable (const KoAbstractGradient *gradient, QVector< KoColor > *table, const KoColorSpace *colorSpace)
 

Function Documentation

◆ applyGradient()

void KisLsUtils::Private::applyGradient ( KisPaintDeviceSP device,
KisPixelSelectionSP selection,
const QRect & applyRect,
const QVector< KoColor > & table,
bool edgeHidden,
int jitter,
const KisLayerStyleFilterEnvironment * env )

Definition at line 215 of file kis_ls_utils.cpp.

222 {
223 if (!jitter) {
224 LinearGradientIndex fetcher;
225 applyGradientImpl(device, selection, applyRect, table, edgeHidden, fetcher);
226 } else {
227 JitterGradientIndex fetcher(applyRect, jitter, env);
228 applyGradientImpl(device, selection, applyRect, table, edgeHidden, fetcher);
229 }
230 }
void applyGradientImpl(KisPaintDeviceSP device, KisPixelSelectionSP selection, const QRect &applyRect, const QVector< KoColor > &table, bool edgeHidden, IndexFetcher &indexFetcher)

References applyGradientImpl().

◆ applyGradientImpl()

template<class IndexFetcher >
void KisLsUtils::Private::applyGradientImpl ( KisPaintDeviceSP device,
KisPixelSelectionSP selection,
const QRect & applyRect,
const QVector< KoColor > & table,
bool edgeHidden,
IndexFetcher & indexFetcher )

Definition at line 166 of file kis_ls_utils.cpp.

172 {
174 *table.first().colorSpace() == *device->colorSpace());
175
176 const KoColorSpace *cs = device->colorSpace();
177 const int pixelSize = cs->pixelSize();
178
179 KisSequentialConstIterator selIt(selection, applyRect);
180 KisSequentialIterator dstIt(device, applyRect);
181
182 if (edgeHidden) {
183
184 while (selIt.nextPixel() &&
185 dstIt.nextPixel() &&
186 indexFetcher.nextPixel()) {
187
188 quint8 selAlpha = *selIt.rawDataConst();
189 int gradientIndex = indexFetcher.popOneIndex(selAlpha);
190 const KoColor &color = table[gradientIndex];
191 quint8 tableAlpha = color.opacityU8();
192
193 memcpy(dstIt.rawData(), color.data(), pixelSize);
194
195 if (selAlpha < 24 && tableAlpha == 255) {
196 tableAlpha = int(selAlpha) * 10 * tableAlpha >> 8;
197 cs->setOpacity(dstIt.rawData(), tableAlpha, 1);
198 }
199
200 }
201
202 } else {
203
204 while (selIt.nextPixel() &&
205 dstIt.nextPixel() &&
206 indexFetcher.nextPixel()) {
207
208 int gradientIndex = indexFetcher.popOneIndex(*selIt.rawDataConst());
209 const KoColor &color = table[gradientIndex];
210 memcpy(dstIt.rawData(), color.data(), pixelSize);
211 }
212 }
213 }
const KoColorSpace * colorSpace() const
virtual quint32 pixelSize() const =0
virtual void setOpacity(quint8 *pixels, quint8 alpha, qint32 nPixels) const =0
quint8 * data()
Definition KoColor.h:144
quint8 opacityU8() const
Definition KoColor.cpp:341
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References KisPaintDevice::colorSpace(), KoColor::data(), KIS_ASSERT_RECOVER_RETURN, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KoColor::opacityU8(), KoColorSpace::pixelSize(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawDataConst(), and KoColorSpace::setOpacity().

◆ getGradientTable()

void KisLsUtils::Private::getGradientTable ( const KoAbstractGradient * gradient,
QVector< KoColor > * table,
const KoColorSpace * colorSpace )

Definition at line 113 of file kis_ls_utils.cpp.

116 {
117 KIS_ASSERT_RECOVER_RETURN(table->size() == 256);
118
119 for (int i = 0; i < 256; i++) {
120 gradient->colorAt(((*table)[i]), qreal(i) / 255.0);
121 (*table)[i].convertTo(colorSpace);
122 }
123 }
virtual void colorAt(KoColor &, qreal t) const
gets the color at position 0 <= t <= 1

References KoAbstractGradient::colorAt(), and KIS_ASSERT_RECOVER_RETURN.