From 9b138999e5bdcd626470bf6ec7752d24d3ca7bb3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 17 May 2020 00:32:59 +0300 Subject: [PATCH] not waveforms respect image rotation/flip... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/metadata.js | 29 +++++++++- ui (gen4)/lib/components/ig-image-graph.js | 64 +++++++++++++++++++--- ui (gen4)/lib/widget/widget.js | 5 +- 3 files changed, 86 insertions(+), 12 deletions(-) diff --git a/ui (gen4)/features/metadata.js b/ui (gen4)/features/metadata.js index 8a74a0b0..b0dc289e 100755 --- a/ui (gen4)/features/metadata.js +++ b/ui (gen4)/features/metadata.js @@ -397,23 +397,48 @@ var MetadataUIActions = actions.Actions({ }, }) } // XXX EXPERIMENTAL: graph - // XXX make this actually update the elem if it exists... // XXX do the calculations in a worker... make.dialog.updateGraph = function(gid, size){ + // prevent from updating too often... + if(this.__graph_updating){ + // request an update... + this.__graph_updating = [gid, size] + return this.graph } + this.__graph_updating = true + setTimeout(function(){ + // update was requested while we were out -> update now... + this.__graph_updating instanceof Array + && this.updateGraph(...this.__graph_updating) + delete this.__graph_updating }.bind(this), 200) + + // graph disabled... if(!graph || !that.config['metadata-graph']){ return } + + // data... gid = that.data.getImage(gid || 'current') var config = that.config['metadata-graph-config'] || {} var url = that.images[gid].preview ? that.images.getBestPreview(gid, size || 300, null, true).url : that.getImagePath(gid) + var flipped = (that.images[gid] || {}).flipped || [] + flipped = flipped.length == 1 ? + flipped[0] + : flipped.length == 2 ? + 'both' + : null + + // build the element... var elem = this.graph = Object.assign( this.graph || document.createElement('ig-image-graph'), config, // orientation.... - {orientation: (that.images[gid] || {}).orientation || 0}) + { + orientation: (that.images[gid] || {}).orientation || 0, + flipped: flipped, + }) Object.assign(elem.style, { width: '500px', height: '200px', diff --git a/ui (gen4)/lib/components/ig-image-graph.js b/ui (gen4)/lib/components/ig-image-graph.js index 92a4fee9..9644e568 100644 --- a/ui (gen4)/lib/components/ig-image-graph.js +++ b/ui (gen4)/lib/components/ig-image-graph.js @@ -2,7 +2,6 @@ * * * -* XXX still thinking on how to package this correctly... * XXX add worker support... * **********************************************************************/ @@ -48,6 +47,42 @@ module.Filters = { context.putImageData(data, 0, 0) }, + // get image pixels normalized to a square of size s, rotated and flipped... + // + // NOTE: flip is applied to the image before it is rotated... (XXX ???) + getNormalizedPixels: function(img, s, rotate, flip){ + s = s || Math.max(img.width, img.height) + rotate = rotate || 0 + + ;(rotate == 90 || rotate == 270) + && (flip = flip == 'horizontal' ? + 'vertical' + : flip == 'vertical' ? + 'horizontal' + : flip) + var [h, v] = flip == 'both' ? + [-1, -1] + : flip == 'horizontal' ? + [-1, 1] + : flip == 'vertical' ? + [1, -1] + : [1, 1] + + var c = this.makeCanvas(s, s) + var context = c.getContext('2d') + context.rect(0, 0, s, s) + context.fillStyle = 'black' + context.fill() + + if(img){ + context.setTransform(h*1, 0, 0, v*1, s/2, s/2) + context.rotate(rotate * Math.PI/180) + context.drawImage(img, -s/2, -s/2, s, s) + } + + return context.getImageData(0, 0, s, s) + }, + filterImage: function(filter, image, var_args){ var args = [this.getPixels(image)] for(var i=2; i