Add simple FITS image loading
This commit is contained in:
+70
-1
@@ -4,6 +4,7 @@
|
||||
#include "imageinfo.h"
|
||||
#include <QFileInfo>
|
||||
#include <libexif/exif-data.h>
|
||||
#include <fitsio2.h>
|
||||
|
||||
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<uint8_t> bits8;
|
||||
std::vector<uint16_t> bits16;
|
||||
std::vector<uint32_t> 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<size; i++)data[i] = bits8[i];
|
||||
break;
|
||||
case SHORT_IMG:
|
||||
bits16.resize(size);
|
||||
fits_read_pix(file, TUSHORT, fpixel, size, NULL, &bits16[0], NULL, &status);
|
||||
if(status)break;
|
||||
for(size_t i=0; i<size; i++)data[i] = bits16[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<size; i++)data[i] = bits16[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);
|
||||
|
||||
Reference in New Issue
Block a user