annotate vp6.c @ 4716:8c00d22d45a0 libavcodec

fix indentation
author bcoudurier
date Sat, 24 Mar 2007 23:23:51 +0000
parents 340c876320eb
children 143b89ab8187
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
1 /**
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
2 * @file vp6.c
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
3 * VP6 compatible video decoder
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
4 *
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
5 * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
6 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3697
diff changeset
7 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3697
diff changeset
8 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3697
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
11 * License as published by the Free Software Foundation; either
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
13 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3697
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
17 * Lesser General Public License for more details.
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
18 *
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3697
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4063
7f991a9cd252 document the extradata protocol for VP6F
aurel
parents: 4062
diff changeset
22 *
7f991a9cd252 document the extradata protocol for VP6F
aurel
parents: 4062
diff changeset
23 *
7f991a9cd252 document the extradata protocol for VP6F
aurel
parents: 4062
diff changeset
24 * The VP6F decoder accept an optional 1 byte extradata. It is composed of:
7f991a9cd252 document the extradata protocol for VP6F
aurel
parents: 4062
diff changeset
25 * - upper 4bits: difference between encoded width and visible width
7f991a9cd252 document the extradata protocol for VP6F
aurel
parents: 4062
diff changeset
26 * - lower 4bits: difference between encoded height and visible height
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
27 */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
28
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
29 #include <stdlib.h>
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
30
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
31 #include "avcodec.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
32 #include "dsputil.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
33 #include "bitstream.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
34 #include "mpegvideo.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
35
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
36 #include "vp56.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
37 #include "vp56data.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
38 #include "vp6data.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
39
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
40
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
41 static int vp6_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
42 int *golden_frame)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
43 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
44 vp56_range_coder_t *c = &s->c;
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
45 int parse_filter_info = 0;
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
46 int coeff_offset = 0;
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
47 int vrt_shift = 0;
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
48 int sub_version;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
49 int rows, cols;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
50 int res = 1;
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
51 int separated_coeff = buf[0] & 1;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
52
4595
340c876320eb Use pointers to avoid copying AVFrame.
aurel
parents: 4594
diff changeset
53 s->framep[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
54 vp56_init_dequant(s, (buf[0] >> 1) & 0x3F);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
55
4595
340c876320eb Use pointers to avoid copying AVFrame.
aurel
parents: 4594
diff changeset
56 if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
57 sub_version = buf[1] >> 3;
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
58 if (sub_version > 8)
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
59 return 0;
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
60 s->filter_header = buf[1] & 0x06;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
61 if (buf[1] & 1) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
62 av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
63 return 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
64 }
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
65 if (separated_coeff || !s->filter_header) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4349
diff changeset
66 coeff_offset = AV_RB16(buf+2) - 2;
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
67 buf += 2;
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
68 buf_size -= 2;
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
69 }
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
70
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
71 rows = buf[2]; /* number of stored macroblock rows */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
72 cols = buf[3]; /* number of stored macroblock cols */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
73 /* buf[4] is number of displayed macroblock rows */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
74 /* buf[5] is number of displayed macroblock cols */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
75
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
76 if (16*cols != s->avctx->coded_width ||
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
77 16*rows != s->avctx->coded_height) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
78 avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
4062
683d458a251f use the adjustment value present in FLV to crop VP6 video
aurel
parents: 4001
diff changeset
79 if (s->avctx->extradata_size == 1) {
683d458a251f use the adjustment value present in FLV to crop VP6 video
aurel
parents: 4001
diff changeset
80 s->avctx->width -= s->avctx->extradata[0] >> 4;
683d458a251f use the adjustment value present in FLV to crop VP6 video
aurel
parents: 4001
diff changeset
81 s->avctx->height -= s->avctx->extradata[0] & 0x0F;
683d458a251f use the adjustment value present in FLV to crop VP6 video
aurel
parents: 4001
diff changeset
82 }
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
83 res = 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
84 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
85
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
86 vp56_init_range_decoder(c, buf+6, buf_size-6);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
87 vp56_rac_gets(c, 2);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
88
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
89 parse_filter_info = s->filter_header;
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
90 if (sub_version < 8)
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
91 vrt_shift = 5;
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
92 s->sub_version = sub_version;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
93 } else {
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
94 if (!s->sub_version)
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
95 return 0;
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
96
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
97 if (separated_coeff || !s->filter_header) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4349
diff changeset
98 coeff_offset = AV_RB16(buf+1) - 2;
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
99 buf += 2;
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
100 buf_size -= 2;
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
101 }
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
102 vp56_init_range_decoder(c, buf+1, buf_size-1);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
103
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
104 *golden_frame = vp56_rac_get(c);
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
105 if (s->filter_header) {
4349
541b65620b5f cosmetics: reindent
aurel
parents: 4348
diff changeset
106 s->deblock_filtering = vp56_rac_get(c);
541b65620b5f cosmetics: reindent
aurel
parents: 4348
diff changeset
107 if (s->deblock_filtering)
541b65620b5f cosmetics: reindent
aurel
parents: 4348
diff changeset
108 vp56_rac_get(c);
541b65620b5f cosmetics: reindent
aurel
parents: 4348
diff changeset
109 if (s->sub_version > 7)
541b65620b5f cosmetics: reindent
aurel
parents: 4348
diff changeset
110 parse_filter_info = vp56_rac_get(c);
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
111 }
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
112 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
113
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
114 if (parse_filter_info) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
115 if (vp56_rac_get(c)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
116 s->filter_mode = 2;
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
117 s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
118 s->max_vector_length = 2 << vp56_rac_gets(c, 3);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
119 } else if (vp56_rac_get(c)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
120 s->filter_mode = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
121 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
122 s->filter_mode = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
123 }
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
124 if (s->sub_version > 7)
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
125 s->filter_selection = vp56_rac_gets(c, 4);
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
126 else
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
127 s->filter_selection = 16;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
128 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
129
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
130 vp56_rac_get(c);
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
131
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
132 if (coeff_offset) {
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
133 vp56_init_range_decoder(&s->cc, buf+coeff_offset,
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
134 buf_size-coeff_offset);
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
135 s->ccp = &s->cc;
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
136 } else {
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
137 s->ccp = &s->c;
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
138 }
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
139
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
140 return res;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
141 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
142
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
143 static void vp6_coeff_order_table_init(vp56_context_t *s)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
144 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
145 int i, pos, idx = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
146
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
147 s->coeff_index_to_pos[0] = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
148 for (i=0; i<16; i++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
149 for (pos=1; pos<64; pos++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
150 if (s->coeff_reorder[pos] == i)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
151 s->coeff_index_to_pos[idx++] = pos;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
152 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
153
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
154 static void vp6_default_models_init(vp56_context_t *s)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
155 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
156 s->vector_model_dct[0] = 0xA2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
157 s->vector_model_dct[1] = 0xA4;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
158 s->vector_model_sig[0] = 0x80;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
159 s->vector_model_sig[1] = 0x80;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
160
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
161 memcpy(s->mb_types_stats, vp56_def_mb_types_stats, sizeof(s->mb_types_stats));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
162 memcpy(s->vector_model_fdv, vp6_def_fdv_vector_model, sizeof(s->vector_model_fdv));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
163 memcpy(s->vector_model_pdv, vp6_def_pdv_vector_model, sizeof(s->vector_model_pdv));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
164 memcpy(s->coeff_model_runv, vp6_def_runv_coeff_model, sizeof(s->coeff_model_runv));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
165 memcpy(s->coeff_reorder, vp6_def_coeff_reorder, sizeof(s->coeff_reorder));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
166
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
167 vp6_coeff_order_table_init(s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
168 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
169
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
170 static void vp6_parse_vector_models(vp56_context_t *s)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
171 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
172 vp56_range_coder_t *c = &s->c;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
173 int comp, node;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
174
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
175 for (comp=0; comp<2; comp++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
176 if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
177 s->vector_model_dct[comp] = vp56_rac_gets_nn(c, 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
178 if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
179 s->vector_model_sig[comp] = vp56_rac_gets_nn(c, 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
180 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
181
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
182 for (comp=0; comp<2; comp++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
183 for (node=0; node<7; node++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
184 if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
185 s->vector_model_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
186
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
187 for (comp=0; comp<2; comp++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
188 for (node=0; node<8; node++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
189 if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
190 s->vector_model_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
191 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
192
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
193 static void vp6_parse_coeff_models(vp56_context_t *s)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
194 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
195 vp56_range_coder_t *c = &s->c;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
196 int def_prob[11];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
197 int node, cg, ctx, pos;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
198 int ct; /* code type */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
199 int pt; /* plane type (0 for Y, 1 for U or V) */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
200
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
201 memset(def_prob, 0x80, sizeof(def_prob));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
202
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
203 for (pt=0; pt<2; pt++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
204 for (node=0; node<11; node++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
205 if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
206 def_prob[node] = vp56_rac_gets_nn(c, 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
207 s->coeff_model_dccv[pt][node] = def_prob[node];
4595
340c876320eb Use pointers to avoid copying AVFrame.
aurel
parents: 4594
diff changeset
208 } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
209 s->coeff_model_dccv[pt][node] = def_prob[node];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
210 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
211
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
212 if (vp56_rac_get(c)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
213 for (pos=1; pos<64; pos++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
214 if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
215 s->coeff_reorder[pos] = vp56_rac_gets(c, 4);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
216 vp6_coeff_order_table_init(s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
217 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
218
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
219 for (cg=0; cg<2; cg++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
220 for (node=0; node<14; node++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
221 if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
222 s->coeff_model_runv[cg][node] = vp56_rac_gets_nn(c, 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
223
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
224 for (ct=0; ct<3; ct++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
225 for (pt=0; pt<2; pt++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
226 for (cg=0; cg<6; cg++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
227 for (node=0; node<11; node++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
228 if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
229 def_prob[node] = vp56_rac_gets_nn(c, 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
230 s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
4595
340c876320eb Use pointers to avoid copying AVFrame.
aurel
parents: 4594
diff changeset
231 } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
232 s->coeff_model_ract[pt][ct][cg][node] = def_prob[node];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
233 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
234
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
235 /* coeff_model_dcct is a linear combination of coeff_model_dccv */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
236 for (pt=0; pt<2; pt++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
237 for (ctx=0; ctx<3; ctx++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
238 for (node=0; node<5; node++)
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 4364
diff changeset
239 s->coeff_model_dcct[pt][ctx][node] = av_clip(((s->coeff_model_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
240 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
241
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
242 static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect)
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
243 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
244 vp56_range_coder_t *c = &s->c;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
245 int comp;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
246
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
247 *vect = (vp56_mv_t) {0,0};
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
248 if (s->vector_candidate_pos < 2)
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
249 *vect = s->vector_candidate[0];
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
250
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
251 for (comp=0; comp<2; comp++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
252 int i, delta = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
253
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
254 if (vp56_rac_get_prob(c, s->vector_model_dct[comp])) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
255 static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
256 for (i=0; i<sizeof(prob_order); i++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
257 int j = prob_order[i];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
258 delta |= vp56_rac_get_prob(c, s->vector_model_fdv[comp][j])<<j;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
259 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
260 if (delta & 0xF0)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
261 delta |= vp56_rac_get_prob(c, s->vector_model_fdv[comp][3])<<3;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
262 else
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
263 delta |= 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
264 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
265 delta = vp56_rac_get_tree(c, vp56_pva_tree,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
266 s->vector_model_pdv[comp]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
267 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
268
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
269 if (delta && vp56_rac_get_prob(c, s->vector_model_sig[comp]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
270 delta = -delta;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
271
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
272 if (!comp)
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
273 vect->x += delta;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
274 else
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
275 vect->y += delta;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
276 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
277 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
278
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
279 static void vp6_parse_coeff(vp56_context_t *s)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
280 {
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
281 vp56_range_coder_t *c = s->ccp;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
282 uint8_t *permute = s->scantable.permutated;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
283 uint8_t *model, *model2, *model3;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
284 int coeff, sign, coeff_idx;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
285 int b, i, cg, idx, ctx;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
286 int pt = 0; /* plane type (0 for Y, 1 for U or V) */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
287
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
288 for (b=0; b<6; b++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
289 int ct = 1; /* code type */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
290 int run = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
291
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
292 if (b > 3) pt = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
293
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
294 ctx = s->left_block[vp56_b6to4[b]].not_null_dc
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
295 + s->above_blocks[s->above_block_idx[b]].not_null_dc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
296 model = s->coeff_model_dccv[pt];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
297 model2 = s->coeff_model_dcct[pt][ctx];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
298
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
299 for (coeff_idx=0; coeff_idx<64; ) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
300 if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
301 /* parse a coeff */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
302 if (coeff_idx == 0) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
303 s->left_block[vp56_b6to4[b]].not_null_dc = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
304 s->above_blocks[s->above_block_idx[b]].not_null_dc = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
305 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
306
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
307 if (vp56_rac_get_prob(c, model2[2])) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
308 if (vp56_rac_get_prob(c, model2[3])) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
309 idx = vp56_rac_get_tree(c, vp56_pc_tree, model);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
310 coeff = vp56_coeff_bias[idx];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
311 for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
312 coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
313 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
314 if (vp56_rac_get_prob(c, model2[4]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
315 coeff = 3 + vp56_rac_get_prob(c, model[5]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
316 else
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
317 coeff = 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
318 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
319 ct = 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
320 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
321 ct = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
322 coeff = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
323 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
324 sign = vp56_rac_get(c);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
325 coeff = (coeff ^ -sign) + sign;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
326 if (coeff_idx)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
327 coeff *= s->dequant_ac;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
328 idx = s->coeff_index_to_pos[coeff_idx];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
329 s->block_coeff[b][permute[idx]] = coeff;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
330 run = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
331 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
332 /* parse a run */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
333 ct = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
334 if (coeff_idx == 0) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
335 s->left_block[vp56_b6to4[b]].not_null_dc = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
336 s->above_blocks[s->above_block_idx[b]].not_null_dc = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
337 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
338 if (!vp56_rac_get_prob(c, model2[1]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
339 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
340
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
341 model3 = s->coeff_model_runv[coeff_idx >= 6];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
342 run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
343 if (!run)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
344 for (run=9, i=0; i<6; i++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
345 run += vp56_rac_get_prob(c, model3[i+8]) << i;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
346 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
347 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
348
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
349 cg = vp6_coeff_groups[coeff_idx+=run];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
350 model = model2 = s->coeff_model_ract[pt][ct][cg];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
351 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
352 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
353 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
354
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
355 static int vp6_adjust(int v, int t)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
356 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
357 int V = v, s = v >> 31;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
358 V ^= s;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
359 V -= s;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
360 if (V-t-1 >= (unsigned)(t-1))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
361 return v;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
362 V = 2*t - V;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
363 V += s;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
364 V ^= s;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
365 return V;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
366 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
367
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
368 static int vp6_block_variance(uint8_t *src, int stride)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
369 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
370 int sum = 0, square_sum = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
371 int y, x;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
372
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
373 for (y=0; y<8; y+=2) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
374 for (x=0; x<8; x+=2) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
375 sum += src[x];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
376 square_sum += src[x]*src[x];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
377 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
378 src += 2*stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
379 }
4306
331961478469 small optimization
aurel
parents: 4078
diff changeset
380 return (16*square_sum - sum*sum) >> 8;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
381 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
382
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
383 static void vp6_filter_hv2(vp56_context_t *s, uint8_t *dst, uint8_t *src,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
384 int stride, int delta, int16_t weight)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
385 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
386 s->dsp.put_pixels_tab[1][0](dst, src, stride, 8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
387 s->dsp.biweight_h264_pixels_tab[3](dst, src+delta, stride, 2,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
388 8-weight, weight, 0);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
389 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
390
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
391 static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
392 int delta, const int16_t *weights)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
393 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
394 int x, y;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
395
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
396 for (y=0; y<8; y++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
397 for (x=0; x<8; x++) {
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 4364
diff changeset
398 dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
399 + src[x ] * weights[1]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
400 + src[x+delta ] * weights[2]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
401 + src[x+2*delta] * weights[3] + 64) >> 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
402 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
403 src += stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
404 dst += stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
405 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
406 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
407
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
408 static void vp6_filter_diag2(vp56_context_t *s, uint8_t *dst, uint8_t *src,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
409 int stride, int h_weight, int v_weight)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
410 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
411 uint8_t *tmp = s->edge_emu_buffer+16;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
412 int x, xmax;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
413
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
414 s->dsp.put_pixels_tab[1][0](tmp, src, stride, 8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
415 s->dsp.biweight_h264_pixels_tab[3](tmp, src+1, stride, 2,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
416 8-h_weight, h_weight, 0);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
417 /* we need a 8x9 block to do vertical filter, so compute one more line */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
418 for (x=8*stride, xmax=x+8; x<xmax; x++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
419 tmp[x] = (src[x]*(8-h_weight) + src[x+1]*h_weight + 4) >> 3;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
420
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
421 s->dsp.put_pixels_tab[1][0](dst, tmp, stride, 8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
422 s->dsp.biweight_h264_pixels_tab[3](dst, tmp+stride, stride, 2,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
423 8-v_weight, v_weight, 0);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
424 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
425
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
426 static void vp6_filter_diag4(uint8_t *dst, uint8_t *src, int stride,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
427 const int16_t *h_weights,const int16_t *v_weights)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
428 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
429 int x, y;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
430 int tmp[8*11];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
431 int *t = tmp;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
432
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
433 src -= stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
434
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
435 for (y=0; y<11; y++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
436 for (x=0; x<8; x++) {
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 4364
diff changeset
437 t[x] = av_clip_uint8(( src[x-1] * h_weights[0]
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
438 + src[x ] * h_weights[1]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
439 + src[x+1] * h_weights[2]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
440 + src[x+2] * h_weights[3] + 64) >> 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
441 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
442 src += stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
443 t += 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
444 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
445
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
446 t = tmp + 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
447 for (y=0; y<8; y++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
448 for (x=0; x<8; x++) {
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 4364
diff changeset
449 dst[x] = av_clip_uint8(( t[x-8 ] * v_weights[0]
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
450 + t[x ] * v_weights[1]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
451 + t[x+8 ] * v_weights[2]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
452 + t[x+16] * v_weights[3] + 64) >> 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
453 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
454 dst += stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
455 t += 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
456 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
457 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
458
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
459 static void vp6_filter(vp56_context_t *s, uint8_t *dst, uint8_t *src,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
460 int offset1, int offset2, int stride,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
461 vp56_mv_t mv, int mask, int select, int luma)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
462 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
463 int filter4 = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
464 int x8 = mv.x & mask;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
465 int y8 = mv.y & mask;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
466
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
467 if (luma) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
468 x8 *= 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
469 y8 *= 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
470 filter4 = s->filter_mode;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
471 if (filter4 == 2) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
472 if (s->max_vector_length &&
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
473 (FFABS(mv.x) > s->max_vector_length ||
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
474 FFABS(mv.y) > s->max_vector_length)) {
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
475 filter4 = 0;
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
476 } else if (s->sample_variance_threshold
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4306
diff changeset
477 && (vp6_block_variance(src+offset1, stride)
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
478 < s->sample_variance_threshold)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
479 filter4 = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
480 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
481 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
482 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
483
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
484 if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
485 offset1 = offset2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
486 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
487
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
488 if (filter4) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
489 if (!y8) { /* left or right combine */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
490 vp6_filter_hv4(dst, src+offset1, stride, 1,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
491 vp6_block_copy_filter[select][x8]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
492 } else if (!x8) { /* above or below combine */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
493 vp6_filter_hv4(dst, src+offset1, stride, stride,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
494 vp6_block_copy_filter[select][y8]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
495 } else if ((mv.x^mv.y) >> 31) { /* lower-left or upper-right combine */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
496 vp6_filter_diag4(dst, src+offset1-1, stride,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
497 vp6_block_copy_filter[select][x8],
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
498 vp6_block_copy_filter[select][y8]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
499 } else { /* lower-right or upper-left combine */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
500 vp6_filter_diag4(dst, src+offset1, stride,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
501 vp6_block_copy_filter[select][x8],
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
502 vp6_block_copy_filter[select][y8]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
503 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
504 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
505 if (!y8) { /* left or right combine */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
506 vp6_filter_hv2(s, dst, src+offset1, stride, 1, x8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
507 } else if (!x8) { /* above or below combine */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
508 vp6_filter_hv2(s, dst, src+offset1, stride, stride, y8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
509 } else if ((mv.x^mv.y) >> 31) { /* lower-left or upper-right combine */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
510 vp6_filter_diag2(s, dst, src+offset1-1, stride, x8, y8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
511 } else { /* lower-right or upper-left combine */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
512 vp6_filter_diag2(s, dst, src+offset1, stride, x8, y8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
513 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
514 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
515 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
516
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
517 static int vp6_decode_init(AVCodecContext *avctx)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
518 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
519 vp56_context_t *s = avctx->priv_data;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
520
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
521 vp56_init(s, avctx, avctx->codec->id == CODEC_ID_VP6);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
522 s->vp56_coord_div = vp6_coord_div;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
523 s->parse_vector_adjustment = vp6_parse_vector_adjustment;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
524 s->adjust = vp6_adjust;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
525 s->filter = vp6_filter;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
526 s->parse_coeff = vp6_parse_coeff;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
527 s->default_models_init = vp6_default_models_init;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
528 s->parse_vector_models = vp6_parse_vector_models;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
529 s->parse_coeff_models = vp6_parse_coeff_models;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
530 s->parse_header = vp6_parse_header;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
531
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
532 return 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
533 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
534
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
535 AVCodec vp6_decoder = {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
536 "vp6",
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
537 CODEC_TYPE_VIDEO,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
538 CODEC_ID_VP6,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
539 sizeof(vp56_context_t),
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
540 vp6_decode_init,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
541 NULL,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
542 vp56_free,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
543 vp56_decode_frame,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
544 };
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
545
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
546 /* flash version, not flipped upside-down */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
547 AVCodec vp6f_decoder = {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
548 "vp6f",
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
549 CODEC_TYPE_VIDEO,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
550 CODEC_ID_VP6F,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
551 sizeof(vp56_context_t),
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
552 vp6_decode_init,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
553 NULL,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
554 vp56_free,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
555 vp56_decode_frame,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
556 };