[Home]History of David Alves/Free Code

Robo Home | Changes | Preferences | AllPages


Revision 7 . . November 5, 2007 4:00 EST by David Alves [Free data saving compression code, help yourself!]
Revision 6 . . (edit) November 5, 2007 3:51 EST by David Alves
Revision 5 . . November 5, 2007 3:47 EST by David Alves [Added data saving stuff]
Revision 4 . . (edit) November 11, 2006 10:05 EST by David Alves
  

Difference (from prior major revision) (author diff)

Added: 18a19,52

/**
* Encodes a float array into byteCount bytes, using DCT.
*
* @return a byte array with the encoded data
*/
public static byte[] encodeSegmentToBytes?(float[] data, int byteCount){
byte[] compressed = new byte[byteCount];

float[] dctValues = forwardDCT(data);

for(int i = 0; i < byteCount; i++){
compressed[i] = (byte) Math.min(Byte.MAX_VALUE, Math.max(Byte.MIN_VALUE, Math.round((i + 1) * 128.0 * dctValues[i])));
if(compressed[i] == Byte.MAX_VALUE){
System.out.println("Warning: max value");
printArray(data);
}
if(compressed[i] == Byte.MIN_VALUE){
System.out.println("Warning: min value");
printArray(data);
}
}

return compressed;
}

/**
* Decodes a float array from the specified array of bytes. The parameter
* arraySize is how many floats should be in the decoded array.
*
* @param data DCT-encoded bytes
* @param arraySize the size of the array
* @return the decompressed array of floats
*/

Added: 22a57,66
/**
* Decodes a float array from the specified array of bytes. The parameter
* arraySize is how many floats should be in the decoded array.
*
* @param useFirstNBytes? how many of the compressed bytes to use when decompressing.
* @param data DCT-encoded bytes
* @param arraySize the size of the array
* @return the decompressed array of floats
*
*/

Added: 35a80,85
/**
* Performs a forward discrete cosine transform on the provided data, and returns the coefficients
*
* @param data the data to encode
* @return DCT-encoded data
*/

Added: 54a105,111
/**
* Performs an inverse discrete cosine transform on the provided coefficients,
* returning an approximation of the original data.
*
* @param coefficients the DCT coefficients
* @return the original data, or as close to it as possible!
*/

Robo Home | Changes | Preferences | AllPages
Search: