From 6f4ae6bcffad89ec9aa0a8a889a4c19e0d2c6490 Mon Sep 17 00:00:00 2001 From: Vojtech Moravec <vojtech.moravec.st@vsb.cz> Date: Thu, 3 Dec 2020 10:11:49 +0100 Subject: [PATCH] Prepare QVC conversion. --- .../java/cz/it4i/qcmp/cache/IQvcFile.java | 2 ++ .../java/cz/it4i/qcmp/cache/SqQvcFile.java | 20 ++++++++++++++++++- .../java/cz/it4i/qcmp/cache/VqQvcFile.java | 7 +++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/cz/it4i/qcmp/cache/IQvcFile.java b/src/main/java/cz/it4i/qcmp/cache/IQvcFile.java index 908361a..b4d678a 100644 --- a/src/main/java/cz/it4i/qcmp/cache/IQvcFile.java +++ b/src/main/java/cz/it4i/qcmp/cache/IQvcFile.java @@ -15,4 +15,6 @@ public interface IQvcFile { IQvcHeader getHeader(); void report(StringBuilder builder); + + void convertToNewerVersion(final boolean inPlace, final String inputPath, final String outputPath) throws IOException; } diff --git a/src/main/java/cz/it4i/qcmp/cache/SqQvcFile.java b/src/main/java/cz/it4i/qcmp/cache/SqQvcFile.java index 4364729..9a27713 100644 --- a/src/main/java/cz/it4i/qcmp/cache/SqQvcFile.java +++ b/src/main/java/cz/it4i/qcmp/cache/SqQvcFile.java @@ -40,7 +40,7 @@ public class SqQvcFile implements IQvcFile { ((QvcHeaderV2) header).setHuffmanDataSize(huffmanTreeBinaryRepresentationSize); header.writeToStream(outputStream); - + final int[] quantizationValues = codebook.getCentroids(); for (final int qV : quantizationValues) { outputStream.writeShort(qV); @@ -90,6 +90,24 @@ public class SqQvcFile implements IQvcFile { codebook = new SQCodebook(centroids, huffmanRoot); } + private void convertQvcFromV1ToV2(final String outputFilePath) { + + } + + @Override + public void convertToNewerVersion(final boolean inPlace, final String inputPath, final String outputPath) { + final int headerVersion = header.getHeaderVersion(); + if (!inPlace && (outputPath == null || outputPath.isEmpty())) { + System.err.println("InPlace conversion wasn't specified nor the output file path."); + return; + } + if (headerVersion == 1) { + convertQvcFromV1ToV2(inPlace ? inputPath : outputPath); + } else { + System.err.printf("Version %d is already the newest version of QVC file.\n", headerVersion); + } + } + @Override public IQvcHeader getHeader() { return header; diff --git a/src/main/java/cz/it4i/qcmp/cache/VqQvcFile.java b/src/main/java/cz/it4i/qcmp/cache/VqQvcFile.java index 5fcd635..ab76c5c 100644 --- a/src/main/java/cz/it4i/qcmp/cache/VqQvcFile.java +++ b/src/main/java/cz/it4i/qcmp/cache/VqQvcFile.java @@ -98,6 +98,11 @@ public class VqQvcFile implements IQvcFile { return codebook; } + @Override + public void convertToNewerVersion(final boolean inPlace, final String inputPath, final String outputPath) { + assert false : "NOT IMPLEMENTED YET"; + } + @Override public void report(final StringBuilder builder) { final int[][] vectors = codebook.getVectors(); @@ -108,5 +113,7 @@ public class VqQvcFile implements IQvcFile { } builder.append("\n- - - - - - - - - - - - - - - - - - - - - - - - -\n"); } + + } } -- GitLab