Compare commits

..

No commits in common. "d05e382063e35126255f127b87b6d564cdbae4ce" and "c478ee23db13631ac3f878f89fb1964ef6e13132" have entirely different histories.

9 changed files with 35 additions and 129 deletions

View File

@ -19,6 +19,6 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse( pip.parse(
hub_name = "pytools_deps", hub_name = "pytools_deps",
python_version = "3.10", python_version = "3.10",
requirements_lock = "//pytools:requirements.lock", requirements_lock = "//pytools:requirements.txt",
) )
use_repo(pip, "pytools_deps") use_repo(pip, "pytools_deps")

View File

@ -1,6 +1,6 @@
{ {
"lockFileVersion": 3, "lockFileVersion": 3,
"moduleFileHash": "b7a605dff62d0b97615cf1feb669dc4d3ce630abf1e74374f624b71287684b40", "moduleFileHash": "f69bdb13b0df2f6d309d415437228ebef31fa559567a65ecfe60de77e328ae1d",
"flags": { "flags": {
"cmdRegistries": [ "cmdRegistries": [
"https://bcr.bazel.build/" "https://bcr.bazel.build/"
@ -72,7 +72,7 @@
"attributeValues": { "attributeValues": {
"hub_name": "pytools_deps", "hub_name": "pytools_deps",
"python_version": "3.10", "python_version": "3.10",
"requirements_lock": "//pytools:requirements.lock" "requirements_lock": "//pytools:requirements.txt"
}, },
"devDependency": false, "devDependency": false,
"location": { "location": {
@ -1741,60 +1741,10 @@
"os:windows,arch:amd64": { "os:windows,arch:amd64": {
"bzlTransitiveDigest": "EY+DGyyJhrqMHBCiplU6kCYiNtiUXl3Olt6+vF4JnfE=", "bzlTransitiveDigest": "EY+DGyyJhrqMHBCiplU6kCYiNtiUXl3Olt6+vF4JnfE=",
"accumulatedFileDigests": { "accumulatedFileDigests": {
"@@//pytools:requirements.lock": "5a2eed9c6e50e9034521853f6016123e3e526900ddf3ff81cc1dbaaa28683629" "@@//pytools:requirements.txt": "ecb2c096486b1bb4dbe407a48fb3375ba496b6ea658c0cd7fc34571f381cd504"
}, },
"envVariables": {}, "envVariables": {},
"generatedRepoSpecs": { "generatedRepoSpecs": {
"pytools_deps_310_jinja2": {
"bzlFile": "@@rules_python~0.31.0//python/pip_install:pip_repository.bzl",
"ruleClassName": "whl_library",
"attributes": {
"name": "rules_python~0.31.0~pip~pytools_deps_310_jinja2",
"requirement": "Jinja2==3.1.3",
"repo": "pytools_deps_310",
"repo_prefix": "pytools_deps_310_",
"whl_patches": {},
"experimental_target_platforms": [],
"python_interpreter": "",
"python_interpreter_target": "@@rules_python~0.31.0~python~python_3_10_host//:python",
"quiet": true,
"timeout": 600,
"isolated": true,
"extra_pip_args": [],
"download_only": false,
"pip_data_exclude": [],
"enable_implicit_namespace_pkgs": false,
"environment": {},
"envsubst": [],
"group_name": "",
"group_deps": []
}
},
"pytools_deps_310_markupsafe": {
"bzlFile": "@@rules_python~0.31.0//python/pip_install:pip_repository.bzl",
"ruleClassName": "whl_library",
"attributes": {
"name": "rules_python~0.31.0~pip~pytools_deps_310_markupsafe",
"requirement": "MarkupSafe==2.1.5",
"repo": "pytools_deps_310",
"repo_prefix": "pytools_deps_310_",
"whl_patches": {},
"experimental_target_platforms": [],
"python_interpreter": "",
"python_interpreter_target": "@@rules_python~0.31.0~python~python_3_10_host//:python",
"quiet": true,
"timeout": 600,
"isolated": true,
"extra_pip_args": [],
"download_only": false,
"pip_data_exclude": [],
"enable_implicit_namespace_pkgs": false,
"environment": {},
"envsubst": [],
"group_name": "",
"group_deps": []
}
},
"pytools_deps_310_pillow": { "pytools_deps_310_pillow": {
"bzlFile": "@@rules_python~0.31.0//python/pip_install:pip_repository.bzl", "bzlFile": "@@rules_python~0.31.0//python/pip_install:pip_repository.bzl",
"ruleClassName": "whl_library", "ruleClassName": "whl_library",
@ -1836,12 +1786,6 @@
"name": "rules_python~0.31.0~pip~pytools_deps", "name": "rules_python~0.31.0~pip~pytools_deps",
"repo_name": "pytools_deps", "repo_name": "pytools_deps",
"whl_map": { "whl_map": {
"jinja2": [
"3.10"
],
"markupsafe": [
"3.10"
],
"pillow": [ "pillow": [
"3.10" "3.10"
] ]

View File

@ -15,11 +15,3 @@ $ bazel run -c opt sdl_host.exe
``` ```
$ bazel run sdl_host.exe $ bazel run sdl_host.exe
``` ```
## Dump requirements
(TODO: Automate)
```
$ pip freeze -r requirements.txt > requirements.lock
```

View File

@ -2,10 +2,9 @@ load("@pytools_deps//:requirements.bzl", "requirement")
py_binary( py_binary(
name = "font", name = "font",
srcs = ["font.py", "shared.py"], srcs = ["font.py"],
deps = [ deps = [
requirement("pillow"), requirement("pillow"),
requirement("Jinja2"),
], ],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )

View File

@ -1,13 +1,6 @@
from typing import Tuple from typing import Tuple
from PIL import Image from PIL import Image
import sys import sys
import shared
TEMPLATE = """
// generated code! be nice!
#include "sys/sys.h"
sys_glyph {{ font_name }}[{{ n_glyphs }}] = { {{- glyphs|join(", ") -}} };
""".lstrip()
def main(font_name, n_glyphs, fname_png, fname_c): def main(font_name, n_glyphs, fname_png, fname_c):
@ -15,32 +8,37 @@ def main(font_name, n_glyphs, fname_png, fname_c):
assert(len(glyphs) == n_glyphs), f"must be exactly {n_glyphs} glyphs" assert(len(glyphs) == n_glyphs), f"must be exactly {n_glyphs} glyphs"
with open(fname_c, "wt") as output: with open(fname_c, "wt") as output:
output.write( output.writelines([
shared.templates.from_string(TEMPLATE).render( "// generated code! be nice!\n",
font_name=font_name, "#include \"sys/sys.h\"\n",
n_glyphs=n_glyphs, f"sys_glyph {font_name}[{n_glyphs}] = {{{', '.join(str(g) for g in glyphs)}}};\n"
glyphs=glyphs, ])
)
)
def load_glyphs(fname_png: str): def load_glyphs(fname_png: str):
width, height, data = shared.load_image(fname_png) with Image.open(fname_png) as im:
monochrome = [pixel_to_monochrome(p) for p in data] width = im.width
height = im.height
glyphs = [] assert width % 8 == 0, "width must be a multiple of 8"
for gy in range(0, height, 8): assert height % 8 == 0, "height must be a multiple of 8"
for gx in range(0, width, 8):
glyph = 0
for py in range(0, 8):
for px in range(0, 8):
x = gx + px
y = gy + py
if monochrome[y * width + x]:
glyph |= 1 << (py * 8 + px)
glyphs.append(glyph)
return glyphs data = list(im.convert("RGBA").getdata())
monochrome = [pixel_to_monochrome(p) for p in data]
glyphs = []
for gy in range(0, height, 8):
for gx in range(0, width, 8):
glyph = 0
for py in range(0, 8):
for px in range(0, 8):
x = gx + px
y = gy + py
if monochrome[y * width + x]:
glyph |= 1 << (py * 8 + px)
glyphs.append(glyph)
return glyphs
def pixel_to_monochrome(rgba: Tuple[int, int, int, int]): def pixel_to_monochrome(rgba: Tuple[int, int, int, int]):

View File

@ -1,4 +0,0 @@
pillow==10.2.0
Jinja2==3.1.3
## The following requirements were added by pip freeze:
MarkupSafe==2.1.5

View File

@ -1,2 +1 @@
pillow==10.2.0 pillow==10.2.0
Jinja2==3.1.3

View File

@ -1,17 +0,0 @@
from PIL import Image
from jinja2 import Environment, BaseLoader, select_autoescape
templates = Environment(
loader=BaseLoader(),
autoescape=select_autoescape(),
)
def load_image(fname):
with Image.open(fname) as im:
width = im.width
height = im.height
assert width % 8 == 0, "width must be a multiple of 8"
assert height % 8 == 0, "height must be a multiple of 8"
return width, height, list(im.convert("RGBA").getdata())

View File

@ -3,18 +3,10 @@
#include <stdint.h> #include <stdint.h>
#define SYS_COLOR_TRANSPARENT 255
#define SYS_COLOR_N 256
#define SYS_SPRITE_H 8
#define SYS_SPRITE_W 8
typedef int32_t sys_i32; typedef int32_t sys_i32;
typedef uint8_t sys_color; typedef uint8_t sys_color;
typedef uint32_t sys_screen_color; typedef uint32_t sys_screen_color;
typedef uint64_t sys_glyph; typedef uint64_t sys_glyph;
typedef struct {
sys_color pixels[SYS_SPRITE_H][SYS_SPRITE_W];
} sys_sprite;
sys_screen_color sys_make_screen_color(uint8_t r, uint8_t g, uint8_t b); sys_screen_color sys_make_screen_color(uint8_t r, uint8_t g, uint8_t b);
@ -23,4 +15,7 @@ sys_i32 sys_min_i32(sys_i32 x, sys_i32 y);
sys_i32 sys_abs_i32(sys_i32 x); sys_i32 sys_abs_i32(sys_i32 x);
sys_i32 sys_sgn_i32(sys_i32 x); sys_i32 sys_sgn_i32(sys_i32 x);
#define SYS_COLOR_TRANSPARENT 255
#define SYS_COLOR_N 256
#endif // CROCPARTY_SYS_DATA_H #endif // CROCPARTY_SYS_DATA_H