/* * read png pixels. determine pattern. * simple... */ #include #include #include #include #define PNG_DEBUG 3 #include #ifndef png_jmpbuf # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) #endif int x, y; int width, height; png_byte color_type; png_byte bit_depth; png_uint_32 rowbytes; png_structp png_ptr; png_infop info_ptr; png_bytep * row_pointers; int answer[3000]; int c =0; int chars = 0; int i =0; 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_set_packing(png_ptr); png_read_info(png_ptr, info_ptr); width = info_ptr->width; printf("width: %d ",width); height = info_ptr->height; printf("height: %d\n",height); color_type = info_ptr->color_type; printf("%d\n",color_type); bit_depth = info_ptr->bit_depth; printf("%d\n",bit_depth); rowbytes = info_ptr->rowbytes; printf("rowbytes: %d\n", rowbytes); /* 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; ybit_depth == 1) printf("It is indeed a 1 bit image!\n"); for (y=0; yanswer[c-1]) { printf("%d", answer[c]); fprintf(fp,"%c",answer[c]); }else{ printf("%d", answer[c]-answer[c-1]); fprintf(fp,"%c", answer[c]-answer[c-1]); } } printf("\n"); fclose(fp); return 0; } int main(int argc, char **argv) { read_png_file(); process_file(); answercode(); return 0; }