Filter Factory "cos" lookup table

Go to cos function / Go to sin function / Go to tan function

Attention: This page only addresses Filter Factory 3.0.4 for Photoshop/Win32.

Filter Factory for Premiere and Transition Factory use a lookup table stored in a resource, while Filter Factory for Photoshop generates the lookup table in-memory.

cos lookup table 1cos lookup table 2

Location

Offset: [1C006004]+0578h
Size: 1024*2 = 800h
Type: Array [0..1023] of sint16

Usage in OPER symbols

cos, sin, r2x, r2y, tan, rad

Reconstructed generation code

C++

sint16 COS_LOOKUP[0..1023];
for (i=0; i<1024; i++) {
	if (i < 256) {
		COS_LOOKUP[i] = Fix2Long(FracCos(FixDiv(i*31416, 5120000)));
	} else if (i < 512) {
		COS_LOOKUP[i] = -COS_LOOKUP[511-i]; // 511-i == 255-(i-256)
	} else if (i < 768) {
		COS_LOOKUP[i] = COS_LOOKUP[1023-i]; // 1023-i == 511-(i-512)
	} else /* if (i < 1024) */ {
		COS_LOOKUP[i] = -COS_LOOKUP[1535-i]; // 1535-i == 1023-(i-1024)
	} /* else {
		COS_LOOKUP[i] = COS_LOOKUP[i%1024];
	} */
}

Delphi

function Fix2Long(a: integer): integer; stdcall; external 'C:\Programme\Adobe\Photoshop 7.0\plugin.dll';
function FracCos(a: integer): integer; stdcall; external 'C:\Programme\Adobe\Photoshop 7.0\plugin.dll';
function FixDiv(a,b: integer): integer; stdcall; external 'C:\Programme\Adobe\Photoshop 7.0\plugin.dll';

function AdobeCos(i: integer): integer;
begin
  if i < 256 then
    result := Fix2Long(FracCos(FixDiv(i*31416, 5120000)))
  else if i < 512 then
    result := -mycos(511-i)
  else if i < 768 then
    result := mycos(1023-i)
  else if i < 1024 then
    result := -mycos(1535-i)
  else
    result := mycos(i mod 1024);
end;

Disassembled generation code

  1C0012FF: A1 04 60 00 1C     mov         eax,[1C006004]
  1C001304: 05 78 05 00 00     add         eax,578h
  1C001309: 50                 push        eax
  1C00130A: E8 41 27 00 00     call        1C003A50 (@@GENERATE_COS)
...
@@GENERATE_COS:
  1C003A50: 53                 push        ebx
  1C003A51: 56                 push        esi
  1C003A52: 57                 push        edi
  1C003A53: 8B 74 24 10        mov         esi,dword ptr [esp+10h] ; esi=[1C006004]+578h
  1C003A57: 2B FF              sub         edi,edi
  1C003A59: 8B DE              mov         ebx,esi
  1C003A5B: 05 00 00 00 00     add         eax,0
@@COS_1:
  1C003A60: 68 00 20 4E 00     push        4E2000h ; 5120000
  1C003A65: 57                 push        edi
  1C003A66: E8 FB 22 00 00     call        FixDiv ; Plugin.dll by Adobe
  1C003A6B: 50                 push        eax
  1C003A6C: 83 C3 02           add         ebx,2
  1C003A6F: E8 EC 22 00 00     call        FracCos ; Plugin.dll by Adobe
  1C003A74: 50                 push        eax
  1C003A75: 81 C7 B8 7A 00 00  add         edi,7AB8h ; 31416 = Pi
  1C003A7B: E8 DA 22 00 00     call        Fix2Long ; Plugin.dll by Adobe
  1C003A80: 66 89 43 FE        mov         word ptr [ebx-2],ax
  1C003A84: 81 FF 00 B8 7A 00  cmp         edi,7AB800h ; 8042496 = 256*31416
  1C003A8A: 7C D4              jl          1C003A60 (@@COS_1)
  1C003A8C: 8D 96 00 02 00 00  lea         edx,[esi+00000200h]
  1C003A92: 81 C6 FE 01 00 00  add         esi,1FEh ; 510
  1C003A98: B9 00 01 00 00     mov         ecx,100h ; 256
  1C003A9D: 8D 49 00           lea         ecx,[ecx]
@@COS_2:
  1C003AA0: 66 8B 06           mov         ax,word ptr [esi]
  1C003AA3: 66 F7 D8           neg         ax
  1C003AA6: 66 89 02           mov         word ptr [edx],ax
  1C003AA9: 83 C2 02           add         edx,2
  1C003AAC: 66 8B 82 FE FD FF  mov         ax,word ptr [edx+FFFFFDFEh] ; -514
            FF
  1C003AB3: 83 EE 02           sub         esi,2
  1C003AB6: 66 F7 D8           neg         ax
  1C003AB9: 66 89 82 FE 01 00  mov         word ptr [edx+000001FEh],ax ; 510
            00
  1C003AC0: 49                 dec         ecx
  1C003AC1: 66 8B 5E 02        mov         bx,word ptr [esi+2]
  1C003AC5: 66 89 9A FE 03 00  mov         word ptr [edx+000003FEh],bx ; 1022
            00
  1C003ACC: 75 D2              jne         1C003AA0 (@@COS_2)
  1C003ACE: 5F                 pop         edi
  1C003ACF: 5E                 pop         esi
  1C003AD0: 5B                 pop         ebx
  1C003AD1: C3                 ret

Constants used

None.

Lookup table

Download as CSV

Download 16-bit dump

C++ array

const int COS_LOOKUP[1024] = {
	16384, 16383, 16382, 16381, 16379, 16376, 16372, 16368, 16364, 16359, 16353, 16346, 16339, 16331, 16323,
	16314, 16305, 16294, 16284, 16272, 16260, 16248, 16234, 16221, 16206, 16191, 16175, 16159, 16142, 16125,
	16107, 16088, 16069, 16049, 16028, 16007, 15985, 15963, 15940, 15917, 15893, 15868, 15842, 15817, 15790,
	15763, 15735, 15707, 15678, 15649, 15618, 15588, 15557, 15525, 15492, 15459, 15426, 15392, 15357, 15322,
	15286, 15249, 15212, 15175, 15136, 15098, 15058, 15018, 14978, 14937, 14895, 14853, 14811, 14767, 14723,
	14679, 14634, 14589, 14543, 14496, 14449, 14401, 14353, 14304, 14255, 14205, 14155, 14104, 14053, 14001,
	13948, 13895, 13842, 13788, 13733, 13678, 13622, 13566, 13510, 13452, 13395, 13337, 13278, 13219, 13159,
	13099, 13039, 12977, 12916, 12854, 12791, 12728, 12665, 12601, 12536, 12471, 12406, 12340, 12273, 12207,
	12139, 12072, 12003, 11935, 11866, 11796, 11726, 11656, 11585, 11513, 11442, 11370, 11297, 11224, 11151,
	11077, 11003, 10928, 10853, 10777, 10701, 10625, 10548, 10471, 10394, 10316, 10237, 10159, 10080, 10000,
	9920, 9840, 9760, 9679, 9597, 9516, 9434, 9351, 9269, 9186, 9102, 9018, 8934, 8850, 8765, 8680, 8595,
	8509, 8423, 8336, 8250, 8163, 8075, 7988, 7900, 7812, 7723, 7634, 7545, 7456, 7366, 7276, 7186, 7096,
	7005, 6914, 6822, 6731, 6639, 6547, 6455, 6362, 6270, 6176, 6083, 5990, 5896, 5802, 5708, 5614, 5519,
	5424, 5329, 5234, 5139, 5043, 4948, 4852, 4756, 4659, 4563, 4466, 4369, 4273, 4175, 4078, 3981, 3883,
	3785, 3687, 3589, 3491, 3393, 3295, 3196, 3097, 2998, 2900, 2801, 2702, 2602, 2503, 2404, 2304, 2205,
	2105, 2005, 1905, 1806, 1706, 1606, 1505, 1405, 1305, 1205, 1105, 1004, 904, 804, 703, 603, 502, 402,
	301, 201, 100, -100, -201, -301, -402, -502, -603, -703, -804, -904, -1004, -1105, -1205, -1305, -1405,
	-1505, -1606, -1706, -1806, -1905, -2005, -2105, -2205, -2304, -2404, -2503, -2602, -2702, -2801, -2900,
	-2998, -3097, -3196, -3295, -3393, -3491, -3589, -3687, -3785, -3883, -3981, -4078, -4175, -4273, -4369,
	-4466, -4563, -4659, -4756, -4852, -4948, -5043, -5139, -5234, -5329, -5424, -5519, -5614, -5708, -5802,
	-5896, -5990, -6083, -6176, -6270, -6362, -6455, -6547, -6639, -6731, -6822, -6914, -7005, -7096, -7186,
	-7276, -7366, -7456, -7545, -7634, -7723, -7812, -7900, -7988, -8075, -8163, -8250, -8336, -8423, -8509,
	-8595, -8680, -8765, -8850, -8934, -9018, -9102, -9186, -9269, -9351, -9434, -9516, -9597, -9679, -9760,
	-9840, -9920, -10000, -10080, -10159, -10237, -10316, -10394, -10471, -10548, -10625, -10701, -10777,
	-10853, -10928, -11003, -11077, -11151, -11224, -11297, -11370, -11442, -11513, -11585, -11656, -11726,
	-11796, -11866, -11935, -12003, -12072, -12139, -12207, -12273, -12340, -12406, -12471, -12536, -12601,
	-12665, -12728, -12791, -12854, -12916, -12977, -13039, -13099, -13159, -13219, -13278, -13337, -13395,
	-13452, -13510, -13566, -13622, -13678, -13733, -13788, -13842, -13895, -13948, -14001, -14053, -14104,
	-14155, -14205, -14255, -14304, -14353, -14401, -14449, -14496, -14543, -14589, -14634, -14679, -14723,
	-14767, -14811, -14853, -14895, -14937, -14978, -15018, -15058, -15098, -15136, -15175, -15212, -15249,
	-15286, -15322, -15357, -15392, -15426, -15459, -15492, -15525, -15557, -15588, -15618, -15649, -15678,
	-15707, -15735, -15763, -15790, -15817, -15842, -15868, -15893, -15917, -15940, -15963, -15985, -16007,
	-16028, -16049, -16069, -16088, -16107, -16125, -16142, -16159, -16175, -16191, -16206, -16221, -16234,
	-16248, -16260, -16272, -16284, -16294, -16305, -16314, -16323, -16331, -16339, -16346, -16353, -16359,
	-16364, -16368, -16372, -16376, -16379, -16381, -16382, -16383, -16384, -16384, -16383, -16382, -16381,
	-16379, -16376, -16372, -16368, -16364, -16359, -16353, -16346, -16339, -16331, -16323, -16314, -16305,
	-16294, -16284, -16272, -16260, -16248, -16234, -16221, -16206, -16191, -16175, -16159, -16142, -16125,
	-16107, -16088, -16069, -16049, -16028, -16007, -15985, -15963, -15940, -15917, -15893, -15868, -15842,
	-15817, -15790, -15763, -15735, -15707, -15678, -15649, -15618, -15588, -15557, -15525, -15492, -15459,
	-15426, -15392, -15357, -15322, -15286, -15249, -15212, -15175, -15136, -15098, -15058, -15018, -14978,
	-14937, -14895, -14853, -14811, -14767, -14723, -14679, -14634, -14589, -14543, -14496, -14449, -14401,
	-14353, -14304, -14255, -14205, -14155, -14104, -14053, -14001, -13948, -13895, -13842, -13788, -13733,
	-13678, -13622, -13566, -13510, -13452, -13395, -13337, -13278, -13219, -13159, -13099, -13039, -12977,
	-12916, -12854, -12791, -12728, -12665, -12601, -12536, -12471, -12406, -12340, -12273, -12207, -12139,
	-12072, -12003, -11935, -11866, -11796, -11726, -11656, -11585, -11513, -11442, -11370, -11297, -11224,
	-11151, -11077, -11003, -10928, -10853, -10777, -10701, -10625, -10548, -10471, -10394, -10316, -10237,
	-10159, -10080, -10000, -9920, -9840, -9760, -9679, -9597, -9516, -9434, -9351, -9269, -9186, -9102,
	-9018, -8934, -8850, -8765, -8680, -8595, -8509, -8423, -8336, -8250, -8163, -8075, -7988, -7900, -7812,
	-7723, -7634, -7545, -7456, -7366, -7276, -7186, -7096, -7005, -6914, -6822, -6731, -6639, -6547, -6455,
	-6362, -6270, -6176, -6083, -5990, -5896, -5802, -5708, -5614, -5519, -5424, -5329, -5234, -5139, -5043,
	-4948, -4852, -4756, -4659, -4563, -4466, -4369, -4273, -4175, -4078, -3981, -3883, -3785, -3687, -3589,
	-3491, -3393, -3295, -3196, -3097, -2998, -2900, -2801, -2702, -2602, -2503, -2404, -2304, -2205, -2105,
	-2005, -1905, -1806, -1706, -1606, -1505, -1405, -1305, -1205, -1105, -1004, -904, -804, -703, -603, -502,
	-402, -301, -201, -100, 100, 201, 301, 402, 502, 603, 703, 804, 904, 1004, 1105, 1205, 1305, 1405, 1505,
	1606, 1706, 1806, 1905, 2005, 2105, 2205, 2304, 2404, 2503, 2602, 2702, 2801, 2900, 2998, 3097, 3196,
	3295, 3393, 3491, 3589, 3687, 3785, 3883, 3981, 4078, 4175, 4273, 4369, 4466, 4563, 4659, 4756, 4852,
	4948, 5043, 5139, 5234, 5329, 5424, 5519, 5614, 5708, 5802, 5896, 5990, 6083, 6176, 6270, 6362, 6455,
	6547, 6639, 6731, 6822, 6914, 7005, 7096, 7186, 7276, 7366, 7456, 7545, 7634, 7723, 7812, 7900, 7988,
	8075, 8163, 8250, 8336, 8423, 8509, 8595, 8680, 8765, 8850, 8934, 9018, 9102, 9186, 9269, 9351, 9434,
	9516, 9597, 9679, 9760, 9840, 9920, 10000, 10080, 10159, 10237, 10316, 10394, 10471, 10548, 10625, 10701,
	10777, 10853, 10928, 11003, 11077, 11151, 11224, 11297, 11370, 11442, 11513, 11585, 11656, 11726, 11796,
	11866, 11935, 12003, 12072, 12139, 12207, 12273, 12340, 12406, 12471, 12536, 12601, 12665, 12728, 12791,
	12854, 12916, 12977, 13039, 13099, 13159, 13219, 13278, 13337, 13395, 13452, 13510, 13566, 13622, 13678,
	13733, 13788, 13842, 13895, 13948, 14001, 14053, 14104, 14155, 14205, 14255, 14304, 14353, 14401, 14449,
	14496, 14543, 14589, 14634, 14679, 14723, 14767, 14811, 14853, 14895, 14937, 14978, 15018, 15058, 15098,
	15136, 15175, 15212, 15249, 15286, 15322, 15357, 15392, 15426, 15459, 15492, 15525, 15557, 15588, 15618,
	15649, 15678, 15707, 15735, 15763, 15790, 15817, 15842, 15868, 15893, 15917, 15940, 15963, 15985, 16007,
	16028, 16049, 16069, 16088, 16107, 16125, 16142, 16159, 16175, 16191, 16206, 16221, 16234, 16248, 16260,
	16272, 16284, 16294, 16305, 16314, 16323, 16331, 16339, 16346, 16353, 16359, 16364, 16368, 16372, 16376,
	16379, 16381, 16382, 16383, 16384 };