Skip to content

Commit

Permalink
remove image-related scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
occivink committed Dec 21, 2017
1 parent ced7f6b commit 2aef3c2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 308 deletions.
14 changes: 0 additions & 14 deletions README.md
Expand Up @@ -118,14 +118,6 @@ Seek to an absolute position in the current video by typing its timestamp.
Toggle with whatever binding you chose. Move the current cursor position with <kbd>←</kbd> and <kbd>→</kbd>, Change the number currently selected with the number keys (duh). Press <kbd>Enter</kbd> to seek to the entered position.
Holds an internal history for timestamps that have been previously navigated, accessible with <kbd>↑</kbd> and <kbd>↓</kbd>.

# drag-to-pan.lua

Pan the current video or image with the cursor.

This script offers two commands `drag-to-pan` and `pan-follows-cursor`. The former is similar to how panning a map works, while the second shows a portion of the image according to the position of the cursor in the mpv window.

You can use this script with mouse bindings such as `MOUSE_BTN0` but any other key works too. Note that `MOUSE_BTN0` clashes with the window dragging feature, you can set `window-dragging=no` to prevent that.

# misc.lua

Some commands that are too simple to warrant their own script. Have a look at the source in case you're curious.
Expand All @@ -146,11 +138,5 @@ b script-message-to blur_edges toggle-blur
# seek-to.lua
t script-message-to seek_to toggle-seeker
# drag-to-pan.lua
# this binding is special because we need to monitor up and down events for this key
MOUSE_BTN0 script-binding drag_to_pan/drag-to-pan
MOUSE_BTN1 script-binding drag_to_pan/pan-follows-cursor
```

204 changes: 0 additions & 204 deletions drag-to-pan.lua

This file was deleted.

90 changes: 0 additions & 90 deletions misc.lua
Expand Up @@ -64,95 +64,6 @@ function clear_filters()
mp.set_property_native("vf", {})
end

function compute_video_dimensions()
-- this function is very much ripped from video/out/aspect.c in mpv's source
local keep_aspect = mp.get_property_bool("keepaspect")
local video_params = mp.get_property_native("video-out-params")
local w = video_params["w"]
local h = video_params["h"]
local dw = video_params["dw"]
local dh = video_params["dh"]
local video_w, video_h
if mp.get_property_number("video-rotate") % 180 == 90 then
w, h = h,w
dw, dh = dh, dw
end
if keep_aspect then
local unscaled = mp.get_property_native("video-unscaled")
local panscan = mp.get_property_number("panscan")
local window_w, window_h = mp.get_osd_size()

local fwidth = window_w
local fheight = math.floor(window_w / dw * dh)
if fheight > window_h or fheight < h then
local tmpw = math.floor(window_h / dh * dw)
if tmpw <= window_w then
fheight = window_h
fwidth = tmpw
end
end
local vo_panscan_area = window_h - fheight
local f_w = fwidth / fheight
local f_h = 1
if vo_panscan_area == 0 then
vo_panscan_area = window_h - fwidth
f_w = 1
f_h = fheight / fwidth
end
if unscaled or unscaled == "downscale-big" then
vo_panscan_area = 0
if unscaled or (dw <= window_w and dh <= window_h) then
fwidth = dw
fheight = dh
end
end

local scaled_width = fwidth + math.floor(vo_panscan_area * panscan * f_w)
local scaled_height = fheight + math.floor(vo_panscan_area * panscan * f_h)

local split_scaling = function (dst_size, scaled_src_size, zoom, align, pan)
scaled_src_size = math.floor(scaled_src_size * 2 ^ zoom)
align = (align + 1) / 2
local dst_start = math.floor((dst_size - scaled_src_size) * align + pan * scaled_src_size)
if dst_start < 0 then
--account for C int cast truncating as opposed to flooring
dst_start = dst_start + 1
end
local dst_end = dst_start + scaled_src_size;
if dst_start >= dst_end then
dst_start = 0
dst_end = 1
end
return dst_end - dst_start
end
local zoom = mp.get_property_number("video-zoom")

local align_x = mp.get_property_number("video-align-x")
local pan_x = mp.get_property_number("video-pan-x")
video_w = split_scaling(window_w, scaled_width, zoom, align_x, pan_x)

local align_y = mp.get_property_number("video-align-y")
local pan_y = mp.get_property_number("video-pan-y")
video_h = split_scaling(window_h, scaled_height, zoom, align_y, pan_y)
else
video_w = window_w
video_h = window_h
end
return video_w, video_h
end

function align(x, y)
local video_w, video_h = compute_video_dimensions()
local window_w, window_h = mp.get_osd_size()
local x,y = tonumber(x), tonumber(y)
if x then
mp.set_property_number("video-pan-x", x * (video_w - window_w) / (2 * video_w))
end
if y then
mp.set_property_number("video-pan-y", y * (video_h - window_h) / (2 * video_h))
end
end

function ab_loop(operation, timestamp)
if not mp.get_property("seekable") then return end
if timestamp ~= "a" and timestamp ~= "b" then return end
Expand All @@ -172,6 +83,5 @@ mp.add_key_binding(nil, "toggle-filter", toggle)
mp.add_key_binding(nil, "clear-filters", clear_filters)
mp.add_key_binding(nil, "remove-last-filter", remove_last_filter)
mp.add_key_binding(nil, "undo-filter-removal", undo_filter_removal)
mp.add_key_binding(nil, "align", align)
mp.add_key_binding(nil, "ab-loop", ab_loop)

0 comments on commit 2aef3c2

Please sign in to comment.