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

Use new InputFileInfo object.

parent 780ef867
No related branches found
No related tags found
No related merge requests found
Showing
with 134 additions and 138 deletions
...@@ -30,7 +30,7 @@ public class DataCompressor { ...@@ -30,7 +30,7 @@ public class DataCompressor {
} }
ParsedCliOptions parsedCliOptions = new ParsedCliOptions(cmd); ParsedCliOptions parsedCliOptions = new ParsedCliOptions(cmd);
if (parsedCliOptions.hasErrorOccured()) { if (parsedCliOptions.didErrorOccure()) {
System.err.println(parsedCliOptions.getError()); System.err.println(parsedCliOptions.getError());
return; return;
} }
......
package azgracompress.benchmark; package azgracompress.benchmark;
import azgracompress.cli.InputFileInfo;
import azgracompress.cli.ParsedCliOptions; import azgracompress.cli.ParsedCliOptions;
import azgracompress.data.ImageU16; import azgracompress.data.ImageU16;
import azgracompress.data.V3i; import azgracompress.data.V3i;
...@@ -53,18 +54,19 @@ abstract class BenchmarkBase { ...@@ -53,18 +54,19 @@ abstract class BenchmarkBase {
} }
protected BenchmarkBase(final ParsedCliOptions options) { protected BenchmarkBase(final ParsedCliOptions options) {
this.inputFile = options.getInputFile(); final InputFileInfo ifi = options.getInputFileInfo();
this.inputFile = ifi.getFilePath();
this.outputDirectory = options.getOutputFile(); this.outputDirectory = options.getOutputFile();
this.rawImageDims = options.getImageDimension(); this.rawImageDims = ifi.getDimensions();
this.hasReferencePlane = options.hasReferencePlaneIndex(); this.hasReferencePlane = options.hasReferencePlaneIndex();
this.referencePlaneIndex = options.getReferencePlaneIndex(); this.referencePlaneIndex = options.getReferencePlaneIndex();
this.codebookSize = (int) Math.pow(2, options.getBitsPerPixel()); this.codebookSize = (int) Math.pow(2, options.getBitsPerPixel());
if (options.hasPlaneIndexSet()) { if (ifi.isPlaneIndexSet()) {
this.planes = new int[]{options.getPlaneIndex()}; this.planes = new int[]{ifi.getPlaneIndex()};
} else if (options.hasPlaneRangeSet()) { } else if (ifi.isPlaneRangeSet()) {
final int from = options.getFromPlaneIndex(); final int from = ifi.getPlaneRange().getX();
final int to = options.getToPlaneIndex(); final int to = ifi.getPlaneRange().getY();
final int count = to - from; final int count = to - from;
this.planes = new int[count + 1]; this.planes = new int[count + 1];
...@@ -72,7 +74,7 @@ abstract class BenchmarkBase { ...@@ -72,7 +74,7 @@ abstract class BenchmarkBase {
this.planes[i] = from + i; this.planes[i] = from + i;
} }
} else { } else {
final int planeCount = options.getImageDimension().getZ(); final int planeCount = ifi.getDimensions().getZ();
this.planes = new int[planeCount]; this.planes = new int[planeCount];
for (int i = 0; i < planeCount; i++) { for (int i = 0; i < planeCount; i++) {
this.planes[i] = i; this.planes[i] = i;
......
...@@ -30,23 +30,32 @@ public class InputFileInfo { ...@@ -30,23 +30,32 @@ public class InputFileInfo {
this.filePath = filePath; this.filePath = filePath;
} }
public void setDimension(V3i dimension) { /**
this.dimension = dimension; * Get number of selected planes to be compressed.
*
* @return Number of planes for compression.
*/
public int getNumberOfPlanes() {
if (planeIndexSet) {
return 1;
} else if (planeRangeSet) {
return ((planeRange.getY() + 1) - planeRange.getX());
} else {
return dimension.getZ();
} }
public void setPlaneIndexSet(boolean planeIndexSet) {
this.planeIndexSet = planeIndexSet;
} }
public void setPlaneIndex(int planeIndex) { public void setDimension(final V3i dimension) {
this.planeIndex = planeIndex; this.dimension = dimension;
} }
public void setPlaneRangeSet(boolean planeRangeSet) { public void setPlaneIndex(final int planeIndex) {
this.planeRangeSet = planeRangeSet; this.planeIndexSet = true;
this.planeIndex = planeIndex;
} }
public void setPlaneRange(V2i planeRange) { public void setPlaneRange(final V2i planeRange) {
this.planeRangeSet = true;
this.planeRange = planeRange; this.planeRange = planeRange;
} }
...@@ -58,7 +67,7 @@ public class InputFileInfo { ...@@ -58,7 +67,7 @@ public class InputFileInfo {
return filePath; return filePath;
} }
public V3i getDimension() { public V3i getDimensions() {
return dimension; return dimension;
} }
......
...@@ -4,6 +4,7 @@ import azgracompress.compression.CompressorDecompressorBase; ...@@ -4,6 +4,7 @@ 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 org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
...@@ -18,16 +19,14 @@ public class ParsedCliOptions { ...@@ -18,16 +19,14 @@ public class ParsedCliOptions {
private ProgramMethod method; private ProgramMethod method;
private QuantizationType quantizationType; private QuantizationType quantizationType;
private String inputFile; private InputFileInfo inputFileInfo;
private String outputFile; private String outputFile;
private String codebookCacheFolder = null; private String codebookCacheFolder = null;
private int bitsPerPixel; private int bitsPerPixel;
private V2i vectorDimension = new V2i(0); private V2i vectorDimension = new V2i(0);
private V3i imageDimension = new V3i(0);
private boolean planeIndexSet = false;
private int planeIndex;
private boolean refPlaneIndexSet = false; private boolean refPlaneIndexSet = false;
private int referencePlaneIndex = -1; private int referencePlaneIndex = -1;
...@@ -37,10 +36,6 @@ public class ParsedCliOptions { ...@@ -37,10 +36,6 @@ public class ParsedCliOptions {
private boolean errorOccurred; private boolean errorOccurred;
private String error; private String error;
private boolean planeRangeSet = false;
private int fromPlaneIndex;
private int toPlaneIndex;
private int workerCount = 1; private int workerCount = 1;
public ParsedCliOptions(CommandLine cmdInput) { public ParsedCliOptions(CommandLine cmdInput) {
...@@ -116,12 +111,37 @@ public class ParsedCliOptions { ...@@ -116,12 +111,37 @@ public class ParsedCliOptions {
codebookCacheFolder = cmd.getOptionValue(CliConstants.CODEBOOK_CACHE_FOLDER_LONG, null); codebookCacheFolder = cmd.getOptionValue(CliConstants.CODEBOOK_CACHE_FOLDER_LONG, null);
if (!errorOccurred) { if (!errorOccurred) {
outputFile = cmd.getOptionValue(CliConstants.OUTPUT_LONG, getDefaultOutputFilePath(inputFile)); outputFile = cmd.getOptionValue(CliConstants.OUTPUT_LONG,
getDefaultOutputFilePath(inputFileInfo.getFilePath()));
} }
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) {
...@@ -130,31 +150,26 @@ public class ParsedCliOptions { ...@@ -130,31 +150,26 @@ public class ParsedCliOptions {
return; return;
} }
inputFile = inputFileArguments[0]; inputFileInfo = new InputFileInfo(getFileType(inputFileArguments[0]), 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)) {
return; return;
} }
File inputFileInfo = new File(inputFile);
// Check if input file exists. // Check if input file exists.
if (!inputFileInfo.exists()) { if (!new File(inputFileInfo.getFilePath()).exists()) {
errorOccurred = true; errorOccurred = true;
errorBuilder.append("Input file doesn't exist.\n"); errorBuilder.append("Input file doesn't exist.\n");
return; return;
} }
final String extension = FilenameUtils.getExtension(inputFile).toLowerCase(); switch (inputFileInfo.getFileType()) {
switch (extension) { case RAW:
case FileExtensions.RAW: {
parseRawFileArguments(errorBuilder, inputFileArguments); parseRawFileArguments(errorBuilder, inputFileArguments);
}
break; break;
case FileExtensions.TIFF: { case TIFF:
parseTiffFileArguments(errorBuilder, inputFileArguments); parseTiffFileArguments(errorBuilder, inputFileArguments);
}
break; break;
default: { default: {
errorOccurred = true; errorOccurred = true;
...@@ -208,9 +223,7 @@ public class ParsedCliOptions { ...@@ -208,9 +223,7 @@ public class ParsedCliOptions {
final ParseResult<Integer> indexToResult = tryParseInt(toIndexString); final ParseResult<Integer> indexToResult = tryParseInt(toIndexString);
if (indexFromResult.isSuccess() && indexToResult.isSuccess()) { if (indexFromResult.isSuccess() && indexToResult.isSuccess()) {
fromPlaneIndex = indexFromResult.getValue(); inputFileInfo.setPlaneRange(new V2i(indexFromResult.getValue(), indexToResult.getValue()));
toPlaneIndex = indexToResult.getValue();
planeRangeSet = true;
} else { } else {
errorOccurred = true; errorOccurred = true;
errorBuilder.append("Plane range index is wrong. Expected format D-D, got: ").append( errorBuilder.append("Plane range index is wrong. Expected format D-D, got: ").append(
...@@ -220,8 +233,7 @@ public class ParsedCliOptions { ...@@ -220,8 +233,7 @@ public class ParsedCliOptions {
// Here we parse single plane index option. // Here we parse single plane index option.
final ParseResult<Integer> parseResult = tryParseInt(inputFileArguments[inputFileArgumentsOffset]); final ParseResult<Integer> parseResult = tryParseInt(inputFileArguments[inputFileArgumentsOffset]);
if (parseResult.isSuccess()) { if (parseResult.isSuccess()) {
planeIndexSet = true; inputFileInfo.setPlaneIndex(parseResult.getValue());
planeIndex = parseResult.getValue();
} else { } else {
errorOccurred = true; errorOccurred = true;
errorBuilder.append("Failed to parse plane index option, expected integer, got: ") errorBuilder.append("Failed to parse plane index option, expected integer, got: ")
...@@ -254,7 +266,7 @@ public class ParsedCliOptions { ...@@ -254,7 +266,7 @@ public class ParsedCliOptions {
final ParseResult<Integer> n1Result = tryParseInt(num1String); final ParseResult<Integer> n1Result = tryParseInt(num1String);
final ParseResult<Integer> n2Result = tryParseInt(secondPart); final ParseResult<Integer> n2Result = tryParseInt(secondPart);
if (n1Result.isSuccess() && n2Result.isSuccess()) { if (n1Result.isSuccess() && n2Result.isSuccess()) {
imageDimension = new V3i(n1Result.getValue(), n2Result.getValue(), 1); inputFileInfo.setDimension(new V3i(n1Result.getValue(), n2Result.getValue(), 1));
} else { } else {
errorOccurred = true; errorOccurred = true;
errorBuilder.append("Failed to parse image dimensions of format DxD, got: "); errorBuilder.append("Failed to parse image dimensions of format DxD, got: ");
...@@ -269,7 +281,7 @@ public class ParsedCliOptions { ...@@ -269,7 +281,7 @@ public class ParsedCliOptions {
final ParseResult<Integer> n3Result = tryParseInt(num3String); final ParseResult<Integer> n3Result = tryParseInt(num3String);
if (n1Result.isSuccess() && n2Result.isSuccess() && n3Result.isSuccess()) { if (n1Result.isSuccess() && n2Result.isSuccess() && n3Result.isSuccess()) {
imageDimension = new V3i(n1Result.getValue(), n2Result.getValue(), n3Result.getValue()); inputFileInfo.setDimension(new V3i(n1Result.getValue(), n2Result.getValue(), n3Result.getValue()));
} else { } else {
errorOccurred = true; errorOccurred = true;
errorBuilder.append("Failed to parse image dimensions of format DxDxD, got: "); errorBuilder.append("Failed to parse image dimensions of format DxDxD, got: ");
...@@ -410,8 +422,8 @@ public class ParsedCliOptions { ...@@ -410,8 +422,8 @@ public class ParsedCliOptions {
return quantizationType; return quantizationType;
} }
public String getInputFile() { public InputFileInfo getInputFileInfo() {
return inputFile; return inputFileInfo;
} }
public String getOutputFile() { public String getOutputFile() {
...@@ -426,14 +438,6 @@ public class ParsedCliOptions { ...@@ -426,14 +438,6 @@ public class ParsedCliOptions {
return vectorDimension; return vectorDimension;
} }
public V3i getImageDimension() {
return imageDimension;
}
public int getPlaneIndex() {
return planeIndex;
}
public int getReferencePlaneIndex() { public int getReferencePlaneIndex() {
return referencePlaneIndex; return referencePlaneIndex;
} }
...@@ -446,11 +450,7 @@ public class ParsedCliOptions { ...@@ -446,11 +450,7 @@ public class ParsedCliOptions {
return refPlaneIndexSet; return refPlaneIndexSet;
} }
public boolean hasPlaneIndexSet() { public boolean didErrorOccure() {
return planeIndexSet;
}
public boolean hasErrorOccured() {
return errorOccurred; return errorOccurred;
} }
...@@ -458,18 +458,6 @@ public class ParsedCliOptions { ...@@ -458,18 +458,6 @@ public class ParsedCliOptions {
return error; return error;
} }
public boolean hasPlaneRangeSet() {
return planeRangeSet;
}
public int getFromPlaneIndex() {
return fromPlaneIndex;
}
public int getToPlaneIndex() {
return toPlaneIndex;
}
public int getWorkerCount() { public int getWorkerCount() {
return workerCount; return workerCount;
} }
...@@ -520,24 +508,24 @@ public class ParsedCliOptions { ...@@ -520,24 +508,24 @@ public class ParsedCliOptions {
sb.append("BitsPerPixel: ").append(bitsPerPixel).append('\n'); sb.append("BitsPerPixel: ").append(bitsPerPixel).append('\n');
sb.append("Output: ").append(outputFile).append('\n'); sb.append("Output: ").append(outputFile).append('\n');
sb.append("InputFile: ").append(inputFile).append('\n'); sb.append("InputFile: ").append(inputFileInfo.getFilePath()).append('\n');
if (hasCodebookCacheFolder()) { if (hasCodebookCacheFolder()) {
sb.append("CodebookCacheFolder: ").append(codebookCacheFolder).append('\n'); sb.append("CodebookCacheFolder: ").append(codebookCacheFolder).append('\n');
} }
if (hasQuantizationType(method)) { if (hasQuantizationType(method)) {
sb.append("Input image dims: ").append(imageDimension.toString()).append('\n'); sb.append("Input image dims: ").append(inputFileInfo.getDimensions().toString()).append('\n');
} }
if (planeIndexSet) { if (inputFileInfo.isPlaneIndexSet()) {
sb.append("PlaneIndex: ").append(planeIndex).append('\n'); sb.append("PlaneIndex: ").append(inputFileInfo.getPlaneIndex()).append('\n');
} }
if (refPlaneIndexSet) { if (refPlaneIndexSet) {
sb.append("ReferencePlaneIndex: ").append(referencePlaneIndex).append('\n'); sb.append("ReferencePlaneIndex: ").append(referencePlaneIndex).append('\n');
} }
if (planeRangeSet) { if (inputFileInfo.isPlaneRangeSet()) {
sb.append("FromPlaneIndex: ").append(fromPlaneIndex).append('\n'); sb.append("FromPlaneIndex: ").append(inputFileInfo.getPlaneRange().getX()).append('\n');
sb.append("ToPlaneIndex: ").append(toPlaneIndex).append('\n'); sb.append("ToPlaneIndex: ").append(inputFileInfo.getPlaneRange().getY()).append('\n');
} }
sb.append("Verbose: ").append(verbose).append('\n'); sb.append("Verbose: ").append(verbose).append('\n');
...@@ -546,18 +534,5 @@ public class ParsedCliOptions { ...@@ -546,18 +534,5 @@ public class ParsedCliOptions {
return sb.toString(); return sb.toString();
} }
/**
* Get number of planes to be compressed.
*
* @return Number of planes for compression.
*/
public int getNumberOfPlanes() {
if (hasPlaneIndexSet()) {
return 1;
} else if (hasPlaneRangeSet()) {
return ((toPlaneIndex + 1) - fromPlaneIndex);
} else {
return imageDimension.getZ();
}
}
} }
package azgracompress.compression; package azgracompress.compression;
import azgracompress.cli.InputFileInfo;
import azgracompress.cli.ParsedCliOptions; import azgracompress.cli.ParsedCliOptions;
public abstract class CompressorDecompressorBase { public abstract class CompressorDecompressorBase {
...@@ -14,11 +15,12 @@ public abstract class CompressorDecompressorBase { ...@@ -14,11 +15,12 @@ public abstract class CompressorDecompressorBase {
} }
protected int[] getPlaneIndicesForCompression() { protected int[] getPlaneIndicesForCompression() {
if (options.hasPlaneIndexSet()) { final InputFileInfo ifi = options.getInputFileInfo();
return new int[]{options.getPlaneIndex()}; if (ifi.isPlaneIndexSet()) {
} else if (options.hasPlaneRangeSet()) { return new int[]{ifi.getPlaneIndex()};
final int from = options.getFromPlaneIndex(); } else if (ifi.isPlaneRangeSet()) {
final int to = options.getToPlaneIndex(); final int from = ifi.getPlaneRange().getX();
final int to = ifi.getPlaneRange().getY();
final int count = to - from; final int count = to - from;
int[] indices = new int[count + 1]; int[] indices = new int[count + 1];
...@@ -27,7 +29,7 @@ public abstract class CompressorDecompressorBase { ...@@ -27,7 +29,7 @@ public abstract class CompressorDecompressorBase {
} }
return indices; return indices;
} else { } else {
return generateAllPlaneIndices(options.getImageDimension().getZ()); return generateAllPlaneIndices(ifi.getDimensions().getZ());
} }
} }
......
...@@ -106,9 +106,9 @@ public class ImageCompressor extends CompressorDecompressorBase { ...@@ -106,9 +106,9 @@ public class ImageCompressor extends CompressorDecompressorBase {
final boolean oneCodebook = options.hasReferencePlaneIndex() || options.hasCodebookCacheFolder(); final boolean oneCodebook = options.hasReferencePlaneIndex() || options.hasCodebookCacheFolder();
header.setCodebookPerPlane(!oneCodebook); header.setCodebookPerPlane(!oneCodebook);
header.setImageSizeX(options.getImageDimension().getX()); header.setImageSizeX(options.getInputFileInfo().getDimensions().getX());
header.setImageSizeY(options.getImageDimension().getY()); header.setImageSizeY(options.getInputFileInfo().getDimensions().getY());
header.setImageSizeZ(options.getNumberOfPlanes()); header.setImageSizeZ(options.getInputFileInfo().getNumberOfPlanes());
header.setVectorDimension(options.getVectorDimension()); header.setVectorDimension(options.getVectorDimension());
......
...@@ -60,7 +60,7 @@ public class ImageDecompressor extends CompressorDecompressorBase { ...@@ -60,7 +60,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
boolean validFile = true; boolean validFile = true;
QCMPFileHeader header = null; QCMPFileHeader header = null;
try (FileInputStream fileInputStream = new FileInputStream(options.getInputFile()); try (FileInputStream fileInputStream = new FileInputStream(options.getInputFileInfo().getFilePath());
DataInputStream dataInputStream = new DataInputStream(fileInputStream)) { DataInputStream dataInputStream = new DataInputStream(fileInputStream)) {
header = readQCMPFileHeader(dataInputStream); header = readQCMPFileHeader(dataInputStream);
} catch (IOException ioEx) { } catch (IOException ioEx) {
...@@ -108,7 +108,7 @@ public class ImageDecompressor extends CompressorDecompressorBase { ...@@ -108,7 +108,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
logBuilder.append("Vector size Y:\t\t").append(header.getVectorSizeY()).append('\n'); logBuilder.append("Vector size Y:\t\t").append(header.getVectorSizeY()).append('\n');
logBuilder.append("Vector size Z:\t\t").append(header.getVectorSizeZ()).append('\n'); logBuilder.append("Vector size Z:\t\t").append(header.getVectorSizeZ()).append('\n');
final long fileSize = new File(options.getInputFile()).length(); final long fileSize = new File(options.getInputFileInfo().getFilePath()).length();
final long dataSize = fileSize - QCMPFileHeader.QCMP_HEADER_SIZE; final long dataSize = fileSize - QCMPFileHeader.QCMP_HEADER_SIZE;
final IImageDecompressor decompressor = getImageDecompressor(header); final IImageDecompressor decompressor = getImageDecompressor(header);
if (decompressor != null) { if (decompressor != null) {
...@@ -128,7 +128,7 @@ public class ImageDecompressor extends CompressorDecompressorBase { ...@@ -128,7 +128,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
public boolean decompress() { public boolean decompress() {
try (FileInputStream fileInputStream = new FileInputStream(options.getInputFile()); try (FileInputStream fileInputStream = new FileInputStream(options.getInputFileInfo().getFilePath());
DataInputStream dataInputStream = new DataInputStream(fileInputStream)) { DataInputStream dataInputStream = new DataInputStream(fileInputStream)) {
final QCMPFileHeader header = readQCMPFileHeader(dataInputStream); final QCMPFileHeader header = readQCMPFileHeader(dataInputStream);
...@@ -148,7 +148,7 @@ public class ImageDecompressor extends CompressorDecompressorBase { ...@@ -148,7 +148,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
return false; return false;
} }
final long fileSize = new File(options.getInputFile()).length(); final long fileSize = new File(options.getInputFileInfo().getFilePath()).length();
final long dataSize = fileSize - QCMPFileHeader.QCMP_HEADER_SIZE; final long dataSize = fileSize - QCMPFileHeader.QCMP_HEADER_SIZE;
final long expectedDataSize = imageDecompressor.getExpectedDataSize(header); final long expectedDataSize = imageDecompressor.getExpectedDataSize(header);
if (dataSize != expectedDataSize) { if (dataSize != expectedDataSize) {
......
package azgracompress.compression; package azgracompress.compression;
import azgracompress.U16; import azgracompress.U16;
import azgracompress.cli.InputFileInfo;
import azgracompress.cli.ParsedCliOptions; import azgracompress.cli.ParsedCliOptions;
import azgracompress.compression.exception.ImageCompressionException; import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.data.ImageU16; import azgracompress.data.ImageU16;
...@@ -65,7 +66,8 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -65,7 +66,8 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
private ScalarQuantizer loadQuantizerFromCache() throws ImageCompressionException { private ScalarQuantizer loadQuantizerFromCache() throws ImageCompressionException {
QuantizationValueCache cache = new QuantizationValueCache(options.getCodebookCacheFolder()); QuantizationValueCache cache = new QuantizationValueCache(options.getCodebookCacheFolder());
try { try {
final int[] quantizationValues = cache.readCachedValues(options.getInputFile(), codebookSize); final int[] quantizationValues = cache.readCachedValues(options.getInputFileInfo().getFilePath(),
codebookSize);
return new ScalarQuantizer(U16.Min, U16.Max, quantizationValues); return new ScalarQuantizer(U16.Min, U16.Max, quantizationValues);
} catch (IOException e) { } catch (IOException e) {
throw new ImageCompressionException("Failed to read quantization values from cache file.", e); throw new ImageCompressionException("Failed to read quantization values from cache file.", e);
...@@ -79,6 +81,7 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -79,6 +81,7 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
* @throws ImageCompressionException When compress process fails. * @throws ImageCompressionException When compress process fails.
*/ */
public void compress(DataOutputStream compressStream) throws ImageCompressionException { public void compress(DataOutputStream compressStream) throws ImageCompressionException {
final InputFileInfo inputFileInfo = options.getInputFileInfo();
Stopwatch stopwatch = new Stopwatch(); Stopwatch stopwatch = new Stopwatch();
final boolean hasGeneralQuantizer = options.hasCodebookCacheFolder() || options.hasReferencePlaneIndex(); final boolean hasGeneralQuantizer = options.hasCodebookCacheFolder() || options.hasReferencePlaneIndex();
...@@ -93,8 +96,8 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -93,8 +96,8 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
stopwatch.restart(); stopwatch.restart();
ImageU16 referencePlane = null; ImageU16 referencePlane = null;
try { try {
referencePlane = RawDataIO.loadImageU16(options.getInputFile(), referencePlane = RawDataIO.loadImageU16(inputFileInfo.getFilePath(),
options.getImageDimension(), inputFileInfo.getDimensions(),
options.getReferencePlaneIndex()); options.getReferencePlaneIndex());
} catch (Exception ex) { } catch (Exception ex) {
throw new ImageCompressionException("Unable to load reference plane data.", ex); throw new ImageCompressionException("Unable to load reference plane data.", ex);
...@@ -118,8 +121,8 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -118,8 +121,8 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
ImageU16 plane = null; ImageU16 plane = null;
try { try {
plane = RawDataIO.loadImageU16(options.getInputFile(), plane = RawDataIO.loadImageU16(inputFileInfo.getFilePath(),
options.getImageDimension(), inputFileInfo.getDimensions(),
planeIndex); planeIndex);
} catch (Exception ex) { } catch (Exception ex) {
throw new ImageCompressionException("Unable to load plane data.", ex); throw new ImageCompressionException("Unable to load plane data.", ex);
...@@ -148,21 +151,22 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -148,21 +151,22 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
} }
private int[] loadConfiguredPlanesData() throws ImageCompressionException { private int[] loadConfiguredPlanesData() throws ImageCompressionException {
final InputFileInfo inputFileInfo = options.getInputFileInfo();
int[] trainData = null; int[] trainData = null;
if (options.hasPlaneIndexSet()) { if (inputFileInfo.isPlaneIndexSet()) {
try { try {
Log("Loading single plane data."); Log("Loading single plane data.");
trainData = RawDataIO.loadImageU16(options.getInputFile(), trainData = RawDataIO.loadImageU16(inputFileInfo.getFilePath(),
options.getImageDimension(), inputFileInfo.getDimensions(),
options.getPlaneIndex()).getData(); inputFileInfo.getPlaneIndex()).getData();
} catch (IOException e) { } catch (IOException e) {
throw new ImageCompressionException("Failed to load reference image data.", e); throw new ImageCompressionException("Failed to load reference image data.", e);
} }
} else if (options.hasPlaneRangeSet()) { } else if (inputFileInfo.isPlaneRangeSet()) {
Log("Loading plane range data."); Log("Loading plane range data.");
final int[] planes = getPlaneIndicesForCompression(); final int[] planes = getPlaneIndicesForCompression();
try { try {
trainData = RawDataIO.loadPlanesData(options.getInputFile(), options.getImageDimension(), planes); trainData = RawDataIO.loadPlanesData(inputFileInfo.getFilePath(), inputFileInfo.getDimensions(), planes);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new ImageCompressionException("Failed to load plane range data.", e); throw new ImageCompressionException("Failed to load plane range data.", e);
...@@ -170,7 +174,7 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -170,7 +174,7 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
} else { } else {
Log("Loading all planes data."); Log("Loading all planes data.");
try { try {
trainData = RawDataIO.loadAllPlanesData(options.getInputFile(), options.getImageDimension()); trainData = RawDataIO.loadAllPlanesData(inputFileInfo.getFilePath(), inputFileInfo.getDimensions());
} catch (IOException e) { } catch (IOException e) {
throw new ImageCompressionException("Failed to load all planes data.", e); throw new ImageCompressionException("Failed to load all planes data.", e);
} }
...@@ -196,7 +200,7 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -196,7 +200,7 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
Log(String.format("Saving cache file to %s", options.getOutputFile())); Log(String.format("Saving cache file to %s", options.getOutputFile()));
QuantizationValueCache cache = new QuantizationValueCache(options.getOutputFile()); QuantizationValueCache cache = new QuantizationValueCache(options.getOutputFile());
try { try {
cache.saveQuantizationValues(options.getInputFile(), qValues); cache.saveQuantizationValues(options.getInputFileInfo().getFilePath(), qValues);
} catch (IOException e) { } catch (IOException e) {
throw new ImageCompressionException("Unable to write cache.", e); throw new ImageCompressionException("Unable to write cache.", e);
} }
......
package azgracompress.compression; package azgracompress.compression;
import azgracompress.cli.InputFileInfo;
import azgracompress.cli.ParsedCliOptions; import azgracompress.cli.ParsedCliOptions;
import azgracompress.compression.exception.ImageCompressionException; import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.data.Chunk2D; import azgracompress.data.Chunk2D;
...@@ -68,7 +69,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -68,7 +69,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
private VectorQuantizer loadQuantizerFromCache() throws ImageCompressionException { private VectorQuantizer loadQuantizerFromCache() throws ImageCompressionException {
QuantizationValueCache cache = new QuantizationValueCache(options.getCodebookCacheFolder()); QuantizationValueCache cache = new QuantizationValueCache(options.getCodebookCacheFolder());
try { try {
final CodebookEntry[] codebook = cache.readCachedValues(options.getInputFile(), final CodebookEntry[] codebook = cache.readCachedValues(options.getInputFileInfo().getFilePath(),
codebookSize, codebookSize,
options.getVectorDimension().getX(), options.getVectorDimension().getX(),
options.getVectorDimension().getY()); options.getVectorDimension().getY());
...@@ -86,6 +87,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -86,6 +87,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* @throws ImageCompressionException When compress process fails. * @throws ImageCompressionException When compress process fails.
*/ */
public void compress(DataOutputStream compressStream) throws ImageCompressionException { public void compress(DataOutputStream compressStream) throws ImageCompressionException {
final InputFileInfo inputFileInfo = options.getInputFileInfo();
Stopwatch stopwatch = new Stopwatch(); Stopwatch stopwatch = new Stopwatch();
final boolean hasGeneralQuantizer = options.hasCodebookCacheFolder() || options.hasReferencePlaneIndex(); final boolean hasGeneralQuantizer = options.hasCodebookCacheFolder() || options.hasReferencePlaneIndex();
VectorQuantizer quantizer = null; VectorQuantizer quantizer = null;
...@@ -100,8 +102,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -100,8 +102,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
ImageU16 referencePlane = null; ImageU16 referencePlane = null;
try { try {
referencePlane = RawDataIO.loadImageU16(options.getInputFile(), referencePlane = RawDataIO.loadImageU16(inputFileInfo.getFilePath(),
options.getImageDimension(), inputFileInfo.getDimensions(),
options.getReferencePlaneIndex()); options.getReferencePlaneIndex());
} catch (Exception ex) { } catch (Exception ex) {
throw new ImageCompressionException("Unable to load reference plane data.", ex); throw new ImageCompressionException("Unable to load reference plane data.", ex);
...@@ -123,8 +125,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -123,8 +125,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
ImageU16 plane = null; ImageU16 plane = null;
try { try {
plane = RawDataIO.loadImageU16(options.getInputFile(), plane = RawDataIO.loadImageU16(inputFileInfo.getFilePath(),
options.getImageDimension(), inputFileInfo.getDimensions(),
planeIndex); planeIndex);
} catch (Exception ex) { } catch (Exception ex) {
throw new ImageCompressionException("Unable to load plane data.", ex); throw new ImageCompressionException("Unable to load plane data.", ex);
...@@ -164,8 +166,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -164,8 +166,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* @throws IOException When reading fails. * @throws IOException When reading fails.
*/ */
private int[][] loadPlaneQuantizationVectors(final int planeIndex) throws IOException { private int[][] loadPlaneQuantizationVectors(final int planeIndex) throws IOException {
ImageU16 refPlane = RawDataIO.loadImageU16(options.getInputFile(), ImageU16 refPlane = RawDataIO.loadImageU16(options.getInputFileInfo().getFilePath(),
options.getImageDimension(), options.getInputFileInfo().getDimensions(),
planeIndex); planeIndex);
return refPlane.toQuantizationVectors(options.getVectorDimension()); return refPlane.toQuantizationVectors(options.getVectorDimension());
...@@ -173,22 +175,23 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -173,22 +175,23 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
private int[][] loadConfiguredPlanesData() throws ImageCompressionException { private int[][] loadConfiguredPlanesData() throws ImageCompressionException {
final int vectorSize = options.getVectorDimension().getX() * options.getVectorDimension().getY(); final int vectorSize = options.getVectorDimension().getX() * options.getVectorDimension().getY();
final InputFileInfo ifi = options.getInputFileInfo();
int[][] trainData = null; int[][] trainData = null;
Stopwatch s = new Stopwatch(); Stopwatch s = new Stopwatch();
s.start(); s.start();
if (options.hasPlaneIndexSet()) { if (ifi.isPlaneIndexSet()) {
Log("VQ: Loading single plane data."); Log("VQ: Loading single plane data.");
try { try {
trainData = loadPlaneQuantizationVectors(options.getPlaneIndex()); trainData = loadPlaneQuantizationVectors(ifi.getPlaneIndex());
} catch (IOException e) { } catch (IOException e) {
throw new ImageCompressionException("Failed to load reference image data.", e); throw new ImageCompressionException("Failed to load reference image data.", e);
} }
} else { } else {
Log(options.hasPlaneRangeSet() ? "VQ: Loading plane range data." : "VQ: Loading all planes data."); Log(ifi.isPlaneRangeSet() ? "VQ: Loading plane range data." : "VQ: Loading all planes data.");
final int[] planeIndices = getPlaneIndicesForCompression(); final int[] planeIndices = getPlaneIndicesForCompression();
final int chunkCountPerPlane = Chunk2D.calculateRequiredChunkCountPerPlane( final int chunkCountPerPlane = Chunk2D.calculateRequiredChunkCountPerPlane(
options.getImageDimension().toV2i(), ifi.getDimensions().toV2i(),
options.getVectorDimension()); options.getVectorDimension());
final int totalChunkCount = chunkCountPerPlane * planeIndices.length; final int totalChunkCount = chunkCountPerPlane * planeIndices.length;
...@@ -227,7 +230,9 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -227,7 +230,9 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
Log("Saving cache file to %s", options.getOutputFile()); Log("Saving cache file to %s", options.getOutputFile());
QuantizationValueCache cache = new QuantizationValueCache(options.getOutputFile()); QuantizationValueCache cache = new QuantizationValueCache(options.getOutputFile());
try { try {
cache.saveQuantizationValues(options.getInputFile(), lbgResult.getCodebook(), options.getVectorDimension()); cache.saveQuantizationValues(options.getInputFileInfo().getFilePath(),
lbgResult.getCodebook(),
options.getVectorDimension());
} catch (IOException e) { } catch (IOException e) {
throw new ImageCompressionException("Unable to write cache.", e); throw new ImageCompressionException("Unable to write cache.", e);
} }
......
...@@ -13,9 +13,7 @@ public class V2i { ...@@ -13,9 +13,7 @@ public class V2i {
this(universalValue, universalValue); this(universalValue, universalValue);
} }
public int getX() { public int getX() { return x; }
return x;
}
public int getY() { public int getY() {
return y; return y;
......
...@@ -3,5 +3,6 @@ package azgracompress.fileformat; ...@@ -3,5 +3,6 @@ package azgracompress.fileformat;
public enum FileType { public enum FileType {
RAW, RAW,
TIFF, TIFF,
QCMP QCMP,
Unsupported
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment