Add thumbnailer

This commit is contained in:
2025-02-16 23:36:25 +01:00
parent c36068aaf4
commit 58c182adc0
5 changed files with 99 additions and 7 deletions
+18 -7
View File
@@ -1,12 +1,17 @@
#include "rawimage.h"
#include <QDebug>
#include <cstring>
#include <lcms2.h>
#ifndef NO_QT
#include <QDebug>
#include <QElapsedTimer>
#include <QFloat16>
#include <QColorSpace>
#include <lcms2.h>
using F16 = qfloat16;
#else
#include <algorithm>
using F16 = uint16_t;
#endif
int THUMB_SIZE = 128;
int THUMB_SIZE_BORDER = 138;
@@ -78,6 +83,7 @@ RawImage::RawImage(RawImage &&d)
m_thumbAspect = d.m_thumbAspect;
}
#ifndef NO_QT
RawImage::RawImage(const QImage &img)
{
qDebug() << img;
@@ -145,6 +151,7 @@ RawImage::RawImage(const QImage &img)
}
m_stats.m_stats = false;
}
#endif
const RawImage::Stats& RawImage::imageStats() const
{
@@ -439,7 +446,9 @@ void RawImage::convertToThumbnail()
loop(out, reinterpret_cast<float*>(m_pixels.get()), 1.0f);
break;
default:
#ifndef NO_QT
qWarning() << "FLOAT64 should not happend";
#endif
return;
}
@@ -922,11 +931,13 @@ bool RawImage::valid() const
return m_width > 0 && m_height > 0;
}
#ifndef NO_QT
void RawImage::setICCProfile(const QByteArray &icc)
{
if(icc.size())
m_iccProfile = std::vector<uint8_t>(icc.begin(), icc.end());
}
#endif
void RawImage::setICCProfile(const LibXISF::ByteArray &icc)
{
@@ -973,12 +984,12 @@ void RawImage::convertTosRGB()
}
else
{
qDebug() << "Failed to create color transform";
//qDebug() << "Failed to create color transform";
}
}
else
{
qDebug() << "Failed to open icc profile";
//qDebug() << "Failed to open icc profile";
}
cmsCloseProfile(inProfile);
@@ -1022,13 +1033,13 @@ void RawImage::generateLUT()
}
else
{
qDebug() << "Failed to create color transform";
//qDebug() << "Failed to create color transform";
m_lut.clear();
}
}
else
{
qDebug() << "Failed to open icc profile";
//qDebug() << "Failed to open icc profile";
m_lut.clear();
}
+6
View File
@@ -7,7 +7,9 @@
#include <stdint.h>
#include <math.h>
#include <memory.h>
#ifndef NO_QT
#include <QImage>
#endif
extern int THUMB_SIZE;
extern int THUMB_SIZE_BORDER;
@@ -83,7 +85,9 @@ public:
RawImage(uint32_t w, uint32_t h, uint32_t ch, DataType type);
RawImage(const RawImage &d);
RawImage(RawImage &&d);
#ifndef NO_QT
RawImage(const QImage &img);
#endif
const RawImage::Stats& imageStats() const;
void calcStats();
uint32_t width() const;
@@ -116,7 +120,9 @@ public:
static size_t typeSize(DataType type);
std::vector<RawImage> split() const;
bool valid() const;
#ifndef NO_QT
void setICCProfile(const QByteArray &icc);
#endif
void setICCProfile(const LibXISF::ByteArray &icc);
void convertTosRGB();
void generateLUT();
+26
View File
@@ -0,0 +1,26 @@
option(BUILD_THUMBNAILER "Build generator of thumbnails" OFF)
if(BUILD_THUMBNAILER)
if(WIN32)
add_library(tenmonthumbnailer SHARED
winmain.cpp
../rawimage.cpp
../rawimage_sse.cpp)
target_compile_definitions(tenmonthumbnailer PRIVATE NO_QT)
target_include_directories(tenmonthumbnailer PRIVATE ../libXISF)
target_link_libraries(tenmonthumbnailer PRIVATE ${LCMS2_LIB} XISF)
else(WIN32)
qt_add_executable(tenmonthumbnailer
main.cpp
../rawimage.cpp
../rawimage_sse.cpp
../loadimage.cpp
../imageinfodata.cpp)
target_link_libraries(tenmonthumbnailer PRIVATE Qt6::Core Qt6::Gui ${EXIF_LIB} ${FITS_LIB} ${RAW_LIB} ${WCS_LIB} ${LCMS2_LIB} XISF)
target_include_directories(tenmonthumbnailer PRIVATE ../libXISF)
endif(WIN32)
endif(BUILD_THUMBNAILER)
+48
View File
@@ -0,0 +1,48 @@
#include <QCoreApplication>
#include <QCommandLineParser>
#include "../rawimage.h"
#include "../loadimage.h"
bool OpenGLES = false;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCommandLineParser parser;
parser.addOption({{"s", "size"}, "Size of the thumbnail in pixels (default: 128)", "size", "128"});
parser.addPositionalArgument("input", "Input image file");
parser.addPositionalArgument("output", "Output image file");
parser.addHelpOption();
parser.process(a);
QStringList args = parser.positionalArguments();
if(args.size() < 2)
return 1;
QString input = args[0];
QString output = args[1];
ImageInfoData info;
std::shared_ptr<RawImage> rawImage;
if(!loadImage(input, info, rawImage))
return 1;
if(!rawImage)
return 2;
rawImage->convertToType(RawImage::UINT8);
QImage img((const uchar*)rawImage->data(), rawImage->width(), rawImage->height(), QImage::Format_RGBA8888);
bool ok = false;
int size = parser.value("s").toInt(&ok);
if(!ok)size = 128;
img = img.scaled(size, size, Qt::KeepAspectRatio);
img.save(output, "png");
//rawImage->convertTosRGB();
return 0;
}
+1
View File
@@ -0,0 +1 @@
bool OpenGLES = false;