Skip to content

Commit

Permalink
fixed draw indent order issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cracked-machine committed Feb 4, 2024
1 parent 3d1334a commit be2b032
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
10 changes: 5 additions & 5 deletions doc/example/report.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
![memory map diagram](report.png)
|name|origin|size|remaining|collisions
|:-|:-|:-|:-|:-|
|<span style='color:deepskyblue'>kernel</span>|0x10|0x50|-0x10|{'rootfs': '0x50'}|
|<span style='color:midnightblue'>uboot</span>|0xD0|0x50|-0x10|{'uboot-scr': '0x110'}|
|<span style='color:darkblue'>rootfs</span>|0x50|0x30|0x10|{'kernel': '0x50'}|
|<span style='color:dimgray'>dtb</span>|0x90|0x30|0x10|{}|
|<span style='color:mediumseagreen'>uboot-scr</span>|0x110|0x30|0x2a8|{'uboot': '0x110'}|
|<span style='color:gray'>kernel</span>|0x10|0x50|-0x10|{'rootfs': '0x50'}|
|<span style='color:darkviolet'>uboot</span>|0xD0|0x50|-0x10|{'uboot-scr': '0x110'}|
|<span style='color:aqua'>rootfs</span>|0x50|0x30|0x10|{'kernel': '0x50'}|
|<span style='color:slateblue'>dtb</span>|0x90|0x30|0x10|{}|
|<span style='color:lime'>uboot-scr</span>|0x110|0x30|0x2a8|{'uboot': '0x110'}|
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.
17 changes: 10 additions & 7 deletions mm/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,17 @@ def __init__(self):
logging.debug("")
# create a list of region objects populated with input data
self._region_list = self._process_input()

# temporarily sort by ascending origin attribute and assign the draw indent
self._region_list.sort(key=lambda x: x.origin, reverse=False)
region_indent = 0
for r in self._region_list:
r.draw_indent = region_indent
region_indent += 5

# sort in descending order so largest regions are drawn first in z-order (background)
self._region_list.sort(key=lambda x: x.size, reverse=True)

# output image diagram
self._create_diagram(self._region_list)
# output markdown report (refs image)
Expand All @@ -53,10 +62,6 @@ def _create_diagram(self, region_list: List[mm.types.Region]):
# init the main image
img_main = PIL.Image.new("RGB", (MemoryMap.width, MemoryMap.height), color=MemoryMap.bgcolour)

# this is the x-axis drawing offset for each region
# we increment this each time we draw a region to clearly show overlaps
region_offset = 0

# add a new layer (region_img) for each region block
# to the main image object (img_main)
for region in region_list:
Expand All @@ -66,8 +71,6 @@ def _create_diagram(self, region_list: List[mm.types.Region]):
logging.warning("Zero size region skipped")
continue

region_offset = region_offset + 5

### Region Blocks and text
region_img = PIL.Image.new("RGBA", (MemoryMap.width - self._legend_width, region.size), color=(255, 255, 0, 5))
region_canvas = PIL.ImageDraw.Draw(region_img)
Expand Down Expand Up @@ -120,7 +123,7 @@ def _create_diagram(self, region_list: List[mm.types.Region]):
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(region_img, (self._legend_width + region.draw_indent, region.origin), region_img)
img_main.paste(endaddr_text_img, (0, endaddr - 6))
img_main.paste(origin_text_img, (0, region.origin - 4))

Expand Down
1 change: 1 addition & 0 deletions mm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, name: str, origin: str, size: str):
"""Number of bytes until next region block"""
self.collisons: Dict(str, str) = {}
"""Map of collision regions by name (str) and distance (hex)"""
self.draw_indent = 0

# both 'lightslategray' and 'lightslategrey' are the same colour
# and we don't want duplicate colours in our diagram
Expand Down

0 comments on commit be2b032

Please sign in to comment.