/*
- * 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.
+ * Image codec. Author: Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * This project is released under Creative Commons Zero (CC0) license.
*/
-
package eu.svjatoslav.imagesqueeze.codec;
-import java.io.IOException;
-
import eu.svjatoslav.commons.data.BitInputStream;
import eu.svjatoslav.commons.data.BitOutputStream;
+import java.io.IOException;
+
/**
* 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 yTable = new Table();
- public Table uTable = new Table();
- public Table vTable = new Table();
-
- public Approximator() {
- }
-
- @Override
- public int compareTo(final Approximator o) {
- int result = yTable.compareTo(o.yTable);
- if (result != 0)
- return result;
-
- result = uTable.compareTo(o.uTable);
- if (result != 0)
- return result;
-
- result = vTable.compareTo(o.vTable);
- return result;
- }
-
- 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 load(final BitInputStream inputStream) throws IOException {
- yTable.load(inputStream);
- uTable.load(inputStream);
- vTable.load(inputStream);
- }
-
- public void save(final BitOutputStream outputStream) throws IOException {
- yTable.save(outputStream);
- uTable.save(outputStream);
- vTable.save(outputStream);
- }
+class Approximator {
+
+ public final Table yTable = new Table();
+ public final Table uTable = new Table();
+ public final Table vTable = new Table();
+
+ public Approximator() {
+ }
+
+
+ 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 load(final BitInputStream inputStream) throws IOException {
+ yTable.load(inputStream);
+ uTable.load(inputStream);
+ vTable.load(inputStream);
+ }
+
+ public void save(final BitOutputStream outputStream) throws IOException {
+ yTable.save(outputStream);
+ uTable.save(outputStream);
+ vTable.save(outputStream);
+ }
}