From 1134915d0e65d9f6e76cb762bb88aab8e26b0518 Mon Sep 17 00:00:00 2001 From: cracked-machine Date: Sun, 4 Feb 2024 16:01:11 +0000 Subject: [PATCH] added region text labels --- doc/example/report.md | 6 +++--- doc/example/report.png | Bin 4635 -> 5670 bytes mmdiagram/generator.py | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/doc/example/report.md b/doc/example/report.md index df0f1a8..567ea3a 100644 --- a/doc/example/report.md +++ b/doc/example/report.md @@ -1,6 +1,6 @@ ![memory map diagram](report.png) |name|origin|size|remaining|collisions |:-|:-|:-|:-|:-| -|dtb|0x90|0x100|0x258|{}| -|kernel|0x10|0x60|0x0|{}| -|rootfs|0x70|0x10|0x10|{'kernel': '0x70'}| +|dtb|0x90|0x100|0x258|{}| +|kernel|0x10|0x60|0x0|{}| +|rootfs|0x70|0x10|0x10|{'kernel': '0x70'}| diff --git a/doc/example/report.png b/doc/example/report.png index 05f685e52589178a00a6209ce80c1d14ba9347b2..b3cb9be46eb429c2ed865face68d19a88ea7058a 100644 GIT binary patch literal 5670 zcmeI0`&ZIw9>+23*e2?1H!N>EXWDIDHF2!eL1k*2t)@wLrY5Zf(0$<$5MBCQnA!MTN$@+ z-i+pums&Fv(qR1SyNY^_!pXE6w#vW#%M*GlO`Z@fb^a%gC%F@x@> zH)&!KrUSuSoQgu5v5(<59bf{dE{txVDUcNz$AosEcz|wP^?I z$@-eT#hzirxwjsK(RqF#T648nIogsQA0N-BhuP*ZjM`xfe6snu7UKG~%Sc&9$}&=Z zgp`f`x)piNh*&e)vHdH-tRK!)pO1aU>AQjY@Jh2i?si#Onealkszr8JJl?yOaKf%_ zGeKI|Y_CftZ=IEoesou!knL~{nZKZ#%{6-Yk^t>Q^JJg3^W!A>Dq`mt0=bWWk z93uHf$b@r$J)dIHGK`&DJt^k-%WgrISscZU8VBquz!1iYDP~EW>mWT05*gTrd7hW} z$=Q)aG$hQ&Ci86EO1dL}T|fAVyGdV92@44!sYY9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ufo#tVtx;5(rn*+6Xl;USoom-)%Ch7 zT}=?=A*3}kN8@%PbUk2_q`qGD|6|%4`OdXy! z*<)y4sSY<0_EskvqGpPj>hR!rL_t1y5IdBbm0ARt-K_7EafOw00U|QB&+p+sV8W4lnsE3%B$1ZFSC@KL0;Ab4 c$A$t*Fg6{CDV(*2{OJS4ZH(V=Wqo?#@A+yVxBvhE diff --git a/mmdiagram/generator.py b/mmdiagram/generator.py index 5f8c0dc..118fe26 100644 --- a/mmdiagram/generator.py +++ b/mmdiagram/generator.py @@ -64,37 +64,44 @@ def _create_diagram(self, region_list: List[mmdiagram.types.Region]): region_offset = region_offset + 5 - # init the layer + ### Region Blocks and text region_img = PIL.Image.new("RGBA", (width - self._legend_width, region.size), color=(255, 255, 0, 5)) region_canvas = PIL.ImageDraw.Draw(region_img) - # draw the region graphic region_canvas.rectangle( (0, 0, width - 1, region.origin + region.size), fill=region.colour, outline="black", width=1, ) + name_text_font = PIL.ImageFont.load_default(10) + name_text_img = PIL.Image.new("RGB", (60, 15), color=(255, 255, 255)) + name_text_canvas = PIL.ImageDraw.Draw(name_text_img) + name_text_canvas.text((0, 0), region.name, fill="black", font=name_text_font) + name_text_img = name_text_img.rotate(180) + region_img.paste(name_text_img, (10, 10)) - img_main.paste(region_img, (self._legend_width + region_offset, region.origin), region_img) - text_font = PIL.ImageFont.load_default(8) + ### Address Text + addr_text_font = PIL.ImageFont.load_default(8) # add text for the region origin origin_text_img = PIL.Image.new("RGB", (30, 10), color=(255, 255, 255)) origin_text_canvas = PIL.ImageDraw.Draw(origin_text_img) - origin_text_canvas.text((0, 0), region._origin, fill="black", font=text_font) + origin_text_canvas.text((0, 0), region._origin, fill="black", font=addr_text_font) origin_text_img = origin_text_img.rotate(180) # add text for the region end endaddr = region.origin + region.size endaddr_text_img = PIL.Image.new("RGB", (30, 10), color=(255, 255, 255)) endaddr_text_canvas = PIL.ImageDraw.Draw(endaddr_text_img) - endaddr_text_canvas.text((0, 0), hex(endaddr), fill="black", font=text_font) + endaddr_text_canvas.text((0, 0), hex(endaddr), fill="black", font=addr_text_font) endaddr_text_img = endaddr_text_img.rotate(180) + # paste all the layers onto the main image + img_main.paste(region_img, (self._legend_width + region_offset, region.origin), region_img) img_main.paste(endaddr_text_img, (0, endaddr - 6)) img_main.paste(origin_text_img, (0, region.origin - 4)) - # horizontal flip and write to file + # 0,0 should start lower right, not upper left img_main = img_main.rotate(180) # output image file