|
5 | 5 |
|
6 | 6 | public static class BlazedPhaseDLL |
7 | 7 | { |
8 | | - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
9 | | - unsafe delegate double* FPhase(); |
| 8 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 9 | + unsafe delegate double* FPhase(); |
10 | 10 |
|
11 | | - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
12 | | - delegate void FRelease(); |
| 11 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 12 | + delegate void FRelease(); |
13 | 13 |
|
14 | | - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
15 | | - unsafe delegate void FCompute(int argc, void** argv); |
| 14 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 15 | + unsafe delegate void FCompute(int argc, void** argv); |
16 | 16 |
|
17 | | - static int Width; |
18 | | - static int Height; |
19 | | - static double X; |
20 | | - static double Y; |
| 17 | + static int Width; |
| 18 | + static int Height; |
| 19 | + static double X; |
| 20 | + static double Y; |
21 | 21 |
|
22 | | - public static void SetParameters(int width, int height, double x, double y) |
23 | | - { |
24 | | - Width = width; |
25 | | - Height = height; |
26 | | - X = x; |
27 | | - Y = y; |
28 | | - } |
| 22 | + public static void SetParameters(int width, int height, double x, double y) |
| 23 | + { |
| 24 | + Width = width; |
| 25 | + Height = height; |
| 26 | + X = x; |
| 27 | + Y = y; |
| 28 | + } |
29 | 29 |
|
30 | | - unsafe public static PhaseOutput ComputePhase(string dll) |
31 | | - { |
32 | | - var file = Common.OSTest.IsWindows() ? String.Format("./libphase++{0}.dll", dll) : (Common.OSTest.IsRunningOnMac() ? String.Format("./libphase++{0}.dylib", dll) : String.Format("./libphase++{0}.so", dll)); |
| 30 | + unsafe public static PhaseOutput ComputePhase(string dll) |
| 31 | + { |
| 32 | + var file = Common.OSTest.IsWindows() ? String.Format("./libphase++{0}.dll", dll) : (Common.OSTest.IsRunningOnMac() ? String.Format("./libphase++{0}.dylib", dll) : String.Format("./libphase++{0}.so", dll)); |
33 | 33 |
|
34 | | - if (File.Exists(file)) |
35 | | - { |
36 | | - IntPtr pLibrary = DLLLoader.LoadLibrary(file); |
37 | | - IntPtr pCompute = DLLLoader.GetProcAddress(pLibrary, "Compute"); |
38 | | - IntPtr pPhase = DLLLoader.GetProcAddress(pLibrary, "Phase"); |
39 | | - IntPtr pRelease = DLLLoader.GetProcAddress(pLibrary, "Release"); |
| 34 | + if (File.Exists(file)) |
| 35 | + { |
| 36 | + IntPtr pLibrary = DLLLoader.LoadLibrary(file); |
| 37 | + IntPtr pCompute = DLLLoader.GetProcAddress(pLibrary, "Compute"); |
| 38 | + IntPtr pPhase = DLLLoader.GetProcAddress(pLibrary, "Phase"); |
| 39 | + IntPtr pRelease = DLLLoader.GetProcAddress(pLibrary, "Release"); |
40 | 40 |
|
41 | | - var Compute = DLLLoader.LoadFunction<FCompute>(pCompute); |
42 | | - var Phase = DLLLoader.LoadFunction<FPhase>(pPhase); |
43 | | - var Release = DLLLoader.LoadFunction<FRelease>(pRelease); |
| 41 | + var Compute = DLLLoader.LoadFunction<FCompute>(pCompute); |
| 42 | + var Phase = DLLLoader.LoadFunction<FPhase>(pPhase); |
| 43 | + var Release = DLLLoader.LoadFunction<FRelease>(pRelease); |
44 | 44 |
|
45 | | - void** Parameters = stackalloc void*[4]; |
| 45 | + void** Parameters = stackalloc void*[4]; |
46 | 46 |
|
47 | | - var width = Width; |
48 | | - var height = Height; |
49 | | - var x = X; |
50 | | - var y = Y; |
| 47 | + var width = Width; |
| 48 | + var height = Height; |
| 49 | + var x = X; |
| 50 | + var y = Y; |
51 | 51 |
|
52 | | - Parameters[0] = &width; |
53 | | - Parameters[1] = &height; |
54 | | - Parameters[2] = &x; |
55 | | - Parameters[3] = &y; |
| 52 | + Parameters[0] = &width; |
| 53 | + Parameters[1] = &height; |
| 54 | + Parameters[2] = &x; |
| 55 | + Parameters[3] = &y; |
56 | 56 |
|
57 | | - Compute(4, Parameters); |
| 57 | + Compute(4, Parameters); |
58 | 58 |
|
59 | | - var output = Phase(); |
| 59 | + var output = Phase(); |
60 | 60 |
|
61 | | - var phase = new PhaseOutput(output, width * height); |
| 61 | + var phase = new PhaseOutput(output, width * height); |
62 | 62 |
|
63 | | - // Free resources |
64 | | - Release(); |
| 63 | + // Free resources |
| 64 | + Release(); |
65 | 65 |
|
66 | | - DLLLoader.FreeLibrary(pLibrary); |
| 66 | + DLLLoader.FreeLibrary(pLibrary); |
67 | 67 |
|
68 | | - return phase; |
69 | | - } |
| 68 | + return phase; |
| 69 | + } |
70 | 70 |
|
71 | | - var length = Width * Height > 0 ? Width * Height : 256 * 256; |
| 71 | + var length = Width * Height > 0 ? Width * Height : 256 * 256; |
72 | 72 |
|
73 | | - return new PhaseOutput(length); |
74 | | - } |
| 73 | + return new PhaseOutput(length); |
| 74 | + } |
75 | 75 | } |
0 commit comments