3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Image management functions - |
* - Image management functions - |
5 |
* |
* |
6 |
* Copyright(C) 2001-2004 Peter Ross <pross@xvid.org> |
* Copyright(C) 2001-2010 Peter Ross <pross@xvid.org> |
7 |
* |
* |
8 |
* This program is free software ; you can redistribute it and/or modify |
* This program is free software ; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
19 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* $Id: image.c,v 1.45 2010-08-10 15:00:12 Isibaar Exp $ |
* $Id: image.c,v 1.46 2010-11-28 15:18:21 Isibaar Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
862 |
return (sse); |
return (sse); |
863 |
} |
} |
864 |
|
|
865 |
|
void image_block_variance(IMAGE * orig_image, |
866 |
|
uint16_t stride, |
867 |
|
MACROBLOCK *mbs, |
868 |
|
uint16_t mb_width, |
869 |
|
uint16_t mb_height) |
870 |
|
{ |
871 |
|
DECLARE_ALIGNED_MATRIX(sums, 1, 4, uint16_t, CACHE_LINE); |
872 |
|
DECLARE_ALIGNED_MATRIX(squares, 1, 4, uint32_t, CACHE_LINE); |
873 |
|
|
874 |
|
int x, y, i, j; |
875 |
|
uint8_t *orig = orig_image->y; |
876 |
|
|
877 |
|
for (y = 0; y < mb_height; y++) { |
878 |
|
for (x = 0; x < mb_width; x++) { |
879 |
|
MACROBLOCK *pMB = &mbs[x + y * mb_width]; |
880 |
|
uint32_t var4[4]; |
881 |
|
uint32_t sum = 0, square = 0; |
882 |
|
|
883 |
|
for (j = 0; j < 2; j++) { |
884 |
|
for (i = 0; i < 2; i++) { |
885 |
|
int lsum = blocksum8(orig + ((y<<4) + (j<<3))*stride + (x<<4) + (i<<3), |
886 |
|
stride, sums, squares); |
887 |
|
int lsquare = (squares[0] + squares[1] + squares[2] + squares[3]); |
888 |
|
|
889 |
|
sum += lsum; |
890 |
|
square += lsquare; |
891 |
|
|
892 |
|
var4[0] = (squares[0]<<4) - sums[0]*sums[0]; |
893 |
|
var4[1] = (squares[1]<<4) - sums[1]*sums[1]; |
894 |
|
var4[2] = (squares[2]<<4) - sums[2]*sums[2]; |
895 |
|
var4[3] = (squares[3]<<4) - sums[3]*sums[3]; |
896 |
|
|
897 |
|
pMB->rel_var8[j*2 + i] = lsquare - lsum*lsum; |
898 |
|
|
899 |
|
if (pMB->rel_var8[j*2 + i]) |
900 |
|
pMB->rel_var8[j*2 + i] = 256*(var4[0] + var4[1] + var4[2] + var4[3]) / |
901 |
|
pMB->rel_var8[j*2 + i]; /* 4*(Var(Di)/Var(D)) */ |
902 |
|
else |
903 |
|
pMB->rel_var8[j*2 + i] = 64; |
904 |
|
} |
905 |
|
} |
906 |
|
} |
907 |
|
} |
908 |
|
} |
909 |
|
|
910 |
#if 0 |
#if 0 |
911 |
|
|
912 |
#include <stdio.h> |
#include <stdio.h> |