forked from TinyTapeout/tt-support-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
htfab
committed
Jan 18, 2025
1 parent
9d3ca84
commit c5fe99f
Showing
11 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
|
||
import gdstk | ||
from git.repo import Repo | ||
from PIL import Image, ImageDraw, ImageFont | ||
|
||
from config import Config | ||
|
||
|
||
class LogoGenerator: | ||
def __init__(self, config: Config | None): | ||
self.config = config | ||
|
||
def gen_logo(self, variant, gds_file, shuttle=None, commit=None): | ||
|
||
assert variant in ("top", "bottom") | ||
if variant == "top": | ||
# use included bitmap | ||
img = Image.open("logo/tt_logo.png") | ||
img = img.convert("L") # convert to greyscale | ||
|
||
elif variant == "bottom": | ||
# generate bitmap from shuttle ID & commit hash | ||
if shuttle is None: | ||
shuttle = self.config["id"] | ||
if commit is None: | ||
commit = Repo(".").commit().hexsha | ||
|
||
img = Image.new("L", (200, 200), (0,)) | ||
draw = ImageDraw.Draw(img) | ||
|
||
font_file = "logo/UbuntuSansMono.ttf" | ||
font = {} | ||
for size in (88, 50, 32): | ||
font[size] = ImageFont.truetype(font_file, size) | ||
font[size].set_variation_by_axes([700]) | ||
|
||
draw.text((2, -15), shuttle, fill=(255,), font=font[88]) | ||
draw.text((2, 67), commit[:7], fill=(255,), font=font[50]) | ||
for i in range(3): | ||
text = commit[7 + 11 * i : 7 + 11 * (i + 1)] | ||
draw.text((1, 111 + i * 27), text, fill=(255,), font=font[32]) | ||
|
||
PRBOUNDARY_LAYER = 235 | ||
PRBOUNDARY_DATATYPE = 4 | ||
MET4_LAYER = 71 | ||
DRAWING_DATATYPE = 20 | ||
PIXEL_SIZE = 0.5 # um | ||
|
||
lib = gdstk.Library() | ||
cell = lib.new_cell(f"tt_logo_{variant}") | ||
boundary = gdstk.rectangle( | ||
(0, 0), | ||
(img.width * PIXEL_SIZE, img.height * PIXEL_SIZE), | ||
layer=PRBOUNDARY_LAYER, | ||
datatype=PRBOUNDARY_DATATYPE, | ||
) | ||
cell.add(boundary) | ||
|
||
for y in range(img.height): | ||
for x in range(img.width): | ||
color = img.getpixel((x, y)) | ||
if color >= 128: | ||
flipped_y = img.height - y - 1 # flip vertically | ||
rect = gdstk.rectangle( | ||
(x * PIXEL_SIZE, flipped_y * PIXEL_SIZE), | ||
((x + 1) * PIXEL_SIZE, (flipped_y + 1) * PIXEL_SIZE), | ||
layer=MET4_LAYER, | ||
datatype=DRAWING_DATATYPE, | ||
) | ||
cell.add(rect) | ||
|
||
lib.write_gds(gds_file) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
try: | ||
if sys.argv[1] == "--top": | ||
LogoGenerator(None).gen_logo("top", "logo/tt_logo_top.gds") | ||
|
||
elif sys.argv[1] == "--bottom": | ||
shuttle = sys.argv[2] # e.g. "TT10" | ||
commit = sys.argv[3] # e.g. "0123456789abcdef0123456789abcdef01234567" | ||
LogoGenerator(None).gen_logo( | ||
"bottom", "logo/tt_logo_bottom.gds", shuttle, commit | ||
) | ||
|
||
except IndexError: | ||
print( | ||
f"Usage:\n {sys.argv[0]} --top\n {sys.argv[0]} --bottom <shuttle> <commit>", | ||
file=sys.stderr, | ||
) |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
VERSION 5.7 ; | ||
NOWIREEXTENSIONATPIN ON ; | ||
DIVIDERCHAR "/" ; | ||
BUSBITCHARS "[]" ; | ||
MACRO tt_logo_bottom | ||
CLASS BLOCK ; | ||
FOREIGN tt_logo_bottom ; | ||
ORIGIN 0.000 0.000 ; | ||
SIZE 100.000 BY 100.000 ; | ||
OBS | ||
LAYER met4 ; | ||
RECT 0.000 0.000 100.000 100.000 ; | ||
END | ||
END tt_logo_bottom | ||
END LIBRARY | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
`default_nettype none | ||
|
||
module tt_logo_bottom (); | ||
endmodule |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
VERSION 5.7 ; | ||
NOWIREEXTENSIONATPIN ON ; | ||
DIVIDERCHAR "/" ; | ||
BUSBITCHARS "[]" ; | ||
MACRO tt_logo_top | ||
CLASS BLOCK ; | ||
FOREIGN tt_logo_top ; | ||
ORIGIN 0.000 0.000 ; | ||
SIZE 100.000 BY 100.000 ; | ||
OBS | ||
LAYER met4 ; | ||
RECT 0.000 0.000 100.000 100.000 ; | ||
END | ||
END tt_logo_top | ||
END LIBRARY | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
`default_nettype none | ||
|
||
module tt_logo_top (); | ||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters