mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-17 08:41:40 +00:00
makeImageGID(...) now working, some refactoring and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
c5f223c473
commit
e90641e255
@ -38,7 +38,7 @@ if(window.CEF_dumpJSON != null){
|
|||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
var fse = require('fs.extra')
|
var fse = require('fs.extra')
|
||||||
var proc = require('child_process')
|
var proc = require('child_process')
|
||||||
var crypto = require('crypto')
|
var node_crypto = require('crypto')
|
||||||
//var exif = require('exif2')
|
//var exif = require('exif2')
|
||||||
var gui = require('nw.gui')
|
var gui = require('nw.gui')
|
||||||
|
|
||||||
@ -126,14 +126,41 @@ if(window.CEF_dumpJSON != null){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX this uses vips...
|
// XXX this uses vips...
|
||||||
|
window.getVipsField = function(field, source){
|
||||||
|
if(source in IMAGES){
|
||||||
|
var img = IMAGES[source]
|
||||||
|
var source = normalizePath(img.path)
|
||||||
|
}
|
||||||
|
var getter = $.Deferred()
|
||||||
|
var cmd = 'vips im_header_string "$FIELD" "$IN"'
|
||||||
|
.replace(/\$IN/g, source.replace(fp, ''))
|
||||||
|
.replace(/\$FIELD/g, field)
|
||||||
|
proc.exec(cmd, function(error, stdout, stderr){
|
||||||
|
getter.resolve(stdout.trim())
|
||||||
|
})
|
||||||
|
return getter
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: source can be either gid or a path...
|
||||||
|
window.getImageOrientation = function(source){
|
||||||
|
var getter = $.Deferred()
|
||||||
|
getVipsField('exif-ifd0-Orientation', source)
|
||||||
|
.done(function(o){
|
||||||
|
getter.resolve(orientationExif2ImageGrid(parseInt(o)))
|
||||||
|
})
|
||||||
|
return getter
|
||||||
|
}
|
||||||
|
|
||||||
// XXX handle errors...
|
// XXX handle errors...
|
||||||
// NOTE: source can be either gid or a path...
|
// NOTE: source can be either gid or a path...
|
||||||
window._getImageSize = function(dimension, source){
|
window._getImageSize = function(dimension, source){
|
||||||
if(source in IMAGES){
|
if(source in IMAGES){
|
||||||
var img = IMAGES[gid]
|
var img = IMAGES[source]
|
||||||
var source = normalizePath(img.path)
|
var source = normalizePath(img.path)
|
||||||
}
|
}
|
||||||
var getter = $.Deferred()
|
var getter = $.Deferred()
|
||||||
|
|
||||||
|
// get max/min dimension...
|
||||||
if(dimension == 'max' || dimension == 'min'){
|
if(dimension == 'max' || dimension == 'min'){
|
||||||
$.when(
|
$.when(
|
||||||
_getImageSize('width', source),
|
_getImageSize('width', source),
|
||||||
@ -142,37 +169,21 @@ if(window.CEF_dumpJSON != null){
|
|||||||
getter.resolve(Math[dimension](w, h))
|
getter.resolve(Math[dimension](w, h))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// get dimension...
|
||||||
} else if(dimension == 'width' || dimension == 'height') {
|
} else if(dimension == 'width' || dimension == 'height') {
|
||||||
var cmd = 'vips im_header_int $DIM "$IN"'
|
getVipsField(dimension, source)
|
||||||
.replace(/\$IN/g, source.replace(fp, ''))
|
.done(function(res){
|
||||||
.replace(/\$DIM/g, dimension)
|
getter.resolve(parseInt(res))
|
||||||
proc.exec(cmd, function(error, stdout, stderr){
|
|
||||||
getter.resolve(parseInt(stdout.trim()))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
} else {
|
|
||||||
// wrong dimension...
|
// wrong dimension...
|
||||||
|
} else {
|
||||||
return getter.reject('unknown dimension:' + dimension)
|
return getter.reject('unknown dimension:' + dimension)
|
||||||
}
|
}
|
||||||
|
|
||||||
return getter
|
return getter
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: source can be either gid or a path...
|
|
||||||
window.getImageOrientation = function(source){
|
|
||||||
if(source in IMAGES){
|
|
||||||
var img = IMAGES[source]
|
|
||||||
var source = normalizePath(img.path)
|
|
||||||
}
|
|
||||||
var getter = $.Deferred()
|
|
||||||
var cmd = 'vips im_header_string exif-ifd0-Orientation "$IN"'
|
|
||||||
.replace(/\$IN/g, source.replace(fp, ''))
|
|
||||||
proc.exec(cmd, function(error, stdout, stderr){
|
|
||||||
getter.resolve(orientationExif2ImageGrid(parseInt(stdout.trim())))
|
|
||||||
})
|
|
||||||
return getter
|
|
||||||
}
|
|
||||||
|
|
||||||
// preview generation...
|
// preview generation...
|
||||||
//
|
//
|
||||||
// possible modes:
|
// possible modes:
|
||||||
@ -200,8 +211,8 @@ if(window.CEF_dumpJSON != null){
|
|||||||
//
|
//
|
||||||
// XXX make this not just vips-specific...
|
// XXX make this not just vips-specific...
|
||||||
// XXX path handling is a mess...
|
// XXX path handling is a mess...
|
||||||
|
// XXX looks a bit too complex for what it is -- revise!
|
||||||
window.makeImagePreviews = function(gid, sizes, mode, no_update_loaded){
|
window.makeImagePreviews = function(gid, sizes, mode, no_update_loaded){
|
||||||
//mode = mode == null ? 'optimized' : mode
|
|
||||||
mode = mode == null ? 'fast_f' : mode
|
mode = mode == null ? 'fast_f' : mode
|
||||||
|
|
||||||
var img = IMAGES[gid]
|
var img = IMAGES[gid]
|
||||||
@ -233,12 +244,6 @@ if(window.CEF_dumpJSON != null){
|
|||||||
var deferred = $.Deferred()
|
var deferred = $.Deferred()
|
||||||
previews.push(deferred)
|
previews.push(deferred)
|
||||||
|
|
||||||
// NOTE: for some magical reason writing this like:
|
|
||||||
// (function(...){
|
|
||||||
// ...
|
|
||||||
// }(...))
|
|
||||||
// produces a "undefined is not a function" in part of the
|
|
||||||
// invocations, usually the later ones...
|
|
||||||
[function(size, target_path, deferred){
|
[function(size, target_path, deferred){
|
||||||
// wait for current image size if needed...
|
// wait for current image size if needed...
|
||||||
size_getter.done(function(source_size){
|
size_getter.done(function(source_size){
|
||||||
@ -293,7 +298,6 @@ if(window.CEF_dumpJSON != null){
|
|||||||
factor = 1
|
factor = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX make this compatible with other image processors...
|
|
||||||
var cmd = 'vips im_shrink "$IN:$RSCALE" "$OUT:$COMPRESSION" $FACTOR $FACTOR'
|
var cmd = 'vips im_shrink "$IN:$RSCALE" "$OUT:$COMPRESSION" $FACTOR $FACTOR'
|
||||||
.replace(/\$IN/g, source.replace(fp, ''))
|
.replace(/\$IN/g, source.replace(fp, ''))
|
||||||
.replace(/\$RSCALE/g, rscale)
|
.replace(/\$RSCALE/g, rscale)
|
||||||
@ -301,7 +305,7 @@ if(window.CEF_dumpJSON != null){
|
|||||||
.replace(/\$COMPRESSION/g, compression)
|
.replace(/\$COMPRESSION/g, compression)
|
||||||
.replace(/\$FACTOR/g, factor)
|
.replace(/\$FACTOR/g, factor)
|
||||||
|
|
||||||
console.log(cmd)
|
//console.log(cmd)
|
||||||
|
|
||||||
proc.exec(cmd, function(error, stdout, stderr){
|
proc.exec(cmd, function(error, stdout, stderr){
|
||||||
if(error != null){
|
if(error != null){
|
||||||
@ -367,6 +371,8 @@ if(window.CEF_dumpJSON != null){
|
|||||||
// XXX check if we are leaking the tail...
|
// XXX check if we are leaking the tail...
|
||||||
// XXX test progress...
|
// XXX test progress...
|
||||||
// ...gets collected but the structure is a tad too complex...
|
// ...gets collected but the structure is a tad too complex...
|
||||||
|
// - should we make it flat???
|
||||||
|
// - do we need all that data????
|
||||||
// NOTE: this will remove the old deferred if it us resolved, thus
|
// NOTE: this will remove the old deferred if it us resolved, thus
|
||||||
// clearing the "log" of previous operations, unless keep_log
|
// clearing the "log" of previous operations, unless keep_log
|
||||||
// is set to true...
|
// is set to true...
|
||||||
@ -409,30 +415,47 @@ if(window.CEF_dumpJSON != null){
|
|||||||
return _PREVIW_CREATE_QUEUE
|
return _PREVIW_CREATE_QUEUE
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX should this be sync???
|
window.makeImageGID = function(source, make_text_gid){
|
||||||
/*
|
if(source in IMAGES){
|
||||||
window.makeImageGID = function(path, make_text_gid){
|
var img = IMAGES[source]
|
||||||
|
var source = normalizePath(img.path)
|
||||||
|
}
|
||||||
|
var getter = $.Deferred()
|
||||||
|
|
||||||
// XXX get exif...
|
$.when(
|
||||||
|
getVipsField('exif-ifd0-Artist', source),
|
||||||
var artist =
|
getVipsField('exif-ifd0-Date and Time', source))
|
||||||
|
.done(function(artist, date){
|
||||||
|
artist = artist
|
||||||
|
.replace(/\([^)]*\)/, '')
|
||||||
|
.trim()
|
||||||
|
artist = artist == '' ? 'Unknown' : artist
|
||||||
// format: "20130102-122315"
|
// format: "20130102-122315"
|
||||||
var date =
|
// XXX if not set, get ctime...
|
||||||
var name = path.split(/[\\\/]/).pop().split('.')[0]
|
date = date
|
||||||
|
.replace(/\([^)]*\)/, '')
|
||||||
|
.trim()
|
||||||
|
.replace(/:/g, '')
|
||||||
|
.replace(/ /g, '-')
|
||||||
|
var name = source.split(/[\\\/]/).pop().split('.')[0]
|
||||||
|
|
||||||
var text_gid = artist +'-'+ date +'-'+ name
|
var text_gid = artist +'-'+ date +'-'+ name
|
||||||
|
|
||||||
|
// text gid...
|
||||||
if(make_text_gid){
|
if(make_text_gid){
|
||||||
return text_gid
|
getter.resolve(text_gid)
|
||||||
}
|
|
||||||
|
|
||||||
var h = crypto.createHash('sha1')
|
// hex gid...
|
||||||
|
} else {
|
||||||
|
var h = node_crypto.createHash('sha1')
|
||||||
h.update(text_gid)
|
h.update(text_gid)
|
||||||
var hex_gid = h.digest('hex')
|
var hex_gid = h.digest('hex')
|
||||||
|
|
||||||
return hex_gid
|
getter.resolve(hex_gid)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return getter
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// UI-specific...
|
// UI-specific...
|
||||||
window.toggleFullscreenMode = createCSSClassToggler(
|
window.toggleFullscreenMode = createCSSClassToggler(
|
||||||
@ -441,7 +464,6 @@ if(window.CEF_dumpJSON != null){
|
|||||||
function(action){
|
function(action){
|
||||||
gui.Window.get().toggleFullscreen()
|
gui.Window.get().toggleFullscreen()
|
||||||
})
|
})
|
||||||
|
|
||||||
window.closeWindow = function(){
|
window.closeWindow = function(){
|
||||||
gui.Window.get().close()
|
gui.Window.get().close()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -494,26 +494,29 @@ function loadRawDir(path, no_preview_processing, prefix){
|
|||||||
|
|
||||||
reloadViewer()
|
reloadViewer()
|
||||||
|
|
||||||
// XXX is this the correct place for this???
|
// read orientation form files...
|
||||||
res.notify(prefix, 'Loading', 'Images orientation.')
|
res.notify(prefix, 'Loading', 'Images orientation.')
|
||||||
var o = updateImagesOrientationQ()
|
var o = updateImagesOrientationQ()
|
||||||
.done(function(){
|
.done(function(){
|
||||||
res.notify(prefix, 'Loaded', 'Images orientation.')
|
res.notify(prefix, 'Loaded', 'Images orientation.')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// load/generate previews...
|
||||||
if(!no_preview_processing){
|
if(!no_preview_processing){
|
||||||
res.notify(prefix, 'Loading/Generating', 'Previews.')
|
res.notify(prefix, 'Loading/Generating', 'Previews.')
|
||||||
var p = makeImagesPreviewsQ()
|
var p = makeImagesPreviewsQ()
|
||||||
.done(function(){
|
.done(function(){
|
||||||
res.notify(prefix, 'Loaded', 'Previews.')
|
res.notify(prefix, 'Loaded', 'Previews.')
|
||||||
})
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var p = 0
|
var p = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX we are not waiting for previews and orientation...
|
// NOTE: we are not waiting for previews and orientation...
|
||||||
return res.resolve()
|
return res.resolve()
|
||||||
/*
|
|
||||||
|
/* XXX do we need to make everyone wait for previews and orientation???
|
||||||
$.when(o, p).done(function(){
|
$.when(o, p).done(function(){
|
||||||
res.resolve()
|
res.resolve()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user