FilterFactory - Function "c2d"

Back to function listing

Angle displacement of the pixel at coordinates x,y

Note: FilterFactory defines c2d(x,y) := atan2(y,x), but d := atan2(-y,-x)

Syntax

c2d(x,y)

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

58 pop eax (param_y)
5B pop ebx (param_x)
33 C9 xor ecx,ecx
0B C0 or eax,eax
7D 05 jnl +$05 (@@1)
F7 D8 neg eax
80 C9 04 or cl,$04 (4)
@@1:
0B DB or ebx,ebx
7D 05 jnl +$05 (@@2)
F7 DB neg ebx
80 C9 03 or cl,$03 (3)
@@2:
3B C3 cmp eax,ebx
7E 04 jle +$04 (@@3)
80 F1 01 xor cl,$01 (1)
93 xchg eax,ebx
@@3:
0B C0 or eax,eax
7E 1B jle +$1b (@@4)
C1 E0 0A shl eax,$0a (10)
99 cdq
F7 F3 div ebx
74 13 jz +$13 (@@4) // C2D_LOOKUP[-1] will never be called. Good!
66 8B 84 47 76 0D 00 00 mov ax,[edi+eax*2+$00000d76] (C2D_LOOKUP-$2) ax=C2D_LOOKUP[eax-1];
C1 E0 09 shl eax,$09 (9)
99 cdq
BB 40 24 03 00 mov ebx,$00032440 (205888)
F7 FB idiv ebx
@@4:
66 0F BA E1 00 bt cx,$00 (0) bit 0 set?
73 07 jnb +$07 (@@5) if ((ecx & 0b1) != 0) goto @@5
F7 D8 neg eax
05 00 01 00 00 add eax,$00000100 (256)
@@5:
66 0F BA E1 01 bt cx,$01 (1) bit 1 set?
73 05 jnb +$05 (@@6) if ((ecx & 0b01) != 0) goto @@6
05 00 01 00 00 add eax,$00000100 (256)
@@6:
66 0F BA E1 02 bt cx,$02 (2) bit 2 set?
73 02 jnb +$02 (@@7) if ((ecx & 0b001) != 0) goto @@7
F7 D8 neg eax
@@7:
50 push eax

C++ code

int factory_c2d(int x, int y) {
	int32_t aaa, bbb, ccc;
	aaa = y;
	bbb = x;
	ccc = 0;
	if (aaa < 0) {
		aaa = -aaa;
		ccc |= 0b0100;
	}
	if (bbb < 0) {
		bbb = -bbb;
		ccc |= 0b0011;
	}
	if (aaa > bbb) {
		int xxx;
		ccc ^= 0b0001;
		xxx = aaa;
		aaa = bbb;
		bbb = xxx;
	}
	if (aaa > 0) {
		aaa = aaa << 10;
		aaa /= bbb;
		if (aaa != 0) {
			aaa = (aaa & 0xFFFF0000) | (C2D_LOOKUP[aaa - 1] & 0xFFFF);
			aaa = aaa << 9;
			bbb = 205888; // 205888/65536 == pi
			aaa /= bbb;
		}
	}
	if ((ccc & 0b0001) != 0) {
		aaa = -aaa;
		aaa += 256;
	}
	if ((ccc & 0b0010) != 0) {
		aaa += 256;
	}
	if ((ccc & 0b0100) != 0) {
		aaa = -aaa;
	}
	return aaa;
}