From dd9accbbb946e2febcdf1258b89c47e93bc33a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Wed, 4 Sep 2019 17:28:44 +0200 Subject: [PATCH] Add simple FITS image loading --- imageringlist.cpp | 2 +- imageselector.pro | 2 +- loadrunable.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++- mainwindow.cpp | 2 +- 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/imageringlist.cpp b/imageringlist.cpp index 14f6b1b..09e4b28 100644 --- a/imageringlist.cpp +++ b/imageringlist.cpp @@ -78,7 +78,7 @@ bool ImageRingList::setDir(const QString path, const QString ¤tFile) if(dir.exists()) { QStringList nameFilter; - nameFilter << "*.jpg" << "*.png" << "*.cr2"; + nameFilter << "*.jpg" << "*.png" << "*.cr2" << "*.fit"; QStringList list = dir.entryList(nameFilter, QDir::Files | QDir::Readable, m_liveMode ? QDir::Time : QDir::Name); QStringList absolutePaths; diff --git a/imageselector.pro b/imageselector.pro index 7436d7c..6af2146 100644 --- a/imageselector.pro +++ b/imageselector.pro @@ -13,7 +13,7 @@ TEMPLATE = app CONFIG += c++11 -LIBS += -lraw -lexif +LIBS += -lraw -lexif -lcfitsio SOURCES += main.cpp\ mainwindow.cpp \ diff --git a/loadrunable.cpp b/loadrunable.cpp index bd2b59c..0af8f07 100644 --- a/loadrunable.cpp +++ b/loadrunable.cpp @@ -4,6 +4,7 @@ #include "imageinfo.h" #include #include +#include LoadRunable::LoadRunable(const QString &file, Image *receiver) : m_file(file), @@ -22,6 +23,69 @@ void loadExifEntry(ImageInfoData &info, ExifContent *content, ExifTag tag) } } +QImage loadFITS(QString path, ImageInfoData &info) +{ + QImage img; + fitsfile *file; + int status = 0; + int type; + fits_open_image(&file, path.toLocal8Bit().data(), READONLY, &status); + fits_get_hdu_type(file, &type, &status); + if(type == IMAGE_HDU) + { + int imgtype; + int naxis; + long naxes[2]; + fits_get_img_param(file, 2, &imgtype, &naxis, naxes, &status); + + if(naxis == 2) + { + std::vector bits8; + std::vector bits16; + std::vector bits32; + long fpixel[2] = {1,1}; + + size_t size = naxes[0]*naxes[1]; + img = QImage(naxes[0], naxes[1], QImage::Format_Grayscale8); + uchar *data = img.bits(); + info.append(StringPair(QObject::tr("Width"), QString::number(naxes[0]))); + info.append(StringPair(QObject::tr("Height"), QString::number(naxes[1]))); + + switch(imgtype) + { + case BYTE_IMG: + bits8.resize(size); + fits_read_pix(file, TBYTE, fpixel, size, NULL, &bits8[0], NULL, &status); + if(status)break; + for(size_t i=0; i> 8; + break; + case LONG_IMG: + bits32.resize(size); + fits_read_pix(file, TUINT, fpixel, size, NULL, &bits32[0], NULL, &status); + if(status)break; + for(size_t i=0; i> 24; + break; + } + } + } + + fits_close_file(file, &status); + if(status) + { + char err[100]; + fits_get_errstatus(status, err); + info.append(StringPair(QObject::tr("Error"), QString(err))); + } + + return img; +} + void LoadRunable::run() { if(!m_receiver->isCurrent()) @@ -58,7 +122,7 @@ void LoadRunable::run() } info.append(StringPair(QObject::tr("Width"), QString::number(rawImg->width))); info.append(StringPair(QObject::tr("Height"), QString::number(rawImg->height))); - info.append(StringPair(QObject::tr("ISO"), QString::number(raw.imgdata.other.iso_speed))); + info.append(StringPair(QObject::tr("ISO"), QString::number(raw.imgdata.other.iso_speed))); info.append(StringPair(QObject::tr("Shutter speed"), shutterSpeed)); #if LIBRAW_MINOR_VERSION>=19 info.append(StringPair(QObject::tr("Camera temperature"), QString::number(raw.imgdata.other.CameraTemperature))); @@ -66,6 +130,11 @@ void LoadRunable::run() raw.dcraw_clear_mem(rawImg); QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img), Q_ARG(ImageInfoData, info)); } + else if(m_file.endsWith(".FIT", Qt::CaseInsensitive)) + { + QImage img = loadFITS(m_file, info); + QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img), Q_ARG(ImageInfoData, info)); + } else { QImage img(m_file); diff --git a/mainwindow.cpp b/mainwindow.cpp index 2e44f44..ce52e3c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -149,7 +149,7 @@ void MainWindow::openFile() if(standardLocations.size()) path = standardLocations.first(); - QString file = QFileDialog::getOpenFileName(this, tr("Open file"), path, tr("Images (*.jpg *.png *.cr2 *.JPG *.PNG *.CR2)")); + QString file = QFileDialog::getOpenFileName(this, tr("Open file"), path, tr("Images (*.jpg *.png *.cr2 *.fit *.JPG *.PNG *.CR2 *.FIT)")); if(!file.isEmpty()) { QFileInfo info(file);