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

Write,Read of QCMPFile header.

parent 80f1cbdf
No related branches found
No related tags found
No related merge requests found
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
target/ target/
class/ class/
out/ out/
~$leFormat.docx
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>10</source> <source>11</source>
<target>10</target> <target>11</target>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
......
...@@ -2,10 +2,14 @@ package compression.fileformat; ...@@ -2,10 +2,14 @@ package compression.fileformat;
import compression.U16; import compression.U16;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class QCMPFileHeader { public class QCMPFileHeader {
public static final String QCMP_MAGIC_VALUE = "QCMPFILE"; public static final String QCMP_MAGIC_VALUE = "QCMPFILE";
private String magicValue; private String magicValue = QCMP_MAGIC_VALUE;
private QuantizationType quantizationType; private QuantizationType quantizationType;
private byte bitsPerPixel; private byte bitsPerPixel;
private boolean codebookPerPlane; private boolean codebookPerPlane;
...@@ -18,8 +22,10 @@ public class QCMPFileHeader { ...@@ -18,8 +22,10 @@ public class QCMPFileHeader {
private int vectorSizeY; private int vectorSizeY;
private int vectorSizeZ; private int vectorSizeZ;
/** /**
* Validate that all header values are in their valid range. * Validate that all header values are in their valid range.
*
* @return True if this is valid QCMPFILE header. * @return True if this is valid QCMPFILE header.
*/ */
public boolean validateHeader() { public boolean validateHeader() {
...@@ -45,4 +51,36 @@ public class QCMPFileHeader { ...@@ -45,4 +51,36 @@ public class QCMPFileHeader {
return true; return true;
} }
private void writeHeader(DataOutputStream outputStream) throws IOException {
outputStream.writeBytes(QCMP_MAGIC_VALUE);
outputStream.writeByte(quantizationType.getValue());
outputStream.writeByte(bitsPerPixel);
outputStream.writeBoolean(codebookPerPlane);
outputStream.writeInt(imageSizeX);
outputStream.writeInt(imageSizeY);
outputStream.writeInt(imageSizeZ);
outputStream.writeInt(vectorSizeX);
outputStream.writeInt(vectorSizeY);
outputStream.writeInt(vectorSizeZ);
}
private void readHeader(DataInputStream inputStream) throws IOException {
magicValue = new String(inputStream.readNBytes(8));
quantizationType = QuantizationType.fromByte(inputStream.readByte());
bitsPerPixel = inputStream.readByte();
codebookPerPlane = inputStream.readBoolean();
imageSizeX = inputStream.readInt();
imageSizeY = inputStream.readInt();
imageSizeZ = inputStream.readInt();
vectorSizeX = inputStream.readInt();
vectorSizeY = inputStream.readInt();
vectorSizeZ = inputStream.readInt();
}
} }
\ No newline at end of file
package compression.fileformat; package compression.fileformat;
public enum QuantizationType { public enum QuantizationType {
Scalar(0), Vector1D(1), Vector2D(2); Scalar(0), Vector1D(1), Vector2D(2), Vector3D(3), Invalid(255);
private final int value; private final int value;
...@@ -12,4 +12,17 @@ public enum QuantizationType { ...@@ -12,4 +12,17 @@ public enum QuantizationType {
public int getValue() { public int getValue() {
return value; return value;
} }
public static QuantizationType fromByte(final byte b) {
if (b == 0)
return Scalar;
if (b == 1)
return Vector1D;
if (b == 2)
return Vector2D;
if (b == 3)
return Vector3D;
else
return Invalid;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment