Add support for greyscale and highest order bit generation

This commit is contained in:
Niles Rogoff 2017-03-19 19:54:59 -04:00
parent 3ba231cd6c
commit eaff58db12
No known key found for this signature in database
GPG Key ID: B78B908F23430F80
22 changed files with 41 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

View File

@ -1,10 +1,14 @@
#!/usr/bin/env python3
import libpme, math, random, sys
import pip._vendor.progress.bar as libbar
img = libpme.PME()
img.height = img.width = 1024
img.color_type = libpme.color_types.GREYSCALE
img.bit_depth = 1
bitmask = 1
greyscale = False
if len(sys.argv) > 1:
if sys.argv[1].lower() == "high":
bitmask = 128
elif sys.argv[1].lower() == "greyscale":
greyscale = True
bitmask = 255
operations = {
"^": lambda x, y: x ^ y,
@ -29,6 +33,7 @@ def gensym():
return lambda x, y: x
else:
r = random.randint(1, 16)
# we can't just write "return lambda x, y: random.randint(1, 16)" or it would generate a different random number for each pixel. That bug took forever to find
return lambda x, y: r
@ -52,34 +57,54 @@ def sbuilder(k, i = 0, recurse = False):
return str(syms[i]("x", "y"))
if recurse:
return "(" + sbuilder(k[1:], i + 1, True) + ") " + k[0] + " " + str(syms[i]("x", "y"))
return "(" + sbuilder(k, i, True) + ") & 1"
return "(" + sbuilder(k, i, True) + ") & " + str(bitmask)
def mask(val):
if greyscale:
return min(255, max(0, val))
if bitmask == 1:
return val & bitmask
else:
return 0 if val & bitmask == 0 else 1
#print(ops)
#the_function = lambda x, y: (((x^y)-y)*x >> 11) & 1
#print(sbuilder(ops));
the_function = lambda x, y: round(builder(ops)(x, y)) & 1
print(sbuilder(ops));
the_function = lambda x, y: mask(round(builder(ops)(x, y)))
#print(the_function(2, 2))
# i = int(sys.argv[1])
# badfiles = open("badfiles", "r").read().split("\n")[:-1]
# the_function = eval("lambda x, y: " + badfiles[i].split("/")[-1].replace(" BAD FILENAME.png", ""))
img = libpme.PME()
img.height = img.width = 1024
img.color_type = libpme.color_types.GREYSCALE
img.bit_depth = 1
data = b''
bar = libbar.IncrementalBar(max = img.height)
bar.start()
if greyscale:
img.bit_depth = 8
for y in range(1024):
data += b'\x00'
for x in range(0, 1024, 8):
this_pixel = 0;
for subx in range(8):
this_x = x + subx
val = the_function(this_x, y)
this_pixel += val
this_pixel <<= 1
this_pixel >>= 1
data += bytes([this_pixel])
if not greyscale:
for x in range(0, 1024, 8):
this_pixel = 0;
for subx in range(8):
this_x = x + subx
val = the_function(this_x, y)
this_pixel += val
this_pixel <<= 1
this_pixel >>= 1
data += bytes([this_pixel])
else:
for x in range(1024):
data += bytes([the_function(x, y)])
bar.index = y
if y % 13 == 0: bar.update()

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B