@ -52,12 +52,14 @@ static void heap_sift(HeapElem *h, int root, int size)
}
}
}
}
int ff_huff_gen_len_table ( uint8_t * dst , const uint64_t * stats , int size )
int ff_huff_gen_len_table ( uint8_t * dst , const uint64_t * stats , int stats_s ize , int skip0 )
{
{
HeapElem * h = av_malloc_array ( sizeof ( * h ) , size ) ;
HeapElem * h = av_malloc_array ( sizeof ( * h ) , stats_size ) ;
int * up = av_malloc_array ( sizeof ( * up ) * 2 , size ) ;
int * up = av_malloc_array ( sizeof ( * up ) * 2 , stats_size ) ;
uint8_t * len = av_malloc_array ( sizeof ( * len ) * 2 , size ) ;
uint8_t * len = av_malloc_array ( sizeof ( * len ) * 2 , stats_size ) ;
uint16_t * map = av_malloc_array ( sizeof ( * map ) , stats_size ) ;
int offset , i , next ;
int offset , i , next ;
int size = 0 ;
int ret = 0 ;
int ret = 0 ;
if ( ! h | | ! up | | ! len ) {
if ( ! h | | ! up | | ! len ) {
@ -65,10 +67,16 @@ int ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats, int size)
goto end ;
goto end ;
}
}
for ( i = 0 ; i < stats_size ; i + + ) {
dst [ i ] = 255 ;
if ( stats [ i ] | | ! skip0 )
map [ size + + ] = i ;
}
for ( offset = 1 ; ; offset < < = 1 ) {
for ( offset = 1 ; ; offset < < = 1 ) {
for ( i = 0 ; i < size ; i + + ) {
for ( i = 0 ; i < size ; i + + ) {
h [ i ] . name = i ;
h [ i ] . name = i ;
h [ i ] . val = ( stats [ i ] < < 14 ) + offset ;
h [ i ] . val = ( stats [ map [ i ] ] < < 14 ) + offset ;
}
}
for ( i = size / 2 - 1 ; i > = 0 ; i - - )
for ( i = size / 2 - 1 ; i > = 0 ; i - - )
heap_sift ( h , i , size ) ;
heap_sift ( h , i , size ) ;
@ -89,8 +97,8 @@ int ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats, int size)
for ( i = 2 * size - 3 ; i > = size ; i - - )
for ( i = 2 * size - 3 ; i > = size ; i - - )
len [ i ] = len [ up [ i ] ] + 1 ;
len [ i ] = len [ up [ i ] ] + 1 ;
for ( i = 0 ; i < size ; i + + ) {
for ( i = 0 ; i < size ; i + + ) {
dst [ i ] = len [ up [ i ] ] + 1 ;
dst [ map [ i ] ] = len [ up [ i ] ] + 1 ;
if ( dst [ i ] > = 32 ) break ;
if ( dst [ map [ i ] ] > = 32 ) break ;
}
}
if ( i = = size ) break ;
if ( i = = size ) break ;
}
}
@ -98,6 +106,7 @@ end:
av_free ( h ) ;
av_free ( h ) ;
av_free ( up ) ;
av_free ( up ) ;
av_free ( len ) ;
av_free ( len ) ;
av_free ( map ) ;
return ret ;
return ret ;
}
}