Skip to content
Snippets Groups Projects
Commit 4496519f authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

When using non-RAW file use SCIFIO.

parent 84e9c0d3
No related branches found
No related tags found
No related merge requests found
package azgracompress; package azgracompress;
import io.scif.FormatException;
import io.scif.Reader;
import io.scif.SCIFIO; import io.scif.SCIFIO;
import io.scif.formats.TIFFFormat;
import java.io.IOException;
public class ScifioWrapper { public class ScifioWrapper {
...@@ -24,6 +27,19 @@ public class ScifioWrapper { ...@@ -24,6 +27,19 @@ public class ScifioWrapper {
return instance.scifioInstance; return instance.scifioInstance;
} }
/**
* Get image file reader.
*
* @param path Path of image file.
* @return Scifio reader.
* @throws IOException
* @throws FormatException
*/
public static Reader getReader(final String path) throws IOException, FormatException {
SCIFIO scifio = getScifio();
return scifio.initializer().initializeReader(path);
}
public synchronized static void dispose() { public synchronized static void dispose() {
if (instance != null) { if (instance != null) {
if (instance.scifioInstance != null) { if (instance.scifioInstance != null) {
...@@ -31,4 +47,6 @@ public class ScifioWrapper { ...@@ -31,4 +47,6 @@ public class ScifioWrapper {
} }
} }
} }
} }
...@@ -2,16 +2,11 @@ package azgracompress.cli; ...@@ -2,16 +2,11 @@ package azgracompress.cli;
import azgracompress.data.V2i; import azgracompress.data.V2i;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import azgracompress.fileformat.FileType;
/** /**
* Information about the input file. * Information about the input file.
*/ */
public class InputFileInfo { public class InputFileInfo {
/**
* Input file type.
*/
private final FileType fileType;
/** /**
* Input file path. * Input file path.
*/ */
...@@ -25,8 +20,7 @@ public class InputFileInfo { ...@@ -25,8 +20,7 @@ public class InputFileInfo {
private boolean planeRangeSet = false; private boolean planeRangeSet = false;
private V2i planeRange; private V2i planeRange;
public InputFileInfo(final FileType fileType, final String filePath) { public InputFileInfo(final String filePath) {
this.fileType = fileType;
this.filePath = filePath; this.filePath = filePath;
} }
...@@ -59,10 +53,6 @@ public class InputFileInfo { ...@@ -59,10 +53,6 @@ public class InputFileInfo {
this.planeRange = planeRange; this.planeRange = planeRange;
} }
public FileType getFileType() {
return fileType;
}
public String getFilePath() { public String getFilePath() {
return filePath; return filePath;
} }
......
package azgracompress.cli; package azgracompress.cli;
import azgracompress.ScifioWrapper;
import azgracompress.compression.CompressorDecompressorBase; import azgracompress.compression.CompressorDecompressorBase;
import azgracompress.data.V2i; import azgracompress.data.V2i;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import azgracompress.fileformat.FileExtensions; import azgracompress.fileformat.FileExtensions;
import azgracompress.fileformat.FileType;
import azgracompress.fileformat.QuantizationType; import azgracompress.fileformat.QuantizationType;
import io.scif.FormatException;
import io.scif.Plane;
import io.scif.Reader;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.Paths; import java.nio.file.Paths;
public class ParsedCliOptions { public class ParsedCliOptions {
...@@ -118,30 +122,6 @@ public class ParsedCliOptions { ...@@ -118,30 +122,6 @@ public class ParsedCliOptions {
error = errorBuilder.toString(); error = errorBuilder.toString();
} }
/**
* Get file type from file extension.
*
* @param path File path.
* @return File type.
*/
private FileType getFileType(final String path) {
final String extension = FilenameUtils.getExtension(path).toLowerCase();
switch (extension) {
case FileExtensions.RAW: {
return FileType.RAW;
}
case FileExtensions.TIFF: {
return FileType.TIFF;
}
case FileExtensions.QCMP: {
return FileType.QCMP;
}
default: {
return FileType.Unsupported;
}
}
}
private void parseInputFilePart(StringBuilder errorBuilder, final String[] inputFileArguments) { private void parseInputFilePart(StringBuilder errorBuilder, final String[] inputFileArguments) {
if (inputFileArguments.length < 1) { if (inputFileArguments.length < 1) {
...@@ -150,7 +130,8 @@ public class ParsedCliOptions { ...@@ -150,7 +130,8 @@ public class ParsedCliOptions {
return; return;
} }
inputFileInfo = new InputFileInfo(getFileType(inputFileArguments[0]), inputFileArguments[0]);
inputFileInfo = new InputFileInfo(inputFileArguments[0]);
// Decompress and Inspect methods doesn't require additional file information. // Decompress and Inspect methods doesn't require additional file information.
if ((method == ProgramMethod.Decompress) || (method == ProgramMethod.InspectFile)) { if ((method == ProgramMethod.Decompress) || (method == ProgramMethod.InspectFile)) {
...@@ -164,28 +145,72 @@ public class ParsedCliOptions { ...@@ -164,28 +145,72 @@ public class ParsedCliOptions {
return; return;
} }
switch (inputFileInfo.getFileType()) { final String extension = FilenameUtils.getExtension(inputFileArguments[0]).toLowerCase();
case RAW: if (FileExtensions.RAW.equals(extension)) {
parseRawFileArguments(errorBuilder, inputFileArguments); parseRawFileArguments(errorBuilder, inputFileArguments);
break; } else {
case TIFF: // Default loading through SCIFIO.
parseTiffFileArguments(errorBuilder, inputFileArguments); parseSCIFIOFileArguments(errorBuilder, inputFileArguments);
break;
default: {
errorOccurred = true;
errorBuilder.append("Unsupported input file type. Currently supporting RAW and TIFF files.\n");
}
} }
} }
private void parseTiffFileArguments(StringBuilder errorBuilder, String[] inputFileArguments) { private void parseSCIFIOFileArguments(StringBuilder errorBuilder,
final String[] inputFileArguments) {
// inputFileInfo is already created with TIFF type. // inputFileInfo is already created with TIFF type.
assert (inputFileInfo.getFileType() == FileType.TIFF) : "Not TIFF type in parse Tiff arguments."; // assert (inputFileInfo.getFileType() == FileType.TIFF) : "Not TIFF type in parse Tiff arguments.";
Reader reader = null;
try {
reader = ScifioWrapper.getReader(inputFileInfo.getFilePath());
} catch (IOException | FormatException e) {
errorOccurred = true;
errorBuilder.append("Failed to get SCIFIO reader for file.\n");
errorBuilder.append(e.getMessage());
return;
}
final int imageCount = reader.getImageCount();
if (imageCount != 1) {
errorOccurred = true;
errorBuilder.append("We are currently not supporting files with multiple images.\n");
return;
}
final long planeCount = reader.getPlaneCount(0);
if (planeCount > (long) Integer.MAX_VALUE) {
errorOccurred = true;
errorBuilder.append("Too many planes.\n");
}
long planeWidth, planeHeight;
try {
Plane plane = reader.openPlane(0, 0);
planeWidth = plane.getLengths()[0];
planeHeight = plane.getLengths()[1];
if ((planeWidth > (long) Integer.MAX_VALUE) ||
(planeHeight > (long) Integer.MAX_VALUE)) {
errorOccurred = true;
errorBuilder.append("We are currently supporting planes with " +
"maximum size of Integer.MAX_VALUE x Integer.MAX_VALUE");
}
errorOccurred = true; } catch (FormatException | IOException e) {
errorBuilder.append("Got TIFF file.\n"); errorOccurred = true;
errorBuilder.append("Unable to open first plane of the first image.\n")
.append(e.getMessage());
return;
}
inputFileInfo.setDimension(new V3i(
(int) planeWidth,
(int) planeHeight,
(int) planeCount
));
if (inputFileArguments.length > 1) {
parseInputFilePlaneOptions(errorBuilder, inputFileArguments, 1);
}
} }
private void parseRawFileArguments(StringBuilder errorBuilder, String[] inputFileArguments) { private void parseRawFileArguments(StringBuilder errorBuilder, String[] inputFileArguments) {
......
...@@ -2,7 +2,6 @@ package azgracompress.fileformat; ...@@ -2,7 +2,6 @@ package azgracompress.fileformat;
public class FileExtensions { public class FileExtensions {
public static final String RAW = "raw"; public static final String RAW = "raw";
public static final String TIFF = "tiff";
public static final String QCMP = "qcmp"; public static final String QCMP = "qcmp";
} }
package azgracompress.fileformat;
public enum FileType {
RAW,
TIFF,
QCMP,
Unsupported
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment