HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 #ifdef WIN32
17  #pragma warning(disable:4251)
18  #pragma warning(disable:4275)
19 #endif
20 
21 
22 template <class Type>
24 {
25 public:
26  UT_Compress();
27  ~UT_Compress();
28 
29  // initializes with a max chunk size (max amount of data you're passing in)
30  // Number of elements, not bytes.
31  void setChunkSize(int size);
32 
33  // constant checking methods (if size = -1, the chunk size is used).
34  int isConstant(const Type *data, int size = -1) const;
35 
36  // prefilters (8 bit only, currently). Returns 1 if the chunk is constant.
37  // this routine modifies the data passed in. Call before RLE or compress.
38  // When uncompressing, use postfilter() after RLE decode or deflate.
39  // these methods do not compress data, but make it easier to compress.
40  int prefilter(Type *data, int size = -1);
41  void postfilter(Type *data, int size = -1);
42 
43  // encodes RLE. Returns a pointer to alloc'd data; do not delete.
44  // decode returns zero if successful, the error location if not.
45  void * encodeRLE(const Type *data, int &result_length, int size =-1,
46  int stride = 1);
47  int decodeRLE(const void *data,int size, Type *dest,int stride=1);
48 
49  // compresses using zlib (levels: 0 fast, 1 med, 2 best compression).
50  void * compress(const void *data, int &result_length, int size =-1,
51  int level = 1);
52  int expand (const void *data,int size, void *dest);
53 
54  unsigned char * getRLEBuf() { return myRLEBuf; }
55  unsigned char * getCompressBuf() { return myCompressBuf; }
56 
57 private:
58  int repeatCount(const Type *data, int max_run, int stride);
59 
60  int myChunkSize;
61  unsigned char *myRLEBuf;
62  unsigned char *myCompressBuf;
63 };
64 
65 
66 // for templates.
67 #include "UT_Compress.C"
68 
69 #endif
void setChunkSize(int size)
Definition: UT_Compress.C:37
GLint level
Definition: glcorearb.h:107
GLsizeiptr size
Definition: glcorearb.h:663
int prefilter(Type *data, int size=-1)
Definition: UT_Compress.C:178
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:871
int expand(const void *data, int size, void *dest)
Definition: UT_Compress.C:401
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
GLboolean * data
Definition: glcorearb.h:130
int decodeRLE(const void *data, int size, Type *dest, int stride=1)
Definition: UT_Compress.C:285
unsigned char * getRLEBuf()
Definition: UT_Compress.h:54
void postfilter(Type *data, int size=-1)
Definition: UT_Compress.C:184
unsigned char * getCompressBuf()
Definition: UT_Compress.h:55
void * compress(const void *data, int &result_length, int size=-1, int level=1)
Definition: UT_Compress.C:379