Don't use replace to update attachement position
This commit is contained in:
+31
-13
@@ -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);
|
||||||
|
|
||||||
|
uint32_t size = 0;
|
||||||
|
std::string header;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
std::stringstream xml;
|
std::stringstream xml;
|
||||||
xml.write(signature, sizeof(signature));
|
xml.write(signature, sizeof(signature));
|
||||||
doc.save(xml, "", pugi::format_raw);
|
doc.save(xml, "", pugi::format_raw);
|
||||||
|
header = xml.str();
|
||||||
std::string header = xml.str();
|
if(size != header.size())
|
||||||
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);
|
size = header.size();
|
||||||
size_t pos = header.find(replace, 32);
|
updateImageAttachmentPos(root, size);
|
||||||
header.replace(pos, replace.size(), blockPos);
|
}
|
||||||
offset += image._dataBlock.data.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;
|
||||||
|
|||||||
Reference in New Issue
Block a user