perform autoscaling if floating point thumbnail found.
This commit is contained in:
parent
4ea2dc7110
commit
0df492ff14
@ -21,7 +21,9 @@ import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
import loci.common.DebugTools;
|
||||
import loci.formats.FormatException;
|
||||
import loci.formats.FormatTools;
|
||||
import loci.formats.ImageReader;
|
||||
import loci.formats.gui.AWTImageTools;
|
||||
import loci.formats.gui.BufferedImageReader;
|
||||
|
||||
public class BioFormatsImageThumbnail {
|
||||
@ -89,8 +91,10 @@ public class BioFormatsImageThumbnail {
|
||||
final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) {
|
||||
final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
|
||||
final ImageWriteParam param = writer.getDefaultWriteParam();
|
||||
if (param.canWriteCompressed()) {
|
||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
param.setCompressionQuality(quality);
|
||||
}
|
||||
writer.setOutput(ios);
|
||||
writer.write(null, new IIOImage(removeAlphaChannel(image, matColor), null, null), param);
|
||||
writer.dispose();
|
||||
@ -166,12 +170,19 @@ public class BioFormatsImageThumbnail {
|
||||
}
|
||||
}
|
||||
reader.setSeries(series);
|
||||
final int no = 0;
|
||||
final int z = reader.getSizeZ() / 2; // middle of slices
|
||||
final int t = reader.getSizeT() / 2; // middle of frames
|
||||
final int c = 0; // first channel
|
||||
final int no = reader.getIndex(z, c, t);
|
||||
// System.out.println("series count: " + seriesCount);
|
||||
// System.out.println("image count: " + reader.getImageCount());
|
||||
// System.out.println("resolution: " + reader.getResolutionCount());
|
||||
// System.out.println("thubmail series: " + series);
|
||||
ret = reader.openThumbImage(no);
|
||||
if (!FormatTools.isFloatingPoint(reader.getPixelType())) {
|
||||
// auto scalling floating point thumbnail.
|
||||
ret = AWTImageTools.autoscale(ret);
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
for (Throwable e = t; e != null; e = e.getCause()) {
|
||||
if (t instanceof OutOfMemoryError) {
|
||||
@ -252,6 +263,7 @@ public class BioFormatsImageThumbnail {
|
||||
System.out.println(dataUri);
|
||||
// saveFile(dataUri, "/var/tmp/thumbnail." + format);
|
||||
} catch (final Throwable t) {
|
||||
// t.printStackTrace();
|
||||
System.out.println(t.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user