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

Fix QCMPFileHeader to support Vector3D quantization.

When Vector3D quantization is used, don't save plane data sizes but
instead save voxel layer data sizes. This means to preallocate less
values in header.

Also modify getHeaderSize() function to return the correct header size.
parent 0d8752b8
No related branches found
No related tags found
No related merge requests found
package azgracompress.fileformat; package azgracompress.fileformat;
import azgracompress.U16; import azgracompress.U16;
import azgracompress.compression.VQImageCompressor;
import azgracompress.data.V3i; import azgracompress.data.V3i;
import java.io.DataInputStream; import java.io.DataInputStream;
...@@ -71,15 +72,17 @@ public class QCMPFileHeader { ...@@ -71,15 +72,17 @@ public class QCMPFileHeader {
outputStream.writeShort(vectorSizeY); outputStream.writeShort(vectorSizeY);
outputStream.writeShort(vectorSizeZ); outputStream.writeShort(vectorSizeZ);
// NOTE(Moravec): Allocate space for plane/voxel layers data sizes. Offset: 23.
final int chunkCount = (quantizationType != QuantizationType.Vector3D)
? imageSizeZ
: VQImageCompressor.calculateVoxelLayerCount(imageSizeZ, vectorSizeZ);
// NOTE(Moravec): Allocate space for plane data sizes. Offset: 23. for (int i = 0; i < chunkCount; i++) {
for (int i = 0; i < imageSizeZ; i++) {
outputStream.writeInt(0x0); outputStream.writeInt(0x0);
} }
} }
public boolean readHeader(DataInputStream inputStream) throws IOException { public boolean readHeader(DataInputStream inputStream) throws IOException {
if (inputStream.available() < BASE_QCMP_HEADER_SIZE) { if (inputStream.available() < BASE_QCMP_HEADER_SIZE) {
return false; return false;
} }
...@@ -108,8 +111,13 @@ public class QCMPFileHeader { ...@@ -108,8 +111,13 @@ public class QCMPFileHeader {
vectorSizeY = inputStream.readUnsignedShort(); vectorSizeY = inputStream.readUnsignedShort();
vectorSizeZ = inputStream.readUnsignedShort(); vectorSizeZ = inputStream.readUnsignedShort();
planeDataSizes = new long[imageSizeZ];
for (int i = 0; i < imageSizeZ; i++) { final int chunkCount = (quantizationType != QuantizationType.Vector3D)
? imageSizeZ
: VQImageCompressor.calculateVoxelLayerCount(imageSizeZ, vectorSizeZ);
planeDataSizes = new long[chunkCount];
for (int i = 0; i < chunkCount; i++) {
final long readValue = inputStream.readInt(); final long readValue = inputStream.readInt();
planeDataSizes[i] = (readValue & 0x00000000FFFFFFFFL); planeDataSizes[i] = (readValue & 0x00000000FFFFFFFFL);
} }
...@@ -214,6 +222,10 @@ public class QCMPFileHeader { ...@@ -214,6 +222,10 @@ public class QCMPFileHeader {
} }
public long getHeaderSize() { public long getHeaderSize() {
return BASE_QCMP_HEADER_SIZE + (imageSizeZ * 4); final int chunkCount = (quantizationType != QuantizationType.Vector3D)
? imageSizeZ
: VQImageCompressor.calculateVoxelLayerCount(imageSizeZ, vectorSizeZ);
return BASE_QCMP_HEADER_SIZE + (chunkCount * 4);
} }
} }
\ 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