MCPcopy Create free account
hub / github.com/BatchDrake/SigDigger / compose

Method compose

Misc/Palette.cpp:78–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78void
79Palette::compose(void)
80{
81 unsigned char bit, byte;
82 qreal alpha, r0, r1, g0, g1, b0, b1;
83
84 int prev = -1;
85 int i, j;
86
87 for (i = 0; i < SIGDIGGER_PALETTE_MAX_STOPS; ++i) {
88 byte = static_cast<unsigned char>(i >> 3);
89 bit = i & 7;
90
91 if (this->bitmap[byte] & (1 << bit)) {
92 /* Used color found! */
93 if (prev == -1) {
94 /* This is the first stop. Fill from 0 until this one */
95 for (j = 0; j < i; ++j)
96 this->gradient[j] = this->gradient[i];
97 } else {
98 /* Not the first stop. perform square root mixing */
99 for (j = prev + 1; j < i; ++j) {
100 alpha = static_cast<qreal>(j - prev) / static_cast<qreal>(i - prev);
101
102 r0 = this->gradient[i].redF();
103 r1 = this->gradient[prev].redF();
104
105 g0 = this->gradient[i].greenF();
106 g1 = this->gradient[prev].greenF();
107
108 b0 = this->gradient[i].blueF();
109 b1 = this->gradient[prev].blueF();
110
111 this->gradient[j].setRgbF(
112 sqrt(alpha * r0 * r0 + (1. - alpha) * r1 * r1),
113 sqrt(alpha * g0 * g0 + (1. - alpha) * g1 * g1),
114 sqrt(alpha * b0 * b0 + (1. - alpha) * b1 * b1));
115 }
116 }
117
118 prev = i;
119 }
120 }
121
122 if (prev != -1)
123 for (j = prev + 1; j < SIGDIGGER_PALETTE_MAX_STOPS; ++j)
124 this->gradient[j] = this->gradient[prev];
125
126 this->updateThumbnail();
127}
128
129void
130Palette::addStop(unsigned int stop, const QColor &color)

Callers 1

deserializeMethod · 0.95

Calls 1

updateThumbnailMethod · 0.95

Tested by

no test coverage detected