20 #define PIXEL_STRIDE 3
24 #define W_MU (1.060660171779821)
28 #define W_PI_4 (5.656854249492381)
30 #define W_PI_8 (23.086554390135440)
35 static int Dist(int32_t *A, int32_t *B)
37 int iDistR = A[0] - B[0];
38 int iDistG = A[1] - B[1];
39 int iDistB = A[2] - B[2];
40 register int iDistY = 2*iDistR + 4*iDistG + iDistB;
41 register int iDistU = -iDistR - 2*iDistG + 3*iDistB;
42 register int iDistV = 4*iDistR - 3*iDistG - iDistB;
43 return (abs(iDistY) + abs(iDistU) + abs(iDistV)) >> 4;
70 int FitStencils(
int *Stencil, int32_t *Image,
int Width,
int Height,
int StencilMul)
73 const int TVStride = 8*Width;
79 int *TvPtr, TvMin, Temp;
83 if(!(StencilTv = (
int *)malloc(
sizeof(
int)*8*Width*Height)))
88 for(y = 0; y < Height; y++)
96 Dv[0][2] = (y > 0) ? Dist(Image - Stride, Image) : 0;
97 Dv[1][2] = (y < Height-1) ? Dist(Image + Stride, Image) : 0;
104 for(x = 0; x < Width; x++, Image +=
PIXEL_STRIDE, TvPtr += 8)
127 Dh[0][1] = Dist(Image-Stride, Image-Stride+
PIXEL_STRIDE);
135 Dh[2][1] = Dist(Image+Stride, Image+Stride+
PIXEL_STRIDE);
157 TvPtr[1] = (Db[1][0] + Db[0][1]) + Db[0][0] + Db[1][1];
158 TvPtr[3] = (Dh[1][0] + Dh[1][1]) + Dh[0][0] + Dh[0][1] + Dh[2][0] + Dh[2][1];
159 TvPtr[5] = (Da[0][0] + Da[1][1]) + Da[1][0] + Da[0][1];
160 TvPtr[7] = (Dv[0][1] + Dv[1][1]) + Dv[0][0] + Dv[1][0] + Dv[0][2] + Dv[1][2];
162 TvPtr[0] = (int)((TvPtr[7] + TvPtr[1]*
W_MU) /
W_PI_8 + 0.5);
163 TvPtr[2] = (int)((TvPtr[1]*W_MU + TvPtr[3]) /
W_PI_8 + 0.5);
164 TvPtr[4] = (int)((TvPtr[3] + TvPtr[5]*W_MU) /
W_PI_8 + 0.5);
165 TvPtr[6] = (int)((TvPtr[5]*W_MU + TvPtr[7]) /
W_PI_8 + 0.5);
167 TvPtr[1] = (int)(TvPtr[1] /
W_PI_4 + 0.5);
168 TvPtr[3] = (int)(TvPtr[3] /
W_PI_2 + 0.5);
169 TvPtr[5] = (int)(TvPtr[5] /
W_PI_4 + 0.5);
170 TvPtr[7] = (int)(TvPtr[7] /
W_PI_2 + 0.5);
176 for(y = 0; y < Height; y++)
178 for(x = 0; x < Width; x++, TvPtr += 8, Stencil++)
180 if(1 <= x && x < Width - 1 && 1 <= y && y < Height - 1)
183 TvMin = TvPtr[-TVStride - 8] + TvPtr[-TVStride + 8]
184 + TvPtr[TVStride - 8] + TvPtr[TVStride + 8]
185 + ((TvPtr[-TVStride] + TvPtr[-8]
186 + TvPtr[8] + TvPtr[TVStride]) << 1)
190 for(k = 1; k < 8; k++)
192 Temp = TvPtr[k - TVStride - 8] + TvPtr[k - TVStride + 8]
193 + TvPtr[k + TVStride - 8] + TvPtr[k + TVStride + 8]
194 + ((TvPtr[k - TVStride] + TvPtr[k - 8]
195 + TvPtr[k + 8] + TvPtr[k + TVStride]) << 1)
211 for(k = 1; k < 8; k++)
213 TvMin = TvPtr[S = k];
216 *Stencil = StencilMul * S;