Compare commits
1 Commits
7b70b6a081
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| de757840b3 |
+66
-7
@@ -17,21 +17,21 @@
|
||||
************************************************************************/
|
||||
|
||||
#include "libxisf.h"
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include "streambuffer.h"
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <lz4.h>
|
||||
#include <lz4hc.h>
|
||||
#include <pugixml.hpp>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <zlib.h>
|
||||
#ifdef HAVE_ZSTD
|
||||
#include <zstd.h>
|
||||
#endif
|
||||
#include "streambuffer.h"
|
||||
|
||||
namespace LibXISF
|
||||
{
|
||||
@@ -701,6 +701,7 @@ public:
|
||||
void open(const ByteArray &data);
|
||||
/** Open image from istream. This method takes ownership of *io pointer */
|
||||
void open(std::istream *io);
|
||||
void open(const std::filesystem::path &path);
|
||||
/** Close opended file release all data. */
|
||||
void close();
|
||||
/** Return number of images inside file */
|
||||
@@ -754,6 +755,14 @@ void XISFReaderPrivate::open(std::istream *io)
|
||||
readXISFHeader();
|
||||
}
|
||||
|
||||
void XISFReaderPrivate::open(const std::filesystem::path &path)
|
||||
{
|
||||
close();
|
||||
_io = std::make_unique<std::ifstream>(path, std::ios_base::in | std::ios_base::binary);
|
||||
readSignature();
|
||||
readXISFHeader();
|
||||
}
|
||||
|
||||
void XISFReaderPrivate::close()
|
||||
{
|
||||
_io.reset();
|
||||
@@ -1032,6 +1041,7 @@ public:
|
||||
void save(const String &name);
|
||||
void save(ByteArray &data);
|
||||
void save(std::ostream &io);
|
||||
void save(const std::filesystem::path &path);
|
||||
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);
|
||||
@@ -1084,6 +1094,16 @@ void XISFWriterPrivate::save(std::ostream &io)
|
||||
}
|
||||
}
|
||||
|
||||
void XISFWriterPrivate::save(const std::filesystem::path &path)
|
||||
{
|
||||
std::ofstream fw(path, std::ios_base::out | std::ios_base::binary);
|
||||
|
||||
if(fw.fail())
|
||||
throw Error("Failed to open file");
|
||||
|
||||
save(fw);
|
||||
}
|
||||
|
||||
void XISFWriterPrivate::writeImage(const Image &image)
|
||||
{
|
||||
_images.push_back(image);
|
||||
@@ -1304,6 +1324,11 @@ void XISFReader::open(std::istream *io)
|
||||
p->open(io);
|
||||
}
|
||||
|
||||
void XISFReader::open(const std::filesystem::path &path)
|
||||
{
|
||||
p->open(path);
|
||||
}
|
||||
|
||||
void XISFReader::close()
|
||||
{
|
||||
p->close();
|
||||
@@ -1349,6 +1374,11 @@ void XISFWriter::save(std::ostream &io)
|
||||
p->save(io);
|
||||
}
|
||||
|
||||
void XISFWriter::save(const std::filesystem::path &path)
|
||||
{
|
||||
p->save(path);
|
||||
}
|
||||
|
||||
void XISFWriter::writeImage(const Image &image)
|
||||
{
|
||||
p->writeImage(image);
|
||||
@@ -1361,12 +1391,14 @@ public:
|
||||
void open(const ByteArray &data);
|
||||
/** Open image from istream. This method takes ownership of *io pointer */
|
||||
void open(std::istream *io);
|
||||
void open(const std::filesystem::path &path);
|
||||
/** Close opended file release all data. */
|
||||
void close();
|
||||
|
||||
void save(const String &name);
|
||||
void save(ByteArray &data);
|
||||
void save(std::ostream &io);
|
||||
void save(const std::filesystem::path &path);
|
||||
|
||||
void addFITSKeyword(uint32_t image, const FITSKeyword &keyword);
|
||||
void updateFITSKeyword(uint32_t image, const FITSKeyword &keyword, bool add);
|
||||
@@ -1408,6 +1440,13 @@ void XISFModifyPrivate::open(std::istream *io)
|
||||
readXISFHeader();
|
||||
}
|
||||
|
||||
void XISFModifyPrivate::open(const std::filesystem::path &path)
|
||||
{
|
||||
close();
|
||||
_io = std::make_unique<std::ifstream>(path, std::ios_base::in | std::ios_base::binary);
|
||||
readXISFHeader();
|
||||
}
|
||||
|
||||
void XISFModifyPrivate::close()
|
||||
{
|
||||
_io.reset();
|
||||
@@ -1487,6 +1526,16 @@ void XISFModifyPrivate::save(std::ostream &io)
|
||||
}
|
||||
}
|
||||
|
||||
void XISFModifyPrivate::save(const std::filesystem::path &path)
|
||||
{
|
||||
std::ofstream fw(path, std::ios_base::out | std::ios_base::binary);
|
||||
|
||||
if(fw.fail())
|
||||
throw Error("Failed to open file");
|
||||
|
||||
save(fw);
|
||||
}
|
||||
|
||||
void XISFModifyPrivate::addFITSKeyword(uint32_t image, const FITSKeyword &keyword)
|
||||
{
|
||||
if(!_root)
|
||||
@@ -1657,6 +1706,11 @@ void XISFModify::open(std::istream *io)
|
||||
p->open(io);
|
||||
}
|
||||
|
||||
void XISFModify::open(const std::filesystem::path &path)
|
||||
{
|
||||
p->open(path);
|
||||
}
|
||||
|
||||
void XISFModify::close()
|
||||
{
|
||||
p->close();
|
||||
@@ -1677,6 +1731,11 @@ void XISFModify::save(std::ostream &io)
|
||||
p->save(io);
|
||||
}
|
||||
|
||||
void XISFModify::save(const std::filesystem::path &path)
|
||||
{
|
||||
p->save(path);
|
||||
}
|
||||
|
||||
void XISFModify::addFITSKeyword(uint32_t image, const FITSKeyword &keyword)
|
||||
{
|
||||
p->addFITSKeyword(image, keyword);
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
#define LIBXISF_H
|
||||
|
||||
#include "libXISF_global.h"
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <variant>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace LibXISF
|
||||
{
|
||||
@@ -370,6 +370,7 @@ public:
|
||||
void open(const ByteArray &data);
|
||||
/** Open image from istream. This method takes ownership of *io pointer */
|
||||
void open(std::istream *io);
|
||||
void open(const std::filesystem::path &path);
|
||||
/** Close opended file release all data. */
|
||||
void close();
|
||||
/** Return number of images inside file */
|
||||
@@ -396,6 +397,7 @@ public:
|
||||
void save(const String &name);
|
||||
void save(ByteArray &data);
|
||||
void save(std::ostream &io);
|
||||
void save(const std::filesystem::path &path);
|
||||
void writeImage(const Image &image);
|
||||
private:
|
||||
XISFWriterPrivate *p;
|
||||
@@ -419,10 +421,12 @@ public:
|
||||
void open(const String &name);
|
||||
void open(const ByteArray &data);
|
||||
void open(std::istream *io);
|
||||
void open(const std::filesystem::path &path);
|
||||
void close();
|
||||
void save(const String &name);
|
||||
void save(ByteArray &data);
|
||||
void save(std::ostream &io);
|
||||
void save(const std::filesystem::path &path);
|
||||
|
||||
/**
|
||||
* @brief addFITSKeyword append new keyword to image
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ int main(int argc, char **argv)
|
||||
else
|
||||
{
|
||||
LibXISF::XISFReader reader;
|
||||
reader.open(argv[1]);
|
||||
reader.open(LibXISF::String(argv[1]));
|
||||
TEST(reader.imagesCount() != 1, "No image");
|
||||
|
||||
const LibXISF::Image &image = reader.getImage(0);
|
||||
|
||||
Reference in New Issue
Block a user