FilterFactory - Function "c2m"

Back to function listing

Magnitude displacement of the pixel at coordinates x,y

Syntax

c2m(x,y)

Original Machine Code (in OPER resource) of Filter Factory 3.0 and 3.0.4 for Photoshop/Win32

5B pop ebx (param_y)
58 pop eax (param_x)
8B D0 mov edx,eax
C1 FA 1F sar edx,$1f (31)
33 C2 xor eax,edx
2B C2 sub eax,edx
8B D3 mov edx,ebx
C1 FA 1F sar edx,$1f (31)
33 DA xor ebx,edx
2B DA sub ebx,edx
3B C3 cmp eax,ebx
75 07 jnz +$07 (@@1)
B8 0A 6A 00 00 mov eax,$00006a0a (27146)
EB 11 jmp +$11 (@@3)
@@1:
7E 01 jle +$01 (@@2)
93 xchg eax,ebx
@@2:
C1 E0 0A shl eax,$0a (10)
99 cdq
F7 F3 div ebx
0F B7 84 47 78 15 00 00 movzx eax,[edi+eax*2+$00001578] (C2M_LOOKUP)
@@3:
F7 E3 mul ebx
0F AC D0 10 shrd eax,edx,$10 (16) Shift EAX right by 16 bits
Store lower 16 bits of EDX into the upper 16 bits of EAX
03 C3 add eax,ebx
50 push eax

C++ code

int factory_c2m(int x, int y) {
	int32_t aaa, bbb;
	bbb = y < 0 ? -y : y;
	aaa = x < 0 ? -x : x;
	if (aaa == bbb) {
		aaa = 27146; // 27146/65536 == sqrt(2)-1
	}
	else {
		if (aaa > bbb) {
			int xxx = aaa;
			aaa = bbb;
			bbb = xxx;
		}
		aaa = aaa << 10;
		aaa /= bbb;
		aaa = C2M_LOOKUP[aaa];
	}
	aaa = ((int64_t)aaa * (int64_t)bbb) >> 16;
	aaa += bbb;
	return aaa;
}