#include #include #include /* Induce simulated CCD noise in a PNM image. Written to make a static image * look like a webcam (some friends and I built a fake machine-room-cam page as * a joke in my first year). */ int main(int argc, char **argv) { int w, h, max, i, range; range = (argc < 2) ? 20 : atoi(argv[1]); srand(time(NULL)); scanf("P6\n"); scanf("%d %d\n", &w, &h); scanf("%d", &max); fgetc(stdin); /* get the last whitespace char */ if (max > 255) exit(20); printf("P6\n%d %d\n%d\n", w, h, max); for (i = 0; i < w * h * 3; i++) { int val = fgetc(stdin); int rndnum = rand() % range; if (rand() % 2) { if (val < 255-rndnum) val += rndnum; } else { if (val > rndnum) val -= rndnum; } fputc(val, stdout); } return 0; }