Xj3D VRML/X3D Code API

org.web3d.vrml.export.compressors
Class CompressionTools

java.lang.Object
  extended byorg.web3d.vrml.export.compressors.CompressionTools

public class CompressionTools
extends java.lang.Object

A set of general tools for compression routines.

Version:
$Revision: 1.15 $
Author:
Alan Hudson

Constructor Summary
CompressionTools()
           
 
Method Summary
static int calcRange(boolean delta, int span, int[] ival)
           
static float calcTolerance(float[] coordinates, float percent)
          Calculate a tolerance value as a percentage of the minimum bounds.
static void compressByteArrayDeltaHuffman(java.io.DataOutputStream dos, byte[] data)
          Compress a byte array.
static void compressFloatArray(java.io.DataOutputStream dos, boolean delta, int span, float[] fval)
          Compress an array of floats.
static void compressIntArrayDeltaHuffman(java.io.DataOutputStream dos, int[] data)
          Compress an integer array.
static void compressShortArrayDeltaHuffman(java.io.DataOutputStream dos, short[] data)
          Compress a byte array.
static int computeBits(int value)
           
static int convertFloatArrayToIntArray(float[] fval, int[] vals)
          Convert an array of floats into an array of integers.
static float[] decompressFloatArray(java.io.InputStream dis, boolean delta, int span)
          Decompress a stream into an array of floats.
static int[] decompressIntArrayDeltaHuffman(java.io.InputStream dis)
          Decompress an integer array.
static float[] dequantizeFloatArray(java.io.InputStream is)
           
static float[] dequantizeFloatArrayHuffman(java.io.InputStream is)
           
static float[] dequantizeFloatArrayInflater(byte[] data, int start, int length)
           
static float[] dequantizeFloatArrayLZW(java.io.InputStream is)
           
static float[] dequantizeVector(java.io.InputStream is, int exponent, int mantissa, boolean signed, int len)
          Dequantize a color vector.
static void printStats()
           
static void quantizeFloatArray(java.io.DataOutputStream dos, float[] fval, float tolerance)
           
static void quantizeFloatArrayDeflater(java.io.DataOutputStream dos, float[] fval, float tolerance)
           
static void quantizeFloatArrayHuffman(java.io.DataOutputStream dos, float[] fval, float tolerance)
           
static void quantizeFloatArrayLZW(java.io.DataOutputStream dos, float[] fval, float tolerance)
           
static void quantizeVector(java.io.DataOutputStream dos, int exponent, int mantissa, boolean signed, float[] fval)
          Quantize a short vector.
static void rangeCompressIntArray(java.io.DataOutputStream dos, boolean delta, int span, int[] ival)
          Compress an array of integers by determning the number of bits needed to express the range of values.
static int[] rangeDecompressIntArray(java.io.InputStream dis, boolean delta, int span)
          Decompress an array of integers compressed by determning the number of bits needed to express the range of values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompressionTools

public CompressionTools()
Method Detail

convertFloatArrayToIntArray

public static int convertFloatArrayToIntArray(float[] fval,
                                              int[] vals)
Convert an array of floats into an array of integers. A multiplication factor 10^n is returned.

Parameters:
fval - The float data
vals - The integer result. Preallocate this.
Returns:
the multipler used.

calcTolerance

public static float calcTolerance(float[] coordinates,
                                  float percent)
Calculate a tolerance value as a percentage of the minimum bounds.

Parameters:
coordinates - The array of coordinates.
percent - The percent of the maximum coordinate range to use as an error.
Returns:
The tolerance value to use.

quantizeFloatArray

public static void quantizeFloatArray(java.io.DataOutputStream dos,
                                      float[] fval,
                                      float tolerance)
                               throws java.io.IOException
Throws:
java.io.IOException

dequantizeFloatArray

public static float[] dequantizeFloatArray(java.io.InputStream is)
                                    throws java.io.IOException
Throws:
java.io.IOException

quantizeVector

public static void quantizeVector(java.io.DataOutputStream dos,
                                  int exponent,
                                  int mantissa,
                                  boolean signed,
                                  float[] fval)
                           throws java.io.IOException
Quantize a short vector. The length will not be stored. The (exponent + mantissa + signed) * len must be a multiple of 8.

Parameters:
dos - The output stream
exponent - How many bits to store for the exponent
mantissa - How many bits to store for the mantissa
signed - Is the number sometimes negative
fval - The vector
Throws:
java.io.IOException

dequantizeVector

public static float[] dequantizeVector(java.io.InputStream is,
                                       int exponent,
                                       int mantissa,
                                       boolean signed,
                                       int len)
                                throws java.io.IOException
Dequantize a color vector. The (exponent + mantissa + sign) * len must be a multiple of 8.

Parameters:
is - The input stream
exponent - How many bits to store for the exponent
mantissa - How many bits to store for the mantissa
signed - Is the number sometimes negative
len - The length of the vector.
Returns:
The decoded vector
Throws:
java.io.IOException

compressFloatArray

public static void compressFloatArray(java.io.DataOutputStream dos,
                                      boolean delta,
                                      int span,
                                      float[] fval)
                               throws java.io.IOException
Compress an array of floats.

Parameters:
dos - The stream to write the results.
delta - Whether to use delta encoding.
span - The repeating frequency of data, a MFVec3f would be a span of 3.
fval - The float array to compress
Throws:
java.io.IOException - on an IO error

decompressFloatArray

public static float[] decompressFloatArray(java.io.InputStream dis,
                                           boolean delta,
                                           int span)
                                    throws java.io.IOException
Decompress a stream into an array of floats. This stream must of been encoded via the compressFloatArray call.

Parameters:
dis - The stream to read.
delta - Whether to use delta encoding.
span - The repeating frequency of data, a MFVec3f would be a span of 3.
Returns:
The float array decompressed.
Throws:
java.io.IOException - on an IO error

calcRange

public static int calcRange(boolean delta,
                            int span,
                            int[] ival)

quantizeFloatArrayHuffman

public static void quantizeFloatArrayHuffman(java.io.DataOutputStream dos,
                                             float[] fval,
                                             float tolerance)
                                      throws java.io.IOException
Throws:
java.io.IOException

dequantizeFloatArrayHuffman

public static float[] dequantizeFloatArrayHuffman(java.io.InputStream is)
                                           throws java.io.IOException
Throws:
java.io.IOException

quantizeFloatArrayLZW

public static void quantizeFloatArrayLZW(java.io.DataOutputStream dos,
                                         float[] fval,
                                         float tolerance)
                                  throws java.io.IOException
Throws:
java.io.IOException

quantizeFloatArrayDeflater

public static void quantizeFloatArrayDeflater(java.io.DataOutputStream dos,
                                              float[] fval,
                                              float tolerance)
                                       throws java.io.IOException
Throws:
java.io.IOException

dequantizeFloatArrayInflater

public static float[] dequantizeFloatArrayInflater(byte[] data,
                                                   int start,
                                                   int length)
                                            throws java.io.IOException
Throws:
java.io.IOException

dequantizeFloatArrayLZW

public static float[] dequantizeFloatArrayLZW(java.io.InputStream is)
                                       throws java.io.IOException
Throws:
java.io.IOException

compressIntArrayDeltaHuffman

public static void compressIntArrayDeltaHuffman(java.io.DataOutputStream dos,
                                                int[] data)
                                         throws java.io.IOException
Compress an integer array. Uses delta encoding if applicable. Huffman encodes the result.

Parameters:
dos - The stream to write to
data - The integer array to encode.
Throws:
java.io.IOException

decompressIntArrayDeltaHuffman

public static int[] decompressIntArrayDeltaHuffman(java.io.InputStream dis)
                                            throws java.io.IOException
Decompress an integer array. Uses delta encoding if applicable. Huffman encodes the result.

Parameters:
dis - The stream to write to
Returns:
The integer array with the decompressed info
Throws:
java.io.IOException

compressByteArrayDeltaHuffman

public static void compressByteArrayDeltaHuffman(java.io.DataOutputStream dos,
                                                 byte[] data)
                                          throws java.io.IOException
Compress a byte array. Uses delta encoding if applicable. Huffman encodes the result.

Parameters:
dos - The stream to write to
data - The integer array to encode.
Throws:
java.io.IOException

compressShortArrayDeltaHuffman

public static void compressShortArrayDeltaHuffman(java.io.DataOutputStream dos,
                                                  short[] data)
                                           throws java.io.IOException
Compress a byte array. Uses delta encoding if applicable. Huffman encodes the result.

Parameters:
dos - The stream to write to
data - The integer array to encode.
Throws:
java.io.IOException

rangeCompressIntArray

public static void rangeCompressIntArray(java.io.DataOutputStream dos,
                                         boolean delta,
                                         int span,
                                         int[] ival)
                                  throws java.io.IOException
Compress an array of integers by determning the number of bits needed to express the range of values. Optional delta coding is provided. Format: Number of ints encoded(27, nothing else if length=0) Number if bits per entry(5) Shift(32) Initial value(32 * span,if delta encoding)

Throws:
java.io.IOException

rangeDecompressIntArray

public static int[] rangeDecompressIntArray(java.io.InputStream dis,
                                            boolean delta,
                                            int span)
                                     throws java.io.IOException
Decompress an array of integers compressed by determning the number of bits needed to express the range of values. Optional delta coding is provided. Format: Number of ints encoded(27) Number if bits per entry(5, nothing else if length=0) Shift(32) Initial value(32 * span,if delta encoding)

Throws:
java.io.IOException

computeBits

public static int computeBits(int value)

printStats

public static void printStats()

Xj3D VRML/X3D Code API

Copyright © 2001 - 2005 Web3D Consortium