Mercurial > libavcodec.hg
comparison h263dec.c @ 1285:6e039762d5cb libavcodec
motion vector vissualization for mpeg1/2
mpeg1/2 cleanup/bugfix
error resilience bugfix
author | michaelni |
---|---|
date | Tue, 27 May 2003 12:31:03 +0000 |
parents | 483db104bb7b |
children | e0e5483c32c5 |
comparison
equal
deleted
inserted
replaced
1284:119c814aa9de | 1285:6e039762d5cb |
---|---|
375 pc->state= state; | 375 pc->state= state; |
376 | 376 |
377 return END_NOT_FOUND; | 377 return END_NOT_FOUND; |
378 } | 378 } |
379 | 379 |
380 /** | |
381 * draws an line from (ex, ey) -> (sx, sy). | |
382 * @param w width of the image | |
383 * @param h height of the image | |
384 * @param stride stride/linesize of the image | |
385 * @param color color of the arrow | |
386 */ | |
387 static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ | |
388 int t, x, y, f; | |
389 | |
390 ex= clip(ex, 0, w-1); | |
391 ey= clip(ey, 0, h-1); | |
392 | |
393 buf[sy*stride + sx]+= color; | |
394 | |
395 if(ABS(ex - sx) > ABS(ey - sy)){ | |
396 if(sx > ex){ | |
397 t=sx; sx=ex; ex=t; | |
398 t=sy; sy=ey; ey=t; | |
399 } | |
400 buf+= sx + sy*stride; | |
401 ex-= sx; | |
402 f= ((ey-sy)<<16)/ex; | |
403 for(x= 0; x <= ex; x++){ | |
404 y= ((x*f) + (1<<15))>>16; | |
405 buf[y*stride + x]+= color; | |
406 } | |
407 }else{ | |
408 if(sy > ey){ | |
409 t=sx; sx=ex; ex=t; | |
410 t=sy; sy=ey; ey=t; | |
411 } | |
412 buf+= sx + sy*stride; | |
413 ey-= sy; | |
414 if(ey) f= ((ex-sx)<<16)/ey; | |
415 else f= 0; | |
416 for(y= 0; y <= ey; y++){ | |
417 x= ((y*f) + (1<<15))>>16; | |
418 buf[y*stride + x]+= color; | |
419 } | |
420 } | |
421 } | |
422 | |
423 /** | |
424 * draws an arrow from (ex, ey) -> (sx, sy). | |
425 * @param w width of the image | |
426 * @param h height of the image | |
427 * @param stride stride/linesize of the image | |
428 * @param color color of the arrow | |
429 */ | |
430 static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ | |
431 int dx= ex - sx; | |
432 int dy= ey - sy; | |
433 | |
434 if(dx*dx + dy*dy > 3*3){ | |
435 int rx= dx + dy; | |
436 int ry= -dx + dy; | |
437 int length= ff_sqrt((rx*rx + ry*ry)<<8); | |
438 | |
439 //FIXME subpixel accuracy | |
440 rx= ROUNDED_DIV(rx*3<<4, length); | |
441 ry= ROUNDED_DIV(ry*3<<4, length); | |
442 | |
443 draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color); | |
444 draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color); | |
445 } | |
446 draw_line(buf, sx, sy, ex, ey, w, h, stride, color); | |
447 } | |
448 | |
449 int ff_h263_decode_frame(AVCodecContext *avctx, | 380 int ff_h263_decode_frame(AVCodecContext *avctx, |
450 void *data, int *data_size, | 381 void *data, int *data_size, |
451 uint8_t *buf, int buf_size) | 382 uint8_t *buf, int buf_size) |
452 { | 383 { |
453 MpegEncContext *s = avctx->priv_data; | 384 MpegEncContext *s = avctx->priv_data; |
738 | 669 |
739 ff_er_frame_end(s); | 670 ff_er_frame_end(s); |
740 | 671 |
741 MPV_frame_end(s); | 672 MPV_frame_end(s); |
742 | 673 |
743 if((avctx->debug&FF_DEBUG_VIS_MV) && s->last_picture_ptr){ | 674 assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); |
744 const int shift= 1 + s->quarter_sample; | 675 assert(s->current_picture.pict_type == s->pict_type); |
745 int mb_y; | |
746 uint8_t *ptr= s->last_picture.data[0]; | |
747 s->low_delay=0; //needed to see the vectors without trashing the buffers | |
748 | |
749 for(mb_y=0; mb_y<s->mb_height; mb_y++){ | |
750 int mb_x; | |
751 for(mb_x=0; mb_x<s->mb_width; mb_x++){ | |
752 const int mb_index= mb_x + mb_y*s->mb_stride; | |
753 if(IS_8X8(s->current_picture.mb_type[mb_index])){ | |
754 int i; | |
755 for(i=0; i<4; i++){ | |
756 int sx= mb_x*16 + 4 + 8*(i&1); | |
757 int sy= mb_y*16 + 4 + 8*(i>>1); | |
758 int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2); | |
759 int mx= (s->motion_val[xy][0]>>shift) + sx; | |
760 int my= (s->motion_val[xy][1]>>shift) + sy; | |
761 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); | |
762 } | |
763 }else{ | |
764 int sx= mb_x*16 + 8; | |
765 int sy= mb_y*16 + 8; | |
766 int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); | |
767 int mx= (s->motion_val[xy][0]>>shift) + sx; | |
768 int my= (s->motion_val[xy][1]>>shift) + sy; | |
769 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); | |
770 } | |
771 s->mbskip_table[mb_index]=0; | |
772 } | |
773 } | |
774 } | |
775 | |
776 if(s->pict_type==B_TYPE || s->low_delay){ | 676 if(s->pict_type==B_TYPE || s->low_delay){ |
777 *pict= *(AVFrame*)&s->current_picture; | 677 *pict= *(AVFrame*)&s->current_picture; |
778 ff_print_debug_info(s, s->current_picture_ptr); | 678 ff_print_debug_info(s, s->current_picture_ptr); |
779 } else { | 679 } else { |
780 *pict= *(AVFrame*)&s->last_picture; | 680 *pict= *(AVFrame*)&s->last_picture; |