| 76 | } |
| 77 | |
| 78 | unsigned char * readPNG( char * infile, int& W, int&H, LodePNGColorType format) |
| 79 | { |
| 80 | std::vector<unsigned char> image; //the raw pixels |
| 81 | unsigned width, height; |
| 82 | |
| 83 | unsigned error = lodepng::decode(image, width, height, infile, format, 8); |
| 84 | |
| 85 | if(error) |
| 86 | { |
| 87 | std::cout << "load png error " << std::endl; |
| 88 | return 0; |
| 89 | } |
| 90 | W = width; |
| 91 | H = height; |
| 92 | std::cout<<"png image loaded, size is "<<W<<" "<<H<<" "<<image.size()<<std::endl; |
| 93 | std::cout<<"min and max "<<W<<" "<<H<<" "<<image.size()<<std::endl; |
| 94 | int imsize; |
| 95 | if(format==LCT_GREY){ |
| 96 | imsize = W*H; |
| 97 | } |
| 98 | else{ |
| 99 | imsize = W*H*3; |
| 100 | } |
| 101 | unsigned char * r = new unsigned char[imsize]; |
| 102 | memcpy(r, &image[0], sizeof(unsigned char)*imsize); |
| 103 | return r; |
| 104 | } |
| 105 | |
| 106 | int main( int argc, char* argv[]){ |
| 107 | if (argc<5){ |