text stringlengths 1 93.6k |
|---|
# <FILESEP>
|
""" Copyright 2015-2017 sta256+mpskit at gmail.com
|
This file is part of mpskit.
|
This program is free software: you can redistribute it and/or modify
|
it under the terms of the GNU Affero General Public License as
|
published by the Free Software Foundation, either version 3 of the
|
License, or (at your option) any later version.
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY.
|
See LICENSE file for more details.
|
"""
|
from common import *
|
from madspack import read_madspack, save_madspack, write_madspack
|
from PIL import Image
|
from palette import attach_palette
|
"""
|
FF file format
|
MADSPACK with 1 section
|
Section 0
|
one pix encoded on 2 bits, 4 possible colors
|
font_colors = []
|
font_colors[0] = 0xFF
|
font_colors[1] = 0x0F
|
font_colors[2] = 0x07
|
font_colors[3] = 0x08
|
"""
|
pal = [(0,0,0,0),(0,255,0,255),(0,127,0,255),(0,63,0,255)]
|
def get_col_index(img,c):
|
if img.mode == 'P':
|
return c
|
elif img.mode == 'RGB':
|
return get_col_index_RGB(c)
|
elif img.mode == 'RGBA':
|
return get_col_index_RGBA(c)
|
else:
|
fail("invalid font image mode: {}; should be 'P', 'RGB', or 'RGBA'", img.mode)
|
def get_col_index_RGB(c):
|
if c == (0,0,0):
|
return 0
|
if c == (0,255,0):
|
return 1
|
if c == (0,127,0):
|
return 2
|
if c == (0,63,0):
|
return 3
|
fail("invalid font color: {}".format(c))
|
def get_col_index_RGBA(c):
|
if c[:3] == (0,0,0):
|
return 0
|
if c == (0,255,0,255):
|
return 1
|
if c == (0,127,0,255):
|
return 2
|
if c == (0,63,0,255):
|
return 3
|
fail("invalid font color: {}".format(c))
|
def load_ff_header(ff_name):
|
return Record.from_list(
|
json.load(open("{}.json".format(ff_name)))
|
)
|
def save_ff_header(ff_name, h):
|
n = "{}.json".format(ff_name)
|
open(n, 'w').write(json.dumps(h.as_list(), indent=2))
|
output(n)
|
def write_ff(ff_name):
|
check_ext(ff_name, '.FF')
|
h = load_ff_header(ff_name)
|
f = BytesIO()
|
f.seek(2 + 128 + 256)
|
for i in range(1,128):
|
write_glyph(f, ff_name, h, i)
|
f.seek(0)
|
write_ff_header(f, h)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.