File: LZSS.c

package info (click to toggle)
unar 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,664 kB
  • sloc: ansic: 52,939; objc: 39,563; cpp: 4,074; makefile: 99; perl: 10
file content (43 lines) | stat: -rw-r--r-- 934 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "LZSS.h"

#include <stdlib.h>
#include <string.h>

bool InitializeLZSS(LZSS *self,int windowsize)
{
	self->window=malloc(windowsize);
	if(!self->window) return false;

	self->mask=windowsize-1; // Assume windows are power-of-two sized!

	RestartLZSS(self);

	return true;
}

void CleanupLZSS(LZSS *self)
{
	free(self->window);
}

void RestartLZSS(LZSS *self)
{
	memset(self->window,0,LZSSWindowSize(self));
	self->position=0;
}

void CopyBytesFromLZSSWindow(LZSS *self,uint8_t *buffer,int64_t startpos,int length)
{
	int windowoffs=LZSSWindowOffsetForPosition(self,startpos);

	if(windowoffs+length<=LZSSWindowSize(self)) // Request fits inside window
	{
		memcpy(buffer,&self->window[windowoffs],length);
	}
	else // Request wraps around window
	{
		int firstpart=LZSSWindowSize(self)-windowoffs;
		memcpy(&buffer[0],&self->window[windowoffs],firstpart);
		memcpy(&buffer[firstpart],&self->window[0],length-firstpart);
	}
}