00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <math.h>
00013 #include <limits.h>
00014 #include <float.h>
00015
00016 #include "global.h"
00017 #include "rdopt_coding_state.h"
00018 #include "mb_access.h"
00019 #include "intrarefresh.h"
00020 #include "image.h"
00021 #include "transform8x8.h"
00022 #include "ratectl.h"
00023 #include "mode_decision.h"
00024 #include "fmo.h"
00025 #include "me_umhex.h"
00026 #include "me_umhexsmp.h"
00027 #include "macroblock.h"
00028 #include "mv_search.h"
00029 #include "md_distortion.h"
00030
00031
00032 void setupDistortion(Slice *currSlice)
00033 {
00034
00035 currSlice->getDistortion = distortionSSE;
00036
00037
00038 }
00039
00040
00041
00042
00043
00044
00045
00046 int64 compute_SSE(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc, int ySize, int xSize)
00047 {
00048 int i, j;
00049 imgpel *lineRef, *lineSrc;
00050 int64 distortion = 0;
00051
00052 for (j = 0; j < ySize; j++)
00053 {
00054 lineRef = &imgRef[j][xRef];
00055 lineSrc = &imgSrc[j][xSrc];
00056
00057 for (i = 0; i < xSize; i++)
00058 distortion += iabs2( *lineRef++ - *lineSrc++ );
00059 }
00060 return distortion;
00061 }
00062
00063 int64 compute_SSE_cr(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc, int ySize, int xSize)
00064 {
00065 int i, j;
00066 imgpel *lineRef, *lineSrc;
00067 int64 distortion = 0;
00068
00069 for (j = 0; j < ySize; j++)
00070 {
00071 lineRef = &imgRef[j][xRef];
00072 lineSrc = &imgSrc[j][xSrc];
00073
00074 for (i = 0; i < xSize; i++)
00075 distortion += iabs2( *lineRef++ - *lineSrc++ );
00076 }
00077
00078 return distortion;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087 int64 compute_SSE16x16(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc)
00088 {
00089 int i, j;
00090 imgpel *lineRef, *lineSrc;
00091 int64 distortion = 0;
00092
00093 for (j = 0; j < MB_BLOCK_SIZE; j++)
00094 {
00095 lineRef = &imgRef[j][xRef];
00096 lineSrc = &imgSrc[j][xSrc];
00097
00098 for (i = 0; i < MB_BLOCK_SIZE; i++)
00099 distortion += iabs2( *lineRef++ - *lineSrc++ );
00100 }
00101 return distortion;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 int64 compute_SSE8x8(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc)
00111 {
00112 int i, j;
00113 imgpel *lineRef, *lineSrc;
00114 int64 distortion = 0;
00115
00116 for (j = 0; j < BLOCK_SIZE_8x8; j++)
00117 {
00118 lineRef = &imgRef[j][xRef];
00119 lineSrc = &imgSrc[j][xSrc];
00120
00121 for (i = 0; i < BLOCK_SIZE_8x8; i++)
00122 distortion += iabs2( *lineRef++ - *lineSrc++ );
00123 }
00124 return distortion;
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134 int64 compute_SSE4x4(imgpel **imgRef, imgpel **imgSrc, int xRef, int xSrc)
00135 {
00136 int i, j;
00137 imgpel *lineRef, *lineSrc;
00138 int64 distortion = 0;
00139
00140 for (j = 0; j < BLOCK_SIZE; j++)
00141 {
00142 lineRef = &imgRef[j][xRef];
00143 lineSrc = &imgSrc[j][xSrc];
00144
00145 for (i = 0; i < BLOCK_SIZE; i++)
00146 distortion += iabs2( *lineRef++ - *lineSrc++ );
00147 }
00148
00149 return distortion;
00150 }
00151
00152
00153
00154
00155
00156
00157
00158 int64 distortionSSE(Macroblock *currMB)
00159 {
00160 ImageParameters *p_Img = currMB->p_Img;
00161 InputParameters *p_Inp = currMB->p_Inp;
00162 int64 distortionY = 0;
00163 int64 distortionCr[2] = {0, 0};
00164
00165
00166 distortionY = compute_SSE16x16(&p_Img->pCurImg[currMB->opix_y], &p_Img->enc_picture->p_curr_img[currMB->pix_y], currMB->pix_x, currMB->pix_x);
00167
00168
00169 if ((p_Img->yuv_format != YUV400) && !IS_INDEPENDENT(p_Inp))
00170 {
00171 distortionCr[0] = compute_SSE_cr(&p_Img->pImgOrg[1][currMB->opix_c_y], &p_Img->enc_picture->imgUV[0][currMB->pix_c_y], currMB->pix_c_x, currMB->pix_c_x, p_Img->mb_cr_size_y, p_Img->mb_cr_size_x);
00172 distortionCr[1] = compute_SSE_cr(&p_Img->pImgOrg[2][currMB->opix_c_y], &p_Img->enc_picture->imgUV[1][currMB->pix_c_y], currMB->pix_c_x, currMB->pix_c_x, p_Img->mb_cr_size_y, p_Img->mb_cr_size_x);
00173 }
00174
00175 return (int64)( distortionY * p_Inp->WeightY + distortionCr[0] * p_Inp->WeightCb + distortionCr[1] * p_Inp->WeightCr );
00176 }
00177
00178