Class CompressionTools
java.lang.Object
org.web3d.vrml.export.compressors.CompressionTools
A set of general tools for compression routines.
- Version:
- $Revision: 1.19 $
- Author:
- Alan Hudson
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
(DataOutputStream dos, byte[] data) Compress a byte array.static void
compressFloatArray
(DataOutputStream dos, boolean delta, int span, float[] fval) Compress an array of floats.static void
compressIntArrayDeltaHuffman
(DataOutputStream dos, int[] data) Compress an integer array.static void
compressShortArrayDeltaHuffman
(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
(InputStream dis, boolean delta, int span) Decompress a stream into an array of floats.static int[]
Decompress an integer array.static float[]
static float[]
static float[]
dequantizeFloatArrayInflater
(byte[] data, int start, int length, boolean useLen) static float[]
static float[]
dequantizeVector
(InputStream is, int exponent, int mantissa, boolean signed, int len) Dequantize a color vector.static void
findFloatParams
(float[] origvals, float tolerance, int[] output) Find the float parameters of exponent, mantissa and sign that will express the array of float values within the tolerance specified.static void
findFloatParams
(float origval, float tolerance, int[] output) Find the float parameters of exponent, mantissa and sign that will express the float value within the tolerance specified.static void
findFloatParamsOld
(float[] origvals, float tolerance, int[] output) Find the float parameters of exponent, mantissa and sign that will express the array of float values within the tolerance specified.static void
static void
static void
quantizeFloatArray
(DataOutputStream dos, float[] fval, float tolerance) static void
quantizeFloatArrayDeflater
(DataOutputStream dos, float[] fval, float tolerance, boolean useLen) Compress a float array by quantizing its values.static void
quantizeFloatArrayHuffman
(DataOutputStream dos, float[] fval, float tolerance) static void
quantizeFloatArrayLZW
(DataOutputStream dos, float[] fval, float tolerance) static void
quantizeVector
(DataOutputStream dos, int exponent, int mantissa, boolean signed, float[] fval) Quantize a short vector.static void
rangeCompressIntArray
(DataOutputStream dos, boolean delta, int span, int[] ival) Compress an array of integers by determining the number of bits needed to express the range of values.static int[]
rangeDecompressIntArray
(InputStream dis, boolean delta, int span) Decompress an array of integers compressed by determining the number of bits needed to express the range of values.
-
Constructor Details
-
CompressionTools
public CompressionTools()
-
-
Method Details
-
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 datavals
- The integer result. Preallocate this.- Returns:
- the multiplier 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(DataOutputStream dos, float[] fval, float tolerance) throws IOException - Parameters:
dos
-fval
-tolerance
-- Throws:
IOException
-
dequantizeFloatArray
- Parameters:
is
-- Returns:
- Throws:
IOException
-
quantizeVector
public static void quantizeVector(DataOutputStream dos, int exponent, int mantissa, boolean signed, float[] fval) throws 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 streamexponent
- How many bits to store for the exponentmantissa
- How many bits to store for the mantissasigned
- Is the number sometimes negativefval
- The vector- Throws:
IOException
-
dequantizeVector
public static float[] dequantizeVector(InputStream is, int exponent, int mantissa, boolean signed, int len) throws IOException Dequantize a color vector. The (exponent + mantissa + sign) * len must be a multiple of 8.- Parameters:
is
- The input streamexponent
- How many bits to store for the exponentmantissa
- How many bits to store for the mantissasigned
- Is the number sometimes negativelen
- The length of the vector.- Returns:
- The decoded vector
- Throws:
IOException
-
compressFloatArray
public static void compressFloatArray(DataOutputStream dos, boolean delta, int span, float[] fval) throws 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:
IOException
- on an IO error
-
decompressFloatArray
public static float[] decompressFloatArray(InputStream dis, boolean delta, int span) throws 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:
IOException
- on an IO error
-
calcRange
public static int calcRange(boolean delta, int span, int[] ival) - Parameters:
delta
-span
-ival
-- Returns:
-
quantizeFloatArrayHuffman
public static void quantizeFloatArrayHuffman(DataOutputStream dos, float[] fval, float tolerance) throws IOException - Parameters:
dos
-fval
-tolerance
-- Throws:
IOException
-
dequantizeFloatArrayHuffman
- Parameters:
is
-- Returns:
- Throws:
IOException
-
quantizeFloatArrayLZW
public static void quantizeFloatArrayLZW(DataOutputStream dos, float[] fval, float tolerance) throws IOException - Parameters:
dos
-fval
-tolerance
-- Throws:
IOException
-
quantizeFloatArrayDeflater
public static void quantizeFloatArrayDeflater(DataOutputStream dos, float[] fval, float tolerance, boolean useLen) throws IOException Compress a float array by quantizing its values.- Parameters:
dos
- The output streamfval
- The float valuestolerance
- The tolerance allowed between equal valuesuseLen
-- Throws:
IOException
-
dequantizeFloatArrayInflater
public static float[] dequantizeFloatArrayInflater(byte[] data, int start, int length, boolean useLen) throws IOException - Parameters:
data
-start
- the start position in the arraylength
- number of values to read from the arrayuseLen
-- Returns:
- Throws:
IOException
-
dequantizeFloatArrayLZW
- Parameters:
is
-- Returns:
- Throws:
IOException
-
compressIntArrayDeltaHuffman
public static void compressIntArrayDeltaHuffman(DataOutputStream dos, int[] data) throws IOException Compress an integer array. Uses delta encoding if applicable. Huffman encodes the result.- Parameters:
dos
- The stream to write todata
- The integer array to encode.- Throws:
IOException
-
decompressIntArrayDeltaHuffman
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:
IOException
-
compressByteArrayDeltaHuffman
public static void compressByteArrayDeltaHuffman(DataOutputStream dos, byte[] data) throws IOException Compress a byte array. Uses delta encoding if applicable. Huffman encodes the result.- Parameters:
dos
- The stream to write todata
- The integer array to encode.- Throws:
IOException
-
compressShortArrayDeltaHuffman
public static void compressShortArrayDeltaHuffman(DataOutputStream dos, short[] data) throws IOException Compress a byte array. Uses delta encoding if applicable. Huffman encodes the result.- Parameters:
dos
- The stream to write todata
- The integer array to encode.- Throws:
IOException
-
rangeCompressIntArray
public static void rangeCompressIntArray(DataOutputStream dos, boolean delta, int span, int[] ival) throws IOException Compress an array of integers by determining 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)- Parameters:
dos
-delta
-span
-ival
-- Throws:
IOException
-
rangeDecompressIntArray
public static int[] rangeDecompressIntArray(InputStream dis, boolean delta, int span) throws IOException Decompress an array of integers compressed by determining 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)- Parameters:
dis
-delta
-span
-- Returns:
- Throws:
IOException
-
computeBits
public static int computeBits(int value) - Parameters:
value
-- Returns:
-
printStats
public static void printStats() -
findFloatParams
public static void findFloatParams(float origval, float tolerance, int[] output) Find the float parameters of exponent, mantissa and sign that will express the float value within the tolerance specified.- Parameters:
origval
- The original valuetolerance
- The error toleranceoutput
- The exponent, mantissa and sign bits needed
-
findFloatParams
public static void findFloatParams(float[] origvals, float tolerance, int[] output) Find the float parameters of exponent, mantissa and sign that will express the array of float values within the tolerance specified.- Parameters:
origvals
- The original valuetolerance
- The error toleranceoutput
- The exponent, mantissa and sign bits needed
-
findFloatParamsOld
public static void findFloatParamsOld(float[] origvals, float tolerance, int[] output) Find the float parameters of exponent, mantissa and sign that will express the array of float values within the tolerance specified.- Parameters:
origvals
- The original valuetolerance
- The error toleranceoutput
- The exponent, mantissa and sign bits needed
-
main
- Parameters:
args
-
-