Compare commits
4 Commits
fa39440b9e
...
7b70b6a081
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b70b6a081 | |||
| 2e74d94641 | |||
| 556bb22d26 | |||
| c6581e1122 |
+1
-1
@@ -16,7 +16,7 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
|
||||
option(USE_BUNDLED_LIBS "Use bundled LZ4 PugiXML and Zlib. You can still exclude some" ON)
|
||||
cmake_dependent_option(USE_BUNDLED_LZ4 "Use bundled LZ4" ON "USE_BUNDLED_LIBS" OFF)
|
||||
cmake_dependent_option(USE_BUNDLED_PUGIXML "Use bundled PugiXML" ON "USE_BUNDLED_LIBS" OFF)
|
||||
cmake_dependent_option(USE_BUNDLED_ZLIB "Use bundled Zlib" ON "USE_BUNDLED_LIBS" OFF)
|
||||
cmake_dependent_option(USE_BUNDLED_ZLIB "Use bundled Zlib" OFF "USE_BUNDLED_LIBS" OFF)
|
||||
|
||||
find_package(PkgConfig)
|
||||
|
||||
|
||||
+31
-3
@@ -1034,11 +1034,11 @@ public:
|
||||
void save(std::ostream &io);
|
||||
void writeImage(const Image &image);
|
||||
static void writeFITSKeyword(pugi::xml_node &node, const FITSKeyword &keyword);
|
||||
static void writePropertyElement(pugi::xml_node &node, const Property &property);
|
||||
private:
|
||||
void writeHeader();
|
||||
void writeImageElement(pugi::xml_node &node, const Image &image);
|
||||
void writeDataBlockAttributes(pugi::xml_node &image_node, const DataBlock &dataBlock);
|
||||
void writePropertyElement(pugi::xml_node &node, const Property &property);
|
||||
void writeMetadata(pugi::xml_node &node);
|
||||
void updateImageAttachmentPos(pugi::xml_node &root, size_t offset);
|
||||
ByteArray _xisfHeader;
|
||||
@@ -1371,6 +1371,7 @@ public:
|
||||
void addFITSKeyword(uint32_t image, const FITSKeyword &keyword);
|
||||
void updateFITSKeyword(uint32_t image, const FITSKeyword &keyword, bool add);
|
||||
void removeFITSKeyword(uint32_t image, const String &name);
|
||||
void updateProperty(uint32_t image, const Property &property);
|
||||
private:
|
||||
void readXISFHeader();
|
||||
void parseAttachmentPos(pugi::xml_node &root);
|
||||
@@ -1382,7 +1383,6 @@ private:
|
||||
pugi::xml_document _doc;
|
||||
pugi::xml_node _root;
|
||||
std::map<int, std::pair<uint64_t, uint64_t>> _attachmentPos;// pair contain position and size
|
||||
std::map<int, std::pair<uint64_t, uint64_t>> _attachmentPosNew;
|
||||
};
|
||||
|
||||
|
||||
@@ -1445,6 +1445,8 @@ void XISFModifyPrivate::save(std::ostream &io)
|
||||
doc.append_child(pugi::node_comment).set_value("\nExtensible Image Serialization Format - XISF version 1.0\nCreated with libXISF - https://nouspiro.space\n");
|
||||
pugi::xml_node root_copy = doc.append_copy(_root);
|
||||
|
||||
parseAttachmentPos(_root);
|
||||
|
||||
uint32_t size = 0;
|
||||
std::string header;
|
||||
while(true)
|
||||
@@ -1551,6 +1553,27 @@ void XISFModifyPrivate::removeFITSKeyword(uint32_t image, const String &name)
|
||||
imageNode.remove_child(keywordNode);
|
||||
}
|
||||
|
||||
void XISFModifyPrivate::updateProperty(uint32_t image, const Property &property)
|
||||
{
|
||||
if(!_root)
|
||||
throw Error("No input file opened");
|
||||
|
||||
pugi::xpath_node_set images = _root.select_nodes("//Image");
|
||||
|
||||
if(image >= images.size())
|
||||
throw Error("Out of bounds");
|
||||
|
||||
pugi::xpath_variable_set variables;
|
||||
variables.set("id", property.id.c_str());
|
||||
pugi::xml_node imageNode = images[image].node();
|
||||
pugi::xml_node propertyNode = imageNode.select_node("Property[@id=string($id)]", &variables).node();
|
||||
|
||||
if(propertyNode)
|
||||
imageNode.remove_child(propertyNode);
|
||||
|
||||
XISFWriterPrivate::writePropertyElement(imageNode, property);
|
||||
}
|
||||
|
||||
void XISFModifyPrivate::readXISFHeader()
|
||||
{
|
||||
char signature[8];
|
||||
@@ -1579,6 +1602,7 @@ void XISFModifyPrivate::readXISFHeader()
|
||||
|
||||
void XISFModifyPrivate::parseAttachmentPos(pugi::xml_node &root)
|
||||
{
|
||||
_attachmentPos.clear();
|
||||
pugi::xpath_node_set locationAttributes = root.select_nodes("//@location");
|
||||
int i = 0;
|
||||
for(auto &attr : locationAttributes)
|
||||
@@ -1603,7 +1627,6 @@ void XISFModifyPrivate::updateAttachmentPos(pugi::xml_node &root, size_t offset)
|
||||
pugi::xml_attribute attr = locationAttributes[pos.first].attribute();
|
||||
uint64_t attachmentSize = pos.second.second;
|
||||
std::string locationStr = "attachment:" + std::to_string(offset) + ":" + std::to_string(attachmentSize);
|
||||
_attachmentPosNew[pos.first] = pos.second;
|
||||
offset += attachmentSize;
|
||||
attr.set_value(locationStr.c_str());
|
||||
}
|
||||
@@ -1669,6 +1692,11 @@ void XISFModify::removeFITSKeyword(uint32_t image, const String &name)
|
||||
p->removeFITSKeyword(image, name);
|
||||
}
|
||||
|
||||
void XISFModify::updateProperty(uint32_t image, const Property &property)
|
||||
{
|
||||
p->updateProperty(image, property);
|
||||
}
|
||||
|
||||
#define STRING_ENUM(map, map2, c, e) { map.insert({#e, c::e}); map2.insert({c::e, #e}); }
|
||||
|
||||
struct Init
|
||||
|
||||
@@ -443,6 +443,12 @@ public:
|
||||
* @param name of keyword that will be removed
|
||||
*/
|
||||
void removeFITSKeyword(uint32_t image, const String &name);
|
||||
/**
|
||||
* @brief updateProperty add new or update existing XISF Property
|
||||
* @param image index of image to update
|
||||
* @param property new value of property
|
||||
*/
|
||||
void updateProperty(uint32_t image, const Property &property);
|
||||
private:
|
||||
XISFModifyPrivate *p;
|
||||
};
|
||||
|
||||
+1
-3
@@ -17,7 +17,6 @@
|
||||
************************************************************************/
|
||||
|
||||
#include <charconv>
|
||||
#include <type_traits>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include <iomanip>
|
||||
@@ -403,7 +402,6 @@ Variant variantFromString(Variant::Type type, const String &str)
|
||||
|
||||
Variant::Type Variant::type() const
|
||||
{
|
||||
int idx = _value.index();
|
||||
return (Variant::Type)_value.index();
|
||||
}
|
||||
|
||||
@@ -442,7 +440,7 @@ String Variant::toString() const
|
||||
ss << "{";
|
||||
for(int o=0; o<matrix.cols(); o++)
|
||||
{
|
||||
#if __GNUC__ >= 11 || __clang__
|
||||
#if __GNUC__ >= 11 || __clang_major__ >= 15
|
||||
char str[128] = {0};
|
||||
char *end = str + sizeof(str);
|
||||
std::to_chars(str, end, matrix(i, o));
|
||||
|
||||
Reference in New Issue
Block a user