From 3415f57140f2f46e1e67cc3b988974aa56148eb3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 7 Jul 2013 19:46:45 +0400 Subject: [PATCH] now vips preview generator uses a faster (vips-based) approach to getting preview size + minor bugfix in index.html... Signed-off-by: Alex A. Naanou --- ui/TODO.otl | 7 +++++++ ui/compatibility.js | 37 ++++++++++++++++++++++++++++++++++++- ui/files.js | 4 ++++ ui/index.html | 4 ++-- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/ui/TODO.otl b/ui/TODO.otl index 25b7ae8a..f50cfb15 100755 --- a/ui/TODO.otl +++ b/ui/TODO.otl @@ -107,6 +107,13 @@ Roadmap [_] index and group ALL files in an archive [_] import metadata [_] real GIDs + [_] % Thumbnail generation strategies + [_] extract existing raw thumbnails + [_] make a preview just bigger than the screen first + | ...to prevent loading the high-res + | + | this should be done BEFORE loading the image -- pre-load phase... + [_] prioritize making thumbs for the ribbon (~350px) [_] BUG: shifting last image out of a ribbon misaligns the current ribbon | i.e. the prev ribbon was deleted and the new focused ribbon | is aligned as if it was not current... diff --git a/ui/compatibility.js b/ui/compatibility.js index d396b940..bb947c1e 100755 --- a/ui/compatibility.js +++ b/ui/compatibility.js @@ -129,6 +129,14 @@ if(window.CEF_dumpJSON != null){ // // NOTE: this will add already existing previews to IMAGES[gid]... // + // XXX possible modes: + // - fast + // make previews using nearest rscale (factor=1) + // - optimized + // use closest rscale and minimal factor + // - best + // only use scale factor (rscale=1) + // XXX get image size without loading the image... // XXX make this not just vips-specific... // XXX path handling is a mess... window.makeImagePreviews = function(gid, sizes){ @@ -153,11 +161,35 @@ if(window.CEF_dumpJSON != null){ // get cur image size... var size_getter = $.Deferred() + + var width_getter = $.Deferred() + var cmd = 'vips im_header_int width "$IN"' + .replace(/\$IN/g, source.replace(fp, '')) + proc.exec(cmd, function(error, stdout, stderr){ + width_getter.resolve(parseInt(stdout)) + }) + + var height_getter = $.Deferred() + var cmd = 'vips im_header_int height "$IN"' + .replace(/\$IN/g, source.replace(fp, '')) + proc.exec(cmd, function(error, stdout, stderr){ + height_getter.resolve(parseInt(stdout)) + }) + + $.when(width_getter, height_getter) + .done(function(w, h){ + size_getter.resolve(Math.max(w, h)) + }) + + /* + // XXX this may get REALLY SLOW for BIG images... + var size_getter = $.Deferred() var _i = new Image() _i.onload = function(){ size_getter.resolve(Math.max(parseInt(this.width), parseInt(this.height))) } _i.src = source + */ for(var i=0; i < sizes.length; i++){ var size = sizes[i] @@ -200,9 +232,12 @@ if(window.CEF_dumpJSON != null){ var preview_path = [target_path, name].join('/') var factor = source_size / size + // this can be 1, 2, 4 or 8... + var rscale = 1 // XXX make this compatible with other image processors... - var cmd = 'vips im_shrink "$IN" "$OUT:$COMPRESSION" $FACTOR $FACTOR' + var cmd = 'vips im_shrink "$IN:$RSCALE" "$OUT:$COMPRESSION" $FACTOR $FACTOR' + .replace(/\$RSCALE/g, rscale) .replace(/\$IN/g, source.replace(fp, '')) .replace(/\$OUT/g, preview_path) .replace(/\$COMPRESSION/g, compression) diff --git a/ui/files.js b/ui/files.js index d8f7c951..ab0ad52e 100755 --- a/ui/files.js +++ b/ui/files.js @@ -465,6 +465,7 @@ function loadRawDir(path, prefix){ var res = $.Deferred() + // filter images... var image_paths = $.map(files, function(e){ return IMAGE_PATTERN.test(e) ? e : null }) @@ -481,6 +482,9 @@ function loadRawDir(path, prefix){ res.notify(prefix, 'Loaded', 'Images.') IMAGES_CREATED = true + // XXX need to make basic previews (screen-size-ish and ribbon-size-ish)... + // XXX + DATA = dataFromImages(IMAGES) res.notify(prefix, 'Loaded', 'Data.') diff --git a/ui/index.html b/ui/index.html index f1ab1f17..7f13544a 100755 --- a/ui/index.html +++ b/ui/index.html @@ -172,9 +172,9 @@ $(function(){ DATA_ATTR + '_SETTINGS' in localStorage && loadLocalStorageSettings() // XXX this will reload everything... - (MARKED.length == 0 + MARKED.length == 0 && DATA_ATTR + '_MARKED' in localStorage - && loadLocalStorageMarks()) + && loadLocalStorageMarks() updateImages()