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
00032 #ifndef __W_PNG_H
00033 #define __W_PNG_H
00034
00035 #include <string>
00036 #include <png.h>
00037 #include <iostream>
00038
00039 namespace Modelib {
00040
00041 class PNGImage
00042 {
00043
00044
00045 public:
00046 std::string filename;
00047 png_structp png_ptr;
00048 png_infop info_ptr;
00049 unsigned width, height;
00050 png_byte **image;
00051 png_byte **row_pointers;
00052 FILE *fp;
00053 int bytes_per_pixel;
00054
00055 public:
00056 PNGImage() { std::cerr.rdbuf(0);};
00057
00058
00059 PNGImage(int _width, int _height) : fp(NULL), bytes_per_pixel(3)
00060 {
00061
00062 std::cerr << "Void cstor";
00063 width = _width;
00064 height = _height;
00065 row_pointers = new png_byte*[width*bytes_per_pixel];
00066 std::cerr.rdbuf(0);
00067 }
00068
00069
00070 PNGImage(const std::string& _filename, int _width, int _height)
00071 : filename(_filename),
00072 png_ptr(NULL), info_ptr(NULL),
00073 width(_width), height(_height),
00074 fp(NULL),
00075 bytes_per_pixel(3)
00076 {
00077
00078
00079
00080 std::cerr.rdbuf(0);
00081
00082 image = new png_byte* [height];
00083 for (unsigned i=0;i<height;i++)
00084 image[i] = new png_byte [width*bytes_per_pixel];
00085
00086 row_pointers = new png_byte*[width*bytes_per_pixel];
00087 }
00088
00089
00090
00091 ~PNGImage();
00092
00093 bool openFileRead();
00094 bool openFileWrite();
00095 bool isPNG(int bytesToCheck);
00096 bool initReadStructs();
00097 bool initWriteStructs();
00098 bool writeHeader();
00099
00100 png_byte** writeImage_Start();
00101 bool writeImage_End();
00102
00103 bool writeEnd();
00104
00105 };
00106
00107 }
00108
00109 #endif