-- PictureSort.lua
local ffi = require"ffi"
local C = ffi.C
local wsize = ffi.sizeof"wchar_t"
local F = far.Flags
local U8 = win.Utf16ToUtf8
local function String(cStr)
if tostring(cStr) == "cdata<const unsigned short *>: NULL" then return nil end
return U8(ffi.string(cStr,C.wcslen(cStr)*wsize))
end
------------------------------------------------
local FILE_ATTRIBUTE_DIRECTORY = 0x00000010
local MediaInfo_GUID = '919C1FC6-A571-4642-99DF-BDACE840ED18'
------------------------------------------------
local aSortData = {w={}; h={}}
local function GetMedia(FName)
local ok, n, _, Vals = Plugin.SyncCall(MediaInfo_GUID, FName,'{Width,Height}')
if ok and n == 2 then
return tonumber( (Vals[1]:gsub("%D",'')) ), tonumber( (Vals[2]:gsub("%D",'')) )
end
end
local function InitSort(Options)
aSortData = {w={}; h={}}
for i=1,APanel.ItemCount do
if band(Panel.Item(0,i,2), FILE_ATTRIBUTE_DIRECTORY) == 0 then
local fn = Panel.Item(0,i,0)
local w,h = GetMedia(fn)
if w then aSortData.w[fn], aSortData.h[fn] = w,h end
end
end
end
local function Compare(sWH, Pi1, Pi2, Options) -- sWH = 'w' or 'h'
local function Sign(arg) return arg < 0 and -1 or (arg > 0 and 1 or 0) end
local Fn1, Fn2 = String(Pi1.FileName), String(Pi2.FileName)
return Sign( (aSortData[sWH][Fn1] or math.huge) - (aSortData[sWH][Fn2] or math.huge) )
end
--------------------------------------------------------------------
Panel.LoadCustomSortMode (F.SM_USER+100, nil)
Panel.LoadCustomSortMode (F.SM_USER+100, {
InitSort = InitSort;
Compare = function(...) return Compare('w', ...) end;
Indicator = 'ŵŴ'; --'wW';
Description = 'Picture width'; --'По ширине изображения';
})
--------------------------------------------------------------------
Panel.LoadCustomSortMode (F.SM_USER+101, nil)
Panel.LoadCustomSortMode (F.SM_USER+101, {
InitSort = InitSort;
Compare = function(...) return Compare('h', ...) end;
Indicator = 'ĥĤ'; --'hH';
Description = 'Picture height'; --'По высоте изображения';
})