Compare commits
3 Commits
4db1d86530
...
v0.2.12
| Author | SHA1 | Date | |
|---|---|---|---|
| 87d65a31fc | |||
| f704b9f041 | |||
| c1e986080c |
+1
-1
@@ -1,6 +1,6 @@
|
||||
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
|
||||
DESCRIPTION "LibXISF is C++ library that can read and write XISF files produced by PixInsight.")
|
||||
|
||||
|
||||
+35
-17
@@ -179,12 +179,12 @@ void DataBlock::decompress(const ByteArray &input, const String &encoding)
|
||||
dstPtr += block.second;
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
throw Error("ZSTD support not compiled");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
subblocks.clear();
|
||||
|
||||
@@ -956,6 +956,7 @@ private:
|
||||
void writePropertyElement(pugi::xml_node &node, const Property &property);
|
||||
void writeFITSKeyword(pugi::xml_node &node, const FITSKeyword &keyword);
|
||||
void writeMetadata(pugi::xml_node &node);
|
||||
void updateImageAttachmentPos(pugi::xml_node &root, size_t offset);
|
||||
ByteArray _xisfHeader;
|
||||
ByteArray _attachmentsData;
|
||||
std::vector<Image> _images;
|
||||
@@ -1026,25 +1027,26 @@ void XISFWriterPrivate::writeHeader()
|
||||
|
||||
writeMetadata(root);
|
||||
|
||||
std::stringstream xml;
|
||||
xml.write(signature, sizeof(signature));
|
||||
doc.save(xml, "", pugi::format_raw);
|
||||
|
||||
std::string header = xml.str();
|
||||
uint32_t size = header.size();
|
||||
|
||||
uint32_t offset = 0;
|
||||
std::string replace = "attachment:2147483648";
|
||||
for(auto &image : _images)
|
||||
uint32_t size = 0;
|
||||
std::string header;
|
||||
while(true)
|
||||
{
|
||||
std::string blockPos = std::string("attachment:") + std::to_string(size + offset);
|
||||
size_t pos = header.find(replace, 32);
|
||||
header.replace(pos, replace.size(), blockPos);
|
||||
offset += image._dataBlock.data.size();
|
||||
std::stringstream xml;
|
||||
xml.write(signature, sizeof(signature));
|
||||
doc.save(xml, "", pugi::format_raw);
|
||||
header = xml.str();
|
||||
if(size != header.size())
|
||||
{
|
||||
size = header.size();
|
||||
updateImageAttachmentPos(root, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t headerSize = header.size() - sizeof(signature);
|
||||
header.resize(size, 0);
|
||||
header.replace(8, sizeof(uint32_t), (const char*)&headerSize, sizeof(uint32_t));
|
||||
|
||||
_xisfHeader = ByteArray(header.c_str(), header.size());
|
||||
@@ -1104,7 +1106,10 @@ void XISFWriterPrivate::writeDataBlockAttributes(pugi::xml_node &image_node, con
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -1177,6 +1182,19 @@ void XISFWriterPrivate::writeMetadata(pugi::xml_node &node)
|
||||
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()
|
||||
{
|
||||
p = new XISFReaderPrivate;
|
||||
|
||||
Reference in New Issue
Block a user