From 5908989d22561a607ee8c91b1da75e8ab0f6183e Mon Sep 17 00:00:00 2001 From: David Manthey Date: Wed, 7 Jun 2023 15:48:17 -0400 Subject: [PATCH] Fix converting multiframe files that vips reads as single frame --- CHANGELOG.md | 3 +++ .../web_client/templates/largeImage_fileAction.pug | 2 +- girder/girder_large_image/web_client/views/fileList.js | 2 +- test/test_converter.py | 10 ++++++++++ utilities/converter/large_image_converter/__init__.py | 4 +++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 358a82d3d..f9fd3959c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ - Refactor reading the .large_image_config.yaml file on the girder client ([#1193](../../pull/1193)) - Refactor of the which-folders-have-annotations pipeline ([#1194](../../pull/1194)) +### Bug Fixes +- Fix an issue converting multiframe files that vips reads as single frame ([#1195](../../pull/1195)) + ## 1.22.2 ### Changes diff --git a/girder/girder_large_image/web_client/templates/largeImage_fileAction.pug b/girder/girder_large_image/web_client/templates/largeImage_fileAction.pug index 76d53fd3c..b82bc8cf0 100644 --- a/girder/girder_large_image/web_client/templates/largeImage_fileAction.pug +++ b/girder/girder_large_image/web_client/templates/largeImage_fileAction.pug @@ -7,5 +7,5 @@ else if largeImage && largeImage.expected === true a.g-large-image-expected(title="A large image file is being generated") i.icon-picture else if !largeImage || !largeImage.fileId - a.g-large-image-create(title="Use this file for a large image") + a.g-large-image-create(title="Use this file for a large image. Ctrl-click to force converting the image before using it") i.icon-picture diff --git a/girder/girder_large_image/web_client/views/fileList.js b/girder/girder_large_image/web_client/views/fileList.js index 31c4647ee..36bdeade2 100644 --- a/girder/girder_large_image/web_client/views/fileList.js +++ b/girder/girder_large_image/web_client/views/fileList.js @@ -53,7 +53,7 @@ wrap(FileListWidget, 'render', function (render) { restRequest({ type: 'POST', url: 'item/' + this.parentItem.id + '/tiles', - data: {fileId: fileId, notify: true}, + data: {fileId: fileId, notify: true, force: !!(e.originalEvent || {}).ctrlKey}, error: function (error) { if (error.status !== 0) { events.trigger('g:alert', { diff --git a/test/test_converter.py b/test/test_converter.py index a8341dd5b..a82b8906a 100644 --- a/test/test_converter.py +++ b/test/test_converter.py @@ -1,6 +1,7 @@ import json import os import shutil +import sys import large_image_converter import large_image_converter.__main__ as main @@ -314,3 +315,12 @@ def testConvertFromTestSourceFrameArray(tmpdir): assert len(metadata['frames']) == 6 info = tifftools.read_tiff(outputPath) assert len(info['ifds']) == 6 + + +@pytest.mark.skipif(sys.version_info < (3, 7), reason='requires python >= 3.7 for the test image') +def testConvertImageJ(tmpdir): + imagePath = datastore.fetch('synthetic_imagej.tiff') + outputPath = os.path.join(tmpdir, 'out.tiff') + large_image_converter.convert(imagePath, outputPath, compression='jpeg', quality=50) + info = tifftools.read_tiff(outputPath) + assert len(info['ifds']) == 44 diff --git a/utilities/converter/large_image_converter/__init__.py b/utilities/converter/large_image_converter/__init__.py index f744eb26c..3265146fb 100644 --- a/utilities/converter/large_image_converter/__init__.py +++ b/utilities/converter/large_image_converter/__init__.py @@ -924,7 +924,9 @@ def convert(inputPath, outputPath=None, **kwargs): # noqa: C901 lidata = _data_from_large_image(inputPath, tempPath, **kwargs) logger.log(logging.DEBUG - 1, 'large_image information for %s: %r', inputPath, lidata) - if not is_vips(inputPath) and lidata: + if lidata and (not is_vips(inputPath) or ( + len(lidata['metadata'].get('frames', [])) >= 2 and + not _is_multiframe(inputPath))): _convert_large_image(inputPath, outputPath, tempPath, lidata, **kwargs) elif _is_multiframe(inputPath): _generate_multiframe_tiff(inputPath, outputPath, tempPath, lidata, **kwargs)