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)
|
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.")
|
||||||
|
|
||||||
|
|||||||
+32
-14
@@ -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);
|
||||||
|
|
||||||
|
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