@@ -174,45 +174,60 @@ bool KisVisualColorSelectorShape::imagesNeedUpdate() const {
174
174
QImage KisVisualColorSelectorShape::getImageMap ()
175
175
{
176
176
// qDebug() << this << ">>>>>>>>> getImageMap()" << m_d->imagesNeedUpdate;
177
- const KisVisualColorSelector *selector = qobject_cast<KisVisualColorSelector*>(parent ());
178
177
179
- if (m_d->imagesNeedUpdate == true ) {
178
+ if (m_d->imagesNeedUpdate ) {
180
179
// Fill a buffer with the right kocolors
181
- quint8 *data = new quint8[width () * height () * m_d->colorSpace ->pixelSize ()];
182
- quint8 *dataPtr = data;
183
- QVector4D coordinates = m_d->currentChannelValues ;
184
- for (int y = 0 ; y < height (); y++) {
185
- for (int x=0 ; x < width (); x++) {
186
- QPointF newcoordinate = convertWidgetCoordinateToShapeCoordinate (QPoint (x, y));
187
- coordinates[m_d->channel1 ] = newcoordinate.x ();
188
- if (m_d->dimension == Dimensions::twodimensional){
189
- coordinates[m_d->channel2 ] = newcoordinate.y ();
190
- }
191
- KoColor c = selector->convertShapeCoordsToKoColor (coordinates);
192
- memcpy (dataPtr, c.data (), m_d->colorSpace ->pixelSize ());
193
- dataPtr += m_d->colorSpace ->pixelSize ();
194
- }
195
- }
196
- // Convert the buffer to a qimage
197
- if (m_d->displayRenderer ) {
198
- m_d->gradient = m_d->displayRenderer ->convertToQImage (m_d->colorSpace , data, width (), height ());
199
- }
200
- else {
201
- m_d->gradient = m_d->colorSpace ->convertToQImage (data, width (), height (), 0 , KoColorConversionTransformation::internalRenderingIntent (), KoColorConversionTransformation::internalConversionFlags ());
202
- }
203
- delete[] data;
204
-
180
+ m_d->gradient = renderBackground (m_d->currentChannelValues , m_d->colorSpace ->pixelSize ());
205
181
m_d->imagesNeedUpdate = false ;
206
- // safeguard:
207
- if (m_d->gradient .isNull ())
208
- {
209
- m_d->gradient = QImage (width (), height (), QImage::Format_ARGB32);
210
- m_d->gradient .fill (Qt::black);
211
- }
212
182
}
213
183
return m_d->gradient ;
214
184
}
215
185
186
+ QImage KisVisualColorSelectorShape::convertImageMap (const quint8 *rawColor, quint32 size) const
187
+ {
188
+ Q_ASSERT (size == width ()*height ()*m_d->colorSpace ->pixelSize ());
189
+ QImage image;
190
+ // Convert the buffer to a qimage
191
+ if (m_d->displayRenderer ) {
192
+ image = m_d->displayRenderer ->convertToQImage (m_d->colorSpace , rawColor, width (), height ());
193
+ }
194
+ else {
195
+ image = m_d->colorSpace ->convertToQImage (rawColor, width (), height (), 0 , KoColorConversionTransformation::internalRenderingIntent (), KoColorConversionTransformation::internalConversionFlags ());
196
+ }
197
+ // safeguard:
198
+ if (image.isNull ())
199
+ {
200
+ image = QImage (width (), height (), QImage::Format_ARGB32);
201
+ image.fill (Qt::black);
202
+ }
203
+
204
+ return image;
205
+ }
206
+
207
+ QImage KisVisualColorSelectorShape::renderBackground (const QVector4D &channelValues, quint32 pixelSize) const
208
+ {
209
+ const KisVisualColorSelector *selector = qobject_cast<KisVisualColorSelector*>(parent ());
210
+ Q_ASSERT (selector);
211
+
212
+ quint32 imageSize = width () * height () * m_d->colorSpace ->pixelSize ();
213
+ QScopedArrayPointer<quint8> raw (new quint8[imageSize] {});
214
+ quint8 *dataPtr = raw.data ();
215
+ QVector4D coordinates = channelValues;
216
+ for (int y = 0 ; y < height (); y++) {
217
+ for (int x=0 ; x < width (); x++) {
218
+ QPointF newcoordinate = convertWidgetCoordinateToShapeCoordinate (QPoint (x, y));
219
+ coordinates[m_d->channel1 ] = newcoordinate.x ();
220
+ if (m_d->dimension == Dimensions::twodimensional){
221
+ coordinates[m_d->channel2 ] = newcoordinate.y ();
222
+ }
223
+ KoColor c = selector->convertShapeCoordsToKoColor (coordinates);
224
+ memcpy (dataPtr, c.data (), pixelSize);
225
+ dataPtr += pixelSize;
226
+ }
227
+ }
228
+ return convertImageMap (raw.data (), imageSize);
229
+ }
230
+
216
231
void KisVisualColorSelectorShape::mousePressEvent (QMouseEvent *e)
217
232
{
218
233
if (e->button ()==Qt::LeftButton) {
0 commit comments