Began proof-of-concept memory module.
[aesalon.git] / src / artisan / gviewport / RenderedImage.cpp
blobfabb878b048a26a91d972d44d09bc5fa0c978e21
1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/artisan/gviewport/RenderedImage.cpp
8 */
10 #include <QPaintDevice>
11 #include <QRect>
12 #include <QMutexLocker>
14 #include "artisan/gviewport/RenderedImage.h"
15 #include "artisan/gviewport/CoordinateMapper.h"
17 #include "util/MessageSystem.h"
19 namespace Artisan {
20 namespace GViewport {
22 RenderedImage::RenderedImage(const Rect &dataRange, const Rect &pixelSize)
23 : m_dataRange(dataRange), m_pixelSize(pixelSize) {
25 m_image = QImage(m_pixelSize.width(), m_pixelSize.height(), QImage::Format_ARGB32);
27 //m_image.fill(qRgb(qrand()%256, qrand()%256, qrand()%256));
28 m_image.fill(qRgb(255, 255, 255));
30 m_painter = new QPainter();
33 RenderedImage::~RenderedImage() {
34 delete m_painter;
37 void RenderedImage::merge(RenderedImage &other) {
38 CoordinateMapper mapper(*this);
39 Rect local = mapper.dataToPixel(other.dataRange());
40 startPainting();
42 m_painter->drawImage(local.toQRect(), other.m_image);
44 stopPainting();
47 void RenderedImage::startPainting() {
48 m_paintLock.lock();
49 m_painter->begin(&m_image);
52 void RenderedImage::stopPainting() {
53 m_painter->end();
54 m_paintLock.unlock();
57 void RenderedImage::paintOnto(QPaintDevice *device) {
58 QPainter painter(device);
59 painter.drawImage(QRect(0, 0, device->width(), device->height()), m_image, m_image.rect());
62 RenderedImage &RenderedImage::operator=(const RenderedImage &other) {
63 m_dataRange = other.m_dataRange;
64 m_pixelSize = other.m_pixelSize;
65 m_image = other.m_image;
66 return *this;
69 } // namespace GViewport
70 } // namespace Artisan