Krita Source Code Documentation
Loading...
Searching...
No Matches
palettegeneratorconfig.cpp
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2014 Manuel Riecke <spell1337@gmail.com>
3
*
4
* SPDX-License-Identifier: ICS
5
*/
6
7
#include "
palettegeneratorconfig.h
"
8
#include <QTextStream>
9
#include <QIODevice>
10
11
PaletteGeneratorConfig::PaletteGeneratorConfig
()
12
{
13
for
(
int
j = 0; j < 4; ++j)
14
{
15
colors
[0][j] = QColor(Qt::white);
16
colors
[1][j] = QColor(Qt::yellow);
17
colors
[2][j] = QColor(Qt::gray);
18
colors
[3][j] = QColor(Qt::black);
19
}
20
21
for
(
int
i = 0; i < 4; ++i)
22
for
(
int
j = 0; j < 4; ++j)
23
colorsEnabled
[i][j] = (j == 0);
24
25
for
(
int
i = 0; i < 3; ++i)
26
gradientSteps
[i] = 4;
27
28
inbetweenRampSteps
= 2;
29
diagonalGradients
=
false
;
30
}
31
32
QByteArray
PaletteGeneratorConfig::toByteArray
()
33
{
34
QByteArray retVal;
35
QDataStream stream(&retVal, QIODevice::WriteOnly);
36
stream.setVersion(QDataStream::Qt_4_6);
37
stream.setByteOrder(QDataStream::BigEndian);
38
39
// Version int
40
stream << 0;
41
42
for
(
int
i = 0; i < 4; ++i)
43
for
(
int
j = 0; j < 4; ++j)
44
stream <<
colors
[i][j];
45
46
for
(
int
i = 0; i < 4; ++i)
47
for
(
int
j = 0; j < 4; ++j)
48
stream <<
colorsEnabled
[i][j];
49
50
for
(
int
i = 0; i < 3; ++i)
51
stream <<
gradientSteps
[i];
52
53
stream <<
inbetweenRampSteps
;
54
stream <<
diagonalGradients
;
55
return
retVal;
56
}
57
58
void
PaletteGeneratorConfig::fromByteArray
(
const
QByteArray& str)
59
{
60
QDataStream stream(str);
61
stream.setVersion(QDataStream::Qt_4_6);
62
stream.setByteOrder(QDataStream::BigEndian);
63
64
int
version;
65
stream >> version;
66
if
(version == 0)
67
{
68
for
(
int
i = 0; i < 4; ++i)
69
for
(
int
j = 0; j < 4; ++j)
70
stream >>
colors
[i][j];
71
72
for
(
int
i = 0; i < 4; ++i)
73
for
(
int
j = 0; j < 4; ++j)
74
stream >>
colorsEnabled
[i][j];
75
76
for
(
int
i = 0; i < 3; ++i)
77
stream >>
gradientSteps
[i];
78
79
stream >>
inbetweenRampSteps
;
80
stream >>
diagonalGradients
;
81
}
82
else
83
qDebug(
"PaletteGeneratorConfig::FromByteArray: Unsupported data version"
);
84
}
85
86
IndexColorPalette
PaletteGeneratorConfig::generate
()
87
{
88
IndexColorPalette
pal;
89
// Add all colors to the palette
90
for
(
int
y = 0; y < 4; ++y)
91
for
(
int
x = 0; x < 4; ++x)
92
if
(
colorsEnabled
[y][x])
93
pal.
insertColor
(
colors
[y][x]);
94
95
for
(
int
y = 0; y < 3; ++y)
96
{
97
for
(
int
x = 0; x < 4; ++x)
98
if
(
colorsEnabled
[y][x] &&
colorsEnabled
[y+1][x])
99
pal.
insertShades
(
colors
[y][x],
colors
[y+1][x],
gradientSteps
[y]);
100
}
101
102
if
(
inbetweenRampSteps
)
103
{
104
for
(
int
y = 0; y < 4; ++y)
105
for
(
int
x = 0; x < 3; ++x)
106
if
(
colorsEnabled
[y][x] &&
colorsEnabled
[y][x+1])
107
pal.
insertShades
(
colors
[y][x],
colors
[y][x+1],
inbetweenRampSteps
);
108
}
109
110
if
(
diagonalGradients
)
111
{
112
for
(
int
y = 0; y < 3; ++y)
113
for
(
int
x = 0; x < 4; ++x)
114
{
115
if
(x+1 < 4)
116
if
(
colorsEnabled
[y][x+1] &&
colorsEnabled
[y+1][x])
117
pal.
insertShades
(
colors
[y][x+1],
colors
[y+1][x],
gradientSteps
[y]);
118
if
(x-1 >= 0)
119
if
(
colorsEnabled
[y][x-1] &&
colorsEnabled
[y+1][x])
120
pal.
insertShades
(
colors
[y][x-1],
colors
[y+1][x],
gradientSteps
[y]);
121
}
122
}
123
return
pal;
124
}
palettegeneratorconfig.h
IndexColorPalette
Definition
indexcolorpalette.h:23
IndexColorPalette::insertColor
void insertColor(QColor clr)
Definition
indexcolorpalette.cpp:149
IndexColorPalette::insertShades
void insertShades(QColor clrA, QColor clrB, int shades)
Definition
indexcolorpalette.cpp:124
PaletteGeneratorConfig::PaletteGeneratorConfig
PaletteGeneratorConfig()
Definition
palettegeneratorconfig.cpp:11
PaletteGeneratorConfig::gradientSteps
int gradientSteps[3]
Definition
palettegeneratorconfig.h:16
PaletteGeneratorConfig::inbetweenRampSteps
int inbetweenRampSteps
Definition
palettegeneratorconfig.h:17
PaletteGeneratorConfig::generate
IndexColorPalette generate()
Definition
palettegeneratorconfig.cpp:86
PaletteGeneratorConfig::toByteArray
QByteArray toByteArray()
Definition
palettegeneratorconfig.cpp:32
PaletteGeneratorConfig::fromByteArray
void fromByteArray(const QByteArray &str)
Definition
palettegeneratorconfig.cpp:58
PaletteGeneratorConfig::colors
QColor colors[4][4]
Definition
palettegeneratorconfig.h:14
PaletteGeneratorConfig::diagonalGradients
bool diagonalGradients
Definition
palettegeneratorconfig.h:18
PaletteGeneratorConfig::colorsEnabled
bool colorsEnabled[4][4]
Definition
palettegeneratorconfig.h:15
plugins
filters
indexcolors
palettegeneratorconfig.cpp
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52