Skip to content

Commit ac74dbd

Browse files
committed
Don't use QPixmap in the worker thread.
1 parent b5cac43 commit ac74dbd

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

src/Editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void Editor::setImage(QImage image)
6666
imageItem->setPos(m_pixmap.width() / 2, m_pixmap.height() / 2);
6767

6868
// Renderer is a thread so use invokeMethod to safely set the input.
69-
QMetaObject::invokeMethod(m_renderer, "setInput", Q_ARG(QPixmap, m_pixmap));
69+
QMetaObject::invokeMethod(m_renderer, "setInput", Q_ARG(QImage, image));
7070
}
7171

7272
void Editor::quit()

src/RenderPreview.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ RenderPreview::RenderPreview(Renderer & renderer, QWidget* parent)
3030
setScene(&m_scene);
3131
setBackgroundBrush(QBrush(Qt::black));
3232

33-
connect(&m_renderer, SIGNAL(processingFinished(const QPixmap &)), this, SLOT(updatePreview(const QPixmap &)));
33+
connect(&m_renderer, SIGNAL(processingFinished(const QImage &)), this, SLOT(updatePreview(const QImage &)));
3434
}
3535

3636
RenderPreview::~RenderPreview()
@@ -52,10 +52,12 @@ void RenderPreview::render()
5252
QMetaObject::invokeMethod(&m_renderer, "render");
5353
}
5454

55-
void RenderPreview::updatePreview(const QPixmap & result)
55+
void RenderPreview::updatePreview(const QImage & result)
5656
{
5757
m_scene.clear();
58-
QGraphicsPixmapItem* item = m_scene.addPixmap(result);
58+
QPixmap pixmap;
59+
pixmap.fromImage(result);
60+
QGraphicsPixmapItem* item = m_scene.addPixmap(pixmap);
5961
item->setPos(0, 0);
6062
}
6163

src/RenderPreview.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public slots:
4040

4141
private slots:
4242

43-
void updatePreview(const QPixmap & result);
43+
void updatePreview(const QImage & result);
4444

4545
signals:
4646

src/Renderer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,14 @@ void Renderer::render()
152152
}
153153
}
154154

155-
m_output.convertFromImage(m_result);
156-
emit processingFinished(m_output);
155+
emit processingFinished(m_result);
157156
}
158157

159-
void Renderer::setInput(const QPixmap & input)
158+
void Renderer::setInput(const QImage & input)
160159
{
161160
m_width = input.width();
162161
m_height = input.height();
163-
m_image = input.toImage();
162+
m_image = input;
164163
m_result = QImage(m_width, m_height, QImage::Format_ARGB32);
165164
m_map = buildHeightMap();
166165
}

src/Renderer.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#ifndef RENDERER_HPP
1717
#define RENDERER_HPP
1818

19-
#include <QPixmap>
2019
#include <QImage>
2120
#include <QObject>
2221
#include <QVector3D>
@@ -43,15 +42,15 @@ public slots:
4342

4443
void render();
4544

46-
void setInput(const QPixmap & input);
45+
void setInput(const QImage & input);
4746

4847
void setAmplitude(float amplitude);
4948

5049
void setRadius(float radius);
5150

5251
signals:
5352

54-
void processingFinished(const QPixmap & result);
53+
void processingFinished(const QImage & result);
5554

5655
private:
5756

@@ -65,7 +64,6 @@ public slots:
6564

6665
QImage m_image;
6766
QImage m_result;
68-
QPixmap m_output;
6967
Renderer::HeightMap m_map;
7068
int m_width;
7169
int m_height;

0 commit comments

Comments
 (0)