+++ /dev/null
-package eu.svjatoslav.imagesqueeze.codec;
-
-/**
- * Write individual bits to the output stream.
- */
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class BitOutputStream {
-
- int currentByte;
- int currentBytePointer;
-
- OutputStream outputStream;
-
- public BitOutputStream(OutputStream outputStream){
- currentByte = 0;
- currentBytePointer = 0;
- this.outputStream = outputStream;
- };
-
-
- public void storeBits(int data, int bitCount) throws IOException {
- for (int i=bitCount-1; i >= 0; i--){
-
- int mask = 1;
- mask = mask << i;
-
- int currentBit = data & mask;
- currentByte = currentByte << 1;
-
- if (currentBit != 0){
- currentByte = currentByte | 1;
- }
- currentBytePointer++;
-
- if (currentBytePointer == 8){
- currentBytePointer = 0;
- outputStream.write(currentByte);
- currentByte = 0;
- }
- }
- }
-
- public void storeIntegerCompressed8(int data) throws IOException{
- if (data < 256){
- storeBits(0, 1);
- storeBits(data, 8);
- } else {
- storeBits(1, 1);
- storeBits(data, 32);
- }
- }
-
- public void finishByte() throws IOException {
- if (currentBytePointer != 0){
- outputStream.write(currentByte);
- currentBytePointer = 0;
- }
- }
-
-}