Add support for FITSKeywords
This commit is contained in:
@@ -37,6 +37,7 @@ Thumbs.db
|
|||||||
|
|
||||||
# qtcreator generated files
|
# qtcreator generated files
|
||||||
*.pro.user*
|
*.pro.user*
|
||||||
|
CMakeLists.txt.user
|
||||||
|
|
||||||
# xemacs temporary files
|
# xemacs temporary files
|
||||||
*.flc
|
*.flc
|
||||||
@@ -71,3 +72,4 @@ Thumbs.db
|
|||||||
*.dll
|
*.dll
|
||||||
*.exe
|
*.exe
|
||||||
|
|
||||||
|
/build*
|
||||||
|
|||||||
+24
-9
@@ -410,6 +410,8 @@ void XISFReader::readImageElement()
|
|||||||
{
|
{
|
||||||
if(_xml->name() == "Property")
|
if(_xml->name() == "Property")
|
||||||
image.properties.push_back(readPropertyElement());
|
image.properties.push_back(readPropertyElement());
|
||||||
|
else if(_xml->name() == "FITSKeyword")
|
||||||
|
image.fitsKeywords.push_back(readFITSKeyword());
|
||||||
else if(_xml->name() == "ICCProfile")
|
else if(_xml->name() == "ICCProfile")
|
||||||
{
|
{
|
||||||
DataBlock icc = readDataBlock();
|
DataBlock icc = readDataBlock();
|
||||||
@@ -442,6 +444,15 @@ Property XISFReader::readPropertyElement()
|
|||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FITSKeyword XISFReader::readFITSKeyword()
|
||||||
|
{
|
||||||
|
QXmlStreamAttributes attributes = _xml->attributes();
|
||||||
|
if(attributes.hasAttribute("name") && attributes.hasAttribute("value") && attributes.hasAttribute("comment"))
|
||||||
|
return { attributes.value("name").toString(), attributes.value("value").toString(), attributes.value("comment").toString() };
|
||||||
|
else
|
||||||
|
throw Error("Invalid FITSKeyword element");
|
||||||
|
}
|
||||||
|
|
||||||
void XISFReader::readDataElement(DataBlock &dataBlock)
|
void XISFReader::readDataElement(DataBlock &dataBlock)
|
||||||
{
|
{
|
||||||
_xml->readNextStartElement();
|
_xml->readNextStartElement();
|
||||||
@@ -552,15 +563,6 @@ void XISFWriter::save(QIODevice &io)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XISFWriter::saveXML(const QString &name)
|
|
||||||
{
|
|
||||||
QFile fw(name);
|
|
||||||
fw.open(QIODevice::WriteOnly);
|
|
||||||
QByteArray header = _xisfHeader.mid(16);
|
|
||||||
header.truncate(header.indexOf('\0'));
|
|
||||||
fw.write(header);
|
|
||||||
}
|
|
||||||
|
|
||||||
void XISFWriter::writeImage(const Image &image)
|
void XISFWriter::writeImage(const Image &image)
|
||||||
{
|
{
|
||||||
_images.push_back(image);
|
_images.push_back(image);
|
||||||
@@ -633,6 +635,9 @@ void XISFWriter::writeImageElement(const Image &image)
|
|||||||
for(auto &property : image.properties)
|
for(auto &property : image.properties)
|
||||||
writePropertyElement(property);
|
writePropertyElement(property);
|
||||||
|
|
||||||
|
for(auto &fitsKeyword : image.fitsKeywords)
|
||||||
|
writeFITSKeyword(fitsKeyword);
|
||||||
|
|
||||||
_xml->writeEndElement();
|
_xml->writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,6 +708,16 @@ void XISFWriter::writePropertyElement(const Property &property)
|
|||||||
throw Error("Failed to write property");
|
throw Error("Failed to write property");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XISFWriter::writeFITSKeyword(const FITSKeyword &keyword)
|
||||||
|
{
|
||||||
|
_xml->writeEmptyElement("FITSKeyword");
|
||||||
|
_xml->writeAttribute("name", keyword.name);
|
||||||
|
_xml->writeAttribute("value", keyword.value);
|
||||||
|
_xml->writeAttribute("comment", keyword.comment);
|
||||||
|
if(_xml->hasError())
|
||||||
|
throw Error("Failed to write FITS keyword");
|
||||||
|
}
|
||||||
|
|
||||||
void XISFWriter::writeMetadata()
|
void XISFWriter::writeMetadata()
|
||||||
{
|
{
|
||||||
_xml->writeStartElement("Metadata");
|
_xml->writeStartElement("Metadata");
|
||||||
|
|||||||
@@ -66,6 +66,13 @@ struct Property
|
|||||||
value(QVariant::fromValue<T>(_value)){}
|
value(QVariant::fromValue<T>(_value)){}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FITSKeyword
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
QString value;
|
||||||
|
QString comment;
|
||||||
|
};
|
||||||
|
|
||||||
struct Image
|
struct Image
|
||||||
{
|
{
|
||||||
enum Type
|
enum Type
|
||||||
@@ -119,6 +126,7 @@ struct Image
|
|||||||
DataBlock dataBlock;
|
DataBlock dataBlock;
|
||||||
QByteArray iccProfile;
|
QByteArray iccProfile;
|
||||||
std::vector<Property> properties;
|
std::vector<Property> properties;
|
||||||
|
std::vector<FITSKeyword> fitsKeywords;
|
||||||
|
|
||||||
void convertPixelStorageTo(PixelStorage storage);
|
void convertPixelStorageTo(PixelStorage storage);
|
||||||
|
|
||||||
@@ -138,7 +146,7 @@ public:
|
|||||||
XISFReader();
|
XISFReader();
|
||||||
void open(const QString &name);
|
void open(const QString &name);
|
||||||
void open(const QByteArray &data);
|
void open(const QByteArray &data);
|
||||||
/** Open image from */
|
/** Open image from QIODevice. This method takes ownership of *io pointer */
|
||||||
void open(QIODevice *io);
|
void open(QIODevice *io);
|
||||||
void close();
|
void close();
|
||||||
int imagesCount() const;
|
int imagesCount() const;
|
||||||
@@ -148,6 +156,7 @@ private:
|
|||||||
void readSignature();
|
void readSignature();
|
||||||
void readImageElement();
|
void readImageElement();
|
||||||
Property readPropertyElement();
|
Property readPropertyElement();
|
||||||
|
FITSKeyword readFITSKeyword();
|
||||||
void readDataElement(DataBlock &dataBlock);
|
void readDataElement(DataBlock &dataBlock);
|
||||||
DataBlock readDataBlock();
|
DataBlock readDataBlock();
|
||||||
void readCompression(DataBlock &dataBlock);
|
void readCompression(DataBlock &dataBlock);
|
||||||
@@ -165,7 +174,6 @@ public:
|
|||||||
void save(const QString &name);
|
void save(const QString &name);
|
||||||
void save(QByteArray &data);
|
void save(QByteArray &data);
|
||||||
void save(QIODevice &io);
|
void save(QIODevice &io);
|
||||||
void saveXML(const QString &name);
|
|
||||||
void writeImage(const Image &image);
|
void writeImage(const Image &image);
|
||||||
private:
|
private:
|
||||||
void writeHeader();
|
void writeHeader();
|
||||||
@@ -173,6 +181,7 @@ private:
|
|||||||
void writeDataBlockAttributes(const DataBlock &dataBlock);
|
void writeDataBlockAttributes(const DataBlock &dataBlock);
|
||||||
void writeCompressionAttributes(const DataBlock &dataBlock);
|
void writeCompressionAttributes(const DataBlock &dataBlock);
|
||||||
void writePropertyElement(const Property &property);
|
void writePropertyElement(const Property &property);
|
||||||
|
void writeFITSKeyword(const FITSKeyword &keyword);
|
||||||
void writeMetadata();
|
void writeMetadata();
|
||||||
std::unique_ptr<QXmlStreamWriter> _xml;
|
std::unique_ptr<QXmlStreamWriter> _xml;
|
||||||
QByteArray _xisfHeader;
|
QByteArray _xisfHeader;
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ int main(int argc, char **argv)
|
|||||||
image.properties.push_back(Property("PropertyFloat64", (Float64) 0.64));
|
image.properties.push_back(Property("PropertyFloat64", (Float64) 0.64));
|
||||||
image.properties.push_back(Property("PropertyComplex32", Complex32{3.0, -2.0}));
|
image.properties.push_back(Property("PropertyComplex32", Complex32{3.0, -2.0}));
|
||||||
image.properties.push_back(Property("PropertyComplex64", Complex64{-3.0, 2.0}));
|
image.properties.push_back(Property("PropertyComplex64", Complex64{-3.0, 2.0}));
|
||||||
|
image.fitsKeywords.push_back({"RA", "226.9751163116387", "Right ascension of the center of the image (deg)"});
|
||||||
|
image.fitsKeywords.push_back({"DEC", "62.02302376908295", "Declination of the center of the image (deg)"});
|
||||||
writer.writeImage(image);
|
writer.writeImage(image);
|
||||||
|
|
||||||
image.imageType = Image::Flat;
|
image.imageType = Image::Flat;
|
||||||
|
|||||||
Reference in New Issue
Block a user