Skip to content
Snippets Groups Projects
Commit 9a423f4f authored by Vojtěch Moravec's avatar Vojtěch Moravec
Browse files

Add loader type and pixel type to InputData.

parent ebe97aa2
Branches
No related tags found
No related merge requests found
Showing
with 133 additions and 51 deletions
package azgracompress.benchmark;
import azgracompress.io.InputDataInfo;
import azgracompress.io.InputData;
import azgracompress.cli.ParsedCliOptions;
import azgracompress.data.ImageU16;
import azgracompress.data.V3i;
......@@ -40,7 +40,7 @@ abstract class BenchmarkBase {
protected BenchmarkBase(final ParsedCliOptions options) {
this.options = options;
final InputDataInfo ifi = options.getInputDataInfo();
final InputData ifi = options.getInputDataInfo();
this.inputFile = ifi.getFilePath();
this.outputDirectory = options.getOutputFilePath();
......
......@@ -8,7 +8,8 @@ import azgracompress.data.V2i;
import azgracompress.data.V3i;
import azgracompress.fileformat.FileExtensions;
import azgracompress.fileformat.QuantizationType;
import azgracompress.io.InputDataInfo;
import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import io.scif.FormatException;
import io.scif.Plane;
import io.scif.Reader;
......@@ -139,7 +140,7 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
setCodebookCacheFolder(cmd.getOptionValue(CliConstants.CODEBOOK_CACHE_FOLDER_LONG, null));
if (!parseErrorOccurred) {
setOutputFilePath(cmd.getOptionValue(CliConstants.OUTPUT_LONG, getDefaultOutputFilePath(getInputDataInfo().getFilePath())));
setOutputFilePath(cmd.getOptionValue(CliConstants.OUTPUT_LONG, getDefaultOutputFilePath(((FileInputData) getInputDataInfo()).getFilePath())));
setCodebookCacheFolder(cmd.getOptionValue(CliConstants.CODEBOOK_CACHE_FOLDER_LONG, null));
}
......@@ -162,7 +163,8 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
return;
}
setInputDataInfo(new InputDataInfo(inputFileArguments[0]));
final FileInputData fileInputData = new FileInputData(inputFileArguments[0]);
setInputDataInfo(fileInputData);
// Decompress and Inspect methods doesn't require additional file information.
if ((method == ProgramMethod.Decompress) || (method == ProgramMethod.InspectFile)) {
......@@ -170,7 +172,7 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
}
// Check if input file exists.
if (!new File(getInputDataInfo().getFilePath()).exists()) {
if (!new File(fileInputData.getFilePath()).exists()) {
parseErrorOccurred = true;
errorBuilder.append("Input file doesn't exist.\n");
return;
......@@ -187,10 +189,10 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
private void parseSCIFIOFileArguments(StringBuilder errorBuilder, final String[] inputFileArguments) {
getInputDataInfo().setDataLoaderType(InputDataInfo.DataLoaderType.SCIFIOLoader);
getInputDataInfo().setDataLoaderType(InputData.DataLoaderType.SCIFIOLoader);
Reader reader;
try {
reader = ScifioWrapper.getReader(getInputDataInfo().getFilePath());
reader = ScifioWrapper.getReader(((FileInputData)getInputDataInfo()).getFilePath());
} catch (IOException | FormatException e) {
parseErrorOccurred = true;
errorBuilder.append("Failed to get SCIFIO reader for file.\n");
......@@ -251,7 +253,7 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
.append("e.g.: 1920x1080x1\n");
return;
}
getInputDataInfo().setDataLoaderType(InputDataInfo.DataLoaderType.RawDataLoader);
getInputDataInfo().setDataLoaderType(InputData.DataLoaderType.RawDataLoader);
parseImageDims(inputFileArguments[1], errorBuilder);
// User specified plane index or plane range.
......@@ -542,7 +544,7 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
}
sb.append("InputFile: ").append(getInputDataInfo().getFilePath()).append('\n');
sb.append("InputFile: ").append(((FileInputData)getInputDataInfo()).getFilePath()).append('\n');
sb.append("Output: ").append(getOutputFilePath()).append('\n');
sb.append("BitsPerCodebookIndex: ").append(getBitsPerCodebookIndex()).append('\n');
if (hasCodebookCacheFolder()) {
......
package azgracompress.cli.functions;
import azgracompress.cli.CustomFunctionBase;
import azgracompress.io.InputDataInfo;
import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import azgracompress.cli.ParsedCliOptions;
import azgracompress.data.ImageU16;
import azgracompress.data.V3i;
......@@ -125,9 +126,9 @@ public class MeasurePlaneErrorFunction extends CustomFunctionBase {
PlaneError[] planeErrors = new PlaneError[dims.getZ()];
InputDataInfo refFileInfo = new InputDataInfo(compFile);
InputData refFileInfo = new FileInputData(compFile);
refFileInfo.setDimension(dims);
InputDataInfo compFileInfo = new InputDataInfo(compressedFile);
InputData compFileInfo = new FileInputData(compressedFile);
compFileInfo.setDimension(dims);
final RawDataLoader refPlaneloader = new RawDataLoader(refFileInfo);
......
package azgracompress.compression;
import azgracompress.io.InputDataInfo;
import azgracompress.io.InputData;
import azgracompress.data.V2i;
import azgracompress.data.V3i;
import azgracompress.fileformat.QuantizationType;
/**
......@@ -12,7 +11,7 @@ public class CompressionOptions {
/**
* Input image or compressed file.
*/
private InputDataInfo inputDataInfo;
private InputData inputDataInfo;
/**
* Output image or compressed file.
......@@ -70,11 +69,11 @@ public class CompressionOptions {
return verbose;
}
public InputDataInfo getInputDataInfo() {
public InputData getInputDataInfo() {
return inputDataInfo;
}
public void setInputDataInfo(InputDataInfo ifi) {
public void setInputDataInfo(InputData ifi) {
this.inputDataInfo = ifi;
}
......
package azgracompress.compression;
import azgracompress.io.InputDataInfo;
import azgracompress.io.InputData;
import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.huffman.Huffman;
import azgracompress.io.OutBitStream;
......@@ -50,7 +50,7 @@ public abstract class CompressorDecompressorBase {
protected int[] getPlaneIndicesForCompression() {
final InputDataInfo ifi = options.getInputDataInfo();
final InputData ifi = options.getInputDataInfo();
if (ifi.isPlaneIndexSet()) {
return new int[]{ifi.getPlaneIndex()};
} else if (ifi.isPlaneRangeSet()) {
......
......@@ -2,7 +2,7 @@ package azgracompress.compression;
import azgracompress.U16;
import azgracompress.cache.QuantizationCacheManager;
import azgracompress.io.InputDataInfo;
import azgracompress.io.InputData;
import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.data.ImageU16;
import azgracompress.huffman.Huffman;
......@@ -88,7 +88,7 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
* @throws ImageCompressionException When compress process fails.
*/
public long[] compress(DataOutputStream compressStream) throws ImageCompressionException {
final InputDataInfo inputDataInfo = options.getInputDataInfo();
final InputData inputDataInfo = options.getInputDataInfo();
Stopwatch stopwatch = new Stopwatch();
final boolean hasGeneralQuantizer = options.hasCodebookCacheFolder() || options.shouldUseMiddlePlane();
......@@ -171,7 +171,7 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
}
private int[] loadConfiguredPlanesData() throws ImageCompressionException {
final InputDataInfo inputDataInfo = options.getInputDataInfo();
final InputData inputDataInfo = options.getInputDataInfo();
final IPlaneLoader planeLoader;
try {
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(inputDataInfo);
......
package azgracompress.compression;
import azgracompress.cache.QuantizationCacheManager;
import azgracompress.io.InputDataInfo;
import azgracompress.io.InputData;
import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.data.Chunk2D;
import azgracompress.data.ImageU16;
......@@ -92,7 +92,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* @throws ImageCompressionException When compress process fails.
*/
public long[] compress(DataOutputStream compressStream) throws ImageCompressionException {
final InputDataInfo inputDataInfo = options.getInputDataInfo();
final InputData inputDataInfo = options.getInputDataInfo();
Stopwatch stopwatch = new Stopwatch();
final boolean hasGeneralQuantizer = options.hasCodebookCacheFolder() || options.shouldUseMiddlePlane();
final IPlaneLoader planeLoader;
......@@ -189,7 +189,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
private int[][] loadConfiguredPlanesData() throws ImageCompressionException {
final int vectorSize = options.getVectorDimension().getX() * options.getVectorDimension().getY();
final InputDataInfo inputDataInfo = options.getInputDataInfo();
final InputData inputDataInfo = options.getInputDataInfo();
final IPlaneLoader planeLoader;
try {
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(inputDataInfo);
......
package azgracompress.io;
/**
* Input data backed by the buffer object.
*/
public class BufferInputData extends InputData {
/**
* Reference to the buffer.
*/
private final Object buffer;
/**
* Create input data backed by buffer object.
* @param buffer Buffer object reference.
*/
public BufferInputData(Object buffer) {
this.buffer = buffer;
}
/**
* Get buffer with the data.
* @return Pointer to array of corresponding pixel values.
*/
public Object getBuffer() {
return buffer;
}
}
package azgracompress.io;
/**
* Input data backed by the file.
*/
public class FileInputData extends InputData {
/**
* Input file path.
*/
private final String filePath;
/**
* Create input data backed by data file.
* @param filePath
*/
public FileInputData(String filePath) {
this.filePath = filePath;
}
/**
* Get path to the data file.
* @return
*/
@Override
public String getFilePath() {
return filePath;
}
}
......@@ -6,23 +6,29 @@ import azgracompress.data.V3i;
/**
* Information about the input file.
*/
public class InputDataInfo {
public abstract class InputData {
public enum DataLoaderType {
RawDataLoader,
SCIFIOLoader,
ImageJBufferLoader
}
/**
* Input file path.
*/
private final String filePath;
public enum PixelType {
Gray16,
AnythingElse
}
/**
* Type of an input data source.
*/
private DataLoaderType dataLoaderType = DataLoaderType.RawDataLoader;
/**
* Pixel type of the image data.
*/
private PixelType pixelType = PixelType.Gray16;
/**
* Image dimension.
*/
......@@ -38,9 +44,6 @@ public class InputDataInfo {
*/
Interval<Integer> planeRange = null;
public InputDataInfo(final String filePath) {
this.filePath = filePath;
}
public boolean isPlaneIndexSet() {
return (planeIndex != null);
......@@ -54,9 +57,6 @@ public class InputDataInfo {
this.dimension = dimension;
}
public String getFilePath() {
return filePath;
}
public V3i getDimensions() {
return dimension;
......@@ -85,4 +85,24 @@ public class InputDataInfo {
public void setDataLoaderType(DataLoaderType dataLoaderType) {
this.dataLoaderType = dataLoaderType;
}
public PixelType getPixelType() {
return pixelType;
}
public void setPixelType(PixelType pixelType) {
this.pixelType = pixelType;
}
public V3i getDimension() {
return dimension;
}
/**
* Override in FileInputData!!!
* @return null!
*/
public String getFilePath() {
return null;
}
}
package azgracompress.io.loader;
import azgracompress.io.InputDataInfo;
import azgracompress.io.InputData;
public final class PlaneLoaderFactory {
......@@ -11,17 +11,17 @@ public final class PlaneLoaderFactory {
* @return Concrete plane loader.
* @throws Exception When fails to create plane loader.
*/
public static IPlaneLoader getPlaneLoaderForInputFile(final InputDataInfo inputDataInfo) throws Exception {
public static IPlaneLoader getPlaneLoaderForInputFile(final InputData inputDataInfo) throws Exception {
switch (inputDataInfo.getDataLoaderType()) {
case RawDataLoader:
return new RawDataLoader(inputDataInfo);
case SCIFIOLoader:
return new SCIFIOLoader(inputDataInfo);
case ImageJBufferLoader:
break;
return new ImageJBufferLoader();
default:
throw new Exception("Unsupported data loader.");
}
return null;
// return null;
}
}
......@@ -2,16 +2,17 @@ package azgracompress.io.loader;
import azgracompress.data.ImageU16;
import azgracompress.data.V3i;
import azgracompress.io.InputDataInfo;
import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import azgracompress.utilities.TypeConverter;
import java.io.*;
import java.util.Arrays;
public class RawDataLoader implements IPlaneLoader {
private final InputDataInfo inputDataInfo;
private final InputData inputDataInfo;
public RawDataLoader(final InputDataInfo inputDataInfo) {
public RawDataLoader(final InputData inputDataInfo) {
this.inputDataInfo = inputDataInfo;
}
......@@ -20,7 +21,7 @@ public class RawDataLoader implements IPlaneLoader {
byte[] buffer;
final V3i rawDataDimension = inputDataInfo.getDimensions();
try (FileInputStream fileStream = new FileInputStream(inputDataInfo.getFilePath())) {
try (FileInputStream fileStream = new FileInputStream(((FileInputData)inputDataInfo).getFilePath())) {
final long planeSize = (long) rawDataDimension.getX() * (long) rawDataDimension.getY() * 2;
final long expectedFileSize = planeSize * rawDataDimension.getZ();
final long fileSize = fileStream.getChannel().size();
......@@ -69,7 +70,7 @@ public class RawDataLoader implements IPlaneLoader {
Arrays.sort(planes);
try (FileInputStream fileStream = new FileInputStream(inputDataInfo.getFilePath());
try (FileInputStream fileStream = new FileInputStream(((FileInputData)inputDataInfo).getFilePath());
DataInputStream dis = new DataInputStream(new BufferedInputStream(fileStream, 8192))) {
int lastIndex = 0;
......@@ -106,7 +107,7 @@ public class RawDataLoader implements IPlaneLoader {
int[] values = new int[(int) dataSize];
try (FileInputStream fileStream = new FileInputStream(inputDataInfo.getFilePath());
try (FileInputStream fileStream = new FileInputStream(((FileInputData)inputDataInfo).getFilePath());
DataInputStream dis = new DataInputStream(new BufferedInputStream(fileStream, 8192))) {
for (int i = 0; i < (int) dataSize; i++) {
......
......@@ -3,7 +3,8 @@ package azgracompress.io.loader;
import azgracompress.ScifioWrapper;
import azgracompress.data.ImageU16;
import azgracompress.data.V3i;
import azgracompress.io.InputDataInfo;
import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import azgracompress.utilities.TypeConverter;
import io.scif.FormatException;
import io.scif.Reader;
......@@ -13,7 +14,7 @@ import java.util.Arrays;
public class SCIFIOLoader implements IPlaneLoader {
private final InputDataInfo inputDataInfo;
private final InputData inputDataInfo;
private final Reader reader;
/**
......@@ -23,9 +24,9 @@ public class SCIFIOLoader implements IPlaneLoader {
* @throws IOException When fails to create SCIFIO reader.
* @throws FormatException When fails to create SCIFIO reader.
*/
public SCIFIOLoader(final InputDataInfo inputDataInfo) throws IOException, FormatException {
public SCIFIOLoader(final InputData inputDataInfo) throws IOException, FormatException {
this.inputDataInfo = inputDataInfo;
this.reader = ScifioWrapper.getReader(this.inputDataInfo.getFilePath());
this.reader = ScifioWrapper.getReader(((FileInputData)this.inputDataInfo).getFilePath());
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment