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

Rename QcmpFileHeader -> QCMPFileHeaderV1.

parent 058f4fbd
Branches
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ package cz.it4i.qcmp.compression;
import cz.it4i.qcmp.compression.exception.ImageDecompressionException;
import cz.it4i.qcmp.fileformat.IQvcFile;
import cz.it4i.qcmp.fileformat.QCMPFileHeader;
import cz.it4i.qcmp.fileformat.QCMPFileHeaderV1;
import java.io.DataInputStream;
import java.io.DataOutputStream;
......@@ -18,7 +18,7 @@ public interface IImageDecompressor extends IListenable {
*/
void decompress(DataInputStream compressedStream,
DataOutputStream decompressStream,
final QCMPFileHeader header) throws ImageDecompressionException;
final QCMPFileHeaderV1 header) throws ImageDecompressionException;
/**
* Decompress the image planes to memory buffer.
......@@ -30,10 +30,10 @@ public interface IImageDecompressor extends IListenable {
*/
void decompressToBuffer(DataInputStream compressedStream,
short[][] buffer,
final QCMPFileHeader header) throws ImageDecompressionException;
final QCMPFileHeaderV1 header) throws ImageDecompressionException;
short[] decompressStreamMode(final DataInputStream compressedStream,
final QCMPFileHeader header) throws ImageDecompressionException;
final QCMPFileHeaderV1 header) throws ImageDecompressionException;
/**
* Preload decompressor codebook and Huffman tree for stream decompressor from provided cache file.
......
......@@ -4,7 +4,7 @@ import cz.it4i.qcmp.U16;
import cz.it4i.qcmp.compression.exception.ImageCompressionException;
import cz.it4i.qcmp.data.Range;
import cz.it4i.qcmp.fileformat.IQvcFile;
import cz.it4i.qcmp.fileformat.QCMPFileHeader;
import cz.it4i.qcmp.fileformat.QCMPFileHeaderV1;
import cz.it4i.qcmp.io.InputData;
import java.io.*;
......@@ -67,7 +67,7 @@ public class ImageCompressor extends CompressorDecompressorBase {
return compressor;
}
private void reportCompressionRatio(final QCMPFileHeader header, final int written) {
private void reportCompressionRatio(final QCMPFileHeaderV1 header, final int written) {
final long originalDataSize = 2 * header.getImageSizeX() * header.getImageSizeY() * header.getImageSizeZ();
final double compressionRatio = (double) written / (double) originalDataSize;
System.out.printf("Compression ratio: %.5f%%\n", compressionRatio);
......@@ -136,7 +136,7 @@ public class ImageCompressor extends CompressorDecompressorBase {
try (final FileOutputStream fos = new FileOutputStream(options.getOutputFilePath(), false);
final DataOutputStream compressStream = new DataOutputStream(new BufferedOutputStream(fos, 8192))) {
final QCMPFileHeader header = createHeader();
final QCMPFileHeaderV1 header = createHeader();
header.writeToStream(compressStream);
planeDataSizes = imageCompressor.compress(compressStream);
......@@ -216,9 +216,9 @@ public class ImageCompressor extends CompressorDecompressorBase {
*
* @return Valid QCMPFile header for compressed file.
*/
private QCMPFileHeader createHeader() {
private QCMPFileHeaderV1 createHeader() {
// TODO(Moravec): Change header to newer version!
final QCMPFileHeader header = new QCMPFileHeader();
final QCMPFileHeaderV1 header = new QCMPFileHeaderV1();
header.setQuantizationType(options.getQuantizationType());
......
......@@ -3,7 +3,7 @@ package cz.it4i.qcmp.compression;
import cz.it4i.qcmp.compression.exception.ImageDecompressionException;
import cz.it4i.qcmp.data.ImageU16Dataset;
import cz.it4i.qcmp.fileformat.IQvcFile;
import cz.it4i.qcmp.fileformat.QCMPFileHeader;
import cz.it4i.qcmp.fileformat.QCMPFileHeaderV1;
import cz.it4i.qcmp.fileformat.QuantizationType;
import cz.it4i.qcmp.utilities.Stopwatch;
import cz.it4i.qcmp.utilities.Utils;
......@@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit;
public class ImageDecompressor extends CompressorDecompressorBase {
private IImageDecompressor cachedDecompressor = null;
private QCMPFileHeader cachedHeader = null;
private QCMPFileHeaderV1 cachedHeader = null;
public ImageDecompressor(final CompressionOptions passedOptions) {
super(passedOptions);
......@@ -31,7 +31,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
assert (cachedDecompressor != null);
cachedDecompressor.preloadGlobalCodebook(codebookCacheFile);
cachedHeader = new QCMPFileHeader();
cachedHeader = new QCMPFileHeaderV1();
cachedHeader.setQuantizationType(codebookCacheFile.getHeader().getQuantizationType());
cachedHeader.setBitsPerCodebookIndex((byte) ((int) Utils.log2(codebookCacheFile.getHeader().getCodebookSize())));
cachedHeader.setVectorDimension(codebookCacheFile.getHeader().getVectorDim());
......@@ -44,8 +44,8 @@ public class ImageDecompressor extends CompressorDecompressorBase {
* @return Decompressed file header.
* @throws IOException when failed to read header.
*/
private QCMPFileHeader readQCMPFileHeader(final DataInputStream inputStream) throws IOException {
final QCMPFileHeader header = new QCMPFileHeader();
private QCMPFileHeaderV1 readQCMPFileHeader(final DataInputStream inputStream) throws IOException {
final QCMPFileHeaderV1 header = new QCMPFileHeaderV1();
header.readFromStream(inputStream);
return header;
}
......@@ -90,7 +90,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
final StringBuilder logBuilder = new StringBuilder();
boolean validFile = true;
final QCMPFileHeader header;
final QCMPFileHeaderV1 header;
try (final FileInputStream fileInputStream = new FileInputStream(options.getInputDataInfo().getFilePath());
final DataInputStream dataInputStream = new DataInputStream(fileInputStream)) {
header = readQCMPFileHeader(dataInputStream);
......@@ -125,7 +125,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
try (final FileInputStream fileInputStream = new FileInputStream(options.getInputDataInfo().getFilePath());
final DataInputStream dataInputStream = new DataInputStream(fileInputStream)) {
final QCMPFileHeader header = decompressQcmpHeader(dataInputStream);
final QCMPFileHeaderV1 header = decompressQcmpHeader(dataInputStream);
if (header == null)
return false;
......@@ -164,7 +164,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
return true;
}
private boolean checkInputFileSize(final QCMPFileHeader header, final IImageDecompressor imageDecompressor) {
private boolean checkInputFileSize(final QCMPFileHeaderV1 header, final IImageDecompressor imageDecompressor) {
final long fileSize = new File(options.getInputDataInfo().getFilePath()).length();
final long dataSize = fileSize - header.getHeaderSize();
final long expectedDataSize = header.getExpectedDataSize();
......@@ -179,7 +179,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
try (final FileInputStream fileInputStream = new FileInputStream(options.getInputDataInfo().getFilePath());
final DataInputStream dataInputStream = new DataInputStream(fileInputStream)) {
final QCMPFileHeader header = decompressQcmpHeader(dataInputStream);
final QCMPFileHeaderV1 header = decompressQcmpHeader(dataInputStream);
if (header == null)
return Optional.empty();
......@@ -217,7 +217,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
try (final DataInputStream dis = new DataInputStream(new BufferedInputStream(compressedStream))) {
assert (dis.markSupported());
final QCMPFileHeader header = cachedHeader.copyOf();
final QCMPFileHeaderV1 header = cachedHeader.copyOf();
header.setImageSizeX(dis.readUnsignedShort());
header.setImageSizeY(dis.readUnsignedShort());
......@@ -254,8 +254,8 @@ public class ImageDecompressor extends CompressorDecompressorBase {
}
@Nullable
private QCMPFileHeader decompressQcmpHeader(final DataInputStream dataInputStream) throws IOException {
final QCMPFileHeader header = readQCMPFileHeader(dataInputStream);
private QCMPFileHeaderV1 decompressQcmpHeader(final DataInputStream dataInputStream) throws IOException {
final QCMPFileHeaderV1 header = readQCMPFileHeader(dataInputStream);
if (header == null) {
System.err.println("Failed to read QCMPFile header");
return null;
......
......@@ -2,7 +2,7 @@ package cz.it4i.qcmp.compression;
import cz.it4i.qcmp.compression.exception.ImageDecompressionException;
import cz.it4i.qcmp.fileformat.IQvcFile;
import cz.it4i.qcmp.fileformat.QCMPFileHeader;
import cz.it4i.qcmp.fileformat.QCMPFileHeaderV1;
import cz.it4i.qcmp.fileformat.SqQvcFile;
import cz.it4i.qcmp.huffman.HuffmanDecoder;
import cz.it4i.qcmp.huffman.HuffmanTreeBuilder;
......@@ -45,7 +45,7 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I
@Override
public void decompress(final DataInputStream compressedStream,
final DataOutputStream decompressStream,
final QCMPFileHeader header) throws ImageDecompressionException {
final QCMPFileHeaderV1 header) throws ImageDecompressionException {
final int codebookSize = (int) Math.pow(2, header.getBitsPerCodebookIndex());
final int planeCountForDecompression = header.getImageSizeZ();
......@@ -118,7 +118,7 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I
@Override
public void decompressToBuffer(final DataInputStream compressedStream,
final short[][] buffer,
final QCMPFileHeader header) throws ImageDecompressionException {
final QCMPFileHeaderV1 header) throws ImageDecompressionException {
final int codebookSize = (int) Math.pow(2, header.getBitsPerCodebookIndex());
final int planeCountForDecompression = header.getImageSizeZ();
......@@ -163,7 +163,7 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I
@Override
public short[] decompressStreamMode(final DataInputStream compressedStream,
final QCMPFileHeader header) throws ImageDecompressionException {
final QCMPFileHeaderV1 header) throws ImageDecompressionException {
throw new ImageDecompressionException("Not implemented yet.");
}
}
......@@ -3,7 +3,7 @@ package cz.it4i.qcmp.compression;
import cz.it4i.qcmp.compression.exception.ImageDecompressionException;
import cz.it4i.qcmp.data.*;
import cz.it4i.qcmp.fileformat.IQvcFile;
import cz.it4i.qcmp.fileformat.QCMPFileHeader;
import cz.it4i.qcmp.fileformat.QCMPFileHeaderV1;
import cz.it4i.qcmp.fileformat.QuantizationType;
import cz.it4i.qcmp.fileformat.VqQvcFile;
import cz.it4i.qcmp.huffman.HuffmanDecoder;
......@@ -36,7 +36,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
super(options);
}
private long calculatePlaneVectorCount(final QCMPFileHeader header) {
private long calculatePlaneVectorCount(final QCMPFileHeaderV1 header) {
final long vectorXCount = (long) Math.ceil((double) header.getImageSizeX() / (double) header.getVectorSizeX());
final long vectorYCount = (long) Math.ceil((double) header.getImageSizeY() / (double) header.getVectorSizeY());
// Number of vectors per plane.
......@@ -98,7 +98,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
@Override
public void decompress(final DataInputStream compressedStream,
final DataOutputStream decompressStream,
final QCMPFileHeader header) throws ImageDecompressionException {
final QCMPFileHeaderV1 header) throws ImageDecompressionException {
if (header.getQuantizationType() == QuantizationType.Vector3D) {
decompressVoxels(compressedStream, decompressStream, header);
return;
......@@ -114,7 +114,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
}
public void decompressImpl(final DataInputStream compressedStream,
final QCMPFileHeader header,
final QCMPFileHeaderV1 header,
final DecompressCallback callback) throws ImageDecompressionException {
final int codebookSize = (int) Math.pow(2, header.getBitsPerCodebookIndex());
assert (header.getVectorSizeZ() == 1);
......@@ -170,7 +170,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
@SuppressWarnings("DuplicatedCode")
public void decompressStreamModelImpl(final DataInputStream compressedStream,
final QCMPFileHeader header,
final QCMPFileHeaderV1 header,
final DecompressCallback callback) throws ImageDecompressionException {
assert (cachedCodebook != null && cachedHuffmanDecoder != null);
......@@ -215,7 +215,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
@Override
public void decompressToBuffer(final DataInputStream compressedStream,
final short[][] buffer,
final QCMPFileHeader header) throws ImageDecompressionException {
final QCMPFileHeaderV1 header) throws ImageDecompressionException {
if (header.getQuantizationType() == QuantizationType.Vector3D) {
decompressVoxelsToBuffer(compressedStream, buffer, header);
return;
......@@ -227,7 +227,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
private void decompressVoxelsImpl(final DataInputStream compressedStream,
final QCMPFileHeader header,
final QCMPFileHeaderV1 header,
final DecompressVoxelCallback callback) throws ImageDecompressionException {
assert (header.getQuantizationType() == QuantizationType.Vector3D);
......@@ -289,7 +289,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
@SuppressWarnings("DuplicatedCode")
private void decompressVoxelsStreamModeImpl(final DataInputStream compressedStream,
final QCMPFileHeader header,
final QCMPFileHeaderV1 header,
final DecompressVoxelCallback callback) throws ImageDecompressionException {
assert (header.getQuantizationType() == QuantizationType.Vector3D);
......@@ -348,7 +348,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
private void decompressVoxelsToBuffer(final DataInputStream compressedStream,
final short[][] buffer,
final QCMPFileHeader header) throws ImageDecompressionException {
final QCMPFileHeaderV1 header) throws ImageDecompressionException {
final V3i voxelDims = new V3i(header.getVectorSizeX(), header.getVectorSizeY(), header.getVectorSizeZ());
......@@ -358,7 +358,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
private void decompressVoxels(final DataInputStream compressedStream,
final DataOutputStream decompressStream,
final QCMPFileHeader header) throws ImageDecompressionException {
final QCMPFileHeaderV1 header) throws ImageDecompressionException {
final V3i voxelDims = new V3i(header.getVectorSizeX(), header.getVectorSizeY(), header.getVectorSizeZ());
decompressVoxelsImpl(compressedStream, header, (voxel, voxelData, planeOffset) -> {
......@@ -377,7 +377,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
@Override
public short[] decompressStreamMode(final DataInputStream compressedStream,
final QCMPFileHeader header) throws ImageDecompressionException {
final QCMPFileHeaderV1 header) throws ImageDecompressionException {
final short[] buffer = new short[(int) header.getImageDims().multiplyTogether()];
if (header.getQuantizationType() == QuantizationType.Vector3D) {
final V3i voxelDim = new V3i(header.getVectorSizeX(), header.getVectorSizeY(), header.getVectorSizeZ());
......
......@@ -11,7 +11,7 @@ import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
public class QCMPFileHeader implements IFileHeader, Cloneable {
public class QCMPFileHeaderV1 implements IFileHeader, Cloneable {
//region Constants
private static final int VERSION = 1;
private static final int BASE_QCMP_HEADER_SIZE = 23;
......@@ -263,9 +263,9 @@ public class QCMPFileHeader implements IFileHeader, Cloneable {
return super.clone();
}
public QCMPFileHeader copyOf() {
public QCMPFileHeaderV1 copyOf() {
try {
return (QCMPFileHeader) this.clone();
return (QCMPFileHeaderV1) this.clone();
} catch (final CloneNotSupportedException e) {
return null;
}
......
package cz.it4i.qcmp.io;
import cz.it4i.qcmp.fileformat.QCMPFileHeader;
import cz.it4i.qcmp.fileformat.QCMPFileHeaderV1;
import cz.it4i.qcmp.fileformat.QvcHeaderV1;
import cz.it4i.qcmp.fileformat.QvcHeaderV2;
......@@ -39,9 +39,9 @@ public class FileTypeInspector {
// QvcHeaderV1.MAGIC_VALUE // 9 bytes
// QvcHeaderV2.MAGIC_VALUE // 9 bytes
try (final FileInputStream stream = new FileInputStream(filePath)) {
final byte[] buf1 = new byte[QCMPFileHeader.MAGIC_VALUE.length()];
final byte[] buf1 = new byte[QCMPFileHeaderV1.MAGIC_VALUE.length()];
RawDataIO.readFullBuffer(stream, buf1);
if (new String(buf1).equals(QCMPFileHeader.MAGIC_VALUE)) {
if (new String(buf1).equals(QCMPFileHeaderV1.MAGIC_VALUE)) {
return FileType.Qcmp;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment