#include #include #include #include int from_png_ (char *path,png_byte IN[10000*10000*2],int *NBPP,int *PNGX, int *PNGY) { int i, j; // char sig_buf [SIG_CHECK_SIZE]; png_info *info_ptr; png_struct *png_ptr; //png_byte **bitmap; //png_uint_32 *w,*h; png_uint_32 width, height; int bit_depth, color_type, interlace_type,rowbytes; unsigned char **row_pointers; char *path_tmp; path_tmp=strtok(path,"\\"); // path_tmp=strcat(path_tmp,"png"); printf("reading %s:::\n",path); FILE *fp; if ((fp = fopen(path, "rb")) == NULL) { printf("Can't open file %s!!!\n",path_tmp); *NBPP=-1; return 0; } png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(png_ptr == NULL) { printf("Error creating read_struct\n"); fclose(fp); return 0; } info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { fclose(fp); png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); return 0; } if (setjmp(png_ptr->jmpbuf)) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); fclose(fp); printf("Error reading file\n"); return 0; } png_init_io(png_ptr, fp); png_read_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL); *NBPP=bit_depth; *PNGX=(int)(width); *PNGY=(int)(height); printf("Image size %d %d %d %d %d %d\n",*PNGX, *PNGY, *NBPP,width, height, bit_depth); // sleep(10); rowbytes=png_get_rowbytes(png_ptr, info_ptr); row_pointers = (unsigned char**)malloc(height * sizeof(unsigned char*)); for(i=0;i<(int)height;i++) { row_pointers[i] = &IN[rowbytes*i]; } png_read_image(png_ptr, row_pointers); png_read_end(png_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); fclose(fp); free(row_pointers); }