FilterFactory - Function "rad"

Back to function listing

Channel z in the source image, which is m units away, at an angle of d, from the center of the image

Syntax

rad(d,m,z)

Synonyms

rad0
rad1

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

5E pop esi (param_z)
8B 04 24 mov eax,[esp] (param_m)
8B 5C 24 04 mov ebx,[esp+$04] (param_d)
81 E3 FF 03 00 00 and ebx,$000003ff (1023)
0F BF 9C 5F 78 05 00 00 movsx ebx,[edi+ebx*2+$00000578] (COS_LOOKUP)
F7 EB imul ebx
05 FF 1F 00 00 add eax,$00001fff (8191)
83 D2 00 adc edx,$00 (0)
8B 4F 48 mov ecx,[edi+$48] (X)
0F AC D0 0E shrd eax,edx,$0e (14) Shift EAX right by 14 bits
Store lower 14 bits of EDX into the upper 14 bits of EAX
2B 4F 44 sub ecx,[edi+$44] (xmin)
D1 E9 shr ecx,1
03 C8 add ecx,eax
0B C9 or ecx,ecx
7D 04 jnl +$04 (@@1)
2B C9 sub ecx,ecx
EB 0A jnl +$0a (@@2)
@@1:
8B 47 48 mov eax,[edi+$48] (X)
3B C8 cmp ecx,eax
7C 03 jl +$03 (@@2)
8D 48 FF lea ecx,[eax-$01 (1)]
@@2:
58 pop eax (param_m)
5B pop ebx (param_d)
81 EB 00 01 00 00 sub ebx,$00000100 (256) param_d -= 256;
81 E3 FF 03 00 00 and ebx,$000003ff (1023) param_d %= 1024;
0F BF 9C 5F 78 05 00 00 movsx ebx,[edi+ebx*2+$00000578] (COS_LOOKUP) param_d = COS_LOOKUP[param_d];
F7 EB imul ebx eax *= param_d;
05 FF 1F 00 00 add eax,$00001fff (8191)
83 D2 00 adc edx,$00 (0)
8B 5F 54 mov ebx,[edi+$54] (Y)
0F AC D0 0E shrd eax,edx,$0e (14)
2B 5F 50 sub ebx,[edi+$50] (ymin)
D1 EB shr ebx,1
03 D8 add ebx,eax
0B DB or ebx,ebx
7D 04 jnl +$04 (@@3)
2B DB sub ebx,ebx
EB 0A jnl +$0a (@@4)
@@3:
8B 47 54 mov eax,[edi+$54] (Y)
3B D8 cmp ebx,eax
7C 03 jl +$03 (@@4)
8D 58 FF lea ebx,[eax-$01 (1)]
@@4:
8B 57 60 mov edx,[edi+$60] (Z)
2B 57 5C sub edx,[edi+$5c] (zmin)
03 B7 A8 45 00 00 add esi,[edi+$000045a8] (CANVAS)
0F AF 9F A0 45 00 00 imul ebx,[edi+$000045a0] (ROW_SIZE)
0F AF CA imul ecx,edx
33 C0 xor eax,eax
03 D9 add ebx,ecx
8A 04 1E mov al,[esi+ebx]
50 push eax

C++ code

int x = 999; // var['x'];
int X = 999; // var['X'];
int xmin = 0;
int y = 999; // var['y'];
int Y = 999; // var['Y'];
int ymin = 0;
int Z = 999; // var['Z'];
int zmin = 0;
int rowSize = 999;
uint8_t canvas[99999]; // RGBARGBARGBA...

int factory_rad(int d, int m, int z) {
	int esi, eax, ebx, ecx, edx;

	esi = z;
	eax = m;
	ebx = d;
	ebx &= 1023;
	ebx = COS_LOOKUP[ebx];
	eax = (((int64_t)eax * (int64_t)ebx) + 8191) >> 14;
	ecx = X;
	ecx -= xmin;
	ecx = ecx >> 1;
	ecx += eax;
	if (ecx < 0) {
		ecx = 0;
	}
	else {
		eax = X;
		if (ecx >= eax) {
			ecx = eax - 1;
		}
	}

	eax = m;
	ebx = d;
	ebx -= 256;
	ebx &= 1023;
	ebx = COS_LOOKUP[ebx];
	eax = (((int64_t)eax * (int64_t)ebx) + 8191) >> 14;
	ebx = Y;
	ebx -= ymin;
	ebx = ebx >> 1;
	ebx += eax;
	if (ebx < 0) {
		ebx = 0;
	}
	else {
		eax = Y;
		if (ebx >= eax) {
			ebx = eax - 1;
		}
	}

	// Now return pixel [x=ecx,y=ebx,z=esi] from the source image!
	edx = Z;
	edx -= zmin;
	ebx *= rowSize;
	ecx *= edx;
	ebx += ecx;
	eax = canvas[esi + ebx];
	return eax;
}