mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-02-12 01:29:29 +00:00
avcodec/mjpegdec: Simplify creating VLC table
ff_init_vlc_from_lengths() can be used to offload the computation of the codes; it also allows to omit the check whether the codes are already properly ordered (they are). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
d4a4a6747d
commit
cd7c3ac84d
@ -50,33 +50,28 @@
|
|||||||
#include "bytestream.h"
|
#include "bytestream.h"
|
||||||
|
|
||||||
|
|
||||||
static void build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
|
static void build_huffman_codes(uint8_t *huff_size, const uint8_t *bits_table)
|
||||||
const uint8_t *bits_table)
|
|
||||||
{
|
{
|
||||||
for (int i = 1, code = 0, k = 0; i <= 16; i++) {
|
for (int i = 1, k = 0; i <= 16; i++) {
|
||||||
int nb = bits_table[i];
|
int nb = bits_table[i];
|
||||||
for (int j = 0; j < nb;j++) {
|
for (int j = 0; j < nb;j++) {
|
||||||
huff_size[k] = i;
|
huff_size[k] = i;
|
||||||
huff_code[k] = code;
|
|
||||||
code++;
|
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
code <<= 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int build_vlc(VLC *vlc, const uint8_t *bits_table,
|
static int build_vlc(VLC *vlc, const uint8_t *bits_table,
|
||||||
const uint8_t *val_table, int nb_codes,
|
const uint8_t *val_table, int nb_codes,
|
||||||
int is_ac)
|
int is_ac, void *logctx)
|
||||||
{
|
{
|
||||||
uint8_t huff_size[256];
|
uint8_t huff_size[256];
|
||||||
uint16_t huff_code[256];
|
|
||||||
uint16_t huff_sym[256];
|
uint16_t huff_sym[256];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
av_assert0(nb_codes <= 256);
|
av_assert0(nb_codes <= 256);
|
||||||
|
|
||||||
build_huffman_codes(huff_size, huff_code, bits_table);
|
build_huffman_codes(huff_size, bits_table);
|
||||||
|
|
||||||
for (i = 0; i < nb_codes; i++) {
|
for (i = 0; i < nb_codes; i++) {
|
||||||
huff_sym[i] = val_table[i] + 16 * is_ac;
|
huff_sym[i] = val_table[i] + 16 * is_ac;
|
||||||
@ -85,8 +80,8 @@ static int build_vlc(VLC *vlc, const uint8_t *bits_table,
|
|||||||
huff_sym[i] = 16 * 256;
|
huff_sym[i] = 16 * 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ff_init_vlc_sparse(vlc, 9, nb_codes, huff_size, 1, 1,
|
return ff_init_vlc_from_lengths(vlc, 9, nb_codes, huff_size, 1,
|
||||||
huff_code, 2, 2, huff_sym, 2, 2, 0);
|
huff_sym, 2, 2, 0, 0, logctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_default_huffman_tables(MJpegDecodeContext *s)
|
static int init_default_huffman_tables(MJpegDecodeContext *s)
|
||||||
@ -116,7 +111,7 @@ static int init_default_huffman_tables(MJpegDecodeContext *s)
|
|||||||
for (i = 0; i < FF_ARRAY_ELEMS(ht); i++) {
|
for (i = 0; i < FF_ARRAY_ELEMS(ht); i++) {
|
||||||
ret = build_vlc(&s->vlcs[ht[i].class][ht[i].index],
|
ret = build_vlc(&s->vlcs[ht[i].class][ht[i].index],
|
||||||
ht[i].bits, ht[i].values, ht[i].length,
|
ht[i].bits, ht[i].values, ht[i].length,
|
||||||
ht[i].class == 1);
|
ht[i].class == 1, s->avctx);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -296,13 +291,13 @@ int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
|
|||||||
av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n",
|
av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n",
|
||||||
class, index, n);
|
class, index, n);
|
||||||
if ((ret = build_vlc(&s->vlcs[class][index], bits_table, val_table,
|
if ((ret = build_vlc(&s->vlcs[class][index], bits_table, val_table,
|
||||||
n, class > 0)) < 0)
|
n, class > 0, s->avctx)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (class > 0) {
|
if (class > 0) {
|
||||||
ff_free_vlc(&s->vlcs[2][index]);
|
ff_free_vlc(&s->vlcs[2][index]);
|
||||||
if ((ret = build_vlc(&s->vlcs[2][index], bits_table, val_table,
|
if ((ret = build_vlc(&s->vlcs[2][index], bits_table, val_table,
|
||||||
n, 0)) < 0)
|
n, 0, s->avctx)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user