+/*
+ * Imagesqueeze - Image codec optimized for photos.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
package eu.svjatoslav.imagesqueeze.codec;
import java.io.IOException;
+import eu.svjatoslav.commons.data.BitInputStream;
+import eu.svjatoslav.commons.data.BitOutputStream;
+
/**
- * Since it is a lossy codec, instead of storing
- * exact values, approximated values are stored
- * to save on bit count.
+ * Since it is a lossy codec, instead of storing exact values, approximated
+ * values are stored to save on bit count.
*/
public class Approximator implements Comparable<Approximator> {
public Table uTable = new Table();
public Table vTable = new Table();
- public Approximator(){
+ public Approximator() {
}
- public int compareTo(Approximator o) {
+ @Override
+ public int compareTo(final Approximator o) {
int result = yTable.compareTo(o.yTable);
- if (result != 0) return result;
+ if (result != 0)
+ return result;
result = uTable.compareTo(o.uTable);
- if (result != 0) return result;
+ if (result != 0)
+ return result;
result = vTable.compareTo(o.vTable);
return result;
}
-
- public void initialize(){
+
+ public void computeLookupTables() {
+ yTable.computeLookupTables();
+ uTable.computeLookupTables();
+ vTable.computeLookupTables();
+ }
+
+ public void initialize() {
yTable.reset();
uTable.reset();
vTable.reset();
-
+
yTable.addEntry(0, 6, 0);
yTable.addEntry(27, 30, 4);
yTable.addEntry(255, 255, 6);
-
+
uTable.addEntry(0, 9, 0);
uTable.addEntry(27, 30, 4);
uTable.addEntry(255, 255, 6);
vTable.addEntry(0, 9, 0);
vTable.addEntry(27, 30, 4);
vTable.addEntry(255, 255, 6);
-
+
computeLookupTables();
}
-
- public void save(BitOutputStream outputStream) throws IOException{
- yTable.save(outputStream);
- uTable.save(outputStream);
- vTable.save(outputStream);
- }
-
- public void load(BitInputStream inputStream) throws IOException {
+
+ public void load(final BitInputStream inputStream) throws IOException {
yTable.load(inputStream);
uTable.load(inputStream);
- vTable.load(inputStream);
+ vTable.load(inputStream);
}
- public void computeLookupTables(){
- yTable.computeLookupTables();
- uTable.computeLookupTables();
- vTable.computeLookupTables();
+ public void save(final BitOutputStream outputStream) throws IOException {
+ yTable.save(outputStream);
+ uTable.save(outputStream);
+ vTable.save(outputStream);
}
-
+
}