diff --git a/CHANGELOG.md b/CHANGELOG.md index f60471bd1..731a6ac22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Improvements - Improve warnings on inefficient tiff files ([#668](../../pull/668)) -- Add more options to setFrameQuad ([#669](../../pull/669)) +- Add more options to setFrameQuad ([#669](../../pull/669), [#670](../../pull/670)) ## Version 1.8.3 diff --git a/girder/girder_large_image/web_client/views/imageViewerWidget/setFrameQuad.js b/girder/girder_large_image/web_client/views/imageViewerWidget/setFrameQuad.js index bd02e3cda..5ae1da8da 100644 --- a/girder/girder_large_image/web_client/views/imageViewerWidget/setFrameQuad.js +++ b/girder/girder_large_image/web_client/views/imageViewerWidget/setFrameQuad.js @@ -53,6 +53,8 @@ * height of an individual frame to this value. * @param {string} [options.crossOrigin] If specified, use this as the * crossOrigin policy for images. + * @param {string} [options.progress] If specified, a function to call whenever + * a texture image is loaded. */ function setFrameQuad(tileinfo, layer, options) { layer.setFrameQuad = function () { }; @@ -106,6 +108,7 @@ function setFrameQuad(tileinfo, layer, options) { fvert = Math.ceil(texSize / (Math.ceil(h * texScale2 ** 0.5 / alignment) * alignment)); // tile sizes fw = Math.floor(texSize / fhorz / alignment) * alignment; + fvert = Math.max(Math.ceil(f / Math.floor(texSize / fw)), fvert); fh = Math.floor(texSize / fvert / alignment) * alignment; if (options.maxFrameSize) { const maxFrameSize = Math.floor(options.maxFrameSize / alignment) * alignment; @@ -119,7 +122,7 @@ function setFrameQuad(tileinfo, layer, options) { fh = Math.ceil(h / alignment) * alignment; } // shrink one dimension to account for aspect ratio - fw = Math.min(Math.ceil(fw * w / h / alignment) * alignment, fw); + fw = Math.min(Math.ceil(fh * w / h / alignment) * alignment, fw); fh = Math.min(Math.ceil(fw * h / w / alignment) * alignment, fh); // recompute frames across the texture fhorz = Math.floor(texSize / fw); @@ -154,7 +157,8 @@ function setFrameQuad(tileinfo, layer, options) { src: [], quads: [], frames: frames, - framesToIdx: {} + framesToIdx: {}, + loadedCount: 0 }; if (tileinfo.tileWidth && tileinfo.tileHeight) { // report that tiles below this level are not needed @@ -178,15 +182,27 @@ function setFrameQuad(tileinfo, layer, options) { status.src.push(src); if (idx === textures - 1) { img.onload = function () { + status.loadedCount += 1; status.loaded = true; if (layer._options && layer._options.minLevel !== undefined && (options.adjustMinLevel === undefined || options.adjustMinLevel) && status.minLevel && status.minLevel > layer._options.minLevel) { layer._options.minLevel = Math.min(layer._options.maxLevel, status.minLevel); } + if (options.progress) { + try { + options.progress(status); + } catch (err) {} + } }; } else { ((idx) => { img.onload = function () { + status.loadedCount += 1; status.images[idx + 1].src = status.src[idx + 1]; + if (options.progress) { + try { + options.progress(status); + } catch (err) {} + } }; })(idx); } diff --git a/large_image/tilesource/base.py b/large_image/tilesource/base.py index 18fcd41ce..3078a7d26 100644 --- a/large_image/tilesource/base.py +++ b/large_image/tilesource/base.py @@ -5,6 +5,7 @@ import pathlib import tempfile import threading +import time import numpy import PIL @@ -1839,6 +1840,7 @@ def tileFrames(self, format=(TILE_FORMAT_IMAGE, ), frameList=None, :returns: regionData, formatOrRegionMime: the image data and either the mime type, if the format is TILE_FORMAT_IMAGE, or the format. """ + lastlog = time.time() kwargs = kwargs.copy() kwargs.pop('tile_position', None) kwargs.pop('frame', None) @@ -1874,7 +1876,15 @@ def tileFrames(self, format=(TILE_FORMAT_IMAGE, ), frameList=None, subimage, _ = self.getRegion(format=TILE_FORMAT_NUMPY, frame=frame, **kwargs) offsetX = (idx % framesAcross) * frameWidth offsetY = (idx // framesAcross) * frameHeight - self.logger.debug('Tiling frame %r', [idx, frame, offsetX, offsetY]) + if time.time() - lastlog > 10: + self.logger.info( + 'Tiling frame %d (%d/%d), offset %dx%d', + frame, idx, len(frameList), offsetX, offsetY) + lastlog = time.time() + else: + self.logger.debug( + 'Tiling frame %d (%d/%d), offset %dx%d', + frame, idx, len(frameList), offsetX, offsetY) image = self._addRegionTileToImage( image, subimage, offsetX, offsetY, outWidth, outHeight, tiled, tile=tile, **kwargs)