From d4ca5ba455bffdb7ca027fd1a11513e3b8f48064 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 31 Oct 2020 02:10:27 +0300 Subject: [PATCH] added transform support for exporting + tweaks and cleanup... Signed-off-by: Alex A. Naanou --- Viewer/features/filesystem.js | 24 +++++++++++++-------- Viewer/features/sharp.js | 39 ++++++++++++++--------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Viewer/features/filesystem.js b/Viewer/features/filesystem.js index 643db672..9b33975b 100755 --- a/Viewer/features/filesystem.js +++ b/Viewer/features/filesystem.js @@ -2131,7 +2131,9 @@ var FileSystemWriterActions = actions.Actions({ // XXX make this dependant on max_size.... include_orig = include_orig || true - var resize = max_size && this.makeResizedImage + // XXX get value from settings... + var resize = max_size + && this.makeResizedImage // clear/backup target... clean_target_dir = clean_target_dir === undefined ? @@ -2252,18 +2254,17 @@ var FileSystemWriterActions = actions.Actions({ res : max return true } - // skip and remove... delete previews[res] replace_orig = true }) // get paths... .map(function(res){ - return res != max ? - decodeURI(previews[res]) - // NOTE: we will skip including the preview - // we are using as the primary image to - // save space... - : null }) + if(res != max){ + return decodeURI(previews[res]) } + // NOTE: we will skip including the preview + // we are using as the primary image to + // save space... + delete previews[res] }) // add primary image (copy)... // XXX check if any of the previews/main images // matches the size and copy instead of resize... @@ -2327,7 +2328,12 @@ var FileSystemWriterActions = actions.Actions({ resize && include_orig && queue - .push(this.makeResizedImage(gids, max_size, path, { logger })) + .push(this.makeResizedImage(gids, max_size, path, { + // NOTE: we do not transform here so as to keep + // the index as-is, minimizing changes... + transform: false, + logger, + })) // index... var index = this.prepareIndexForWrite(json, true) diff --git a/Viewer/features/sharp.js b/Viewer/features/sharp.js index f074e84a..36d12736 100755 --- a/Viewer/features/sharp.js +++ b/Viewer/features/sharp.js @@ -170,7 +170,8 @@ var SharpActions = actions.Actions({ transform: ..., crop: ..., - logger: ... + timestamp: ..., + logger: ..., , } @@ -220,26 +221,24 @@ var SharpActions = actions.Actions({ overwrite, // transformations... - // XXX not implemented... transform, // XXX not implemented... crop, + timestamp, logger, } = options // defaults... pattern = pattern || '%n' - /* XXX transform = transform === undefined ? true : transform - //*/ + timestamp = timestamp || Date.timeStamp() logger = logger || this.logger logger = logger && logger.push('Resize') // backup... // XXX make backup name pattern configurable... - var timestamp = Date.timeStamp() var backupName = function(to){ var i = 0 while(fse.existsSync(`${to}.${timestamp}.bak`+ (i || ''))){ @@ -301,21 +300,17 @@ var SharpActions = actions.Actions({ .clone() // handle transform (.orientation / .flip) and .crop... .run(function(){ + var img_data = that.images[gid] + if(transform && (img_data.orientation || img_data.flipped)){ + img_data.orientation + && this.rotate(img_data.orientation) + img_data.flipped + && img_data.flipped.includes('horizontal') + && this.flip() } + img_data.flipped + && img_data.flipped.includes('vertical') + && this.flop() // XXX - if(transform || crop){ - throw new Error('.makeResizedImage(..): ' - +[ - transform ? 'transform' : [], - crop ? 'crop' : [], - ].flat().join(' and ') - +' not implemented...') } - // XXX need clear spec defining what - // order transforms are applied - // and in which coordinates we - // crop (i.e. pre/post transform)... - if(transform){ - // XXX - } if(crop){ // XXX } @@ -444,8 +439,7 @@ var SharpActions = actions.Actions({ img.orientation = o.orientation img.flipped = o.flipped - that.markChanged('images', [data.gid]) - } + that.markChanged('images', [data.gid]) } // NOTE: this will handle both 'queue' and 'resolved' statuses... logger && @@ -482,8 +476,7 @@ var SharpActions = actions.Actions({ } data == 'completed' ? resolve() - : post_handler(err, data) } - }) })) + : post_handler(err, data) } }) })) // now do the work (sync)... } else {