KisDabCacheUtils.cpp 3.35 KB
Newer Older
1
/*
2
 *  SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
3
 *
Samuel Gaist's avatar
Samuel Gaist committed
4
 *  SPDX-License-Identifier: GPL-2.0-or-later
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 */

#include "KisDabCacheUtils.h"

#include "kis_brush.h"
#include "kis_paint_device.h"
#include "kis_fixed_paint_device.h"
#include "kis_color_source.h"

#include <kis_pressure_sharpness_option.h>
#include <kis_texture_option.h>

#include <kundo2command.h>

namespace KisDabCacheUtils
{

22
23
24
25
26
27
28
29
DabRenderingResources::DabRenderingResources()
{
}

DabRenderingResources::~DabRenderingResources()
{
}

30
void DabRenderingResources::syncResourcesToSeqNo(int seqNo, const KisPaintInformation &info)
31
{
32
    brush->prepareForSeqNo(info, seqNo);
33
}
34
35
36
37
38
39
40
41
42
43
44

QRect correctDabRectWhenFetchedFromCache(const QRect &dabRect,
                                         const QSize &realDabSize)
{
    int diffX = (realDabSize.width() - dabRect.width()) / 2;
    int diffY = (realDabSize.height() - dabRect.height()) / 2;

    return QRect(dabRect.x() - diffX, dabRect.y() - diffY,
                 realDabSize.width() , realDabSize.height());
}

45
void generateDab(const DabGenerationInfo &di, DabRenderingResources *resources, KisFixedPaintDeviceSP *dab, bool forceNormalizedRGBAImageStamp)
46
{
47
    KIS_SAFE_ASSERT_RECOVER_RETURN(*dab);
48
49
50
    const KoColorSpace *cs = (*dab)->colorSpace();


51
    if (forceNormalizedRGBAImageStamp || resources->brush->brushApplication() == IMAGESTAMP) {
52
        *dab = resources->brush->paintDevice(cs, di.shape, di.info,
53
54
55
56
                                             di.subPixel.x(),
                                             di.subPixel.y(),
                                             forceNormalizedRGBAImageStamp);

57
58
59
60
61
62
    } else if (di.solidColorFill) {
        resources->brush->mask(*dab,
                               di.paintColor,
                               di.shape,
                               di.info,
                               di.subPixel.x(), di.subPixel.y(),
63
64
                               di.softnessFactor,
                               di.lightnessStrength);
65
66
67
68
69
70
71
72
73
74
75
76
77
    }
    else {
        if (!resources->colorSourceDevice ||
            *cs != *resources->colorSourceDevice->colorSpace()) {

            resources->colorSourceDevice = new KisPaintDevice(cs);
        }
        else {
            resources->colorSourceDevice->clear();
        }

        QRect maskRect(QPoint(), di.dstDabRect.size());
        resources->colorSource->colorize(resources->colorSourceDevice, maskRect, di.info.pos().toPoint());
78
        resources->colorSourceDevice->convertTo(cs);
79
80
81
82
83

        resources->brush->mask(*dab, resources->colorSourceDevice,
                               di.shape,
                               di.info,
                               di.subPixel.x(), di.subPixel.y(),
84
85
                               di.softnessFactor,
                               di.lightnessStrength);
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    }

    if (!di.mirrorProperties.isEmpty()) {
        (*dab)->mirror(di.mirrorProperties.horizontalMirror,
                       di.mirrorProperties.verticalMirror);
    }
}

void postProcessDab(KisFixedPaintDeviceSP dab,
                    const QPoint &dabTopLeft,
                    const KisPaintInformation& info,
                    DabRenderingResources *resources)
{
    if (resources->sharpnessOption) {
100
        resources->sharpnessOption->applyThreshold(dab, info);
101
102
103
104
105
106
107
108
109
    }

    if (resources->textureOption) {
        resources->textureOption->apply(dab, dabTopLeft, info);
    }
}

}