summaryrefslogtreecommitdiff
path: root/osd.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-10 00:08:58 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-01-10 00:08:58 -0800
commit5f6b4c254798d14c5f148e4ea4404007d1aa7f3a (patch)
tree1c889eb625cb59ccd476e63d4c7e6ffbf2a8a264 /osd.lua
parent7428ae5098fdbd351fa3c9c470699ce71dd3b9a5 (diff)
downloadmpv-iptv-menu-master.tar.gz
mpv-iptv-menu-master.tar.xz
refine image scaling behaviourHEADmaster
Diffstat (limited to 'osd.lua')
-rw-r--r--osd.lua44
1 files changed, 28 insertions, 16 deletions
diff --git a/osd.lua b/osd.lua
index f9d4078..36026cb 100644
--- a/osd.lua
+++ b/osd.lua
@@ -184,8 +184,9 @@ function mt:load_img()
'magick', self.img.path,
'-depth', '8',
'-resize', string.format(
- 'x%%[fx:max(%d, min(%d, %d*h/w))]',
- self.img.min_h, self.img.max_h, self.img.max_w),
+ 'x%%[fx:max(min(%d,%d*h/w),min(%d,%d*h/w))]',
+ self.img.min_h, self.img.min_w,
+ self.img.max_h, self.img.max_w),
'-print', '%w %h',
'tmp.bgra'
}
@@ -261,32 +262,42 @@ end
function mt:set_img(path, menu_res)
-- images require *real* dimensions and coordinates, unlike other OSD
-- functions which scale the given values automatically
- local padding = self.scale * self.padding
- local start = self.scale * menu_res.x1
+ local padding = math.ceil(self.scale * self.padding)
+ local start = math.ceil(self.scale * menu_res.x1)
local fs = self.scale * config.font_size
-- images are scaled to fit the available OSD area when treated as
- -- having the 2:3 aspect ratio of a standard film poster. when this
- -- results in an image height less than a minimum font-size-derived
- -- value, the image is instead scaled to this minimum height. this
- -- ensures that a given screen has all images, regardless of original
- -- aspect ratio, scaled to either a common width or a common height.
+ -- having the 2:3 aspect ratio of a standard film poster. a minimum
+ -- size, derived from font size and total area, is used as a fallback
+ -- when insufficient space remains, potentially overlapping the tail
+ -- end of text. when the underlying image reaches this minimum height,
+ -- the 2:3 treatment is abandoned, fixing the height and allowing the
+ -- image to grow horizontally to an arbitrary limit, after which the
+ -- width becomes fixed and the height continues to shrink.
+ --
+ -- this is designed to keep images legible while fixing at least one
+ -- dimension under normal circumstances, preventing jarring switches
+ -- between different images rendered on the same menu.
--
-- because we have only the total width of the current OSD text, we
-- cannot slightly reduce the image width to avoid overlapping some
-- longer line at the bottom, as we do not know where the offending
-- line is. if it were possible to place images *under* text, maybe
-- we'd allow overlap, but mpv currently hard-codes this order.
- local min_h = math.floor(3 * fs)
- local max_h = math.floor(math.max(min_h, math.min(
- self.height - 2*padding,
- (self.width - start - 2*padding) * 3/2)))
- local max_w = math.floor(max_h * 2/3)
- local top = math.floor(padding)
- local right = math.floor(self.width - padding)
+ local pw = self.width - 2*padding
+ local min_h = math.min(3 * fs, pw * 3/2)
+ local min_w = math.ceil(math.min(3 * min_h, pw))
+ local max_h = math.max(min_h, math.min(
+ self.height - 2*padding, (pw - start) * 3/2))
+ local max_w = math.ceil(max_h * 2/3)
+ min_h = math.floor(min_h)
+ max_h = math.floor(max_h)
+ local top = padding
+ local right = self.width - padding
if self.img and path == self.img.path and
min_h == self.img.min_h and
+ min_w == self.img.min_w and
max_h == self.img.max_h and
max_w == self.img.max_w then
if top == self.img.top and right == self.img.right then
@@ -305,6 +316,7 @@ function mt:set_img(path, menu_res)
self.img = {
path = path,
min_h = min_h,
+ min_w = min_w,
max_h = max_h,
max_w = max_w,
top = top,