#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavutil/pixdesc.h"
-#include "libavutil/timer.h"
#include "avcodec.h"
#include "internal.h"
40, 40, 41, 79, 43, 44, 45, 45, 48, 48, 64, 50, 51, 52, 88, 52,
53, 74, 55, 57, 58, 58, 74, 60, 101, 61, 62, 84, 66, 66, 68, 69,
87, 82, 71, 97, 73, 73, 82, 75, 111, 77, 94, 78, 87, 81, 83, 97,
- 85, 83, 94, 86, 99, 89, 90, 99, 111, 92, 93, 134, 95, 98, 105, 98,
+ 85, 83, 94, 86, 99, 89, 90, 99, 111, 92, 93, 134, 95, 98, 105, 98,
105, 110, 102, 108, 102, 118, 103, 106, 106, 113, 109, 112, 114, 112, 116, 125,
115, 116, 117, 117, 126, 119, 125, 121, 121, 123, 145, 124, 126, 131, 127, 129,
165, 130, 132, 138, 133, 135, 145, 136, 137, 139, 146, 141, 143, 142, 144, 148,
sample[0][-1]= sample[1][0 ];
sample[1][ w]= sample[1][w-1];
-// { START_TIMER
if (s->bits_per_raw_sample <= 8) {
for (x = 0; x < w; x++)
sample[0][x] = src[x * pixel_stride + stride * y];
if((ret = encode_line(s, w, sample, plane_index, s->bits_per_raw_sample)) < 0)
return ret;
}
-// STOP_TIMER("encode line") }
}
return 0;
}
write_quant_table(c, quant_table[i]);
}
+static int contains_non_128(uint8_t (*initial_state)[CONTEXT_SIZE],
+ int nb_contexts)
+{
+ if (!initial_state)
+ return 0;
+ for (int i = 0; i < nb_contexts; i++)
+ for (int j = 0; j < CONTEXT_SIZE; j++)
+ if (initial_state[i][j] != 128)
+ return 1;
+ return 0;
+}
+
static void write_header(FFV1Context *f)
{
uint8_t state[CONTEXT_SIZE];
write_quant_tables(c, f->quant_tables[i]);
for (i = 0; i < f->quant_table_count; i++) {
- for (j = 0; j < f->context_count[i] * CONTEXT_SIZE; j++)
- if (f->initial_states[i] && f->initial_states[i][0][j] != 128)
- break;
- if (j < f->context_count[i] * CONTEXT_SIZE) {
+ if (contains_non_128(f->initial_states[i], f->context_count[i])) {
put_rac(c, state, 1);
for (j = 0; j < f->context_count[i]; j++)
for (k = 0; k < CONTEXT_SIZE; k++) {
put_symbol(c, state, f->intra = (f->avctx->gop_size < 2), 0);
}
- f->avctx->extradata_size = ff_rac_terminate(c);
+ f->avctx->extradata_size = ff_rac_terminate(c, 0);
v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size);
AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v);
f->avctx->extradata_size += 4;
s->ec = (s->version >= 3);
}
+ // CRC requires version 3+
+ if (s->ec)
+ s->version = FFMAX(s->version, 3);
+
if ((s->version == 2 || s->version>3) && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
av_log(avctx, AV_LOG_ERROR, "Version 2 needed for requested features but version 2 is experimental and not enabled\n");
return AVERROR_INVALIDDATA;
case AV_PIX_FMT_YUVA420P:
s->chroma_planes = desc->nb_components < 3 ? 0 : 1;
s->colorspace = 0;
- s->transparency = desc->nb_components == 4 || desc->nb_components == 2;
+ s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample)
s->bits_per_raw_sample = 8;
else if (!s->bits_per_raw_sample)
s->bits_per_raw_sample = 16;
else if (!s->bits_per_raw_sample)
s->bits_per_raw_sample = avctx->bits_per_raw_sample;
- s->transparency = desc->nb_components == 4 || desc->nb_components == 2;
+ s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
s->colorspace = 1;
s->chroma_planes = 1;
if (s->bits_per_raw_sample >= 16) {
encode_slice_header(f, fs);
}
if (fs->ac == AC_GOLOMB_RICE) {
- if (f->version > 2)
- put_rac(&fs->c, (uint8_t[]) { 129 }, 0);
- fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c) : 0;
+ fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0;
init_put_bits(&fs->pb,
fs->c.bytestream_start + fs->ac_byte_count,
fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count);
int bytes;
if (fs->ac != AC_GOLOMB_RICE) {
- uint8_t state = 129;
- put_rac(&fs->c, &state, 0);
- bytes = ff_rac_terminate(&fs->c);
+ bytes = ff_rac_terminate(&fs->c, 1);
} else {
flush_put_bits(&fs->pb); // FIXME: nicer padding
bytes = fs->ac_byte_count + (put_bits_count(&fs->pb) + 7) / 8;