00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PNGPP_GENERATOR_HPP_INCLUDED
00032 #define PNGPP_GENERATOR_HPP_INCLUDED
00033
00034 #include <cassert>
00035 #include <stdexcept>
00036 #include "error.hpp"
00037 #include "streaming_base.hpp"
00038 #include "writer.hpp"
00039
00040 namespace png
00041 {
00042
00108 template< typename pixel,
00109 class pixgen,
00110 class info_holder = def_image_info_holder,
00111 bool interlacing_supported = false >
00112 class generator
00113 : public streaming_base< pixel, info_holder >
00114 {
00115 public:
00124 void write(std::ostream& stream)
00125 {
00126 writer wr(stream);
00127 wr.set_image_info(this->get_info());
00128 wr.write_info();
00129
00130 size_t pass_count;
00131 if (this->get_info().get_interlace_type() != interlace_none)
00132 {
00133 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
00134 if (interlacing_supported)
00135 {
00136 pass_count = wr.set_interlace_handling();
00137 }
00138 else
00139 {
00140 throw std::logic_error("Cannot write interlaced image --"
00141 " generator does not support it.");
00142 }
00143 #else
00144 throw error("Cannot write interlaced image --"
00145 " interlace handling disabled.");
00146 #endif
00147 }
00148 else
00149 {
00150 pass_count = 1;
00151 }
00152 pixgen* pixel_gen = static_cast< pixgen* >(this);
00153 for (size_t pass = 0; pass < pass_count; ++pass)
00154 {
00155 pixel_gen->reset(pass);
00156
00157 for (size_t pos = 0; pos < this->get_info().get_height(); ++pos)
00158 {
00159 wr.write_row(pixel_gen->get_next_row(pos));
00160 }
00161 }
00162
00163 wr.write_end_info();
00164 }
00165
00166 protected:
00167 typedef streaming_base< pixel, info_holder > base;
00168
00173 explicit generator(image_info& info)
00174 : base(info)
00175 {
00176 }
00177
00182 generator(size_t width, size_t height)
00183 : base(width, height)
00184 {
00185 }
00186 };
00187
00188 }
00189
00190 #endif // PNGPP_GENERATOR_HPP_INCLUDED