| 1 | #!/usr/bin/python |
| 2 | |
| 3 | import sys |
| 4 | import Image |
| 5 | |
| 6 | if len(sys.argv) < 3: |
| 7 | sys.stderr.write("usage: icom-gen INFILE OUTFILE\n") |
| 8 | |
| 9 | inf = Image.open(sys.argv[1]) |
| 10 | sz = inf.size |
| 11 | tsz = (25, 25) |
| 12 | out = [] |
| 13 | |
| 14 | for y in xrange(tsz[1]): |
| 15 | line = [] |
| 16 | for x in xrange(tsz[0]): |
| 17 | sum = [0, 0, 0] |
| 18 | n = 0 |
| 19 | for y2 in xrange(y * sz[1] / tsz[1], (y + 1) * sz[1] / tsz[1]): |
| 20 | for x2 in xrange(x * sz[0] / tsz[0], (x + 1) * sz[0] / tsz[0]): |
| 21 | p = inf.getpixel((x2, y2)) |
| 22 | for c in xrange(3): |
| 23 | sum[c] += p[c] |
| 24 | n += 1 |
| 25 | for c in xrange(3): |
| 26 | sum[c] /= n |
| 27 | line.append(tuple(sum)) |
| 28 | out.append(line) |
| 29 | |
| 30 | f = open(sys.argv[2], "w") |
| 31 | for line in out: |
| 32 | for p in line: |
| 33 | for c in p: |
| 34 | f.write(chr(c)) |
| 35 | f.close() |