33 delete [] myCompressBuf;
36 template <
class Type>
void
39 if(myChunkSize != size)
44 delete [] myCompressBuf;
47 myCompressBuf =
new unsigned char[
sizeof(
Type) * size * 11/10 + 12];
48 myRLEBuf =
new unsigned char[size * 2 *
sizeof(
Type)];
54 template <
class Type>
int
63 while(size > 0 && *itr++ == val) size--;
74 unsigned char prev,tmp;
75 unsigned char *itr =
data;
128 unsigned short prev,tmp;
129 unsigned short *itr =
data;
177 template<
class Type>
int
180 return isConstant(data,size);
183 template<
class Type>
void
191 template <
class Type>
void *
210 repeat = repeatCount(ci, (size<128) ? size : 128, stride);
213 *co++ = char(repeat);
217 memcpy(co, ci,
sizeof(
Type)*(-repeat));
219 co +=
sizeof(
Type)*(-repeat);
223 for (i=0; i< -
repeat; i++)
225 memcpy(co,ci,
sizeof(
Type));
233 *co++ = char(repeat-1);
234 memcpy(co,ci,
sizeof(
Type));
242 result_length = co - myRLEBuf;
247 template <
class Type>
int
250 const Type *ci, *ci1, *ci2;
256 for (repeat = 1; repeat < max_run; repeat++)
270 for (repeat = 2; repeat < max_run; repeat++)
272 if (*ci2 == *ci && *ci1 == *ci)
284 template<
class Type>
int
288 const unsigned char *ci, *
end;
295 ci = (
unsigned char *)cdata;
303 count = 256 -
int(*ci);
304 size += count*
sizeof(
Type)+1;
309 memcpy(co, ci,
sizeof(
Type)*count);
310 ci+=
sizeof(
Type)*count;
315 for (i=0; i<
count; i++)
317 memcpy(co,ci,
sizeof(
Type));
325 count = 1 +
int(*ci);
326 size += 1 +
sizeof(
Type);
331 memcpy(co,ci,
sizeof(
Type));
338 return (end == ci) ? 0 :
size;
350 stream.next_in = (
Bytef*)source;
351 stream.avail_in = (
uInt)sourceLen;
354 if ((
uLong)stream.avail_in != sourceLen)
return Z_BUF_ERROR;
356 stream.next_out = dest;
357 stream.avail_out = (
uInt)*destLen;
358 if ((
uLong)stream.avail_out != *destLen)
return Z_BUF_ERROR;
360 stream.zalloc = (alloc_func)0;
361 stream.zfree = (free_func)0;
362 stream.opaque = (
voidpf)0;
364 err = deflateInit(&stream, level);
365 if (err != Z_OK)
return err;
367 err = deflate(&stream, Z_FINISH);
368 if (err != Z_STREAM_END) {
370 return err == Z_OK ? Z_BUF_ERROR : err;
372 *destLen = stream.total_out;
374 err = deflateEnd(&stream);
378 template<
class Type>
void *
387 length =
sizeof(
Type) * myChunkSize * 11 / 10 + 12;
393 result_length = (
int) length;
394 return myCompressBuf;
400 template<
class Type>
int
405 length = myChunkSize *
sizeof(
Type);
406 size *=
sizeof(
Type);
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
void setChunkSize(int size)
GLuint GLsizei GLsizei * length
int compressLevel(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
int prefilter(Type *data, int size=-1)
int expand(const void *data, int size, void *dest)
GLsizei GLsizei GLchar * source
GLint GLenum GLboolean GLsizei stride
void * encodeRLE(const Type *data, int &result_length, int size=-1, int stride=1)
int isConstant(const Type *data, int size=-1) const
int decodeRLE(const void *data, int size, Type *dest, int stride=1)
void postfilter(Type *data, int size=-1)
std::string OIIO_UTIL_API repeat(string_view str, int n)
Repeat a string formed by concatenating str n times.
void * compress(const void *data, int &result_length, int size=-1, int level=1)