HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Compress.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Compress.h UT library (C++)
7  *
8  * COMMENTS:
9  * Class to do simple (RLE) and complex compression (zlib).
10  * Also has some other simple prefilter and constant checking methods.
11  *
12  */
13 #ifndef UT_COMPRESS_H
14 #define UT_COMPRESS_H
15 
16 template <class Type>
18 {
19 public:
20  UT_Compress();
21  ~UT_Compress();
22 
23  // initializes with a max chunk size (max amount of data you're passing in)
24  // Number of elements, not bytes.
25  void setChunkSize(int size);
26 
27  // constant checking methods (if size = -1, the chunk size is used).
28  int isConstant(const Type *data, int size = -1) const;
29 
30  // prefilters (8 bit only, currently). Returns 1 if the chunk is constant.
31  // this routine modifies the data passed in. Call before RLE or compress.
32  // When uncompressing, use postfilter() after RLE decode or deflate.
33  // these methods do not compress data, but make it easier to compress.
34  int prefilter(Type *data, int size = -1);
35  void postfilter(Type *data, int size = -1);
36 
37  // encodes RLE. Returns a pointer to alloc'd data; do not delete.
38  // decode returns zero if successful, the error location if not.
39  void * encodeRLE(const Type *data, int &result_length, int size =-1,
40  int stride = 1);
41  int decodeRLE(const void *data,int size, Type *dest,int stride=1);
42 
43  // compresses using zlib (levels: 0 fast, 1 med, 2 best compression).
44  void * compress(const void *data, int &result_length, int size =-1,
45  int level = 1);
46  int expand (const void *data,int size, void *dest);
47 
48  unsigned char * getRLEBuf() { return myRLEBuf; }
49  unsigned char * getCompressBuf() { return myCompressBuf; }
50 
51 private:
52  int repeatCount(const Type *data, int max_run, int stride);
53 
54  int myChunkSize;
55  unsigned char *myRLEBuf;
56  unsigned char *myCompressBuf;
57 };
58 
59 
60 // for templates.
61 #include "UT_Compress.C"
62 
63 #endif
void setChunkSize(int size)
Definition: UT_Compress.C:37
GLint level
Definition: glcorearb.h:108
int prefilter(Type *data, int size=-1)
Definition: UT_Compress.C:178
int expand(const void *data, int size, void *dest)
Definition: UT_Compress.C:401
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
void * encodeRLE(const Type *data, int &result_length, int size=-1, int stride=1)
Definition: UT_Compress.C:192
int isConstant(const Type *data, int size=-1) const
Definition: UT_Compress.C:55
int decodeRLE(const void *data, int size, Type *dest, int stride=1)
Definition: UT_Compress.C:285
unsigned char * getRLEBuf()
Definition: UT_Compress.h:48
void postfilter(Type *data, int size=-1)
Definition: UT_Compress.C:184
GLsizeiptr size
Definition: glcorearb.h:664
unsigned char * getCompressBuf()
Definition: UT_Compress.h:49
void * compress(const void *data, int &result_length, int size=-1, int level=1)
Definition: UT_Compress.C:379
Definition: format.h:895