About
SophiaSCALE for BREW is for compressing data used for BREW Application.
Contents
The following files are included in the package.
- SophiaScale.h (include file)
- ScaleOptions.h (compression parameter)
- ScaleDecorder.c (decode routine)
- ScaleEncorder.c (compress routine)
- ScaleTest.c (test program)
- Makefile (makefile for compile)
- Readme.txt (user's guide)
Environment
Compiler: RVCTB 1.2 Build 848
Usage Procedure
- Include SophiaScale.h in your application's project file.
- Encode (compress)
void *data ... Address of original data int data_size ... Size of original data void *compressed_data; SSDataSize compressed_size; //Check the worst sum of compressed data compressed_size = ScaleEstimateEncodeSize(data_size); //allocate memory compressed_data = malloc(compressed_size); //Actual size of compressed data goes into compressed_size compressed_size = ScaleEncoder(compressed_data, compressed_size, data, data_size); if (compressed_size < 0) error handling //Release unused memory compressed_data = realloc(compressed_data, compressed_size);
- Decode (decompress)
void *cdata ... Address of compressed data int cdata_size ... Size of compressed data void *orig_data; SSDataSize orig_size; //Check the size of original data orig_size = ScaleEstimateEncodeSize(cdata); //allocate memory orig_data = malloc(orig_size); //decode+(size of actual compressed data goes into orig_size) orig_size = ScaleDecoder(orig_data, orig_size, data, data_size); if (orig_size < 0) error handling //Release unused memory (not required when decoding) //orig_data = realloc(orig_data, orig_size);
Error Code
When errors occur during operation, negative values will be returned.
Error Code | Meaning |
---|---|
SSERR_NO_MEMORY | Failed to allocate memory (malloc) |
SSERR_NO_ROOM | Overflowed from the allocated memory area |
SSERR_DATA_BROKEN | Error occurred during decompression.File might be broken. |
Caution
- ScaleEstimateEncodeSize() returns the worst possible size of compressed data.
The actual compressed data will be half of this size. - ScaleEncoder allocates a great amount of memory, twice as big as return value of ScaleEstimateEncodeSize(). Please be aware of memory vacancy when compressing huge data.
- In the current implementation of SophiaSCALE, the use of malloc is minimized. Instead, the stack is heavily used, which leaves the possibility of Stack Overflow open.
- Edit ScaleOptions.h to change the compression parameters.