/* * read png pixels. determine pattern. * simple... */ #include #include #include #include #define PNG_DEBUG 3 #include int x, y; int width, height; png_byte color_type; png_byte bit_depth; png_structp png_ptr; png_infop info_ptr; int number_of_passes; png_bytep * row_pointers; void read_png_file() { char header[8]; // 8 is the maximum size that can be checked /* open file and test for it being a png */ FILE *fp = fopen("PNG.png", "rb"); if (!fp) printf("Failed to open image file!\n"); fread(header, 1, 8, fp); if (png_sig_cmp(header, 0, 8)) printf("Not a PNG file!\n"); /* initialize stuff */ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) printf("Could not create read struct!\n"); info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) printf("Could not create info struct!\n"); if (setjmp(png_jmpbuf(png_ptr))) printf("setjmp() failed!\n"); png_init_io(png_ptr, fp); png_set_sig_bytes(png_ptr, 8); png_read_info(png_ptr, info_ptr); width = info_ptr->width; height = info_ptr->height; color_type = info_ptr->color_type; bit_depth = info_ptr->bit_depth; number_of_passes = png_set_interlace_handling(png_ptr); png_read_update_info(png_ptr, info_ptr); /* read file */ if (setjmp(png_jmpbuf(png_ptr))) printf("Failed to read image!\n"); row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height); for (y=0; yrowbytes); png_read_image(png_ptr, row_pointers); fclose(fp); } void process_file(void) { if (info_ptr->color_type != PNG_COLOR_TYPE_RGBA) printf("Unexpected color type - %d", info_ptr->color_type); for (y=0; y<1; y++) { png_byte* row = row_pointers[y]; for (x=0; x