00001 #pragma ident "$Id: PNG.hpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002
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 #ifndef VDRAW_PNG_H
00029 #define VDRAW_PNG_H
00030
00031 #include<string>
00032 #include<sstream>
00033 #include<cmath>
00034 #include<memory>
00035
00036 #include "Bitmap.hpp"
00037 #include "Color.hpp"
00038 #include "ColorMap.hpp"
00039 #include "InterpolatedColorMap.hpp"
00040 #include "Palette.hpp"
00041 #include "CRC32.hpp"
00042 #include "Adler32.hpp"
00043
00044 namespace vdraw
00045 {
00048
00052 class PNG
00053 {
00054 public:
00056 typedef std::auto_ptr<std::string> string_ptr;
00057
00062 static std::string png(const Bitmap &b);
00063
00068 static string_ptr png(const ColorMap &c, int osr=1, int osc=1);
00069
00074 static string_ptr png(const InterpolatedColorMap &c, int osr=1, int osc=1);
00075
00078 static int cost_indexed(const Bitmap& b);
00079
00081 static int cost_indexed(int rows, int cols, int numcol);
00082
00084 static int cost_constant(const Bitmap& b);
00085
00087 static int cost_constant(int rows, int cols);
00088
00089 protected:
00091 static const std::string header;
00092
00094 static int cost_idat(int stream);
00095
00097 static string_ptr ihdr_full(int width, int height);
00098
00100 static string_ptr ihdr_indexed(int width, int height);
00101
00103 static string_ptr srgb();
00104
00106 static string_ptr phys();
00107
00109 static string_ptr plte(const InterpolatedColorMap &c);
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00125 static string_ptr idat(const InterpolatedColorMap &c, int osr, int osc);
00126
00128 static string_ptr idat(const ColorMap &c, int osr, int osc);
00129
00131 static string_ptr split(const std::string &str);
00132
00134 static string_ptr prefix(const std::string &str);
00135
00137 static string_ptr huff(const std::string &str);
00138
00140 static string_ptr data(const ColorMap &c, int osr, int osc);
00141
00143 static string_ptr data(const InterpolatedColorMap &c, int osr, int osc);
00144
00146 static unsigned int alder(const string_ptr &str);
00147
00149 static string_ptr iend();
00150
00152 static string_ptr chunk(const std::string &title, const std::string &text);
00153
00155 static string_ptr itos(int i);
00156
00158 static string_ptr ctos(const Color &color);
00159
00161 static char btoc(int b);
00162
00163 };
00164
00166
00167 }
00168
00169 #endif //VDRAW_PNG_H
00170
00171