moved compressed integer support out of svjatoslavcommons
[imagesqueeze.git] / src / main / java / eu / svjatoslav / imagesqueeze / codec / Table.java
index 33637d7..4e6e638 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -94,15 +94,13 @@ public class Table implements Comparable<Table> {
 
                for (int i = 0; i < 256; i++) {
 
-                       if (range[currentCheckPointer] == i) {
+                       if (range[currentCheckPointer] == i)
                                currentCheckPointer++;
-                       }
 
-                       if (currentCheckPointer > 0) {
+                       if (currentCheckPointer > 0)
                                bitCountForRange[i] = bitcount[currentCheckPointer - 1];
-                       } else {
+                       else
                                bitCountForRange[i] = 0;
-                       }
 
                }
 
@@ -110,20 +108,16 @@ public class Table implements Comparable<Table> {
 
                        int seek;
                        seekLoop: {
-                               for (seek = 0; seek < usedEntries; seek++) {
-
+                               for (seek = 0; seek < usedEntries; seek++)
                                        if (switchTreshold[seek] >= i)
                                                break seekLoop;
-
-                               }
                        }
 
                        proposedRangeForActualRange[i] = range[seek];
-                       if (seek == 0) {
+                       if (seek == 0)
                                proposedRangeForActualRangeLow[i] = 0;
-                       } else {
+                       else
                                proposedRangeForActualRangeLow[i] = switchTreshold[seek - 1] + 1;
-                       }
                        proposedRangeForActualRangeHigh[i] = switchTreshold[seek];
                }
 
@@ -132,11 +126,10 @@ public class Table implements Comparable<Table> {
                        if (range[currentCheckPointer] == i)
                                currentCheckPointer--;
 
-                       if (currentCheckPointer < 0) {
+                       if (currentCheckPointer < 0)
                                proposedDecreasedRange[i] = 0;
-                       } else {
+                       else
                                proposedDecreasedRange[i] = (byte) (range[currentCheckPointer]);
-                       }
                }
 
        }
@@ -144,12 +137,12 @@ public class Table implements Comparable<Table> {
        public void load(final BitInputStream inputStream) throws IOException {
                reset();
 
-               final int availableEntries = inputStream.readIntegerCompressed8();
+               final int availableEntries = ImageDecoder
+                               .readIntegerCompressed8(inputStream);
 
-               for (int i = 0; i < availableEntries; i++) {
+               for (int i = 0; i < availableEntries; i++)
                        addEntry(inputStream.readBits(8), inputStream.readBits(8),
                                        inputStream.readBits(4));
-               }
        }
 
        public int proposeBitcountForRange(int range) {
@@ -177,9 +170,8 @@ public class Table implements Comparable<Table> {
                if (inheritedRange < 0)
                        inheritedRange = 0;
 
-               if (proposedRangeForActualRangeLow[inheritedRange] <= actualRange) {
+               if (proposedRangeForActualRangeLow[inheritedRange] <= actualRange)
                        return inheritedRange;
-               }
 
                return proposeDecreasedRange(inheritedRange);
        }
@@ -199,7 +191,7 @@ public class Table implements Comparable<Table> {
        }
 
        public void save(final BitOutputStream outputStream) throws IOException {
-               outputStream.storeIntegerCompressed8(usedEntries);
+               ImageEncoder.storeIntegerCompressed8(outputStream, usedEntries);
 
                for (int i = 0; i < usedEntries; i++) {
                        outputStream.storeBits(range[i], 8);