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
8#include <QTextStream>
9#include <QIODevice>
10
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
29 diagonalGradients = false;
30}
31
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
58void 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
87{
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
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
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}
void insertColor(QColor clr)
void insertShades(QColor clrA, QColor clrB, int shades)
void fromByteArray(const QByteArray &str)