Add support for ICC color profiles

This commit is contained in:
2022-10-18 20:34:07 +02:00
parent 95c6fc5343
commit 4fe546f0e5
+20
View File
@@ -5,6 +5,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QPainter> #include <QPainter>
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QColorSpace>
#include <QDebug> #include <QDebug>
#include <iostream> #include <iostream>
#include <libexif/exif-data.h> #include <libexif/exif-data.h>
@@ -14,6 +15,8 @@
#include "starfit.h" #include "starfit.h"
#include "wcslib/wcshdr.h" #include "wcslib/wcshdr.h"
static pcl::ICCProfile sRgbIccProfile((void*)QColorSpace(QColorSpace::SRgb).iccProfile().data());
LoadRunable::LoadRunable(const QString &file, Image *receiver, AnalyzeLevel level, bool thumbnail) : LoadRunable::LoadRunable(const QString &file, Image *receiver, AnalyzeLevel level, bool thumbnail) :
m_file(file), m_file(file),
m_receiver(receiver), m_receiver(receiver),
@@ -281,11 +284,24 @@ bool loadFITS(const QString path, ImageInfoData &info, RawImage **image)
return true; return true;
} }
#include "pcl/ICCProfileTransformation.h"
template<typename T, typename PCLtype, int CVtype> template<typename T, typename PCLtype, int CVtype>
bool loadPCLImage(pcl::XISFReader &xisf, RawImage **image) bool loadPCLImage(pcl::XISFReader &xisf, RawImage **image)
{ {
PCLtype pclImage; PCLtype pclImage;
xisf.ReadImage(pclImage); xisf.ReadImage(pclImage);
pclImage.Status().DisableInitialization();
pcl::ICCProfile iccProfile = xisf.ReadICCProfile();
if(iccProfile.IsProfile())
{
pcl::ICCProfileTransformation iccTran;
iccTran.DisableParallelProcessing();
iccTran.Add(iccProfile);
iccTran.Add(sRgbIccProfile);
iccTran >> pclImage;
}
int numChannels = pclImage.NumberOfChannels(); int numChannels = pclImage.NumberOfChannels();
cv::Mat cvImg[numChannels]; cv::Mat cvImg[numChannels];
@@ -315,6 +331,7 @@ bool loadXISF(const QString &path, ImageInfoData &info, RawImage **image)
{ {
try try
{ {
pcl::XISF::EnsurePTLUTInitialized();
pcl::String pclPath = path.utf16(); pcl::String pclPath = path.utf16();
pcl::XISFReader xisf; pcl::XISFReader xisf;
xisf.Open(pclPath); xisf.Open(pclPath);
@@ -384,6 +401,9 @@ void LoadRunable::run()
else else
{ {
QImage img(m_file); QImage img(m_file);
if(img.colorSpace().isValid())
img.convertToColorSpace(QColorSpace::SRgb);
ExifData *exif = exif_data_new_from_file(m_file.toLocal8Bit().constData()); ExifData *exif = exif_data_new_from_file(m_file.toLocal8Bit().constData());
info.info.append({QObject::tr("Width"), QString::number(img.width())}); info.info.append({QObject::tr("Width"), QString::number(img.width())});
info.info.append({QObject::tr("Height"), QString::number(img.height())}); info.info.append({QObject::tr("Height"), QString::number(img.height())});