thumbnailer: use single process + load original
This commit is contained in:
parent
137fd56bb2
commit
dff2bde9a3
3 changed files with 28 additions and 43 deletions
|
|
@ -41,6 +41,7 @@ Item {
|
|||
|
||||
anchors.fill: parent
|
||||
|
||||
loadOriginal: true
|
||||
asynchronous: true
|
||||
cache: false
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ Singleton {
|
|||
|
||||
readonly property string thumbDir: `${StandardPaths.standardLocations(StandardPaths.GenericCacheLocation)[0]}/caelestia/thumbnails`.slice(7)
|
||||
|
||||
function go(path: string, width: int, height: int): var {
|
||||
return thumbComp.createObject(root, {
|
||||
originalPath: path,
|
||||
width: width,
|
||||
height: height
|
||||
function go(obj: var): var {
|
||||
return thumbComp.createObject(obj, {
|
||||
originalPath: obj.path,
|
||||
width: obj.width,
|
||||
height: obj.height,
|
||||
loadOriginal: obj.loadOriginal
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -25,46 +26,41 @@ Singleton {
|
|||
required property string originalPath
|
||||
required property int width
|
||||
required property int height
|
||||
required property bool loadOriginal
|
||||
|
||||
property string path
|
||||
|
||||
readonly property Process shaProc: Process {
|
||||
readonly property Process proc: Process {
|
||||
running: true
|
||||
command: ["sha1sum", obj.originalPath]
|
||||
stdout: SplitParser {
|
||||
onRead: data => {
|
||||
const sha = data.split(" ")[0];
|
||||
obj.path = `${root.thumbDir}/${sha}@${obj.width}x${obj.height}-exact.png`;
|
||||
obj.thumbProc.signal(9);
|
||||
obj.thumbProc.running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readonly property Process thumbProc: Process {
|
||||
command: ["fish", "-c", `
|
||||
if test -f ${obj.path}
|
||||
exit 1
|
||||
set -l path "${root.thumbDir}/$(sha1sum ${obj.originalPath} | cut -d ' ' -f 1)@${obj.width}x${obj.height}-exact.png"
|
||||
if test -f $path
|
||||
echo $path
|
||||
else
|
||||
echo 'start'
|
||||
set -l size (identify -ping -format '%w\n%h' ${obj.originalPath})
|
||||
if test $size[1] -gt ${obj.width} -o $size[2] -gt ${obj.height}
|
||||
magick ${obj.originalPath} -${obj.width > 1024 || obj.height > 1024 ? "resize" : "thumbnail"} ${obj.width}x${obj.height}^ -background none -gravity center -extent ${obj.width}x${obj.height} -unsharp 0x.5 ${obj.path}
|
||||
magick ${obj.originalPath} -${obj.width > 1024 || obj.height > 1024 ? "resize" : "thumbnail"} ${obj.width}x${obj.height}^ -background none -gravity center -extent ${obj.width}x${obj.height} -unsharp 0x.5 $path
|
||||
else
|
||||
cp ${obj.originalPath} ${obj.path}
|
||||
cp ${obj.originalPath} $path
|
||||
end
|
||||
echo $path
|
||||
end`]
|
||||
onExited: code => {
|
||||
if (code === 0) {
|
||||
const path = obj.path;
|
||||
obj.path = "";
|
||||
obj.path = path;
|
||||
stdout: SplitParser {
|
||||
onRead: data => {
|
||||
if (data === "start") {
|
||||
if (obj.loadOriginal)
|
||||
obj.path = obj.originalPath;
|
||||
} else {
|
||||
obj.path = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reload(): void {
|
||||
shaProc.signal(9);
|
||||
shaProc.running = true;
|
||||
proc.signal(9);
|
||||
proc.running = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,22 +6,10 @@ Image {
|
|||
id: root
|
||||
|
||||
property string path
|
||||
readonly property Thumbnailer.Thumbnail thumbnail: Thumbnailer.go(path, width, height)
|
||||
property bool loadOriginal
|
||||
readonly property Thumbnailer.Thumbnail thumbnail: Thumbnailer.go(this)
|
||||
|
||||
source: thumbnail.path ? `file://${thumbnail.path}` : ""
|
||||
asynchronous: true
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
|
||||
onPathChanged: {
|
||||
thumbnail.originalPath = path;
|
||||
thumbnail.reload();
|
||||
}
|
||||
onWidthChanged: {
|
||||
thumbnail.width = width;
|
||||
thumbnail.reload();
|
||||
}
|
||||
onHeightChanged: {
|
||||
thumbnail.height = height;
|
||||
thumbnail.reload();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue