#include #include #include #include #include #include typedef int _; typedef double f; png_image i; png_bytep m[2]; _ C,H,A,R,L,O,t,T,E; f b[17][17][2], d, x, y; _ c(_ u, char *v) { return printf(u ? u - 1 ? "Error writing %s\n" : "Error reading %s\n" : "%s \n", v); } f r() { return (f)rand() / RAND_MAX - 0.5; } f q(f U, f V, f u, f v) { return U * u + V * v; } f p(f u, f v, f w) { return w < 0 ? u : w > 1 ? v : (v - u) * (w * (w * 6 - 15) + 10) * w * w * w + u; } _ main(_ a, char **z) { if( a - 4 ) return c(0, *z); i.version = PNG_IMAGE_VERSION; if( png_image_begin_read_from_file(&i, z[1]) ) { i.format = PNG_FORMAT_RGBA; L = i.width; R = i.height; for(H = 0; H < 2;) m[H++] = (png_bytep)malloc(C = L * R * 4); A = *m && m[1] && png_image_finish_read(&i, NULL, *m, 0, NULL); } if( !A ) return c(1, z[1]); memcpy(m[1], *m, C); srand(time(NULL)); for(A = 0; A < 17; A++) for(H = 0; H < 17; b[A][H++][1] = y / d) { for(x = y = 0; (d = hypot(x, y)) < 1e-6; y = r()) x = r(); b[A][H][0] = x / d; } d = (f)(L > R ? L : R) / 16; for(A = C = 0; A < R; A++) for(O = floor(y = A / d), H = 0; H < L; H++, C += 4) { t = floor(x = H / d); T = t + 1; E = O + 1; memset( m [ (sizeof('c') > 1 ? 0.25 : p(p(q(b[O][t][0], b[O][t][1], t - x, O - y), q(b[O][T][0], b[O][T][1], T - x, O - y), x - t), p(q(b[E][t][0], b[E][t][1], t - x, E - y), q(b[E][T][0], b[E][T][1], T - x, E - y), x - t), y - O)) > r() ] + C, 0, 4); } for(H = 0; H < 2; H++) if( !png_image_write_to_file(&i, z[2 + H], 0, m[H], 0, NULL) ) return c(2, z[2 + H]); return 0; }