ReactOS 0.4.15-dev-7907-g95bf896
lzx_compress.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  lzx_results
 

Typedefs

typedef struct lzx_data lzx_data
 
typedef int(* lzx_get_bytes_t) (void *arg, int n, void *buf)
 
typedef int(* lzx_put_bytes_t) (void *arg, int n, void *buf)
 
typedef void(* lzx_mark_frame_t) (void *arg, uint32_t uncomp, uint32_t comp)
 
typedef int(* lzx_at_eof_t) (void *arg)
 
typedef struct lzx_results lzx_results
 

Functions

int lzx_init (struct lzx_data **lzxdp, int wsize_code, lzx_get_bytes_t get_bytes, void *get_bytes_arg, lzx_at_eof_t at_eof, lzx_put_bytes_t put_bytes, void *put_bytes_arg, lzx_mark_frame_t mark_frame, void *mark_frame_arg)
 
void lzx_reset (lzx_data *lzxd)
 
int lzx_compress_block (lzx_data *lzxd, int block_size, int subdivide)
 
int lzx_finish (struct lzx_data *lzxd, struct lzx_results *lzxr)
 

Typedef Documentation

◆ lzx_at_eof_t

typedef int(* lzx_at_eof_t) (void *arg)

Definition at line 22 of file lzx_compress.h.

◆ lzx_data

Definition at line 18 of file lzx_compress.h.

◆ lzx_get_bytes_t

typedef int(* lzx_get_bytes_t) (void *arg, int n, void *buf)

Definition at line 19 of file lzx_compress.h.

◆ lzx_mark_frame_t

typedef void(* lzx_mark_frame_t) (void *arg, uint32_t uncomp, uint32_t comp)

Definition at line 21 of file lzx_compress.h.

◆ lzx_put_bytes_t

typedef int(* lzx_put_bytes_t) (void *arg, int n, void *buf)

Definition at line 20 of file lzx_compress.h.

◆ lzx_results

Function Documentation

◆ lzx_compress_block()

int lzx_compress_block ( lzx_data lzxd,
int  block_size,
int  subdivide 
)

Definition at line 1062 of file lzx_layer.c.

1063{
1064 int i;
1065 uint32_t written_sofar = 0;
1066 int block_type;
1067 long uncomp_bits;
1068 long comp_bits;
1069 long comp_bits_ovh;
1070 long uncomp_length;
1071
1072 if ((lzxd->block_size != block_size) || (lzxd->block_codes == NULL)) {
1073 if (lzxd->block_codes != NULL) free(lzxd->block_codes);
1074 lzxd->block_size = block_size;
1075 lzxd->block_codes = malloc(block_size * sizeof(uint32_t));
1076 }
1077 lzxd->subdivide = subdivide?1:0;
1078
1079 lzxd->left_in_block = block_size;
1081 lzxd->main_entropy = 0.0;
1082 lzxd->last_ratio = 9999999.0;
1083 lzxd->block_codesp = lzxd->block_codes;
1084
1085 memset(lzxd->length_freq_table, 0, NUM_SECONDARY_LENGTHS * sizeof(int));
1086 memset(lzxd->main_freq_table, 0, lzxd->main_tree_size * sizeof(int));
1087 memset(lzxd->aligned_freq_table, 0, LZX_ALIGNED_SIZE * sizeof(int));
1088 do {
1089 lz_compress(lzxd->lzi, lzxd->left_in_block);
1090 if (lzxd->left_in_frame == 0)
1092
1093 if ((lzxd->subdivide<0) || !lzxd->left_in_block ||
1094 (!lz_left_to_process(lzxd->lzi) && lzxd->at_eof(lzxd->in_arg))) {
1095 /* now one block is LZ-analyzed. */
1096 /* time to write it out */
1097 uncomp_length = lzxd->block_size - lzxd->left_in_block - written_sofar;
1098 /* uncomp_length will sometimes be 0 when input length is
1099 an exact multiple of frame size */
1100 if (uncomp_length == 0)
1101 continue;
1102 if (lzxd->subdivide < 0) {
1103#ifdef DEBUG_ENTROPY
1104 fprintf(stderr, "subdivided\n");
1105#endif
1106 lzxd->subdivide = 1;
1107 }
1108
1109 if (lzxd->need_1bit_header) {
1110 /* one bit Intel preprocessing header */
1111 /* always 0 because this implementation doesn't do Intel preprocessing */
1112 lzx_write_bits(lzxd, 1, 0);
1113 lzxd->need_1bit_header = 0;
1114 }
1115
1116 /* handle extra bits */
1117 uncomp_bits = comp_bits = 0;
1119 for (i = 0; i < LZX_ALIGNED_SIZE; i++) {
1120 uncomp_bits += lzxd->aligned_freq_table[i]* 3;
1121 comp_bits += lzxd->aligned_freq_table[i]* lzxd->aligned_tree[i].codelength;
1122 }
1123 comp_bits_ovh = comp_bits + LZX_ALIGNED_SIZE * 3;
1124 if (comp_bits_ovh < uncomp_bits)
1125 block_type = LZX_ALIGNED_OFFSET_BLOCK;
1126 else
1127 block_type = LZX_VERBATIM_BLOCK;
1128
1129#ifdef DEBUG_EXTRA_BITS
1130 fprintf(stderr, "Extra bits uncompressed: %5d compressed: %5d compressed w/overhead %5d gain/loss %5d\n", uncomp_bits, comp_bits, comp_bits_ovh, uncomp_bits - comp_bits_ovh);
1131#endif
1132
1133 /* block type */
1134 lzx_write_bits(lzxd, 3, block_type);
1135 /* uncompressed length */
1136 lzx_write_bits(lzxd, 24, uncomp_length);
1137
1138 written_sofar = lzxd->block_size - lzxd->left_in_block;
1139
1140 /* now write out the aligned offset trees if present */
1141 if (block_type == LZX_ALIGNED_OFFSET_BLOCK) {
1142 for (i = 0; i < LZX_ALIGNED_SIZE; i++) {
1143 lzx_write_bits(lzxd, 3, lzxd->aligned_tree[i].codelength);
1144 }
1145 }
1146 /* end extra bits */
1148 lzxd->main_freq_table, lzxd->main_tree);
1150 lzxd->length_freq_table, lzxd->length_tree);
1151
1152
1153
1154 /* now write the pre-tree and tree for main 1 */
1156
1157 /* now write the pre-tree and tree for main 2*/
1160 lzxd->main_tree_size - NUM_CHARS);
1161
1162 /* now write the pre tree and tree for length */
1165
1166 /* now write literals */
1167 lzx_write_compressed_literals(lzxd, block_type);
1168
1169 /* copy treelengths somewhere safe to do delta compression */
1170 for (i = 0; i < lzxd->main_tree_size; i++) {
1172 }
1173 for (i = 0; i < NUM_SECONDARY_LENGTHS; i++) {
1175 }
1176 lzxd->main_entropy = 0.0;
1177 lzxd->last_ratio = 9999999.0;
1178 lzxd->block_codesp = lzxd->block_codes;
1179
1180 memset(lzxd->length_freq_table, 0, NUM_SECONDARY_LENGTHS * sizeof(int));
1181 memset(lzxd->main_freq_table, 0, lzxd->main_tree_size * sizeof(int));
1182 memset(lzxd->aligned_freq_table, 0, LZX_ALIGNED_SIZE * sizeof(int));
1183 }
1184 }
1185 while (lzxd->left_in_block && (lz_left_to_process(lzxd->lzi) || !lzxd->at_eof(lzxd->in_arg)));
1186 return 0;
1187}
#define NUM_CHARS
Definition: chargen.c:15
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
UINT32 uint32_t
Definition: types.h:75
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#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 DWORD block_size(DWORD block)
Definition: jsutils.c:66
int lz_compress(lz_info *lzi, int nchars)
Definition: lz_nonslide.c:289
int lz_left_to_process(lz_info *lzi)
Definition: lz_nonslide.c:142
#define LZX_ALIGNED_SIZE
Definition: lzx_constants.h:37
#define LZX_MAX_CODE_LENGTH
Definition: lzx_constants.h:33
#define LZX_FRAME_SIZE
Definition: lzx_constants.h:34
#define LZX_ALIGNED_OFFSET_BLOCK
Definition: lzx_constants.h:40
#define LZX_VERBATIM_BLOCK
Definition: lzx_constants.h:39
#define NUM_SECONDARY_LENGTHS
Definition: lzx_constants.h:30
static void lzx_write_compressed_literals(lzx_data *lzxd, int block_type)
Definition: lzx_layer.c:845
static void lzx_write_bits(lzx_data *lzxd, int nbits, uint32_t bits)
Definition: lzx_layer.c:787
static void build_huffman_tree(int nelem, int max_code_length, int *freq, huff_entry *tree)
Definition: lzx_layer.c:111
static int lzx_write_compressed_tree(struct lzx_data *lzxd, struct huff_entry *tree, uint8_t *prevlengths, int treesize)
Definition: lzx_layer.c:930
#define memset(x, y, z)
Definition: compat.h:39
short codelength
Definition: lzx_layer.c:73
void * in_arg
Definition: lzx_layer.c:394
int left_in_frame
Definition: lzx_layer.c:404
short need_1bit_header
Definition: lzx_layer.c:427
lzx_at_eof_t at_eof
Definition: lzx_layer.c:398
short subdivide
Definition: lzx_layer.c:428
double last_ratio
Definition: lzx_layer.c:422
int length_freq_table[NUM_SECONDARY_LENGTHS]
Definition: lzx_layer.c:411
uint32_t * block_codesp
Definition: lzx_layer.c:414
int main_tree_size
Definition: lzx_layer.c:418
huff_entry aligned_tree[LZX_ALIGNED_SIZE]
Definition: lzx_layer.c:417
uint8_t * prev_main_treelengths
Definition: lzx_layer.c:423
int block_size
Definition: lzx_layer.c:409
struct lz_info * lzi
Definition: lzx_layer.c:401
int left_in_block
Definition: lzx_layer.c:405
int * main_freq_table
Definition: lzx_layer.c:410
uint32_t * block_codes
Definition: lzx_layer.c:413
huff_entry length_tree[NUM_SECONDARY_LENGTHS]
Definition: lzx_layer.c:416
double main_entropy
Definition: lzx_layer.c:421
int aligned_freq_table[LZX_ALIGNED_SIZE]
Definition: lzx_layer.c:412
uint8_t prev_length_treelengths[NUM_SECONDARY_LENGTHS]
Definition: lzx_layer.c:424
huff_entry * main_tree
Definition: lzx_layer.c:415

Referenced by chmc_crunch_lzx().

◆ lzx_finish()

int lzx_finish ( struct lzx_data lzxd,
struct lzx_results lzxr 
)

Definition at line 1236 of file lzx_layer.c.

1237{
1238 /* lzx_align_output(lzxd); Not needed as long as frame padding is in place */
1239 if (lzxr) {
1242 }
1243 lz_release(lzxd->lzi);
1244 free(lzxd->lzi);
1246 free(lzxd->main_tree);
1247 free(lzxd->main_freq_table);
1248 free(lzxd);
1249 return 0;
1250}
void lz_release(lz_info *lzi)
Definition: lz_nonslide.c:83
uint32_t len_uncompressed_input
Definition: lzx_layer.c:425
uint32_t len_compressed_output
Definition: lzx_layer.c:426
long len_compressed_output
Definition: lzx_compress.h:27
long len_uncompressed_input
Definition: lzx_compress.h:28

Referenced by chmc_crunch_lzx().

◆ lzx_init()

int lzx_init ( struct lzx_data **  lzxdp,
int  wsize_code,
lzx_get_bytes_t  get_bytes,
void get_bytes_arg,
lzx_at_eof_t  at_eof,
lzx_put_bytes_t  put_bytes,
void put_bytes_arg,
lzx_mark_frame_t  mark_frame,
void mark_frame_arg 
)

Definition at line 1189 of file lzx_layer.c.

1194{
1195 int wsize;
1196 struct lzx_data *lzxd;
1197
1198 if ((wsize_code < 15) || (wsize_code > 21)) {
1199 return -1;
1200 }
1202
1203 *lzxdp = lzxd = malloc(sizeof(*lzxd));
1204 if (lzxd == 0)
1205 return -2;
1206
1207 lzxd->in_arg = get_bytes_arg;
1208 lzxd->out_arg = put_bytes_arg;
1210 lzxd->get_bytes = get_bytes;
1211 lzxd->put_bytes = put_bytes;
1212 lzxd->at_eof = at_eof;
1213 lzxd->mark_frame = mark_frame;
1214
1215 wsize = 1 << (wsize_code);
1216
1217 lzxd->bits_in_buf = 0;
1218 lzxd->block_codes = NULL;
1219 lzxd->num_position_slots = num_position_slots[wsize_code-15];
1220 lzxd->main_tree_size = (NUM_CHARS + 8 * lzxd->num_position_slots);
1221
1222 lzxd->main_freq_table = malloc(sizeof(int) * lzxd->main_tree_size);
1223 lzxd->main_tree = malloc(sizeof(huff_entry)* lzxd->main_tree_size);
1224 lzxd->prev_main_treelengths = malloc(sizeof(uint8_t)*lzxd->main_tree_size);
1225
1226 lzxd->lzi = malloc(sizeof (*lzxd->lzi));
1227 /* the -3 prevents matches at wsize, wsize-1, wsize-2, all of which are illegal */
1228 lz_init(lzxd->lzi, wsize, wsize - 3, MAX_MATCH, MIN_MATCH, LZX_FRAME_SIZE,
1230 lzxd->len_uncompressed_input = 0;
1231 lzxd->len_compressed_output = 0;
1232 lzx_reset(lzxd);
1233 return 0;
1234}
#define MIN_MATCH
Definition: zutil.h:64
#define MAX_MATCH
Definition: zutil.h:65
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: lz_nonslide.c:42
short num_position_slots[]
Definition: lzx_layer.c:50
static void lzx_output_literal(lz_info *lzi, u_char ch)
Definition: lzx_layer.c:771
static int lzx_output_match(lz_info *lzi, int match_pos, int match_len)
Definition: lzx_layer.c:596
void lzx_reset(lzx_data *lzxd)
Definition: lzx_layer.c:1053
static void lzx_init_static(void)
Definition: lzx_layer.c:374
static int lzx_get_chars(lz_info *lzi, int n, u_char *buf)
Definition: lzx_layer.c:432
BYTE uint8_t
Definition: msvideo1.c:66
Definition: lzx_layer.c:72
void * mark_frame_arg
Definition: lzx_layer.c:396
int num_position_slots
Definition: lzx_layer.c:407
void * out_arg
Definition: lzx_layer.c:395
lzx_put_bytes_t put_bytes
Definition: lzx_layer.c:399
int bits_in_buf
Definition: lzx_layer.c:420
lzx_mark_frame_t mark_frame
Definition: lzx_layer.c:400
lzx_get_bytes_t get_bytes
Definition: lzx_layer.c:397

Referenced by chmc_crunch_lzx().

◆ lzx_reset()

void lzx_reset ( lzx_data lzxd)

Definition at line 1053 of file lzx_layer.c.

1054{
1055 lzxd->need_1bit_header = 1;
1056 lzxd->R0 = lzxd->R1 = lzxd->R2 = 1;
1057 memset(lzxd->prev_main_treelengths, 0, lzxd->main_tree_size * sizeof(uint8_t));
1059 lz_reset(lzxd->lzi);
1060}
void lz_reset(lz_info *lzi)
Definition: lz_nonslide.c:90
int R2
Definition: lzx_layer.c:406
int R1
Definition: lzx_layer.c:406
int R0
Definition: lzx_layer.c:406

Referenced by chmc_crunch_lzx(), and lzx_init().