31 #ifndef PNGPP_WRITER_HPP_INCLUDED
32 #define PNGPP_WRITER_HPP_INCLUDED
65 template<
class ostream >
75 :
io_base(png_create_write_struct(PNG_LIBPNG_VER_STRING,
80 png_set_write_fn(
m_png, & stream, write_data, flush_data);
91 if (setjmp(png_jmpbuf(
m_png)))
106 if (setjmp(png_jmpbuf(
m_png)))
118 if (setjmp(png_jmpbuf(
m_png)))
122 png_write_row(
m_png, bytes);
130 if (setjmp(png_jmpbuf(
m_png)))
138 static void write_data(png_struct* png,
byte* data,
size_t length)
143 ostream* stream =
reinterpret_cast< ostream*
>(png_get_io_ptr(png));
146 stream->write(reinterpret_cast< char* >(data), length);
149 wr->
set_error(
"ostream::write() failed");
152 catch (std::exception
const& error)
158 assert(!
"caught something wrong");
159 wr->
set_error(
"write_data: caught something wrong");
167 static void flush_data(png_struct* png)
172 ostream* stream =
reinterpret_cast< ostream*
>(png_get_io_ptr(png));
178 wr->set_error(
"ostream::flush() failed");
181 catch (std::exception
const& error)
183 wr->set_error(error.what());
187 assert(!
"caught something wrong");
188 wr->set_error(
"flush_data: caught something wrong");
199 #endif // PNGPP_WRITER_HPP_INCLUDED