2 * Imagesqueeze - Image codec optimized for photos.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.imagesqueeze.codec;
12 import eu.svjatoslav.commons.data.BitInputStream;
13 import eu.svjatoslav.commons.data.BitOutputStream;
15 import java.io.IOException;
18 * Since it is a lossy codec, instead of storing exact values, approximated
19 * values are stored to save on bit count.
24 public final Table yTable = new Table();
25 public final Table uTable = new Table();
26 public final Table vTable = new Table();
28 public Approximator() {
32 public void computeLookupTables() {
33 yTable.computeLookupTables();
34 uTable.computeLookupTables();
35 vTable.computeLookupTables();
38 public void initialize() {
43 yTable.addEntry(0, 6, 0);
44 yTable.addEntry(27, 30, 4);
45 yTable.addEntry(255, 255, 6);
47 uTable.addEntry(0, 9, 0);
48 uTable.addEntry(27, 30, 4);
49 uTable.addEntry(255, 255, 6);
51 vTable.addEntry(0, 9, 0);
52 vTable.addEntry(27, 30, 4);
53 vTable.addEntry(255, 255, 6);
55 computeLookupTables();
58 public void load(final BitInputStream inputStream) throws IOException {
59 yTable.load(inputStream);
60 uTable.load(inputStream);
61 vTable.load(inputStream);
64 public void save(final BitOutputStream outputStream) throws IOException {
65 yTable.save(outputStream);
66 uTable.save(outputStream);
67 vTable.save(outputStream);