diff options
author | ExMix <rahuba.youri@gmail.com> | 2013-03-13 12:45:53 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:51:40 +0300 |
commit | 0332bed0045c8b0fe3fe06e6bcb8137973c3789b (patch) | |
tree | 61e8f99921d10bfae2cbeb43cf7a1eb801e481b6 /coding | |
parent | c086fd7b56528f200439a28827e0908575433a84 (diff) |
Support png writer for gil::view. Work only for Texture<RGBA8Traits>
Diffstat (limited to 'coding')
-rw-r--r-- | coding/lodepng.cpp | 17 | ||||
-rw-r--r-- | coding/lodepng.hpp | 3 | ||||
-rw-r--r-- | coding/lodepng_io.hpp | 8 | ||||
-rw-r--r-- | coding/lodepng_io_private.hpp | 8 | ||||
-rw-r--r-- | coding/writer.hpp | 28 |
5 files changed, 46 insertions, 18 deletions
diff --git a/coding/lodepng.cpp b/coding/lodepng.cpp index dd07351236..a1db3ec190 100644 --- a/coding/lodepng.cpp +++ b/coding/lodepng.cpp @@ -4265,15 +4265,14 @@ namespace LodePNG } /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ -// void saveFile(const std::vector<unsigned char>& buffer, const std::string& filename) -// { -// size_t const sz = buffer.size(); -// if (sz > 0) -// { -// FileWriter writer(filename); -// writer.Write(&buffer[0], sz); -// } -// } + void saveFile(const std::vector<unsigned char>& buffer, WriterPtr<Writer> &writer) + { + size_t const sz = buffer.size(); + if (sz > 0) + { + writer.Write(&buffer[0], sz); + } + } //#endif /*LODEPNG_COMPILE_DISK*/ diff --git a/coding/lodepng.hpp b/coding/lodepng.hpp index d6c906e912..a9a4f8f532 100644 --- a/coding/lodepng.hpp +++ b/coding/lodepng.hpp @@ -31,6 +31,7 @@ freely, subject to the following restrictions: #include <string.h> #include "reader.hpp" +#include "writer.hpp" /* ////////////////////////////////////////////////////////////////////////// */ /* Code Sections */ @@ -491,7 +492,7 @@ namespace LodePNG //#ifdef LODEPNG_COMPILE_DISK //free functions allowing to load and save a file from/to harddisk void loadFile(std::vector<unsigned char>& buffer, ReaderPtr<Reader> & reader); -// void saveFile(const std::vector<unsigned char>& buffer, const std::string& filename); + void saveFile(const std::vector<unsigned char>& buffer, WriterPtr<Writer> & writer); //#endif //LODEPNG_COMPILE_DISK } //namespace LodePNG diff --git a/coding/lodepng_io.hpp b/coding/lodepng_io.hpp index f6254e4c62..23b7787e70 100644 --- a/coding/lodepng_io.hpp +++ b/coding/lodepng_io.hpp @@ -193,18 +193,18 @@ struct lodepng_write_support { /// Triggers a compile assert if the view color space and channel depth are not supported by the PNG library or by the I/O extension. /// Throws std::ios_base::failure if it fails to create the file. template <typename View> -inline void lodepng_write_view(const char* filename,const View& view) { +inline void lodepng_write_view(WriterPtr<Writer> & writer,const View& view) { BOOST_STATIC_ASSERT(lodepng_write_support<View>::is_supported); - detail::lodepng_writer m(filename); + detail::lodepng_writer m(writer); m.apply(view); } /// \ingroup LODEPNG_IO /// \brief Saves the view to a png file specified by the given png image file name. -template <typename View> +/*template <typename View> inline void lodepng_write_view(const std::string& filename,const View& view) { lodepng_write_view(filename.c_str(),view); -} +}*/ } } // namespace boost::gil diff --git a/coding/lodepng_io_private.hpp b/coding/lodepng_io_private.hpp index 88e9ab741f..72e2732aaf 100644 --- a/coding/lodepng_io_private.hpp +++ b/coding/lodepng_io_private.hpp @@ -369,16 +369,16 @@ public: }; -class lodepng_writer : public file_mgr { +class lodepng_writer /*: public file_mgr */{ protected: LodePNG::Encoder m_encoder; - std::string m_fileName; + WriterPtr<Writer> & m_writer; void init() {} public: - lodepng_writer(const char* filename) : file_mgr(filename, "wb"), m_fileName(filename) { init(); } + lodepng_writer(WriterPtr<Writer> & writer) : /*file_mgr(filename, "wb"), m_fileName(filename)*/ m_writer(writer) { init(); } template <typename View> void apply(const View& view) @@ -418,7 +418,7 @@ public: view.height() ); -// LodePNG::saveFile(buffer, m_fileName); + LodePNG::saveFile(buffer, m_writer); } }; diff --git a/coding/writer.hpp b/coding/writer.hpp index 2f300b2ffe..528d0f28da 100644 --- a/coding/writer.hpp +++ b/coding/writer.hpp @@ -3,6 +3,7 @@ #include "../base/base.hpp" #include "../base/exception.hpp" #include "../std/algorithm.hpp" +#include "../std/shared_ptr.hpp" #include "../std/memcpy.hpp" #include "../std/string.hpp" #include "../std/vector.hpp" @@ -115,6 +116,33 @@ private: #endif }; +template<typename WriterT> +class WriterPtr +{ +public: + WriterPtr(WriterT * p = 0) : m_p(p) {} + + void Seek(int64_t pos) + { + m_p->Seek(pos); + } + + int64_t Pos() const + { + return m_p->Pos(); + } + + void Write(void const * p, size_t size) + { + m_p->Write(p, size); + } + + WriterT * GetPtr() const { return m_p.get(); } + +protected: + shared_ptr<WriterT> m_p; +}; + template <typename WriterT> class WriterSink { |