00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00029 #include "internal.h"
00030 #include "dsputil.h"
00031 #include "avcodec.h"
00032 #include "mpegvideo.h"
00033 #include "h263.h"
00034 #include "vc1.h"
00035 #include "vc1data.h"
00036 #include "vc1acdata.h"
00037 #include "msmpeg4data.h"
00038 #include "unary.h"
00039 #include "mathops.h"
00040 #include "vdpau_internal.h"
00041 #include "libavutil/avassert.h"
00042
00043 #undef NDEBUG
00044 #include <assert.h>
00045
00046 #define MB_INTRA_VLC_BITS 9
00047 #define DC_VLC_BITS 9
00048
00049
00050
00051 static const int offset_table1[9] = { 0, 1, 2, 4, 8, 16, 32, 64, 128 };
00052 static const int offset_table2[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
00053
00054
00065 enum Imode {
00066 IMODE_RAW,
00067 IMODE_NORM2,
00068 IMODE_DIFF2,
00069 IMODE_NORM6,
00070 IMODE_DIFF6,
00071 IMODE_ROWSKIP,
00072 IMODE_COLSKIP
00073 };
00075
00076
00078
00079 static void vc1_put_signed_blocks_clamped(VC1Context *v)
00080 {
00081 MpegEncContext *s = &v->s;
00082 int topleft_mb_pos, top_mb_pos;
00083 int stride_y, fieldtx;
00084 int v_dist;
00085
00086
00087
00088
00089
00090
00091
00092
00093 if (!s->first_slice_line) {
00094 if (s->mb_x) {
00095 topleft_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x - 1;
00096 fieldtx = v->fieldtx_plane[topleft_mb_pos];
00097 stride_y = s->linesize << fieldtx;
00098 v_dist = (16 - fieldtx) >> (fieldtx == 0);
00099 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][0],
00100 s->dest[0] - 16 * s->linesize - 16,
00101 stride_y);
00102 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][1],
00103 s->dest[0] - 16 * s->linesize - 8,
00104 stride_y);
00105 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][2],
00106 s->dest[0] - v_dist * s->linesize - 16,
00107 stride_y);
00108 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][3],
00109 s->dest[0] - v_dist * s->linesize - 8,
00110 stride_y);
00111 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][4],
00112 s->dest[1] - 8 * s->uvlinesize - 8,
00113 s->uvlinesize);
00114 s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][5],
00115 s->dest[2] - 8 * s->uvlinesize - 8,
00116 s->uvlinesize);
00117 }
00118 if (s->mb_x == s->mb_width - 1) {
00119 top_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x;
00120 fieldtx = v->fieldtx_plane[top_mb_pos];
00121 stride_y = s->linesize << fieldtx;
00122 v_dist = fieldtx ? 15 : 8;
00123 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][0],
00124 s->dest[0] - 16 * s->linesize,
00125 stride_y);
00126 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][1],
00127 s->dest[0] - 16 * s->linesize + 8,
00128 stride_y);
00129 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][2],
00130 s->dest[0] - v_dist * s->linesize,
00131 stride_y);
00132 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][3],
00133 s->dest[0] - v_dist * s->linesize + 8,
00134 stride_y);
00135 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][4],
00136 s->dest[1] - 8 * s->uvlinesize,
00137 s->uvlinesize);
00138 s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][5],
00139 s->dest[2] - 8 * s->uvlinesize,
00140 s->uvlinesize);
00141 }
00142 }
00143
00144 #define inc_blk_idx(idx) do { \
00145 idx++; \
00146 if (idx >= v->n_allocated_blks) \
00147 idx = 0; \
00148 } while (0)
00149
00150 inc_blk_idx(v->topleft_blk_idx);
00151 inc_blk_idx(v->top_blk_idx);
00152 inc_blk_idx(v->left_blk_idx);
00153 inc_blk_idx(v->cur_blk_idx);
00154 }
00155
00156 static void vc1_loop_filter_iblk(VC1Context *v, int pq)
00157 {
00158 MpegEncContext *s = &v->s;
00159 int j;
00160 if (!s->first_slice_line) {
00161 v->vc1dsp.vc1_v_loop_filter16(s->dest[0], s->linesize, pq);
00162 if (s->mb_x)
00163 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq);
00164 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize + 8, s->linesize, pq);
00165 for (j = 0; j < 2; j++) {
00166 v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1], s->uvlinesize, pq);
00167 if (s->mb_x)
00168 v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq);
00169 }
00170 }
00171 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] + 8 * s->linesize, s->linesize, pq);
00172
00173 if (s->mb_y == s->end_mb_y - 1) {
00174 if (s->mb_x) {
00175 v->vc1dsp.vc1_h_loop_filter16(s->dest[0], s->linesize, pq);
00176 v->vc1dsp.vc1_h_loop_filter8(s->dest[1], s->uvlinesize, pq);
00177 v->vc1dsp.vc1_h_loop_filter8(s->dest[2], s->uvlinesize, pq);
00178 }
00179 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] + 8, s->linesize, pq);
00180 }
00181 }
00182
00183 static void vc1_loop_filter_iblk_delayed(VC1Context *v, int pq)
00184 {
00185 MpegEncContext *s = &v->s;
00186 int j;
00187
00188
00189
00190 if (!s->first_slice_line) {
00191 if (s->mb_x) {
00192 if (s->mb_y >= s->start_mb_y + 2) {
00193 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq);
00194
00195 if (s->mb_x >= 2)
00196 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 16, s->linesize, pq);
00197 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 8, s->linesize, pq);
00198 for (j = 0; j < 2; j++) {
00199 v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq);
00200 if (s->mb_x >= 2) {
00201 v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 16 * s->uvlinesize - 8, s->uvlinesize, pq);
00202 }
00203 }
00204 }
00205 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize - 16, s->linesize, pq);
00206 }
00207
00208 if (s->mb_x == s->mb_width - 1) {
00209 if (s->mb_y >= s->start_mb_y + 2) {
00210 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq);
00211
00212 if (s->mb_x)
00213 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize, s->linesize, pq);
00214 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize + 8, s->linesize, pq);
00215 for (j = 0; j < 2; j++) {
00216 v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq);
00217 if (s->mb_x >= 2) {
00218 v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 16 * s->uvlinesize, s->uvlinesize, pq);
00219 }
00220 }
00221 }
00222 v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize, s->linesize, pq);
00223 }
00224
00225 if (s->mb_y == s->end_mb_y) {
00226 if (s->mb_x) {
00227 if (s->mb_x >= 2)
00228 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq);
00229 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 8, s->linesize, pq);
00230 if (s->mb_x >= 2) {
00231 for (j = 0; j < 2; j++) {
00232 v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq);
00233 }
00234 }
00235 }
00236
00237 if (s->mb_x == s->mb_width - 1) {
00238 if (s->mb_x)
00239 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq);
00240 v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize + 8, s->linesize, pq);
00241 if (s->mb_x) {
00242 for (j = 0; j < 2; j++) {
00243 v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq);
00244 }
00245 }
00246 }
00247 }
00248 }
00249 }
00250
00251 static void vc1_smooth_overlap_filter_iblk(VC1Context *v)
00252 {
00253 MpegEncContext *s = &v->s;
00254 int mb_pos;
00255
00256 if (v->condover == CONDOVER_NONE)
00257 return;
00258
00259 mb_pos = s->mb_x + s->mb_y * s->mb_stride;
00260
00261
00262
00263
00264
00265
00266
00267
00268 if (v->condover == CONDOVER_ALL || v->pq >= 9 || v->over_flags_plane[mb_pos]) {
00269 if (s->mb_x && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
00270 v->over_flags_plane[mb_pos - 1])) {
00271 v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][1],
00272 v->block[v->cur_blk_idx][0]);
00273 v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][3],
00274 v->block[v->cur_blk_idx][2]);
00275 if (!(s->flags & CODEC_FLAG_GRAY)) {
00276 v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][4],
00277 v->block[v->cur_blk_idx][4]);
00278 v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][5],
00279 v->block[v->cur_blk_idx][5]);
00280 }
00281 }
00282 v->vc1dsp.vc1_h_s_overlap(v->block[v->cur_blk_idx][0],
00283 v->block[v->cur_blk_idx][1]);
00284 v->vc1dsp.vc1_h_s_overlap(v->block[v->cur_blk_idx][2],
00285 v->block[v->cur_blk_idx][3]);
00286
00287 if (s->mb_x == s->mb_width - 1) {
00288 if (!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
00289 v->over_flags_plane[mb_pos - s->mb_stride])) {
00290 v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][2],
00291 v->block[v->cur_blk_idx][0]);
00292 v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][3],
00293 v->block[v->cur_blk_idx][1]);
00294 if (!(s->flags & CODEC_FLAG_GRAY)) {
00295 v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][4],
00296 v->block[v->cur_blk_idx][4]);
00297 v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][5],
00298 v->block[v->cur_blk_idx][5]);
00299 }
00300 }
00301 v->vc1dsp.vc1_v_s_overlap(v->block[v->cur_blk_idx][0],
00302 v->block[v->cur_blk_idx][2]);
00303 v->vc1dsp.vc1_v_s_overlap(v->block[v->cur_blk_idx][1],
00304 v->block[v->cur_blk_idx][3]);
00305 }
00306 }
00307 if (s->mb_x && (v->condover == CONDOVER_ALL || v->over_flags_plane[mb_pos - 1])) {
00308 if (!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 ||
00309 v->over_flags_plane[mb_pos - s->mb_stride - 1])) {
00310 v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][2],
00311 v->block[v->left_blk_idx][0]);
00312 v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][3],
00313 v->block[v->left_blk_idx][1]);
00314 if (!(s->flags & CODEC_FLAG_GRAY)) {
00315 v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][4],
00316 v->block[v->left_blk_idx][4]);
00317 v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][5],
00318 v->block[v->left_blk_idx][5]);
00319 }
00320 }
00321 v->vc1dsp.vc1_v_s_overlap(v->block[v->left_blk_idx][0],
00322 v->block[v->left_blk_idx][2]);
00323 v->vc1dsp.vc1_v_s_overlap(v->block[v->left_blk_idx][1],
00324 v->block[v->left_blk_idx][3]);
00325 }
00326 }
00327
00331 static void vc1_mc_1mv(VC1Context *v, int dir)
00332 {
00333 MpegEncContext *s = &v->s;
00334 DSPContext *dsp = &v->s.dsp;
00335 uint8_t *srcY, *srcU, *srcV;
00336 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
00337 int off, off_uv;
00338 int v_edge_pos = s->v_edge_pos >> v->field_mode;
00339
00340 if ((!v->field_mode ||
00341 (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&
00342 !v->s.last_picture.f.data[0])
00343 return;
00344
00345 mx = s->mv[dir][0][0];
00346 my = s->mv[dir][0][1];
00347
00348
00349 if (s->pict_type == AV_PICTURE_TYPE_P) {
00350 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = mx;
00351 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = my;
00352 }
00353
00354 uvmx = (mx + ((mx & 3) == 3)) >> 1;
00355 uvmy = (my + ((my & 3) == 3)) >> 1;
00356 v->luma_mv[s->mb_x][0] = uvmx;
00357 v->luma_mv[s->mb_x][1] = uvmy;
00358
00359 if (v->field_mode &&
00360 v->cur_field_type != v->ref_field_type[dir]) {
00361 my = my - 2 + 4 * v->cur_field_type;
00362 uvmy = uvmy - 2 + 4 * v->cur_field_type;
00363 }
00364
00365
00366 if (v->fastuvmc && (v->fcm != ILACE_FRAME)) {
00367 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
00368 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
00369 }
00370 if (v->field_mode) {
00371 if (!dir) {
00372 if ((v->cur_field_type != v->ref_field_type[dir]) && v->second_field) {
00373 srcY = s->current_picture.f.data[0];
00374 srcU = s->current_picture.f.data[1];
00375 srcV = s->current_picture.f.data[2];
00376 } else {
00377 srcY = s->last_picture.f.data[0];
00378 srcU = s->last_picture.f.data[1];
00379 srcV = s->last_picture.f.data[2];
00380 }
00381 } else {
00382 srcY = s->next_picture.f.data[0];
00383 srcU = s->next_picture.f.data[1];
00384 srcV = s->next_picture.f.data[2];
00385 }
00386 } else {
00387 if (!dir) {
00388 srcY = s->last_picture.f.data[0];
00389 srcU = s->last_picture.f.data[1];
00390 srcV = s->last_picture.f.data[2];
00391 } else {
00392 srcY = s->next_picture.f.data[0];
00393 srcU = s->next_picture.f.data[1];
00394 srcV = s->next_picture.f.data[2];
00395 }
00396 }
00397
00398 if(!srcY)
00399 return;
00400
00401 src_x = s->mb_x * 16 + (mx >> 2);
00402 src_y = s->mb_y * 16 + (my >> 2);
00403 uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
00404 uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
00405
00406 if (v->profile != PROFILE_ADVANCED) {
00407 src_x = av_clip( src_x, -16, s->mb_width * 16);
00408 src_y = av_clip( src_y, -16, s->mb_height * 16);
00409 uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
00410 uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
00411 } else {
00412 src_x = av_clip( src_x, -17, s->avctx->coded_width);
00413 src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
00414 uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
00415 uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
00416 }
00417
00418 srcY += src_y * s->linesize + src_x;
00419 srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
00420 srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
00421
00422 if (v->field_mode && v->ref_field_type[dir]) {
00423 srcY += s->current_picture_ptr->f.linesize[0];
00424 srcU += s->current_picture_ptr->f.linesize[1];
00425 srcV += s->current_picture_ptr->f.linesize[2];
00426 }
00427
00428
00429 if (s->flags & CODEC_FLAG_GRAY) {
00430 srcU = s->edge_emu_buffer + 18 * s->linesize;
00431 srcV = s->edge_emu_buffer + 18 * s->linesize;
00432 }
00433
00434 if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
00435 || s->h_edge_pos < 22 || v_edge_pos < 22
00436 || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel * 3
00437 || (unsigned)(src_y - 1) > v_edge_pos - (my&3) - 16 - 3) {
00438 uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize;
00439
00440 srcY -= s->mspel * (1 + s->linesize);
00441 s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
00442 17 + s->mspel * 2, 17 + s->mspel * 2,
00443 src_x - s->mspel, src_y - s->mspel,
00444 s->h_edge_pos, v_edge_pos);
00445 srcY = s->edge_emu_buffer;
00446 s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8 + 1, 8 + 1,
00447 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1);
00448 s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8 + 1, 8 + 1,
00449 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1);
00450 srcU = uvbuf;
00451 srcV = uvbuf + 16;
00452
00453 if (v->rangeredfrm) {
00454 int i, j;
00455 uint8_t *src, *src2;
00456
00457 src = srcY;
00458 for (j = 0; j < 17 + s->mspel * 2; j++) {
00459 for (i = 0; i < 17 + s->mspel * 2; i++)
00460 src[i] = ((src[i] - 128) >> 1) + 128;
00461 src += s->linesize;
00462 }
00463 src = srcU;
00464 src2 = srcV;
00465 for (j = 0; j < 9; j++) {
00466 for (i = 0; i < 9; i++) {
00467 src[i] = ((src[i] - 128) >> 1) + 128;
00468 src2[i] = ((src2[i] - 128) >> 1) + 128;
00469 }
00470 src += s->uvlinesize;
00471 src2 += s->uvlinesize;
00472 }
00473 }
00474
00475 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
00476 int i, j;
00477 uint8_t *src, *src2;
00478
00479 src = srcY;
00480 for (j = 0; j < 17 + s->mspel * 2; j++) {
00481 for (i = 0; i < 17 + s->mspel * 2; i++)
00482 src[i] = v->luty[src[i]];
00483 src += s->linesize;
00484 }
00485 src = srcU;
00486 src2 = srcV;
00487 for (j = 0; j < 9; j++) {
00488 for (i = 0; i < 9; i++) {
00489 src[i] = v->lutuv[src[i]];
00490 src2[i] = v->lutuv[src2[i]];
00491 }
00492 src += s->uvlinesize;
00493 src2 += s->uvlinesize;
00494 }
00495 }
00496 srcY += s->mspel * (1 + s->linesize);
00497 }
00498
00499 if (v->field_mode && v->second_field) {
00500 off = s->current_picture_ptr->f.linesize[0];
00501 off_uv = s->current_picture_ptr->f.linesize[1];
00502 } else {
00503 off = 0;
00504 off_uv = 0;
00505 }
00506 if (s->mspel) {
00507 dxy = ((my & 3) << 2) | (mx & 3);
00508 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off , srcY , s->linesize, v->rnd);
00509 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8, srcY + 8, s->linesize, v->rnd);
00510 srcY += s->linesize * 8;
00511 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize , srcY , s->linesize, v->rnd);
00512 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
00513 } else {
00514 dxy = (my & 2) | ((mx & 2) >> 1);
00515 if (!v->rnd)
00516 dsp->put_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
00517 else
00518 dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
00519 }
00520
00521 if (s->flags & CODEC_FLAG_GRAY) return;
00522
00523 uvmx = (uvmx & 3) << 1;
00524 uvmy = (uvmy & 3) << 1;
00525 if (!v->rnd) {
00526 dsp->put_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
00527 dsp->put_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
00528 } else {
00529 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
00530 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
00531 }
00532 }
00533
00534 static inline int median4(int a, int b, int c, int d)
00535 {
00536 if (a < b) {
00537 if (c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2;
00538 else return (FFMIN(b, c) + FFMAX(a, d)) / 2;
00539 } else {
00540 if (c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2;
00541 else return (FFMIN(a, c) + FFMAX(b, d)) / 2;
00542 }
00543 }
00544
00547 static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
00548 {
00549 MpegEncContext *s = &v->s;
00550 DSPContext *dsp = &v->s.dsp;
00551 uint8_t *srcY;
00552 int dxy, mx, my, src_x, src_y;
00553 int off;
00554 int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0;
00555 int v_edge_pos = s->v_edge_pos >> v->field_mode;
00556
00557 if ((!v->field_mode ||
00558 (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&
00559 !v->s.last_picture.f.data[0])
00560 return;
00561
00562 mx = s->mv[dir][n][0];
00563 my = s->mv[dir][n][1];
00564
00565 if (!dir) {
00566 if (v->field_mode) {
00567 if ((v->cur_field_type != v->ref_field_type[dir]) && v->second_field)
00568 srcY = s->current_picture.f.data[0];
00569 else
00570 srcY = s->last_picture.f.data[0];
00571 } else
00572 srcY = s->last_picture.f.data[0];
00573 } else
00574 srcY = s->next_picture.f.data[0];
00575
00576 if(!srcY)
00577 return;
00578
00579 if (v->field_mode) {
00580 if (v->cur_field_type != v->ref_field_type[dir])
00581 my = my - 2 + 4 * v->cur_field_type;
00582 }
00583
00584 if (s->pict_type == AV_PICTURE_TYPE_P && n == 3 && v->field_mode) {
00585 int same_count = 0, opp_count = 0, k;
00586 int chosen_mv[2][4][2], f;
00587 int tx, ty;
00588 for (k = 0; k < 4; k++) {
00589 f = v->mv_f[0][s->block_index[k] + v->blocks_off];
00590 chosen_mv[f][f ? opp_count : same_count][0] = s->mv[0][k][0];
00591 chosen_mv[f][f ? opp_count : same_count][1] = s->mv[0][k][1];
00592 opp_count += f;
00593 same_count += 1 - f;
00594 }
00595 f = opp_count > same_count;
00596 switch (f ? opp_count : same_count) {
00597 case 4:
00598 tx = median4(chosen_mv[f][0][0], chosen_mv[f][1][0],
00599 chosen_mv[f][2][0], chosen_mv[f][3][0]);
00600 ty = median4(chosen_mv[f][0][1], chosen_mv[f][1][1],
00601 chosen_mv[f][2][1], chosen_mv[f][3][1]);
00602 break;
00603 case 3:
00604 tx = mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]);
00605 ty = mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]);
00606 break;
00607 case 2:
00608 tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2;
00609 ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2;
00610 break;
00611 default:
00612 av_assert2(0);
00613 }
00614 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;
00615 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;
00616 for (k = 0; k < 4; k++)
00617 v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
00618 }
00619
00620 if (v->fcm == ILACE_FRAME) {
00621 int qx, qy;
00622 int width = s->avctx->coded_width;
00623 int height = s->avctx->coded_height >> 1;
00624 qx = (s->mb_x * 16) + (mx >> 2);
00625 qy = (s->mb_y * 8) + (my >> 3);
00626
00627 if (qx < -17)
00628 mx -= 4 * (qx + 17);
00629 else if (qx > width)
00630 mx -= 4 * (qx - width);
00631 if (qy < -18)
00632 my -= 8 * (qy + 18);
00633 else if (qy > height + 1)
00634 my -= 8 * (qy - height - 1);
00635 }
00636
00637 if ((v->fcm == ILACE_FRAME) && fieldmv)
00638 off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8;
00639 else
00640 off = s->linesize * 4 * (n & 2) + (n & 1) * 8;
00641 if (v->field_mode && v->second_field)
00642 off += s->current_picture_ptr->f.linesize[0];
00643
00644 src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2);
00645 if (!fieldmv)
00646 src_y = s->mb_y * 16 + (n & 2) * 4 + (my >> 2);
00647 else
00648 src_y = s->mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2);
00649
00650 if (v->profile != PROFILE_ADVANCED) {
00651 src_x = av_clip(src_x, -16, s->mb_width * 16);
00652 src_y = av_clip(src_y, -16, s->mb_height * 16);
00653 } else {
00654 src_x = av_clip(src_x, -17, s->avctx->coded_width);
00655 if (v->fcm == ILACE_FRAME) {
00656 if (src_y & 1)
00657 src_y = av_clip(src_y, -17, s->avctx->coded_height + 1);
00658 else
00659 src_y = av_clip(src_y, -18, s->avctx->coded_height);
00660 } else {
00661 src_y = av_clip(src_y, -18, s->avctx->coded_height + 1);
00662 }
00663 }
00664
00665 srcY += src_y * s->linesize + src_x;
00666 if (v->field_mode && v->ref_field_type[dir])
00667 srcY += s->current_picture_ptr->f.linesize[0];
00668
00669 if (fieldmv && !(src_y & 1))
00670 v_edge_pos--;
00671 if (fieldmv && (src_y & 1) && src_y < 4)
00672 src_y--;
00673 if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
00674 || s->h_edge_pos < 13 || v_edge_pos < 23
00675 || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 8 - s->mspel * 2
00676 || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) {
00677 srcY -= s->mspel * (1 + (s->linesize << fieldmv));
00678
00679 s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
00680 9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv,
00681 src_x - s->mspel, src_y - (s->mspel << fieldmv),
00682 s->h_edge_pos, v_edge_pos);
00683 srcY = s->edge_emu_buffer;
00684
00685 if (v->rangeredfrm) {
00686 int i, j;
00687 uint8_t *src;
00688
00689 src = srcY;
00690 for (j = 0; j < 9 + s->mspel * 2; j++) {
00691 for (i = 0; i < 9 + s->mspel * 2; i++)
00692 src[i] = ((src[i] - 128) >> 1) + 128;
00693 src += s->linesize << fieldmv;
00694 }
00695 }
00696
00697 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
00698 int i, j;
00699 uint8_t *src;
00700
00701 src = srcY;
00702 for (j = 0; j < 9 + s->mspel * 2; j++) {
00703 for (i = 0; i < 9 + s->mspel * 2; i++)
00704 src[i] = v->luty[src[i]];
00705 src += s->linesize << fieldmv;
00706 }
00707 }
00708 srcY += s->mspel * (1 + (s->linesize << fieldmv));
00709 }
00710
00711 if (s->mspel) {
00712 dxy = ((my & 3) << 2) | (mx & 3);
00713 v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);
00714 } else {
00715 dxy = (my & 2) | ((mx & 2) >> 1);
00716 if (!v->rnd)
00717 dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
00718 else
00719 dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8);
00720 }
00721 }
00722
00723 static av_always_inline int get_chroma_mv(int *mvx, int *mvy, int *a, int flag, int *tx, int *ty)
00724 {
00725 int idx, i;
00726 static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
00727
00728 idx = ((a[3] != flag) << 3)
00729 | ((a[2] != flag) << 2)
00730 | ((a[1] != flag) << 1)
00731 | (a[0] != flag);
00732 if (!idx) {
00733 *tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
00734 *ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
00735 return 4;
00736 } else if (count[idx] == 1) {
00737 switch (idx) {
00738 case 0x1:
00739 *tx = mid_pred(mvx[1], mvx[2], mvx[3]);
00740 *ty = mid_pred(mvy[1], mvy[2], mvy[3]);
00741 return 3;
00742 case 0x2:
00743 *tx = mid_pred(mvx[0], mvx[2], mvx[3]);
00744 *ty = mid_pred(mvy[0], mvy[2], mvy[3]);
00745 return 3;
00746 case 0x4:
00747 *tx = mid_pred(mvx[0], mvx[1], mvx[3]);
00748 *ty = mid_pred(mvy[0], mvy[1], mvy[3]);
00749 return 3;
00750 case 0x8:
00751 *tx = mid_pred(mvx[0], mvx[1], mvx[2]);
00752 *ty = mid_pred(mvy[0], mvy[1], mvy[2]);
00753 return 3;
00754 }
00755 } else if (count[idx] == 2) {
00756 int t1 = 0, t2 = 0;
00757 for (i = 0; i < 3; i++)
00758 if (!a[i]) {
00759 t1 = i;
00760 break;
00761 }
00762 for (i = t1 + 1; i < 4; i++)
00763 if (!a[i]) {
00764 t2 = i;
00765 break;
00766 }
00767 *tx = (mvx[t1] + mvx[t2]) / 2;
00768 *ty = (mvy[t1] + mvy[t2]) / 2;
00769 return 2;
00770 } else {
00771 return 0;
00772 }
00773 return -1;
00774 }
00775
00778 static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
00779 {
00780 MpegEncContext *s = &v->s;
00781 DSPContext *dsp = &v->s.dsp;
00782 uint8_t *srcU, *srcV;
00783 int uvmx, uvmy, uvsrc_x, uvsrc_y;
00784 int k, tx = 0, ty = 0;
00785 int mvx[4], mvy[4], intra[4], mv_f[4];
00786 int valid_count;
00787 int chroma_ref_type = v->cur_field_type, off = 0;
00788 int v_edge_pos = s->v_edge_pos >> v->field_mode;
00789
00790 if (!v->field_mode && !v->s.last_picture.f.data[0])
00791 return;
00792 if (s->flags & CODEC_FLAG_GRAY)
00793 return;
00794
00795 for (k = 0; k < 4; k++) {
00796 mvx[k] = s->mv[dir][k][0];
00797 mvy[k] = s->mv[dir][k][1];
00798 intra[k] = v->mb_type[0][s->block_index[k]];
00799 if (v->field_mode)
00800 mv_f[k] = v->mv_f[dir][s->block_index[k] + v->blocks_off];
00801 }
00802
00803
00804 if (!v->field_mode || (v->field_mode && !v->numref)) {
00805 valid_count = get_chroma_mv(mvx, mvy, intra, 0, &tx, &ty);
00806 chroma_ref_type = v->reffield;
00807 if (!valid_count) {
00808 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
00809 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
00810 v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
00811 return;
00812 }
00813 } else {
00814 int dominant = 0;
00815 if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2)
00816 dominant = 1;
00817 valid_count = get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty);
00818 if (dominant)
00819 chroma_ref_type = !v->cur_field_type;
00820 }
00821 if (v->field_mode && chroma_ref_type == 1 && v->cur_field_type == 1 && !v->s.last_picture.f.data[0])
00822 return;
00823 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;
00824 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;
00825 uvmx = (tx + ((tx & 3) == 3)) >> 1;
00826 uvmy = (ty + ((ty & 3) == 3)) >> 1;
00827
00828 v->luma_mv[s->mb_x][0] = uvmx;
00829 v->luma_mv[s->mb_x][1] = uvmy;
00830
00831 if (v->fastuvmc) {
00832 uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
00833 uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
00834 }
00835
00836 if (v->cur_field_type != chroma_ref_type)
00837 uvmy += 2 - 4 * chroma_ref_type;
00838
00839 uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
00840 uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
00841
00842 if (v->profile != PROFILE_ADVANCED) {
00843 uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
00844 uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
00845 } else {
00846 uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
00847 uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
00848 }
00849
00850 if (!dir) {
00851 if (v->field_mode) {
00852 if ((v->cur_field_type != chroma_ref_type) && v->cur_field_type) {
00853 srcU = s->current_picture.f.data[1];
00854 srcV = s->current_picture.f.data[2];
00855 } else {
00856 srcU = s->last_picture.f.data[1];
00857 srcV = s->last_picture.f.data[2];
00858 }
00859 } else {
00860 srcU = s->last_picture.f.data[1];
00861 srcV = s->last_picture.f.data[2];
00862 }
00863 } else {
00864 srcU = s->next_picture.f.data[1];
00865 srcV = s->next_picture.f.data[2];
00866 }
00867
00868 if(!srcU)
00869 return;
00870
00871 srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
00872 srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
00873
00874 if (v->field_mode) {
00875 if (chroma_ref_type) {
00876 srcU += s->current_picture_ptr->f.linesize[1];
00877 srcV += s->current_picture_ptr->f.linesize[2];
00878 }
00879 off = v->second_field ? s->current_picture_ptr->f.linesize[1] : 0;
00880 }
00881
00882 if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
00883 || s->h_edge_pos < 18 || v_edge_pos < 18
00884 || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
00885 || (unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
00886 s->dsp.emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize,
00887 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
00888 s->h_edge_pos >> 1, v_edge_pos >> 1);
00889 s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize,
00890 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
00891 s->h_edge_pos >> 1, v_edge_pos >> 1);
00892 srcU = s->edge_emu_buffer;
00893 srcV = s->edge_emu_buffer + 16;
00894
00895
00896 if (v->rangeredfrm) {
00897 int i, j;
00898 uint8_t *src, *src2;
00899
00900 src = srcU;
00901 src2 = srcV;
00902 for (j = 0; j < 9; j++) {
00903 for (i = 0; i < 9; i++) {
00904 src[i] = ((src[i] - 128) >> 1) + 128;
00905 src2[i] = ((src2[i] - 128) >> 1) + 128;
00906 }
00907 src += s->uvlinesize;
00908 src2 += s->uvlinesize;
00909 }
00910 }
00911
00912 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
00913 int i, j;
00914 uint8_t *src, *src2;
00915
00916 src = srcU;
00917 src2 = srcV;
00918 for (j = 0; j < 9; j++) {
00919 for (i = 0; i < 9; i++) {
00920 src[i] = v->lutuv[src[i]];
00921 src2[i] = v->lutuv[src2[i]];
00922 }
00923 src += s->uvlinesize;
00924 src2 += s->uvlinesize;
00925 }
00926 }
00927 }
00928
00929
00930 uvmx = (uvmx & 3) << 1;
00931 uvmy = (uvmy & 3) << 1;
00932 if (!v->rnd) {
00933 dsp->put_h264_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy);
00934 dsp->put_h264_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy);
00935 } else {
00936 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy);
00937 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy);
00938 }
00939 }
00940
00943 static void vc1_mc_4mv_chroma4(VC1Context *v)
00944 {
00945 MpegEncContext *s = &v->s;
00946 DSPContext *dsp = &v->s.dsp;
00947 uint8_t *srcU, *srcV;
00948 int uvsrc_x, uvsrc_y;
00949 int uvmx_field[4], uvmy_field[4];
00950 int i, off, tx, ty;
00951 int fieldmv = v->blk_mv_type[s->block_index[0]];
00952 static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };
00953 int v_dist = fieldmv ? 1 : 4;
00954 int v_edge_pos = s->v_edge_pos >> 1;
00955
00956 if (!v->s.last_picture.f.data[0])
00957 return;
00958 if (s->flags & CODEC_FLAG_GRAY)
00959 return;
00960
00961 for (i = 0; i < 4; i++) {
00962 tx = s->mv[0][i][0];
00963 uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;
00964 ty = s->mv[0][i][1];
00965 if (fieldmv)
00966 uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];
00967 else
00968 uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;
00969 }
00970
00971 for (i = 0; i < 4; i++) {
00972 off = (i & 1) * 4 + ((i & 2) ? v_dist * s->uvlinesize : 0);
00973 uvsrc_x = s->mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2);
00974 uvsrc_y = s->mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);
00975
00976 uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
00977 uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
00978 srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
00979 srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
00980 uvmx_field[i] = (uvmx_field[i] & 3) << 1;
00981 uvmy_field[i] = (uvmy_field[i] & 3) << 1;
00982
00983 if (fieldmv && !(uvsrc_y & 1))
00984 v_edge_pos = (s->v_edge_pos >> 1) - 1;
00985
00986 if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)
00987 uvsrc_y--;
00988 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP)
00989 || s->h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)
00990 || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 5
00991 || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
00992 s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcU, s->uvlinesize,
00993 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
00994 s->h_edge_pos >> 1, v_edge_pos);
00995 s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize,
00996 5, (5 << fieldmv), uvsrc_x, uvsrc_y,
00997 s->h_edge_pos >> 1, v_edge_pos);
00998 srcU = s->edge_emu_buffer;
00999 srcV = s->edge_emu_buffer + 16;
01000
01001
01002 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
01003 int i, j;
01004 uint8_t *src, *src2;
01005
01006 src = srcU;
01007 src2 = srcV;
01008 for (j = 0; j < 5; j++) {
01009 for (i = 0; i < 5; i++) {
01010 src[i] = v->lutuv[src[i]];
01011 src2[i] = v->lutuv[src2[i]];
01012 }
01013 src += s->uvlinesize << 1;
01014 src2 += s->uvlinesize << 1;
01015 }
01016 }
01017 }
01018 if (!v->rnd) {
01019 dsp->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
01020 dsp->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
01021 } else {
01022 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
01023 v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);
01024 }
01025 }
01026 }
01027
01028
01039 #define GET_MQUANT() \
01040 if (v->dquantfrm) { \
01041 int edges = 0; \
01042 if (v->dqprofile == DQPROFILE_ALL_MBS) { \
01043 if (v->dqbilevel) { \
01044 mquant = (get_bits1(gb)) ? v->altpq : v->pq; \
01045 } else { \
01046 mqdiff = get_bits(gb, 3); \
01047 if (mqdiff != 7) \
01048 mquant = v->pq + mqdiff; \
01049 else \
01050 mquant = get_bits(gb, 5); \
01051 } \
01052 } \
01053 if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \
01054 edges = 1 << v->dqsbedge; \
01055 else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \
01056 edges = (3 << v->dqsbedge) % 15; \
01057 else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \
01058 edges = 15; \
01059 if ((edges&1) && !s->mb_x) \
01060 mquant = v->altpq; \
01061 if ((edges&2) && s->first_slice_line) \
01062 mquant = v->altpq; \
01063 if ((edges&4) && s->mb_x == (s->mb_width - 1)) \
01064 mquant = v->altpq; \
01065 if ((edges&8) && s->mb_y == (s->mb_height - 1)) \
01066 mquant = v->altpq; \
01067 if (!mquant || mquant > 31) { \
01068 av_log(v->s.avctx, AV_LOG_ERROR, \
01069 "Overriding invalid mquant %d\n", mquant); \
01070 mquant = 1; \
01071 } \
01072 }
01073
01081 #define GET_MVDATA(_dmv_x, _dmv_y) \
01082 index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
01083 VC1_MV_DIFF_VLC_BITS, 2); \
01084 if (index > 36) { \
01085 mb_has_coeffs = 1; \
01086 index -= 37; \
01087 } else \
01088 mb_has_coeffs = 0; \
01089 s->mb_intra = 0; \
01090 if (!index) { \
01091 _dmv_x = _dmv_y = 0; \
01092 } else if (index == 35) { \
01093 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
01094 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
01095 } else if (index == 36) { \
01096 _dmv_x = 0; \
01097 _dmv_y = 0; \
01098 s->mb_intra = 1; \
01099 } else { \
01100 index1 = index % 6; \
01101 if (!s->quarter_sample && index1 == 5) val = 1; \
01102 else val = 0; \
01103 if (size_table[index1] - val > 0) \
01104 val = get_bits(gb, size_table[index1] - val); \
01105 else val = 0; \
01106 sign = 0 - (val&1); \
01107 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
01108 \
01109 index1 = index / 6; \
01110 if (!s->quarter_sample && index1 == 5) val = 1; \
01111 else val = 0; \
01112 if (size_table[index1] - val > 0) \
01113 val = get_bits(gb, size_table[index1] - val); \
01114 else val = 0; \
01115 sign = 0 - (val & 1); \
01116 _dmv_y = (sign ^ ((val >> 1) + offset_table[index1])) - sign; \
01117 }
01118
01119 static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x,
01120 int *dmv_y, int *pred_flag)
01121 {
01122 int index, index1;
01123 int extend_x = 0, extend_y = 0;
01124 GetBitContext *gb = &v->s.gb;
01125 int bits, esc;
01126 int val, sign;
01127 const int* offs_tab;
01128
01129 if (v->numref) {
01130 bits = VC1_2REF_MVDATA_VLC_BITS;
01131 esc = 125;
01132 } else {
01133 bits = VC1_1REF_MVDATA_VLC_BITS;
01134 esc = 71;
01135 }
01136 switch (v->dmvrange) {
01137 case 1:
01138 extend_x = 1;
01139 break;
01140 case 2:
01141 extend_y = 1;
01142 break;
01143 case 3:
01144 extend_x = extend_y = 1;
01145 break;
01146 }
01147 index = get_vlc2(gb, v->imv_vlc->table, bits, 3);
01148 if (index == esc) {
01149 *dmv_x = get_bits(gb, v->k_x);
01150 *dmv_y = get_bits(gb, v->k_y);
01151 if (v->numref) {
01152 *pred_flag = *dmv_y & 1;
01153 *dmv_y = (*dmv_y + *pred_flag) >> 1;
01154 }
01155 }
01156 else {
01157 av_assert0(index < esc);
01158 if (extend_x)
01159 offs_tab = offset_table2;
01160 else
01161 offs_tab = offset_table1;
01162 index1 = (index + 1) % 9;
01163 if (index1 != 0) {
01164 val = get_bits(gb, index1 + extend_x);
01165 sign = 0 -(val & 1);
01166 *dmv_x = (sign ^ ((val >> 1) + offs_tab[index1])) - sign;
01167 } else
01168 *dmv_x = 0;
01169 if (extend_y)
01170 offs_tab = offset_table2;
01171 else
01172 offs_tab = offset_table1;
01173 index1 = (index + 1) / 9;
01174 if (index1 > v->numref) {
01175 val = get_bits(gb, (index1 + (extend_y << v->numref)) >> v->numref);
01176 sign = 0 - (val & 1);
01177 *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->numref])) - sign;
01178 } else
01179 *dmv_y = 0;
01180 if (v->numref)
01181 *pred_flag = index1 & 1;
01182 }
01183 }
01184
01185 static av_always_inline int scaleforsame_x(VC1Context *v, int n , int dir)
01186 {
01187 int scaledvalue, refdist;
01188 int scalesame1, scalesame2;
01189 int scalezone1_x, zone1offset_x;
01190 int table_index = dir ^ v->second_field;
01191
01192 if (v->s.pict_type != AV_PICTURE_TYPE_B)
01193 refdist = v->refdist;
01194 else
01195 refdist = dir ? v->brfd : v->frfd;
01196 if (refdist > 3)
01197 refdist = 3;
01198 scalesame1 = ff_vc1_field_mvpred_scales[table_index][1][refdist];
01199 scalesame2 = ff_vc1_field_mvpred_scales[table_index][2][refdist];
01200 scalezone1_x = ff_vc1_field_mvpred_scales[table_index][3][refdist];
01201 zone1offset_x = ff_vc1_field_mvpred_scales[table_index][5][refdist];
01202
01203 if (FFABS(n) > 255)
01204 scaledvalue = n;
01205 else {
01206 if (FFABS(n) < scalezone1_x)
01207 scaledvalue = (n * scalesame1) >> 8;
01208 else {
01209 if (n < 0)
01210 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
01211 else
01212 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
01213 }
01214 }
01215 return av_clip(scaledvalue, -v->range_x, v->range_x - 1);
01216 }
01217
01218 static av_always_inline int scaleforsame_y(VC1Context *v, int i, int n , int dir)
01219 {
01220 int scaledvalue, refdist;
01221 int scalesame1, scalesame2;
01222 int scalezone1_y, zone1offset_y;
01223 int table_index = dir ^ v->second_field;
01224
01225 if (v->s.pict_type != AV_PICTURE_TYPE_B)
01226 refdist = v->refdist;
01227 else
01228 refdist = dir ? v->brfd : v->frfd;
01229 if (refdist > 3)
01230 refdist = 3;
01231 scalesame1 = ff_vc1_field_mvpred_scales[table_index][1][refdist];
01232 scalesame2 = ff_vc1_field_mvpred_scales[table_index][2][refdist];
01233 scalezone1_y = ff_vc1_field_mvpred_scales[table_index][4][refdist];
01234 zone1offset_y = ff_vc1_field_mvpred_scales[table_index][6][refdist];
01235
01236 if (FFABS(n) > 63)
01237 scaledvalue = n;
01238 else {
01239 if (FFABS(n) < scalezone1_y)
01240 scaledvalue = (n * scalesame1) >> 8;
01241 else {
01242 if (n < 0)
01243 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
01244 else
01245 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
01246 }
01247 }
01248
01249 if (v->cur_field_type && !v->ref_field_type[dir])
01250 return av_clip(scaledvalue, -v->range_y / 2 + 1, v->range_y / 2);
01251 else
01252 return av_clip(scaledvalue, -v->range_y / 2, v->range_y / 2 - 1);
01253 }
01254
01255 static av_always_inline int scaleforopp_x(VC1Context *v, int n )
01256 {
01257 int scalezone1_x, zone1offset_x;
01258 int scaleopp1, scaleopp2, brfd;
01259 int scaledvalue;
01260
01261 brfd = FFMIN(v->brfd, 3);
01262 scalezone1_x = ff_vc1_b_field_mvpred_scales[3][brfd];
01263 zone1offset_x = ff_vc1_b_field_mvpred_scales[5][brfd];
01264 scaleopp1 = ff_vc1_b_field_mvpred_scales[1][brfd];
01265 scaleopp2 = ff_vc1_b_field_mvpred_scales[2][brfd];
01266
01267 if (FFABS(n) > 255)
01268 scaledvalue = n;
01269 else {
01270 if (FFABS(n) < scalezone1_x)
01271 scaledvalue = (n * scaleopp1) >> 8;
01272 else {
01273 if (n < 0)
01274 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
01275 else
01276 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
01277 }
01278 }
01279 return av_clip(scaledvalue, -v->range_x, v->range_x - 1);
01280 }
01281
01282 static av_always_inline int scaleforopp_y(VC1Context *v, int n , int dir)
01283 {
01284 int scalezone1_y, zone1offset_y;
01285 int scaleopp1, scaleopp2, brfd;
01286 int scaledvalue;
01287
01288 brfd = FFMIN(v->brfd, 3);
01289 scalezone1_y = ff_vc1_b_field_mvpred_scales[4][brfd];
01290 zone1offset_y = ff_vc1_b_field_mvpred_scales[6][brfd];
01291 scaleopp1 = ff_vc1_b_field_mvpred_scales[1][brfd];
01292 scaleopp2 = ff_vc1_b_field_mvpred_scales[2][brfd];
01293
01294 if (FFABS(n) > 63)
01295 scaledvalue = n;
01296 else {
01297 if (FFABS(n) < scalezone1_y)
01298 scaledvalue = (n * scaleopp1) >> 8;
01299 else {
01300 if (n < 0)
01301 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
01302 else
01303 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
01304 }
01305 }
01306 if (v->cur_field_type && !v->ref_field_type[dir]) {
01307 return av_clip(scaledvalue, -v->range_y / 2 + 1, v->range_y / 2);
01308 } else {
01309 return av_clip(scaledvalue, -v->range_y / 2, v->range_y / 2 - 1);
01310 }
01311 }
01312
01313 static av_always_inline int scaleforsame(VC1Context *v, int i, int n ,
01314 int dim, int dir)
01315 {
01316 int brfd, scalesame;
01317 int hpel = 1 - v->s.quarter_sample;
01318
01319 n >>= hpel;
01320 if (v->s.pict_type != AV_PICTURE_TYPE_B || v->second_field || !dir) {
01321 if (dim)
01322 n = scaleforsame_y(v, i, n, dir) << hpel;
01323 else
01324 n = scaleforsame_x(v, n, dir) << hpel;
01325 return n;
01326 }
01327 brfd = FFMIN(v->brfd, 3);
01328 scalesame = ff_vc1_b_field_mvpred_scales[0][brfd];
01329
01330 n = (n * scalesame >> 8) << hpel;
01331 return n;
01332 }
01333
01334 static av_always_inline int scaleforopp(VC1Context *v, int n ,
01335 int dim, int dir)
01336 {
01337 int refdist, scaleopp;
01338 int hpel = 1 - v->s.quarter_sample;
01339
01340 n >>= hpel;
01341 if (v->s.pict_type == AV_PICTURE_TYPE_B && !v->second_field && dir == 1) {
01342 if (dim)
01343 n = scaleforopp_y(v, n, dir) << hpel;
01344 else
01345 n = scaleforopp_x(v, n) << hpel;
01346 return n;
01347 }
01348 if (v->s.pict_type != AV_PICTURE_TYPE_B)
01349 refdist = FFMIN(v->refdist, 3);
01350 else
01351 refdist = dir ? v->brfd : v->frfd;
01352 scaleopp = ff_vc1_field_mvpred_scales[dir ^ v->second_field][0][refdist];
01353
01354 n = (n * scaleopp >> 8) << hpel;
01355 return n;
01356 }
01357
01360 static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
01361 int mv1, int r_x, int r_y, uint8_t* is_intra,
01362 int pred_flag, int dir)
01363 {
01364 MpegEncContext *s = &v->s;
01365 int xy, wrap, off = 0;
01366 int16_t *A, *B, *C;
01367 int px, py;
01368 int sum;
01369 int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
01370 int opposite, a_f, b_f, c_f;
01371 int16_t field_predA[2];
01372 int16_t field_predB[2];
01373 int16_t field_predC[2];
01374 int a_valid, b_valid, c_valid;
01375 int hybridmv_thresh, y_bias = 0;
01376
01377 if (v->mv_mode == MV_PMODE_MIXED_MV ||
01378 ((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV)))
01379 mixedmv_pic = 1;
01380 else
01381 mixedmv_pic = 0;
01382
01383 dmv_x <<= 1 - s->quarter_sample;
01384 dmv_y <<= 1 - s->quarter_sample;
01385
01386 wrap = s->b8_stride;
01387 xy = s->block_index[n];
01388
01389 if (s->mb_intra) {
01390 s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = 0;
01391 s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = 0;
01392 s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = 0;
01393 s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0;
01394 if (mv1) {
01395 s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][0] = 0;
01396 s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][1] = 0;
01397 s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][0] = 0;
01398 s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][1] = 0;
01399 s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0;
01400 s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0;
01401 v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
01402 s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][0] = 0;
01403 s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][1] = 0;
01404 s->current_picture.f.motion_val[1][xy + wrap][0] = 0;
01405 s->current_picture.f.motion_val[1][xy + wrap + v->blocks_off][1] = 0;
01406 s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0;
01407 s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0;
01408 }
01409 return;
01410 }
01411
01412 C = s->current_picture.f.motion_val[dir][xy - 1 + v->blocks_off];
01413 A = s->current_picture.f.motion_val[dir][xy - wrap + v->blocks_off];
01414 if (mv1) {
01415 if (v->field_mode && mixedmv_pic)
01416 off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
01417 else
01418 off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
01419 } else {
01420
01421 switch (n) {
01422 case 0:
01423 off = (s->mb_x > 0) ? -1 : 1;
01424 break;
01425 case 1:
01426 off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;
01427 break;
01428 case 2:
01429 off = 1;
01430 break;
01431 case 3:
01432 off = -1;
01433 }
01434 }
01435 B = s->current_picture.f.motion_val[dir][xy - wrap + off + v->blocks_off];
01436
01437 a_valid = !s->first_slice_line || (n == 2 || n == 3);
01438 b_valid = a_valid && (s->mb_width > 1);
01439 c_valid = s->mb_x || (n == 1 || n == 3);
01440 if (v->field_mode) {
01441 a_valid = a_valid && !is_intra[xy - wrap];
01442 b_valid = b_valid && !is_intra[xy - wrap + off];
01443 c_valid = c_valid && !is_intra[xy - 1];
01444 }
01445
01446 if (a_valid) {
01447 a_f = v->mv_f[dir][xy - wrap + v->blocks_off];
01448 num_oppfield += a_f;
01449 num_samefield += 1 - a_f;
01450 field_predA[0] = A[0];
01451 field_predA[1] = A[1];
01452 } else {
01453 field_predA[0] = field_predA[1] = 0;
01454 a_f = 0;
01455 }
01456 if (b_valid) {
01457 b_f = v->mv_f[dir][xy - wrap + off + v->blocks_off];
01458 num_oppfield += b_f;
01459 num_samefield += 1 - b_f;
01460 field_predB[0] = B[0];
01461 field_predB[1] = B[1];
01462 } else {
01463 field_predB[0] = field_predB[1] = 0;
01464 b_f = 0;
01465 }
01466 if (c_valid) {
01467 c_f = v->mv_f[dir][xy - 1 + v->blocks_off];
01468 num_oppfield += c_f;
01469 num_samefield += 1 - c_f;
01470 field_predC[0] = C[0];
01471 field_predC[1] = C[1];
01472 } else {
01473 field_predC[0] = field_predC[1] = 0;
01474 c_f = 0;
01475 }
01476
01477 if (v->field_mode) {
01478 if (!v->numref)
01479
01480
01481 opposite = 1 - v->reffield;
01482 else {
01483 if (num_samefield <= num_oppfield)
01484 opposite = 1 - pred_flag;
01485 else
01486 opposite = pred_flag;
01487 }
01488 } else
01489 opposite = 0;
01490 if (opposite) {
01491 if (a_valid && !a_f) {
01492 field_predA[0] = scaleforopp(v, field_predA[0], 0, dir);
01493 field_predA[1] = scaleforopp(v, field_predA[1], 1, dir);
01494 }
01495 if (b_valid && !b_f) {
01496 field_predB[0] = scaleforopp(v, field_predB[0], 0, dir);
01497 field_predB[1] = scaleforopp(v, field_predB[1], 1, dir);
01498 }
01499 if (c_valid && !c_f) {
01500 field_predC[0] = scaleforopp(v, field_predC[0], 0, dir);
01501 field_predC[1] = scaleforopp(v, field_predC[1], 1, dir);
01502 }
01503 v->mv_f[dir][xy + v->blocks_off] = 1;
01504 v->ref_field_type[dir] = !v->cur_field_type;
01505 } else {
01506 if (a_valid && a_f) {
01507 field_predA[0] = scaleforsame(v, n, field_predA[0], 0, dir);
01508 field_predA[1] = scaleforsame(v, n, field_predA[1], 1, dir);
01509 }
01510 if (b_valid && b_f) {
01511 field_predB[0] = scaleforsame(v, n, field_predB[0], 0, dir);
01512 field_predB[1] = scaleforsame(v, n, field_predB[1], 1, dir);
01513 }
01514 if (c_valid && c_f) {
01515 field_predC[0] = scaleforsame(v, n, field_predC[0], 0, dir);
01516 field_predC[1] = scaleforsame(v, n, field_predC[1], 1, dir);
01517 }
01518 v->mv_f[dir][xy + v->blocks_off] = 0;
01519 v->ref_field_type[dir] = v->cur_field_type;
01520 }
01521
01522 if (a_valid) {
01523 px = field_predA[0];
01524 py = field_predA[1];
01525 } else if (c_valid) {
01526 px = field_predC[0];
01527 py = field_predC[1];
01528 } else if (b_valid) {
01529 px = field_predB[0];
01530 py = field_predB[1];
01531 } else {
01532 px = 0;
01533 py = 0;
01534 }
01535
01536 if (num_samefield + num_oppfield > 1) {
01537 px = mid_pred(field_predA[0], field_predB[0], field_predC[0]);
01538 py = mid_pred(field_predA[1], field_predB[1], field_predC[1]);
01539 }
01540
01541
01542 if (!v->field_mode) {
01543 int qx, qy, X, Y;
01544 qx = (s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
01545 qy = (s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
01546 X = (s->mb_width << 6) - 4;
01547 Y = (s->mb_height << 6) - 4;
01548 if (mv1) {
01549 if (qx + px < -60) px = -60 - qx;
01550 if (qy + py < -60) py = -60 - qy;
01551 } else {
01552 if (qx + px < -28) px = -28 - qx;
01553 if (qy + py < -28) py = -28 - qy;
01554 }
01555 if (qx + px > X) px = X - qx;
01556 if (qy + py > Y) py = Y - qy;
01557 }
01558
01559 if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) {
01560
01561 hybridmv_thresh = 32;
01562 if (a_valid && c_valid) {
01563 if (is_intra[xy - wrap])
01564 sum = FFABS(px) + FFABS(py);
01565 else
01566 sum = FFABS(px - field_predA[0]) + FFABS(py - field_predA[1]);
01567 if (sum > hybridmv_thresh) {
01568 if (get_bits1(&s->gb)) {
01569 px = field_predA[0];
01570 py = field_predA[1];
01571 } else {
01572 px = field_predC[0];
01573 py = field_predC[1];
01574 }
01575 } else {
01576 if (is_intra[xy - 1])
01577 sum = FFABS(px) + FFABS(py);
01578 else
01579 sum = FFABS(px - field_predC[0]) + FFABS(py - field_predC[1]);
01580 if (sum > hybridmv_thresh) {
01581 if (get_bits1(&s->gb)) {
01582 px = field_predA[0];
01583 py = field_predA[1];
01584 } else {
01585 px = field_predC[0];
01586 py = field_predC[1];
01587 }
01588 }
01589 }
01590 }
01591 }
01592
01593 if (v->field_mode && v->numref)
01594 r_y >>= 1;
01595 if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0)
01596 y_bias = 1;
01597
01598 s->mv[dir][n][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
01599 s->mv[dir][n][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias;
01600 if (mv1) {
01601 s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
01602 s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
01603 s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
01604 s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
01605 s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
01606 s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
01607 v->mv_f[dir][xy + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];
01608 v->mv_f[dir][xy + wrap + v->blocks_off] = v->mv_f[dir][xy + wrap + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];
01609 }
01610 }
01611
01614 static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
01615 int mvn, int r_x, int r_y, uint8_t* is_intra)
01616 {
01617 MpegEncContext *s = &v->s;
01618 int xy, wrap, off = 0;
01619 int A[2], B[2], C[2];
01620 int px, py;
01621 int a_valid = 0, b_valid = 0, c_valid = 0;
01622 int field_a, field_b, field_c;
01623 int total_valid, num_samefield, num_oppfield;
01624 int pos_c, pos_b, n_adj;
01625
01626 wrap = s->b8_stride;
01627 xy = s->block_index[n];
01628
01629 if (s->mb_intra) {
01630 s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy][0] = 0;
01631 s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy][1] = 0;
01632 s->current_picture.f.motion_val[1][xy][0] = 0;
01633 s->current_picture.f.motion_val[1][xy][1] = 0;
01634 if (mvn == 1) {
01635 s->current_picture.f.motion_val[0][xy + 1][0] = 0;
01636 s->current_picture.f.motion_val[0][xy + 1][1] = 0;
01637 s->current_picture.f.motion_val[0][xy + wrap][0] = 0;
01638 s->current_picture.f.motion_val[0][xy + wrap][1] = 0;
01639 s->current_picture.f.motion_val[0][xy + wrap + 1][0] = 0;
01640 s->current_picture.f.motion_val[0][xy + wrap + 1][1] = 0;
01641 v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
01642 s->current_picture.f.motion_val[1][xy + 1][0] = 0;
01643 s->current_picture.f.motion_val[1][xy + 1][1] = 0;
01644 s->current_picture.f.motion_val[1][xy + wrap][0] = 0;
01645 s->current_picture.f.motion_val[1][xy + wrap][1] = 0;
01646 s->current_picture.f.motion_val[1][xy + wrap + 1][0] = 0;
01647 s->current_picture.f.motion_val[1][xy + wrap + 1][1] = 0;
01648 }
01649 return;
01650 }
01651
01652 off = ((n == 0) || (n == 1)) ? 1 : -1;
01653
01654 if (s->mb_x || (n == 1) || (n == 3)) {
01655 if ((v->blk_mv_type[xy])
01656 || (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) {
01657 A[0] = s->current_picture.f.motion_val[0][xy - 1][0];
01658 A[1] = s->current_picture.f.motion_val[0][xy - 1][1];
01659 a_valid = 1;
01660 } else {
01661 A[0] = (s->current_picture.f.motion_val[0][xy - 1][0]
01662 + s->current_picture.f.motion_val[0][xy - 1 + off * wrap][0] + 1) >> 1;
01663 A[1] = (s->current_picture.f.motion_val[0][xy - 1][1]
01664 + s->current_picture.f.motion_val[0][xy - 1 + off * wrap][1] + 1) >> 1;
01665 a_valid = 1;
01666 }
01667 if (!(n & 1) && v->is_intra[s->mb_x - 1]) {
01668 a_valid = 0;
01669 A[0] = A[1] = 0;
01670 }
01671 } else
01672 A[0] = A[1] = 0;
01673
01674 B[0] = B[1] = C[0] = C[1] = 0;
01675 if (n == 0 || n == 1 || v->blk_mv_type[xy]) {
01676 if (!s->first_slice_line) {
01677 if (!v->is_intra[s->mb_x - s->mb_stride]) {
01678 b_valid = 1;
01679 n_adj = n | 2;
01680 pos_b = s->block_index[n_adj] - 2 * wrap;
01681 if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) {
01682 n_adj = (n & 2) | (n & 1);
01683 }
01684 B[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap][0];
01685 B[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap][1];
01686 if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) {
01687 B[0] = (B[0] + s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
01688 B[1] = (B[1] + s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
01689 }
01690 }
01691 if (s->mb_width > 1) {
01692 if (!v->is_intra[s->mb_x - s->mb_stride + 1]) {
01693 c_valid = 1;
01694 n_adj = 2;
01695 pos_c = s->block_index[2] - 2 * wrap + 2;
01696 if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
01697 n_adj = n & 2;
01698 }
01699 C[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][0];
01700 C[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][1];
01701 if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
01702 C[0] = (1 + C[0] + (s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
01703 C[1] = (1 + C[1] + (s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
01704 }
01705 if (s->mb_x == s->mb_width - 1) {
01706 if (!v->is_intra[s->mb_x - s->mb_stride - 1]) {
01707 c_valid = 1;
01708 n_adj = 3;
01709 pos_c = s->block_index[3] - 2 * wrap - 2;
01710 if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
01711 n_adj = n | 1;
01712 }
01713 C[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][0];
01714 C[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][1];
01715 if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
01716 C[0] = (1 + C[0] + s->current_picture.f.motion_val[0][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
01717 C[1] = (1 + C[1] + s->current_picture.f.motion_val[0][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
01718 }
01719 } else
01720 c_valid = 0;
01721 }
01722 }
01723 }
01724 }
01725 } else {
01726 pos_b = s->block_index[1];
01727 b_valid = 1;
01728 B[0] = s->current_picture.f.motion_val[0][pos_b][0];
01729 B[1] = s->current_picture.f.motion_val[0][pos_b][1];
01730 pos_c = s->block_index[0];
01731 c_valid = 1;
01732 C[0] = s->current_picture.f.motion_val[0][pos_c][0];
01733 C[1] = s->current_picture.f.motion_val[0][pos_c][1];
01734 }
01735
01736 total_valid = a_valid + b_valid + c_valid;
01737
01738 if (!s->mb_x && !(n == 1 || n == 3)) {
01739 A[0] = A[1] = 0;
01740 }
01741
01742 if ((s->first_slice_line && v->blk_mv_type[xy]) || (s->first_slice_line && !(n & 2))) {
01743 B[0] = B[1] = C[0] = C[1] = 0;
01744 }
01745 if (!v->blk_mv_type[xy]) {
01746 if (s->mb_width == 1) {
01747 px = B[0];
01748 py = B[1];
01749 } else {
01750 if (total_valid >= 2) {
01751 px = mid_pred(A[0], B[0], C[0]);
01752 py = mid_pred(A[1], B[1], C[1]);
01753 } else if (total_valid) {
01754 if (a_valid) { px = A[0]; py = A[1]; }
01755 if (b_valid) { px = B[0]; py = B[1]; }
01756 if (c_valid) { px = C[0]; py = C[1]; }
01757 } else
01758 px = py = 0;
01759 }
01760 } else {
01761 if (a_valid)
01762 field_a = (A[1] & 4) ? 1 : 0;
01763 else
01764 field_a = 0;
01765 if (b_valid)
01766 field_b = (B[1] & 4) ? 1 : 0;
01767 else
01768 field_b = 0;
01769 if (c_valid)
01770 field_c = (C[1] & 4) ? 1 : 0;
01771 else
01772 field_c = 0;
01773
01774 num_oppfield = field_a + field_b + field_c;
01775 num_samefield = total_valid - num_oppfield;
01776 if (total_valid == 3) {
01777 if ((num_samefield == 3) || (num_oppfield == 3)) {
01778 px = mid_pred(A[0], B[0], C[0]);
01779 py = mid_pred(A[1], B[1], C[1]);
01780 } else if (num_samefield >= num_oppfield) {
01781
01782
01783 px = !field_a ? A[0] : B[0];
01784 py = !field_a ? A[1] : B[1];
01785 } else {
01786 px = field_a ? A[0] : B[0];
01787 py = field_a ? A[1] : B[1];
01788 }
01789 } else if (total_valid == 2) {
01790 if (num_samefield >= num_oppfield) {
01791 if (!field_a && a_valid) {
01792 px = A[0];
01793 py = A[1];
01794 } else if (!field_b && b_valid) {
01795 px = B[0];
01796 py = B[1];
01797 } else if (c_valid) {
01798 px = C[0];
01799 py = C[1];
01800 } else px = py = 0;
01801 } else {
01802 if (field_a && a_valid) {
01803 px = A[0];
01804 py = A[1];
01805 } else if (field_b && b_valid) {
01806 px = B[0];
01807 py = B[1];
01808 } else if (c_valid) {
01809 px = C[0];
01810 py = C[1];
01811 } else px = py = 0;
01812 }
01813 } else if (total_valid == 1) {
01814 px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
01815 py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
01816 } else
01817 px = py = 0;
01818 }
01819
01820
01821 s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
01822 s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
01823 if (mvn == 1) {
01824 s->current_picture.f.motion_val[0][xy + 1 ][0] = s->current_picture.f.motion_val[0][xy][0];
01825 s->current_picture.f.motion_val[0][xy + 1 ][1] = s->current_picture.f.motion_val[0][xy][1];
01826 s->current_picture.f.motion_val[0][xy + wrap ][0] = s->current_picture.f.motion_val[0][xy][0];
01827 s->current_picture.f.motion_val[0][xy + wrap ][1] = s->current_picture.f.motion_val[0][xy][1];
01828 s->current_picture.f.motion_val[0][xy + wrap + 1][0] = s->current_picture.f.motion_val[0][xy][0];
01829 s->current_picture.f.motion_val[0][xy + wrap + 1][1] = s->current_picture.f.motion_val[0][xy][1];
01830 } else if (mvn == 2) {
01831 s->current_picture.f.motion_val[0][xy + 1][0] = s->current_picture.f.motion_val[0][xy][0];
01832 s->current_picture.f.motion_val[0][xy + 1][1] = s->current_picture.f.motion_val[0][xy][1];
01833 s->mv[0][n + 1][0] = s->mv[0][n][0];
01834 s->mv[0][n + 1][1] = s->mv[0][n][1];
01835 }
01836 }
01837
01840 static void vc1_interp_mc(VC1Context *v)
01841 {
01842 MpegEncContext *s = &v->s;
01843 DSPContext *dsp = &v->s.dsp;
01844 uint8_t *srcY, *srcU, *srcV;
01845 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
01846 int off, off_uv;
01847 int v_edge_pos = s->v_edge_pos >> v->field_mode;
01848
01849 if (!v->field_mode && !v->s.next_picture.f.data[0])
01850 return;
01851
01852 mx = s->mv[1][0][0];
01853 my = s->mv[1][0][1];
01854 uvmx = (mx + ((mx & 3) == 3)) >> 1;
01855 uvmy = (my + ((my & 3) == 3)) >> 1;
01856 if (v->field_mode) {
01857 if (v->cur_field_type != v->ref_field_type[1])
01858 my = my - 2 + 4 * v->cur_field_type;
01859 uvmy = uvmy - 2 + 4 * v->cur_field_type;
01860 }
01861 if (v->fastuvmc) {
01862 uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1));
01863 uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1));
01864 }
01865 srcY = s->next_picture.f.data[0];
01866 srcU = s->next_picture.f.data[1];
01867 srcV = s->next_picture.f.data[2];
01868
01869 src_x = s->mb_x * 16 + (mx >> 2);
01870 src_y = s->mb_y * 16 + (my >> 2);
01871 uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
01872 uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
01873
01874 if (v->profile != PROFILE_ADVANCED) {
01875 src_x = av_clip( src_x, -16, s->mb_width * 16);
01876 src_y = av_clip( src_y, -16, s->mb_height * 16);
01877 uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
01878 uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
01879 } else {
01880 src_x = av_clip( src_x, -17, s->avctx->coded_width);
01881 src_y = av_clip( src_y, -18, s->avctx->coded_height + 1);
01882 uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
01883 uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
01884 }
01885
01886 srcY += src_y * s->linesize + src_x;
01887 srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
01888 srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
01889
01890 if (v->field_mode && v->ref_field_type[1]) {
01891 srcY += s->current_picture_ptr->f.linesize[0];
01892 srcU += s->current_picture_ptr->f.linesize[1];
01893 srcV += s->current_picture_ptr->f.linesize[2];
01894 }
01895
01896
01897 if (s->flags & CODEC_FLAG_GRAY) {
01898 srcU = s->edge_emu_buffer + 18 * s->linesize;
01899 srcV = s->edge_emu_buffer + 18 * s->linesize;
01900 }
01901
01902 if (v->rangeredfrm || s->h_edge_pos < 22 || v_edge_pos < 22
01903 || (unsigned)(src_x - 1) > s->h_edge_pos - (mx & 3) - 16 - 3
01904 || (unsigned)(src_y - 1) > v_edge_pos - (my & 3) - 16 - 3) {
01905 uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize;
01906
01907 srcY -= s->mspel * (1 + s->linesize);
01908 s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize,
01909 17 + s->mspel * 2, 17 + s->mspel * 2,
01910 src_x - s->mspel, src_y - s->mspel,
01911 s->h_edge_pos, v_edge_pos);
01912 srcY = s->edge_emu_buffer;
01913 s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8 + 1, 8 + 1,
01914 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1);
01915 s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8 + 1, 8 + 1,
01916 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1);
01917 srcU = uvbuf;
01918 srcV = uvbuf + 16;
01919
01920 if (v->rangeredfrm) {
01921 int i, j;
01922 uint8_t *src, *src2;
01923
01924 src = srcY;
01925 for (j = 0; j < 17 + s->mspel * 2; j++) {
01926 for (i = 0; i < 17 + s->mspel * 2; i++)
01927 src[i] = ((src[i] - 128) >> 1) + 128;
01928 src += s->linesize;
01929 }
01930 src = srcU;
01931 src2 = srcV;
01932 for (j = 0; j < 9; j++) {
01933 for (i = 0; i < 9; i++) {
01934 src[i] = ((src[i] - 128) >> 1) + 128;
01935 src2[i] = ((src2[i] - 128) >> 1) + 128;
01936 }
01937 src += s->uvlinesize;
01938 src2 += s->uvlinesize;
01939 }
01940 }
01941 srcY += s->mspel * (1 + s->linesize);
01942 }
01943
01944 if (v->field_mode && v->second_field) {
01945 off = s->current_picture_ptr->f.linesize[0];
01946 off_uv = s->current_picture_ptr->f.linesize[1];
01947 } else {
01948 off = 0;
01949 off_uv = 0;
01950 }
01951
01952 if (s->mspel) {
01953 dxy = ((my & 3) << 2) | (mx & 3);
01954 v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off , srcY , s->linesize, v->rnd);
01955 v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8, srcY + 8, s->linesize, v->rnd);
01956 srcY += s->linesize * 8;
01957 v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize , srcY , s->linesize, v->rnd);
01958 v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd);
01959 } else {
01960 dxy = (my & 2) | ((mx & 2) >> 1);
01961
01962 if (!v->rnd)
01963 dsp->avg_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
01964 else
01965 dsp->avg_no_rnd_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16);
01966 }
01967
01968 if (s->flags & CODEC_FLAG_GRAY) return;
01969
01970 uvmx = (uvmx & 3) << 1;
01971 uvmy = (uvmy & 3) << 1;
01972 if (!v->rnd) {
01973 dsp->avg_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
01974 dsp->avg_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
01975 } else {
01976 v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy);
01977 v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy);
01978 }
01979 }
01980
01981 static av_always_inline int scale_mv(int value, int bfrac, int inv, int qs)
01982 {
01983 int n = bfrac;
01984
01985 #if B_FRACTION_DEN==256
01986 if (inv)
01987 n -= 256;
01988 if (!qs)
01989 return 2 * ((value * n + 255) >> 9);
01990 return (value * n + 128) >> 8;
01991 #else
01992 if (inv)
01993 n -= B_FRACTION_DEN;
01994 if (!qs)
01995 return 2 * ((value * n + B_FRACTION_DEN - 1) / (2 * B_FRACTION_DEN));
01996 return (value * n + B_FRACTION_DEN/2) / B_FRACTION_DEN;
01997 #endif
01998 }
01999
02002 static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2],
02003 int direct, int mode)
02004 {
02005 if (v->use_ic) {
02006 v->mv_mode2 = v->mv_mode;
02007 v->mv_mode = MV_PMODE_INTENSITY_COMP;
02008 }
02009 if (direct) {
02010 vc1_mc_1mv(v, 0);
02011 vc1_interp_mc(v);
02012 if (v->use_ic)
02013 v->mv_mode = v->mv_mode2;
02014 return;
02015 }
02016 if (mode == BMV_TYPE_INTERPOLATED) {
02017 vc1_mc_1mv(v, 0);
02018 vc1_interp_mc(v);
02019 if (v->use_ic)
02020 v->mv_mode = v->mv_mode2;
02021 return;
02022 }
02023
02024 if (v->use_ic && (mode == BMV_TYPE_BACKWARD))
02025 v->mv_mode = v->mv_mode2;
02026 vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD));
02027 if (v->use_ic)
02028 v->mv_mode = v->mv_mode2;
02029 }
02030
02031 static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
02032 int direct, int mvtype)
02033 {
02034 MpegEncContext *s = &v->s;
02035 int xy, wrap, off = 0;
02036 int16_t *A, *B, *C;
02037 int px, py;
02038 int sum;
02039 int r_x, r_y;
02040 const uint8_t *is_intra = v->mb_type[0];
02041
02042 r_x = v->range_x;
02043 r_y = v->range_y;
02044
02045 dmv_x[0] <<= 1 - s->quarter_sample;
02046 dmv_y[0] <<= 1 - s->quarter_sample;
02047 dmv_x[1] <<= 1 - s->quarter_sample;
02048 dmv_y[1] <<= 1 - s->quarter_sample;
02049
02050 wrap = s->b8_stride;
02051 xy = s->block_index[0];
02052
02053 if (s->mb_intra) {
02054 s->current_picture.f.motion_val[0][xy + v->blocks_off][0] =
02055 s->current_picture.f.motion_val[0][xy + v->blocks_off][1] =
02056 s->current_picture.f.motion_val[1][xy + v->blocks_off][0] =
02057 s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0;
02058 return;
02059 }
02060 if (!v->field_mode) {
02061 s->mv[0][0][0] = scale_mv(s->next_picture.f.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
02062 s->mv[0][0][1] = scale_mv(s->next_picture.f.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
02063 s->mv[1][0][0] = scale_mv(s->next_picture.f.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
02064 s->mv[1][0][1] = scale_mv(s->next_picture.f.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
02065
02066
02067 s->mv[0][0][0] = av_clip(s->mv[0][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6));
02068 s->mv[0][0][1] = av_clip(s->mv[0][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
02069 s->mv[1][0][0] = av_clip(s->mv[1][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6));
02070 s->mv[1][0][1] = av_clip(s->mv[1][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
02071 }
02072 if (direct) {
02073 s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = s->mv[0][0][0];
02074 s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = s->mv[0][0][1];
02075 s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = s->mv[1][0][0];
02076 s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = s->mv[1][0][1];
02077 return;
02078 }
02079
02080 if ((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
02081 C = s->current_picture.f.motion_val[0][xy - 2];
02082 A = s->current_picture.f.motion_val[0][xy - wrap * 2];
02083 off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
02084 B = s->current_picture.f.motion_val[0][xy - wrap * 2 + off];
02085
02086 if (!s->mb_x) C[0] = C[1] = 0;
02087 if (!s->first_slice_line) {
02088 if (s->mb_width == 1) {
02089 px = A[0];
02090 py = A[1];
02091 } else {
02092 px = mid_pred(A[0], B[0], C[0]);
02093 py = mid_pred(A[1], B[1], C[1]);
02094 }
02095 } else if (s->mb_x) {
02096 px = C[0];
02097 py = C[1];
02098 } else {
02099 px = py = 0;
02100 }
02101
02102 {
02103 int qx, qy, X, Y;
02104 if (v->profile < PROFILE_ADVANCED) {
02105 qx = (s->mb_x << 5);
02106 qy = (s->mb_y << 5);
02107 X = (s->mb_width << 5) - 4;
02108 Y = (s->mb_height << 5) - 4;
02109 if (qx + px < -28) px = -28 - qx;
02110 if (qy + py < -28) py = -28 - qy;
02111 if (qx + px > X) px = X - qx;
02112 if (qy + py > Y) py = Y - qy;
02113 } else {
02114 qx = (s->mb_x << 6);
02115 qy = (s->mb_y << 6);
02116 X = (s->mb_width << 6) - 4;
02117 Y = (s->mb_height << 6) - 4;
02118 if (qx + px < -60) px = -60 - qx;
02119 if (qy + py < -60) py = -60 - qy;
02120 if (qx + px > X) px = X - qx;
02121 if (qy + py > Y) py = Y - qy;
02122 }
02123 }
02124
02125 if (0 && !s->first_slice_line && s->mb_x) {
02126 if (is_intra[xy - wrap])
02127 sum = FFABS(px) + FFABS(py);
02128 else
02129 sum = FFABS(px - A[0]) + FFABS(py - A[1]);
02130 if (sum > 32) {
02131 if (get_bits1(&s->gb)) {
02132 px = A[0];
02133 py = A[1];
02134 } else {
02135 px = C[0];
02136 py = C[1];
02137 }
02138 } else {
02139 if (is_intra[xy - 2])
02140 sum = FFABS(px) + FFABS(py);
02141 else
02142 sum = FFABS(px - C[0]) + FFABS(py - C[1]);
02143 if (sum > 32) {
02144 if (get_bits1(&s->gb)) {
02145 px = A[0];
02146 py = A[1];
02147 } else {
02148 px = C[0];
02149 py = C[1];
02150 }
02151 }
02152 }
02153 }
02154
02155 s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
02156 s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
02157 }
02158 if ((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
02159 C = s->current_picture.f.motion_val[1][xy - 2];
02160 A = s->current_picture.f.motion_val[1][xy - wrap * 2];
02161 off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
02162 B = s->current_picture.f.motion_val[1][xy - wrap * 2 + off];
02163
02164 if (!s->mb_x)
02165 C[0] = C[1] = 0;
02166 if (!s->first_slice_line) {
02167 if (s->mb_width == 1) {
02168 px = A[0];
02169 py = A[1];
02170 } else {
02171 px = mid_pred(A[0], B[0], C[0]);
02172 py = mid_pred(A[1], B[1], C[1]);
02173 }
02174 } else if (s->mb_x) {
02175 px = C[0];
02176 py = C[1];
02177 } else {
02178 px = py = 0;
02179 }
02180
02181 {
02182 int qx, qy, X, Y;
02183 if (v->profile < PROFILE_ADVANCED) {
02184 qx = (s->mb_x << 5);
02185 qy = (s->mb_y << 5);
02186 X = (s->mb_width << 5) - 4;
02187 Y = (s->mb_height << 5) - 4;
02188 if (qx + px < -28) px = -28 - qx;
02189 if (qy + py < -28) py = -28 - qy;
02190 if (qx + px > X) px = X - qx;
02191 if (qy + py > Y) py = Y - qy;
02192 } else {
02193 qx = (s->mb_x << 6);
02194 qy = (s->mb_y << 6);
02195 X = (s->mb_width << 6) - 4;
02196 Y = (s->mb_height << 6) - 4;
02197 if (qx + px < -60) px = -60 - qx;
02198 if (qy + py < -60) py = -60 - qy;
02199 if (qx + px > X) px = X - qx;
02200 if (qy + py > Y) py = Y - qy;
02201 }
02202 }
02203
02204 if (0 && !s->first_slice_line && s->mb_x) {
02205 if (is_intra[xy - wrap])
02206 sum = FFABS(px) + FFABS(py);
02207 else
02208 sum = FFABS(px - A[0]) + FFABS(py - A[1]);
02209 if (sum > 32) {
02210 if (get_bits1(&s->gb)) {
02211 px = A[0];
02212 py = A[1];
02213 } else {
02214 px = C[0];
02215 py = C[1];
02216 }
02217 } else {
02218 if (is_intra[xy - 2])
02219 sum = FFABS(px) + FFABS(py);
02220 else
02221 sum = FFABS(px - C[0]) + FFABS(py - C[1]);
02222 if (sum > 32) {
02223 if (get_bits1(&s->gb)) {
02224 px = A[0];
02225 py = A[1];
02226 } else {
02227 px = C[0];
02228 py = C[1];
02229 }
02230 }
02231 }
02232 }
02233
02234
02235 s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
02236 s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
02237 }
02238 s->current_picture.f.motion_val[0][xy][0] = s->mv[0][0][0];
02239 s->current_picture.f.motion_val[0][xy][1] = s->mv[0][0][1];
02240 s->current_picture.f.motion_val[1][xy][0] = s->mv[1][0][0];
02241 s->current_picture.f.motion_val[1][xy][1] = s->mv[1][0][1];
02242 }
02243
02244 static inline void vc1_pred_b_mv_intfi(VC1Context *v, int n, int *dmv_x, int *dmv_y, int mv1, int *pred_flag)
02245 {
02246 int dir = (v->bmvtype == BMV_TYPE_BACKWARD) ? 1 : 0;
02247 MpegEncContext *s = &v->s;
02248 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
02249
02250 if (v->bmvtype == BMV_TYPE_DIRECT) {
02251 int total_opp, k, f;
02252 if (s->next_picture.f.mb_type[mb_pos + v->mb_off] != MB_TYPE_INTRA) {
02253 s->mv[0][0][0] = scale_mv(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0],
02254 v->bfraction, 0, s->quarter_sample);
02255 s->mv[0][0][1] = scale_mv(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1],
02256 v->bfraction, 0, s->quarter_sample);
02257 s->mv[1][0][0] = scale_mv(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0],
02258 v->bfraction, 1, s->quarter_sample);
02259 s->mv[1][0][1] = scale_mv(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1],
02260 v->bfraction, 1, s->quarter_sample);
02261
02262 total_opp = v->mv_f_next[0][s->block_index[0] + v->blocks_off]
02263 + v->mv_f_next[0][s->block_index[1] + v->blocks_off]
02264 + v->mv_f_next[0][s->block_index[2] + v->blocks_off]
02265 + v->mv_f_next[0][s->block_index[3] + v->blocks_off];
02266 f = (total_opp > 2) ? 1 : 0;
02267 } else {
02268 s->mv[0][0][0] = s->mv[0][0][1] = 0;
02269 s->mv[1][0][0] = s->mv[1][0][1] = 0;
02270 f = 0;
02271 }
02272 v->ref_field_type[0] = v->ref_field_type[1] = v->cur_field_type ^ f;
02273 for (k = 0; k < 4; k++) {
02274 s->current_picture.f.motion_val[0][s->block_index[k] + v->blocks_off][0] = s->mv[0][0][0];
02275 s->current_picture.f.motion_val[0][s->block_index[k] + v->blocks_off][1] = s->mv[0][0][1];
02276 s->current_picture.f.motion_val[1][s->block_index[k] + v->blocks_off][0] = s->mv[1][0][0];
02277 s->current_picture.f.motion_val[1][s->block_index[k] + v->blocks_off][1] = s->mv[1][0][1];
02278 v->mv_f[0][s->block_index[k] + v->blocks_off] = f;
02279 v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
02280 }
02281 return;
02282 }
02283 if (v->bmvtype == BMV_TYPE_INTERPOLATED) {
02284 vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0);
02285 vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1);
02286 return;
02287 }
02288 if (dir) {
02289 vc1_pred_mv(v, n, dmv_x[1], dmv_y[1], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1);
02290 if (n == 3 || mv1) {
02291 vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
02292 }
02293 } else {
02294 vc1_pred_mv(v, n, dmv_x[0], dmv_y[0], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0);
02295 if (n == 3 || mv1) {
02296 vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type[0], 0, 1);
02297 }
02298 }
02299 }
02300
02310 static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
02311 int16_t **dc_val_ptr, int *dir_ptr)
02312 {
02313 int a, b, c, wrap, pred, scale;
02314 int16_t *dc_val;
02315 static const uint16_t dcpred[32] = {
02316 -1, 1024, 512, 341, 256, 205, 171, 146, 128,
02317 114, 102, 93, 85, 79, 73, 68, 64,
02318 60, 57, 54, 51, 49, 47, 45, 43,
02319 41, 39, 38, 37, 35, 34, 33
02320 };
02321
02322
02323 if (n < 4) scale = s->y_dc_scale;
02324 else scale = s->c_dc_scale;
02325
02326 wrap = s->block_wrap[n];
02327 dc_val = s->dc_val[0] + s->block_index[n];
02328
02329
02330
02331
02332 c = dc_val[ - 1];
02333 b = dc_val[ - 1 - wrap];
02334 a = dc_val[ - wrap];
02335
02336 if (pq < 9 || !overlap) {
02337
02338 if (s->first_slice_line && (n != 2 && n != 3))
02339 b = a = dcpred[scale];
02340 if (s->mb_x == 0 && (n != 1 && n != 3))
02341 b = c = dcpred[scale];
02342 } else {
02343
02344 if (s->first_slice_line && (n != 2 && n != 3))
02345 b = a = 0;
02346 if (s->mb_x == 0 && (n != 1 && n != 3))
02347 b = c = 0;
02348 }
02349
02350 if (abs(a - b) <= abs(b - c)) {
02351 pred = c;
02352 *dir_ptr = 1;
02353 } else {
02354 pred = a;
02355 *dir_ptr = 0;
02356 }
02357
02358
02359 *dc_val_ptr = &dc_val[0];
02360 return pred;
02361 }
02362
02363
02375 static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n,
02376 int a_avail, int c_avail,
02377 int16_t **dc_val_ptr, int *dir_ptr)
02378 {
02379 int a, b, c, wrap, pred;
02380 int16_t *dc_val;
02381 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
02382 int q1, q2 = 0;
02383 int dqscale_index;
02384
02385 wrap = s->block_wrap[n];
02386 dc_val = s->dc_val[0] + s->block_index[n];
02387
02388
02389
02390
02391 c = dc_val[ - 1];
02392 b = dc_val[ - 1 - wrap];
02393 a = dc_val[ - wrap];
02394
02395 q1 = s->current_picture.f.qscale_table[mb_pos];
02396 dqscale_index = s->y_dc_scale_table[q1] - 1;
02397 if (dqscale_index < 0)
02398 return 0;
02399 if (c_avail && (n != 1 && n != 3)) {
02400 q2 = s->current_picture.f.qscale_table[mb_pos - 1];
02401 if (q2 && q2 != q1)
02402 c = (c * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
02403 }
02404 if (a_avail && (n != 2 && n != 3)) {
02405 q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride];
02406 if (q2 && q2 != q1)
02407 a = (a * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
02408 }
02409 if (a_avail && c_avail && (n != 3)) {
02410 int off = mb_pos;
02411 if (n != 1)
02412 off--;
02413 if (n != 2)
02414 off -= s->mb_stride;
02415 q2 = s->current_picture.f.qscale_table[off];
02416 if (q2 && q2 != q1)
02417 b = (b * s->y_dc_scale_table[q2] * ff_vc1_dqscale[dqscale_index] + 0x20000) >> 18;
02418 }
02419
02420 if (a_avail && c_avail) {
02421 if (abs(a - b) <= abs(b - c)) {
02422 pred = c;
02423 *dir_ptr = 1;
02424 } else {
02425 pred = a;
02426 *dir_ptr = 0;
02427 }
02428 } else if (a_avail) {
02429 pred = a;
02430 *dir_ptr = 0;
02431 } else if (c_avail) {
02432 pred = c;
02433 *dir_ptr = 1;
02434 } else {
02435 pred = 0;
02436 *dir_ptr = 1;
02437 }
02438
02439
02440 *dc_val_ptr = &dc_val[0];
02441 return pred;
02442 }
02443
02445
02452 static inline int vc1_coded_block_pred(MpegEncContext * s, int n,
02453 uint8_t **coded_block_ptr)
02454 {
02455 int xy, wrap, pred, a, b, c;
02456
02457 xy = s->block_index[n];
02458 wrap = s->b8_stride;
02459
02460
02461
02462
02463 a = s->coded_block[xy - 1 ];
02464 b = s->coded_block[xy - 1 - wrap];
02465 c = s->coded_block[xy - wrap];
02466
02467 if (b == c) {
02468 pred = a;
02469 } else {
02470 pred = c;
02471 }
02472
02473
02474 *coded_block_ptr = &s->coded_block[xy];
02475
02476 return pred;
02477 }
02478
02488 static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
02489 int *value, int codingset)
02490 {
02491 GetBitContext *gb = &v->s.gb;
02492 int index, escape, run = 0, level = 0, lst = 0;
02493
02494 index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
02495 if (index != ff_vc1_ac_sizes[codingset] - 1) {
02496 run = vc1_index_decode_table[codingset][index][0];
02497 level = vc1_index_decode_table[codingset][index][1];
02498 lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0;
02499 if (get_bits1(gb))
02500 level = -level;
02501 } else {
02502 escape = decode210(gb);
02503 if (escape != 2) {
02504 index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
02505 run = vc1_index_decode_table[codingset][index][0];
02506 level = vc1_index_decode_table[codingset][index][1];
02507 lst = index >= vc1_last_decode_table[codingset];
02508 if (escape == 0) {
02509 if (lst)
02510 level += vc1_last_delta_level_table[codingset][run];
02511 else
02512 level += vc1_delta_level_table[codingset][run];
02513 } else {
02514 if (lst)
02515 run += vc1_last_delta_run_table[codingset][level] + 1;
02516 else
02517 run += vc1_delta_run_table[codingset][level] + 1;
02518 }
02519 if (get_bits1(gb))
02520 level = -level;
02521 } else {
02522 int sign;
02523 lst = get_bits1(gb);
02524 if (v->s.esc3_level_length == 0) {
02525 if (v->pq < 8 || v->dquantfrm) {
02526 v->s.esc3_level_length = get_bits(gb, 3);
02527 if (!v->s.esc3_level_length)
02528 v->s.esc3_level_length = get_bits(gb, 2) + 8;
02529 } else {
02530 v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;
02531 }
02532 v->s.esc3_run_length = 3 + get_bits(gb, 2);
02533 }
02534 run = get_bits(gb, v->s.esc3_run_length);
02535 sign = get_bits1(gb);
02536 level = get_bits(gb, v->s.esc3_level_length);
02537 if (sign)
02538 level = -level;
02539 }
02540 }
02541
02542 *last = lst;
02543 *skip = run;
02544 *value = level;
02545 }
02546
02554 static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n,
02555 int coded, int codingset)
02556 {
02557 GetBitContext *gb = &v->s.gb;
02558 MpegEncContext *s = &v->s;
02559 int dc_pred_dir = 0;
02560 int i;
02561 int16_t *dc_val;
02562 int16_t *ac_val, *ac_val2;
02563 int dcdiff;
02564
02565
02566 if (n < 4) {
02567 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
02568 } else {
02569 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
02570 }
02571 if (dcdiff < 0) {
02572 av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
02573 return -1;
02574 }
02575 if (dcdiff) {
02576 if (dcdiff == 119 ) {
02577
02578 if (v->pq == 1) dcdiff = get_bits(gb, 10);
02579 else if (v->pq == 2) dcdiff = get_bits(gb, 9);
02580 else dcdiff = get_bits(gb, 8);
02581 } else {
02582 if (v->pq == 1)
02583 dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;
02584 else if (v->pq == 2)
02585 dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;
02586 }
02587 if (get_bits1(gb))
02588 dcdiff = -dcdiff;
02589 }
02590
02591
02592 dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);
02593 *dc_val = dcdiff;
02594
02595
02596 if (n < 4) {
02597 block[0] = dcdiff * s->y_dc_scale;
02598 } else {
02599 block[0] = dcdiff * s->c_dc_scale;
02600 }
02601
02602 if (!coded) {
02603 goto not_coded;
02604 }
02605
02606
02607 i = 1;
02608
02609 {
02610 int last = 0, skip, value;
02611 const uint8_t *zz_table;
02612 int scale;
02613 int k;
02614
02615 scale = v->pq * 2 + v->halfpq;
02616
02617 if (v->s.ac_pred) {
02618 if (!dc_pred_dir)
02619 zz_table = v->zz_8x8[2];
02620 else
02621 zz_table = v->zz_8x8[3];
02622 } else
02623 zz_table = v->zz_8x8[1];
02624
02625 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
02626 ac_val2 = ac_val;
02627 if (dc_pred_dir)
02628 ac_val -= 16;
02629 else
02630 ac_val -= 16 * s->block_wrap[n];
02631
02632 while (!last) {
02633 vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
02634 i += skip;
02635 if (i > 63)
02636 break;
02637 block[zz_table[i++]] = value;
02638 }
02639
02640
02641 if (s->ac_pred) {
02642 if (dc_pred_dir) {
02643 for (k = 1; k < 8; k++)
02644 block[k << v->left_blk_sh] += ac_val[k];
02645 } else {
02646 for (k = 1; k < 8; k++)
02647 block[k << v->top_blk_sh] += ac_val[k + 8];
02648 }
02649 }
02650
02651 for (k = 1; k < 8; k++) {
02652 ac_val2[k] = block[k << v->left_blk_sh];
02653 ac_val2[k + 8] = block[k << v->top_blk_sh];
02654 }
02655
02656
02657 for (k = 1; k < 64; k++)
02658 if (block[k]) {
02659 block[k] *= scale;
02660 if (!v->pquantizer)
02661 block[k] += (block[k] < 0) ? -v->pq : v->pq;
02662 }
02663
02664 if (s->ac_pred) i = 63;
02665 }
02666
02667 not_coded:
02668 if (!coded) {
02669 int k, scale;
02670 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
02671 ac_val2 = ac_val;
02672
02673 i = 0;
02674 scale = v->pq * 2 + v->halfpq;
02675 memset(ac_val2, 0, 16 * 2);
02676 if (dc_pred_dir) {
02677 ac_val -= 16;
02678 if (s->ac_pred)
02679 memcpy(ac_val2, ac_val, 8 * 2);
02680 } else {
02681 ac_val -= 16 * s->block_wrap[n];
02682 if (s->ac_pred)
02683 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
02684 }
02685
02686
02687 if (s->ac_pred) {
02688 if (dc_pred_dir) {
02689 for (k = 1; k < 8; k++) {
02690 block[k << v->left_blk_sh] = ac_val[k] * scale;
02691 if (!v->pquantizer && block[k << v->left_blk_sh])
02692 block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -v->pq : v->pq;
02693 }
02694 } else {
02695 for (k = 1; k < 8; k++) {
02696 block[k << v->top_blk_sh] = ac_val[k + 8] * scale;
02697 if (!v->pquantizer && block[k << v->top_blk_sh])
02698 block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -v->pq : v->pq;
02699 }
02700 }
02701 i = 63;
02702 }
02703 }
02704 s->block_last_index[n] = i;
02705
02706 return 0;
02707 }
02708
02717 static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n,
02718 int coded, int codingset, int mquant)
02719 {
02720 GetBitContext *gb = &v->s.gb;
02721 MpegEncContext *s = &v->s;
02722 int dc_pred_dir = 0;
02723 int i;
02724 int16_t *dc_val;
02725 int16_t *ac_val, *ac_val2;
02726 int dcdiff;
02727 int a_avail = v->a_avail, c_avail = v->c_avail;
02728 int use_pred = s->ac_pred;
02729 int scale;
02730 int q1, q2 = 0;
02731 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
02732
02733
02734 if (n < 4) {
02735 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
02736 } else {
02737 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
02738 }
02739 if (dcdiff < 0) {
02740 av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
02741 return -1;
02742 }
02743 if (dcdiff) {
02744 if (dcdiff == 119 ) {
02745
02746 if (mquant == 1) dcdiff = get_bits(gb, 10);
02747 else if (mquant == 2) dcdiff = get_bits(gb, 9);
02748 else dcdiff = get_bits(gb, 8);
02749 } else {
02750 if (mquant == 1)
02751 dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;
02752 else if (mquant == 2)
02753 dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;
02754 }
02755 if (get_bits1(gb))
02756 dcdiff = -dcdiff;
02757 }
02758
02759
02760 dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir);
02761 *dc_val = dcdiff;
02762
02763
02764 if (n < 4) {
02765 block[0] = dcdiff * s->y_dc_scale;
02766 } else {
02767 block[0] = dcdiff * s->c_dc_scale;
02768 }
02769
02770
02771 i = 1;
02772
02773
02774 if (!a_avail && !c_avail)
02775 use_pred = 0;
02776 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
02777 ac_val2 = ac_val;
02778
02779 scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0);
02780
02781 if (dc_pred_dir)
02782 ac_val -= 16;
02783 else
02784 ac_val -= 16 * s->block_wrap[n];
02785
02786 q1 = s->current_picture.f.qscale_table[mb_pos];
02787 if ( dc_pred_dir && c_avail && mb_pos)
02788 q2 = s->current_picture.f.qscale_table[mb_pos - 1];
02789 if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride)
02790 q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride];
02791 if ( dc_pred_dir && n == 1)
02792 q2 = q1;
02793 if (!dc_pred_dir && n == 2)
02794 q2 = q1;
02795 if (n == 3)
02796 q2 = q1;
02797
02798 if (coded) {
02799 int last = 0, skip, value;
02800 const uint8_t *zz_table;
02801 int k;
02802
02803 if (v->s.ac_pred) {
02804 if (!use_pred && v->fcm == ILACE_FRAME) {
02805 zz_table = v->zzi_8x8;
02806 } else {
02807 if (!dc_pred_dir)
02808 zz_table = v->zz_8x8[2];
02809 else
02810 zz_table = v->zz_8x8[3];
02811 }
02812 } else {
02813 if (v->fcm != ILACE_FRAME)
02814 zz_table = v->zz_8x8[1];
02815 else
02816 zz_table = v->zzi_8x8;
02817 }
02818
02819 while (!last) {
02820 vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
02821 i += skip;
02822 if (i > 63)
02823 break;
02824 block[zz_table[i++]] = value;
02825 }
02826
02827
02828 if (use_pred) {
02829
02830 if (q2 && q1 != q2) {
02831 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
02832 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
02833
02834 if (q1 < 1)
02835 return AVERROR_INVALIDDATA;
02836 if (dc_pred_dir) {
02837 for (k = 1; k < 8; k++)
02838 block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
02839 } else {
02840 for (k = 1; k < 8; k++)
02841 block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
02842 }
02843 } else {
02844 if (dc_pred_dir) {
02845 for (k = 1; k < 8; k++)
02846 block[k << v->left_blk_sh] += ac_val[k];
02847 } else {
02848 for (k = 1; k < 8; k++)
02849 block[k << v->top_blk_sh] += ac_val[k + 8];
02850 }
02851 }
02852 }
02853
02854 for (k = 1; k < 8; k++) {
02855 ac_val2[k ] = block[k << v->left_blk_sh];
02856 ac_val2[k + 8] = block[k << v->top_blk_sh];
02857 }
02858
02859
02860 for (k = 1; k < 64; k++)
02861 if (block[k]) {
02862 block[k] *= scale;
02863 if (!v->pquantizer)
02864 block[k] += (block[k] < 0) ? -mquant : mquant;
02865 }
02866
02867 if (use_pred) i = 63;
02868 } else {
02869 int k;
02870
02871 memset(ac_val2, 0, 16 * 2);
02872 if (dc_pred_dir) {
02873 if (use_pred) {
02874 memcpy(ac_val2, ac_val, 8 * 2);
02875 if (q2 && q1 != q2) {
02876 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
02877 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
02878 if (q1 < 1)
02879 return AVERROR_INVALIDDATA;
02880 for (k = 1; k < 8; k++)
02881 ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
02882 }
02883 }
02884 } else {
02885 if (use_pred) {
02886 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
02887 if (q2 && q1 != q2) {
02888 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
02889 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
02890 if (q1 < 1)
02891 return AVERROR_INVALIDDATA;
02892 for (k = 1; k < 8; k++)
02893 ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
02894 }
02895 }
02896 }
02897
02898
02899 if (use_pred) {
02900 if (dc_pred_dir) {
02901 for (k = 1; k < 8; k++) {
02902 block[k << v->left_blk_sh] = ac_val2[k] * scale;
02903 if (!v->pquantizer && block[k << v->left_blk_sh])
02904 block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant;
02905 }
02906 } else {
02907 for (k = 1; k < 8; k++) {
02908 block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;
02909 if (!v->pquantizer && block[k << v->top_blk_sh])
02910 block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant;
02911 }
02912 }
02913 i = 63;
02914 }
02915 }
02916 s->block_last_index[n] = i;
02917
02918 return 0;
02919 }
02920
02929 static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n,
02930 int coded, int mquant, int codingset)
02931 {
02932 GetBitContext *gb = &v->s.gb;
02933 MpegEncContext *s = &v->s;
02934 int dc_pred_dir = 0;
02935 int i;
02936 int16_t *dc_val;
02937 int16_t *ac_val, *ac_val2;
02938 int dcdiff;
02939 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
02940 int a_avail = v->a_avail, c_avail = v->c_avail;
02941 int use_pred = s->ac_pred;
02942 int scale;
02943 int q1, q2 = 0;
02944
02945 s->dsp.clear_block(block);
02946
02947
02948 mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant);
02949
02950
02951 s->y_dc_scale = s->y_dc_scale_table[mquant];
02952 s->c_dc_scale = s->c_dc_scale_table[mquant];
02953
02954
02955 if (n < 4) {
02956 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
02957 } else {
02958 dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
02959 }
02960 if (dcdiff < 0) {
02961 av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
02962 return -1;
02963 }
02964 if (dcdiff) {
02965 if (dcdiff == 119 ) {
02966
02967 if (mquant == 1) dcdiff = get_bits(gb, 10);
02968 else if (mquant == 2) dcdiff = get_bits(gb, 9);
02969 else dcdiff = get_bits(gb, 8);
02970 } else {
02971 if (mquant == 1)
02972 dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;
02973 else if (mquant == 2)
02974 dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;
02975 }
02976 if (get_bits1(gb))
02977 dcdiff = -dcdiff;
02978 }
02979
02980
02981 dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);
02982 *dc_val = dcdiff;
02983
02984
02985
02986 if (n < 4) {
02987 block[0] = dcdiff * s->y_dc_scale;
02988 } else {
02989 block[0] = dcdiff * s->c_dc_scale;
02990 }
02991
02992
02993 i = 1;
02994
02995
02996 if (!a_avail) dc_pred_dir = 1;
02997 if (!c_avail) dc_pred_dir = 0;
02998 if (!a_avail && !c_avail) use_pred = 0;
02999 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
03000 ac_val2 = ac_val;
03001
03002 scale = mquant * 2 + v->halfpq;
03003
03004 if (dc_pred_dir)
03005 ac_val -= 16;
03006 else
03007 ac_val -= 16 * s->block_wrap[n];
03008
03009 q1 = s->current_picture.f.qscale_table[mb_pos];
03010 if (dc_pred_dir && c_avail && mb_pos)
03011 q2 = s->current_picture.f.qscale_table[mb_pos - 1];
03012 if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride)
03013 q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride];
03014 if ( dc_pred_dir && n == 1)
03015 q2 = q1;
03016 if (!dc_pred_dir && n == 2)
03017 q2 = q1;
03018 if (n == 3) q2 = q1;
03019
03020 if (coded) {
03021 int last = 0, skip, value;
03022 int k;
03023
03024 while (!last) {
03025 vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
03026 i += skip;
03027 if (i > 63)
03028 break;
03029 if (v->fcm == PROGRESSIVE)
03030 block[v->zz_8x8[0][i++]] = value;
03031 else {
03032 if (use_pred && (v->fcm == ILACE_FRAME)) {
03033 if (!dc_pred_dir)
03034 block[v->zz_8x8[2][i++]] = value;
03035 else
03036 block[v->zz_8x8[3][i++]] = value;
03037 } else {
03038 block[v->zzi_8x8[i++]] = value;
03039 }
03040 }
03041 }
03042
03043
03044 if (use_pred) {
03045
03046 if (q2 && q1 != q2) {
03047 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
03048 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
03049
03050 if (q1 < 1)
03051 return AVERROR_INVALIDDATA;
03052 if (dc_pred_dir) {
03053 for (k = 1; k < 8; k++)
03054 block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
03055 } else {
03056 for (k = 1; k < 8; k++)
03057 block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
03058 }
03059 } else {
03060 if (dc_pred_dir) {
03061 for (k = 1; k < 8; k++)
03062 block[k << v->left_blk_sh] += ac_val[k];
03063 } else {
03064 for (k = 1; k < 8; k++)
03065 block[k << v->top_blk_sh] += ac_val[k + 8];
03066 }
03067 }
03068 }
03069
03070 for (k = 1; k < 8; k++) {
03071 ac_val2[k ] = block[k << v->left_blk_sh];
03072 ac_val2[k + 8] = block[k << v->top_blk_sh];
03073 }
03074
03075
03076 for (k = 1; k < 64; k++)
03077 if (block[k]) {
03078 block[k] *= scale;
03079 if (!v->pquantizer)
03080 block[k] += (block[k] < 0) ? -mquant : mquant;
03081 }
03082
03083 if (use_pred) i = 63;
03084 } else {
03085 int k;
03086
03087 memset(ac_val2, 0, 16 * 2);
03088 if (dc_pred_dir) {
03089 if (use_pred) {
03090 memcpy(ac_val2, ac_val, 8 * 2);
03091 if (q2 && q1 != q2) {
03092 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
03093 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
03094 if (q1 < 1)
03095 return AVERROR_INVALIDDATA;
03096 for (k = 1; k < 8; k++)
03097 ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
03098 }
03099 }
03100 } else {
03101 if (use_pred) {
03102 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
03103 if (q2 && q1 != q2) {
03104 q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;
03105 q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;
03106 if (q1 < 1)
03107 return AVERROR_INVALIDDATA;
03108 for (k = 1; k < 8; k++)
03109 ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;
03110 }
03111 }
03112 }
03113
03114
03115 if (use_pred) {
03116 if (dc_pred_dir) {
03117 for (k = 1; k < 8; k++) {
03118 block[k << v->left_blk_sh] = ac_val2[k] * scale;
03119 if (!v->pquantizer && block[k << v->left_blk_sh])
03120 block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant;
03121 }
03122 } else {
03123 for (k = 1; k < 8; k++) {
03124 block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;
03125 if (!v->pquantizer && block[k << v->top_blk_sh])
03126 block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant;
03127 }
03128 }
03129 i = 63;
03130 }
03131 }
03132 s->block_last_index[n] = i;
03133
03134 return 0;
03135 }
03136
03139 static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n,
03140 int mquant, int ttmb, int first_block,
03141 uint8_t *dst, int linesize, int skip_block,
03142 int *ttmb_out)
03143 {
03144 MpegEncContext *s = &v->s;
03145 GetBitContext *gb = &s->gb;
03146 int i, j;
03147 int subblkpat = 0;
03148 int scale, off, idx, last, skip, value;
03149 int ttblk = ttmb & 7;
03150 int pat = 0;
03151
03152 s->dsp.clear_block(block);
03153
03154 if (ttmb == -1) {
03155 ttblk = ff_vc1_ttblk_to_tt[v->tt_index][get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
03156 }
03157 if (ttblk == TT_4X4) {
03158 subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
03159 }
03160 if ((ttblk != TT_8X8 && ttblk != TT_4X4)
03161 && ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
03162 || (!v->res_rtm_flag && !first_block))) {
03163 subblkpat = decode012(gb);
03164 if (subblkpat)
03165 subblkpat ^= 3;
03166 if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM)
03167 ttblk = TT_8X4;
03168 if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT)
03169 ttblk = TT_4X8;
03170 }
03171 scale = 2 * mquant + ((v->pq == mquant) ? v->halfpq : 0);
03172
03173
03174 if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) {
03175 subblkpat = 2 - (ttblk == TT_8X4_TOP);
03176 ttblk = TT_8X4;
03177 }
03178 if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
03179 subblkpat = 2 - (ttblk == TT_4X8_LEFT);
03180 ttblk = TT_4X8;
03181 }
03182 switch (ttblk) {
03183 case TT_8X8:
03184 pat = 0xF;
03185 i = 0;
03186 last = 0;
03187 while (!last) {
03188 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
03189 i += skip;
03190 if (i > 63)
03191 break;
03192 if (!v->fcm)
03193 idx = v->zz_8x8[0][i++];
03194 else
03195 idx = v->zzi_8x8[i++];
03196 block[idx] = value * scale;
03197 if (!v->pquantizer)
03198 block[idx] += (block[idx] < 0) ? -mquant : mquant;
03199 }
03200 if (!skip_block) {
03201 if (i == 1)
03202 v->vc1dsp.vc1_inv_trans_8x8_dc(dst, linesize, block);
03203 else {
03204 v->vc1dsp.vc1_inv_trans_8x8(block);
03205 s->dsp.add_pixels_clamped(block, dst, linesize);
03206 }
03207 }
03208 break;
03209 case TT_4X4:
03210 pat = ~subblkpat & 0xF;
03211 for (j = 0; j < 4; j++) {
03212 last = subblkpat & (1 << (3 - j));
03213 i = 0;
03214 off = (j & 1) * 4 + (j & 2) * 16;
03215 while (!last) {
03216 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
03217 i += skip;
03218 if (i > 15)
03219 break;
03220 if (!v->fcm)
03221 idx = ff_vc1_simple_progressive_4x4_zz[i++];
03222 else
03223 idx = ff_vc1_adv_interlaced_4x4_zz[i++];
03224 block[idx + off] = value * scale;
03225 if (!v->pquantizer)
03226 block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant;
03227 }
03228 if (!(subblkpat & (1 << (3 - j))) && !skip_block) {
03229 if (i == 1)
03230 v->vc1dsp.vc1_inv_trans_4x4_dc(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off);
03231 else
03232 v->vc1dsp.vc1_inv_trans_4x4(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off);
03233 }
03234 }
03235 break;
03236 case TT_8X4:
03237 pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF;
03238 for (j = 0; j < 2; j++) {
03239 last = subblkpat & (1 << (1 - j));
03240 i = 0;
03241 off = j * 32;
03242 while (!last) {
03243 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
03244 i += skip;
03245 if (i > 31)
03246 break;
03247 if (!v->fcm)
03248 idx = v->zz_8x4[i++] + off;
03249 else
03250 idx = ff_vc1_adv_interlaced_8x4_zz[i++] + off;
03251 block[idx] = value * scale;
03252 if (!v->pquantizer)
03253 block[idx] += (block[idx] < 0) ? -mquant : mquant;
03254 }
03255 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
03256 if (i == 1)
03257 v->vc1dsp.vc1_inv_trans_8x4_dc(dst + j * 4 * linesize, linesize, block + off);
03258 else
03259 v->vc1dsp.vc1_inv_trans_8x4(dst + j * 4 * linesize, linesize, block + off);
03260 }
03261 }
03262 break;
03263 case TT_4X8:
03264 pat = ~(subblkpat * 5) & 0xF;
03265 for (j = 0; j < 2; j++) {
03266 last = subblkpat & (1 << (1 - j));
03267 i = 0;
03268 off = j * 4;
03269 while (!last) {
03270 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
03271 i += skip;
03272 if (i > 31)
03273 break;
03274 if (!v->fcm)
03275 idx = v->zz_4x8[i++] + off;
03276 else
03277 idx = ff_vc1_adv_interlaced_4x8_zz[i++] + off;
03278 block[idx] = value * scale;
03279 if (!v->pquantizer)
03280 block[idx] += (block[idx] < 0) ? -mquant : mquant;
03281 }
03282 if (!(subblkpat & (1 << (1 - j))) && !skip_block) {
03283 if (i == 1)
03284 v->vc1dsp.vc1_inv_trans_4x8_dc(dst + j * 4, linesize, block + off);
03285 else
03286 v->vc1dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off);
03287 }
03288 }
03289 break;
03290 }
03291 if (ttmb_out)
03292 *ttmb_out |= ttblk << (n * 4);
03293 return pat;
03294 }
03295
03297
03298 static const int size_table [6] = { 0, 2, 3, 4, 5, 8 };
03299 static const int offset_table[6] = { 0, 1, 3, 7, 15, 31 };
03300
03301 static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_num)
03302 {
03303 MpegEncContext *s = &v->s;
03304 int mb_cbp = v->cbp[s->mb_x - s->mb_stride],
03305 block_cbp = mb_cbp >> (block_num * 4), bottom_cbp,
03306 mb_is_intra = v->is_intra[s->mb_x - s->mb_stride],
03307 block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra;
03308 int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
03309 uint8_t *dst;
03310
03311 if (block_num > 3) {
03312 dst = s->dest[block_num - 3];
03313 } else {
03314 dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize;
03315 }
03316 if (s->mb_y != s->end_mb_y || block_num < 2) {
03317 int16_t (*mv)[2];
03318 int mv_stride;
03319
03320 if (block_num > 3) {
03321 bottom_cbp = v->cbp[s->mb_x] >> (block_num * 4);
03322 bottom_is_intra = v->is_intra[s->mb_x] >> (block_num * 4);
03323 mv = &v->luma_mv[s->mb_x - s->mb_stride];
03324 mv_stride = s->mb_stride;
03325 } else {
03326 bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4))
03327 : (v->cbp[s->mb_x] >> ((block_num - 2) * 4));
03328 bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4))
03329 : (v->is_intra[s->mb_x] >> ((block_num - 2) * 4));
03330 mv_stride = s->b8_stride;
03331 mv = &s->current_picture.f.motion_val[0][s->block_index[block_num] - 2 * mv_stride];
03332 }
03333
03334 if (bottom_is_intra & 1 || block_is_intra & 1 ||
03335 mv[0][0] != mv[mv_stride][0] || mv[0][1] != mv[mv_stride][1]) {
03336 v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
03337 } else {
03338 idx = ((bottom_cbp >> 2) | block_cbp) & 3;
03339 if (idx == 3) {
03340 v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
03341 } else if (idx) {
03342 if (idx == 1)
03343 v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq);
03344 else
03345 v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq);
03346 }
03347 }
03348 }
03349
03350 dst -= 4 * linesize;
03351 ttblk = (v->ttblk[s->mb_x - s->mb_stride] >> (block_num * 4)) & 0xF;
03352 if (ttblk == TT_4X4 || ttblk == TT_8X4) {
03353 idx = (block_cbp | (block_cbp >> 2)) & 3;
03354 if (idx == 3) {
03355 v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq);
03356 } else if (idx) {
03357 if (idx == 1)
03358 v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq);
03359 else
03360 v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq);
03361 }
03362 }
03363 }
03364
03365 static av_always_inline void vc1_apply_p_h_loop_filter(VC1Context *v, int block_num)
03366 {
03367 MpegEncContext *s = &v->s;
03368 int mb_cbp = v->cbp[s->mb_x - 1 - s->mb_stride],
03369 block_cbp = mb_cbp >> (block_num * 4), right_cbp,
03370 mb_is_intra = v->is_intra[s->mb_x - 1 - s->mb_stride],
03371 block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra;
03372 int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk;
03373 uint8_t *dst;
03374
03375 if (block_num > 3) {
03376 dst = s->dest[block_num - 3] - 8 * linesize;
03377 } else {
03378 dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 16) * linesize - 8;
03379 }
03380
03381 if (s->mb_x != s->mb_width || !(block_num & 5)) {
03382 int16_t (*mv)[2];
03383
03384 if (block_num > 3) {
03385 right_cbp = v->cbp[s->mb_x - s->mb_stride] >> (block_num * 4);
03386 right_is_intra = v->is_intra[s->mb_x - s->mb_stride] >> (block_num * 4);
03387 mv = &v->luma_mv[s->mb_x - s->mb_stride - 1];
03388 } else {
03389 right_cbp = (block_num & 1) ? (v->cbp[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4))
03390 : (mb_cbp >> ((block_num + 1) * 4));
03391 right_is_intra = (block_num & 1) ? (v->is_intra[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4))
03392 : (mb_is_intra >> ((block_num + 1) * 4));
03393 mv = &s->current_picture.f.motion_val[0][s->block_index[block_num] - s->b8_stride * 2 - 2];
03394 }
03395 if (block_is_intra & 1 || right_is_intra & 1 || mv[0][0] != mv[1][0] || mv[0][1] != mv[1][1]) {
03396 v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
03397 } else {
03398 idx = ((right_cbp >> 1) | block_cbp) & 5;
03399 if (idx == 5) {
03400 v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
03401 } else if (idx) {
03402 if (idx == 1)
03403 v->vc1dsp.vc1_h_loop_filter4(dst + 4 * linesize, linesize, v->pq);
03404 else
03405 v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq);
03406 }
03407 }
03408 }
03409
03410 dst -= 4;
03411 ttblk = (v->ttblk[s->mb_x - s->mb_stride - 1] >> (block_num * 4)) & 0xf;
03412 if (ttblk == TT_4X4 || ttblk == TT_4X8) {
03413 idx = (block_cbp | (block_cbp >> 1)) & 5;
03414 if (idx == 5) {
03415 v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq);
03416 } else if (idx) {
03417 if (idx == 1)
03418 v->vc1dsp.vc1_h_loop_filter4(dst + linesize * 4, linesize, v->pq);
03419 else
03420 v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq);
03421 }
03422 }
03423 }
03424
03425 static void vc1_apply_p_loop_filter(VC1Context *v)
03426 {
03427 MpegEncContext *s = &v->s;
03428 int i;
03429
03430 for (i = 0; i < 6; i++) {
03431 vc1_apply_p_v_loop_filter(v, i);
03432 }
03433
03434
03435
03436 if (s->mb_x) {
03437 for (i = 0; i < 6; i++) {
03438 vc1_apply_p_h_loop_filter(v, i);
03439 }
03440 if (s->mb_x == s->mb_width - 1) {
03441 s->mb_x++;
03442 ff_update_block_index(s);
03443 for (i = 0; i < 6; i++) {
03444 vc1_apply_p_h_loop_filter(v, i);
03445 }
03446 }
03447 }
03448 }
03449
03452 static int vc1_decode_p_mb(VC1Context *v)
03453 {
03454 MpegEncContext *s = &v->s;
03455 GetBitContext *gb = &s->gb;
03456 int i, j;
03457 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
03458 int cbp;
03459 int mqdiff, mquant;
03460 int ttmb = v->ttfrm;
03461
03462 int mb_has_coeffs = 1;
03463 int dmv_x, dmv_y;
03464 int index, index1;
03465 int val, sign;
03466 int first_block = 1;
03467 int dst_idx, off;
03468 int skipped, fourmv;
03469 int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
03470
03471 mquant = v->pq;
03472
03473 if (v->mv_type_is_raw)
03474 fourmv = get_bits1(gb);
03475 else
03476 fourmv = v->mv_type_mb_plane[mb_pos];
03477 if (v->skip_is_raw)
03478 skipped = get_bits1(gb);
03479 else
03480 skipped = v->s.mbskip_table[mb_pos];
03481
03482 if (!fourmv) {
03483 if (!skipped) {
03484 GET_MVDATA(dmv_x, dmv_y);
03485
03486 if (s->mb_intra) {
03487 s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
03488 s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
03489 }
03490 s->current_picture.f.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
03491 vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
03492
03493
03494 if (s->mb_intra && !mb_has_coeffs) {
03495 GET_MQUANT();
03496 s->ac_pred = get_bits1(gb);
03497 cbp = 0;
03498 } else if (mb_has_coeffs) {
03499 if (s->mb_intra)
03500 s->ac_pred = get_bits1(gb);
03501 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
03502 GET_MQUANT();
03503 } else {
03504 mquant = v->pq;
03505 cbp = 0;
03506 }
03507 s->current_picture.f.qscale_table[mb_pos] = mquant;
03508
03509 if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
03510 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,
03511 VC1_TTMB_VLC_BITS, 2);
03512 if (!s->mb_intra) vc1_mc_1mv(v, 0);
03513 dst_idx = 0;
03514 for (i = 0; i < 6; i++) {
03515 s->dc_val[0][s->block_index[i]] = 0;
03516 dst_idx += i >> 2;
03517 val = ((cbp >> (5 - i)) & 1);
03518 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
03519 v->mb_type[0][s->block_index[i]] = s->mb_intra;
03520 if (s->mb_intra) {
03521
03522 v->a_avail = v->c_avail = 0;
03523 if (i == 2 || i == 3 || !s->first_slice_line)
03524 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
03525 if (i == 1 || i == 3 || s->mb_x)
03526 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
03527
03528 vc1_decode_intra_block(v, s->block[i], i, val, mquant,
03529 (i & 4) ? v->codingset2 : v->codingset);
03530 if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
03531 continue;
03532 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
03533 if (v->rangeredfrm)
03534 for (j = 0; j < 64; j++)
03535 s->block[i][j] <<= 1;
03536 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
03537 if (v->pq >= 9 && v->overlap) {
03538 if (v->c_avail)
03539 v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
03540 if (v->a_avail)
03541 v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
03542 }
03543 block_cbp |= 0xF << (i << 2);
03544 block_intra |= 1 << i;
03545 } else if (val) {
03546 pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block,
03547 s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize,
03548 (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
03549 block_cbp |= pat << (i << 2);
03550 if (!v->ttmbf && ttmb < 8)
03551 ttmb = -1;
03552 first_block = 0;
03553 }
03554 }
03555 } else {
03556 s->mb_intra = 0;
03557 for (i = 0; i < 6; i++) {
03558 v->mb_type[0][s->block_index[i]] = 0;
03559 s->dc_val[0][s->block_index[i]] = 0;
03560 }
03561 s->current_picture.f.mb_type[mb_pos] = MB_TYPE_SKIP;
03562 s->current_picture.f.qscale_table[mb_pos] = 0;
03563 vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
03564 vc1_mc_1mv(v, 0);
03565 }
03566 } else {
03567 if (!skipped ) {
03568 int intra_count = 0, coded_inter = 0;
03569 int is_intra[6], is_coded[6];
03570
03571 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
03572 for (i = 0; i < 6; i++) {
03573 val = ((cbp >> (5 - i)) & 1);
03574 s->dc_val[0][s->block_index[i]] = 0;
03575 s->mb_intra = 0;
03576 if (i < 4) {
03577 dmv_x = dmv_y = 0;
03578 s->mb_intra = 0;
03579 mb_has_coeffs = 0;
03580 if (val) {
03581 GET_MVDATA(dmv_x, dmv_y);
03582 }
03583 vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
03584 if (!s->mb_intra)
03585 vc1_mc_4mv_luma(v, i, 0);
03586 intra_count += s->mb_intra;
03587 is_intra[i] = s->mb_intra;
03588 is_coded[i] = mb_has_coeffs;
03589 }
03590 if (i & 4) {
03591 is_intra[i] = (intra_count >= 3);
03592 is_coded[i] = val;
03593 }
03594 if (i == 4)
03595 vc1_mc_4mv_chroma(v, 0);
03596 v->mb_type[0][s->block_index[i]] = is_intra[i];
03597 if (!coded_inter)
03598 coded_inter = !is_intra[i] & is_coded[i];
03599 }
03600
03601 dst_idx = 0;
03602 if (!intra_count && !coded_inter)
03603 goto end;
03604 GET_MQUANT();
03605 s->current_picture.f.qscale_table[mb_pos] = mquant;
03606
03607 {
03608 int intrapred = 0;
03609 for (i = 0; i < 6; i++)
03610 if (is_intra[i]) {
03611 if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
03612 || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) {
03613 intrapred = 1;
03614 break;
03615 }
03616 }
03617 if (intrapred)
03618 s->ac_pred = get_bits1(gb);
03619 else
03620 s->ac_pred = 0;
03621 }
03622 if (!v->ttmbf && coded_inter)
03623 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
03624 for (i = 0; i < 6; i++) {
03625 dst_idx += i >> 2;
03626 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
03627 s->mb_intra = is_intra[i];
03628 if (is_intra[i]) {
03629
03630 v->a_avail = v->c_avail = 0;
03631 if (i == 2 || i == 3 || !s->first_slice_line)
03632 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
03633 if (i == 1 || i == 3 || s->mb_x)
03634 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
03635
03636 vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant,
03637 (i & 4) ? v->codingset2 : v->codingset);
03638 if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
03639 continue;
03640 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
03641 if (v->rangeredfrm)
03642 for (j = 0; j < 64; j++)
03643 s->block[i][j] <<= 1;
03644 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off,
03645 (i & 4) ? s->uvlinesize : s->linesize);
03646 if (v->pq >= 9 && v->overlap) {
03647 if (v->c_avail)
03648 v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
03649 if (v->a_avail)
03650 v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
03651 }
03652 block_cbp |= 0xF << (i << 2);
03653 block_intra |= 1 << i;
03654 } else if (is_coded[i]) {
03655 pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
03656 first_block, s->dest[dst_idx] + off,
03657 (i & 4) ? s->uvlinesize : s->linesize,
03658 (i & 4) && (s->flags & CODEC_FLAG_GRAY),
03659 &block_tt);
03660 block_cbp |= pat << (i << 2);
03661 if (!v->ttmbf && ttmb < 8)
03662 ttmb = -1;
03663 first_block = 0;
03664 }
03665 }
03666 } else {
03667 s->mb_intra = 0;
03668 s->current_picture.f.qscale_table[mb_pos] = 0;
03669 for (i = 0; i < 6; i++) {
03670 v->mb_type[0][s->block_index[i]] = 0;
03671 s->dc_val[0][s->block_index[i]] = 0;
03672 }
03673 for (i = 0; i < 4; i++) {
03674 vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
03675 vc1_mc_4mv_luma(v, i, 0);
03676 }
03677 vc1_mc_4mv_chroma(v, 0);
03678 s->current_picture.f.qscale_table[mb_pos] = 0;
03679 }
03680 }
03681 end:
03682 v->cbp[s->mb_x] = block_cbp;
03683 v->ttblk[s->mb_x] = block_tt;
03684 v->is_intra[s->mb_x] = block_intra;
03685
03686 return 0;
03687 }
03688
03689
03690
03691 static int vc1_decode_p_mb_intfr(VC1Context *v)
03692 {
03693 MpegEncContext *s = &v->s;
03694 GetBitContext *gb = &s->gb;
03695 int i;
03696 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
03697 int cbp = 0;
03698 int mqdiff, mquant;
03699 int ttmb = v->ttfrm;
03700
03701 int mb_has_coeffs = 1;
03702 int dmv_x, dmv_y;
03703 int val;
03704 int first_block = 1;
03705 int dst_idx, off;
03706 int skipped, fourmv = 0, twomv = 0;
03707 int block_cbp = 0, pat, block_tt = 0;
03708 int idx_mbmode = 0, mvbp;
03709 int stride_y, fieldtx;
03710
03711 mquant = v->pq;
03712
03713 if (v->skip_is_raw)
03714 skipped = get_bits1(gb);
03715 else
03716 skipped = v->s.mbskip_table[mb_pos];
03717 if (!skipped) {
03718 if (v->fourmvswitch)
03719 idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_4MV_MBMODE_VLC_BITS, 2);
03720 else
03721 idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2);
03722 switch (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0]) {
03723
03724 case MV_PMODE_INTFR_4MV:
03725 fourmv = 1;
03726 v->blk_mv_type[s->block_index[0]] = 0;
03727 v->blk_mv_type[s->block_index[1]] = 0;
03728 v->blk_mv_type[s->block_index[2]] = 0;
03729 v->blk_mv_type[s->block_index[3]] = 0;
03730 break;
03731 case MV_PMODE_INTFR_4MV_FIELD:
03732 fourmv = 1;
03733 v->blk_mv_type[s->block_index[0]] = 1;
03734 v->blk_mv_type[s->block_index[1]] = 1;
03735 v->blk_mv_type[s->block_index[2]] = 1;
03736 v->blk_mv_type[s->block_index[3]] = 1;
03737 break;
03738 case MV_PMODE_INTFR_2MV_FIELD:
03739 twomv = 1;
03740 v->blk_mv_type[s->block_index[0]] = 1;
03741 v->blk_mv_type[s->block_index[1]] = 1;
03742 v->blk_mv_type[s->block_index[2]] = 1;
03743 v->blk_mv_type[s->block_index[3]] = 1;
03744 break;
03745 case MV_PMODE_INTFR_1MV:
03746 v->blk_mv_type[s->block_index[0]] = 0;
03747 v->blk_mv_type[s->block_index[1]] = 0;
03748 v->blk_mv_type[s->block_index[2]] = 0;
03749 v->blk_mv_type[s->block_index[3]] = 0;
03750 break;
03751 }
03752 if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) {
03753 s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
03754 s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
03755 s->current_picture.f.mb_type[mb_pos] = MB_TYPE_INTRA;
03756 s->mb_intra = v->is_intra[s->mb_x] = 1;
03757 for (i = 0; i < 6; i++)
03758 v->mb_type[0][s->block_index[i]] = 1;
03759 fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
03760 mb_has_coeffs = get_bits1(gb);
03761 if (mb_has_coeffs)
03762 cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
03763 v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
03764 GET_MQUANT();
03765 s->current_picture.f.qscale_table[mb_pos] = mquant;
03766
03767 s->y_dc_scale = s->y_dc_scale_table[mquant];
03768 s->c_dc_scale = s->c_dc_scale_table[mquant];
03769 dst_idx = 0;
03770 for (i = 0; i < 6; i++) {
03771 s->dc_val[0][s->block_index[i]] = 0;
03772 dst_idx += i >> 2;
03773 val = ((cbp >> (5 - i)) & 1);
03774 v->mb_type[0][s->block_index[i]] = s->mb_intra;
03775 v->a_avail = v->c_avail = 0;
03776 if (i == 2 || i == 3 || !s->first_slice_line)
03777 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
03778 if (i == 1 || i == 3 || s->mb_x)
03779 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
03780
03781 vc1_decode_intra_block(v, s->block[i], i, val, mquant,
03782 (i & 4) ? v->codingset2 : v->codingset);
03783 if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
03784 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
03785 if (i < 4) {
03786 stride_y = s->linesize << fieldtx;
03787 off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize;
03788 } else {
03789 stride_y = s->uvlinesize;
03790 off = 0;
03791 }
03792 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, stride_y);
03793
03794 }
03795
03796 } else {
03797 mb_has_coeffs = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][3];
03798 if (mb_has_coeffs)
03799 cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
03800 if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
03801 v->twomvbp = get_vlc2(gb, v->twomvbp_vlc->table, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
03802 } else {
03803 if ((ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV)
03804 || (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV_FIELD)) {
03805 v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
03806 }
03807 }
03808 s->mb_intra = v->is_intra[s->mb_x] = 0;
03809 for (i = 0; i < 6; i++)
03810 v->mb_type[0][s->block_index[i]] = 0;
03811 fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][1];
03812
03813 dst_idx = 0;
03814 if (fourmv) {
03815 mvbp = v->fourmvbp;
03816 for (i = 0; i < 6; i++) {
03817 if (i < 4) {
03818 dmv_x = dmv_y = 0;
03819 val = ((mvbp >> (3 - i)) & 1);
03820 if (val) {
03821 get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
03822 }
03823 vc1_pred_mv_intfr(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
03824 vc1_mc_4mv_luma(v, i, 0);
03825 } else if (i == 4) {
03826 vc1_mc_4mv_chroma4(v);
03827 }
03828 }
03829 } else if (twomv) {
03830 mvbp = v->twomvbp;
03831 dmv_x = dmv_y = 0;
03832 if (mvbp & 2) {
03833 get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
03834 }
03835 vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0]);
03836 vc1_mc_4mv_luma(v, 0, 0);
03837 vc1_mc_4mv_luma(v, 1, 0);
03838 dmv_x = dmv_y = 0;
03839 if (mvbp & 1) {
03840 get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
03841 }
03842 vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0]);
03843 vc1_mc_4mv_luma(v, 2, 0);
03844 vc1_mc_4mv_luma(v, 3, 0);
03845 vc1_mc_4mv_chroma4(v);
03846 } else {
03847 mvbp = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][2];
03848 dmv_x = dmv_y = 0;
03849 if (mvbp) {
03850 get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
03851 }
03852 vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
03853 vc1_mc_1mv(v, 0);
03854 }
03855 if (cbp)
03856 GET_MQUANT();
03857 s->current_picture.f.qscale_table[mb_pos] = mquant;
03858 if (!v->ttmbf && cbp)
03859 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
03860 for (i = 0; i < 6; i++) {
03861 s->dc_val[0][s->block_index[i]] = 0;
03862 dst_idx += i >> 2;
03863 val = ((cbp >> (5 - i)) & 1);
03864 if (!fieldtx)
03865 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
03866 else
03867 off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize));
03868 if (val) {
03869 pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
03870 first_block, s->dest[dst_idx] + off,
03871 (i & 4) ? s->uvlinesize : (s->linesize << fieldtx),
03872 (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
03873 block_cbp |= pat << (i << 2);
03874 if (!v->ttmbf && ttmb < 8)
03875 ttmb = -1;
03876 first_block = 0;
03877 }
03878 }
03879 }
03880 } else {
03881 s->mb_intra = v->is_intra[s->mb_x] = 0;
03882 for (i = 0; i < 6; i++) {
03883 v->mb_type[0][s->block_index[i]] = 0;
03884 s->dc_val[0][s->block_index[i]] = 0;
03885 }
03886 s->current_picture.f.mb_type[mb_pos] = MB_TYPE_SKIP;
03887 s->current_picture.f.qscale_table[mb_pos] = 0;
03888 v->blk_mv_type[s->block_index[0]] = 0;
03889 v->blk_mv_type[s->block_index[1]] = 0;
03890 v->blk_mv_type[s->block_index[2]] = 0;
03891 v->blk_mv_type[s->block_index[3]] = 0;
03892 vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
03893 vc1_mc_1mv(v, 0);
03894 }
03895 if (s->mb_x == s->mb_width - 1)
03896 memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0])*s->mb_stride);
03897 return 0;
03898 }
03899
03900 static int vc1_decode_p_mb_intfi(VC1Context *v)
03901 {
03902 MpegEncContext *s = &v->s;
03903 GetBitContext *gb = &s->gb;
03904 int i;
03905 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
03906 int cbp = 0;
03907 int mqdiff, mquant;
03908 int ttmb = v->ttfrm;
03909
03910 int mb_has_coeffs = 1;
03911 int dmv_x, dmv_y;
03912 int val;
03913 int first_block = 1;
03914 int dst_idx, off;
03915 int pred_flag = 0;
03916 int block_cbp = 0, pat, block_tt = 0;
03917 int idx_mbmode = 0;
03918
03919 mquant = v->pq;
03920
03921 idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
03922 if (idx_mbmode <= 1) {
03923 s->mb_intra = v->is_intra[s->mb_x] = 1;
03924 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
03925 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
03926 s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
03927 GET_MQUANT();
03928 s->current_picture.f.qscale_table[mb_pos] = mquant;
03929
03930 s->y_dc_scale = s->y_dc_scale_table[mquant];
03931 s->c_dc_scale = s->c_dc_scale_table[mquant];
03932 v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
03933 mb_has_coeffs = idx_mbmode & 1;
03934 if (mb_has_coeffs)
03935 cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
03936 dst_idx = 0;
03937 for (i = 0; i < 6; i++) {
03938 s->dc_val[0][s->block_index[i]] = 0;
03939 v->mb_type[0][s->block_index[i]] = 1;
03940 dst_idx += i >> 2;
03941 val = ((cbp >> (5 - i)) & 1);
03942 v->a_avail = v->c_avail = 0;
03943 if (i == 2 || i == 3 || !s->first_slice_line)
03944 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
03945 if (i == 1 || i == 3 || s->mb_x)
03946 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
03947
03948 vc1_decode_intra_block(v, s->block[i], i, val, mquant,
03949 (i & 4) ? v->codingset2 : v->codingset);
03950 if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
03951 continue;
03952 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
03953 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
03954 off += v->second_field ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0;
03955 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize);
03956
03957 }
03958 } else {
03959 s->mb_intra = v->is_intra[s->mb_x] = 0;
03960 s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
03961 for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;
03962 if (idx_mbmode <= 5) {
03963 dmv_x = dmv_y = pred_flag = 0;
03964 if (idx_mbmode & 1) {
03965 get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
03966 }
03967 vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
03968 vc1_mc_1mv(v, 0);
03969 mb_has_coeffs = !(idx_mbmode & 2);
03970 } else {
03971 v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
03972 for (i = 0; i < 6; i++) {
03973 if (i < 4) {
03974 dmv_x = dmv_y = pred_flag = 0;
03975 val = ((v->fourmvbp >> (3 - i)) & 1);
03976 if (val) {
03977 get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
03978 }
03979 vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
03980 vc1_mc_4mv_luma(v, i, 0);
03981 } else if (i == 4)
03982 vc1_mc_4mv_chroma(v, 0);
03983 }
03984 mb_has_coeffs = idx_mbmode & 1;
03985 }
03986 if (mb_has_coeffs)
03987 cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
03988 if (cbp) {
03989 GET_MQUANT();
03990 }
03991 s->current_picture.f.qscale_table[mb_pos] = mquant;
03992 if (!v->ttmbf && cbp) {
03993 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
03994 }
03995 dst_idx = 0;
03996 for (i = 0; i < 6; i++) {
03997 s->dc_val[0][s->block_index[i]] = 0;
03998 dst_idx += i >> 2;
03999 val = ((cbp >> (5 - i)) & 1);
04000 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
04001 if (v->second_field)
04002 off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0];
04003 if (val) {
04004 pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
04005 first_block, s->dest[dst_idx] + off,
04006 (i & 4) ? s->uvlinesize : s->linesize,
04007 (i & 4) && (s->flags & CODEC_FLAG_GRAY),
04008 &block_tt);
04009 block_cbp |= pat << (i << 2);
04010 if (!v->ttmbf && ttmb < 8) ttmb = -1;
04011 first_block = 0;
04012 }
04013 }
04014 }
04015 if (s->mb_x == s->mb_width - 1)
04016 memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride);
04017 return 0;
04018 }
04019
04022 static void vc1_decode_b_mb(VC1Context *v)
04023 {
04024 MpegEncContext *s = &v->s;
04025 GetBitContext *gb = &s->gb;
04026 int i, j;
04027 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
04028 int cbp = 0;
04029 int mqdiff, mquant;
04030 int ttmb = v->ttfrm;
04031 int mb_has_coeffs = 0;
04032 int index, index1;
04033 int val, sign;
04034 int first_block = 1;
04035 int dst_idx, off;
04036 int skipped, direct;
04037 int dmv_x[2], dmv_y[2];
04038 int bmvtype = BMV_TYPE_BACKWARD;
04039
04040 mquant = v->pq;
04041 s->mb_intra = 0;
04042
04043 if (v->dmb_is_raw)
04044 direct = get_bits1(gb);
04045 else
04046 direct = v->direct_mb_plane[mb_pos];
04047 if (v->skip_is_raw)
04048 skipped = get_bits1(gb);
04049 else
04050 skipped = v->s.mbskip_table[mb_pos];
04051
04052 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
04053 for (i = 0; i < 6; i++) {
04054 v->mb_type[0][s->block_index[i]] = 0;
04055 s->dc_val[0][s->block_index[i]] = 0;
04056 }
04057 s->current_picture.f.qscale_table[mb_pos] = 0;
04058
04059 if (!direct) {
04060 if (!skipped) {
04061 GET_MVDATA(dmv_x[0], dmv_y[0]);
04062 dmv_x[1] = dmv_x[0];
04063 dmv_y[1] = dmv_y[0];
04064 }
04065 if (skipped || !s->mb_intra) {
04066 bmvtype = decode012(gb);
04067 switch (bmvtype) {
04068 case 0:
04069 bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
04070 break;
04071 case 1:
04072 bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
04073 break;
04074 case 2:
04075 bmvtype = BMV_TYPE_INTERPOLATED;
04076 dmv_x[0] = dmv_y[0] = 0;
04077 }
04078 }
04079 }
04080 for (i = 0; i < 6; i++)
04081 v->mb_type[0][s->block_index[i]] = s->mb_intra;
04082
04083 if (skipped) {
04084 if (direct)
04085 bmvtype = BMV_TYPE_INTERPOLATED;
04086 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
04087 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
04088 return;
04089 }
04090 if (direct) {
04091 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
04092 GET_MQUANT();
04093 s->mb_intra = 0;
04094 s->current_picture.f.qscale_table[mb_pos] = mquant;
04095 if (!v->ttmbf)
04096 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
04097 dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
04098 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
04099 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
04100 } else {
04101 if (!mb_has_coeffs && !s->mb_intra) {
04102
04103 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
04104 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
04105 return;
04106 }
04107 if (s->mb_intra && !mb_has_coeffs) {
04108 GET_MQUANT();
04109 s->current_picture.f.qscale_table[mb_pos] = mquant;
04110 s->ac_pred = get_bits1(gb);
04111 cbp = 0;
04112 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
04113 } else {
04114 if (bmvtype == BMV_TYPE_INTERPOLATED) {
04115 GET_MVDATA(dmv_x[0], dmv_y[0]);
04116 if (!mb_has_coeffs) {
04117
04118 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
04119 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
04120 return;
04121 }
04122 }
04123 vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
04124 if (!s->mb_intra) {
04125 vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
04126 }
04127 if (s->mb_intra)
04128 s->ac_pred = get_bits1(gb);
04129 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
04130 GET_MQUANT();
04131 s->current_picture.f.qscale_table[mb_pos] = mquant;
04132 if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
04133 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
04134 }
04135 }
04136 dst_idx = 0;
04137 for (i = 0; i < 6; i++) {
04138 s->dc_val[0][s->block_index[i]] = 0;
04139 dst_idx += i >> 2;
04140 val = ((cbp >> (5 - i)) & 1);
04141 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
04142 v->mb_type[0][s->block_index[i]] = s->mb_intra;
04143 if (s->mb_intra) {
04144
04145 v->a_avail = v->c_avail = 0;
04146 if (i == 2 || i == 3 || !s->first_slice_line)
04147 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
04148 if (i == 1 || i == 3 || s->mb_x)
04149 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
04150
04151 vc1_decode_intra_block(v, s->block[i], i, val, mquant,
04152 (i & 4) ? v->codingset2 : v->codingset);
04153 if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
04154 continue;
04155 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
04156 if (v->rangeredfrm)
04157 for (j = 0; j < 64; j++)
04158 s->block[i][j] <<= 1;
04159 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
04160 } else if (val) {
04161 vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
04162 first_block, s->dest[dst_idx] + off,
04163 (i & 4) ? s->uvlinesize : s->linesize,
04164 (i & 4) && (s->flags & CODEC_FLAG_GRAY), NULL);
04165 if (!v->ttmbf && ttmb < 8)
04166 ttmb = -1;
04167 first_block = 0;
04168 }
04169 }
04170 }
04171
04174 static void vc1_decode_b_mb_intfi(VC1Context *v)
04175 {
04176 MpegEncContext *s = &v->s;
04177 GetBitContext *gb = &s->gb;
04178 int i, j;
04179 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
04180 int cbp = 0;
04181 int mqdiff, mquant;
04182 int ttmb = v->ttfrm;
04183 int mb_has_coeffs = 0;
04184 int val;
04185 int first_block = 1;
04186 int dst_idx, off;
04187 int fwd;
04188 int dmv_x[2], dmv_y[2], pred_flag[2];
04189 int bmvtype = BMV_TYPE_BACKWARD;
04190 int idx_mbmode, interpmvp;
04191
04192 mquant = v->pq;
04193 s->mb_intra = 0;
04194
04195 idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
04196 if (idx_mbmode <= 1) {
04197 s->mb_intra = v->is_intra[s->mb_x] = 1;
04198 s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
04199 s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
04200 s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
04201 GET_MQUANT();
04202 s->current_picture.f.qscale_table[mb_pos] = mquant;
04203
04204 s->y_dc_scale = s->y_dc_scale_table[mquant];
04205 s->c_dc_scale = s->c_dc_scale_table[mquant];
04206 v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
04207 mb_has_coeffs = idx_mbmode & 1;
04208 if (mb_has_coeffs)
04209 cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
04210 dst_idx = 0;
04211 for (i = 0; i < 6; i++) {
04212 s->dc_val[0][s->block_index[i]] = 0;
04213 dst_idx += i >> 2;
04214 val = ((cbp >> (5 - i)) & 1);
04215 v->mb_type[0][s->block_index[i]] = s->mb_intra;
04216 v->a_avail = v->c_avail = 0;
04217 if (i == 2 || i == 3 || !s->first_slice_line)
04218 v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
04219 if (i == 1 || i == 3 || s->mb_x)
04220 v->c_avail = v->mb_type[0][s->block_index[i] - 1];
04221
04222 vc1_decode_intra_block(v, s->block[i], i, val, mquant,
04223 (i & 4) ? v->codingset2 : v->codingset);
04224 if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
04225 continue;
04226 v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
04227 if (v->rangeredfrm)
04228 for (j = 0; j < 64; j++)
04229 s->block[i][j] <<= 1;
04230 off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
04231 off += v->second_field ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0;
04232 s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize);
04233
04234 }
04235 } else {
04236 s->mb_intra = v->is_intra[s->mb_x] = 0;
04237 s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16;
04238 for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0;
04239 if (v->fmb_is_raw)
04240 fwd = v->forward_mb_plane[mb_pos] = get_bits1(gb);
04241 else
04242 fwd = v->forward_mb_plane[mb_pos];
04243 if (idx_mbmode <= 5) {
04244 dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0;
04245 pred_flag[0] = pred_flag[1] = 0;
04246 if (fwd)
04247 bmvtype = BMV_TYPE_FORWARD;
04248 else {
04249 bmvtype = decode012(gb);
04250 switch (bmvtype) {
04251 case 0:
04252 bmvtype = BMV_TYPE_BACKWARD;
04253 break;
04254 case 1:
04255 bmvtype = BMV_TYPE_DIRECT;
04256 break;
04257 case 2:
04258 bmvtype = BMV_TYPE_INTERPOLATED;
04259 interpmvp = get_bits1(gb);
04260 }
04261 }
04262 v->bmvtype = bmvtype;
04263 if (bmvtype != BMV_TYPE_DIRECT && idx_mbmode & 1) {
04264 get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD], &dmv_y[bmvtype == BMV_TYPE_BACKWARD], &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
04265 }
04266 if (bmvtype == BMV_TYPE_INTERPOLATED && interpmvp) {
04267 get_mvdata_interlaced(v, &dmv_x[1], &dmv_y[1], &pred_flag[1]);
04268 }
04269 if (bmvtype == BMV_TYPE_DIRECT) {
04270 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
04271 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
04272 }
04273 vc1_pred_b_mv_intfi(v, 0, dmv_x, dmv_y, 1, pred_flag);
04274 vc1_b_mc(v, dmv_x, dmv_y, (bmvtype == BMV_TYPE_DIRECT), bmvtype);
04275 mb_has_coeffs = !(idx_mbmode & 2);
04276 } else {
04277 if (fwd)
04278 bmvtype = BMV_TYPE_FORWARD;
04279 v->bmvtype = bmvtype;
04280 v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
04281 for (i = 0; i < 6; i++) {
04282 if (i < 4) {
04283 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
04284 dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
04285 val = ((v->fourmvbp >> (3 - i)) & 1);
04286 if (val) {
04287 get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD],
04288 &dmv_y[bmvtype == BMV_TYPE_BACKWARD],
04289 &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
04290 }
04291 vc1_pred_b_mv_intfi(v, i, dmv_x, dmv_y, 0, pred_flag);
04292 vc1_mc_4mv_luma(v, i, bmvtype == BMV_TYPE_BACKWARD);
04293 } else if (i == 4)
04294 vc1_mc_4mv_chroma(v, bmvtype == BMV_TYPE_BACKWARD);
04295 }
04296 mb_has_coeffs = idx_mbmode & 1;
04297 }
04298 if (mb_has_coeffs)
04299 cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
04300 if (cbp) {
04301 GET_MQUANT();
04302 }
04303 s->current_picture.f.qscale_table[mb_pos] = mquant;
04304 if (!v->ttmbf && cbp) {
04305 ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
04306 }
04307 dst_idx = 0;
04308 for (i = 0; i < 6; i++) {
04309 s->dc_val[0][s->block_index[i]] = 0;
04310 dst_idx += i >> 2;
04311 val = ((cbp >> (5 - i)) & 1);
04312 off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
04313 if (v->second_field)
04314 off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0];
04315 if (val) {
04316 vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
04317 first_block, s->dest[dst_idx] + off,
04318 (i & 4) ? s->uvlinesize : s->linesize,
04319 (i & 4) && (s->flags & CODEC_FLAG_GRAY), NULL);
04320 if (!v->ttmbf && ttmb < 8)
04321 ttmb = -1;
04322 first_block = 0;
04323 }
04324 }
04325 }
04326 }
04327
04330 static void vc1_decode_i_blocks(VC1Context *v)
04331 {
04332 int k, j;
04333 MpegEncContext *s = &v->s;
04334 int cbp, val;
04335 uint8_t *coded_val;
04336 int mb_pos;
04337
04338
04339 switch (v->y_ac_table_index) {
04340 case 0:
04341 v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
04342 break;
04343 case 1:
04344 v->codingset = CS_HIGH_MOT_INTRA;
04345 break;
04346 case 2:
04347 v->codingset = CS_MID_RATE_INTRA;
04348 break;
04349 }
04350
04351 switch (v->c_ac_table_index) {
04352 case 0:
04353 v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
04354 break;
04355 case 1:
04356 v->codingset2 = CS_HIGH_MOT_INTER;
04357 break;
04358 case 2:
04359 v->codingset2 = CS_MID_RATE_INTER;
04360 break;
04361 }
04362
04363
04364 s->y_dc_scale = s->y_dc_scale_table[v->pq];
04365 s->c_dc_scale = s->c_dc_scale_table[v->pq];
04366
04367
04368 s->mb_x = s->mb_y = 0;
04369 s->mb_intra = 1;
04370 s->first_slice_line = 1;
04371 for (s->mb_y = 0; s->mb_y < s->end_mb_y; s->mb_y++) {
04372 s->mb_x = 0;
04373 ff_init_block_index(s);
04374 for (; s->mb_x < v->end_mb_x; s->mb_x++) {
04375 uint8_t *dst[6];
04376 ff_update_block_index(s);
04377 dst[0] = s->dest[0];
04378 dst[1] = dst[0] + 8;
04379 dst[2] = s->dest[0] + s->linesize * 8;
04380 dst[3] = dst[2] + 8;
04381 dst[4] = s->dest[1];
04382 dst[5] = s->dest[2];
04383 s->dsp.clear_blocks(s->block[0]);
04384 mb_pos = s->mb_x + s->mb_y * s->mb_width;
04385 s->current_picture.f.mb_type[mb_pos] = MB_TYPE_INTRA;
04386 s->current_picture.f.qscale_table[mb_pos] = v->pq;
04387 s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
04388 s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
04389
04390
04391 cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
04392 v->s.ac_pred = get_bits1(&v->s.gb);
04393
04394 for (k = 0; k < 6; k++) {
04395 val = ((cbp >> (5 - k)) & 1);
04396
04397 if (k < 4) {
04398 int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
04399 val = val ^ pred;
04400 *coded_val = val;
04401 }
04402 cbp |= val << (5 - k);
04403
04404 vc1_decode_i_block(v, s->block[k], k, val, (k < 4) ? v->codingset : v->codingset2);
04405
04406 if (k > 3 && (s->flags & CODEC_FLAG_GRAY))
04407 continue;
04408 v->vc1dsp.vc1_inv_trans_8x8(s->block[k]);
04409 if (v->pq >= 9 && v->overlap) {
04410 if (v->rangeredfrm)
04411 for (j = 0; j < 64; j++)
04412 s->block[k][j] <<= 1;
04413 s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize);
04414 } else {
04415 if (v->rangeredfrm)
04416 for (j = 0; j < 64; j++)
04417 s->block[k][j] = (s->block[k][j] - 64) << 1;
04418 s->dsp.put_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize);
04419 }
04420 }
04421
04422 if (v->pq >= 9 && v->overlap) {
04423 if (s->mb_x) {
04424 v->vc1dsp.vc1_h_overlap(s->dest[0], s->linesize);
04425 v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
04426 if (!(s->flags & CODEC_FLAG_GRAY)) {
04427 v->vc1dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);
04428 v->vc1dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);
04429 }
04430 }
04431 v->vc1dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);
04432 v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
04433 if (!s->first_slice_line) {
04434 v->vc1dsp.vc1_v_overlap(s->dest[0], s->linesize);
04435 v->vc1dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);
04436 if (!(s->flags & CODEC_FLAG_GRAY)) {
04437 v->vc1dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);
04438 v->vc1dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);
04439 }
04440 }
04441 v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);
04442 v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);
04443 }
04444 if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
04445
04446 if (get_bits_count(&s->gb) > v->bits) {
04447 ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR);
04448 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
04449 get_bits_count(&s->gb), v->bits);
04450 return;
04451 }
04452 }
04453 if (!v->s.loop_filter)
04454 ff_draw_horiz_band(s, s->mb_y * 16, 16);
04455 else if (s->mb_y)
04456 ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
04457
04458 s->first_slice_line = 0;
04459 }
04460 if (v->s.loop_filter)
04461 ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
04462
04463
04464
04465 ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END);
04466 }
04467
04470 static void vc1_decode_i_blocks_adv(VC1Context *v)
04471 {
04472 int k;
04473 MpegEncContext *s = &v->s;
04474 int cbp, val;
04475 uint8_t *coded_val;
04476 int mb_pos;
04477 int mquant = v->pq;
04478 int mqdiff;
04479 GetBitContext *gb = &s->gb;
04480
04481
04482 switch (v->y_ac_table_index) {
04483 case 0:
04484 v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
04485 break;
04486 case 1:
04487 v->codingset = CS_HIGH_MOT_INTRA;
04488 break;
04489 case 2:
04490 v->codingset = CS_MID_RATE_INTRA;
04491 break;
04492 }
04493
04494 switch (v->c_ac_table_index) {
04495 case 0:
04496 v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
04497 break;
04498 case 1:
04499 v->codingset2 = CS_HIGH_MOT_INTER;
04500 break;
04501 case 2:
04502 v->codingset2 = CS_MID_RATE_INTER;
04503 break;
04504 }
04505
04506
04507 s->mb_x = s->mb_y = 0;
04508 s->mb_intra = 1;
04509 s->first_slice_line = 1;
04510 s->mb_y = s->start_mb_y;
04511 if (s->start_mb_y) {
04512 s->mb_x = 0;
04513 ff_init_block_index(s);
04514 memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0,
04515 (1 + s->b8_stride) * sizeof(*s->coded_block));
04516 }
04517 for (; s->mb_y < s->end_mb_y; s->mb_y++) {
04518 s->mb_x = 0;
04519 ff_init_block_index(s);
04520 for (;s->mb_x < s->mb_width; s->mb_x++) {
04521 DCTELEM (*block)[64] = v->block[v->cur_blk_idx];
04522 ff_update_block_index(s);
04523 s->dsp.clear_blocks(block[0]);
04524 mb_pos = s->mb_x + s->mb_y * s->mb_stride;
04525 s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA;
04526 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
04527 s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
04528
04529
04530 if (v->fieldtx_is_raw)
04531 v->fieldtx_plane[mb_pos] = get_bits1(&v->s.gb);
04532 cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
04533 if ( v->acpred_is_raw)
04534 v->s.ac_pred = get_bits1(&v->s.gb);
04535 else
04536 v->s.ac_pred = v->acpred_plane[mb_pos];
04537
04538 if (v->condover == CONDOVER_SELECT && v->overflg_is_raw)
04539 v->over_flags_plane[mb_pos] = get_bits1(&v->s.gb);
04540
04541 GET_MQUANT();
04542
04543 s->current_picture.f.qscale_table[mb_pos] = mquant;
04544
04545 s->y_dc_scale = s->y_dc_scale_table[mquant];
04546 s->c_dc_scale = s->c_dc_scale_table[mquant];
04547
04548 for (k = 0; k < 6; k++) {
04549 val = ((cbp >> (5 - k)) & 1);
04550
04551 if (k < 4) {
04552 int pred = vc1_coded_block_pred(&v->s, k, &coded_val);
04553 val = val ^ pred;
04554 *coded_val = val;
04555 }
04556 cbp |= val << (5 - k);
04557
04558 v->a_avail = !s->first_slice_line || (k == 2 || k == 3);
04559 v->c_avail = !!s->mb_x || (k == 1 || k == 3);
04560
04561 vc1_decode_i_block_adv(v, block[k], k, val,
04562 (k < 4) ? v->codingset : v->codingset2, mquant);
04563
04564 if (k > 3 && (s->flags & CODEC_FLAG_GRAY))
04565 continue;
04566 v->vc1dsp.vc1_inv_trans_8x8(block[k]);
04567 }
04568
04569 vc1_smooth_overlap_filter_iblk(v);
04570 vc1_put_signed_blocks_clamped(v);
04571 if (v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq);
04572
04573 if (get_bits_count(&s->gb) > v->bits) {
04574
04575 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
04576 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
04577 get_bits_count(&s->gb), v->bits);
04578 return;
04579 }
04580 }
04581 if (!v->s.loop_filter)
04582 ff_draw_horiz_band(s, s->mb_y * 16, 16);
04583 else if (s->mb_y)
04584 ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16);
04585 s->first_slice_line = 0;
04586 }
04587
04588
04589 s->mb_x = 0;
04590 ff_init_block_index(s);
04591 for (;s->mb_x < s->mb_width; s->mb_x++) {
04592 ff_update_block_index(s);
04593 vc1_put_signed_blocks_clamped(v);
04594 if (v->s.loop_filter)
04595 vc1_loop_filter_iblk_delayed(v, v->pq);
04596 }
04597 if (v->s.loop_filter)
04598 ff_draw_horiz_band(s, (s->end_mb_y-1)*16, 16);
04599 ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
04600 (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
04601 }
04602
04603 static void vc1_decode_p_blocks(VC1Context *v)
04604 {
04605 MpegEncContext *s = &v->s;
04606 int apply_loop_filter;
04607
04608
04609 switch (v->c_ac_table_index) {
04610 case 0:
04611 v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
04612 break;
04613 case 1:
04614 v->codingset = CS_HIGH_MOT_INTRA;
04615 break;
04616 case 2:
04617 v->codingset = CS_MID_RATE_INTRA;
04618 break;
04619 }
04620
04621 switch (v->c_ac_table_index) {
04622 case 0:
04623 v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
04624 break;
04625 case 1:
04626 v->codingset2 = CS_HIGH_MOT_INTER;
04627 break;
04628 case 2:
04629 v->codingset2 = CS_MID_RATE_INTER;
04630 break;
04631 }
04632
04633 apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
04634 s->first_slice_line = 1;
04635 memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride);
04636 for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
04637 s->mb_x = 0;
04638 ff_init_block_index(s);
04639 for (; s->mb_x < s->mb_width; s->mb_x++) {
04640 ff_update_block_index(s);
04641
04642 if (v->fcm == ILACE_FIELD)
04643 vc1_decode_p_mb_intfi(v);
04644 else if (v->fcm == ILACE_FRAME)
04645 vc1_decode_p_mb_intfr(v);
04646 else vc1_decode_p_mb(v);
04647 if (s->mb_y != s->start_mb_y && apply_loop_filter && v->fcm == PROGRESSIVE)
04648 vc1_apply_p_loop_filter(v);
04649 if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
04650
04651 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
04652 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
04653 get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);
04654 return;
04655 }
04656 }
04657 memmove(v->cbp_base, v->cbp, sizeof(v->cbp_base[0]) * s->mb_stride);
04658 memmove(v->ttblk_base, v->ttblk, sizeof(v->ttblk_base[0]) * s->mb_stride);
04659 memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride);
04660 memmove(v->luma_mv_base, v->luma_mv, sizeof(v->luma_mv_base[0]) * s->mb_stride);
04661 if (s->mb_y != s->start_mb_y) ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
04662 s->first_slice_line = 0;
04663 }
04664 if (apply_loop_filter && v->fcm == PROGRESSIVE) {
04665 s->mb_x = 0;
04666 ff_init_block_index(s);
04667 for (; s->mb_x < s->mb_width; s->mb_x++) {
04668 ff_update_block_index(s);
04669 vc1_apply_p_loop_filter(v);
04670 }
04671 }
04672 if (s->end_mb_y >= s->start_mb_y)
04673 ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
04674 ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
04675 (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
04676 }
04677
04678 static void vc1_decode_b_blocks(VC1Context *v)
04679 {
04680 MpegEncContext *s = &v->s;
04681
04682
04683 switch (v->c_ac_table_index) {
04684 case 0:
04685 v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;
04686 break;
04687 case 1:
04688 v->codingset = CS_HIGH_MOT_INTRA;
04689 break;
04690 case 2:
04691 v->codingset = CS_MID_RATE_INTRA;
04692 break;
04693 }
04694
04695 switch (v->c_ac_table_index) {
04696 case 0:
04697 v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;
04698 break;
04699 case 1:
04700 v->codingset2 = CS_HIGH_MOT_INTER;
04701 break;
04702 case 2:
04703 v->codingset2 = CS_MID_RATE_INTER;
04704 break;
04705 }
04706
04707 s->first_slice_line = 1;
04708 for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
04709 s->mb_x = 0;
04710 ff_init_block_index(s);
04711 for (; s->mb_x < s->mb_width; s->mb_x++) {
04712 ff_update_block_index(s);
04713
04714 if (v->fcm == ILACE_FIELD)
04715 vc1_decode_b_mb_intfi(v);
04716 else
04717 vc1_decode_b_mb(v);
04718 if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
04719
04720 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
04721 av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
04722 get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y);
04723 return;
04724 }
04725 if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
04726 }
04727 if (!v->s.loop_filter)
04728 ff_draw_horiz_band(s, s->mb_y * 16, 16);
04729 else if (s->mb_y)
04730 ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);
04731 s->first_slice_line = 0;
04732 }
04733 if (v->s.loop_filter)
04734 ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);
04735 ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1,
04736 (s->end_mb_y << v->field_mode) - 1, ER_MB_END);
04737 }
04738
04739 static void vc1_decode_skip_blocks(VC1Context *v)
04740 {
04741 MpegEncContext *s = &v->s;
04742
04743 ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, ER_MB_END);
04744 s->first_slice_line = 1;
04745 for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
04746 s->mb_x = 0;
04747 ff_init_block_index(s);
04748 ff_update_block_index(s);
04749 if (s->last_picture.f.data[0]) {
04750 memcpy(s->dest[0], s->last_picture.f.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16);
04751 memcpy(s->dest[1], s->last_picture.f.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
04752 memcpy(s->dest[2], s->last_picture.f.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8);
04753 }
04754 ff_draw_horiz_band(s, s->mb_y * 16, 16);
04755 s->first_slice_line = 0;
04756 }
04757 s->pict_type = AV_PICTURE_TYPE_P;
04758 }
04759
04760 void ff_vc1_decode_blocks(VC1Context *v)
04761 {
04762
04763 v->s.esc3_level_length = 0;
04764 if (v->x8_type) {
04765 ff_intrax8_decode_picture(&v->x8, 2*v->pq + v->halfpq, v->pq * !v->pquantizer);
04766 } else {
04767 v->cur_blk_idx = 0;
04768 v->left_blk_idx = -1;
04769 v->topleft_blk_idx = 1;
04770 v->top_blk_idx = 2;
04771 switch (v->s.pict_type) {
04772 case AV_PICTURE_TYPE_I:
04773 if (v->profile == PROFILE_ADVANCED)
04774 vc1_decode_i_blocks_adv(v);
04775 else
04776 vc1_decode_i_blocks(v);
04777 break;
04778 case AV_PICTURE_TYPE_P:
04779 if (v->p_frame_skipped)
04780 vc1_decode_skip_blocks(v);
04781 else
04782 vc1_decode_p_blocks(v);
04783 break;
04784 case AV_PICTURE_TYPE_B:
04785 if (v->bi_type) {
04786 if (v->profile == PROFILE_ADVANCED)
04787 vc1_decode_i_blocks_adv(v);
04788 else
04789 vc1_decode_i_blocks(v);
04790 } else
04791 vc1_decode_b_blocks(v);
04792 break;
04793 }
04794 }
04795 }
04796
04797 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
04798
04799 typedef struct {
04811 int coefs[2][7];
04812
04813 int effect_type, effect_flag;
04814 int effect_pcount1, effect_pcount2;
04815 int effect_params1[15], effect_params2[10];
04816 } SpriteData;
04817
04818 static inline int get_fp_val(GetBitContext* gb)
04819 {
04820 return (get_bits_long(gb, 30) - (1 << 29)) << 1;
04821 }
04822
04823 static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7])
04824 {
04825 c[1] = c[3] = 0;
04826
04827 switch (get_bits(gb, 2)) {
04828 case 0:
04829 c[0] = 1 << 16;
04830 c[2] = get_fp_val(gb);
04831 c[4] = 1 << 16;
04832 break;
04833 case 1:
04834 c[0] = c[4] = get_fp_val(gb);
04835 c[2] = get_fp_val(gb);
04836 break;
04837 case 2:
04838 c[0] = get_fp_val(gb);
04839 c[2] = get_fp_val(gb);
04840 c[4] = get_fp_val(gb);
04841 break;
04842 case 3:
04843 c[0] = get_fp_val(gb);
04844 c[1] = get_fp_val(gb);
04845 c[2] = get_fp_val(gb);
04846 c[3] = get_fp_val(gb);
04847 c[4] = get_fp_val(gb);
04848 break;
04849 }
04850 c[5] = get_fp_val(gb);
04851 if (get_bits1(gb))
04852 c[6] = get_fp_val(gb);
04853 else
04854 c[6] = 1 << 16;
04855 }
04856
04857 static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd)
04858 {
04859 AVCodecContext *avctx = v->s.avctx;
04860 int sprite, i;
04861
04862 for (sprite = 0; sprite <= v->two_sprites; sprite++) {
04863 vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
04864 if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
04865 av_log_ask_for_sample(avctx, "Rotation coefficients are not zero");
04866 av_log(avctx, AV_LOG_DEBUG, sprite ? "S2:" : "S1:");
04867 for (i = 0; i < 7; i++)
04868 av_log(avctx, AV_LOG_DEBUG, " %d.%.3d",
04869 sd->coefs[sprite][i] / (1<<16),
04870 (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
04871 av_log(avctx, AV_LOG_DEBUG, "\n");
04872 }
04873
04874 skip_bits(gb, 2);
04875 if (sd->effect_type = get_bits_long(gb, 30)) {
04876 switch (sd->effect_pcount1 = get_bits(gb, 4)) {
04877 case 7:
04878 vc1_sprite_parse_transform(gb, sd->effect_params1);
04879 break;
04880 case 14:
04881 vc1_sprite_parse_transform(gb, sd->effect_params1);
04882 vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
04883 break;
04884 default:
04885 for (i = 0; i < sd->effect_pcount1; i++)
04886 sd->effect_params1[i] = get_fp_val(gb);
04887 }
04888 if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
04889
04890 av_log(avctx, AV_LOG_DEBUG, "Effect: %d; params: ", sd->effect_type);
04891 for (i = 0; i < sd->effect_pcount1; i++)
04892 av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
04893 sd->effect_params1[i] / (1 << 16),
04894 (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
04895 av_log(avctx, AV_LOG_DEBUG, "\n");
04896 }
04897
04898 sd->effect_pcount2 = get_bits(gb, 16);
04899 if (sd->effect_pcount2 > 10) {
04900 av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n");
04901 return;
04902 } else if (sd->effect_pcount2) {
04903 i = -1;
04904 av_log(avctx, AV_LOG_DEBUG, "Effect params 2: ");
04905 while (++i < sd->effect_pcount2) {
04906 sd->effect_params2[i] = get_fp_val(gb);
04907 av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
04908 sd->effect_params2[i] / (1 << 16),
04909 (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
04910 }
04911 av_log(avctx, AV_LOG_DEBUG, "\n");
04912 }
04913 }
04914 if (sd->effect_flag = get_bits1(gb))
04915 av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n");
04916
04917 if (get_bits_count(gb) >= gb->size_in_bits +
04918 (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE ? 64 : 0))
04919 av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n");
04920 if (get_bits_count(gb) < gb->size_in_bits - 8)
04921 av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n");
04922 }
04923
04924 static void vc1_draw_sprites(VC1Context *v, SpriteData* sd)
04925 {
04926 int i, plane, row, sprite;
04927 int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
04928 uint8_t* src_h[2][2];
04929 int xoff[2], xadv[2], yoff[2], yadv[2], alpha;
04930 int ysub[2];
04931 MpegEncContext *s = &v->s;
04932
04933 for (i = 0; i < 2; i++) {
04934 xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16);
04935 xadv[i] = sd->coefs[i][0];
04936 if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i])
04937 xadv[i] = av_clip(xadv[i], 0, ((v->sprite_width<<16) - xoff[i] - 1) / v->output_width);
04938
04939 yoff[i] = av_clip(sd->coefs[i][5], 0, v->sprite_height-1 << 16);
04940 yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height << 16) - yoff[i]) / v->output_height);
04941 }
04942 alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1);
04943
04944 for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++) {
04945 int width = v->output_width>>!!plane;
04946
04947 for (row = 0; row < v->output_height>>!!plane; row++) {
04948 uint8_t *dst = v->sprite_output_frame.data[plane] +
04949 v->sprite_output_frame.linesize[plane] * row;
04950
04951 for (sprite = 0; sprite <= v->two_sprites; sprite++) {
04952 uint8_t *iplane = s->current_picture.f.data[plane];
04953 int iline = s->current_picture.f.linesize[plane];
04954 int ycoord = yoff[sprite] + yadv[sprite] * row;
04955 int yline = ycoord >> 16;
04956 int next_line;
04957 ysub[sprite] = ycoord & 0xFFFF;
04958 if (sprite) {
04959 iplane = s->last_picture.f.data[plane];
04960 iline = s->last_picture.f.linesize[plane];
04961 }
04962 next_line = FFMIN(yline + 1, (v->sprite_height >> !!plane) - 1) * iline;
04963 if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
04964 src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
04965 if (ysub[sprite])
04966 src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
04967 } else {
04968 if (sr_cache[sprite][0] != yline) {
04969 if (sr_cache[sprite][1] == yline) {
04970 FFSWAP(uint8_t*, v->sr_rows[sprite][0], v->sr_rows[sprite][1]);
04971 FFSWAP(int, sr_cache[sprite][0], sr_cache[sprite][1]);
04972 } else {
04973 v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
04974 sr_cache[sprite][0] = yline;
04975 }
04976 }
04977 if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
04978 v->vc1dsp.sprite_h(v->sr_rows[sprite][1],
04979 iplane + next_line, xoff[sprite],
04980 xadv[sprite], width);
04981 sr_cache[sprite][1] = yline + 1;
04982 }
04983 src_h[sprite][0] = v->sr_rows[sprite][0];
04984 src_h[sprite][1] = v->sr_rows[sprite][1];
04985 }
04986 }
04987
04988 if (!v->two_sprites) {
04989 if (ysub[0]) {
04990 v->vc1dsp.sprite_v_single(dst, src_h[0][0], src_h[0][1], ysub[0], width);
04991 } else {
04992 memcpy(dst, src_h[0][0], width);
04993 }
04994 } else {
04995 if (ysub[0] && ysub[1]) {
04996 v->vc1dsp.sprite_v_double_twoscale(dst, src_h[0][0], src_h[0][1], ysub[0],
04997 src_h[1][0], src_h[1][1], ysub[1], alpha, width);
04998 } else if (ysub[0]) {
04999 v->vc1dsp.sprite_v_double_onescale(dst, src_h[0][0], src_h[0][1], ysub[0],
05000 src_h[1][0], alpha, width);
05001 } else if (ysub[1]) {
05002 v->vc1dsp.sprite_v_double_onescale(dst, src_h[1][0], src_h[1][1], ysub[1],
05003 src_h[0][0], (1<<16)-1-alpha, width);
05004 } else {
05005 v->vc1dsp.sprite_v_double_noscale(dst, src_h[0][0], src_h[1][0], alpha, width);
05006 }
05007 }
05008 }
05009
05010 if (!plane) {
05011 for (i = 0; i < 2; i++) {
05012 xoff[i] >>= 1;
05013 yoff[i] >>= 1;
05014 }
05015 }
05016
05017 }
05018 }
05019
05020
05021 static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb)
05022 {
05023 MpegEncContext *s = &v->s;
05024 AVCodecContext *avctx = s->avctx;
05025 SpriteData sd;
05026
05027 vc1_parse_sprites(v, gb, &sd);
05028
05029 if (!s->current_picture.f.data[0]) {
05030 av_log(avctx, AV_LOG_ERROR, "Got no sprites\n");
05031 return -1;
05032 }
05033
05034 if (v->two_sprites && (!s->last_picture_ptr || !s->last_picture.f.data[0])) {
05035 av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n");
05036 v->two_sprites = 0;
05037 }
05038
05039 if (v->sprite_output_frame.data[0])
05040 avctx->release_buffer(avctx, &v->sprite_output_frame);
05041
05042 v->sprite_output_frame.buffer_hints = FF_BUFFER_HINTS_VALID;
05043 v->sprite_output_frame.reference = 0;
05044 if (ff_get_buffer(avctx, &v->sprite_output_frame) < 0) {
05045 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
05046 return -1;
05047 }
05048
05049 vc1_draw_sprites(v, &sd);
05050
05051 return 0;
05052 }
05053
05054 static void vc1_sprite_flush(AVCodecContext *avctx)
05055 {
05056 VC1Context *v = avctx->priv_data;
05057 MpegEncContext *s = &v->s;
05058 AVFrame *f = &s->current_picture.f;
05059 int plane, i;
05060
05061
05062
05063
05064
05065 if (f->data[0])
05066 for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++)
05067 for (i = 0; i < v->sprite_height>>!!plane; i++)
05068 memset(f->data[plane] + i * f->linesize[plane],
05069 plane ? 128 : 0, f->linesize[plane]);
05070 }
05071
05072 #endif
05073
05074 av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v)
05075 {
05076 MpegEncContext *s = &v->s;
05077 int i;
05078
05079
05080 v->mv_type_mb_plane = av_malloc (s->mb_stride * s->mb_height);
05081 v->direct_mb_plane = av_malloc (s->mb_stride * s->mb_height);
05082 v->forward_mb_plane = av_malloc (s->mb_stride * s->mb_height);
05083 v->fieldtx_plane = av_mallocz(s->mb_stride * s->mb_height);
05084 v->acpred_plane = av_malloc (s->mb_stride * s->mb_height);
05085 v->over_flags_plane = av_malloc (s->mb_stride * s->mb_height);
05086
05087 v->n_allocated_blks = s->mb_width + 2;
05088 v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks);
05089 v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
05090 v->cbp = v->cbp_base + s->mb_stride;
05091 v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
05092 v->ttblk = v->ttblk_base + s->mb_stride;
05093 v->is_intra_base = av_mallocz(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
05094 v->is_intra = v->is_intra_base + s->mb_stride;
05095 v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
05096 v->luma_mv = v->luma_mv_base + s->mb_stride;
05097
05098
05099 v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
05100 v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
05101 v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1;
05102 v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1);
05103
05104
05105 v->blk_mv_type_base = av_mallocz( s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
05106 v->blk_mv_type = v->blk_mv_type_base + s->b8_stride + 1;
05107 v->mv_f_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
05108 v->mv_f[0] = v->mv_f_base + s->b8_stride + 1;
05109 v->mv_f[1] = v->mv_f[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
05110 v->mv_f_last_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
05111 v->mv_f_last[0] = v->mv_f_last_base + s->b8_stride + 1;
05112 v->mv_f_last[1] = v->mv_f_last[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
05113 v->mv_f_next_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
05114 v->mv_f_next[0] = v->mv_f_next_base + s->b8_stride + 1;
05115 v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2);
05116
05117
05118 if (v->profile == PROFILE_ADVANCED) {
05119
05120
05121
05122
05123 }
05124
05125 ff_intrax8_common_init(&v->x8,s);
05126
05127 if (s->avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || s->avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
05128 for (i = 0; i < 4; i++)
05129 if (!(v->sr_rows[i >> 1][i & 1] = av_malloc(v->output_width))) return -1;
05130 }
05131
05132 if (!v->mv_type_mb_plane || !v->direct_mb_plane || !v->acpred_plane || !v->over_flags_plane ||
05133 !v->block || !v->cbp_base || !v->ttblk_base || !v->is_intra_base || !v->luma_mv_base ||
05134 !v->mb_type_base)
05135 return -1;
05136
05137 return 0;
05138 }
05139
05140 av_cold void ff_vc1_init_transposed_scantables(VC1Context *v)
05141 {
05142 int i;
05143 for (i = 0; i < 64; i++) {
05144 #define transpose(x) ((x >> 3) | ((x & 7) << 3))
05145 v->zz_8x8[0][i] = transpose(ff_wmv1_scantable[0][i]);
05146 v->zz_8x8[1][i] = transpose(ff_wmv1_scantable[1][i]);
05147 v->zz_8x8[2][i] = transpose(ff_wmv1_scantable[2][i]);
05148 v->zz_8x8[3][i] = transpose(ff_wmv1_scantable[3][i]);
05149 v->zzi_8x8[i] = transpose(ff_vc1_adv_interlaced_8x8_zz[i]);
05150 }
05151 v->left_blk_sh = 0;
05152 v->top_blk_sh = 3;
05153 }
05154
05159 static av_cold int vc1_decode_init(AVCodecContext *avctx)
05160 {
05161 VC1Context *v = avctx->priv_data;
05162 MpegEncContext *s = &v->s;
05163 GetBitContext gb;
05164
05165
05166 v->output_width = avctx->width;
05167 v->output_height = avctx->height;
05168
05169 if (!avctx->extradata_size || !avctx->extradata)
05170 return -1;
05171 if (!(avctx->flags & CODEC_FLAG_GRAY))
05172 avctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts);
05173 else
05174 avctx->pix_fmt = AV_PIX_FMT_GRAY8;
05175 avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
05176 v->s.avctx = avctx;
05177 avctx->flags |= CODEC_FLAG_EMU_EDGE;
05178 v->s.flags |= CODEC_FLAG_EMU_EDGE;
05179
05180 if (avctx->idct_algo == FF_IDCT_AUTO) {
05181 avctx->idct_algo = FF_IDCT_WMV2;
05182 }
05183
05184 if (ff_vc1_init_common(v) < 0)
05185 return -1;
05186
05187 if (ff_msmpeg4_decode_init(avctx) < 0)
05188 return -1;
05189 if (ff_vc1_decode_init_alloc_tables(v) < 0)
05190 return -1;
05191
05192
05193
05194 ff_vc1_decode_end(avctx);
05195 ff_vc1dsp_init(&v->vc1dsp);
05196
05197 if (avctx->codec_id == AV_CODEC_ID_WMV3 || avctx->codec_id == AV_CODEC_ID_WMV3IMAGE) {
05198 int count = 0;
05199
05200
05201
05202
05203
05204
05205 init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);
05206
05207 if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0)
05208 return -1;
05209
05210 count = avctx->extradata_size*8 - get_bits_count(&gb);
05211 if (count > 0) {
05212 av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
05213 count, get_bits(&gb, count));
05214 } else if (count < 0) {
05215 av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
05216 }
05217 } else {
05218 const uint8_t *start = avctx->extradata;
05219 uint8_t *end = avctx->extradata + avctx->extradata_size;
05220 const uint8_t *next;
05221 int size, buf2_size;
05222 uint8_t *buf2 = NULL;
05223 int seq_initialized = 0, ep_initialized = 0;
05224
05225 if (avctx->extradata_size < 16) {
05226 av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
05227 return -1;
05228 }
05229
05230 buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
05231 start = find_next_marker(start, end);
05232 next = start;
05233 for (; next < end; start = next) {
05234 next = find_next_marker(start + 4, end);
05235 size = next - start - 4;
05236 if (size <= 0)
05237 continue;
05238 buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
05239 init_get_bits(&gb, buf2, buf2_size * 8);
05240 switch (AV_RB32(start)) {
05241 case VC1_CODE_SEQHDR:
05242 if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0) {
05243 av_free(buf2);
05244 return -1;
05245 }
05246 seq_initialized = 1;
05247 break;
05248 case VC1_CODE_ENTRYPOINT:
05249 if (ff_vc1_decode_entry_point(avctx, v, &gb) < 0) {
05250 av_free(buf2);
05251 return -1;
05252 }
05253 ep_initialized = 1;
05254 break;
05255 }
05256 }
05257 av_free(buf2);
05258 if (!seq_initialized || !ep_initialized) {
05259 av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
05260 return -1;
05261 }
05262 v->res_sprite = (avctx->codec_tag == MKTAG('W','V','P','2'));
05263 }
05264
05265 avctx->profile = v->profile;
05266 if (v->profile == PROFILE_ADVANCED)
05267 avctx->level = v->level;
05268
05269 avctx->has_b_frames = !!avctx->max_b_frames;
05270
05271 s->mb_width = (avctx->coded_width + 15) >> 4;
05272 s->mb_height = (avctx->coded_height + 15) >> 4;
05273
05274 if (v->profile == PROFILE_ADVANCED || v->res_fasttx) {
05275 ff_vc1_init_transposed_scantables(v);
05276 } else {
05277 memcpy(v->zz_8x8, ff_wmv1_scantable, 4*64);
05278 v->left_blk_sh = 3;
05279 v->top_blk_sh = 0;
05280 }
05281
05282 if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
05283 v->sprite_width = avctx->coded_width;
05284 v->sprite_height = avctx->coded_height;
05285
05286 avctx->coded_width = avctx->width = v->output_width;
05287 avctx->coded_height = avctx->height = v->output_height;
05288
05289
05290 if (v->sprite_width > 1 << 14 ||
05291 v->sprite_height > 1 << 14 ||
05292 v->output_width > 1 << 14 ||
05293 v->output_height > 1 << 14) return -1;
05294 }
05295 return 0;
05296 }
05297
05301 av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
05302 {
05303 VC1Context *v = avctx->priv_data;
05304 int i;
05305
05306 if ((avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE)
05307 && v->sprite_output_frame.data[0])
05308 avctx->release_buffer(avctx, &v->sprite_output_frame);
05309 for (i = 0; i < 4; i++)
05310 av_freep(&v->sr_rows[i >> 1][i & 1]);
05311 av_freep(&v->hrd_rate);
05312 av_freep(&v->hrd_buffer);
05313 ff_MPV_common_end(&v->s);
05314 av_freep(&v->mv_type_mb_plane);
05315 av_freep(&v->direct_mb_plane);
05316 av_freep(&v->forward_mb_plane);
05317 av_freep(&v->fieldtx_plane);
05318 av_freep(&v->acpred_plane);
05319 av_freep(&v->over_flags_plane);
05320 av_freep(&v->mb_type_base);
05321 av_freep(&v->blk_mv_type_base);
05322 av_freep(&v->mv_f_base);
05323 av_freep(&v->mv_f_last_base);
05324 av_freep(&v->mv_f_next_base);
05325 av_freep(&v->block);
05326 av_freep(&v->cbp_base);
05327 av_freep(&v->ttblk_base);
05328 av_freep(&v->is_intra_base);
05329 av_freep(&v->luma_mv_base);
05330 ff_intrax8_common_end(&v->x8);
05331 return 0;
05332 }
05333
05334
05338 static int vc1_decode_frame(AVCodecContext *avctx, void *data,
05339 int *got_frame, AVPacket *avpkt)
05340 {
05341 const uint8_t *buf = avpkt->data;
05342 int buf_size = avpkt->size, n_slices = 0, i;
05343 VC1Context *v = avctx->priv_data;
05344 MpegEncContext *s = &v->s;
05345 AVFrame *pict = data;
05346 uint8_t *buf2 = NULL;
05347 const uint8_t *buf_start = buf, *buf_start_second_field = NULL;
05348 int mb_height, n_slices1=-1;
05349 struct {
05350 uint8_t *buf;
05351 GetBitContext gb;
05352 int mby_start;
05353 } *slices = NULL, *tmp;
05354
05355 v->second_field = 0;
05356
05357 if(s->flags & CODEC_FLAG_LOW_DELAY)
05358 s->low_delay = 1;
05359
05360
05361 if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
05362
05363 if (s->low_delay == 0 && s->next_picture_ptr) {
05364 *pict = s->next_picture_ptr->f;
05365 s->next_picture_ptr = NULL;
05366
05367 *got_frame = 1;
05368 }
05369
05370 return buf_size;
05371 }
05372
05373 if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) {
05374 if (v->profile < PROFILE_ADVANCED)
05375 avctx->pix_fmt = AV_PIX_FMT_VDPAU_WMV3;
05376 else
05377 avctx->pix_fmt = AV_PIX_FMT_VDPAU_VC1;
05378 }
05379
05380
05381 if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
05382 int buf_size2 = 0;
05383 buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
05384
05385 if (IS_MARKER(AV_RB32(buf))) {
05386 const uint8_t *start, *end, *next;
05387 int size;
05388
05389 next = buf;
05390 for (start = buf, end = buf + buf_size; next < end; start = next) {
05391 next = find_next_marker(start + 4, end);
05392 size = next - start - 4;
05393 if (size <= 0) continue;
05394 switch (AV_RB32(start)) {
05395 case VC1_CODE_FRAME:
05396 if (avctx->hwaccel ||
05397 s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
05398 buf_start = start;
05399 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
05400 break;
05401 case VC1_CODE_FIELD: {
05402 int buf_size3;
05403 if (avctx->hwaccel ||
05404 s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
05405 buf_start_second_field = start;
05406 tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
05407 if (!tmp)
05408 goto err;
05409 slices = tmp;
05410 slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
05411 if (!slices[n_slices].buf)
05412 goto err;
05413 buf_size3 = vc1_unescape_buffer(start + 4, size,
05414 slices[n_slices].buf);
05415 init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
05416 buf_size3 << 3);
05417
05418
05419 slices[n_slices].mby_start = s->mb_height >> 1;
05420 n_slices1 = n_slices - 1;
05421 n_slices++;
05422 break;
05423 }
05424 case VC1_CODE_ENTRYPOINT:
05425 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
05426 init_get_bits(&s->gb, buf2, buf_size2 * 8);
05427 ff_vc1_decode_entry_point(avctx, v, &s->gb);
05428 break;
05429 case VC1_CODE_SLICE: {
05430 int buf_size3;
05431 tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
05432 if (!tmp)
05433 goto err;
05434 slices = tmp;
05435 slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
05436 if (!slices[n_slices].buf)
05437 goto err;
05438 buf_size3 = vc1_unescape_buffer(start + 4, size,
05439 slices[n_slices].buf);
05440 init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
05441 buf_size3 << 3);
05442 slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9);
05443 n_slices++;
05444 break;
05445 }
05446 }
05447 }
05448 } else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) {
05449 const uint8_t *divider;
05450 int buf_size3;
05451
05452 divider = find_next_marker(buf, buf + buf_size);
05453 if ((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD) {
05454 av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
05455 goto err;
05456 } else {
05457 if (avctx->hwaccel ||
05458 s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
05459 buf_start_second_field = divider;
05460 tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
05461 if (!tmp)
05462 goto err;
05463 slices = tmp;
05464 slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
05465 if (!slices[n_slices].buf)
05466 goto err;
05467 buf_size3 = vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
05468 init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
05469 buf_size3 << 3);
05470 slices[n_slices].mby_start = s->mb_height >> 1;
05471 n_slices1 = n_slices - 1;
05472 n_slices++;
05473 }
05474 buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2);
05475 } else {
05476 buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2);
05477 }
05478 init_get_bits(&s->gb, buf2, buf_size2*8);
05479 } else
05480 init_get_bits(&s->gb, buf, buf_size*8);
05481
05482 if (v->res_sprite) {
05483 v->new_sprite = !get_bits1(&s->gb);
05484 v->two_sprites = get_bits1(&s->gb);
05485
05486
05487
05488
05489 if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
05490 if (v->new_sprite) {
05491
05492 avctx->width = avctx->coded_width = v->sprite_width;
05493 avctx->height = avctx->coded_height = v->sprite_height;
05494 } else {
05495 goto image;
05496 }
05497 }
05498 }
05499
05500 if (s->context_initialized &&
05501 (s->width != avctx->coded_width ||
05502 s->height != avctx->coded_height)) {
05503 ff_vc1_decode_end(avctx);
05504 }
05505
05506 if (!s->context_initialized) {
05507 if (ff_msmpeg4_decode_init(avctx) < 0 || ff_vc1_decode_init_alloc_tables(v) < 0)
05508 goto err;
05509
05510 s->low_delay = !avctx->has_b_frames || v->res_sprite;
05511
05512 if (v->profile == PROFILE_ADVANCED) {
05513 if(avctx->coded_width<=1 || avctx->coded_height<=1)
05514 goto err;
05515 s->h_edge_pos = avctx->coded_width;
05516 s->v_edge_pos = avctx->coded_height;
05517 }
05518 }
05519
05520
05521
05522 if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) {
05523 int i = ff_find_unused_picture(s, 0);
05524 if (i < 0)
05525 goto err;
05526 s->current_picture_ptr = &s->picture[i];
05527 }
05528
05529
05530 v->pic_header_flag = 0;
05531 v->first_pic_header_flag = 1;
05532 if (v->profile < PROFILE_ADVANCED) {
05533 if (ff_vc1_parse_frame_header(v, &s->gb) < 0) {
05534 goto err;
05535 }
05536 } else {
05537 if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
05538 goto err;
05539 }
05540 }
05541 v->first_pic_header_flag = 0;
05542
05543 if (avctx->debug & FF_DEBUG_PICT_INFO)
05544 av_log(v->s.avctx, AV_LOG_DEBUG, "pict_type: %c\n", av_get_picture_type_char(s->pict_type));
05545
05546 if ((avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE)
05547 && s->pict_type != AV_PICTURE_TYPE_I) {
05548 av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n");
05549 goto err;
05550 }
05551
05552 if ((s->mb_height >> v->field_mode) == 0) {
05553 av_log(v->s.avctx, AV_LOG_ERROR, "image too short\n");
05554 goto err;
05555 }
05556
05557
05558 s->current_picture_ptr->f.repeat_pict = 0;
05559
05560
05561 if (v->rff) {
05562
05563 s->current_picture_ptr->f.repeat_pict = 1;
05564 } else if (v->rptfrm) {
05565
05566 s->current_picture_ptr->f.repeat_pict = v->rptfrm * 2;
05567 }
05568
05569
05570 s->current_picture.f.pict_type = s->pict_type;
05571 s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
05572
05573
05574 if (s->last_picture_ptr == NULL && (s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) {
05575 goto err;
05576 }
05577 if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
05578 (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
05579 avctx->skip_frame >= AVDISCARD_ALL) {
05580 goto end;
05581 }
05582
05583 if (s->next_p_frame_damaged) {
05584 if (s->pict_type == AV_PICTURE_TYPE_B)
05585 goto end;
05586 else
05587 s->next_p_frame_damaged = 0;
05588 }
05589
05590 if (ff_MPV_frame_start(s, avctx) < 0) {
05591 goto err;
05592 }
05593
05594 v->s.current_picture_ptr->f.interlaced_frame = (v->fcm != PROGRESSIVE);
05595 v->s.current_picture_ptr->f.top_field_first = v->tff;
05596
05597 s->me.qpel_put = s->dsp.put_qpel_pixels_tab;
05598 s->me.qpel_avg = s->dsp.avg_qpel_pixels_tab;
05599
05600 if ((CONFIG_VC1_VDPAU_DECODER)
05601 &&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
05602 ff_vdpau_vc1_decode_picture(s, buf_start, (buf + buf_size) - buf_start);
05603 else if (avctx->hwaccel) {
05604 if (v->field_mode && buf_start_second_field) {
05605
05606 s->picture_structure = PICT_BOTTOM_FIELD - v->tff;
05607 if (avctx->hwaccel->start_frame(avctx, buf_start, buf_start_second_field - buf_start) < 0)
05608 goto err;
05609 if (avctx->hwaccel->decode_slice(avctx, buf_start, buf_start_second_field - buf_start) < 0)
05610 goto err;
05611 if (avctx->hwaccel->end_frame(avctx) < 0)
05612 goto err;
05613
05614
05615 s->gb = slices[n_slices1 + 1].gb;
05616 s->picture_structure = PICT_TOP_FIELD + v->tff;
05617 v->second_field = 1;
05618 v->pic_header_flag = 0;
05619 if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
05620 av_log(avctx, AV_LOG_ERROR, "parsing header for second field failed");
05621 goto err;
05622 }
05623 v->s.current_picture_ptr->f.pict_type = v->s.pict_type;
05624
05625 if (avctx->hwaccel->start_frame(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
05626 goto err;
05627 if (avctx->hwaccel->decode_slice(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field) < 0)
05628 goto err;
05629 if (avctx->hwaccel->end_frame(avctx) < 0)
05630 goto err;
05631 } else {
05632 s->picture_structure = PICT_FRAME;
05633 if (avctx->hwaccel->start_frame(avctx, buf_start, (buf + buf_size) - buf_start) < 0)
05634 goto err;
05635 if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0)
05636 goto err;
05637 if (avctx->hwaccel->end_frame(avctx) < 0)
05638 goto err;
05639 }
05640 } else {
05641 if (v->fcm == ILACE_FRAME && s->pict_type == AV_PICTURE_TYPE_B)
05642 goto err;
05643
05644 ff_er_frame_start(s);
05645
05646 v->bits = buf_size * 8;
05647 v->end_mb_x = s->mb_width;
05648 if (v->field_mode) {
05649 uint8_t *tmp[2];
05650 s->current_picture.f.linesize[0] <<= 1;
05651 s->current_picture.f.linesize[1] <<= 1;
05652 s->current_picture.f.linesize[2] <<= 1;
05653 s->linesize <<= 1;
05654 s->uvlinesize <<= 1;
05655 tmp[0] = v->mv_f_last[0];
05656 tmp[1] = v->mv_f_last[1];
05657 v->mv_f_last[0] = v->mv_f_next[0];
05658 v->mv_f_last[1] = v->mv_f_next[1];
05659 v->mv_f_next[0] = v->mv_f[0];
05660 v->mv_f_next[1] = v->mv_f[1];
05661 v->mv_f[0] = tmp[0];
05662 v->mv_f[1] = tmp[1];
05663 }
05664 mb_height = s->mb_height >> v->field_mode;
05665 for (i = 0; i <= n_slices; i++) {
05666 if (i > 0 && slices[i - 1].mby_start >= mb_height) {
05667 if (v->field_mode <= 0) {
05668 av_log(v->s.avctx, AV_LOG_ERROR, "Slice %d starts beyond "
05669 "picture boundary (%d >= %d)\n", i,
05670 slices[i - 1].mby_start, mb_height);
05671 continue;
05672 }
05673 v->second_field = 1;
05674 v->blocks_off = s->mb_width * s->mb_height << 1;
05675 v->mb_off = s->mb_stride * s->mb_height >> 1;
05676 } else {
05677 v->second_field = 0;
05678 v->blocks_off = 0;
05679 v->mb_off = 0;
05680 }
05681 if (i) {
05682 v->pic_header_flag = 0;
05683 if (v->field_mode && i == n_slices1 + 2) {
05684 if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
05685 av_log(v->s.avctx, AV_LOG_ERROR, "Field header damaged\n");
05686 continue;
05687 }
05688 } else if (get_bits1(&s->gb)) {
05689 v->pic_header_flag = 1;
05690 if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
05691 av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
05692 continue;
05693 }
05694 }
05695 }
05696 s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start % mb_height);
05697 if (!v->field_mode || v->second_field)
05698 s->end_mb_y = (i == n_slices ) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
05699 else {
05700 if (i >= n_slices) {
05701 av_log(v->s.avctx, AV_LOG_ERROR, "first field slice count too large\n");
05702 continue;
05703 }
05704 s->end_mb_y = (i <= n_slices1 + 1) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
05705 }
05706 if (s->end_mb_y <= s->start_mb_y) {
05707 av_log(v->s.avctx, AV_LOG_ERROR, "end mb y %d %d invalid\n", s->end_mb_y, s->start_mb_y);
05708 continue;
05709 }
05710 ff_vc1_decode_blocks(v);
05711 if (i != n_slices)
05712 s->gb = slices[i].gb;
05713 }
05714 if (v->field_mode) {
05715 v->second_field = 0;
05716 if (s->pict_type == AV_PICTURE_TYPE_B) {
05717 memcpy(v->mv_f_base, v->mv_f_next_base,
05718 2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2));
05719 }
05720 s->current_picture.f.linesize[0] >>= 1;
05721 s->current_picture.f.linesize[1] >>= 1;
05722 s->current_picture.f.linesize[2] >>= 1;
05723 s->linesize >>= 1;
05724 s->uvlinesize >>= 1;
05725 }
05726 av_dlog(s->avctx, "Consumed %i/%i bits\n",
05727 get_bits_count(&s->gb), s->gb.size_in_bits);
05728
05729
05730 if(s->error_occurred && s->pict_type == AV_PICTURE_TYPE_B)
05731 goto err;
05732 if(!v->field_mode)
05733 ff_er_frame_end(s);
05734 }
05735
05736 ff_MPV_frame_end(s);
05737
05738 if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
05739 image:
05740 avctx->width = avctx->coded_width = v->output_width;
05741 avctx->height = avctx->coded_height = v->output_height;
05742 if (avctx->skip_frame >= AVDISCARD_NONREF)
05743 goto end;
05744 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
05745 if (vc1_decode_sprites(v, &s->gb))
05746 goto err;
05747 #endif
05748 *pict = v->sprite_output_frame;
05749 *got_frame = 1;
05750 } else {
05751 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
05752 *pict = s->current_picture_ptr->f;
05753 } else if (s->last_picture_ptr != NULL) {
05754 *pict = s->last_picture_ptr->f;
05755 }
05756 if (s->last_picture_ptr || s->low_delay) {
05757 *got_frame = 1;
05758 ff_print_debug_info(s, pict);
05759 }
05760 }
05761
05762 end:
05763 av_free(buf2);
05764 for (i = 0; i < n_slices; i++)
05765 av_free(slices[i].buf);
05766 av_free(slices);
05767 return buf_size;
05768
05769 err:
05770 av_free(buf2);
05771 for (i = 0; i < n_slices; i++)
05772 av_free(slices[i].buf);
05773 av_free(slices);
05774 return -1;
05775 }
05776
05777
05778 static const AVProfile profiles[] = {
05779 { FF_PROFILE_VC1_SIMPLE, "Simple" },
05780 { FF_PROFILE_VC1_MAIN, "Main" },
05781 { FF_PROFILE_VC1_COMPLEX, "Complex" },
05782 { FF_PROFILE_VC1_ADVANCED, "Advanced" },
05783 { FF_PROFILE_UNKNOWN },
05784 };
05785
05786 AVCodec ff_vc1_decoder = {
05787 .name = "vc1",
05788 .type = AVMEDIA_TYPE_VIDEO,
05789 .id = AV_CODEC_ID_VC1,
05790 .priv_data_size = sizeof(VC1Context),
05791 .init = vc1_decode_init,
05792 .close = ff_vc1_decode_end,
05793 .decode = vc1_decode_frame,
05794 .flush = ff_mpeg_flush,
05795 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
05796 .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
05797 .pix_fmts = ff_hwaccel_pixfmt_list_420,
05798 .profiles = NULL_IF_CONFIG_SMALL(profiles)
05799 };
05800
05801 #if CONFIG_WMV3_DECODER
05802 AVCodec ff_wmv3_decoder = {
05803 .name = "wmv3",
05804 .type = AVMEDIA_TYPE_VIDEO,
05805 .id = AV_CODEC_ID_WMV3,
05806 .priv_data_size = sizeof(VC1Context),
05807 .init = vc1_decode_init,
05808 .close = ff_vc1_decode_end,
05809 .decode = vc1_decode_frame,
05810 .flush = ff_mpeg_flush,
05811 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY,
05812 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
05813 .pix_fmts = ff_hwaccel_pixfmt_list_420,
05814 .profiles = NULL_IF_CONFIG_SMALL(profiles)
05815 };
05816 #endif
05817
05818 #if CONFIG_WMV3_VDPAU_DECODER
05819 AVCodec ff_wmv3_vdpau_decoder = {
05820 .name = "wmv3_vdpau",
05821 .type = AVMEDIA_TYPE_VIDEO,
05822 .id = AV_CODEC_ID_WMV3,
05823 .priv_data_size = sizeof(VC1Context),
05824 .init = vc1_decode_init,
05825 .close = ff_vc1_decode_end,
05826 .decode = vc1_decode_frame,
05827 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
05828 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 VDPAU"),
05829 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_VDPAU_WMV3, AV_PIX_FMT_NONE },
05830 .profiles = NULL_IF_CONFIG_SMALL(profiles)
05831 };
05832 #endif
05833
05834 #if CONFIG_VC1_VDPAU_DECODER
05835 AVCodec ff_vc1_vdpau_decoder = {
05836 .name = "vc1_vdpau",
05837 .type = AVMEDIA_TYPE_VIDEO,
05838 .id = AV_CODEC_ID_VC1,
05839 .priv_data_size = sizeof(VC1Context),
05840 .init = vc1_decode_init,
05841 .close = ff_vc1_decode_end,
05842 .decode = vc1_decode_frame,
05843 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
05844 .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 VDPAU"),
05845 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_VDPAU_VC1, AV_PIX_FMT_NONE },
05846 .profiles = NULL_IF_CONFIG_SMALL(profiles)
05847 };
05848 #endif
05849
05850 #if CONFIG_WMV3IMAGE_DECODER
05851 AVCodec ff_wmv3image_decoder = {
05852 .name = "wmv3image",
05853 .type = AVMEDIA_TYPE_VIDEO,
05854 .id = AV_CODEC_ID_WMV3IMAGE,
05855 .priv_data_size = sizeof(VC1Context),
05856 .init = vc1_decode_init,
05857 .close = ff_vc1_decode_end,
05858 .decode = vc1_decode_frame,
05859 .capabilities = CODEC_CAP_DR1,
05860 .flush = vc1_sprite_flush,
05861 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image"),
05862 .pix_fmts = ff_pixfmt_list_420
05863 };
05864 #endif
05865
05866 #if CONFIG_VC1IMAGE_DECODER
05867 AVCodec ff_vc1image_decoder = {
05868 .name = "vc1image",
05869 .type = AVMEDIA_TYPE_VIDEO,
05870 .id = AV_CODEC_ID_VC1IMAGE,
05871 .priv_data_size = sizeof(VC1Context),
05872 .init = vc1_decode_init,
05873 .close = ff_vc1_decode_end,
05874 .decode = vc1_decode_frame,
05875 .capabilities = CODEC_CAP_DR1,
05876 .flush = vc1_sprite_flush,
05877 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image v2"),
05878 .pix_fmts = ff_pixfmt_list_420
05879 };
05880 #endif