H
hitman007260
Unregistered / Unconfirmed
GUEST, unregistred user!
const int __idecimal = 4096;
inline int AverageResize32VergeLine(BYTE * p_out,BYTE * p_in1,BYTE * p_in2,int x_verge,int x_in2,int x_delta)
{
//ebx : x_in2
//ecx : x_out
//edi : p_out
//esi : p_in1
//edx : p_in2
__asm
{
xor ecx,ecx
cmp ecx,x_verge
ja __end
mov edi,p_out
mov esi,p_in1
mov edx,p_in2
mov ebx,x_in2
__loop:
mov eax,ebx
shr eax,12
movd mm0,dword ptr [esi + eax * 4 + 0]
movd mm3,dword ptr [edx + eax * 4 + 0]
punpcklbw mm0,mm0
punpcklbw mm3,mm3
psrlw mm0,8
psrlw mm3,8
paddw mm0,mm3
psrlw mm0,1
packuswb mm0,mm0
movd dword ptr[edi + ecx * 4 + 0],mm0
add ebx,x_delta
inc ecx
cmp ecx,x_verge
jbe __loop
__end:
mov x_in2,ebx
}
return x_in2;
}
void AverageResize32Line(BYTE * p_out,BYTE * p_in1,BYTE * p_in2,int x_verge,int out_width,int x_in2,int x_delta)
{
//ebx : x_in2
//ecx : x_out
//edi : p_out
//esi : p_in1
//edx : p_in2
__asm
{
mov ecx,x_verge
cmp ecx,out_width
jae __end
mov edi,p_out
mov esi,p_in1
mov edx,p_in2
mov ebx,x_in2
__loop:
#ifdo
UBLE_AVERAGE
mov eax,ebx
sub eax,x_delta
shr eax,12
movd mm0,dword ptr [esi + eax * 4 + 0]
movd mm1,dword ptr [edx + eax * 4 + 0]
mov eax,ebx
shr eax,12
movd mm2,dword ptr [esi + eax * 4 + 0]
movd mm3,dword ptr [edx + eax * 4 + 0]
punpcklbw mm0,mm0
punpcklbw mm1,mm1
punpcklbw mm2,mm2
punpcklbw mm3,mm3
psrlw mm0,8
psrlw mm1,8
psrlw mm2,8
psrlw mm3,8
paddw mm2,mm3
paddw mm0,mm1
paddw mm0,mm2
psrlw mm0,2
packuswb mm0,mm0
#else
mov eax,ebx
sub eax,x_delta
shr eax,12
movd mm0,dword ptr [esi + eax * 4 + 0]
mov eax,ebx
shr eax,12
movd mm3,dword ptr [edx + eax * 4 + 0]
punpcklbw mm0,mm0
punpcklbw mm3,mm3
psrlw mm0,8
psrlw mm3,8
paddw mm0,mm3
psrlw mm0,1
packuswb mm0,mm0
#endif
movd dword ptr[edi + ecx * 4 + 0],mm0
add ebx,x_delta
inc ecx
cmp ecx,out_width
jb __loop
__end:
}
}
unsigned int AverageResize32(void * out,int out_width,int out_height,int out_pitch,
const void * in,int in_width,int in_height,int in_pitch)
{
//边界值
int y_delta = __idecimal * in_height / out_height;
int x_delta = __idecimal * in_width / out_width;
int y_verge = in_height / out_height / 2;
int x_verge = in_width / out_width / 2;
BYTE * p_out = (BYTE *)out;
int y_in2 = y_delta / 2;
//y边界条件
BYTE * p_in1 = (BYTE *)in;
BYTE * p_in2 = (BYTE *)((int)in + in_pitch * (y_in2 / __idecimal));
for(int y_out=0;
y_out<y_verge;
++y_out)
{
//y,x边界条件
int x_in2 = x_delta / 2;
x_in2 = AverageResize32VergeLine(p_out,p_in1,p_in2,x_verge,x_in2,x_delta);
AverageResize32Line(p_out,p_in1,p_in2,x_verge,out_width,x_in2,x_delta);
p_out = (BYTE *)((int)p_out + out_pitch);
y_in2 += y_delta;
p_in2 = (BYTE *)((int)p_in2 + in_pitch * (y_in2 / __idecimal));
y_in2 %= __idecimal;
}
p_in1 = (BYTE *)((int)in + in_pitch * ((y_delta * y_out - y_delta / 2) / __idecimal));
p_in2 = (BYTE *)((int)in + in_pitch * ((y_delta * y_out + y_delta / 2) / __idecimal));
for(;
y_out<out_height;
++y_out)
{
//x边界条件
int x_in2 = x_delta / 2;
x_in2 = AverageResize32VergeLine(p_out,p_in1,p_in2,x_verge,x_in2,x_delta);
AverageResize32Line(p_out,p_in1,p_in2,x_verge,out_width,x_in2,x_delta);
p_out = (BYTE *)((int)p_out + out_pitch);
y_in2 += y_delta;
p_in1 = p_in2;
//p_in1 = (BYTE *)((int)p_in1 + in_pitch * (y_in2 / __idecimal));
p_in2 = (BYTE *)((int)p_in2 + in_pitch * (y_in2 / __idecimal));
y_in2 %= __idecimal;
}
__asm emms;
return 0;
}
inline int AverageResize32VergeLine(BYTE * p_out,BYTE * p_in1,BYTE * p_in2,int x_verge,int x_in2,int x_delta)
{
//ebx : x_in2
//ecx : x_out
//edi : p_out
//esi : p_in1
//edx : p_in2
__asm
{
xor ecx,ecx
cmp ecx,x_verge
ja __end
mov edi,p_out
mov esi,p_in1
mov edx,p_in2
mov ebx,x_in2
__loop:
mov eax,ebx
shr eax,12
movd mm0,dword ptr [esi + eax * 4 + 0]
movd mm3,dword ptr [edx + eax * 4 + 0]
punpcklbw mm0,mm0
punpcklbw mm3,mm3
psrlw mm0,8
psrlw mm3,8
paddw mm0,mm3
psrlw mm0,1
packuswb mm0,mm0
movd dword ptr[edi + ecx * 4 + 0],mm0
add ebx,x_delta
inc ecx
cmp ecx,x_verge
jbe __loop
__end:
mov x_in2,ebx
}
return x_in2;
}
void AverageResize32Line(BYTE * p_out,BYTE * p_in1,BYTE * p_in2,int x_verge,int out_width,int x_in2,int x_delta)
{
//ebx : x_in2
//ecx : x_out
//edi : p_out
//esi : p_in1
//edx : p_in2
__asm
{
mov ecx,x_verge
cmp ecx,out_width
jae __end
mov edi,p_out
mov esi,p_in1
mov edx,p_in2
mov ebx,x_in2
__loop:
#ifdo
UBLE_AVERAGE
mov eax,ebx
sub eax,x_delta
shr eax,12
movd mm0,dword ptr [esi + eax * 4 + 0]
movd mm1,dword ptr [edx + eax * 4 + 0]
mov eax,ebx
shr eax,12
movd mm2,dword ptr [esi + eax * 4 + 0]
movd mm3,dword ptr [edx + eax * 4 + 0]
punpcklbw mm0,mm0
punpcklbw mm1,mm1
punpcklbw mm2,mm2
punpcklbw mm3,mm3
psrlw mm0,8
psrlw mm1,8
psrlw mm2,8
psrlw mm3,8
paddw mm2,mm3
paddw mm0,mm1
paddw mm0,mm2
psrlw mm0,2
packuswb mm0,mm0
#else
mov eax,ebx
sub eax,x_delta
shr eax,12
movd mm0,dword ptr [esi + eax * 4 + 0]
mov eax,ebx
shr eax,12
movd mm3,dword ptr [edx + eax * 4 + 0]
punpcklbw mm0,mm0
punpcklbw mm3,mm3
psrlw mm0,8
psrlw mm3,8
paddw mm0,mm3
psrlw mm0,1
packuswb mm0,mm0
#endif
movd dword ptr[edi + ecx * 4 + 0],mm0
add ebx,x_delta
inc ecx
cmp ecx,out_width
jb __loop
__end:
}
}
unsigned int AverageResize32(void * out,int out_width,int out_height,int out_pitch,
const void * in,int in_width,int in_height,int in_pitch)
{
//边界值
int y_delta = __idecimal * in_height / out_height;
int x_delta = __idecimal * in_width / out_width;
int y_verge = in_height / out_height / 2;
int x_verge = in_width / out_width / 2;
BYTE * p_out = (BYTE *)out;
int y_in2 = y_delta / 2;
//y边界条件
BYTE * p_in1 = (BYTE *)in;
BYTE * p_in2 = (BYTE *)((int)in + in_pitch * (y_in2 / __idecimal));
for(int y_out=0;
y_out<y_verge;
++y_out)
{
//y,x边界条件
int x_in2 = x_delta / 2;
x_in2 = AverageResize32VergeLine(p_out,p_in1,p_in2,x_verge,x_in2,x_delta);
AverageResize32Line(p_out,p_in1,p_in2,x_verge,out_width,x_in2,x_delta);
p_out = (BYTE *)((int)p_out + out_pitch);
y_in2 += y_delta;
p_in2 = (BYTE *)((int)p_in2 + in_pitch * (y_in2 / __idecimal));
y_in2 %= __idecimal;
}
p_in1 = (BYTE *)((int)in + in_pitch * ((y_delta * y_out - y_delta / 2) / __idecimal));
p_in2 = (BYTE *)((int)in + in_pitch * ((y_delta * y_out + y_delta / 2) / __idecimal));
for(;
y_out<out_height;
++y_out)
{
//x边界条件
int x_in2 = x_delta / 2;
x_in2 = AverageResize32VergeLine(p_out,p_in1,p_in2,x_verge,x_in2,x_delta);
AverageResize32Line(p_out,p_in1,p_in2,x_verge,out_width,x_in2,x_delta);
p_out = (BYTE *)((int)p_out + out_pitch);
y_in2 += y_delta;
p_in1 = p_in2;
//p_in1 = (BYTE *)((int)p_in1 + in_pitch * (y_in2 / __idecimal));
p_in2 = (BYTE *)((int)p_in2 + in_pitch * (y_in2 / __idecimal));
y_in2 %= __idecimal;
}
__asm emms;
return 0;
}