59 |
#include "image.h" |
#include "image.h" |
60 |
#include "colorspace.h" |
#include "colorspace.h" |
61 |
#include "interpolate8x8.h" |
#include "interpolate8x8.h" |
62 |
#include "../divx4.h" |
#include "reduced.h" |
63 |
#include "../utils/mem_align.h" |
#include "../utils/mem_align.h" |
64 |
|
|
65 |
#include "font.h" // XXX: remove later |
#include "font.h" // XXX: remove later |
475 |
} |
} |
476 |
|
|
477 |
|
|
478 |
|
/* |
479 |
|
chroma optimize filter, invented by mf |
480 |
|
a chroma pixel is average from the surrounding pixels, when the |
481 |
|
correpsonding luma pixels are pure black or white. |
482 |
|
*/ |
483 |
|
|
484 |
|
void |
485 |
|
image_chroma_optimize(IMAGE * img, int width, int height, int edged_width) |
486 |
|
{ |
487 |
|
int x,y; |
488 |
|
int pixels = 0; |
489 |
|
|
490 |
|
for (y = 1; y < height/2 - 1; y++) |
491 |
|
for (x = 1; x < width/2 - 1; x++) |
492 |
|
{ |
493 |
|
#define IS_PURE(a) ((a)<=16||(a)>=235) |
494 |
|
#define IMG_Y(Y,X) img->y[(Y)*edged_width + (X)] |
495 |
|
#define IMG_U(Y,X) img->u[(Y)*edged_width/2 + (X)] |
496 |
|
#define IMG_V(Y,X) img->v[(Y)*edged_width/2 + (X)] |
497 |
|
|
498 |
|
if (IS_PURE(IMG_Y(y*2 ,x*2 )) && |
499 |
|
IS_PURE(IMG_Y(y*2 ,x*2+1)) && |
500 |
|
IS_PURE(IMG_Y(y*2+1,x*2 )) && |
501 |
|
IS_PURE(IMG_Y(y*2+1,x*2+1))) |
502 |
|
{ |
503 |
|
IMG_U(y,x) = (IMG_U(y,x-1) + IMG_U(y-1, x) + IMG_U(y, x+1) + IMG_U(y+1, x)) / 4; |
504 |
|
IMG_V(y,x) = (IMG_V(y,x-1) + IMG_V(y-1, x) + IMG_V(y, x+1) + IMG_V(y+1, x)) / 4; |
505 |
|
pixels++; |
506 |
|
} |
507 |
|
|
508 |
|
#undef IS_PURE |
509 |
|
#undef IMG_Y |
510 |
|
#undef IMG_U |
511 |
|
#undef IMG_V |
512 |
|
} |
513 |
|
|
514 |
|
DPRINTF(DPRINTF_DEBUG,"chroma_optimized_pixels = %i/%i", pixels, width*height/4); |
515 |
|
} |
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
/* |
/* |
522 |
perform safe packed colorspace conversion, by splitting |
perform safe packed colorspace conversion, by splitting |
563 |
uint32_t width, |
uint32_t width, |
564 |
int height, |
int height, |
565 |
uint32_t edged_width, |
uint32_t edged_width, |
566 |
uint8_t * src, |
uint8_t * src[4], |
567 |
int src_stride, |
int src_stride[4], |
568 |
int csp, |
int csp, |
569 |
int interlacing) |
int interlacing) |
570 |
{ |
{ |
573 |
const int height2 = height/2; |
const int height2 = height/2; |
574 |
//const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height; |
//const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height; |
575 |
|
|
|
|
|
|
// int src_stride = width; |
|
|
|
|
|
// --- xvid 2.1 compatiblity patch --- |
|
|
// --- remove when xvid_dec_frame->stride equals real stride |
|
|
/* |
|
|
if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_YVYU || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_UYVY) |
|
|
{ |
|
|
src_stride *= 2; |
|
|
} |
|
|
else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB24) |
|
|
{ |
|
|
src_stride *= 3; |
|
|
} |
|
|
else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB32 || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_ABGR || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGBA) |
|
|
{ |
|
|
src_stride *= 4; |
|
|
} |
|
|
*/ |
|
|
// ^--- xvid 2.1 compatiblity fix ---^ |
|
|
|
|
576 |
switch (csp & ~XVID_CSP_VFLIP) { |
switch (csp & ~XVID_CSP_VFLIP) { |
577 |
case XVID_CSP_RGB555: |
case XVID_CSP_RGB555: |
578 |
safe_packed_conv( |
safe_packed_conv( |
579 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
580 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
581 |
interlacing?rgb555i_to_yv12 :rgb555_to_yv12, |
interlacing?rgb555i_to_yv12 :rgb555_to_yv12, |
582 |
interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2); |
interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2); |
584 |
|
|
585 |
case XVID_CSP_RGB565: |
case XVID_CSP_RGB565: |
586 |
safe_packed_conv( |
safe_packed_conv( |
587 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
588 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
589 |
interlacing?rgb565i_to_yv12 :rgb565_to_yv12, |
interlacing?rgb565i_to_yv12 :rgb565_to_yv12, |
590 |
interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2); |
interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2); |
591 |
break; |
break; |
592 |
|
|
593 |
|
|
594 |
case XVID_CSP_RGB24: |
case XVID_CSP_BGR: |
595 |
safe_packed_conv( |
safe_packed_conv( |
596 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
597 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
598 |
interlacing?bgri_to_yv12 :bgr_to_yv12, |
interlacing?bgri_to_yv12 :bgr_to_yv12, |
599 |
interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3); |
interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3); |
600 |
break; |
break; |
601 |
|
|
602 |
case XVID_CSP_RGB32: |
case XVID_CSP_BGRA: |
603 |
safe_packed_conv( |
safe_packed_conv( |
604 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
605 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
606 |
interlacing?bgrai_to_yv12 :bgra_to_yv12, |
interlacing?bgrai_to_yv12 :bgra_to_yv12, |
607 |
interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4); |
interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4); |
609 |
|
|
610 |
case XVID_CSP_ABGR : |
case XVID_CSP_ABGR : |
611 |
safe_packed_conv( |
safe_packed_conv( |
612 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
613 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
614 |
interlacing?abgri_to_yv12 :abgr_to_yv12, |
interlacing?abgri_to_yv12 :abgr_to_yv12, |
615 |
interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4); |
interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4); |
617 |
|
|
618 |
case XVID_CSP_RGBA : |
case XVID_CSP_RGBA : |
619 |
safe_packed_conv( |
safe_packed_conv( |
620 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
621 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
622 |
interlacing?rgbai_to_yv12 :rgba_to_yv12, |
interlacing?rgbai_to_yv12 :rgba_to_yv12, |
623 |
interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4); |
interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4); |
625 |
|
|
626 |
case XVID_CSP_YUY2: |
case XVID_CSP_YUY2: |
627 |
safe_packed_conv( |
safe_packed_conv( |
628 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
629 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
630 |
interlacing?yuyvi_to_yv12 :yuyv_to_yv12, |
interlacing?yuyvi_to_yv12 :yuyv_to_yv12, |
631 |
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); |
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); |
633 |
|
|
634 |
case XVID_CSP_YVYU: /* u/v swapped */ |
case XVID_CSP_YVYU: /* u/v swapped */ |
635 |
safe_packed_conv( |
safe_packed_conv( |
636 |
src, src_stride, image->y, image->v, image->y, |
src[0], src_stride[0], image->y, image->v, image->y, |
637 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
638 |
interlacing?yuyvi_to_yv12 :yuyv_to_yv12, |
interlacing?yuyvi_to_yv12 :yuyv_to_yv12, |
639 |
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); |
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); |
641 |
|
|
642 |
case XVID_CSP_UYVY: |
case XVID_CSP_UYVY: |
643 |
safe_packed_conv( |
safe_packed_conv( |
644 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
645 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
646 |
interlacing?uyvyi_to_yv12 :uyvy_to_yv12, |
interlacing?uyvyi_to_yv12 :uyvy_to_yv12, |
647 |
interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2); |
interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2); |
649 |
|
|
650 |
case XVID_CSP_I420: |
case XVID_CSP_I420: |
651 |
yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2, |
yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2, |
652 |
src, src + width*height, src + width*height + width2*height2, |
src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2, |
653 |
width, width2, width, height, (csp & XVID_CSP_VFLIP)); |
src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP)); |
654 |
break |
break |
655 |
; |
; |
656 |
case XVID_CSP_YV12: /* u/v swapped */ |
case XVID_CSP_YV12: /* u/v swapped */ |
657 |
yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2, |
yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2, |
658 |
src, src + width*height, src + width*height + width2*height2, |
src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2, |
659 |
width, width2, width, height, (csp & XVID_CSP_VFLIP)); |
src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP)); |
660 |
break; |
break; |
661 |
|
|
662 |
case XVID_CSP_USER: |
case XVID_CSP_USER: |
663 |
{ |
/*XXX: support for different u & v strides */ |
|
DEC_PICTURE * pic = (DEC_PICTURE*)src; |
|
664 |
yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2, |
yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2, |
665 |
pic->y, pic->u, pic->v, pic->stride_y, pic->stride_y, |
src[0], src[1], src[2], src_stride[0], src_stride[1], |
666 |
width, height, (csp & XVID_CSP_VFLIP)); |
width, height, (csp & XVID_CSP_VFLIP)); |
|
} |
|
667 |
break; |
break; |
668 |
|
|
669 |
case XVID_CSP_NULL: |
case XVID_CSP_NULL: |
729 |
uint32_t width, |
uint32_t width, |
730 |
int height, |
int height, |
731 |
uint32_t edged_width, |
uint32_t edged_width, |
732 |
uint8_t * dst, |
uint8_t * dst[4], |
733 |
uint32_t dst_stride, |
uint32_t dst_stride[4], |
734 |
int csp, |
int csp, |
735 |
int interlacing) |
int interlacing) |
736 |
{ |
{ |
737 |
const int edged_width2 = edged_width/2; |
const int edged_width2 = edged_width/2; |
|
int width2 = width/2; |
|
738 |
int height2 = height/2; |
int height2 = height/2; |
739 |
|
|
740 |
/* |
/* |
743 |
image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm"); |
image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm"); |
744 |
*/ |
*/ |
745 |
|
|
|
|
|
|
// --- xvid 2.1 compatiblity patch --- |
|
|
// --- remove when xvid_dec_frame->stride equals real stride |
|
|
/* |
|
|
if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_YVYU || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_UYVY) |
|
|
{ |
|
|
dst_stride *= 2; |
|
|
} |
|
|
else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB24) |
|
|
{ |
|
|
dst_stride *= 3; |
|
|
} |
|
|
else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB32 || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_ABGR || |
|
|
(csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGBA) |
|
|
{ |
|
|
dst_stride *= 4; |
|
|
} |
|
|
*/ |
|
|
// ^--- xvid 2.1 compatiblity fix ---^ |
|
|
|
|
|
|
|
746 |
switch (csp & ~XVID_CSP_VFLIP) { |
switch (csp & ~XVID_CSP_VFLIP) { |
747 |
case XVID_CSP_RGB555: |
case XVID_CSP_RGB555: |
748 |
safe_packed_conv( |
safe_packed_conv( |
749 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
750 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
751 |
interlacing?yv12_to_rgb555i :yv12_to_rgb555, |
interlacing?yv12_to_rgb555i :yv12_to_rgb555, |
752 |
interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2); |
interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2); |
754 |
|
|
755 |
case XVID_CSP_RGB565: |
case XVID_CSP_RGB565: |
756 |
safe_packed_conv( |
safe_packed_conv( |
757 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
758 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
759 |
interlacing?yv12_to_rgb565i :yv12_to_rgb565, |
interlacing?yv12_to_rgb565i :yv12_to_rgb565, |
760 |
interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2); |
interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2); |
761 |
return 0; |
return 0; |
762 |
|
|
763 |
case XVID_CSP_RGB24: |
case XVID_CSP_BGR: |
764 |
safe_packed_conv( |
safe_packed_conv( |
765 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
766 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
767 |
interlacing?yv12_to_bgri :yv12_to_bgr, |
interlacing?yv12_to_bgri :yv12_to_bgr, |
768 |
interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3); |
interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3); |
769 |
return 0; |
return 0; |
770 |
|
|
771 |
case XVID_CSP_RGB32: |
case XVID_CSP_BGRA: |
772 |
safe_packed_conv( |
safe_packed_conv( |
773 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
774 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
775 |
interlacing?yv12_to_bgrai :yv12_to_bgra, |
interlacing?yv12_to_bgrai :yv12_to_bgra, |
776 |
interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4); |
interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4); |
778 |
|
|
779 |
case XVID_CSP_ABGR: |
case XVID_CSP_ABGR: |
780 |
safe_packed_conv( |
safe_packed_conv( |
781 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
782 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
783 |
interlacing?yv12_to_abgri :yv12_to_abgr, |
interlacing?yv12_to_abgri :yv12_to_abgr, |
784 |
interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4); |
interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4); |
786 |
|
|
787 |
case XVID_CSP_RGBA: |
case XVID_CSP_RGBA: |
788 |
safe_packed_conv( |
safe_packed_conv( |
789 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
790 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
791 |
interlacing?yv12_to_rgbai :yv12_to_rgba, |
interlacing?yv12_to_rgbai :yv12_to_rgba, |
792 |
interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4); |
interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4); |
794 |
|
|
795 |
case XVID_CSP_YUY2: |
case XVID_CSP_YUY2: |
796 |
safe_packed_conv( |
safe_packed_conv( |
797 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
798 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
799 |
interlacing?yv12_to_yuyvi :yv12_to_yuyv, |
interlacing?yv12_to_yuyvi :yv12_to_yuyv, |
800 |
interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); |
interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); |
802 |
|
|
803 |
case XVID_CSP_YVYU: // u,v swapped |
case XVID_CSP_YVYU: // u,v swapped |
804 |
safe_packed_conv( |
safe_packed_conv( |
805 |
dst, dst_stride, image->y, image->v, image->u, |
dst[0], dst_stride[0], image->y, image->v, image->u, |
806 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
807 |
interlacing?yv12_to_yuyvi :yv12_to_yuyv, |
interlacing?yv12_to_yuyvi :yv12_to_yuyv, |
808 |
interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); |
interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); |
810 |
|
|
811 |
case XVID_CSP_UYVY: |
case XVID_CSP_UYVY: |
812 |
safe_packed_conv( |
safe_packed_conv( |
813 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
814 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
815 |
interlacing?yv12_to_uyvyi :yv12_to_uyvy, |
interlacing?yv12_to_uyvyi :yv12_to_uyvy, |
816 |
interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2); |
interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2); |
817 |
return 0; |
return 0; |
818 |
|
|
819 |
case XVID_CSP_I420: |
case XVID_CSP_I420: |
820 |
yv12_to_yv12(dst, dst + width*height, dst + width*height + width2*height2, |
yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2, |
821 |
width, width2, |
dst_stride[0], dst_stride[0]/2, |
822 |
image->y, image->u, image->v, edged_width, edged_width2, |
image->y, image->u, image->v, edged_width, edged_width2, |
823 |
width, height, (csp & XVID_CSP_VFLIP)); |
width, height, (csp & XVID_CSP_VFLIP)); |
824 |
return 0; |
return 0; |
825 |
|
|
826 |
case XVID_CSP_YV12: // u,v swapped |
case XVID_CSP_YV12: // u,v swapped |
827 |
yv12_to_yv12(dst, dst + width*height, dst + width*height + width2*height2, |
yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2, |
828 |
width, width2, |
dst_stride[0], dst_stride[0]/2, |
829 |
image->y, image->v, image->u, edged_width, edged_width2, |
image->y, image->v, image->u, edged_width, edged_width2, |
830 |
width, height, (csp & XVID_CSP_VFLIP)); |
width, height, (csp & XVID_CSP_VFLIP)); |
831 |
return 0; |
return 0; |
832 |
|
|
833 |
case XVID_CSP_USER: |
case XVID_CSP_USER : // u,v swapped |
834 |
{ |
yv12_to_yv12(dst[0], dst[1], dst[2], |
835 |
DEC_PICTURE * pic = (DEC_PICTURE*)dst; |
dst_stride[0], dst_stride[1], /* v: dst_stride[2] */ |
836 |
pic->y = image->y; |
image->y, image->v, image->u, edged_width, edged_width2, |
837 |
pic->u = image->u; |
width, height, (csp & XVID_CSP_VFLIP)); |
838 |
pic->v = image->v; |
return 0; |
839 |
pic->stride_y = edged_width; |
|
840 |
pic->stride_uv = edged_width / 2; |
case XVID_CSP_INTERNAL : |
841 |
} |
dst[0] = image->y; |
842 |
|
dst[1] = image->u; |
843 |
|
dst[2] = image->v; |
844 |
|
dst_stride[0] = edged_width; |
845 |
|
dst_stride[1] = edged_width/2; |
846 |
|
dst_stride[2] = edged_width/2; |
847 |
return 0; |
return 0; |
848 |
|
|
849 |
case XVID_CSP_NULL: |
case XVID_CSP_NULL: |
850 |
case XVID_CSP_EXTERN: |
case XVID_CSP_SLICE: |
851 |
return 0; |
return 0; |
852 |
|
|
853 |
} |
} |
887 |
return psnr_y; |
return psnr_y; |
888 |
} |
} |
889 |
|
|
890 |
|
|
891 |
|
float sse_to_PSNR(long sse, int pixels) |
892 |
|
{ |
893 |
|
if (sse==0) |
894 |
|
return 99.99F; |
895 |
|
|
896 |
|
return 48.131F - 10*(float)log10((float)sse/(float)(pixels)); // log10(255*255)=4.8131 |
897 |
|
|
898 |
|
} |
899 |
|
|
900 |
|
long plane_sse(uint8_t * orig, |
901 |
|
uint8_t * recon, |
902 |
|
uint16_t stride, |
903 |
|
uint16_t width, |
904 |
|
uint16_t height) |
905 |
|
{ |
906 |
|
int diff, x, y; |
907 |
|
long sse=0; |
908 |
|
|
909 |
|
for (y = 0; y < height; y++) { |
910 |
|
for (x = 0; x < width; x++) { |
911 |
|
diff = *(orig + x) - *(recon + x); |
912 |
|
sse += diff * diff; |
913 |
|
} |
914 |
|
orig += stride; |
915 |
|
recon += stride; |
916 |
|
} |
917 |
|
return sse; |
918 |
|
} |
919 |
|
|
920 |
/* |
/* |
921 |
|
|
922 |
#include <stdio.h> |
#include <stdio.h> |
1013 |
} |
} |
1014 |
|
|
1015 |
|
|
|
#define ABS(X) (((X)>0)?(X):-(X)) |
|
1016 |
float |
float |
1017 |
image_mad(const IMAGE * img1, |
image_mad(const IMAGE * img1, |
1018 |
const IMAGE * img2, |
const IMAGE * img2, |
1043 |
} |
} |
1044 |
|
|
1045 |
void |
void |
1046 |
output_slice(IMAGE * cur, int std, int width, XVID_DEC_PICTURE* out_frm, int mbx, int mby,int mbl) { |
output_slice(IMAGE * cur, int std, int width, xvid_image_t* out_frm, int mbx, int mby,int mbl) { |
1047 |
uint8_t *dY,*dU,*dV,*sY,*sU,*sV; |
uint8_t *dY,*dU,*dV,*sY,*sU,*sV; |
1048 |
int std2 = std >> 1; |
int std2 = std >> 1; |
1049 |
int w = mbl << 4, w2,i; |
int w = mbl << 4, w2,i; |
1052 |
w = width; |
w = width; |
1053 |
w2 = w >> 1; |
w2 = w >> 1; |
1054 |
|
|
1055 |
dY = (uint8_t*)out_frm->y + (mby << 4) * out_frm->stride_y + (mbx << 4); |
dY = (uint8_t*)out_frm->plane[0] + (mby << 4) * out_frm->stride[0] + (mbx << 4); |
1056 |
dU = (uint8_t*)out_frm->u + (mby << 3) * out_frm->stride_u + (mbx << 3); |
dU = (uint8_t*)out_frm->plane[1] + (mby << 3) * out_frm->stride[1] + (mbx << 3); |
1057 |
dV = (uint8_t*)out_frm->v + (mby << 3) * out_frm->stride_v + (mbx << 3); |
dV = (uint8_t*)out_frm->plane[2] + (mby << 3) * out_frm->stride[2] + (mbx << 3); |
1058 |
sY = cur->y + (mby << 4) * std + (mbx << 4); |
sY = cur->y + (mby << 4) * std + (mbx << 4); |
1059 |
sU = cur->u + (mby << 3) * std2 + (mbx << 3); |
sU = cur->u + (mby << 3) * std2 + (mbx << 3); |
1060 |
sV = cur->v + (mby << 3) * std2 + (mbx << 3); |
sV = cur->v + (mby << 3) * std2 + (mbx << 3); |
1061 |
|
|
1062 |
for(i = 0 ; i < 16 ; i++) { |
for(i = 0 ; i < 16 ; i++) { |
1063 |
memcpy(dY,sY,w); |
memcpy(dY,sY,w); |
1064 |
dY += out_frm->stride_y; |
dY += out_frm->stride[0]; |
1065 |
sY += std; |
sY += std; |
1066 |
} |
} |
1067 |
for(i = 0 ; i < 8 ; i++) { |
for(i = 0 ; i < 8 ; i++) { |
1068 |
memcpy(dU,sU,w2); |
memcpy(dU,sU,w2); |
1069 |
dU += out_frm->stride_u; |
dU += out_frm->stride[1]; |
1070 |
sU += std2; |
sU += std2; |
1071 |
} |
} |
1072 |
for(i = 0 ; i < 8 ; i++) { |
for(i = 0 ; i < 8 ; i++) { |
1073 |
memcpy(dV,sV,w2); |
memcpy(dV,sV,w2); |
1074 |
dV += out_frm->stride_v; |
dV += out_frm->stride[2]; |
1075 |
sV += std2; |
sV += std2; |
1076 |
} |
} |
1077 |
} |
} |
1078 |
|
|
1079 |
|
|
1080 |
|
void |
1081 |
|
image_clear(IMAGE * img, int width, int height, int edged_width, |
1082 |
|
int y, int u, int v) |
1083 |
|
{ |
1084 |
|
uint8_t * p; |
1085 |
|
int i; |
1086 |
|
|
1087 |
|
p = img->y; |
1088 |
|
for (i = 0; i < height; i++) { |
1089 |
|
memset(p, y, width); |
1090 |
|
p += edged_width; |
1091 |
|
} |
1092 |
|
|
1093 |
|
p = img->u; |
1094 |
|
for (i = 0; i < height/2; i++) { |
1095 |
|
memset(p, u, width/2); |
1096 |
|
p += edged_width/2; |
1097 |
|
} |
1098 |
|
|
1099 |
|
p = img->v; |
1100 |
|
for (i = 0; i < height/2; i++) { |
1101 |
|
memset(p, v, width/2); |
1102 |
|
p += edged_width/2; |
1103 |
|
} |
1104 |
|
} |
1105 |
|
|
1106 |
|
|
1107 |
|
/* reduced resolution deblocking filter |
1108 |
|
block = block size (16=rrv, 8=full resolution) |
1109 |
|
flags = XVID_DEC_YDEBLOCK|XVID_DEC_UVDEBLOCK |
1110 |
|
*/ |
1111 |
|
void |
1112 |
|
image_deblock_rrv(IMAGE * img, int edged_width, |
1113 |
|
const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride, |
1114 |
|
int block, int flags) |
1115 |
|
{ |
1116 |
|
const int edged_width2 = edged_width /2; |
1117 |
|
const int nblocks = block / 8; /* skals code uses 8pixel block uints */ |
1118 |
|
int i,j; |
1119 |
|
|
1120 |
|
/* luma: j,i in block units */ |
1121 |
|
|
1122 |
|
for (j = 1; j < mb_height*2; j++) /* horizontal deblocking */ |
1123 |
|
for (i = 0; i < mb_width*2; i++) |
1124 |
|
{ |
1125 |
|
if (mbs[(j-1)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED || |
1126 |
|
mbs[(j+0)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED) |
1127 |
|
{ |
1128 |
|
hfilter_31(img->y + (j*block - 1)*edged_width + i*block, |
1129 |
|
img->y + (j*block + 0)*edged_width + i*block, nblocks); |
1130 |
|
} |
1131 |
|
} |
1132 |
|
|
1133 |
|
for (j = 0; j < mb_height*2; j++) /* vertical deblocking */ |
1134 |
|
for (i = 1; i < mb_width*2; i++) |
1135 |
|
{ |
1136 |
|
if (mbs[(j/2)*mb_stride + (i-1)/2].mode != MODE_NOT_CODED || |
1137 |
|
mbs[(j/2)*mb_stride + (i+0)/2].mode != MODE_NOT_CODED) |
1138 |
|
{ |
1139 |
|
vfilter_31(img->y + (j*block)*edged_width + i*block - 1, |
1140 |
|
img->y + (j*block)*edged_width + i*block + 0, |
1141 |
|
edged_width, nblocks); |
1142 |
|
} |
1143 |
|
} |
1144 |
|
|
1145 |
|
|
1146 |
|
|
1147 |
|
/* chroma */ |
1148 |
|
|
1149 |
|
for (j = 1; j < mb_height; j++) /* horizontal deblocking */ |
1150 |
|
for (i = 0; i < mb_width; i++) |
1151 |
|
{ |
1152 |
|
if (mbs[(j-1)*mb_stride + i].mode != MODE_NOT_CODED || |
1153 |
|
mbs[(j+0)*mb_stride + i].mode != MODE_NOT_CODED) |
1154 |
|
{ |
1155 |
|
hfilter_31(img->u + (j*block - 1)*edged_width2 + i*block, |
1156 |
|
img->u + (j*block + 0)*edged_width2 + i*block, nblocks); |
1157 |
|
hfilter_31(img->v + (j*block - 1)*edged_width2 + i*block, |
1158 |
|
img->v + (j*block + 0)*edged_width2 + i*block, nblocks); |
1159 |
|
} |
1160 |
|
} |
1161 |
|
|
1162 |
|
for (j = 0; j < mb_height; j++) /* vertical deblocking */ |
1163 |
|
for (i = 1; i < mb_width; i++) |
1164 |
|
{ |
1165 |
|
if (mbs[j*mb_stride + i - 1].mode != MODE_NOT_CODED || |
1166 |
|
mbs[j*mb_stride + i + 0].mode != MODE_NOT_CODED) |
1167 |
|
{ |
1168 |
|
vfilter_31(img->u + (j*block)*edged_width2 + i*block - 1, |
1169 |
|
img->u + (j*block)*edged_width2 + i*block + 0, |
1170 |
|
edged_width2, nblocks); |
1171 |
|
vfilter_31(img->v + (j*block)*edged_width2 + i*block - 1, |
1172 |
|
img->v + (j*block)*edged_width2 + i*block + 0, |
1173 |
|
edged_width2, nblocks); |
1174 |
|
} |
1175 |
|
} |
1176 |
|
|
1177 |
|
|
1178 |
|
} |
1179 |
|
|