Skip to content
Snippets Groups Projects
Commit 22501b29 authored by Vojtěch Moravec's avatar Vojtěch Moravec
Browse files

Change data in ImageU16Dataset.

We have to set each plane data separately in ImageJ. To support that
functionality we return 2D pixel array in the dataset class.

This commit also contains modification in the decompressors to support
decompression into this 2D array.
parent 47290471
Branches
No related tags found
No related merge requests found
......@@ -132,10 +132,4 @@ public abstract class CompressorDecompressorBase {
protected int getCodebookSize() {
return codebookSize;
}
protected void copyIntArrayToShortArray(final int[] srcBuffer, final short[] destBuffer, final int destOffset, final int copyLen) {
for (int i = 0; i < copyLen; i++) {
destBuffer[destOffset + i] = (short) srcBuffer[i];
}
}
}
......@@ -36,7 +36,7 @@ public interface IImageDecompressor {
* @throws ImageDecompressionException when decompression fails.
*/
void decompressToBuffer(DataInputStream compressedStream,
short[] buffer,
short[][] buffer,
final QCMPFileHeader header) throws ImageDecompressionException;
}
......@@ -237,8 +237,8 @@ public class ImageDecompressor extends CompressorDecompressorBase {
return null;
}
final int totalPixelCount = (int) header.getImageDims().multiplyTogether();
final short[] decompressedData = new short[totalPixelCount];
final int planePixelCount = header.getImageSizeX() * header.getImageSizeY();
final short[][] decompressedData = new short[header.getImageSizeZ()][planePixelCount];
try {
......
......@@ -125,13 +125,12 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I
}
@Override
public void decompressToBuffer(DataInputStream compressedStream, short[] buffer, QCMPFileHeader header) throws ImageDecompressionException {
public void decompressToBuffer(DataInputStream compressedStream, short[][] buffer, QCMPFileHeader header) throws ImageDecompressionException {
final int codebookSize = (int) Math.pow(2, header.getBitsPerCodebookIndex());
final int[] huffmanSymbols = createHuffmanSymbols(codebookSize);
final int planeCountForDecompression = header.getImageSizeZ();
final int planePixelCount = header.getImageSizeX() * header.getImageSizeY();
int bufferOffset = 0;
SQCodebook codebook = null;
Huffman huffman = null;
......@@ -165,8 +164,7 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I
decompressedValues[pixel] = quantizationValues[currentHuffmanNode.getSymbol()];
}
copyIntArrayToShortArray(decompressedValues, buffer, bufferOffset, planePixelCount);
bufferOffset += planePixelCount;
buffer[planeIndex] = TypeConverter.intArrayToShortArray(decompressedValues);
} catch (Exception ex) {
throw new ImageDecompressionException("Unable to read indices from InBitStream.", ex);
}
......
......@@ -15,6 +15,7 @@ import azgracompress.utilities.TypeConverter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Type;
// TODO(Moravec): Handle huffman decoding.
......@@ -180,16 +181,13 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
}
@Override
public void decompressToBuffer(DataInputStream compressedStream, short[] buffer, QCMPFileHeader header) throws ImageDecompressionException {
public void decompressToBuffer(DataInputStream compressedStream, short[][] buffer, QCMPFileHeader header) throws ImageDecompressionException {
// TODO: Think how to remove the duplicate code.
final int planePixelCount = header.getImageSizeX() * header.getImageSizeY();
int bufferOffset = 0;
final int codebookSize = (int) Math.pow(2, header.getBitsPerCodebookIndex());
assert (header.getVectorSizeZ() == 1);
final int vectorSize = header.getVectorSizeX() * header.getVectorSizeY() * header.getVectorSizeZ();
final int planeCountForDecompression = header.getImageSizeZ();
final long planeVectorCount = calculatePlaneVectorCount(header);
//final long planeDataSize = calculatePlaneDataSize(planeVectorCount, header.getBitsPerPixel());
final V2i qVector = new V2i(header.getVectorSizeX(), header.getVectorSizeY());
final int[] huffmanSymbols = createHuffmanSymbols(codebookSize);
......@@ -238,9 +236,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
qVector,
header.getImageDims());
copyIntArrayToShortArray(decompressedPlane.getData(), buffer, bufferOffset, planePixelCount);
bufferOffset += planePixelCount;
buffer[planeIndex] = TypeConverter.intArrayToShortArray(decompressedPlane.getData());
} catch (Exception ex) {
throw new ImageDecompressionException("Unable to read indices from InBitStream.", ex);
}
......
......@@ -3,12 +3,12 @@ package azgracompress.data;
public class ImageU16Dataset {
private final V2i planeDimensions;
private final int planeCount;
private final short[] data;
private final short[][] data;
public ImageU16Dataset(V2i planeDimensions, int planeCount, short[] data) {
public ImageU16Dataset(V2i planeDimensions, int planeCount, short[][] planeData) {
this.planeDimensions = planeDimensions;
this.planeCount = planeCount;
this.data = data;
this.data = planeData;
}
public V2i getPlaneDimensions() {
......@@ -19,7 +19,9 @@ public class ImageU16Dataset {
return planeCount;
}
public short[] getData() {
return data;
public short[] getPlaneData(final int planeIndex) {
assert (planeIndex >= 0);
assert (planeIndex < data.length);
return data[planeIndex];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment