pngcrush  1.8.13
About: Pngcrush is an optimizer for PNG (Portable Network Graphics) files.
  Fossies Dox: pngcrush-1.8.13.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

trees.c File Reference
#include "deflate.h"
Include dependency graph for trees.c:

Go to the source code of this file.

Data Structures

struct  static_tree_desc_s
 

Macros

#define MAX_BL_BITS   7
 
#define END_BLOCK   256
 
#define REP_3_6   16
 
#define REPZ_3_10   17
 
#define REPZ_11_138   18
 
#define DIST_CODE_LEN   512 /* see definition of array dist_code below */
 
#define send_code(s, c, tree)   send_bits(s, tree[c].Code, tree[c].Len)
 
#define put_short(s, w)
 
#define send_bits(s, value, length)
 
#define SMALLEST   1
 
#define pqremove(s, tree, top)
 
#define smaller(tree, n, m, depth)
 

Functions

static void tr_static_init ()
 
static void init_block ()
 
static void pqdownheap ()
 
static void gen_bitlen ()
 
static void gen_codes ()
 
static void build_tree ()
 
static void scan_tree ()
 
static void send_tree ()
 
static int build_bl_tree ()
 
static void send_all_trees ()
 
static void compress_block ()
 
static int detect_data_type ()
 
static unsigned bi_reverse ()
 
static void bi_windup ()
 
static void bi_flush ()
 
void _tr_init (deflate_state *s)
 
static void init_block (deflate_state *s)
 
static void pqdownheap (deflate_state *s, ct_data *tree, int k)
 
static void gen_bitlen (deflate_state *s, tree_desc *desc)
 
static void gen_codes (ct_data *tree, int max_code, ushf *bl_count)
 
static void build_tree (deflate_state *s, tree_desc *desc)
 
static void scan_tree (deflate_state *s, ct_data *tree, int max_code)
 
static void send_tree (deflate_state *s, ct_data *tree, int max_code)
 
static int build_bl_tree (deflate_state *s)
 
static void send_all_trees (deflate_state *s, int lcodes, int dcodes, int blcodes)
 
void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int last)
 
void _tr_flush_bits (deflate_state *s)
 
void _tr_align (deflate_state *s)
 
void _tr_flush_block (deflate_state *s, charf *buf, ulg stored_len, int last)
 
int _tr_tally (deflate_state *s, unsigned dist, unsigned lc)
 
static void compress_block (deflate_state *s, const ct_data *ltree, const ct_data *dtree)
 
static int detect_data_type (deflate_state *s)
 
static unsigned bi_reverse (unsigned code, int len)
 
static void bi_flush (deflate_state *s)
 
static void bi_windup (deflate_state *s)
 

Variables

static const int extra_lbits [29] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}
 
static const int extra_dbits [30] = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}
 
static const int extra_blbits [19] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}
 
static const uch bl_order [19] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}
 
static ct_data static_ltree [(256+1+29)+2]
 
static ct_data static_dtree [30]
 
uch _dist_code [512]
 
uch _length_code [258 - 3+1]
 
static int base_length [29]
 
static int base_dist [30]
 
static const static_tree_desc static_l_desc
 
static const static_tree_desc static_d_desc
 
static const static_tree_desc static_bl_desc
 

Macro Definition Documentation

◆ DIST_CODE_LEN

#define DIST_CODE_LEN   512 /* see definition of array dist_code below */

Definition at line 81 of file trees.c.

◆ END_BLOCK

#define END_BLOCK   256

Definition at line 50 of file trees.c.

◆ MAX_BL_BITS

#define MAX_BL_BITS   7

Definition at line 47 of file trees.c.

◆ pqremove

#define pqremove (   s,
  tree,
  top 
)
Value:
{\
top = s->heap[SMALLEST]; \
s->heap[SMALLEST] = s->heap[s->heap_len--]; \
pqdownheap(s, tree, SMALLEST); \
}

Definition at line 430 of file trees.c.

◆ put_short

#define put_short (   s,
 
)
Value:
{ \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}

Definition at line 174 of file trees.c.

◆ REP_3_6

#define REP_3_6   16

Definition at line 53 of file trees.c.

◆ REPZ_11_138

#define REPZ_11_138   18

Definition at line 59 of file trees.c.

◆ REPZ_3_10

#define REPZ_3_10   17

Definition at line 56 of file trees.c.

◆ send_bits

#define send_bits (   s,
  value,
  length 
)
Value:
{ int len = length;\
if (s->bi_valid > (int)Buf_size - len) {\
int val = (int)value;\
s->bi_buf |= (ush)val << s->bi_valid;\
put_short(s, s->bi_buf);\
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
s->bi_valid += len - Buf_size;\
} else {\
s->bi_buf |= (ush)(value) << s->bi_valid;\
s->bi_valid += len;\
}\
}

Definition at line 211 of file trees.c.

◆ send_code

#define send_code (   s,
  c,
  tree 
)    send_bits(s, tree[c].Code, tree[c].Len)

Definition at line 161 of file trees.c.

◆ smaller

#define smaller (   tree,
  n,
  m,
  depth 
)
Value:
(tree[n].Freq < tree[m].Freq || \
(tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))

Definition at line 441 of file trees.c.

◆ SMALLEST

#define SMALLEST   1

Definition at line 422 of file trees.c.

Function Documentation

◆ _tr_align()

void _tr_align ( deflate_state s)

Definition at line 896 of file trees.c.

References bi_flush(), END_BLOCK, send_bits, send_code, static_ltree, and STATIC_TREES.

◆ _tr_flush_bits()

void _tr_flush_bits ( deflate_state s)

Definition at line 886 of file trees.c.

References bi_flush().

◆ _tr_flush_block()

◆ _tr_init()

void _tr_init ( deflate_state s)

Definition at line 379 of file trees.c.

References init_block(), static_bl_desc, static_d_desc, static_l_desc, and tr_static_init().

◆ _tr_stored_block()

void _tr_stored_block ( deflate_state s,
charf buf,
ulg  stored_len,
int  last 
)

Definition at line 863 of file trees.c.

References bi_windup(), put_short, send_bits, STORED_BLOCK, and zmemcpy().

Referenced by _tr_flush_block().

◆ _tr_tally()

int _tr_tally ( deflate_state s,
unsigned  dist,
unsigned  lc 
)

◆ bi_flush() [1/2]

static void bi_flush ( )
static

Referenced by _tr_align(), and _tr_flush_bits().

◆ bi_flush() [2/2]

static void bi_flush ( deflate_state s)
static

Definition at line 1173 of file trees.c.

References put_byte, and put_short.

◆ bi_reverse() [1/2]

static unsigned bi_reverse ( )
static

Referenced by gen_codes(), and tr_static_init().

◆ bi_reverse() [2/2]

static unsigned bi_reverse ( unsigned  code,
int  len 
)
static

Definition at line 1158 of file trees.c.

◆ bi_windup() [1/2]

static void bi_windup ( )
static

◆ bi_windup() [2/2]

static void bi_windup ( deflate_state s)
static

Definition at line 1190 of file trees.c.

References put_byte, and put_short.

◆ build_bl_tree() [1/2]

static int build_bl_tree ( )
static

Referenced by _tr_flush_block().

◆ build_bl_tree() [2/2]

static int build_bl_tree ( deflate_state s)
static

Definition at line 799 of file trees.c.

References BL_CODES, bl_order, build_tree(), scan_tree(), and Tracev.

◆ build_tree() [1/2]

static void build_tree ( )
static

Referenced by _tr_flush_block(), and build_bl_tree().

◆ build_tree() [2/2]

◆ compress_block() [1/2]

static void compress_block ( )
static

Referenced by _tr_flush_block().

◆ compress_block() [2/2]

static void compress_block ( deflate_state s,
const ct_data ltree,
const ct_data dtree 
)
static

◆ detect_data_type() [1/2]

static int detect_data_type ( )
static

Referenced by _tr_flush_block().

◆ detect_data_type() [2/2]

static int detect_data_type ( deflate_state s)
static

Definition at line 1124 of file trees.c.

References LITERALS, Z_BINARY, and Z_TEXT.

◆ gen_bitlen() [1/2]

static void gen_bitlen ( )
static

Referenced by build_tree().

◆ gen_bitlen() [2/2]

◆ gen_codes() [1/2]

static void gen_codes ( )
static

Referenced by build_tree(), and tr_static_init().

◆ gen_codes() [2/2]

static void gen_codes ( ct_data tree,
int  max_code,
ushf bl_count 
)
static

Definition at line 572 of file trees.c.

References Assert, bi_reverse(), Code, MAX_BITS, static_ltree, Tracecv, and Tracev.

◆ init_block() [1/2]

static void init_block ( )
static

Referenced by _tr_flush_block(), and _tr_init().

◆ init_block() [2/2]

static void init_block ( deflate_state s)
static

Definition at line 407 of file trees.c.

References BL_CODES, D_CODES, internal_state::dyn_ltree, END_BLOCK, and L_CODES.

◆ pqdownheap() [1/2]

static void pqdownheap ( )
static

Referenced by build_tree().

◆ pqdownheap() [2/2]

static void pqdownheap ( deflate_state s,
ct_data tree,
int  k 
)
static

Definition at line 451 of file trees.c.

References smaller.

◆ scan_tree() [1/2]

static void scan_tree ( )
static

Referenced by build_bl_tree().

◆ scan_tree() [2/2]

static void scan_tree ( deflate_state s,
ct_data tree,
int  max_code 
)
static

Definition at line 703 of file trees.c.

References REP_3_6, REPZ_11_138, and REPZ_3_10.

◆ send_all_trees() [1/2]

static void send_all_trees ( )
static

Referenced by _tr_flush_block().

◆ send_all_trees() [2/2]

static void send_all_trees ( deflate_state s,
int  lcodes,
int  dcodes,
int  blcodes 
)
static

Definition at line 834 of file trees.c.

References Assert, BL_CODES, bl_order, D_CODES, L_CODES, send_bits, send_tree(), and Tracev.

◆ send_tree() [1/2]

static void send_tree ( )
static

Referenced by send_all_trees().

◆ send_tree() [2/2]

static void send_tree ( deflate_state s,
ct_data tree,
int  max_code 
)
static

Definition at line 748 of file trees.c.

References Assert, REP_3_6, REPZ_11_138, REPZ_3_10, send_bits, and send_code.

◆ tr_static_init()

Variable Documentation

◆ _dist_code

uch _dist_code[512]

Definition at line 98 of file trees.c.

Referenced by tr_static_init().

◆ _length_code

uch _length_code[258 - 3+1]

Definition at line 104 of file trees.c.

Referenced by _tr_tally(), compress_block(), and tr_static_init().

◆ base_dist

int base_dist[30]
static

Definition at line 110 of file trees.c.

Referenced by compress_block(), and tr_static_init().

◆ base_length

int base_length[29]
static

Definition at line 107 of file trees.c.

Referenced by compress_block(), and tr_static_init().

◆ bl_order

const uch bl_order[19] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}
static

Definition at line 72 of file trees.c.

Referenced by build_bl_tree(), and send_all_trees().

◆ extra_blbits

const int extra_blbits[19] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}
static

Definition at line 69 of file trees.c.

Referenced by tr_static_init().

◆ extra_dbits

const int extra_dbits[30] = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}
static

Definition at line 66 of file trees.c.

Referenced by _tr_tally(), compress_block(), and tr_static_init().

◆ extra_lbits

const int extra_lbits[29] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}
static

Definition at line 63 of file trees.c.

Referenced by compress_block(), and tr_static_init().

◆ static_bl_desc

const static_tree_desc static_bl_desc
static
Initial value:
=
{(const ct_data *)0, extra_blbits, 0, 19 , 7 }

Definition at line 131 of file trees.c.

Referenced by _tr_init(), and tr_static_init().

◆ static_d_desc

const static_tree_desc static_d_desc
static
Initial value:
=
{static_dtree, extra_dbits, 0, 30 , 15 }

Definition at line 128 of file trees.c.

Referenced by _tr_init(), and tr_static_init().

◆ static_dtree

ct_data static_dtree[30]
static

Definition at line 93 of file trees.c.

Referenced by _tr_flush_block(), and tr_static_init().

◆ static_l_desc

const static_tree_desc static_l_desc
static
Initial value:
=
{static_ltree, extra_lbits, 256 +1, ( 256 +1+ 29 ) , 15 }

Definition at line 125 of file trees.c.

Referenced by _tr_init(), and tr_static_init().

◆ static_ltree

ct_data static_ltree[(256+1+29)+2]
static

Definition at line 86 of file trees.c.

Referenced by _tr_align(), _tr_flush_block(), gen_codes(), and tr_static_init().

static_ltree
static ct_data static_ltree[(256+1+29)+2]
Definition: trees.c:86
SMALLEST
#define SMALLEST
Definition: trees.c:422
uch
unsigned char uch
Definition: zutil.h:43
static_dtree
static ct_data static_dtree[30]
Definition: trees.c:93
ush
unsigned short ush
Definition: zutil.h:45
Buf_size
#define Buf_size
Definition: deflate.h:51
extra_blbits
static const int extra_blbits[19]
Definition: trees.c:69
ct_data_s
Definition: deflate.h:68
extra_lbits
static const int extra_lbits[29]
Definition: trees.c:63
length
png_uint_32 length
Definition: png.c:2253
put_short
#define put_short(s, w)
Definition: trees.c:174
extra_dbits
static const int extra_dbits[30]
Definition: trees.c:66