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

Change ConcretePlaneLoader to PlaneLoaderFactory.

parent a84b8a1c
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,8 @@ import azgracompress.U16;
import azgracompress.cli.ParsedCliOptions;
import azgracompress.de.DeException;
import azgracompress.de.shade.ILShadeSolver;
import azgracompress.io.ConcretePlaneLoader;
import azgracompress.io.IPlaneLoader;
import azgracompress.io.PlaneLoaderFactory;
import azgracompress.quantization.QTrainIteration;
import azgracompress.quantization.QuantizationValueCache;
import azgracompress.quantization.scalar.LloydMaxU16ScalarQuantization;
......@@ -25,9 +26,9 @@ public class ScalarQuantizationBenchmark extends BenchmarkBase {
@Override
public void startBenchmark() {
ConcretePlaneLoader planeLoader = null;
IPlaneLoader planeLoader;
try {
planeLoader = new ConcretePlaneLoader(options.getInputFileInfo());
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(options.getInputFileInfo());
} catch (Exception e) {
e.printStackTrace();
System.err.println("Unable to create SCIFIO reader.");
......
......@@ -2,7 +2,8 @@ package azgracompress.benchmark;
import azgracompress.cli.ParsedCliOptions;
import azgracompress.data.*;
import azgracompress.io.ConcretePlaneLoader;
import azgracompress.io.IPlaneLoader;
import azgracompress.io.PlaneLoaderFactory;
import azgracompress.quantization.QuantizationValueCache;
import azgracompress.quantization.vector.CodebookEntry;
import azgracompress.quantization.vector.LBGResult;
......@@ -48,9 +49,9 @@ public class VectorQuantizationBenchmark extends BenchmarkBase {
if (planes.length < 1) {
return;
}
ConcretePlaneLoader planeLoader = null;
IPlaneLoader planeLoader;
try {
planeLoader = new ConcretePlaneLoader(options.getInputFileInfo());
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(options.getInputFileInfo());
} catch (Exception e) {
e.printStackTrace();
System.err.println("Unable to create SCIFIO reader.");
......
......@@ -5,7 +5,8 @@ import azgracompress.cli.InputFileInfo;
import azgracompress.cli.ParsedCliOptions;
import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.data.ImageU16;
import azgracompress.io.ConcretePlaneLoader;
import azgracompress.io.IPlaneLoader;
import azgracompress.io.PlaneLoaderFactory;
import azgracompress.io.OutBitStream;
import azgracompress.quantization.QuantizationValueCache;
import azgracompress.quantization.scalar.LloydMaxU16ScalarQuantization;
......@@ -85,9 +86,9 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
Stopwatch stopwatch = new Stopwatch();
final boolean hasGeneralQuantizer = options.hasCodebookCacheFolder() || options.hasReferencePlaneIndex();
final ConcretePlaneLoader planeLoader;
final IPlaneLoader planeLoader;
try {
planeLoader = new ConcretePlaneLoader(inputFileInfo);
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(inputFileInfo);
} catch (Exception e) {
throw new ImageCompressionException("Unable to create SCIFIO reader. " + e.getMessage());
}
......@@ -155,9 +156,9 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
private int[] loadConfiguredPlanesData() throws ImageCompressionException {
final InputFileInfo inputFileInfo = options.getInputFileInfo();
final ConcretePlaneLoader planeLoader;
final IPlaneLoader planeLoader;
try {
planeLoader = new ConcretePlaneLoader(inputFileInfo);
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(inputFileInfo);
} catch (Exception e) {
throw new ImageCompressionException("Unable to create SCIFIO reader. " + e.getMessage());
}
......
......@@ -5,7 +5,7 @@ import azgracompress.cli.ParsedCliOptions;
import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.data.Chunk2D;
import azgracompress.data.ImageU16;
import azgracompress.io.ConcretePlaneLoader;
import azgracompress.io.PlaneLoaderFactory;
import azgracompress.io.IPlaneLoader;
import azgracompress.io.OutBitStream;
import azgracompress.quantization.QuantizationValueCache;
......@@ -91,9 +91,9 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final InputFileInfo inputFileInfo = options.getInputFileInfo();
Stopwatch stopwatch = new Stopwatch();
final boolean hasGeneralQuantizer = options.hasCodebookCacheFolder() || options.hasReferencePlaneIndex();
final ConcretePlaneLoader planeLoader;
final IPlaneLoader planeLoader;
try {
planeLoader = new ConcretePlaneLoader(inputFileInfo);
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(inputFileInfo);
} catch (Exception e) {
throw new ImageCompressionException("Unable to create SCIFIO reader. " + e.getMessage());
}
......@@ -177,9 +177,9 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
private int[][] loadConfiguredPlanesData() throws ImageCompressionException {
final int vectorSize = options.getVectorDimension().getX() * options.getVectorDimension().getY();
final InputFileInfo inputFileInfo = options.getInputFileInfo();
final ConcretePlaneLoader planeLoader;
final IPlaneLoader planeLoader;
try {
planeLoader = new ConcretePlaneLoader(inputFileInfo);
planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(inputFileInfo);
} catch (Exception e) {
throw new ImageCompressionException("Unable to create SCIFIO reader. " + e.getMessage());
}
......
package azgracompress.io;
import azgracompress.cli.InputFileInfo;
import azgracompress.data.ImageU16;
import java.io.IOException;
public class ConcretePlaneLoader implements IPlaneLoader {
private final IPlaneLoader loader;
private final InputFileInfo inputFileInfo;
/**
* Create plane loader.
*
* @param inputFileInfo Information about input file.
* @throws Exception When fails to create SCIFIO reader.
*/
public ConcretePlaneLoader(final InputFileInfo inputFileInfo) throws Exception {
this.inputFileInfo = inputFileInfo;
if (inputFileInfo.isRAW()) {
loader = new RawDataLoader(inputFileInfo);
} else {
loader = new SCIFIOLoader(inputFileInfo);
}
}
@Override
public ImageU16 loadPlaneU16(int plane) throws IOException {
return loader.loadPlaneU16(plane);
}
@Override
public int[] loadPlanesU16Data(int[] planes) throws IOException {
return loader.loadPlanesU16Data(planes);
}
@Override
public int[] loadAllPlanesU16Data() throws IOException {
return loader.loadAllPlanesU16Data();
}
}
package azgracompress.io;
import azgracompress.cli.InputFileInfo;
public final class PlaneLoaderFactory {
/**
* Create concrete plane loader for the input file.
*
* @param inputFileInfo Input file information.
* @return Concrete plane loader.
* @throws Exception When fails to create plane loader.
*/
public static IPlaneLoader getPlaneLoaderForInputFile(final InputFileInfo inputFileInfo) throws Exception {
if (inputFileInfo.isRAW()) {
return new RawDataLoader(inputFileInfo);
} else {
return new SCIFIOLoader(inputFileInfo);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment