Skip to content
Snippets Groups Projects
Commit cfea253d authored by gpawel's avatar gpawel
Browse files

LMS-2699 Thumbnails pyramid: better log messages, possibility to specify exact...

LMS-2699 Thumbnails pyramid: better log messages, possibility to specify exact resolution of thumbnails, errors in case of zoom levels > 100%

SVN: 23987
parent b9c9eae3
No related branches found
No related tags found
No related merge requests found
...@@ -97,14 +97,13 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient ...@@ -97,14 +97,13 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient
thumbnailPaths.putDataSet(thumbnailPhysicalDatasetPermId, thumbnailPaths.putDataSet(thumbnailPhysicalDatasetPermId,
thumbnailsStorageFormatOrNull.getThumbnailsFileName()); thumbnailsStorageFormatOrNull.getThumbnailsFileName());
File thumbnailsFile = new File(thumbnailFilePath); File thumbnailsFile = new File(thumbnailFilePath);
final String relativeThumbnailFilePath = thumbnailsFile.getName();
HDF5Container container = new HDF5Container(thumbnailsFile); HDF5Container container = new HDF5Container(thumbnailsFile);
ImageLibraryInfo imageLibrary = imageStorageConfiguraton.tryGetImageLibrary(); ImageLibraryInfo imageLibrary = imageStorageConfiguraton.tryGetImageLibrary();
Hdf5ThumbnailGenerator thumbnailsGenerator = Hdf5ThumbnailGenerator thumbnailsGenerator =
new Hdf5ThumbnailGenerator(imageDataSetStructure, imagesParentDirectory, new Hdf5ThumbnailGenerator(imageDataSetStructure, imagesParentDirectory,
thumbnailPhysicalDatasetPermId, thumbnailsStorageFormatOrNull, thumbnailPhysicalDatasetPermId, thumbnailsStorageFormatOrNull,
imageLibrary, relativeThumbnailFilePath, thumbnailPaths, operationLog); imageLibrary, thumbnailPaths, operationLog);
container.runWriterClient(thumbnailsStorageFormatOrNull.isStoreCompressed(), container.runWriterClient(thumbnailsStorageFormatOrNull.isStoreCompressed(),
thumbnailsGenerator); thumbnailsGenerator);
} }
...@@ -130,8 +129,6 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient ...@@ -130,8 +129,6 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient
private final ImageLibraryInfo imageLibraryOrNull; private final ImageLibraryInfo imageLibraryOrNull;
private final String relativeThumbnailFilePath;
private final ThumbnailsInfo thumbnailPathCollector; private final ThumbnailsInfo thumbnailPathCollector;
private final Logger logger; private final Logger logger;
...@@ -139,15 +136,13 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient ...@@ -139,15 +136,13 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient
private Hdf5ThumbnailGenerator(ImageDataSetStructure imageDataSetStructure, private Hdf5ThumbnailGenerator(ImageDataSetStructure imageDataSetStructure,
File imagesParentDirectory, String thumbnailPhysicalDatasetPermId, File imagesParentDirectory, String thumbnailPhysicalDatasetPermId,
ThumbnailsStorageFormat thumbnailsStorageFormat, ImageLibraryInfo imageLibraryOrNull, ThumbnailsStorageFormat thumbnailsStorageFormat, ImageLibraryInfo imageLibraryOrNull,
String relativeThumbnailFilePath, ThumbnailsInfo thumbnailPathCollector, ThumbnailsInfo thumbnailPathCollector, Logger operationLog)
Logger operationLog)
{ {
this.imageDataSetStructure = imageDataSetStructure; this.imageDataSetStructure = imageDataSetStructure;
this.imagesParentDirectory = imagesParentDirectory; this.imagesParentDirectory = imagesParentDirectory;
this.thumbnailPhysicalDatasetPermId = thumbnailPhysicalDatasetPermId; this.thumbnailPhysicalDatasetPermId = thumbnailPhysicalDatasetPermId;
this.thumbnailsStorageFormat = thumbnailsStorageFormat; this.thumbnailsStorageFormat = thumbnailsStorageFormat;
this.imageLibraryOrNull = imageLibraryOrNull; this.imageLibraryOrNull = imageLibraryOrNull;
this.relativeThumbnailFilePath = relativeThumbnailFilePath;
this.thumbnailPathCollector = thumbnailPathCollector; this.thumbnailPathCollector = thumbnailPathCollector;
this.logger = operationLog; this.logger = operationLog;
} }
...@@ -336,17 +331,19 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient ...@@ -336,17 +331,19 @@ public class Hdf5ThumbnailGenerator implements IHDF5WriterClient
public void runWithSimpleWriter(IHDF5ContainerWriter writer) public void runWithSimpleWriter(IHDF5ContainerWriter writer)
{ {
final String thumbnailsName = " (" + thumbnailsStorageFormat.getThumbnailsFileName() + ")";
Collection<FailureRecord<ImageFileInfo>> errors = Collection<FailureRecord<ImageFileInfo>> errors =
ParallelizedExecutor.process(imageDataSetStructure.getImages(), ParallelizedExecutor.process(imageDataSetStructure.getImages(),
createThumbnailGenerator(writer), createThumbnailGenerator(writer),
thumbnailsStorageFormat.getAllowedMachineLoadDuringGeneration(), 100, thumbnailsStorageFormat.getAllowedMachineLoadDuringGeneration(), 100,
"Thumbnails generation", MAX_RETRY_OF_FAILED_GENERATION, true); "Thumbnails generation" + thumbnailsName, MAX_RETRY_OF_FAILED_GENERATION,
true);
if (errors.size() > 0) if (errors.size() > 0)
{ {
throw new IllegalStateException( throw new IllegalStateException(String.format(
String.format( "There were errors when generating %d thumbnails" + thumbnailsName
"There were errors when generating %d thumbnails, the whole thumbnails generation process fails.", + ", the whole thumbnails generation process fails.", errors.size()));
errors.size()));
} }
} }
} }
...@@ -26,6 +26,7 @@ import ch.systemsx.cisd.common.shared.basic.utils.StringUtils; ...@@ -26,6 +26,7 @@ import ch.systemsx.cisd.common.shared.basic.utils.StringUtils;
import ch.systemsx.cisd.openbis.dss.etl.dto.ImageLibraryInfo; import ch.systemsx.cisd.openbis.dss.etl.dto.ImageLibraryInfo;
import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.thumbnails.DefaultThumbnailsConfiguration; import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.thumbnails.DefaultThumbnailsConfiguration;
import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.thumbnails.IThumbnailsConfiguration; import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.thumbnails.IThumbnailsConfiguration;
import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.thumbnails.ResolutionBasedThumbnailsConfiguration;
import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.thumbnails.ZoomLevelBasedThumbnailsConfiguration; import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.thumbnails.ZoomLevelBasedThumbnailsConfiguration;
import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.transformations.ConvertToolImageTransformerFactory; import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.transformations.ConvertToolImageTransformerFactory;
import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.transformations.ImageTransformation; import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.transformations.ImageTransformation;
...@@ -204,8 +205,7 @@ abstract public class SimpleImageDataConfig ...@@ -204,8 +205,7 @@ abstract public class SimpleImageDataConfig
private String[] recognizedImageExtensions = new String[] private String[] recognizedImageExtensions = new String[]
{ "tiff", "tif", "png", "gif", "jpg", "jpeg" }; { "tiff", "tif", "png", "gif", "jpg", "jpeg" };
private List<IThumbnailsConfiguration> imagePyramid = private List<IThumbnailsConfiguration> imagePyramid = new ArrayList<IThumbnailsConfiguration>();
new ArrayList<IThumbnailsConfiguration>();
private int maxThumbnailWidthAndHeight = 256; private int maxThumbnailWidthAndHeight = 256;
...@@ -372,6 +372,27 @@ abstract public class SimpleImageDataConfig ...@@ -372,6 +372,27 @@ abstract public class SimpleImageDataConfig
} }
} }
public void setGenerateImagePyramidWithImageResolution(String[] resolutions)
{
imagePyramid.clear();
if (resolutions != null)
{
for (String resolution : resolutions)
{
String[] dimension = resolution.split("x");
if (dimension.length != 2)
{
throw new IllegalArgumentException(
"Resolution must be specified in format width x height, e. g. '400x300', but was: '"
+ resolution + "'");
}
int width = Integer.parseInt(dimension[0].trim());
int height = Integer.parseInt(dimension[1].trim());
imagePyramid.add(new ResolutionBasedThumbnailsConfiguration(width, height));
}
}
}
/** the maximal width and height of the generated thumbnails */ /** the maximal width and height of the generated thumbnails */
public void setMaxThumbnailWidthAndHeight(int maxThumbnailWidthAndHeight) public void setMaxThumbnailWidthAndHeight(int maxThumbnailWidthAndHeight)
{ {
......
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.thumbnails;
import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.SimpleImageDataConfig;
import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.ThumbnailsStorageFormat;
/**
* @author Pawel Glyzewski
*/
public class ResolutionBasedThumbnailsConfiguration extends AbstractThumbnailsConfiguration
{
private final int maxWidth;
private final int maxHeight;
public ResolutionBasedThumbnailsConfiguration(int maxWidth, int maxHeight)
{
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
}
public ThumbnailsStorageFormat getThumbnailsStorageFormat(SimpleImageDataConfig config)
{
ThumbnailsStorageFormat thumbnailsStorageFormat = new ThumbnailsStorageFormat();
thumbnailsStorageFormat.setAllowedMachineLoadDuringGeneration(config
.getAllowedMachineLoadDuringThumbnailsGeneration());
thumbnailsStorageFormat.setMaxWidth(maxWidth);
thumbnailsStorageFormat.setMaxHeight(maxHeight);
thumbnailsStorageFormat.setThumbnailsFileName(String.format("thumbnails_%dx%d.h5",
maxWidth, maxHeight));
thumbnailsStorageFormat.setGenerateWithImageMagic(config
.getGenerateThumbnailsWithImageMagic());
thumbnailsStorageFormat.setImageMagicParams(config
.getThumbnailsGenerationImageMagicParams());
thumbnailsStorageFormat.setHighQuality(config.getGenerateThumbnailsIn8BitHighQuality());
return thumbnailsStorageFormat;
}
}
...@@ -24,10 +24,16 @@ import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.ThumbnailsStorageFormat; ...@@ -24,10 +24,16 @@ import ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.ThumbnailsStorageFormat;
*/ */
public class ZoomLevelBasedThumbnailsConfiguration extends AbstractThumbnailsConfiguration public class ZoomLevelBasedThumbnailsConfiguration extends AbstractThumbnailsConfiguration
{ {
private double zoomLevel; private final double zoomLevel;
public ZoomLevelBasedThumbnailsConfiguration(double zoomLevel) public ZoomLevelBasedThumbnailsConfiguration(double zoomLevel)
{ {
if (zoomLevel > 100d || zoomLevel < 0d)
{
throw new IllegalStateException("Zoom level must be between 0% and 100%, but was: "
+ zoomLevel);
}
this.zoomLevel = zoomLevel; this.zoomLevel = zoomLevel;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment