Add ability to have user defined colormaps
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define IMAGESCROLLAREA_H
|
||||
|
||||
#include "imagewidget.h"
|
||||
#include <QScrollBar>
|
||||
|
||||
class ImageScrollArea : public QWidget
|
||||
{
|
||||
|
||||
+24
-4
@@ -9,8 +9,10 @@
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QPainter>
|
||||
#include "imageringlist.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QFloat16>
|
||||
#include <QStyle>
|
||||
#include "imageringlist.h"
|
||||
|
||||
int FILTERING = 1;
|
||||
bool OpenGLES = false;
|
||||
@@ -774,9 +776,7 @@ void ImageWidgetGL::initializeGL()
|
||||
m_lut->allocateStorage();
|
||||
m_lut->bind(2);
|
||||
|
||||
QImage colormap(":/colormap.png");
|
||||
colormap = colormap.convertToFormat(QImage::Format_RGBA8888);
|
||||
qDebug() << colormap;
|
||||
QImage colormap = loadColormap();
|
||||
m_colormap = std::make_unique<QOpenGLTexture>(QOpenGLTexture::Target1DArray);
|
||||
m_colormap->setSize(colormap.width());
|
||||
m_colormap->setLayers(colormap.height());
|
||||
@@ -970,3 +970,23 @@ void ImageWidgetGL::updateScrollBars()
|
||||
else
|
||||
emit scrollBarsUpdate(m_dx, m_width, m_imgWidth * m_scale - m_width, m_dy, m_height, m_imgHeight * m_scale - m_height);
|
||||
}
|
||||
|
||||
QImage ImageWidget::loadColormap()
|
||||
{
|
||||
QImage embedded(":/colormap.png");
|
||||
QStringList path = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
|
||||
if(path.size())
|
||||
{
|
||||
QImage user(path.first() + "/colormap.png");
|
||||
if(!user.isNull())
|
||||
{
|
||||
user = user.scaledToWidth(embedded.width(), Qt::SmoothTransformation);
|
||||
QImage tmp(embedded.width(), embedded.height() + user.height(), QImage::Format_RGBA8888);
|
||||
QPainter painter(&tmp);
|
||||
painter.drawImage(0, 0, embedded);
|
||||
painter.drawImage(0, embedded.height(), user);
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
return embedded.convertToFormat(QImage::Format_RGBA8888);
|
||||
}
|
||||
|
||||
+3
-1
@@ -10,7 +10,7 @@
|
||||
#include <QOpenGLFunctions>
|
||||
#include "database.h"
|
||||
#include "rawimage.h"
|
||||
#include "imageinfo.h"
|
||||
#include "imageinfodata.h"
|
||||
#include "stretchtoolbar.h"
|
||||
|
||||
class ImageWidget
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
virtual QImage renderToImage() = 0;
|
||||
virtual void thumbnailLoaded(const Image *image) = 0;
|
||||
virtual void showThumbnail(bool enable) = 0;
|
||||
|
||||
static QImage loadColormap();
|
||||
};
|
||||
|
||||
struct ImageThumb
|
||||
|
||||
+6
-6
@@ -211,14 +211,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
"Inferno", "Plasma", "Viridis", "Cividis", "Twilight", "Twilight shifted", "Turbo", "Deepgreen"};
|
||||
QMenu *colormapMenu = viewMenu->addMenu(tr("Colormap"));
|
||||
QActionGroup *colormapActionGroup = new QActionGroup(this);
|
||||
int idx = 0;
|
||||
QImage cmImg(":/colormap.png");
|
||||
for(QString &colormap : colormaps)
|
||||
|
||||
QImage cmImg = ImageWidget::loadColormap();
|
||||
for(int i=0; i<cmImg.height(); i++)
|
||||
{
|
||||
QImage icon = cmImg.copy(0, idx, cmImg.width(), 1).scaled(32, 32);
|
||||
QAction *action = colormapActionGroup->addAction(colormap);
|
||||
QImage icon = cmImg.copy(0, i, cmImg.width(), 1).scaled(32, 32);
|
||||
QAction *action = colormapActionGroup->addAction(i < colormaps.size() ? colormaps[i] : tr("User %1").arg(i - colormaps.size() + 1));
|
||||
action->setIcon(QPixmap::fromImage(icon));
|
||||
action->setCheckable(true); action->setData(idx++);
|
||||
action->setCheckable(true); action->setData(i);
|
||||
colormapMenu->addAction(action);
|
||||
}
|
||||
viewMenu->addMenu(colormapMenu);
|
||||
|
||||
Reference in New Issue
Block a user