From bb330398b92d9a304aa301e7db527ce762693b83 Mon Sep 17 00:00:00 2001 From: Tim Hall Date: Wed, 29 Apr 2020 15:13:00 +0100 Subject: Apply fixes to mlw_encoder - Fix weight encoder palette allocation Change-Id: If79655f65cfb4820bf0f8ba6472b3df940b1e44b Signed-off-by: Tim Hall --- ethosu/mlw_codec/mlw_encode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ethosu/mlw_codec/mlw_encode.c b/ethosu/mlw_codec/mlw_encode.c index ac25fc52..7820106e 100644 --- a/ethosu/mlw_codec/mlw_encode.c +++ b/ethosu/mlw_codec/mlw_encode.c @@ -65,7 +65,7 @@ static int search_palette_sections( int16_t *buf, int size, int **palette_restar int i,j,got_palette,restart_i,palette_size=0, last_restart_idx, zero_cnt; int prev_idx[512]; // For each value, keep track of the index of the previous occurence int *restart_pos; - int max_palettes = size/64; + int max_palettes = (size+63)/64; // Preliminary allocation of sufficient size restart_pos = (int*)malloc( max_palettes*sizeof(int) ); @@ -89,7 +89,10 @@ static int search_palette_sections( int16_t *buf, int size, int **palette_restar if ( (i - last_restart_idx - zero_cnt) > 512 || (palette_size-exclude_zero)>32 ) { // create a new palette because we extend a long lasting palette to require one more index bit DPRINTF("Note: at pos %d create new palette because previous has to increase one more index bit. last_restart_idx %d n %d zero_cnt %d\n", i, last_restart_idx, i - last_restart_idx, zero_cnt ); - assert( restart_i < max_palettes ); + if (restart_i == max_palettes) { + max_palettes = max_palettes*2; + restart_pos = (int*)realloc( restart_pos, max_palettes*sizeof(int) ); + } DPRINTF("restart %d pos %d\n", restart_i, i); restart_pos[restart_i++] = i; last_restart_idx = i; @@ -154,7 +157,10 @@ static int search_palette_sections( int16_t *buf, int size, int **palette_restar last_restart_idx = restart_idx; DPRINTF("Note: at pos %d create palette of size %d\n", last_restart_idx, new_palette_size); if ( restart_pos[restart_i-1] != last_restart_idx) { - assert( restart_i < max_palettes ); + if (restart_i == max_palettes) { + max_palettes = max_palettes*2; + restart_pos = (int*)realloc( restart_pos, max_palettes*sizeof(int) ); + } restart_pos[restart_i++] = last_restart_idx; } zero_cnt=0; -- cgit v1.2.1