Add indexing of XISF

This commit is contained in:
Dušan Poizl 2022-04-12 09:03:29 +02:00
parent 0fb27266c7
commit a44c456cab
4 changed files with 64 additions and 31 deletions

@ -110,7 +110,7 @@ bool Database::checkError(QSqlQuery &query)
}
}
static QStringList nameFilters = {"*.fit", "*.fits"};
static QStringList nameFilters = {"*.fit", "*.fits", "*.xisf"};
static int countFiles(const QDir &dir, int count = 0)
{
@ -176,33 +176,41 @@ bool Database::indexDir2(const QDir &dir, QProgressDialog *progress)
}
}
readFITSHeader(filePath, info);
m_insertFile.bindValue(0, filePath);
m_insertFile.bindValue(1, mtime);
if(!m_insertFile.exec())
{
qDebug() << m_insertFile.lastError();
return false;
}
qlonglong last_id = m_insertFile.lastInsertId().toLongLong();
QVariantList file_id, keys, values, comments;
for(auto &record : info.fitsHeader)
{
file_id << last_id;
keys << QString(record.key);
values << record.value.toString();
comments << QString(record.comment);
}
m_insertFitsHeader.bindValue(0, file_id);
m_insertFitsHeader.bindValue(1, keys);
m_insertFitsHeader.bindValue(2, values);
m_insertFitsHeader.bindValue(3, comments);
if(!m_insertFitsHeader.execBatch())
{
qDebug() << m_insertFitsHeader.lastError();
return false;
}
bool ok;
if(filePath.endsWith(".xisf", Qt::CaseInsensitive))
ok = readXISFHeader(filePath, info);
else
ok = readFITSHeader(filePath, info);
qlonglong last_id = -1;
if(ok)
{
m_insertFile.bindValue(0, filePath);
m_insertFile.bindValue(1, mtime);
if(!m_insertFile.exec())
{
qDebug() << m_insertFile.lastError();
return false;
}
last_id = m_insertFile.lastInsertId().toLongLong();
QVariantList file_id, keys, values, comments;
for(auto &record : info.fitsHeader)
{
file_id << last_id;
keys << QString(record.key);
values << record.value.toString();
comments << QString(record.comment);
}
m_insertFitsHeader.bindValue(0, file_id);
m_insertFitsHeader.bindValue(1, keys);
m_insertFitsHeader.bindValue(2, values);
m_insertFitsHeader.bindValue(3, comments);
if(!m_insertFitsHeader.execBatch())
{
qDebug() << m_insertFitsHeader.lastError();
return false;
}
}
qDebug() << filePath << last_id;
info.fitsHeader.clear();
}

@ -449,8 +449,32 @@ bool readFITSHeader(const QString &path, ImageInfoData &info)
int status = 0;
fits_open_diskfile(&fr, path.toLocal8Bit().data(), READONLY, &status);
status = loadFITSHeader(fr, info);
fits_close_file(fr, &status);
if(fr && status == 0)
{
status = loadFITSHeader(fr, info);
fits_close_file(fr, &status);
}
return status == 0;
}
bool readXISFHeader(const QString &path, ImageInfoData &info)
{
try
{
pcl::String pclPath = path.utf16();
pcl::XISFReader xisf;
xisf.Open(pclPath);
auto fitskeywords = xisf.ReadFITSKeywords();
for(auto fits : fitskeywords)
{
info.fitsHeader.append({fits.name.c_str(), fits.value.c_str(), fits.comment.c_str()});
}
}
catch (pcl::Error err)
{
qDebug() << err.FormatInfo().ToUTF8().c_str();
return false;
}
return true;
}

@ -6,6 +6,7 @@
#include "imageinfo.h"
bool readFITSHeader(const QString &path, ImageInfoData &info);
bool readXISFHeader(const QString &path, ImageInfoData &info);
class Image;

@ -5,5 +5,5 @@ Icon=org.nou.tenmon
Comment=FITS Image viewer
Name=Tenmon
Categories=Graphics;2DGraphics;RasterGraphics;Viewer;
MimeType=image/fits;
MimeType=image/fits;image/x-xisf;
Terminal=false