ReactOS 0.4.15-dev-7953-g1f49173
lz_nonslide.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  lz_info
 

Typedefs

typedef struct lz_info lz_info
 
typedef int(* get_chars_t) (lz_info *lzi, int n, u_char *buf)
 
typedef int(* output_match_t) (lz_info *lzi, int match_pos, int match_len)
 
typedef void(* output_literal_t) (lz_info *lzi, u_char ch)
 

Functions

void lz_init (lz_info *lzi, int wsize, int max_dist, int max_match, int min_match, int frame_size, get_chars_t get_chars, output_match_t output_match, output_literal_t output_literal, void *user_data)
 
void lz_release (lz_info *lzi)
 
void lz_reset (lz_info *lzi)
 
void lz_stop_compressing (lz_info *lzi)
 
int lz_left_to_process (lz_info *lzi)
 
int lz_compress (lz_info *lzi, int nchars)
 

Typedef Documentation

◆ get_chars_t

typedef int(* get_chars_t) (lz_info *lzi, int n, u_char *buf)

Definition at line 24 of file lz_nonslide.h.

◆ lz_info

Definition at line 23 of file lz_nonslide.h.

◆ output_literal_t

typedef void(* output_literal_t) (lz_info *lzi, u_char ch)

Definition at line 26 of file lz_nonslide.h.

◆ output_match_t

typedef int(* output_match_t) (lz_info *lzi, int match_pos, int match_len)

Definition at line 25 of file lz_nonslide.h.

Function Documentation

◆ lz_compress()

int lz_compress ( lz_info lzi,
int  nchars 
)

Definition at line 289 of file lz_nonslide.c.

290{
291
292 u_char *bbp, *bbe;
293 int *lentab, *lenp;
294 u_char **prevtab, **prevp;
295 int len;
296 int holdback;
297 short trimmed;
298
299 lzi->stop = 0;
300 while ((lz_left_to_process(lzi) || !lzi->eofcount) && !lzi->stop && nchars > 0) {
301#if 1
302 if (!lzi->analysis_valid ||
303 (!lzi->eofcount &&
304 ((lzi->chars_in_buf- lzi->block_loc) < nchars))) {
305 int residual = lzi->chars_in_buf - lzi->block_loc;
306 int bytes_to_move = lzi->max_dist + residual;
307 if (bytes_to_move > lzi->chars_in_buf)
308 bytes_to_move = lzi->chars_in_buf;
309#ifdef DEBUG_ANALYZE_BLOCK
310 fprintf(stderr, "Moving %06x, chars_in_buf %06x, residual = %06x, nchars= %06x block_loc = %06x\n", bytes_to_move, lzi->chars_in_buf, residual, nchars, lzi->block_loc);
311#endif
312 memmove(lzi->block_buf, lzi->block_buf + lzi->chars_in_buf - bytes_to_move,
313 bytes_to_move);
314
315 lzi->block_loc = bytes_to_move - residual;
316 lzi->chars_in_buf = bytes_to_move;
317#ifdef DEBUG_ANALYZE_BLOCK
318 fprintf(stderr, "New chars_in_buf %06x, new block_loc = %06x, eof = %1d\n", lzi->chars_in_buf, lzi->block_loc, lzi->eofcount);
319#endif
320 fill_blockbuf(lzi, nchars);
321#ifdef DEBUG_ANALYZE_BLOCK
322 fprintf(stderr, "Really new chars_in_buf %06x, new block_loc = %06x, eof = %1d\n", lzi->chars_in_buf, lzi->block_loc, lzi->eofcount);
323#endif
324 lz_analyze_block(lzi);
325 }
326#else
327 if (!lzi->analysis_valid ||
328 (lzi->block_loc - lzi->chars_in_buf) == 0) {
329 lzi->block_loc = 0;
330 lzi->chars_in_buf = 0;
331 fill_blockbuf(lzi, nchars);
332 lz_analyze_block(lzi);
333 }
334#endif
335 prevtab = prevp = lzi->prevtab + lzi->block_loc;
336 lentab = lenp = lzi->lentab + lzi->block_loc;
337 bbp = lzi->block_buf + lzi->block_loc;
338 holdback = lzi->max_match;
339 if (lzi->eofcount) holdback = 0;
340 if (lzi->chars_in_buf < (nchars + lzi->block_loc))
341 bbe = lzi->block_buf + lzi->chars_in_buf - holdback;
342 else
343 bbe = bbp + nchars;
344 while ((bbp < bbe) && (!lzi->stop)) {
345 trimmed = 0;
346 len = *lenp;
347 if (lzi->frame_size && (len > (lzi->frame_size - lzi->cur_loc % lzi->frame_size))) {
348#ifdef DEBUG_TRIMMING
349 fprintf(stderr, "Trim for framing: %06x %d %d\n", lzi->cur_loc,len, (lzi->frame_size - lzi->cur_loc % lzi->frame_size));
350#endif
351 trimmed = 1;
352 len = (lzi->frame_size - lzi->cur_loc % lzi->frame_size);
353 }
354 if (len > nchars) {
355#ifdef DEBUG_TRIMMING
356 fprintf(stderr, "Trim for blocking: %06x %d %d\n", lzi->cur_loc,len, nchars);
357#endif
358 trimmed = 1;
359 len = nchars;
360 }
361 if (len >= lzi->min_match) {
362#ifdef LAZY
363 if ((bbp < bbe -1) && !trimmed &&
364 ((lenp[1] > (len + 1)) /* || ((lenp[1] == len) && (prevp[1] > prevp[0])) */)) {
365 len = 1;
366 /* this is the lazy eval case */
367 }
368 else
369#endif
370 if (lzi->output_match(lzi, (*prevp - lzi->block_buf) - lzi->block_loc,
371 len) < 0) {
372 // fprintf(stderr, "Match rejected: %06x %d\n", lzi->cur_loc, len);
373 len = 1; /* match rejected */
374 }
375 }
376 else
377 len = 1;
378
379 if (len < lzi->min_match) {
380 assert(len == 1);
381 lzi->output_literal(lzi, *bbp);
382 }
383 // fprintf(stderr, "len = %3d, *lenp = %3d, cur_loc = %06x, block_loc = %06x\n", len, *lenp, lzi->cur_loc, lzi->block_loc);
384 bbp += len;
385 prevp += len;
386 lenp += len;
387 lzi->cur_loc += len;
388 lzi->block_loc += len;
389 assert(nchars >= len);
390 nchars -= len;
391
392 }
393 }
394 return 0;
395}
UCHAR u_char
Definition: types.h:80
#define assert(x)
Definition: debug.h:53
GLenum GLsizei len
Definition: glext.h:6722
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static void lz_analyze_block(lz_info *lzi)
Definition: lz_nonslide.c:165
static void fill_blockbuf(lz_info *lzi, int maxchars)
Definition: lz_nonslide.c:148
int lz_left_to_process(lz_info *lzi)
Definition: lz_nonslide.c:142
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
int frame_size
Definition: lz_nonslide.h:39
output_match_t output_match
Definition: lz_nonslide.h:48
int cur_loc
Definition: lz_nonslide.h:37
int chars_in_buf
Definition: lz_nonslide.h:36
int min_match
Definition: lz_nonslide.h:32
output_literal_t output_literal
Definition: lz_nonslide.h:49
short stop
Definition: lz_nonslide.h:44
u_char * block_buf
Definition: lz_nonslide.h:33
short analysis_valid
Definition: lz_nonslide.h:45
int max_match
Definition: lz_nonslide.h:31
int max_dist
Definition: lz_nonslide.h:40
short eofcount
Definition: lz_nonslide.h:43
u_char ** prevtab
Definition: lz_nonslide.h:41
int block_loc
Definition: lz_nonslide.h:38
int * lentab
Definition: lz_nonslide.h:42

Referenced by lzx_compress_block().

◆ lz_init()

void lz_init ( lz_info lzi,
int  wsize,
int  max_dist,
int  max_match,
int  min_match,
int  frame_size,
get_chars_t  get_chars,
output_match_t  output_match,
output_literal_t  output_literal,
void user_data 
)

Definition at line 42 of file lz_nonslide.c.

48{
49 /* the reason for the separate max_dist value is LZX can't reach the
50 first three characters in its nominal window. But using a smaller
51 window results in inefficiency when dealing with reset intervals
52 which are the length of the nominal window */
53
54 lzi->wsize = wsize;
55 if (max_match > wsize)
56 lzi->max_match = wsize;
57 else
58 lzi->max_match = max_match;
59
60 lzi->min_match = min_match;
61 if (lzi->min_match < 3) lzi->min_match = 3;
62
63 lzi->max_dist = max_dist;
64 lzi->block_buf_size = wsize + lzi->max_dist;
65 lzi->block_buf = malloc(lzi->block_buf_size);
66 lzi->block_bufe = lzi->block_buf + lzi->block_buf_size;
67 assert(lzi->block_buf != NULL);
68
69 lzi->cur_loc = 0;
70 lzi->block_loc = 0;
71 lzi->chars_in_buf = 0;
72 lzi->eofcount = 0;
73 lzi->get_chars = get_chars;
74 lzi->output_match = output_match;
75 lzi->output_literal = output_literal;
76 lzi->user_data = user_data;
77 lzi->frame_size = frame_size;
78 lzi->lentab = calloc(sizeof(int), lzi->block_buf_size);
79 lzi->prevtab = calloc(sizeof(u_char *), lzi->block_buf_size);
80 lzi->analysis_valid = 0;
81}
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define calloc
Definition: rosglue.h:14
int wsize
Definition: lz_nonslide.h:30
void * user_data
Definition: lz_nonslide.h:50
get_chars_t get_chars
Definition: lz_nonslide.h:47
u_char * block_bufe
Definition: lz_nonslide.h:34
int block_buf_size
Definition: lz_nonslide.h:35

Referenced by lzx_init().

◆ lz_left_to_process()

int lz_left_to_process ( lz_info lzi)

Definition at line 142 of file lz_nonslide.c.

143{
144 return lzi->chars_in_buf - lzi->block_loc;
145}

Referenced by fill_blockbuf(), lz_compress(), and lzx_compress_block().

◆ lz_release()

void lz_release ( lz_info lzi)

Definition at line 83 of file lz_nonslide.c.

84{
85 free(lzi->block_buf);
86 free(lzi->lentab);
87 free(lzi->prevtab);
88}
#define free
Definition: debug_ros.c:5

Referenced by lzx_finish().

◆ lz_reset()

void lz_reset ( lz_info lzi)

Definition at line 90 of file lz_nonslide.c.

91{
92 int residual = lzi->chars_in_buf - lzi->block_loc;
93 memmove(lzi->block_buf, lzi->block_buf + lzi->block_loc, residual);
94 lzi->chars_in_buf = residual;
95 lzi->block_loc = 0;
96 lzi->analysis_valid = 0;
97}

Referenced by lzx_reset().

◆ lz_stop_compressing()

void lz_stop_compressing ( lz_info lzi)

Definition at line 283 of file lz_nonslide.c.

284{
285 lzi->stop = 1;
286 /* fprintf(stderr, "Stopping...\n");*/
287}

Referenced by check_entropy().