diff --git a/src/main/java/azgracompress/compression/VQImageCompressor.java b/src/main/java/azgracompress/compression/VQImageCompressor.java index e1da06671feef320095861a70fe840c0994ef093..4f6db44bc6cf5eceb31be14bd882b686174e1e2c 100644 --- a/src/main/java/azgracompress/compression/VQImageCompressor.java +++ b/src/main/java/azgracompress/compression/VQImageCompressor.java @@ -24,7 +24,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm private VectorQuantizer cachedQuantizer = null; private Huffman cachedHuffman = null; - public VQImageCompressor(CompressionOptions options) { + public VQImageCompressor(final CompressionOptions options) { super(options); } @@ -43,11 +43,11 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm */ private VectorQuantizer trainVectorQuantizerFromPlaneVectors(final int[][] planeVectors) { - LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(planeVectors, - getCodebookSize(), - options.getWorkerCount(), - options.getQuantizationVector()); - LBGResult vqResult = vqInitializer.findOptimalCodebook(); + final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(planeVectors, + getCodebookSize(), + options.getWorkerCount(), + options.getQuantizationVector()); + final LBGResult vqResult = vqInitializer.findOptimalCodebook(); return new VectorQuantizer(vqResult.getCodebook()); } @@ -59,7 +59,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm * @throws ImageCompressionException When unable to write quantizer. */ private void writeQuantizerToCompressStream(final VectorQuantizer quantizer, - DataOutputStream compressStream) throws ImageCompressionException { + final DataOutputStream compressStream) throws ImageCompressionException { final int[][] codebook = quantizer.getCodebookVectors(); try { for (final int[] entry : codebook) { @@ -71,7 +71,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm for (final long symbolFrequency : frequencies) { compressStream.writeLong(symbolFrequency); } - } catch (IOException ioEx) { + } catch (final IOException ioEx) { throw new ImageCompressionException("Unable to write codebook to compress stream.", ioEx); } if (options.isVerbose()) { @@ -86,7 +86,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm * @throws ImageCompressionException when fails to read cached codebook. */ private VectorQuantizer loadQuantizerFromCache() throws ImageCompressionException { - QuantizationCacheManager cacheManager = new QuantizationCacheManager(options.getCodebookCacheFolder()); + final QuantizationCacheManager cacheManager = new QuantizationCacheManager(options.getCodebookCacheFolder()); if (!cacheManager.doesVQCacheExists(options.getInputDataInfo().getCacheFileName(), getCodebookSize(), @@ -112,7 +112,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm * @throws ImageCompressionException When compress process fails. */ @Override - public long[] compress(DataOutputStream compressStream) throws ImageCompressionException { + public long[] compress(final DataOutputStream compressStream) throws ImageCompressionException { if (options.getQuantizationType() == QuantizationType.Vector3D) { return compressVoxels(compressStream, false, options.getInputDataInfo()); } @@ -121,7 +121,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm } @Override - public long[] compressStreamChunk(DataOutputStream compressStream, final InputData inputData) throws ImageCompressionException { + public long[] compressStreamChunk(final DataOutputStream compressStream, final InputData inputData) throws ImageCompressionException { if (options.getQuantizationType() == QuantizationType.Vector3D) { return compressVoxels(compressStream, true, inputData); } @@ -134,13 +134,13 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm final boolean streamMode, final InputData inputData) throws ImageCompressionException { - Stopwatch stopwatch = new Stopwatch(); + final Stopwatch stopwatch = new Stopwatch(); final boolean hasGeneralQuantizer = options.getCodebookType() != CompressionOptions.CodebookType.Individual; final IPlaneLoader planeLoader; final int[] huffmanSymbols = createHuffmanSymbols(getCodebookSize()); try { planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(inputData); - } catch (Exception e) { + } catch (final Exception e) { throw new ImageCompressionException("Unable to create plane reader. " + e.getMessage()); } @@ -177,11 +177,11 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm // Write voxel layer in stream mode. compressStream.writeShort(planeIndices.length); - } catch (IOException e) { + } catch (final IOException e) { throw new ImageCompressionException("Failed to write short value to compression stream.", e); } } - long[] planeDataSizes = new long[planeIndices.length]; + final long[] planeDataSizes = new long[planeIndices.length]; int planeCounter = 0; for (final int planeIndex : planeIndices) { @@ -224,11 +224,11 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm final IPlaneLoader planeLoader; try { planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(options.getInputDataInfo()); - } catch (Exception e) { + } catch (final Exception e) { throw new ImageCompressionException("Unable to create plane reader. " + e.getMessage()); } - int[][] trainingData; + final int[][] trainingData; if (options.getInputDataInfo().isPlaneIndexSet()) { reportStatusToListeners("VQ: Loading single plane data."); final int planeIndex = options.getInputDataInfo().getPlaneIndex(); @@ -243,22 +243,22 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm } - LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(trainingData, - getCodebookSize(), - options.getWorkerCount(), - options.getQuantizationVector()); + final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(trainingData, + getCodebookSize(), + options.getWorkerCount(), + options.getQuantizationVector()); reportStatusToListeners("Starting LBG optimization."); vqInitializer.setStatusListener(this::reportStatusToListeners); - LBGResult lbgResult = vqInitializer.findOptimalCodebook(); + final LBGResult lbgResult = vqInitializer.findOptimalCodebook(); reportStatusToListeners("Learned the optimal codebook."); - QuantizationCacheManager cacheManager = new QuantizationCacheManager(options.getCodebookCacheFolder()); + final QuantizationCacheManager cacheManager = new QuantizationCacheManager(options.getCodebookCacheFolder()); try { final String cacheFilePath = cacheManager.saveCodebook(options.getInputDataInfo().getCacheFileName(), lbgResult.getCodebook()); reportStatusToListeners("Saved cache file to %s", cacheFilePath); - } catch (IOException e) { + } catch (final IOException e) { throw new ImageCompressionException("Unable to write VQ cache.", e); } reportStatusToListeners("Operation completed."); @@ -284,7 +284,7 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm try { planeLoader = PlaneLoaderFactory.getPlaneLoaderForInputFile(inputData); planeLoader.setWorkerCount(options.getWorkerCount()); - } catch (Exception e) { + } catch (final Exception e) { throw new ImageCompressionException("Unable to create plane reader. " + e.getMessage()); } @@ -299,11 +299,11 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm // Write voxel layer in stream mode. compressStream.writeShort(voxelLayerCount); - } catch (IOException e) { + } catch (final IOException e) { throw new ImageCompressionException("Failed to write short value to compression stream.", e); } } - long[] voxelLayersSizes = new long[voxelLayerCount]; + final long[] voxelLayersSizes = new long[voxelLayerCount]; final VectorQuantizer quantizer = (cachedQuantizer != null) ? cachedQuantizer : loadQuantizerFromCache(); final Huffman huffman = (cachedHuffman != null) ? cachedHuffman : createHuffmanCoder(huffmanSymbols, quantizer.getFrequencies()); @@ -311,15 +311,11 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm writeQuantizerToCompressStream(quantizer, compressStream); int[][] voxelData; - Stopwatch stopwatch = new Stopwatch(); + final Stopwatch stopwatch = new Stopwatch(); for (int voxelLayerIndex = 0; voxelLayerIndex < voxelLayerCount; voxelLayerIndex++) { stopwatch.restart(); final int fromZ = (voxelLayerIndex * voxelLayerDepth); - // TODO(Moravec): There is a problem! - // If dataset.Z is not divisible by voxel.Z we end up creating a lot stupid voxels. - // Those stupid voxels have only one or two layers of actual data and the rest are zeros. - // This ends up increasing the file size because they have quite long Huffman codes. final int toZ = (voxelLayerIndex == voxelLayerCount - 1) ? inputData.getDimensions().getZ() : (voxelLayerDepth + (voxelLayerIndex * voxelLayerDepth)); @@ -329,11 +325,12 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm try { voxelData = planeLoader.loadVoxels(options.getQuantizationVector(), voxelLayerRange); - } catch (IOException e) { + } catch (final IOException e) { throw new ImageCompressionException("Unable to load voxels from voxel layer " + voxelLayerRange, e); } final int[] indices = quantizer.quantizeIntoIndices(voxelData, options.getWorkerCount()); +// final int[] indices = quantizer.quantizeIntoIndicesUsingKDTree(voxelData, options.getWorkerCount()); voxelLayersSizes[voxelLayerIndex] = writeHuffmanEncodedIndices(compressStream, huffman, indices); stopwatch.stop(); if (options.isConsoleApplication()) { diff --git a/src/main/java/azgracompress/compression/VQImageDecompressor.java b/src/main/java/azgracompress/compression/VQImageDecompressor.java index d7a9c4577648a506ba470b6e74d07cae08c1c774..9a2e086e788ee116340e3579e9d826bcd152b35c 100644 --- a/src/main/java/azgracompress/compression/VQImageDecompressor.java +++ b/src/main/java/azgracompress/compression/VQImageDecompressor.java @@ -32,7 +32,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I final int planeOffset) throws ImageDecompressionException; } - public VQImageDecompressor(CompressionOptions options) { + public VQImageDecompressor(final CompressionOptions options) { super(options); } @@ -43,7 +43,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I return (vectorXCount * vectorYCount); } - private VQCodebook readCodebook(DataInputStream compressedStream, + private VQCodebook readCodebook(final DataInputStream compressedStream, final int codebookSize, final int vectorSize) throws ImageDecompressionException { @@ -59,7 +59,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I for (int codebookIndex = 0; codebookIndex < codebookSize; codebookIndex++) { frequencies[codebookIndex] = compressedStream.readLong(); } - } catch (IOException ioEx) { + } catch (final IOException ioEx) { throw new ImageDecompressionException("Unable to read quantization values from compressed stream.", ioEx); } @@ -70,7 +70,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I @Override public void preloadGlobalCodebook(final ICacheFile codebookCacheFile) { assert (codebookCacheFile instanceof VQCacheFile) : "Incorrect codebook cache file type for VQImageDecompressor"; - VQCacheFile codebookCache = (VQCacheFile) codebookCacheFile; + final VQCacheFile codebookCache = (VQCacheFile) codebookCacheFile; cachedCodebook = codebookCache.getCodebook(); cachedHuffman = createHuffmanCoder(createHuffmanSymbols(cachedCodebook.getCodebookSize()), cachedCodebook.getVectorFrequencies()); @@ -81,7 +81,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I final V2i qVector, final V3i imageDims) { - Block reconstructedChunk = new Block(new V2i(imageDims.getX(), imageDims.getY())); + final Block reconstructedChunk = new Block(new V2i(imageDims.getX(), imageDims.getY())); if (qVector.getY() > 1) { reconstructedChunk.reconstructFrom2DVectors(vectors, qVector); } else { @@ -92,7 +92,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I } @Override - public long getExpectedDataSize(QCMPFileHeader header) { + public long getExpectedDataSize(final QCMPFileHeader header) { // Vector count in codebook final int codebookSize = (int) Math.pow(2, header.getBitsPerCodebookIndex()); @@ -104,7 +104,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I (header.isCodebookPerPlane() ? header.getImageSizeZ() : 1); // Indices are encoded using huffman. Plane data size is written in the header. - long[] planeDataSizes = header.getPlaneDataSizes(); + final long[] planeDataSizes = header.getPlaneDataSizes(); long totalPlaneDataSize = 0; for (final long planeDataSize : planeDataSizes) { totalPlaneDataSize += planeDataSize; @@ -113,9 +113,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I } @Override - public void decompress(DataInputStream compressedStream, - DataOutputStream decompressStream, - QCMPFileHeader header) throws ImageDecompressionException { + public void decompress(final DataInputStream compressedStream, + final DataOutputStream decompressStream, + final QCMPFileHeader header) throws ImageDecompressionException { if (header.getQuantizationType() == QuantizationType.Vector3D) { decompressVoxels(compressedStream, decompressStream, header); return; @@ -124,15 +124,15 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I decompressImpl(compressedStream, header, (imageBlock, planeIndex) -> { try { decompressStream.write(TypeConverter.unsignedShortArrayToByteArray(imageBlock.getData(), false)); - } catch (IOException e) { + } catch (final IOException e) { throw new ImageDecompressionException("Unable to write decompressed data to decompress stream.", e); } }); } - public void decompressImpl(DataInputStream compressedStream, - QCMPFileHeader header, - DecompressCallback callback) throws ImageDecompressionException { + public void decompressImpl(final DataInputStream compressedStream, + final QCMPFileHeader header, + final DecompressCallback callback) throws ImageDecompressionException { final int codebookSize = (int) Math.pow(2, header.getBitsPerCodebookIndex()); assert (header.getVectorSizeZ() == 1); final int vectorSize = header.getVectorSizeX() * header.getVectorSizeY() * header.getVectorSizeZ(); @@ -159,13 +159,13 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I final int planeDataSize = (int) header.getPlaneDataSizes()[planeIndex]; - try (InBitStream inBitStream = new InBitStream(compressedStream, - header.getBitsPerCodebookIndex(), - planeDataSize)) { + try (final InBitStream inBitStream = new InBitStream(compressedStream, + header.getBitsPerCodebookIndex(), + planeDataSize)) { inBitStream.readToBuffer(); inBitStream.setAllowReadFromUnderlyingStream(false); - int[][] decompressedVectors = new int[(int) planeVectorCount][vectorSize]; + final int[][] decompressedVectors = new int[(int) planeVectorCount][vectorSize]; for (int vecIndex = 0; vecIndex < planeVectorCount; vecIndex++) { HuffmanNode currentHuffmanNode = huffman.getRoot(); boolean bit; @@ -183,7 +183,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I header.getImageDims()); callback.process(decompressedPlane, planeIndex); - } catch (Exception ex) { + } catch (final Exception ex) { throw new ImageDecompressionException("VQImageDecompressor::decompressToBuffer() - Unable to read indices from " + "InBitStream.", ex); @@ -194,9 +194,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I } @SuppressWarnings("DuplicatedCode") - public void decompressStreamModelImpl(DataInputStream compressedStream, - QCMPFileHeader header, - DecompressCallback callback) throws ImageDecompressionException { + public void decompressStreamModelImpl(final DataInputStream compressedStream, + final QCMPFileHeader header, + final DecompressCallback callback) throws ImageDecompressionException { assert (cachedCodebook != null && cachedHuffman != null); assert (header.getVectorSizeZ() == 1); @@ -209,13 +209,13 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I for (int planeIndex = 0; planeIndex < planeCountForDecompression; planeIndex++) { final int planeDataSize = (int) header.getPlaneDataSizes()[planeIndex]; - try (InBitStream inBitStream = new InBitStream(compressedStream, - header.getBitsPerCodebookIndex(), - planeDataSize)) { + try (final InBitStream inBitStream = new InBitStream(compressedStream, + header.getBitsPerCodebookIndex(), + planeDataSize)) { inBitStream.readToBuffer(); inBitStream.setAllowReadFromUnderlyingStream(false); - int[][] decompressedVectors = new int[(int) planeVectorCount][vectorSize]; + final int[][] decompressedVectors = new int[(int) planeVectorCount][vectorSize]; int huffmanIndex; for (int vecIndex = 0; vecIndex < planeVectorCount; vecIndex++) { huffmanIndex = decodeHuffmanSymbol(cachedHuffman, inBitStream); @@ -226,7 +226,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I final Block decompressedPlane = reconstructImageFromQuantizedVectors(decompressedVectors, qVector, header.getImageDims()); callback.process(decompressedPlane, planeIndex); - } catch (Exception ex) { + } catch (final Exception ex) { throw new ImageDecompressionException("VQImageDecompressor::decompressToBuffer() - Unable to read indices from " + "InBitStream.", ex); @@ -238,9 +238,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I @Override - public void decompressToBuffer(DataInputStream compressedStream, - short[][] buffer, - QCMPFileHeader header) throws ImageDecompressionException { + public void decompressToBuffer(final DataInputStream compressedStream, + final short[][] buffer, + final QCMPFileHeader header) throws ImageDecompressionException { if (header.getQuantizationType() == QuantizationType.Vector3D) { decompressVoxelsToBuffer(compressedStream, buffer, header); return; @@ -251,9 +251,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I } - private void decompressVoxelsImpl(DataInputStream compressedStream, - QCMPFileHeader header, - DecompressVoxelCallback callback) throws ImageDecompressionException { + private void decompressVoxelsImpl(final DataInputStream compressedStream, + final QCMPFileHeader header, + final DecompressVoxelCallback callback) throws ImageDecompressionException { assert (header.getQuantizationType() == QuantizationType.Vector3D); assert (!header.isCodebookPerPlane()); // SHOULD ALWAYS BE GLOBAL. @@ -269,7 +269,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I final Huffman huffman = createHuffmanCoder(huffmanSymbols, codebook.getVectorFrequencies()); final int voxelLayerCount = VQImageCompressor.calculateVoxelLayerCount(header.getImageSizeZ(), header.getVectorSizeZ()); - Stopwatch stopwatch = new Stopwatch(); + final Stopwatch stopwatch = new Stopwatch(); for (int voxelLayerIndex = 0; voxelLayerIndex < voxelLayerCount; voxelLayerIndex++) { stopwatch.restart(); @@ -281,9 +281,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I final int voxelLayerDataSize = (int) header.getPlaneDataSizes()[voxelLayerIndex]; final int voxelLayerVoxelCount = Voxel.calculateRequiredVoxelCount(currentVoxelLayerDims, voxelDims); - int[][] decompressedVoxels = new int[voxelLayerVoxelCount][vectorSize]; + final int[][] decompressedVoxels = new int[voxelLayerVoxelCount][vectorSize]; - try (InBitStream inBitStream = new InBitStream(compressedStream, header.getBitsPerCodebookIndex(), voxelLayerDataSize)) { + try (final InBitStream inBitStream = new InBitStream(compressedStream, header.getBitsPerCodebookIndex(), voxelLayerDataSize)) { inBitStream.readToBuffer(); inBitStream.setAllowReadFromUnderlyingStream(false); @@ -292,7 +292,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I System.arraycopy(codebook.getVectors()[huffmanSymbol], 0, decompressedVoxels[voxelIndex], 0, vectorSize); } - } catch (Exception e) { + } catch (final Exception e) { throw new ImageDecompressionException("VQImageDecompressor::decompressVoxels() - Unable to read indices from InBitStream.", e); } @@ -313,9 +313,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I } @SuppressWarnings("DuplicatedCode") - private void decompressVoxelsStreamModeImpl(DataInputStream compressedStream, - QCMPFileHeader header, - DecompressVoxelCallback callback) throws ImageDecompressionException { + private void decompressVoxelsStreamModeImpl(final DataInputStream compressedStream, + final QCMPFileHeader header, + final DecompressVoxelCallback callback) throws ImageDecompressionException { assert (header.getQuantizationType() == QuantizationType.Vector3D); assert (!header.isCodebookPerPlane()); // SHOULD ALWAYS BE GLOBAL. @@ -327,7 +327,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I final int voxelLayerCount = VQImageCompressor.calculateVoxelLayerCount(header.getImageSizeZ(), header.getVectorSizeZ()); - Stopwatch stopwatch = new Stopwatch(); + final Stopwatch stopwatch = new Stopwatch(); for (int voxelLayerIndex = 0; voxelLayerIndex < voxelLayerCount; voxelLayerIndex++) { stopwatch.restart(); @@ -339,9 +339,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I final int voxelLayerDataSize = (int) header.getPlaneDataSizes()[voxelLayerIndex]; final int voxelLayerVoxelCount = Voxel.calculateRequiredVoxelCount(currentVoxelLayerDims, voxelDims); - int[][] decompressedVoxels = new int[voxelLayerVoxelCount][vectorSize]; + final int[][] decompressedVoxels = new int[voxelLayerVoxelCount][vectorSize]; - try (InBitStream inBitStream = new InBitStream(compressedStream, header.getBitsPerCodebookIndex(), voxelLayerDataSize)) { + try (final InBitStream inBitStream = new InBitStream(compressedStream, header.getBitsPerCodebookIndex(), voxelLayerDataSize)) { inBitStream.readToBuffer(); inBitStream.setAllowReadFromUnderlyingStream(false); @@ -350,7 +350,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I System.arraycopy(cachedCodebook.getVectors()[huffmanSymbol], 0, decompressedVoxels[voxelIndex], 0, vectorSize); } - } catch (Exception e) { + } catch (final Exception e) { throw new ImageDecompressionException("VQImageDecompressor::decompressVoxels() - Unable to read indices from InBitStream.", e); } @@ -371,9 +371,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I } - private void decompressVoxelsToBuffer(DataInputStream compressedStream, - short[][] buffer, - QCMPFileHeader header) throws ImageDecompressionException { + private void decompressVoxelsToBuffer(final DataInputStream compressedStream, + final short[][] buffer, + final QCMPFileHeader header) throws ImageDecompressionException { final V3i voxelDims = new V3i(header.getVectorSizeX(), header.getVectorSizeY(), header.getVectorSizeZ()); @@ -381,9 +381,9 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I decompressedVoxel.reconstructFromVoxels(voxelDims, decompressedVoxelData, buffer, planeOffset)); } - private void decompressVoxels(DataInputStream compressedStream, - DataOutputStream decompressStream, - QCMPFileHeader header) throws ImageDecompressionException { + private void decompressVoxels(final DataInputStream compressedStream, + final DataOutputStream decompressStream, + final QCMPFileHeader header) throws ImageDecompressionException { final V3i voxelDims = new V3i(header.getVectorSizeX(), header.getVectorSizeY(), header.getVectorSizeZ()); decompressVoxelsImpl(compressedStream, header, (voxel, voxelData, planeOffset) -> { @@ -393,14 +393,14 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I for (int layer = 0; layer < voxel.getDims().getZ(); layer++) { try { decompressStream.write(TypeConverter.unsignedShortArrayToByteArray(currentVoxelLayer.getPlaneData(layer), false)); - } catch (IOException e) { + } catch (final IOException e) { throw new ImageDecompressionException("Unable to write to decompress stream.", e); } } }); } - private int decodeHuffmanSymbol(Huffman huffman, InBitStream inBitStream) throws IOException { + private int decodeHuffmanSymbol(final Huffman huffman, final InBitStream inBitStream) throws IOException { HuffmanNode currentHuffmanNode = huffman.getRoot(); while (!currentHuffmanNode.isLeaf()) { currentHuffmanNode = currentHuffmanNode.traverse(inBitStream.readBit()); diff --git a/src/main/java/azgracompress/quantization/vector/VectorQuantizer.java b/src/main/java/azgracompress/quantization/vector/VectorQuantizer.java index efca6ebb9b8bfd27a0c1afb205ebcfbaf9e87469..8806b18f56a9f35d13513dcf6d04f3d558b11f3c 100644 --- a/src/main/java/azgracompress/quantization/vector/VectorQuantizer.java +++ b/src/main/java/azgracompress/quantization/vector/VectorQuantizer.java @@ -37,7 +37,7 @@ public class VectorQuantizer { public int[][] quantize(final int[][] dataVectors, final int workerCount) { assert (dataVectors.length > 0 && dataVectors[0].length % vectorSize == 0) : "Wrong vector size"; - int[][] result = new int[dataVectors.length][vectorSize]; + final int[][] result = new int[dataVectors.length][vectorSize]; if (workerCount == 1) { for (int vectorIndex = 0; vectorIndex < dataVectors.length; vectorIndex++) { @@ -61,8 +61,9 @@ public class VectorQuantizer { final int maxWorkerCount, final QuantizeVectorMethod method) { + assert (dataVectors.length > 0 && dataVectors[0].length == vectorSize) : "Wrong vector size"; - int[] indices = new int[dataVectors.length]; + final int[] indices = new int[dataVectors.length]; if (maxWorkerCount == 1) { for (int vectorIndex = 0; vectorIndex < dataVectors.length; vectorIndex++) { @@ -71,7 +72,7 @@ public class VectorQuantizer { } else { // Cap the worker count on 8 final int workerCount = Math.min(maxWorkerCount, 8); - Thread[] workers = new Thread[workerCount]; + final Thread[] workers = new Thread[workerCount]; final int workSize = dataVectors.length / workerCount; for (int wId = 0; wId < workerCount; wId++) { @@ -90,7 +91,7 @@ public class VectorQuantizer { for (int wId = 0; wId < workerCount; wId++) { workers[wId].join(); } - } catch (InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); } }