From 0242fc547a4357bd879ff0a4f9e2c92e65b40d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 3 May 2012 18:41:15 +0000 Subject: [PATCH] paysages : Preview improvements. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@316 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 4 ++-- gui_qt/basepreview.cpp | 35 +++++++++++++++++++++-------------- gui_qt/basepreview.h | 1 + 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index 8c78db9..6f4a14b 100644 --- a/TODO +++ b/TODO @@ -10,11 +10,11 @@ Technology Preview 2 : - Add a noise filler (and maybe noise intervals ?). - Improve curve editor. - Water and terrain LOD moves with the camera, fix it like in the wanderer. -- There should not have to be more preview threads than cpu cores. - Pause previews drawing of main window when a dialog is opened. - Interrupt preview chunk renderings that will be discarded at commit, or that are no more visible. - Can't overwrite picture files (ILError). -- Fix "RGB parameters out of range" on preview while moving render size fast in render tab. +- Fix "RGB parameters out of range" (and segfault) on preview while moving render params fast in render tab. +- When there are two previews in the same view, balance rendering between the two. Technology Preview 3 : - Restore render progress. diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index e086923..605519a 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -331,9 +331,9 @@ QImage BasePreview::startChunkTransaction(int x, int y, int w, int h, int* revis void BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision) { + lock_drawing->lock(); if (revision == _revision) { - lock_drawing->lock(); for (int ix = 0; ix < w; ix++) { for (int iy = 0; iy < h; iy++) @@ -341,9 +341,9 @@ void BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int pixbuf->setPixel(x + ix, y + iy, chunk->pixel(ix, iy)); } } - lock_drawing->unlock(); emit contentChange(); } + lock_drawing->unlock(); } QColor BasePreview::getPixelColor(int x, int y) @@ -356,14 +356,7 @@ void BasePreview::handleRedraw() lock_drawing->lock(); updateData(); - - QImage part = pixbuf->copy(); - pixbuf->fill(0x00000000); - QPainter painter(pixbuf); - painter.setOpacity(0.99); - painter.drawImage(0, 0, part); - - updateChunks(); + invalidatePixbuf(128); lock_drawing->unlock(); } @@ -426,6 +419,22 @@ void BasePreview::updateChunks() _revision++; } +void BasePreview::invalidatePixbuf(int value) +{ + for (int ix = 0; ix < _width; ix++) + { + for (int iy = 0; iy < _height; iy++) + { + QRgb col = pixbuf->pixel(ix, iy); + if (qAlpha(col) == 255) + { + pixbuf->setPixel(ix, iy, qRgba(qRed(col), qGreen(col), qBlue(col), value)); + } + } + } + updateChunks(); +} + void BasePreview::mousePressEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) @@ -590,9 +599,8 @@ void BasePreview::wheelEvent(QWheelEvent* event) QImage part = pixbuf->copy((width - new_width) / 2, (height - new_height) / 2, new_width, new_height).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QPainter painter(pixbuf); pixbuf->fill(0x00000000); - painter.setOpacity(0.99); painter.drawImage(0, 0, part); - updateChunks(); + invalidatePixbuf(254); lock_drawing->unlock(); emit contentChange(); @@ -603,9 +611,8 @@ void BasePreview::wheelEvent(QWheelEvent* event) QImage part = pixbuf->scaled((int) floor(((double) width) * old_scaling / scaling), (int) floor(((double) height) * old_scaling / scaling), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QPainter painter(pixbuf); pixbuf->fill(0x00000000); - painter.setOpacity(0.99); painter.drawImage((width - part.width()) / 2, (height - part.height()) / 2, part); - updateChunks(); + invalidatePixbuf(254); lock_drawing->unlock(); emit contentChange(); diff --git a/gui_qt/basepreview.h b/gui_qt/basepreview.h index 30859c1..7d0dda2 100644 --- a/gui_qt/basepreview.h +++ b/gui_qt/basepreview.h @@ -39,6 +39,7 @@ protected: private: void updateScaling(); void updateChunks(); + void invalidatePixbuf(int value); void showEvent(QShowEvent* event); void resizeEvent(QResizeEvent* event);