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

Formatting and fixes.

Some code formatting. Redirect compression of voxels to its separate
function
parent 20e16248
Branches
Tags
No related merge requests found
package azgracompress.compression;
import azgracompress.cache.QuantizationCacheManager;
import azgracompress.fileformat.QuantizationType;
import azgracompress.io.InputData;
import azgracompress.compression.exception.ImageCompressionException;
import azgracompress.data.Chunk2D;
......@@ -98,6 +99,11 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* @throws ImageCompressionException When compress process fails.
*/
public long[] compress(DataOutputStream compressStream) throws ImageCompressionException {
if (options.getQuantizationType() == QuantizationType.Vector3D) {
return compressVoxels(compressStream);
}
assert (options.getQuantizationVector().getZ() == 1);
final InputData inputDataInfo = options.getInputDataInfo();
Stopwatch stopwatch = new Stopwatch();
final boolean hasGeneralQuantizer = options.getCodebookType() != CompressionOptions.CodebookType.Individual;
......@@ -130,7 +136,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
}
reportStatusToListeners(String.format("Training vector quantizer from middle plane %d.", middlePlaneIndex));
final int[][] refPlaneVectors = middlePlane.toQuantizationVectors(options.getQuantizationVector());
final int[][] refPlaneVectors = middlePlane.toQuantizationVectors(options.getQuantizationVector().toV2i());
quantizer = trainVectorQuantizerFromPlaneVectors(refPlaneVectors);
huffman = createHuffmanCoder(huffmanSymbols, quantizer.getFrequencies());
writeQuantizerToCompressStream(quantizer, compressStream);
......@@ -148,13 +154,12 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
ImageU16 plane = null;
try {
plane = planeLoader.loadPlaneU16(planeIndex);
} catch (IOException ex) {
throw new ImageCompressionException("Unable to load plane data.", ex);
}
final int[][] planeVectors = plane.toQuantizationVectors(options.getQuantizationVector());
final int[][] planeVectors = plane.toQuantizationVectors(options.getQuantizationVector().toV2i());
if (!hasGeneralQuantizer) {
reportStatusToListeners(String.format("Training vector quantizer from plane %d.", planeIndex));
......@@ -188,7 +193,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
private int[][] loadPlaneQuantizationVectors(final IPlaneLoader planeLoader,
final int planeIndex) throws IOException {
ImageU16 refPlane = planeLoader.loadPlaneU16(planeIndex);
return refPlane.toQuantizationVectors(options.getQuantizationVector());
return refPlane.toQuantizationVectors(options.getQuantizationVector().toV2i());
}
private int[][] loadConfiguredPlanesData() throws ImageCompressionException {
......@@ -200,13 +205,12 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
} catch (Exception e) {
throw new ImageCompressionException("Unable to create SCIFIO reader. " + e.getMessage());
}
int[][] trainData = null;
int[][] trainData;
Stopwatch s = new Stopwatch();
s.start();
if (inputDataInfo.isPlaneIndexSet()) {
reportStatusToListeners("VQ: Loading single plane data.");
try {
trainData = loadPlaneQuantizationVectors(planeLoader, inputDataInfo.getPlaneIndex());
} catch (IOException e) {
throw new ImageCompressionException("Failed to load plane data.", e);
......@@ -215,9 +219,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
reportStatusToListeners(inputDataInfo.isPlaneRangeSet() ? "VQ: Loading plane range data." : "VQ: Loading all planes data.");
final int[] planeIndices = getPlaneIndicesForCompression();
final int chunkCountPerPlane = Chunk2D.calculateRequiredChunkCount(
inputDataInfo.getDimensions().toV2i(),
options.getQuantizationVector());
final int chunkCountPerPlane = Chunk2D.calculateRequiredChunkCount(inputDataInfo.getDimensions().toV2i(),
options.getQuantizationVector().toV2i());
final int totalChunkCount = chunkCountPerPlane * planeIndices.length;
trainData = new int[totalChunkCount][vectorSize];
......@@ -270,5 +273,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
reportStatusToListeners("Operation completed.");
}
public long[] compressVoxels(DataOutputStream compressStream) throws ImageCompressionException {
}
}
......@@ -3,10 +3,12 @@ package azgracompress.io.loader;
import azgracompress.data.ImageU16;
import azgracompress.data.V3i;
import azgracompress.io.FileInputData;
import azgracompress.io.InputData;
import azgracompress.utilities.TypeConverter;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
public class RawDataLoader implements IPlaneLoader {
......
......@@ -3,13 +3,11 @@ package azgracompress.quantization.vector;
public class VectorQuantizer {
private final VectorDistanceMetric metric = VectorDistanceMetric.Euclidean;
private final VQCodebook codebook;
private final CodebookEntry[] codebookVectors;
private final int vectorSize;
private final long[] frequencies;
public VectorQuantizer(final VQCodebook codebook) {
this.codebook = codebook;
this.codebookVectors = codebook.getVectors();
vectorSize = codebookVectors[0].getVector().length;
this.frequencies = codebook.getVectorFrequencies();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment