FilterFactory - Symbol "M"

Back to function listing

Range of magnitudes with the image, where mmin is always 0 and M is always one half the diagonal size of the image

Syntax

M

Synonyms

mmax

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

8B 47 48 mov eax,[edi+$48] (X) .
8B 5F 54 mov ebx,[edi+$54] (Y) .
2B 47 44 sub eax,[edi+$44] (xmin) .
2B 5F 50 sub ebx,[edi+$50] (ymin) .
D1 F8 sar eax,1 a = (X-xmin)/2;
D1 FB sar ebx,1 b = (Y-ymin)/2;
3B C3 cmp eax,ebx .
75 07 jnz +$07 (@@1) if (a!=b) goto @@1;
B8 0A 6A 00 00 mov eax,$00006a0a (27146) a = 27146; // proportion for a==b . Imaginary C2M_LOOKUP[1024]
EB 11 jmp +$11 (@@3) goto @@3;
@@1: @@1: // a!=b
7E 01 jle +$01 (@@2) if (a<=b) goto @@2; // effective: a<b ?
93 xchg eax,ebx tmp=a; a=b; b=tmp;
@@2: @@2: // a<=b, effektiv a<b ?
C1 E0 0A shl eax,$0a (10) a *= 1024;
99 cdq d = (a<0) ? -1 : 0;
F7 F3 div ebx a /= b;
0F B7 84 47 78 15 00 00 movzx eax,[edi+eax*2+$00001578] (C2M_LOOKUP) a = C2M_LOOKUP[a];
@@3: @@3:
F7 E3 mul ebx a *= b;
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 a += b;
50 push eax return res;

C++ code

int X, xmin, Y, ymin;

int factory_M() {
	int eax, ebx;

	eax = (X - xmin) >> 1;
	ebx = (Y - ymin) >> 1;
	if (eax == ebx) {
		eax = 27146; // 27146/65536 == sqrt(2)-1
	}
	else {
		if (eax > ebx) {
			int xxx = eax;
			eax = ebx;
			ebx = xxx;
		}
		eax = eax << 10;
		eax /= ebx;
		eax = C2M_LOOKUP[eax];
	}
	eax = ((int64_t)eax * (int64_t)ebx) >> 16;
	eax += ebx;
	return eax;
}

Implementation in Windows plugin 3.00a (beta version) and 3.00b (internal build)

3.00a (beta version) and 3.00b (internal build) did internally calculate (X-xmin) instead of (X-xmin)/2, and (Y-ymin) instead of (Y-ymin)/2.

Version 3.00a (beta version) and 3.00b (internal build) Version 3.00 (final) and 3.0.4
mov eax,DWORD PTR [edi+0x48] ; X
mov ebx,DWORD PTR [edi+0x54] ; Y
sub eax,DWORD PTR [edi+0x44] ; xmin
sub ebx,DWORD PTR [edi+0x50] ; ymin


cmp eax,ebx
jne @@1
mov eax,0x6a0a ; 27146/65536 == sqrt(2)-1
jmp @@3
@@1:
jle @@2
xchg ebx,eax
@@2:
shl eax,0xa
cdq
div ebx
movzx eax,WORD PTR [edi+eax*2+0x1578] ; C2M_LOOKUP
@@3:
mul ebx
shrd eax,edx,0x10
add eax,ebx
push eax 
mov eax,DWORD PTR [edi+0x48] ; X
mov ebx,DWORD PTR [edi+0x54] ; Y
sub eax,DWORD PTR [edi+0x44] ; xmin
sub ebx,DWORD PTR [edi+0x50] ; ymin
sar eax,1     ; added eax = (X-xmin)/2
sar ebx,1     ; added ebx = (Y-ymin)/2
cmp eax,ebx
jne @@1
mov eax,0x6a0a ; 27146/65536 == sqrt(2)-1
jmp @@3
@@1:
jle @@2
xchg ebx,eax
@@2:
shl eax,0xa
cdq
div ebx
movzx eax,WORD PTR [edi+eax*2+0x1578] ; C2M_LOOKUP
@@3:
mul ebx
shrd eax,edx,0x10
add eax,ebx
push eax