From dc2d58d28e51bc73d5006aba63c1081969f20e3f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 28 Apr 2025 21:48:10 -0500 Subject: [PATCH] scripts: dbgbmap[d3].py: Prioritize rows at low resolution This prevents some pretty unintuitive behavior with dbgbmap.py -H2 (the default) in the terminal. Consider before: bd 4096x256, 7.8% mdir, 0.4% btree, 0.0% data mm--------b-----mm--mm--mm--mmmmmmm--mm--mmmm----------------------- Vs after: bd 4096x256, 7.8% mdir, 0.4% btree, 0.0% data m-----------------------------------b-mmmmmmmm---------------------- Compared to the original bmap (-H5): bd 4096x256, 7.8% mdir, 0.4% btree, 0.0% data mm------------------------------------------------------------------ -------------------------------------------------------------------- ----------b-----mm--mm--mm--mmmmmmm--mm--mmmm----------------------- -------------------------------------------------------------------- What's happening is dbgbmap.py is prioritizing aspect ratio over pixel boundaries, so it's happy drawing a 4-row bmap to a 1-row Canvas. But of course we can't see subpixels, so the result is quite confusing. Prioritizing rows while tiling avoids this. --- scripts/dbgbmap.py | 7 ++++--- scripts/dbgbmapd3.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/dbgbmap.py b/scripts/dbgbmap.py index 61e1e1eb..db415cce 100755 --- a/scripts/dbgbmap.py +++ b/scripts/dbgbmap.py @@ -4717,18 +4717,19 @@ def main_(ring, disk, mroots=None, *, block_cols_ = block_cols block_rows_ = mt.ceil(len(bmap) / block_cols) else: + # prioritize rows at low resolution + block_rows_ = min(len(bmap), max(canvas.height, 1)) # was len(bmap) + block_cols_ = mt.ceil(len(bmap) / block_rows_) # was 1 # divide by 2 until we hit our target ratio, this works # well for things that are often powers-of-two - block_cols_ = 1 - block_rows_ = len(bmap) while (abs(((canvas.width/(block_cols_*2)) / max(canvas.height/mt.ceil(block_rows_/2), 1)) - block_ratio) < abs(((canvas.width/block_cols_) / max(canvas.height/block_rows_, 1))) - block_ratio): - block_cols_ *= 2 block_rows_ = mt.ceil(block_rows_ / 2) + block_cols_ *= 2 block_width_ = canvas.width / block_cols_ block_height_ = canvas.height / block_rows_ diff --git a/scripts/dbgbmapd3.py b/scripts/dbgbmapd3.py index f3e4e06d..54e2bcd3 100755 --- a/scripts/dbgbmapd3.py +++ b/scripts/dbgbmapd3.py @@ -4440,18 +4440,19 @@ def main(disk, output, mroots=None, *, block_cols_ = block_cols block_rows_ = mt.ceil(len(bmap) / block_cols) else: + # prioritize rows at low resolution + block_rows_ = min(len(bmap), max(height__, 1)) # was len(bmap) + block_cols_ = mt.ceil(len(bmap) / block_rows_) # was 1 # divide by 2 until we hit our target ratio, this works # well for things that are often powers-of-two - block_cols_ = 1 - block_rows_ = len(bmap) while (abs(((width__/(block_cols_*2)) / max(height__/mt.ceil(block_rows_/2), 1)) - block_ratio) < abs(((width__/block_cols_) / max(height__/block_rows_, 1))) - block_ratio): - block_cols_ *= 2 block_rows_ = mt.ceil(block_rows_ / 2) + block_cols_ *= 2 block_width_ = width__ / block_cols_ block_height_ = height__ / block_rows_