45#define REMAP_MAX_LOG2_MUL_COUNT 10
46#define REMAP_MAX_MUL_COUNT (1 << REMAP_MAX_LOG2_MUL_COUNT)
47#define REMAP_MAX_LOG2_MUL 22
48#define FFV1_MAX_MUL_COUNT 4096
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
60 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
61 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
62 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
63 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
64 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
65 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
66 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
67 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
68 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
69 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
70 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
71 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1,
72 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
73 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
74 -1, -1, -1, -1, -1, -1, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0,
78 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
79 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
80 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
81 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
82 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
83 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
84 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
85 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
86 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
87 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
88 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
89 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
90 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
91 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
92 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
93 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1,
97 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
98 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
99 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
100 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
101 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
102 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
103 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
104 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
105 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
106 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
107 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
108 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
109 -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3,
110 -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
111 -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
112 -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -0, -0, -0, -0,
116 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
117 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
118 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
119 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
120 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
121 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
122 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
123 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
124 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
125 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
126 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
127 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
128 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5,
129 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -4, -4,
130 -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
131 -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -1,
135 0, 10, 10, 10, 10, 16, 16, 16, 28, 16, 16, 29, 42, 49, 20, 49,
136 59, 25, 26, 26, 27, 31, 33, 33, 33, 34, 34, 37, 67, 38, 39, 39,
137 40, 40, 41, 79, 43, 44, 45, 45, 48, 48, 64, 50, 51, 52, 88, 52,
138 53, 74, 55, 57, 58, 58, 74, 60, 101, 61, 62, 84, 66, 66, 68, 69,
139 87, 82, 71, 97, 73, 73, 82, 75, 111, 77, 94, 78, 87, 81, 83, 97,
140 85, 83, 94, 86, 99, 89, 90, 99, 111, 92, 93, 134, 95, 98, 105, 98,
141 105, 110, 102, 108, 102, 118, 103, 106, 106, 113, 109, 112, 114, 112, 116, 125,
142 115, 116, 117, 117, 126, 119, 125, 121, 121, 123, 145, 124, 126, 131, 127, 129,
143 165, 130, 132, 138, 133, 135, 145, 136, 137, 139, 146, 141, 143, 142, 144, 148,
144 147, 155, 151, 149, 151, 150, 152, 157, 153, 154, 156, 168, 158, 162, 161, 160,
145 172, 163, 169, 164, 166, 184, 167, 170, 177, 174, 171, 173, 182, 176, 180, 178,
146 175, 189, 179, 181, 186, 183, 192, 185, 200, 187, 191, 188, 190, 197, 193, 196,
147 197, 194, 195, 196, 198, 202, 199, 201, 210, 203, 207, 204, 205, 206, 208, 214,
148 209, 211, 221, 212, 213, 215, 224, 216, 217, 218, 219, 220, 222, 228, 223, 225,
149 226, 224, 227, 229, 240, 230, 231, 232, 233, 234, 235, 236, 238, 239, 237, 242,
150 241, 243, 242, 244, 245, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255,
154 const uint8_t one_state[256])
159 for (
i = 1;
i < 256;
i++)
160 l2tab[
i] = -
log2(
i / 256.0) * ((1U << 31) / 8);
162 for (
i = 0;
i < 256;
i++) {
163 uint64_t best_len[256];
165 for (j = 0; j < 256; j++)
166 best_len[j] = UINT64_MAX;
168 for (j =
FFMAX(
i - 10, 1); j <
FFMIN(
i + 11, 256); j++) {
169 uint32_t occ[256] = { 0 };
176 for (k = 0; k < 256; k++) {
177 uint32_t newocc[256] = { 0 };
178 for (m = 1; m < 256; m++)
180 len += (occ[m]*((
i *(uint64_t)l2tab[ m]
181 + (256-
i)*(uint64_t)l2tab[256-m])>>8)) >> 8;
183 if (
len < best_len[k]) {
185 best_state[
i][k] = j;
187 for (m = 1; m < 256; m++)
189 newocc[ one_state[ m]] += occ[m] * (uint64_t)
i >> 8;
190 newocc[256 - one_state[256 - m]] += occ[m] * (uint64_t)(256 -
i) >> 8;
192 memcpy(occ, newocc,
sizeof(occ));
199 uint8_t *
state,
int v,
201 uint64_t rc_stat[256][2],
202 uint64_t rc_stat2[32][2])
206#define put_rac(C, S, B) \
209 rc_stat[*(S)][B]++; \
210 rc_stat2[(S) - state][B]++; \
216 const unsigned a = is_signed ?
FFABS(v) : v;
220 for (
i = 0;
i < e;
i++)
224 for (
i = e - 1;
i >= 0;
i--)
230 for (
i = 0;
i < e;
i++)
234 for (
i = e - 1;
i >= 0;
i--)
247 int v,
int is_signed)
270 ff_dlog(
NULL,
"v:%d/%d bias:%d error:%d drift:%d count:%d k:%d\n", v,
code,
278#define RENAME(name) name
284#define RENAME(name) name ## 32
288 const uint8_t *
src,
int w,
int h,
289 int stride,
int plane_index,
int remap_index,
int pixel_stride,
int ac)
293 const int ring_size =
f->context_model ? 3 : 2;
301 for (y = 0; y <
h; y++) {
308 if (
f->bits_per_raw_sample <= 8) {
309 for (x = 0; x <
w; x++)
312 for (x = 0; x <
w; x++)
318 if (
f->packed_at_lsb) {
319 for (x = 0; x <
w; x++) {
323 for (x = 0; x <
w; x++) {
324 sample[0][x] = ((uint16_t*)(
src +
stride*y))[x * pixel_stride] >> (16 -
f->bits_per_raw_sample);
328 for (x = 0; x <
w; x++)
339 const uint8_t *
src,
int w,
int h,
340 int stride,
int remap_index,
int pixel_stride)
344 memset(sc->
fltmap[remap_index], 0, 65536 *
sizeof(*sc->
fltmap[remap_index]));
346 for (y = 0; y <
h; y++) {
347 if (
f->bits_per_raw_sample <= 8) {
348 for (x = 0; x <
w; x++)
351 if (
f->packed_at_lsb) {
352 for (x = 0; x <
w; x++)
353 sc->
fltmap[remap_index][ ((uint16_t*)(
src +
stride*y))[x * pixel_stride] ] = 1;
355 for (x = 0; x <
w; x++)
356 sc->
fltmap[remap_index][ ((uint16_t*)(
src +
stride*y))[x * pixel_stride] >> (16 -
f->bits_per_raw_sample) ] = 1;
381 for (
i = 0;
i < 5;
i++)
390 for (
int i = 0;
i < nb_contexts;
i++)
392 if (initial_state[
i][j] != 128)
405 if (
f->version < 2) {
409 for (
i = 1;
i < 256;
i++)
411 f->state_transition[
i] -
c->one_state[
i], 1);
422 }
else if (
f->version < 3) {
424 for (
i = 0;
i <
f->slice_count;
i++) {
427 (
fs->slice_x + 1) *
f->num_h_slices /
f->width, 0);
429 (
fs->slice_y + 1) *
f->num_v_slices /
f->height, 0);
431 (
fs->slice_width + 1) *
f->num_h_slices /
f->width - 1,
434 (
fs->slice_height + 1) *
f->num_v_slices /
f->height - 1,
436 for (j = 0; j <
f->plane_count; j++) {
438 av_assert0(
fs->plane[j].quant_table_index ==
f->context_model);
446 f->combined_version =
f->version << 16;
447 if (
f->version > 2) {
448 if (
f->version == 3) {
449 f->micro_version = 4;
450 }
else if (
f->version == 4) {
451 f->micro_version = 10;
455 f->combined_version +=
f->micro_version;
470 memset(state2, 128,
sizeof(state2));
473 f->avctx->extradata_size = 10000 + 4 +
474 (11 * 11 * 5 * 5 * 5 + 11 * 11 * 11) * 32;
476 if (!
f->avctx->extradata)
487 for (
i = 1;
i < 256;
i++)
496 if (
f->colorspace == 2)
502 for (
i = 0;
i <
f->quant_table_count;
i++)
505 for (
i = 0;
i <
f->quant_table_count;
i++) {
508 for (j = 0; j <
f->context_count[
i]; j++)
510 int pred = j ?
f->initial_states[
i][j - 1][k] : 128;
512 (int8_t)(
f->initial_states[
i][j][k] -
pred), 1);
519 if (
f->version > 2) {
522 if (
f->combined_version >= 0x40004)
528 AV_WL32(
f->avctx->extradata +
f->avctx->extradata_size, v);
529 f->avctx->extradata_size += 4;
536 int i, i2, changed,
print = 0;
540 for (
i = 12;
i < 244;
i++) {
541 for (i2 =
i + 1; i2 < 245 && i2 <
i + 4; i2++) {
543#define COST(old, new) \
544 s->rc_stat[old][0] * -log2((256 - (new)) / 256.0) + \
545 s->rc_stat[old][1] * -log2((new) / 256.0)
547#define COST2(old, new) \
548 COST(old, new) + COST(256 - (old), 256 - (new))
552 if (size0 - sizeX > size0*(1e-14) &&
i != 128 && i2 != 128) {
555 FFSWAP(
int,
s->rc_stat[
i][0],
s->rc_stat[i2][0]);
556 FFSWAP(
int,
s->rc_stat[
i][1],
s->rc_stat[i2][1]);
558 FFSWAP(
int, stt[256 -
i], stt[256 - i2]);
559 FFSWAP(
int,
s->rc_stat[256 -
i][0],
s->rc_stat[256 - i2][0]);
560 FFSWAP(
int,
s->rc_stat[256 -
i][1],
s->rc_stat[256 - i2][1]);
562 for (j = 1; j < 256; j++) {
565 else if (stt[j] == i2)
568 if (stt[256 - j] == 256 -
i)
569 stt[256 - j] = 256 - i2;
570 else if (stt[256 - j] == 256 - i2)
571 stt[256 - j] = 256 -
i;
586 int plane_count = 1 + 2*
s->chroma_planes +
s->bayer +
s->transparency;
589 s->num_v_slices = (avctx->
width > 352 || avctx->
height > 288 || !avctx->
slices) ? 2 : 1;
590 s->num_v_slices =
FFMIN(
s->num_v_slices, max_v_slices);
591 for (;
s->num_v_slices <= 32;
s->num_v_slices++) {
592 for (
s->num_h_slices =
s->num_v_slices;
s->num_h_slices <= 2*
s->num_v_slices;
s->num_h_slices++) {
593 int maxw = (avctx->
width +
s->num_h_slices - 1) /
s->num_h_slices;
594 int maxh = (avctx->
height +
s->num_v_slices - 1) /
s->num_v_slices;
595 if (
s->num_h_slices > max_h_slices ||
s->num_v_slices > max_v_slices)
597 if (maxw * maxh * (
int64_t)(
s->bits_per_raw_sample+1) * plane_count > 8<<24)
605 if (maxw*maxh > 360*288)
612 "Unsupported number %d of slices requested, please specify a "
613 "supported number with -slices (ex:4,6,9,12,16, ...)\n",
625 s->version =
FFMAX(
s->version, 2);
634 s->version =
FFMAX(
s->version, 2);
636 if (avctx->
level <= 0 &&
s->version == 2) {
640 if (avctx->
level <
s->version) {
641 av_log(avctx,
AV_LOG_ERROR,
"Version %d needed for requested features but %d requested\n",
s->version, avctx->
level);
644 s->version = avctx->
level;
645 }
else if (
s->version < 3)
649 if (
s->version >= 4) {
651 }
else if (
s->version >= 3) {
659 s->version =
FFMAX(
s->version, 3);
661 s->version =
FFMAX(
s->version, 4);
662 s->crcref = 0x7a8c4079;
666 av_log(avctx,
AV_LOG_ERROR,
"Version 2 or 4 needed for requested features but version 2 or 4 is experimental and not enabled\n");
671 for (
i = 1;
i < 256;
i++)
676 for (
i = 1;
i < 256;
i++)
677 s->state_transition[
i] =
c.one_state[
i];
680 for (
i = 0;
i < 256;
i++) {
681 s->quant_table_count = 2;
682 if ((
s->qtable == -1 &&
s->bits_per_raw_sample <= 8) ||
s->qtable == 1) {
688 s->quant_tables[1][2][
i]= 11*11*
quant5 [
i];
689 s->quant_tables[1][3][
i]= 5*11*11*
quant5 [
i];
690 s->quant_tables[1][4][
i]= 5*5*11*11*
quant5 [
i];
691 s->context_count[0] = (11 * 11 * 11 + 1) / 2;
692 s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2;
702 s->context_count[0] = (9 * 9 * 9 + 1) / 2;
703 s->context_count[1] = (9 * 9 * 5 * 5 * 5 + 1) / 2;
711 if (
s->context_model == 2) {
712 const int8_t *q5 = (
s->qtable == -1 &&
s->bits_per_raw_sample <= 8) ||
s->qtable == 1 ?
714 s->quant_table_count = 3;
715 for (
i = 0;
i < 256;
i++) {
716 s->quant_tables[2][0][
i] = q5[
i];
717 s->quant_tables[2][1][
i] = 5*q5[
i];
719 s->context_count[2] = (5 * 5 + 1) / 2;
725 if (!
s->transparency)
727 if (!
s->chroma_planes &&
s->version > 3)
732 s->picture_number = 0;
735 for (
i = 0;
i <
s->quant_table_count;
i++) {
737 sizeof(*
s->rc_stat2[
i]));
753 for (j = 0; j < 256; j++)
754 for (
i = 0;
i < 2;
i++) {
755 s->rc_stat[j][
i] = strtol(p, &next, 0);
758 "2Pass file invalid at %d %d [%s]\n", j,
i, p);
764 for (
i = 0;
i <
s->quant_table_count;
i++)
765 for (j = 0; j <
s->context_count[
i]; j++) {
766 for (k = 0; k < 32; k++)
767 for (m = 0; m < 2; m++) {
768 s->rc_stat2[
i][j][k][m] = strtol(p, &next, 0);
771 "2Pass file invalid at %d %d %d %d [%s]\n",
779 gob_count = strtol(p, &next, 0);
780 if (next == p || gob_count <= 0) {
786 while (*p ==
'\n' || *p ==
' ')
796 for (
i = 0;
i <
s->quant_table_count;
i++) {
797 for (k = 0; k < 32; k++) {
800 for (j = 0; j <
s->context_count[
i]; j++) {
802 if (
s->rc_stat2[
i][j][k][0] +
s->rc_stat2[
i][j][k][1] > 200 && j ||
a+
b > 200) {
804 p = 256.0 *
b / (
a +
b);
805 s->initial_states[
i][jp][k] =
807 for(jp++; jp<j; jp++)
808 s->initial_states[
i][jp][k] =
s->initial_states[
i][jp-1][k];
811 a +=
s->rc_stat2[
i][j][k][0];
812 b +=
s->rc_stat2[
i][j][k][1];
814 p = 256.0 *
b / (
a +
b);
816 s->initial_states[
i][j][k] =
824 if (
s->version <= 1) {
852 s->bits_per_raw_sample = 9;
863 s->bits_per_raw_sample = 10;
873 s->bits_per_raw_sample = 12;
880 s->bits_per_raw_sample = 14;
881 s->packed_at_lsb = 1;
896 s->bits_per_raw_sample = 16;
897 }
else if (!
s->bits_per_raw_sample) {
900 if (
s->bits_per_raw_sample <= 8) {
904 s->version =
FFMAX(
s->version, 1);
920 s->chroma_planes =
desc->nb_components < 3 ? 0 : 1;
924 s->bits_per_raw_sample = 8;
925 else if (!
s->bits_per_raw_sample)
926 s->bits_per_raw_sample = 8;
931 s->chroma_planes = 1;
932 s->bits_per_raw_sample = 8;
937 s->chroma_planes = 1;
938 s->bits_per_raw_sample = 16;
940 s->version =
FFMAX(
s->version, 1);
944 s->chroma_planes = 1;
945 s->bits_per_raw_sample = 16;
947 s->version =
FFMAX(
s->version, 1);
951 s->chroma_planes = 1;
952 s->bits_per_raw_sample = 16;
954 s->version =
FFMAX(
s->version, 4);
960 s->chroma_planes = 1;
961 s->bits_per_raw_sample = 8;
965 s->bits_per_raw_sample = 9;
972 s->bits_per_raw_sample = 10;
977 s->bits_per_raw_sample = 12;
982 s->bits_per_raw_sample = 14;
989 s->bits_per_raw_sample = 16;
994 s->bits_per_raw_sample = 32;
995 else if (!
s->bits_per_raw_sample)
999 s->chroma_planes = 1;
1000 if (
s->bits_per_raw_sample >= 16) {
1003 s->version =
FFMAX(
s->version, 1);
1011 if (
s->flt ||
s->remap_mode > 0)
1012 s->version =
FFMAX(
s->version, 4);
1015 if (
s->remap_mode < 0)
1016 s->remap_mode =
s->flt ? 2 : 0;
1017 if (
s->remap_mode == 0 &&
s->bits_per_raw_sample == 32) {
1021 if (
s->remap_mode == 2 &&
1022 !((
s->bits_per_raw_sample == 16 ||
s->bits_per_raw_sample == 32 ||
s->bits_per_raw_sample == 64) &&
s->flt)) {
1047 if (
s->bayer && (avctx->
width & 1 || avctx->
height & 1)) {
1052 if (
s->bits_per_raw_sample > (
s->version > 3 ? 16 : 8) && !
s->remap_mode) {
1055 "high bits_per_raw_sample, forcing range coder\n");
1065 if (
s->version > 1) {
1075 ((avctx->
width +
s->num_h_slices - 1) /
s->num_h_slices) *
1076 (
int64_t)((avctx->
height +
s->num_v_slices - 1) /
s->num_v_slices) > 1 << 18) {
1077 av_log(avctx,
AV_LOG_ERROR,
"Slices larger than 262144 pixels are not supported with 32bit floats and the Golomb-Rice coder\n");
1087 s->slice_count =
s->max_slice_count;
1089 for (
int j = 0; j <
s->slice_count; j++) {
1092 for (
int i = 0;
i <
s->plane_count;
i++) {
1095 p->quant_table_index =
s->context_model;
1096 p->context_count =
s->context_count[p->quant_table_index];
1099 if (
s->remap_mode) {
1100 if (
s->bits_per_raw_sample == 32) {
1105 for (
int p = 0; p < 1 + 2*
s->chroma_planes +
s->transparency ; p++) {
1106 if (
s->bits_per_raw_sample == 32) {
1123 s->slices[j].remap =
s->remap_mode;
1129#define STATS_OUT_SIZE 1024 * 1024 * 6
1134 for (
int i = 0;
i <
s->quant_table_count;
i++)
1135 for (
int j = 0; j <
s->max_slice_count; j++) {
1159 for (j=0; j<
f->plane_count; j++) {
1169 if (
f->version > 3) {
1182#define NB_Y_COEFF 15
1190 stat[
i] += partial[
i];
1196 const uint8_t *
src[3],
const int stride[3],
int w,
int h)
1198 static const int rct_y_coeff[15][2] = {
1219 int x, y,
i, p, best;
1221 int lbd =
f->bits_per_raw_sample <= 8;
1222 int packed = !
src[1];
1223 int transparency =
f->transparency;
1224 int packed_size = (3 + transparency)*2;
1226 for (y = 0; y <
h; y++) {
1227 int lastr=0, lastg=0, lastb=0;
1228 for (p = 0; p < 3; p++)
1231 for (x = 0; x <
w; x++) {
1235 unsigned v = *((
const uint32_t*)(
src[0] + x*4 +
stride[0]*y));
1237 g = (v >> 8) & 0xFF;
1238 r = (v >> 16) & 0xFF;
1239 }
else if (packed) {
1240 const uint16_t *p = ((
const uint16_t*)(
src[0] + x*packed_size +
stride[0]*y));
1244 }
else if (
f->use32bit || transparency) {
1245 g = *((
const uint16_t *)(
src[0] + x*2 +
stride[0]*y));
1246 b = *((
const uint16_t *)(
src[1] + x*2 +
stride[1]*y));
1247 r = *((
const uint16_t *)(
src[2] + x*2 +
stride[2]*y));
1249 b = *((
const uint16_t*)(
src[0] + x*2 +
stride[0]*y));
1250 g = *((
const uint16_t*)(
src[1] + x*2 +
stride[1]*y));
1251 r = *((
const uint16_t*)(
src[2] + x*2 +
stride[2]*y));
1258 int bg = ag -
sample[0][x];
1259 int bb = ab -
sample[1][x];
1260 int br = ar -
sample[2][x];
1266 partial[
i] +=
FFABS(bg + ((br*rct_y_coeff[
i][0] + bb*rct_y_coeff[
i][1])>>2));
1277 if ((x & 4095) == 4095)
1285 if (stat[
i] < stat[best])
1294 const uint8_t *
src[4],
const int stride[4],
1297 static const int rct_y_coeff[
NB_Y_COEFF][2] = {
1298 { 0, 0 }, { 1, 1 }, { 2, 2 }, { 0, 2 }, { 2, 0 }, { 4, 0 }, { 0, 4 }, { 0, 3 },
1299 { 3, 0 }, { 3, 1 }, { 1, 3 }, { 1, 2 }, { 2, 1 }, { 0, 1 }, { 1, 0 },
1308 for (
i = 0;
i < 3;
i++)
1311 for (
int y = 0; y <
h; y += 2) {
1312 int last_gm = 0, last_b = 0, last_r = 0;
1313 for (
int x = 0; x <
w; x++) {
1314 const uint16_t *l1 = (
const uint16_t *)(
src[0] +
stride[0]*(y + 0) + x*2*2);
1315 const uint16_t *l2 = (
const uint16_t *)(
src[0] +
stride[0]*(y + 1) + x*2*2);
1321 int gm = gb + (gd >> 1);
1323 int agm = gm - last_gm;
1324 int ab =
b - last_b;
1325 int ar =
r - last_r;
1328 int bgm = agm -
sample[0][x];
1329 int bb = ab -
sample[1][x];
1330 int br = ar -
sample[2][x];
1336 partial[
i] +=
FFABS(bgm + ((br*rct_y_coeff[
i][0] + bb*rct_y_coeff[
i][1]) >> 2));
1345 if ((x & 4095) == 4095)
1353 if (stat[
i] < stat[best])
1362 int len = 1 <<
f->bits_per_raw_sample;
1365 for (
int p= 0; p < 1 + 2*
f->chroma_planes +
f->transparency; p++) {
1368 uint8_t
state[2][32];
1374 for (
int i= 0;
i<
len;
i++) {
1375 int ri =
i ^ ((
i&0x8000) ? 0 :
flip);
1396 const uint8_t *
src[4],
1400 int transparency =
f->transparency;
1403 for (y = 0; y <
h; y++) {
1404 for (x = 0; x <
w; x++) {
1407 g = *((
const uint32_t *)(
src[0] + x*4 +
stride[0]*y));
1408 b = *((
const uint32_t *)(
src[1] + x*4 +
stride[1]*y));
1409 r = *((
const uint32_t *)(
src[2] + x*4 +
stride[2]*y));
1411 a = *((
const uint32_t *)(
src[3] + x*4 +
stride[3]*y));
1413 if (sc->
remap == 2) {
1414#define FLIP(f) (((f)&0x80000000) ? (f) : (f)^0x7FFFFFFF);
1439#define CMP(A,B) ((A)->val - (int64_t)(B)->val)
1448 int p,
int mul_count,
int *mul_tab,
int update,
int final)
1451 uint8_t
state[2][3][32];
1457 int compact_index = -1;
1459 int current_mul_index = -1;
1462 int run1start_last_val;
1463 int run1start_mul_index;
1465 memcpy(mul, mul_tab,
sizeof(*mul_tab)*(mul_count+1));
1470 for (;
i < pixel_num+1;
i++) {
1471 int current_mul = current_mul_index < 0 ? 1 :
FFABS(mul[current_mul_index]);
1473 if (
i == pixel_num) {
1474 if (last_val == 0xFFFFFFFF && (!
run || run1final)) {
1477 val = last_val + ((1LL<<32) - last_val + current_mul - 1) / current_mul * current_mul;
1479 val += lu * current_mul;
1484 if (last_val !=
val) {
1490 delta -= step*current_mul;
1497 run1start_i =
i - 1;
1498 run1start_last_val = last_val;
1499 run1start_mul_index= current_mul_index;
1513 last_val += current_mul;
1517 last_val = run1start_last_val;
1518 current_mul_index = run1start_mul_index;
1530 if (current_mul > 1)
1538 current_mul_index = ((last_val + 1) * mul_count) >> 32;
1539 if (!
run || run1final) {
1541 if (mul[ current_mul_index ] < 0) {
1543 mul[ current_mul_index ] *= -1;
1550 if (!
run || run1final)
1551 if (
final &&
i < pixel_num)
1563 const uint8_t *
src[4])
1566 const int max_log2_mul_count = ((
int[]){ 1, 1, 1, 9, 9, 10})[
f->remap_optimizer];
1567 const int log2_mul_count_step = ((
int[]){ 1, 1, 1, 9, 9, 1})[
f->remap_optimizer];
1568 const int max_log2_mul = ((
int[]){ 1, 8, 8, 9, 22, 22})[
f->remap_optimizer];
1569 const int log2_mul_step = ((
int[]){ 1, 8, 1, 1, 1, 1})[
f->remap_optimizer];
1570 const int bruteforce_count = ((
int[]){ 0, 0, 0, 1, 1, 1})[
f->remap_optimizer];
1571 const int stair_mode = ((
int[]){ 0, 0, 0, 1, 0, 0})[
f->remap_optimizer];
1572 const int magic_log2 = ((
int[]){ 1, 1, 1, 1, 0, 0})[
f->remap_optimizer];
1577 for (
int p= 0; p < 1 + 2*
f->chroma_planes +
f->transparency; p++) {
1578 int best_log2_mul_count = 0;
1582 for (
int log2_mul_count= 0; log2_mul_count <= max_log2_mul_count; log2_mul_count += log2_mul_count_step) {
1585 int *mul_tab = mul_all[log2_mul_count];
1586 int last_mul_index = -1;
1587 int mul_count = 1 << log2_mul_count;
1589 score_sum[log2_mul_count] = 2 * log2_mul_count;
1591 score_sum[log2_mul_count] =
av_float2int((
float)mul_count * mul_count);
1592 for (
int i= 0;
i<pixel_num;
i++) {
1594 int mul_index = (
val + 1LL)*mul_count >> 32;
1595 if (
val != last_val) {
1596 float *score_tab = score_tab_all[(last_val + 1LL)*mul_count >> 32];
1598 for(
int si= 0; si <= max_log2_mul; si += log2_mul_step) {
1605 }
else if (stair_mode && mul_count == 512 && si == max_log2_mul ) {
1606 if (mul_index >= 0x378/8 && mul_index <= 23 + 0x378/8) {
1607 mul = (0x800080 >> (mul_index - 0x378/8));
1611 mul = (0x10001LL)<<si >> 16;
1623 if (mul_index != last_mul_index)
1628 score_tab[si] +=
log2f(score);
1632 last_mul_index = mul_index;
1634 for(
int i= 0;
i<mul_count;
i++) {
1636 float *score_tab = score_tab_all[
i];
1637 for(
int si= 0; si <= max_log2_mul; si += log2_mul_step) {
1638 if (score_tab[si] < score_tab[ best_index ])
1641 if (stair_mode && mul_count == 512 && best_index == max_log2_mul ) {
1642 if (
i >= 0x378/8 &&
i <= 23 + 0x378/8) {
1643 mul_tab[
i] = -(0x800080 >> (
i - 0x378/8));
1647 mul_tab[
i] = -((0x10001LL)<<best_index >> 16);
1648 score_sum[log2_mul_count] += score_tab[ best_index ];
1650 mul_tab[mul_count] = 1;
1652 if (bruteforce_count)
1655 if (score_sum[log2_mul_count] < score_sum[best_log2_mul_count])
1656 best_log2_mul_count = log2_mul_count;
1664 const uint8_t *
src[4],
1665 int w,
int h,
const int stride[4],
int ac)
1668 const int ring_size =
f->context_model ? 3 : 2;
1672 int transparency =
f->transparency;
1684 for (y = 0; y <
h; y++) {
1689 for (x = 0; x <
w; x++) {
1710 for (p = 0; p < 3 + transparency; p++) {
1714 ret = encode_line32(
f, sc,
f->avctx,
w,
sample[p], (p + 1) / 2,
1715 bits[p], ac, pass1);
1724 const uint8_t *
src[4],
1725 int w,
int h,
const int stride[4],
int ac)
1728 const int ring_size =
f->context_model ? 3 : 2;
1744 for (
int y = 0; y <
h; y += 2) {
1750 for (
int x = 0; x <
w; x++) {
1751 const uint16_t *l1 = ((
const uint16_t*)(
src[0] +
stride[0]*(y + 0) + x*2*2));
1752 const uint16_t *l2 = ((
const uint16_t*)(
src[0] +
stride[0]*(y + 1) + x*2*2));
1767 int gm = gb + (gd >> 1);
1786 for (
int p = 0; p < 4; p++) {
1794 p == 1 ? 2 : (p > 1),
1795 bits[p], ac, pass1);
1812 const AVFrame *
const p =
f->cur_enc_frame;
1818 const uint8_t *
planes[4] = {p->data[0] + ps*x + y*p->linesize[0],
1819 p->data[1] ? p->data[1] + ps*x + y*p->linesize[1] :
NULL,
1820 p->data[2] ? p->data[2] + ps*x + y*p->linesize[2] :
NULL,
1821 p->data[3] ? p->data[3] + ps*x + y*p->linesize[3] :
NULL};
1825 if (
f->version > 3 &&
f->colorspace == 1) {
1827 }
else if (
f->bayer) {
1837 if (
f->version > 2) {
1845 if (
f->bits_per_raw_sample != 32) {
1847 const int cx = x >>
f->chroma_h_shift;
1848 const int cy = y >>
f->chroma_v_shift;
1855 if (
f->chroma_planes) {
1856 load_plane(
f, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
1857 load_plane(
f, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 2, 1);
1859 if (
f->transparency)
1864 }
else if (
f->use32bit) {
1884 const int cx = x >>
f->chroma_h_shift;
1885 const int cy = y >>
f->chroma_v_shift;
1889 if (
f->chroma_planes) {
1890 ret |=
encode_plane(
f, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1, 1, ac);
1891 ret |=
encode_plane(
f, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 2, 1, ac);
1893 if (
f->transparency)
1898 }
else if (
f->bits_per_raw_sample == 32) {
1900 }
else if (
f->bayer) {
1902 }
else if (
f->use32bit) {
1917 if (
f->version < 4) {
1935 int w = avctx->
width +
f->num_h_slices;
1936 int h = avctx->
height +
f->num_v_slices;
1937 size_t maxsize =
w*
h * (1 +
f->transparency);
1938 if (
f->chroma_planes)
1940 maxsize +=
f->slice_count * 800;
1941 if (
f->version > 3) {
1942 maxsize *=
f->bits_per_raw_sample + 1;
1944 maxsize +=
f->slice_count * 70000 * (1 + 2*
f->chroma_planes +
f->bayer +
f->transparency);
1946 maxsize +=
f->slice_count * 2 * (avctx->
width + avctx->
height);
1947 maxsize *= 8*(2*
f->bits_per_raw_sample + 5);
1956 const AVFrame *pict,
int *got_packet)
1960 uint8_t keystate = 128;
1971 memset(
f->rc_stat, 0,
sizeof(
f->rc_stat));
1972 for (
i = 0;
i <
f->quant_table_count;
i++)
1973 memset(
f->rc_stat2[
i], 0,
f->context_count[
i] *
sizeof(*
f->rc_stat2[
i]));
1976 for (j = 0; j <
f->slice_count; j++) {
1978 for (
i = 0;
i < 256;
i++) {
1982 for (
i = 0;
i <
f->quant_table_count;
i++) {
1983 for (k = 0; k <
f->context_count[
i]; k++)
1984 for (m = 0; m < 32; m++) {
1985 f->rc_stat2[
i][k][m][0] += sc->
rc_stat2[
i][k][m][0];
1986 f->rc_stat2[
i][k][m][1] += sc->
rc_stat2[
i][k][m][1];
1991 for (j = 0; j < 256; j++) {
1992 snprintf(p, end - p,
"%" PRIu64
" %" PRIu64
" ",
1993 f->rc_stat[j][0],
f->rc_stat[j][1]);
1996 snprintf(p, end - p,
"\n");
1998 for (
i = 0;
i <
f->quant_table_count;
i++) {
1999 for (j = 0; j <
f->context_count[
i]; j++)
2000 for (m = 0; m < 32; m++) {
2001 snprintf(p, end - p,
"%" PRIu64
" %" PRIu64
" ",
2002 f->rc_stat2[
i][j][m][0],
f->rc_stat2[
i][j][m][1]);
2006 snprintf(p, end - p,
"%d\n",
f->gob_count);
2016 if (!
f->maxsize_warned) {
2017 av_log(avctx,
AV_LOG_WARNING,
"Cannot allocate worst case packet size, the encoding could fail\n");
2018 f->maxsize_warned++;
2029 f->cur_enc_frame = pict;
2043 for (
i = 1;
i < 256;
i++) {
2044 c->one_state[
i] =
f->state_transition[
i];
2045 c->zero_state[256 -
i] = 256 -
c->one_state[
i];
2049 for (
i = 0;
i <
f->slice_count;
i++) {
2052 int len =
pkt->size /
f->slice_count;
2062 f->slice_count,
sizeof(*
f->slices));
2065 for (
i = 0;
i <
f->slice_count;
i++) {
2068 if (
i > 0 ||
f->version > 2) {
2072 AV_WB24(buf_p + bytes, bytes);
2088 f->picture_number++;
2089 pkt->size = buf_p -
pkt->data;
2100 for (
int j = 0; j <
s->max_slice_count; j++) {
2103 for(
int p = 0; p<4; p++) {
2115#define OFFSET(x) offsetof(FFV1Context, x)
2116#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
2120 { .i64 = 0 }, -2, 2,
VE, .unit =
"coder" },
2127 {
"ac",
"Range with custom table (the ac option exists for compatibility and is deprecated)", 0,
AV_OPT_TYPE_CONST,
2128 { .i64 = 1 }, INT_MIN, INT_MAX,
VE, .unit =
"coder" },
2130 { .i64 = 0 }, 0, 2,
VE },
2132 { .i64 = -1 }, -1, 2,
VE , .unit =
"qtable"},
2136 { .i64 =
QTABLE_8BIT }, INT_MIN, INT_MAX,
VE, .unit =
"qtable" },
2139 {
"remap_mode",
"Remap Mode",
OFFSET(remap_mode),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2,
VE, .unit =
"remap_mode" },
2141 { .i64 = -1 }, INT_MIN, INT_MAX,
VE, .unit =
"remap_mode" },
2143 { .i64 = 0 }, INT_MIN, INT_MAX,
VE, .unit =
"remap_mode" },
2145 { .i64 = 1 }, INT_MIN, INT_MAX,
VE, .unit =
"remap_mode" },
2147 { .i64 = 2 }, INT_MIN, INT_MAX,
VE, .unit =
"remap_mode" },
2148 {
"remap_optimizer",
"Remap Optimizer",
OFFSET(remap_optimizer),
AV_OPT_TYPE_INT, { .i64 = 3 }, 0, 5,
VE, .unit =
"remap_optimizer" },
2154 .class_name =
"ffv1 encoder",
static double val(void *priv, double ch)
static av_always_inline void update(AVFilterContext *ctx, AVFrame *insamples, int is_silence, int current_sample, int64_t nb_samples_notify, AVRational time_base)
const FFCodec ff_ffv1_encoder
static int ring_size(RingBuffer *ring)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
#define FF_CODEC_CAP_EOF_FLUSH
The encoder has AV_CODEC_CAP_DELAY set, but does not actually have delay - it only wants to be flushe...
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AV_CEIL_RSHIFT(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Public header for CRC hash function implementation.
static av_cold int encode_close(AVCodecContext *avctx)
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static enum AVPixelFormat pix_fmt
int(* init)(AVBSFContext *ctx)
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
#define FF_INPUT_BUFFER_MIN_SIZE
Used by some encoders as upper bound for the length of headers.
static const uint8_t bits[8]
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
av_cold int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s)
av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
int ff_need_new_slices(int width, int num_h_slices, int chroma_shift)
av_cold void ff_ffv1_close(FFV1Context *s)
int ff_ffv1_allocate_initial_states(FFV1Context *f)
void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc)
void ff_ffv1_compute_bits_per_plane(const FFV1Context *f, FFV1SliceContext *sc, int bits[4], int *offset, int mask[4], int bits_per_raw_sample)
av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
FF Video Codec 1 (a lossless codec)
static void update_vlc_state(VlcState *const state, const int v)
#define MAX_QUANT_TABLE_SIZE
#define AC_RANGE_DEFAULT_TAB_FORCE
#define AC_RANGE_CUSTOM_TAB
#define AC_RANGE_DEFAULT_TAB
static av_always_inline int fold(int diff, int bits)
#define MAX_CONTEXT_INPUTS
static void write_quant_tables(RangeCoder *c, int16_t quant_table[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE])
static int encode_float32_rgb_frame(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4], int ac)
int ff_ffv1_encode_determine_slices(AVCodecContext *avctx)
#define REMAP_MAX_MUL_COUNT
static void write_quant_table(RangeCoder *c, int16_t *quant_table)
static av_noinline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed)
static int contains_non_128(uint8_t(*initial_state)[CONTEXT_SIZE], int nb_contexts)
static int encode_slice(AVCodecContext *c, void *arg)
static void set_micro_version(FFV1Context *f)
#define FFV1_MAX_MUL_COUNT
static void choose_rct_params_bayer(const FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], const int stride[4], int w, int h)
static void put_vlc_symbol(PutBitContext *pb, VlcState *const state, int v, int bits)
static void write_header(FFV1Context *f)
av_cold int ff_ffv1_encode_init(AVCodecContext *avctx)
static av_cold int encode_close(AVCodecContext *avctx)
static const int8_t quant9_10bit[256]
static int encode_float32_remap_segment(FFV1SliceContext *sc, int p, int mul_count, int *mul_tab, int update, int final)
static const int8_t quant5[256]
static int encode_bayer_frame(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4], int ac)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static void load_rgb_float32_frame(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4])
static const int8_t quant5_10bit[256]
static void encode_histogram_remap(FFV1Context *f, FFV1SliceContext *sc)
static int sort_stt(FFV1Context *s, uint8_t stt[256])
static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[3], const int stride[3], int w, int h)
static const AVClass ffv1_class
static av_always_inline av_flatten void put_symbol_inline(RangeCoder *c, uint8_t *state, int v, int is_signed, uint64_t rc_stat[256][2], uint64_t rc_stat2[32][2])
static av_cold int encode_init_internal(AVCodecContext *avctx)
static void encode_slice_header(FFV1Context *f, FFV1SliceContext *sc)
size_t ff_ffv1_encode_buffer_size(AVCodecContext *avctx)
av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx, enum AVPixelFormat pix_fmt)
static const int8_t quant11[256]
static av_always_inline void accumulate_rct_stats(int64_t stat[NB_Y_COEFF], int partial[NB_Y_COEFF])
static void find_best_state(uint8_t best_state[256][256], const uint8_t one_state[256])
#define REMAP_MAX_LOG2_MUL_COUNT
#define REMAP_MAX_LOG2_MUL
av_cold int ff_ffv1_write_extradata(AVCodecContext *avctx)
static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4])
static void load_plane(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src, int w, int h, int stride, int remap_index, int pixel_stride)
static int encode_plane(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src, int w, int h, int stride, int plane_index, int remap_index, int pixel_stride, int ac)
static const uint8_t ver2_state[256]
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
static const int16_t quant_table[64]
#define u(width, name, range_min, range_max)
static void flip(AVCodecContext *avctx, AVFrame *frame)
Macro definitions for various function/variable attributes.
static const struct @257111027162314367033347246032313251342043035002 planes[]
#define FFSWAP(type, a, b)
Memory handling functions.
static void encode_line(AVCodecContext *avctx, uint8_t **data, const uint8_t *line, int length)
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
#define AV_PIX_FMT_0RGB32
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_GRAYF16
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRAP14
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRAPF16
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_BAYER_RGGB16
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_X2RGB10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_X2BGR10
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GBRPF16
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int put_bytes_output(const PutBitContext *s)
exp golomb vlc writing stuff
static void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len)
write signed golomb rice code (ffv1).
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
int ff_rac_terminate(RangeCoder *c, int version)
Terminates the range coder.
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
av_cold void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size)
static int get_rac_count(RangeCoder *c)
static const float pred[4]
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
char * stats_out
pass1 encoding statistics output buffer
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
int level
Encoding level descriptor.
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int flags
AV_CODEC_FLAG_*.
int slices
Number of slices.
int step
Number of elements between 2 horizontally consecutive pixels.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
int mul_all[REMAP_MAX_LOG2_MUL_COUNT+1][REMAP_MAX_MUL_COUNT+1]
float score_tab_all[REMAP_MAX_MUL_COUNT+1][REMAP_MAX_LOG2_MUL+1]
int mul[FFV1_MAX_MUL_COUNT+1]
struct FFV1RemapBuffers * remap_buf
encoder-only, allocated for 32-bit float remap
int ac_byte_count
number of bytes used for AC coding
uint64_t(*[MAX_QUANT_TABLES] rc_stat2)[32][2]
int32_t * sample_buffer32
struct FFV1SliceContext::Unit * unit[4]
uint8_t * bytestream_start
#define av_malloc_array(a, b)
static struct @232240247175332074307271266321204261331170211232 state
static void print(AVTreeNode *t, int depth)