3 Commits

Author SHA1 Message Date
nou 87d65a31fc Release 0.2.12 2024-03-23 09:21:33 +01:00
nou f704b9f041 Fix wrong bracket position 2024-03-21 18:12:25 +01:00
nou c1e986080c Don't use replace to update attachement position 2024-03-21 16:52:25 +01:00
2 changed files with 36 additions and 18 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.14)
project(libXISF VERSION 0.2.11 LANGUAGES CXX C project(libXISF VERSION 0.2.12 LANGUAGES CXX C
HOMEPAGE_URL https://gitea.nouspiro.space/nou/libXISF HOMEPAGE_URL https://gitea.nouspiro.space/nou/libXISF
DESCRIPTION "LibXISF is C++ library that can read and write XISF files produced by PixInsight.") DESCRIPTION "LibXISF is C++ library that can read and write XISF files produced by PixInsight.")
+35 -17
View File
@@ -179,12 +179,12 @@ void DataBlock::decompress(const ByteArray &input, const String &encoding)
dstPtr += block.second; dstPtr += block.second;
} }
}
#else #else
throw Error("ZSTD support not compiled"); throw Error("ZSTD support not compiled");
#endif #endif
break; break;
} }
}
subblocks.clear(); subblocks.clear();
@@ -956,6 +956,7 @@ private:
void writePropertyElement(pugi::xml_node &node, const Property &property); void writePropertyElement(pugi::xml_node &node, const Property &property);
void writeFITSKeyword(pugi::xml_node &node, const FITSKeyword &keyword); void writeFITSKeyword(pugi::xml_node &node, const FITSKeyword &keyword);
void writeMetadata(pugi::xml_node &node); void writeMetadata(pugi::xml_node &node);
void updateImageAttachmentPos(pugi::xml_node &root, size_t offset);
ByteArray _xisfHeader; ByteArray _xisfHeader;
ByteArray _attachmentsData; ByteArray _attachmentsData;
std::vector<Image> _images; std::vector<Image> _images;
@@ -1026,25 +1027,26 @@ void XISFWriterPrivate::writeHeader()
writeMetadata(root); writeMetadata(root);
std::stringstream xml; uint32_t size = 0;
xml.write(signature, sizeof(signature)); std::string header;
doc.save(xml, "", pugi::format_raw); while(true)
std::string header = xml.str();
uint32_t size = header.size();
uint32_t offset = 0;
std::string replace = "attachment:2147483648";
for(auto &image : _images)
{ {
std::string blockPos = std::string("attachment:") + std::to_string(size + offset); std::stringstream xml;
size_t pos = header.find(replace, 32); xml.write(signature, sizeof(signature));
header.replace(pos, replace.size(), blockPos); doc.save(xml, "", pugi::format_raw);
offset += image._dataBlock.data.size(); header = xml.str();
if(size != header.size())
{
size = header.size();
updateImageAttachmentPos(root, size);
}
else
{
break;
}
} }
uint32_t headerSize = header.size() - sizeof(signature); uint32_t headerSize = header.size() - sizeof(signature);
header.resize(size, 0);
header.replace(8, sizeof(uint32_t), (const char*)&headerSize, sizeof(uint32_t)); header.replace(8, sizeof(uint32_t), (const char*)&headerSize, sizeof(uint32_t));
_xisfHeader = ByteArray(header.c_str(), header.size()); _xisfHeader = ByteArray(header.c_str(), header.size());
@@ -1104,7 +1106,10 @@ void XISFWriterPrivate::writeDataBlockAttributes(pugi::xml_node &image_node, con
} }
else else
{ {
std::string attachment = "attachment:2147483648:" + std::to_string(dataBlock.data.size()); std::string attachment = "attachment:";
if(dataBlock.attachmentPos == 0) attachment += "99999";
else attachment += std::to_string(dataBlock.attachmentPos);
attachment += ":" + std::to_string(dataBlock.data.size());
image_node.append_attribute("location").set_value(attachment.c_str()); image_node.append_attribute("location").set_value(attachment.c_str());
} }
@@ -1177,6 +1182,19 @@ void XISFWriterPrivate::writeMetadata(pugi::xml_node &node)
writePropertyElement(metadata, Property("XISF:CreatorApplication", "LibXISF")); writePropertyElement(metadata, Property("XISF:CreatorApplication", "LibXISF"));
} }
void XISFWriterPrivate::updateImageAttachmentPos(pugi::xml_node &root, size_t offset)
{
pugi::xpath_node_set imageNodes = root.select_nodes("//Image");
int i = 0;
for(auto &image : _images)
{
pugi::xml_node node = imageNodes[i++].node();
std::string location = "attachment:" + std::to_string(offset) + ":" + std::to_string(image._dataBlock.data.size());
offset += image._dataBlock.data.size();
node.attribute("location").set_value(location.c_str());
}
}
XISFReader::XISFReader() XISFReader::XISFReader()
{ {
p = new XISFReaderPrivate; p = new XISFReaderPrivate;