From a4d269030976e04d9db0ae9e9c0ed21865048936 Mon Sep 17 00:00:00 2001 From: Tobias Bindhammer Date: Tue, 5 Oct 2010 12:14:14 +0000 Subject: [PATCH] Introduce palette with dynamic size. Originally committed as revision 25344 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/a64enc.h | 2 ++ libavcodec/a64multienc.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libavcodec/a64enc.h b/libavcodec/a64enc.h index caa4891e09..fb559ba82b 100644 --- a/libavcodec/a64enc.h +++ b/libavcodec/a64enc.h @@ -48,6 +48,8 @@ typedef struct A64Context { int mc_luma_vals[5]; uint8_t *mc_charset; uint8_t *mc_colram; + uint8_t *mc_palette; + int mc_pal_size; } A64Context; #endif /* AVCODEC_A64ENC_H */ diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c index 5e127e1515..6b3d79787b 100644 --- a/libavcodec/a64multienc.c +++ b/libavcodec/a64multienc.c @@ -86,16 +86,16 @@ static void render_charset(AVCodecContext *avctx, uint8_t *charset, /* generate lookup-tables for dither and index before looping */ i = 0; for (a=0; a < 256; a++) { - if(i < 4 && a == c->mc_luma_vals[i+1]) { + if(i < c->mc_pal_size -1 && a == c->mc_luma_vals[i+1]) { distance = c->mc_luma_vals[i+1] - c->mc_luma_vals[i]; for(b = 0; b <= distance; b++) { dither[c->mc_luma_vals[i]+b] = b * (DITHERSTEPS - 1) / distance; } i++; } - if(i >=4 ) dither[a] = 0; + if(i >= c->mc_pal_size - 1) dither[a] = 0; index1[a] = i; - index2[a] = FFMIN(i+1, 4); + index2[a] = FFMIN(i+1, c->mc_pal_size - 1); } /* and render charset */ for (charpos = 0; charpos < CHARSET_CHARS; charpos++) { @@ -183,16 +183,17 @@ static av_cold int a64multi_init_encoder(AVCodecContext *avctx) av_log(avctx, AV_LOG_INFO, "charset lifetime set to %d frame(s)\n", c->mc_lifetime); + c->mc_frame_counter = 0; + c->mc_use_5col = avctx->codec->id == CODEC_ID_A64_MULTI5; + c->mc_pal_size = 4 + c->mc_use_5col; + /* precalc luma values for later use */ - for (a = 0; a < 5; a++) { + for (a = 0; a < c->mc_pal_size; a++) { c->mc_luma_vals[a]=a64_palette[mc_colors[a]][0] * 0.30 + a64_palette[mc_colors[a]][1] * 0.59 + a64_palette[mc_colors[a]][2] * 0.11; } - c->mc_frame_counter = 0; - c->mc_use_5col = avctx->codec->id == CODEC_ID_A64_MULTI5; - if(!(c->mc_meta_charset = av_malloc (32000 * c->mc_lifetime * sizeof(int))) || !(c->mc_best_cb = av_malloc (CHARSET_CHARS * 32 * sizeof(int))) || !(c->mc_charmap = av_mallocz(1000 * c->mc_lifetime * sizeof(int))) ||