#include "avcodec.h"
#include "blockdsp.h"
#include "copy_block.h"
-#include "hwaccel.h"
+#include "hwconfig.h"
#include "idctdsp.h"
#include "internal.h"
#include "jpegtables.h"
#include "bytestream.h"
+static void build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
+ const uint8_t *bits_table)
+{
+ for (int i = 1, code = 0, k = 0; i <= 16; i++) {
+ int nb = bits_table[i];
+ for (int j = 0; j < nb;j++) {
+ huff_size[k] = i;
+ huff_code[k] = code;
+ code++;
+ k++;
+ }
+ code <<= 1;
+ }
+}
+
static int build_vlc(VLC *vlc, const uint8_t *bits_table,
const uint8_t *val_table, int nb_codes,
- int use_static, int is_ac)
+ int is_ac)
{
- uint8_t huff_size[256] = { 0 };
+ uint8_t huff_size[256];
uint16_t huff_code[256];
uint16_t huff_sym[256];
int i;
av_assert0(nb_codes <= 256);
- ff_mjpeg_build_huffman_codes(huff_size, huff_code, bits_table, val_table);
+ build_huffman_codes(huff_size, huff_code, bits_table);
- for (i = 0; i < 256; i++)
- huff_sym[i] = i + 16 * is_ac;
+ for (i = 0; i < nb_codes; i++) {
+ huff_sym[i] = val_table[i] + 16 * is_ac;
- if (is_ac)
- huff_sym[0] = 16 * 256;
+ if (is_ac && !val_table[i])
+ huff_sym[i] = 16 * 256;
+ }
return ff_init_vlc_sparse(vlc, 9, nb_codes, huff_size, 1, 1,
- huff_code, 2, 2, huff_sym, 2, 2, use_static);
+ huff_code, 2, 2, huff_sym, 2, 2, 0);
}
static int init_default_huffman_tables(MJpegDecodeContext *s)
int index;
const uint8_t *bits;
const uint8_t *values;
- int codes;
int length;
} ht[] = {
{ 0, 0, avpriv_mjpeg_bits_dc_luminance,
- avpriv_mjpeg_val_dc, 12, 12 },
+ avpriv_mjpeg_val_dc, 12 },
{ 0, 1, avpriv_mjpeg_bits_dc_chrominance,
- avpriv_mjpeg_val_dc, 12, 12 },
+ avpriv_mjpeg_val_dc, 12 },
{ 1, 0, avpriv_mjpeg_bits_ac_luminance,
- avpriv_mjpeg_val_ac_luminance, 251, 162 },
+ avpriv_mjpeg_val_ac_luminance, 162 },
{ 1, 1, avpriv_mjpeg_bits_ac_chrominance,
- avpriv_mjpeg_val_ac_chrominance, 251, 162 },
+ avpriv_mjpeg_val_ac_chrominance, 162 },
{ 2, 0, avpriv_mjpeg_bits_ac_luminance,
- avpriv_mjpeg_val_ac_luminance, 251, 162 },
+ avpriv_mjpeg_val_ac_luminance, 162 },
{ 2, 1, avpriv_mjpeg_bits_ac_chrominance,
- avpriv_mjpeg_val_ac_chrominance, 251, 162 },
+ avpriv_mjpeg_val_ac_chrominance, 162 },
};
int i, ret;
for (i = 0; i < FF_ARRAY_ELEMS(ht); i++) {
ret = build_vlc(&s->vlcs[ht[i].class][ht[i].index],
- ht[i].bits, ht[i].values, ht[i].codes,
- 0, ht[i].class == 1);
+ ht[i].bits, ht[i].values, ht[i].length,
+ ht[i].class == 1);
if (ret < 0)
return ret;
/* decode huffman tables and build VLC decoders */
int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
{
- int len, index, i, class, n, v, code_max;
+ int len, index, i, class, n, v;
uint8_t bits_table[17];
uint8_t val_table[256];
int ret = 0;
if (len < n || n > 256)
return AVERROR_INVALIDDATA;
- code_max = 0;
for (i = 0; i < n; i++) {
v = get_bits(&s->gb, 8);
- if (v > code_max)
- code_max = v;
val_table[i] = v;
}
len -= n;
/* build VLC and flush previous vlc if present */
ff_free_vlc(&s->vlcs[class][index]);
av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n",
- class, index, code_max + 1);
+ class, index, n);
if ((ret = build_vlc(&s->vlcs[class][index], bits_table, val_table,
- code_max + 1, 0, class > 0)) < 0)
+ n, class > 0)) < 0)
return ret;
if (class > 0) {
ff_free_vlc(&s->vlcs[2][index]);
if ((ret = build_vlc(&s->vlcs[2][index], bits_table, val_table,
- code_max + 1, 0, 0)) < 0)
+ n, 0)) < 0)
return ret;
}
}
}
+ if (s->bayer) {
+ if (pix_fmt_id != 0x11110000 && pix_fmt_id != 0x11000000)
+ goto unk_pixfmt;
+ }
+
switch (pix_fmt_id) {
case 0x11110000: /* for bayer-encoded huffman lossless JPEGs embedded in DNGs */
if (!s->bayer)