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

Added logging to simple compress/decompress.

parent 4888aa07
No related branches found
No related tags found
No related merge requests found
......@@ -95,10 +95,6 @@ public class DataCompressor {
false,
"Inspect the compressed file"));
methodGroup.addOption(new Option(CliConstants.HELP_SHORT, CliConstants.HELP_LONG, false, "Print help"));
methodGroup.addOption(new Option(CliConstants.VERBOSE_SHORT,
CliConstants.VERBOSE_LONG,
false,
"Make program verbose"));
OptionGroup compressionMethodGroup = new OptionGroup();
compressionMethodGroup.addOption(new Option(CliConstants.SCALAR_QUANTIZATION_SHORT,
......@@ -118,6 +114,10 @@ public class DataCompressor {
CliConstants.REFERENCE_PLANE_LONG,
true,
"Reference plane index");
options.addOption(new Option(CliConstants.VERBOSE_SHORT,
CliConstants.VERBOSE_LONG,
false,
"Make program verbose"));
// options.addRequiredOption(INPUT_SHORT, INPUT_LONG, true, "Input file");
options.addOption(CliConstants.OUTPUT_SHORT, CliConstants.OUTPUT_LONG, true, "Custom output file");
return options;
......
......@@ -26,4 +26,16 @@ public class CompressorDecompressorBase {
}
return planeIndices;
}
protected void Log(final String message) {
if (options.isVerbose()) {
System.out.println(message);
}
}
protected void LogError(final String message) {
if (options.isVerbose()) {
System.err.println(message);
}
}
}
......@@ -83,7 +83,7 @@ public class ImageCompressor extends CompressorDecompressorBase {
private ScalarQuantizer getScalarQuantizerFromPlane(final ImageU16 plane) {
LloydMaxU16ScalarQuantization lloydMax = new LloydMaxU16ScalarQuantization(plane.getData(), codebookSize);
lloydMax.train(options.isVerbose());
lloydMax.train(false);
return new ScalarQuantizer(U16.Min, U16.Max, lloydMax.getCentroids());
}
......@@ -93,28 +93,36 @@ public class ImageCompressor extends CompressorDecompressorBase {
final ImageU16 referencePlane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(),
options.getReferencePlaneIndex());
Log("Creating codebook from reference plane...");
quantizer = getScalarQuantizerFromPlane(referencePlane);
writeCodebookToOutputStream(quantizer, outputStream);
Log("Wrote reference codebook.");
}
final int[] planeIndices = getPlaneIndicesForCompression();
for (final int planeIndex : planeIndices) {
Log(String.format("Loading plane %d...", planeIndex));
final ImageU16 plane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(),
planeIndex);
if (!options.hasReferencePlaneIndex()) {
Log("Creating plane codebook...");
quantizer = getScalarQuantizerFromPlane(plane);
writeCodebookToOutputStream(quantizer, outputStream);
Log("Wrote plane codebook.");
}
assert (quantizer != null);
final int[] indices = quantizer.quantizeIntoIndices(plane.getData());
Log("Writing quantization indices...");
final int[] indices = quantizer.quantizeIntoIndices(plane.getData());
OutBitStream outBitStream = new OutBitStream(outputStream, options.getBitsPerPixel(), 2048);
outBitStream.write(indices);
outBitStream.flush();
Log(String.format("Finished processing of plane %d", planeIndex));
}
}
}
......@@ -194,16 +194,19 @@ public class ImageDecompressor extends CompressorDecompressorBase {
int[] quantizationValues = null;
if (!header.isCodebookPerPlane()) {
// There is only one codebook.
Log("Loading reference codebook...");
quantizationValues = readQuantizationValues(compressedStream, codebookSize);
}
for (int planeIndex = 0; planeIndex < planeCountForDecompression; planeIndex++) {
if (header.isCodebookPerPlane()) {
Log("Loading plane codebook...");
quantizationValues = readQuantizationValues(compressedStream, codebookSize);
}
assert (quantizationValues != null);
Log(String.format("Decompressing plane %d...", planeIndex));
InBitStream inBitStream = new InBitStream(compressedStream, header.getBitsPerPixel(), planeIndicesDataSize);
inBitStream.readToBuffer();
inBitStream.setAllowReadFromUnderlyingStream(false);
......@@ -216,6 +219,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
final byte[] decompressedPlaneData = TypeConverter.shortArrayToByteArray(decompressedValues, false);
decompressStream.write(decompressedPlaneData);
Log(String.format("Decompressed plane %d.", planeIndex));
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment