Add compression parameters
This commit is contained in:
+32
-2
@@ -517,10 +517,11 @@ bool loadImage(const QString &path, ImageInfoData &info, std::shared_ptr<RawImag
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConvertRunable::ConvertRunable(const QString &in, const QString &out, const QString &format) :
|
ConvertRunable::ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms) :
|
||||||
m_infile(in),
|
m_infile(in),
|
||||||
m_outfile(out),
|
m_outfile(out),
|
||||||
m_format(format)
|
m_format(format),
|
||||||
|
m_params(params)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,6 +599,7 @@ void writeFITSImage(fitsfile *fw, std::shared_ptr<RawImage> rawimage, ImageInfoD
|
|||||||
|
|
||||||
void ConvertRunable::run()
|
void ConvertRunable::run()
|
||||||
{
|
{
|
||||||
|
qDebug() << m_infile << m_outfile;
|
||||||
ImageInfoData imageinfo;
|
ImageInfoData imageinfo;
|
||||||
std::shared_ptr<RawImage> rawimage;
|
std::shared_ptr<RawImage> rawimage;
|
||||||
loadImage(m_infile, imageinfo, rawimage);
|
loadImage(m_infile, imageinfo, rawimage);
|
||||||
@@ -646,6 +648,18 @@ void ConvertRunable::run()
|
|||||||
image.addFITSKeyword({record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()});
|
image.addFITSKeyword({record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_params.compressionType.startsWith("zstd") && LibXISF::DataBlock::CompressionCodecSupported(LibXISF::DataBlock::ZSTD))
|
||||||
|
image.setCompression(LibXISF::DataBlock::ZSTD, m_params.compressionLevel);
|
||||||
|
else if(m_params.compressionType.startsWith("lz4hc"))
|
||||||
|
image.setCompression(LibXISF::DataBlock::LZ4HC, m_params.compressionLevel);
|
||||||
|
else if(m_params.compressionType.startsWith("lz4"))
|
||||||
|
image.setCompression(LibXISF::DataBlock::LZ4, m_params.compressionLevel);
|
||||||
|
else if(m_params.compressionType.startsWith("zlib"))
|
||||||
|
image.setCompression(LibXISF::DataBlock::Zlib, m_params.compressionLevel);
|
||||||
|
|
||||||
|
if(m_params.compressionType.endsWith("+sh"))
|
||||||
|
image.setByteshuffling(true);
|
||||||
|
|
||||||
xisf.writeImage(image);
|
xisf.writeImage(image);
|
||||||
xisf.save(m_outfile.toLocal8Bit().data());
|
xisf.save(m_outfile.toLocal8Bit().data());
|
||||||
}
|
}
|
||||||
@@ -661,6 +675,13 @@ void ConvertRunable::run()
|
|||||||
fitsfile *fw;
|
fitsfile *fw;
|
||||||
if(QFileInfo(m_outfile).exists())QFile::remove(m_outfile);
|
if(QFileInfo(m_outfile).exists())QFile::remove(m_outfile);
|
||||||
fits_create_diskfile(&fw, m_outfile.toLocal8Bit().data(), &status);
|
fits_create_diskfile(&fw, m_outfile.toLocal8Bit().data(), &status);
|
||||||
|
if(!m_params.compressionType.isEmpty())
|
||||||
|
{
|
||||||
|
if(m_params.compressionType == "gzip")
|
||||||
|
fits_set_compression_type(fw, GZIP_1, &status);
|
||||||
|
else if(m_params.compressionType == "rice")
|
||||||
|
fits_set_compression_type(fw, RICE_1, &status);
|
||||||
|
}
|
||||||
writeFITSImage(fw, rawimage, imageinfo);
|
writeFITSImage(fw, rawimage, imageinfo);
|
||||||
fits_close_file(fw, &status);
|
fits_close_file(fw, &status);
|
||||||
}
|
}
|
||||||
@@ -694,3 +715,12 @@ void ConvertRunable::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConvertRunable::ConvertParams::ConvertParams(const QVariantMap &map)
|
||||||
|
{
|
||||||
|
if(map.contains("compressionLevel"))
|
||||||
|
compressionLevel = map["compressionLevel"].toInt();
|
||||||
|
|
||||||
|
if(map.contains("compressionType"))
|
||||||
|
compressionType = map["compressionType"].toString();
|
||||||
|
}
|
||||||
|
|||||||
+13
-3
@@ -24,14 +24,24 @@ public:
|
|||||||
void run() override;
|
void run() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ConvertRunable : public QRunnable
|
class ConvertRunable : public QRunnable
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
struct ConvertParams
|
||||||
|
{
|
||||||
|
int compressionLevel = -1;
|
||||||
|
QString compressionType;
|
||||||
|
ConvertParams(){}
|
||||||
|
ConvertParams(const QVariantMap &map);
|
||||||
|
};
|
||||||
|
ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms = ConvertParams());
|
||||||
|
void run() override;
|
||||||
|
private:
|
||||||
QString m_infile;
|
QString m_infile;
|
||||||
QString m_outfile;
|
QString m_outfile;
|
||||||
QString m_format;
|
QString m_format;
|
||||||
public:
|
ConvertParams m_params;
|
||||||
ConvertRunable(const QString &in, const QString &out, const QString &format);
|
|
||||||
void run() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOADRUNABLE_H
|
#endif // LOADRUNABLE_H
|
||||||
|
|||||||
+2
-3
@@ -66,9 +66,8 @@ bool ScriptEngine::isMarked(const File *file) const
|
|||||||
return _database->isMarked(file->absoluteFilePath());
|
return _database->isMarked(file->absoluteFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptEngine::convert(File *file, QString &outpath, QJSValue ¶ms)
|
bool ScriptEngine::convert(File *file, QString &outpath, QString format, QVariantMap params)
|
||||||
{
|
{
|
||||||
QString format = params.toString();
|
|
||||||
QString path;
|
QString path;
|
||||||
QDir dir(_outputDir);
|
QDir dir(_outputDir);
|
||||||
QFileInfo info(outpath);
|
QFileInfo info(outpath);
|
||||||
@@ -80,7 +79,7 @@ bool ScriptEngine::convert(File *file, QString &outpath, QJSValue ¶ms)
|
|||||||
|
|
||||||
info.setFile(path);
|
info.setFile(path);
|
||||||
//qDebug() << info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower();
|
//qDebug() << info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower();
|
||||||
_pool->start(new ConvertRunable(file->absoluteFilePath(), info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower(), format));
|
_pool->start(new ConvertRunable(file->absoluteFilePath(), info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower(), format, params));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ public:
|
|||||||
Q_INVOKABLE void mark(File *file);
|
Q_INVOKABLE void mark(File *file);
|
||||||
Q_INVOKABLE void unmark(File *file);
|
Q_INVOKABLE void unmark(File *file);
|
||||||
Q_INVOKABLE bool isMarked(const File *file) const;
|
Q_INVOKABLE bool isMarked(const File *file) const;
|
||||||
Q_INVOKABLE bool convert(File *file, QString &outpath, QJSValue ¶ms);
|
Q_INVOKABLE bool convert(File *file, QString &outpath, QString format, QVariantMap params);
|
||||||
QJSValue newObject();
|
QJSValue newObject();
|
||||||
public slots:
|
public slots:
|
||||||
void run();
|
void run();
|
||||||
|
|||||||
Reference in New Issue
Block a user