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 |
131 |
image_swap(IMAGE * image1, |
image_swap(IMAGE * image1, |
132 |
IMAGE * image2) |
IMAGE * image2) |
133 |
{ |
{ |
134 |
uint8_t *tmp; |
SWAP(uint8_t*, image1->y, image2->y); |
135 |
|
SWAP(uint8_t*, image1->u, image2->u); |
136 |
tmp = image1->y; |
SWAP(uint8_t*, image1->v, image2->v); |
|
image1->y = image2->y; |
|
|
image2->y = tmp; |
|
|
|
|
|
tmp = image1->u; |
|
|
image1->u = image2->u; |
|
|
image2->u = tmp; |
|
|
|
|
|
tmp = image1->v; |
|
|
image1->v = image2->v; |
|
|
image2->v = tmp; |
|
137 |
} |
} |
138 |
|
|
139 |
|
|
465 |
} |
} |
466 |
|
|
467 |
|
|
468 |
|
/* |
469 |
|
chroma optimize filter, invented by mf |
470 |
|
a chroma pixel is average from the surrounding pixels, when the |
471 |
|
correpsonding luma pixels are pure black or white. |
472 |
|
*/ |
473 |
|
|
474 |
|
void |
475 |
|
image_chroma_optimize(IMAGE * img, int width, int height, int edged_width) |
476 |
|
{ |
477 |
|
int x,y; |
478 |
|
int pixels = 0; |
479 |
|
|
480 |
|
for (y = 1; y < height/2 - 1; y++) |
481 |
|
for (x = 1; x < width/2 - 1; x++) |
482 |
|
{ |
483 |
|
#define IS_PURE(a) ((a)<=16||(a)>=235) |
484 |
|
#define IMG_Y(Y,X) img->y[(Y)*edged_width + (X)] |
485 |
|
#define IMG_U(Y,X) img->u[(Y)*edged_width/2 + (X)] |
486 |
|
#define IMG_V(Y,X) img->v[(Y)*edged_width/2 + (X)] |
487 |
|
|
488 |
|
if (IS_PURE(IMG_Y(y*2 ,x*2 )) && |
489 |
|
IS_PURE(IMG_Y(y*2 ,x*2+1)) && |
490 |
|
IS_PURE(IMG_Y(y*2+1,x*2 )) && |
491 |
|
IS_PURE(IMG_Y(y*2+1,x*2+1))) |
492 |
|
{ |
493 |
|
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; |
494 |
|
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; |
495 |
|
pixels++; |
496 |
|
} |
497 |
|
|
498 |
|
#undef IS_PURE |
499 |
|
#undef IMG_Y |
500 |
|
#undef IMG_U |
501 |
|
#undef IMG_V |
502 |
|
} |
503 |
|
|
504 |
|
DPRINTF(DPRINTF_DEBUG,"chroma_optimized_pixels = %i/%i", pixels, width*height/4); |
505 |
|
} |
506 |
|
|
507 |
|
|
508 |
|
|
509 |
|
|
510 |
|
|
511 |
/* |
/* |
512 |
perform safe packed colorspace conversion, by splitting |
perform safe packed colorspace conversion, by splitting |
553 |
uint32_t width, |
uint32_t width, |
554 |
int height, |
int height, |
555 |
uint32_t edged_width, |
uint32_t edged_width, |
556 |
uint8_t * src, |
uint8_t * src[4], |
557 |
int src_stride, |
int src_stride[4], |
558 |
int csp, |
int csp, |
559 |
int interlacing) |
int interlacing) |
560 |
{ |
{ |
563 |
const int height2 = height/2; |
const int height2 = height/2; |
564 |
//const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height; |
//const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height; |
565 |
|
|
|
|
|
|
// 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 ---^ |
|
|
|
|
566 |
switch (csp & ~XVID_CSP_VFLIP) { |
switch (csp & ~XVID_CSP_VFLIP) { |
567 |
case XVID_CSP_RGB555: |
case XVID_CSP_RGB555: |
568 |
safe_packed_conv( |
safe_packed_conv( |
569 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
570 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
571 |
interlacing?rgb555i_to_yv12 :rgb555_to_yv12, |
interlacing?rgb555i_to_yv12 :rgb555_to_yv12, |
572 |
interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2); |
interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2); |
574 |
|
|
575 |
case XVID_CSP_RGB565: |
case XVID_CSP_RGB565: |
576 |
safe_packed_conv( |
safe_packed_conv( |
577 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
578 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
579 |
interlacing?rgb565i_to_yv12 :rgb565_to_yv12, |
interlacing?rgb565i_to_yv12 :rgb565_to_yv12, |
580 |
interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2); |
interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2); |
581 |
break; |
break; |
582 |
|
|
583 |
|
|
584 |
case XVID_CSP_RGB24: |
case XVID_CSP_BGR: |
585 |
safe_packed_conv( |
safe_packed_conv( |
586 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
587 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
588 |
interlacing?bgri_to_yv12 :bgr_to_yv12, |
interlacing?bgri_to_yv12 :bgr_to_yv12, |
589 |
interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3); |
interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3); |
590 |
break; |
break; |
591 |
|
|
592 |
case XVID_CSP_RGB32: |
case XVID_CSP_BGRA: |
593 |
safe_packed_conv( |
safe_packed_conv( |
594 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
595 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
596 |
interlacing?bgrai_to_yv12 :bgra_to_yv12, |
interlacing?bgrai_to_yv12 :bgra_to_yv12, |
597 |
interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4); |
interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4); |
599 |
|
|
600 |
case XVID_CSP_ABGR : |
case XVID_CSP_ABGR : |
601 |
safe_packed_conv( |
safe_packed_conv( |
602 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
603 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
604 |
interlacing?abgri_to_yv12 :abgr_to_yv12, |
interlacing?abgri_to_yv12 :abgr_to_yv12, |
605 |
interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4); |
interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4); |
607 |
|
|
608 |
case XVID_CSP_RGBA : |
case XVID_CSP_RGBA : |
609 |
safe_packed_conv( |
safe_packed_conv( |
610 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
611 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
612 |
interlacing?rgbai_to_yv12 :rgba_to_yv12, |
interlacing?rgbai_to_yv12 :rgba_to_yv12, |
613 |
interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4); |
interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4); |
615 |
|
|
616 |
case XVID_CSP_YUY2: |
case XVID_CSP_YUY2: |
617 |
safe_packed_conv( |
safe_packed_conv( |
618 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
619 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
620 |
interlacing?yuyvi_to_yv12 :yuyv_to_yv12, |
interlacing?yuyvi_to_yv12 :yuyv_to_yv12, |
621 |
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); |
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); |
623 |
|
|
624 |
case XVID_CSP_YVYU: /* u/v swapped */ |
case XVID_CSP_YVYU: /* u/v swapped */ |
625 |
safe_packed_conv( |
safe_packed_conv( |
626 |
src, src_stride, image->y, image->v, image->y, |
src[0], src_stride[0], image->y, image->v, image->y, |
627 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
628 |
interlacing?yuyvi_to_yv12 :yuyv_to_yv12, |
interlacing?yuyvi_to_yv12 :yuyv_to_yv12, |
629 |
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); |
interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); |
631 |
|
|
632 |
case XVID_CSP_UYVY: |
case XVID_CSP_UYVY: |
633 |
safe_packed_conv( |
safe_packed_conv( |
634 |
src, src_stride, image->y, image->u, image->v, |
src[0], src_stride[0], image->y, image->u, image->v, |
635 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
636 |
interlacing?uyvyi_to_yv12 :uyvy_to_yv12, |
interlacing?uyvyi_to_yv12 :uyvy_to_yv12, |
637 |
interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2); |
interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2); |
639 |
|
|
640 |
case XVID_CSP_I420: |
case XVID_CSP_I420: |
641 |
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, |
642 |
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, |
643 |
width, width2, width, height, (csp & XVID_CSP_VFLIP)); |
src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP)); |
644 |
break |
break |
645 |
; |
; |
646 |
case XVID_CSP_YV12: /* u/v swapped */ |
case XVID_CSP_YV12: /* u/v swapped */ |
647 |
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, |
648 |
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, |
649 |
width, width2, width, height, (csp & XVID_CSP_VFLIP)); |
src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP)); |
650 |
break; |
break; |
651 |
|
|
652 |
case XVID_CSP_USER: |
case XVID_CSP_USER: |
653 |
{ |
/*XXX: support for different u & v strides */ |
|
DEC_PICTURE * pic = (DEC_PICTURE*)src; |
|
654 |
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, |
655 |
pic->y, pic->u, pic->v, pic->stride_y, pic->stride_y, |
src[0], src[1], src[2], src_stride[0], src_stride[1], |
656 |
width, height, (csp & XVID_CSP_VFLIP)); |
width, height, (csp & XVID_CSP_VFLIP)); |
|
} |
|
657 |
break; |
break; |
658 |
|
|
659 |
case XVID_CSP_NULL: |
case XVID_CSP_NULL: |
719 |
uint32_t width, |
uint32_t width, |
720 |
int height, |
int height, |
721 |
uint32_t edged_width, |
uint32_t edged_width, |
722 |
uint8_t * dst, |
uint8_t * dst[4], |
723 |
uint32_t dst_stride, |
uint32_t dst_stride[4], |
724 |
int csp, |
int csp, |
725 |
int interlacing) |
int interlacing) |
726 |
{ |
{ |
727 |
const int edged_width2 = edged_width/2; |
const int edged_width2 = edged_width/2; |
|
int width2 = width/2; |
|
728 |
int height2 = height/2; |
int height2 = height/2; |
729 |
|
|
730 |
/* |
/* |
733 |
image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm"); |
image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm"); |
734 |
*/ |
*/ |
735 |
|
|
|
|
|
|
// --- 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 ---^ |
|
|
|
|
|
|
|
736 |
switch (csp & ~XVID_CSP_VFLIP) { |
switch (csp & ~XVID_CSP_VFLIP) { |
737 |
case XVID_CSP_RGB555: |
case XVID_CSP_RGB555: |
738 |
safe_packed_conv( |
safe_packed_conv( |
739 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
740 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
741 |
interlacing?yv12_to_rgb555i :yv12_to_rgb555, |
interlacing?yv12_to_rgb555i :yv12_to_rgb555, |
742 |
interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2); |
interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2); |
744 |
|
|
745 |
case XVID_CSP_RGB565: |
case XVID_CSP_RGB565: |
746 |
safe_packed_conv( |
safe_packed_conv( |
747 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
748 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
749 |
interlacing?yv12_to_rgb565i :yv12_to_rgb565, |
interlacing?yv12_to_rgb565i :yv12_to_rgb565, |
750 |
interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2); |
interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2); |
751 |
return 0; |
return 0; |
752 |
|
|
753 |
case XVID_CSP_RGB24: |
case XVID_CSP_BGR: |
754 |
safe_packed_conv( |
safe_packed_conv( |
755 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
756 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
757 |
interlacing?yv12_to_bgri :yv12_to_bgr, |
interlacing?yv12_to_bgri :yv12_to_bgr, |
758 |
interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3); |
interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3); |
759 |
return 0; |
return 0; |
760 |
|
|
761 |
case XVID_CSP_RGB32: |
case XVID_CSP_BGRA: |
762 |
safe_packed_conv( |
safe_packed_conv( |
763 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
764 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
765 |
interlacing?yv12_to_bgrai :yv12_to_bgra, |
interlacing?yv12_to_bgrai :yv12_to_bgra, |
766 |
interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4); |
interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4); |
768 |
|
|
769 |
case XVID_CSP_ABGR: |
case XVID_CSP_ABGR: |
770 |
safe_packed_conv( |
safe_packed_conv( |
771 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
772 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
773 |
interlacing?yv12_to_abgri :yv12_to_abgr, |
interlacing?yv12_to_abgri :yv12_to_abgr, |
774 |
interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4); |
interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4); |
776 |
|
|
777 |
case XVID_CSP_RGBA: |
case XVID_CSP_RGBA: |
778 |
safe_packed_conv( |
safe_packed_conv( |
779 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
780 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
781 |
interlacing?yv12_to_rgbai :yv12_to_rgba, |
interlacing?yv12_to_rgbai :yv12_to_rgba, |
782 |
interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4); |
interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4); |
784 |
|
|
785 |
case XVID_CSP_YUY2: |
case XVID_CSP_YUY2: |
786 |
safe_packed_conv( |
safe_packed_conv( |
787 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
788 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
789 |
interlacing?yv12_to_yuyvi :yv12_to_yuyv, |
interlacing?yv12_to_yuyvi :yv12_to_yuyv, |
790 |
interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); |
interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); |
792 |
|
|
793 |
case XVID_CSP_YVYU: // u,v swapped |
case XVID_CSP_YVYU: // u,v swapped |
794 |
safe_packed_conv( |
safe_packed_conv( |
795 |
dst, dst_stride, image->y, image->v, image->u, |
dst[0], dst_stride[0], image->y, image->v, image->u, |
796 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
797 |
interlacing?yv12_to_yuyvi :yv12_to_yuyv, |
interlacing?yv12_to_yuyvi :yv12_to_yuyv, |
798 |
interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); |
interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); |
800 |
|
|
801 |
case XVID_CSP_UYVY: |
case XVID_CSP_UYVY: |
802 |
safe_packed_conv( |
safe_packed_conv( |
803 |
dst, dst_stride, image->y, image->u, image->v, |
dst[0], dst_stride[0], image->y, image->u, image->v, |
804 |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), |
805 |
interlacing?yv12_to_uyvyi :yv12_to_uyvy, |
interlacing?yv12_to_uyvyi :yv12_to_uyvy, |
806 |
interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2); |
interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2); |
807 |
return 0; |
return 0; |
808 |
|
|
809 |
case XVID_CSP_I420: |
case XVID_CSP_I420: |
810 |
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, |
811 |
width, width2, |
dst_stride[0], dst_stride[0]/2, |
812 |
image->y, image->u, image->v, edged_width, edged_width2, |
image->y, image->u, image->v, edged_width, edged_width2, |
813 |
width, height, (csp & XVID_CSP_VFLIP)); |
width, height, (csp & XVID_CSP_VFLIP)); |
814 |
return 0; |
return 0; |
815 |
|
|
816 |
case XVID_CSP_YV12: // u,v swapped |
case XVID_CSP_YV12: // u,v swapped |
817 |
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, |
818 |
width, width2, |
dst_stride[0], dst_stride[0]/2, |
819 |
image->y, image->v, image->u, edged_width, edged_width2, |
image->y, image->v, image->u, edged_width, edged_width2, |
820 |
width, height, (csp & XVID_CSP_VFLIP)); |
width, height, (csp & XVID_CSP_VFLIP)); |
821 |
return 0; |
return 0; |
822 |
|
|
823 |
case XVID_CSP_USER: |
case XVID_CSP_USER : // u,v swapped |
824 |
{ |
yv12_to_yv12(dst[0], dst[1], dst[2], |
825 |
DEC_PICTURE * pic = (DEC_PICTURE*)dst; |
dst_stride[0], dst_stride[1], /* v: dst_stride[2] */ |
826 |
pic->y = image->y; |
image->y, image->v, image->u, edged_width, edged_width2, |
827 |
pic->u = image->u; |
width, height, (csp & XVID_CSP_VFLIP)); |
828 |
pic->v = image->v; |
return 0; |
829 |
pic->stride_y = edged_width; |
|
830 |
pic->stride_uv = edged_width / 2; |
case XVID_CSP_INTERNAL : |
831 |
} |
dst[0] = image->y; |
832 |
|
dst[1] = image->u; |
833 |
|
dst[2] = image->v; |
834 |
|
dst_stride[0] = edged_width; |
835 |
|
dst_stride[1] = edged_width/2; |
836 |
|
dst_stride[2] = edged_width/2; |
837 |
return 0; |
return 0; |
838 |
|
|
839 |
case XVID_CSP_NULL: |
case XVID_CSP_NULL: |
840 |
case XVID_CSP_EXTERN: |
case XVID_CSP_SLICE: |
841 |
return 0; |
return 0; |
842 |
|
|
843 |
} |
} |
877 |
return psnr_y; |
return psnr_y; |
878 |
} |
} |
879 |
|
|
880 |
|
|
881 |
|
float sse_to_PSNR(long sse, int pixels) |
882 |
|
{ |
883 |
|
if (sse==0) |
884 |
|
return 99.99F; |
885 |
|
|
886 |
|
return 48.131F - 10*(float)log10((float)sse/(float)(pixels)); // log10(255*255)=4.8131 |
887 |
|
|
888 |
|
} |
889 |
|
|
890 |
|
long plane_sse(uint8_t * orig, |
891 |
|
uint8_t * recon, |
892 |
|
uint16_t stride, |
893 |
|
uint16_t width, |
894 |
|
uint16_t height) |
895 |
|
{ |
896 |
|
int diff, x, y; |
897 |
|
long sse=0; |
898 |
|
|
899 |
|
for (y = 0; y < height; y++) { |
900 |
|
for (x = 0; x < width; x++) { |
901 |
|
diff = *(orig + x) - *(recon + x); |
902 |
|
sse += diff * diff; |
903 |
|
} |
904 |
|
orig += stride; |
905 |
|
recon += stride; |
906 |
|
} |
907 |
|
return sse; |
908 |
|
} |
909 |
|
|
910 |
/* |
/* |
911 |
|
|
912 |
#include <stdio.h> |
#include <stdio.h> |
1003 |
} |
} |
1004 |
|
|
1005 |
|
|
|
#define ABS(X) (((X)>0)?(X):-(X)) |
|
1006 |
float |
float |
1007 |
image_mad(const IMAGE * img1, |
image_mad(const IMAGE * img1, |
1008 |
const IMAGE * img2, |
const IMAGE * img2, |
1033 |
} |
} |
1034 |
|
|
1035 |
void |
void |
1036 |
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) { |
1037 |
uint8_t *dY,*dU,*dV,*sY,*sU,*sV; |
uint8_t *dY,*dU,*dV,*sY,*sU,*sV; |
1038 |
int std2 = std >> 1; |
int std2 = std >> 1; |
1039 |
int w = mbl << 4, w2,i; |
int w = mbl << 4, w2,i; |
1042 |
w = width; |
w = width; |
1043 |
w2 = w >> 1; |
w2 = w >> 1; |
1044 |
|
|
1045 |
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); |
1046 |
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); |
1047 |
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); |
1048 |
sY = cur->y + (mby << 4) * std + (mbx << 4); |
sY = cur->y + (mby << 4) * std + (mbx << 4); |
1049 |
sU = cur->u + (mby << 3) * std2 + (mbx << 3); |
sU = cur->u + (mby << 3) * std2 + (mbx << 3); |
1050 |
sV = cur->v + (mby << 3) * std2 + (mbx << 3); |
sV = cur->v + (mby << 3) * std2 + (mbx << 3); |
1051 |
|
|
1052 |
for(i = 0 ; i < 16 ; i++) { |
for(i = 0 ; i < 16 ; i++) { |
1053 |
memcpy(dY,sY,w); |
memcpy(dY,sY,w); |
1054 |
dY += out_frm->stride_y; |
dY += out_frm->stride[0]; |
1055 |
sY += std; |
sY += std; |
1056 |
} |
} |
1057 |
for(i = 0 ; i < 8 ; i++) { |
for(i = 0 ; i < 8 ; i++) { |
1058 |
memcpy(dU,sU,w2); |
memcpy(dU,sU,w2); |
1059 |
dU += out_frm->stride_u; |
dU += out_frm->stride[1]; |
1060 |
sU += std2; |
sU += std2; |
1061 |
} |
} |
1062 |
for(i = 0 ; i < 8 ; i++) { |
for(i = 0 ; i < 8 ; i++) { |
1063 |
memcpy(dV,sV,w2); |
memcpy(dV,sV,w2); |
1064 |
dV += out_frm->stride_v; |
dV += out_frm->stride[2]; |
1065 |
sV += std2; |
sV += std2; |
1066 |
} |
} |
1067 |
} |
} |
1068 |
|
|
1069 |
|
|
1070 |
|
void |
1071 |
|
image_clear(IMAGE * img, int width, int height, int edged_width, |
1072 |
|
int y, int u, int v) |
1073 |
|
{ |
1074 |
|
uint8_t * p; |
1075 |
|
int i; |
1076 |
|
|
1077 |
|
p = img->y; |
1078 |
|
for (i = 0; i < height; i++) { |
1079 |
|
memset(p, y, width); |
1080 |
|
p += edged_width; |
1081 |
|
} |
1082 |
|
|
1083 |
|
p = img->u; |
1084 |
|
for (i = 0; i < height/2; i++) { |
1085 |
|
memset(p, u, width/2); |
1086 |
|
p += edged_width/2; |
1087 |
|
} |
1088 |
|
|
1089 |
|
p = img->v; |
1090 |
|
for (i = 0; i < height/2; i++) { |
1091 |
|
memset(p, v, width/2); |
1092 |
|
p += edged_width/2; |
1093 |
|
} |
1094 |
|
} |
1095 |
|
|
1096 |
|
|
1097 |
|
/* reduced resolution deblocking filter |
1098 |
|
block = block size (16=rrv, 8=full resolution) |
1099 |
|
flags = XVID_DEC_YDEBLOCK|XVID_DEC_UVDEBLOCK |
1100 |
|
*/ |
1101 |
|
void |
1102 |
|
image_deblock_rrv(IMAGE * img, int edged_width, |
1103 |
|
const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride, |
1104 |
|
int block, int flags) |
1105 |
|
{ |
1106 |
|
const int edged_width2 = edged_width /2; |
1107 |
|
const int nblocks = block / 8; /* skals code uses 8pixel block uints */ |
1108 |
|
int i,j; |
1109 |
|
|
1110 |
|
/* luma: j,i in block units */ |
1111 |
|
|
1112 |
|
for (j = 1; j < mb_height*2; j++) /* horizontal deblocking */ |
1113 |
|
for (i = 0; i < mb_width*2; i++) |
1114 |
|
{ |
1115 |
|
if (mbs[(j-1)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED || |
1116 |
|
mbs[(j+0)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED) |
1117 |
|
{ |
1118 |
|
hfilter_31(img->y + (j*block - 1)*edged_width + i*block, |
1119 |
|
img->y + (j*block + 0)*edged_width + i*block, nblocks); |
1120 |
|
} |
1121 |
|
} |
1122 |
|
|
1123 |
|
for (j = 0; j < mb_height*2; j++) /* vertical deblocking */ |
1124 |
|
for (i = 1; i < mb_width*2; i++) |
1125 |
|
{ |
1126 |
|
if (mbs[(j/2)*mb_stride + (i-1)/2].mode != MODE_NOT_CODED || |
1127 |
|
mbs[(j/2)*mb_stride + (i+0)/2].mode != MODE_NOT_CODED) |
1128 |
|
{ |
1129 |
|
vfilter_31(img->y + (j*block)*edged_width + i*block - 1, |
1130 |
|
img->y + (j*block)*edged_width + i*block + 0, |
1131 |
|
edged_width, nblocks); |
1132 |
|
} |
1133 |
|
} |
1134 |
|
|
1135 |
|
|
1136 |
|
|
1137 |
|
/* chroma */ |
1138 |
|
|
1139 |
|
for (j = 1; j < mb_height; j++) /* horizontal deblocking */ |
1140 |
|
for (i = 0; i < mb_width; i++) |
1141 |
|
{ |
1142 |
|
if (mbs[(j-1)*mb_stride + i].mode != MODE_NOT_CODED || |
1143 |
|
mbs[(j+0)*mb_stride + i].mode != MODE_NOT_CODED) |
1144 |
|
{ |
1145 |
|
hfilter_31(img->u + (j*block - 1)*edged_width2 + i*block, |
1146 |
|
img->u + (j*block + 0)*edged_width2 + i*block, nblocks); |
1147 |
|
hfilter_31(img->v + (j*block - 1)*edged_width2 + i*block, |
1148 |
|
img->v + (j*block + 0)*edged_width2 + i*block, nblocks); |
1149 |
|
} |
1150 |
|
} |
1151 |
|
|
1152 |
|
for (j = 0; j < mb_height; j++) /* vertical deblocking */ |
1153 |
|
for (i = 1; i < mb_width; i++) |
1154 |
|
{ |
1155 |
|
if (mbs[j*mb_stride + i - 1].mode != MODE_NOT_CODED || |
1156 |
|
mbs[j*mb_stride + i + 0].mode != MODE_NOT_CODED) |
1157 |
|
{ |
1158 |
|
vfilter_31(img->u + (j*block)*edged_width2 + i*block - 1, |
1159 |
|
img->u + (j*block)*edged_width2 + i*block + 0, |
1160 |
|
edged_width2, nblocks); |
1161 |
|
vfilter_31(img->v + (j*block)*edged_width2 + i*block - 1, |
1162 |
|
img->v + (j*block)*edged_width2 + i*block + 0, |
1163 |
|
edged_width2, nblocks); |
1164 |
|
} |
1165 |
|
} |
1166 |
|
|
1167 |
|
|
1168 |
|
} |
1169 |
|
|