Skip to content

Commit

Permalink
Merge pull request #670 from girder/set-frame-quad-options
Browse files Browse the repository at this point in the history
Add more options to setFrameQuad
  • Loading branch information
manthey authored Oct 25, 2021
2 parents e51b925 + 364cc73 commit b6c6d42
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () { };
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
12 changes: 11 additions & 1 deletion large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib
import tempfile
import threading
import time

import numpy
import PIL
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b6c6d42

Please sign in to comment.