Skip to content

Commit e5dd9ab

Browse files
authored
I guess this is enough?
1 parent ba105ba commit e5dd9ab

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

Diff for: pingus_font.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,34 @@
55
"""
66
import png
77

8-
palette = [(0xff, 0xff, 0xff, i) for i in range(1, 255)]
8+
palette = [(0xff, 0xff, 0xff, i) for i in range(255, -1, -1)]
99

10-
def ungamma(x: int) -> int:
11-
"""Terrible ungamma, [0, 256)"""
12-
a = 0.055
13-
srgb = x / 255.0
14-
if srgb <= 0.04045:
15-
return int(srgb / 12.92 * 255)
16-
else:
17-
return int(((srgb + a) / (1 + a)) ** 2.4 * 255)
18-
19-
def read_pgm2(pgmf):
20-
"""A dirty P2 pgm reader for fontgen only."""
10+
def read_pgm2(pgmf) -> list:
11+
"""
12+
A dirty P2 pgm reader for fontgen only.
13+
14+
Actually returns List[list], but let's not mess that up for now.
15+
"""
2116
assert pgrm.readline() == 'P3\n' # type
2217
assert pgrm.readline()[0] == '#' # comment signature
2318
(w, h) = map(int, pgrm.readline().split())
2419
depth = int(pgmf.readline())
2520
assert depth <= 255
2621

27-
return (w, h, [list(itertools.islice(pgmf, w)) for i in range(h)])
22+
return (w, h, [int(i) for i in pgmf])
2823

2924
def convert(filename):
25+
"""
26+
Takes a pgm and makes it a pingus png font sprite.
27+
"""
3028
global palette
3129
with open(filename) as pgmf:
3230
w, h, pixels = read_pgm2(pgmf)
3331
writer = png.Writer(size=(w,h), palette=palette, compression=9, bitdepth=8)
3432

33+
# We don't need any gamma here: freetype's greyscale output is a coverage map.
34+
with open(filename[:-4] + '.png', 'wb'):
35+
writer.write(pixels)
36+
37+
import sys
38+
convert(sys.argv[1])

0 commit comments

Comments
 (0)