-
Notifications
You must be signed in to change notification settings - Fork 0
/
picturegen.py
68 lines (64 loc) · 2.05 KB
/
picturegen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from sys import argv
from sys import stdin
from math import floor
from PIL import Image
import PIL
class HashThings:
internalStates = [0, 0, 0]
def add(self, nums):
self.internalStates = [self.internalStates[i] + nums[i] for i in range(3)]
for i, state in enumerate(self.internalStates):
if state > 255:
self.internalStates[i] = state - ((state // 255) * 255)
def reset(self):
self.internalStates = [0, 0, 0]
def getPix(self):
return tuple(self.internalStates)
if '-f' in argv:
outFile = argv[argv.index('-f') + 1]
BIter = False
else:
outFile = '1.png'
BIter = True
if ('-d' in argv) and not ('-f' in argv):
outDir = argv[argv.index('-d') + 1]
else:
outDir = ''
if '-i' in argv:
iterations = int(argv[argv.index('-i') + 1])
else:
iterations = 2
if '-w' in argv:
w = int(argv[argv.index('-w') + 1])
else:
w = 100
if '-h' in argv:
h = int(argv[argv.index('-h') + 1])
else:
h = 100
reset = not ('-nre' in argv)
verbose = ('-v' in argv)
im = Image.new('RGB', (w, h))
imArray = []
hashThing = HashThings()
vbArray = [25, 50, 75, 100]
for inBytes in range(1, iterations+1):
if verbose:
print('Starting iteration ' + str(inBytes))
for x in range(w):
for y in range(h):
if verbose and (floor((((x * w) + y) / ((w * h) - 1)) * 100)) in vbArray:
print('Picture ' + str(inBytes) + ': Pixel ' + str((x * w) + y) + ' out of ' + str((w * h) - 1))
vbArray.pop(0)
if reset:
hashThing.reset()
hashThing.add((int.from_bytes(stdin.buffer.read(inBytes), byteorder='little'),
int.from_bytes(stdin.buffer.read(inBytes), byteorder='little'),
int.from_bytes(stdin.buffer.read(inBytes), byteorder='little')))
imArray.append(hashThing.getPix())
im.putdata(imArray)
im.save(outDir + outFile)
imArray = []
vbArray = [25, 50, 75, 100]
if BIter:
outFile = str(int(outFile[:-4])+1) + outFile[-4:]