43 if(::fread(header,1,8,a_file)!=8) {
49 if(::png_sig_cmp(header,0,8)) {
57 ::png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
65 png_infop info_ptr = ::png_create_info_struct(png_ptr);
67 ::png_destroy_read_struct(&png_ptr,NULL,NULL);
74 if(::setjmp(png_jmpbuf(png_ptr))) {
75 ::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
82 ::png_init_io(png_ptr,a_file);
83 ::png_set_sig_bytes(png_ptr,8);
85 ::png_read_info(png_ptr,info_ptr);
87 png_uint_32 width = ::png_get_image_width(png_ptr,info_ptr);
88 png_uint_32 height = ::png_get_image_height(png_ptr,info_ptr);
89 png_uint_32 rowbytes = ::png_get_rowbytes(png_ptr,info_ptr);
90 int bpp = width?rowbytes/width:0;
92 if((width<=0)||(height<=0)||(bpp<=0)) {
93 ::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
106 ::png_read_update_info(png_ptr,info_ptr);
108 if(::setjmp(png_jmpbuf(png_ptr))) {
109 ::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
116 unsigned char* buffer =
new unsigned char[rowbytes * height];
118 ::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
125 {png_bytep* row_pointers =
new png_bytep[height];
126 png_byte* pos = buffer+rowbytes*(height-1);
127 for(png_uint_32 y=0;y<height;y++) {
128 row_pointers[y] = pos;
131 ::png_read_image(png_ptr,row_pointers);
132 delete [] row_pointers;}
134 ::png_read_end(png_ptr,info_ptr);
136 ::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);