mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 10:50:08 +00:00
more work on caching and related web workers...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
015a7a0403
commit
b2f0dcbd52
@ -422,7 +422,11 @@ module.ImagesPrototype = {
|
|||||||
// Image data helpers...
|
// Image data helpers...
|
||||||
|
|
||||||
// XXX see: ribbons.js for details...
|
// XXX see: ribbons.js for details...
|
||||||
getBestPreview: function(gid, size, img_data){
|
getBestPreview: function(gid, size, img_data, full_path){
|
||||||
|
if(img_data === true){
|
||||||
|
full_path = true
|
||||||
|
img_data = null
|
||||||
|
}
|
||||||
//gid = gid == null ? getImageGID(): gid
|
//gid = gid == null ? getImageGID(): gid
|
||||||
//size = size == null ? getVisibleImageSize('max') : size
|
//size = size == null ? getVisibleImageSize('max') : size
|
||||||
img_data = img_data == null ? this[gid] : img_data
|
img_data = img_data == null ? this[gid] : img_data
|
||||||
@ -450,7 +454,10 @@ module.ImagesPrototype = {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
//url: normalizePath(url),
|
//url: normalizePath(url),
|
||||||
url: url,
|
url: (full_path && img_data.base_path ?
|
||||||
|
img_data.base_path + '/'
|
||||||
|
: '')
|
||||||
|
+ url,
|
||||||
size: preview_size
|
size: preview_size
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1113,13 +1113,7 @@ var RibbonsPrototype = {
|
|||||||
that.flipImage(image, img_data.flipped == null ? [] : img_data.flipped)
|
that.flipImage(image, img_data.flipped == null ? [] : img_data.flipped)
|
||||||
|
|
||||||
// preview...
|
// preview...
|
||||||
var p_url = that.images.getBestPreview(img_data.id, size, img_data).url
|
var p_url = that.images.getBestPreview(img_data.id, size, img_data, true).url
|
||||||
|
|
||||||
// XXX experimental...
|
|
||||||
if(img_data.base_path != null){
|
|
||||||
// XXX need to check if p_url is already absolute...
|
|
||||||
p_url = img_data.base_path +'/'+ p_url
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the preview if it's a new image or...
|
// update the preview if it's a new image or...
|
||||||
// XXX this should be pushed as far back as possible...
|
// XXX this should be pushed as far back as possible...
|
||||||
|
|||||||
@ -1465,6 +1465,52 @@ module.Journal = ImageGridFeatures.Feature({
|
|||||||
// XXX try a strategy: load more in the direction of movement by an offset...
|
// XXX try a strategy: load more in the direction of movement by an offset...
|
||||||
// XXX updateRibbon(..) is not signature compatible with data.updateRibbon(..)
|
// XXX updateRibbon(..) is not signature compatible with data.updateRibbon(..)
|
||||||
var PartialRibbonsActions = actions.Actions({
|
var PartialRibbonsActions = actions.Actions({
|
||||||
|
// NOTE: this will not work from chrome when loading from a local fs...
|
||||||
|
// XXX experimental...
|
||||||
|
startCacheWorker: [
|
||||||
|
function(){
|
||||||
|
// a worker is started already...
|
||||||
|
if(this.cacheWorker != null){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var b = new Blob([[
|
||||||
|
'addEventListener(\'message\', function(e) {',
|
||||||
|
' var urls = e.data',
|
||||||
|
' urls = urls.constructor !== Array ? [urls] : urls',
|
||||||
|
' var l = urls.length',
|
||||||
|
' urls.forEach(function(url){',
|
||||||
|
' var xhr = new XMLHttpRequest()',
|
||||||
|
' xhr.responseType = \'blob\'',
|
||||||
|
/*
|
||||||
|
' xhr.onload = xhr.onerror = function(){',
|
||||||
|
' l -= 1',
|
||||||
|
' if(l <= 0){',
|
||||||
|
' postMessage({status: \'done.\', urls: urls})',
|
||||||
|
' }',
|
||||||
|
' }',
|
||||||
|
*/
|
||||||
|
' xhr.open(\'GET\', url, true)',
|
||||||
|
' xhr.send()',
|
||||||
|
' })',
|
||||||
|
'}, false)',
|
||||||
|
].join('\n')])
|
||||||
|
|
||||||
|
var url = URL.createObjectURL(b)
|
||||||
|
|
||||||
|
this.cacheWorker = new Worker(url)
|
||||||
|
this.cacheWorker.url = url
|
||||||
|
}],
|
||||||
|
stopCacheWorker: [
|
||||||
|
function(){
|
||||||
|
if(this.cacheWorker){
|
||||||
|
this.cacheWorker.terminate()
|
||||||
|
URL.revokeObjectURL(this.cacheWorker.url)
|
||||||
|
delete this.cacheWorker
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
|
||||||
|
|
||||||
// Pre-load images...
|
// Pre-load images...
|
||||||
//
|
//
|
||||||
// Sources supported:
|
// Sources supported:
|
||||||
@ -1474,11 +1520,32 @@ var PartialRibbonsActions = actions.Actions({
|
|||||||
// 'ribbon' - pre-cache from current ribbon
|
// 'ribbon' - pre-cache from current ribbon
|
||||||
// 'order' - pre-cache from images in order
|
// 'order' - pre-cache from images in order
|
||||||
//
|
//
|
||||||
|
// NOTE: workers when loaded from file:// in a browser context
|
||||||
|
// will not have access to local images...
|
||||||
|
//
|
||||||
|
// XXX need a clear strategy to run this...
|
||||||
|
// XXX might be a good idea to make the worker queue the lists...
|
||||||
|
// ...this will need careful prioritization logic...
|
||||||
|
// - avoid loading the same url too often
|
||||||
|
// - load the most probable urls first
|
||||||
|
// - next targets
|
||||||
|
// - next/prev
|
||||||
|
// .preCacheJumpTargets(target, 'ribbon', this.screenwidth)
|
||||||
|
// - next/prev marked/bookmarked/order
|
||||||
|
// .preCacheJumpTargets(target, 'marked')
|
||||||
|
// .preCacheJumpTargets(target, 'bookmarked')
|
||||||
|
// .preCacheJumpTargets(target, 'order')
|
||||||
|
// - next/prev screen
|
||||||
|
// .preCacheJumpTargets(target, 'ribbon',
|
||||||
|
// this.config['preload-radius'] * this.screenwidth)
|
||||||
|
// - next/prev ribbon
|
||||||
|
// .preCacheJumpTargets(target, this.data.getRibbon(target, 1))
|
||||||
|
// .preCacheJumpTargets(target, this.data.getRibbon(target, -1))
|
||||||
|
// - next blocks
|
||||||
|
// - what resize ribbon does...
|
||||||
|
// XXX coordinate this with .resizeRibbon(..)
|
||||||
// XXX make this support an explicit list of gids....
|
// XXX make this support an explicit list of gids....
|
||||||
// XXX should this be here???
|
// XXX should this be here???
|
||||||
// XXX should this be run in a worker???
|
|
||||||
// NOTE: workers when loaded from file:// in a browser context
|
|
||||||
// will not have access to local images...
|
|
||||||
preCacheJumpTargets: ['Interface/Pre-cache potential jump target images',
|
preCacheJumpTargets: ['Interface/Pre-cache potential jump target images',
|
||||||
function(target, sources, radius, size){
|
function(target, sources, radius, size){
|
||||||
target = target instanceof jQuery
|
target = target instanceof jQuery
|
||||||
@ -1494,12 +1561,13 @@ var PartialRibbonsActions = actions.Actions({
|
|||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
|
// get preview...
|
||||||
var _getPreview = function(c){
|
var _getPreview = function(c){
|
||||||
return that.images[c] && (that.images[c].base_path ?
|
return that.images[c]
|
||||||
(that.images[c].base_path +'/')
|
&& that.images.getBestPreview(c, size, true).url
|
||||||
: '')
|
|
||||||
+ that.images.getBestPreview(c, size).url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get a stet of paths...
|
||||||
// NOTE: we are also ordering the resulting gids by their
|
// NOTE: we are also ordering the resulting gids by their
|
||||||
// distance from target...
|
// distance from target...
|
||||||
var _get = function(i, lst, source, radius, oddity, step){
|
var _get = function(i, lst, source, radius, oddity, step){
|
||||||
@ -1523,9 +1591,8 @@ var PartialRibbonsActions = actions.Actions({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run the actual preload...
|
||||||
// run async...
|
var _run = function(){
|
||||||
setTimeout(function(){
|
|
||||||
sources.forEach(function(tag){
|
sources.forEach(function(tag){
|
||||||
// order...
|
// order...
|
||||||
if(tag == 'order'){
|
if(tag == 'order'){
|
||||||
@ -1563,13 +1630,27 @@ var PartialRibbonsActions = actions.Actions({
|
|||||||
var p = _getPreview(that.data.getImage(target))
|
var p = _getPreview(that.data.getImage(target))
|
||||||
p && lst.splice(0, 0, p)
|
p && lst.splice(0, 0, p)
|
||||||
|
|
||||||
// do the actual preloading...
|
// web worker...
|
||||||
lst.forEach(function(url){
|
if(that.cacheWorker != null){
|
||||||
var img = new Image()
|
that.cacheWorker.postMessage(lst)
|
||||||
img.src = url
|
|
||||||
})
|
// async inline...
|
||||||
|
} else {
|
||||||
|
// do the actual preloading...
|
||||||
|
lst.forEach(function(url){
|
||||||
|
var img = new Image()
|
||||||
|
img.src = url
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}, 0)
|
}
|
||||||
|
|
||||||
|
if(that.cacheWorker != null){
|
||||||
|
_run()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setTimeout(_run, 0)
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
// NOTE: this will force sync resize if one of the following is true:
|
// NOTE: this will force sync resize if one of the following is true:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user