1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2026-04-21 21:16:51 +00:00

use Github gists for sharing

This commit is contained in:
Steven Hugg
2017-01-25 12:30:05 -05:00
parent f9c9fc91aa
commit ec2391f16e
6 changed files with 96 additions and 34 deletions
+2
View File
@@ -11,3 +11,5 @@
%-48.pbm: %.jpg
convert $< -resize 48x192\! -colorspace Gray -dither FloydSteinberg $@
ship1.pbm: ship1.png
convert ship1.png -negate -flop ship1.pbm
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/python
import sys, struct
# reverse byte
def rev(n):
return int('{:08b}'.format(n)[::-1], 2)
# output bits in given range
def out(i, pix, lb, hb, reverse=0, shift=0):
x = (pix >> lb) & ((1<<(hb-lb))-1)
if reverse:
x = rev(x)
if shift:
x = x << shift
assert(x>=0 and x<=255)
output[i].append(x)
# read PBM (binary P4 format) file
with open(sys.argv[1],'rb') as f:
# read PBM header
header = f.readline().strip()
assert(header == 'P4')
dims = f.readline().strip()
if dims[0] == '#':
dims = f.readline().strip()
width,height = map(int, dims.split())
wbytes = (width+7)/8
data = f.read()
print "{%d,%d," % (wbytes,height),
for i in range(0,len(data)):
if i>0:
sys.stdout.write(",")
ofs = i+wbytes-(i%wbytes)*2-1
sys.stdout.write( "0x%02x" % ord(data[ofs]) )
print "}"