Skip to content

Commit

Permalink
added region text labels
Browse files Browse the repository at this point in the history
  • Loading branch information
cracked-machine committed Feb 4, 2024
1 parent 487353f commit 1134915
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions doc/example/report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![memory map diagram](report.png)
|name|origin|size|remaining|collisions
|:-|:-|:-|:-|:-|
|<span style='color:navy'>dtb</span>|0x90|0x100|0x258|{}|
|<span style='color:lime'>kernel</span>|0x10|0x60|0x0|{}|
|<span style='color:lightskyblue'>rootfs</span>|0x70|0x10|0x10|{'kernel': '0x70'}|
|<span style='color:midnightblue'>dtb</span>|0x90|0x100|0x258|{}|
|<span style='color:aqua'>kernel</span>|0x10|0x60|0x0|{}|
|<span style='color:lime'>rootfs</span>|0x70|0x10|0x10|{'kernel': '0x70'}|
Binary file modified doc/example/report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 14 additions & 7 deletions mmdiagram/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1134915

Please sign in to comment.