Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_random_sub_accessor.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the KDE project
3 *
4 * SPDX-FileCopyrightText: 2006 Cyrille Berger <cberger@cberger.net>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
10#include <QtGlobal>
11
12#include <KoColorSpace.h>
13#include <KoMixColorsOp.h>
14#include <QtMath>
15
16#include "kis_paint_device.h"
17
19 : m_device(device)
20 , m_currentPoint(0, 0)
21 , m_randomAccessor(device->createRandomConstAccessorNG())
22{
23}
24
25
29
30
32{
33 const quint8* pixels[4];
34 qint16 weights[4];
35 int x = qFloor(m_currentPoint.x());
36 int y = qFloor(m_currentPoint.y());
37
38 double hsub = m_currentPoint.x() - x;
39 if (hsub < 0.0) {
40 hsub = 1.0 + hsub;
41 }
42 double vsub = m_currentPoint.y() - y;
43 if (vsub < 0.0) {
44 vsub = 1.0 + vsub;
45 }
46
47 int sumOfWeights = 0;
48
49 weights[0] = qRound((1.0 - hsub) * (1.0 - vsub) * 255);
50 sumOfWeights += weights[0];
52 pixels[0] = m_randomAccessor->oldRawData();
53 weights[1] = qRound((1.0 - vsub) * hsub * 255);
54 sumOfWeights += weights[1];
55 m_randomAccessor->moveTo(x + 1, y);
56 pixels[1] = m_randomAccessor->oldRawData();
57 weights[2] = qRound(vsub * (1.0 - hsub) * 255);
58 sumOfWeights += weights[2];
59 m_randomAccessor->moveTo(x, y + 1);
60 pixels[2] = m_randomAccessor->oldRawData();
61 weights[3] = qRound(hsub * vsub * 255);
62 sumOfWeights += weights[3];
63 m_randomAccessor->moveTo(x + 1, y + 1);
64 pixels[3] = m_randomAccessor->oldRawData();
65
66 m_device->colorSpace()->mixColorsOp()->mixColors(pixels, weights, 4, dst, sumOfWeights);
67}
68
69
71{
72 const quint8* pixels[4];
73 qint16 weights[4];
74 int x = qFloor(m_currentPoint.x());
75 int y = qFloor(m_currentPoint.y());
76
77 double hsub = m_currentPoint.x() - x;
78 if (hsub < 0.0) {
79 hsub = 1.0 + hsub;
80 }
81 double vsub = m_currentPoint.y() - y;
82 if (vsub < 0.0) {
83 vsub = 1.0 + vsub;
84 }
85
86 int sumOfWeights = 0;
87
88 weights[0] = qRound((1.0 - hsub) * (1.0 - vsub) * 255);
89 sumOfWeights += weights[0];
91 pixels[0] = m_randomAccessor->rawDataConst();
92 weights[1] = qRound((1.0 - vsub) * hsub * 255);
93 sumOfWeights += weights[1];
94 m_randomAccessor->moveTo(x + 1, y);
95 pixels[1] = m_randomAccessor->rawDataConst();
96 weights[2] = qRound(vsub * (1.0 - hsub) * 255);
97 sumOfWeights += weights[2];
98 m_randomAccessor->moveTo(x, y + 1);
99 pixels[2] = m_randomAccessor->rawDataConst();
100 weights[3] = qRound(hsub * vsub * 255);
101 sumOfWeights += weights[3];
102 m_randomAccessor->moveTo(x + 1, y + 1);
103 pixels[3] = m_randomAccessor->rawDataConst();
104 m_device->colorSpace()->mixColorsOp()->mixColors(pixels, weights, 4, dst, sumOfWeights);
105}
virtual const quint8 * oldRawData() const =0
virtual const quint8 * rawDataConst() const =0
const KoColorSpace * colorSpace() const
virtual void moveTo(qint32 x, qint32 y)=0
KisRandomSubAccessor(KisPaintDeviceSP device)
KisRandomConstAccessorSP m_randomAccessor
void sampledOldRawData(quint8 *dst)
KoMixColorsOp * mixColorsOp
virtual void mixColors(const quint8 *const *colors, const qint16 *weights, int nColors, quint8 *dst, int weightSum=255) const =0