#include #include #include #include #include int main(int argc, char **argv) { png_image image; png_bytep buffer1, buffer2; int s, i; if( argc != 4 ) return printf("%s \n", *argv); memset(&image, 0, sizeof(image)); image.version = PNG_IMAGE_VERSION; if( !png_image_begin_read_from_file(&image, argv[1]) ) return printf("Error reading %s\n", argv[1]); image.format = PNG_FORMAT_RGBA; s = image.width * image.height; buffer1 = (png_bytep)malloc(s * 4); buffer2 = (png_bytep)calloc(s, 4); if( buffer1 == NULL || buffer2 == NULL ) return puts("Out of memory"); if( !png_image_finish_read(&image, NULL, buffer1, 0, NULL) ) return printf("Error loading %s\n", argv[1]); srand(time(NULL)); for(i = 0; i < s; i++) { if( rand() > RAND_MAX / 2 ) { memcpy(buffer2 + (i * 4), buffer1 + (i * 4), 4); memset(buffer1 + (i * 4), 0, 4); } } if( !png_image_write_to_file(&image, argv[2], 0, buffer1, 0, NULL) ) return printf("Error writing %s\n", argv[2]); if( !png_image_write_to_file(&image, argv[3], 0, buffer2, 0, NULL) ) return printf("Error writing %s\n", argv[3]); return 0; }