Example #1
0
        public void Test_Null_Argument()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>(0));

            DLLLoader loader = new DLLLoader();
            ICollection <IExcelProcess> plugins = loader.Load(null);

            Assert.AreEqual(0, plugins.Count);
        }
Example #2
0
        public void Test_Load_Assembly()
        {
            // Plugin stub
            string cwd             = Directory.GetCurrentDirectory();
            string stubs_directory = Path.Combine(cwd, "../stubs/");

            DLLLoader loader = new DLLLoader();
            ICollection <IExcelProcess> plugins = loader.Load(stubs_directory);

            Assert.AreEqual(1, plugins.Count);
        }
Example #3
0
        public void Test_Nothing_To_Load()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"c:\myfile.txt", new MockFileData("bogus!") },
            });

            DLLLoader loader = new DLLLoader(fileSystem);
            ICollection <IExcelProcess> plugins = loader.Load(@"C:\");

            Assert.AreEqual(0, plugins.Count);
        }
Example #4
0
    unsafe public static PhaseOutput ComputePhase(string dll)
    {
        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));

        if (File.Exists(file))
        {
            IntPtr pLibrary = DLLLoader.LoadLibrary(file);
            IntPtr pCompute = DLLLoader.GetProcAddress(pLibrary, "Compute");
            IntPtr pPhase   = DLLLoader.GetProcAddress(pLibrary, "Phase");
            IntPtr pRelease = DLLLoader.GetProcAddress(pLibrary, "Release");

            var Compute = DLLLoader.LoadFunction <FCompute>(pCompute);
            var Phase   = DLLLoader.LoadFunction <FPhase>(pPhase);
            var Release = DLLLoader.LoadFunction <FRelease>(pRelease);

            double *SpotsX;
            double *SpotsY;

            GetPoints(Spots, Width, Height, out SpotsX, out SpotsY);

            void **Parameters = stackalloc void *[6];

            var width  = Width;
            var height = Height;
            var nfft   = Math.Max(NFFT, Math.Max(Width, Height));
            var N      = Spots.Count;

            Parameters[0] = &width;
            Parameters[1] = &height;
            Parameters[2] = &nfft;
            Parameters[3] = &N;
            Parameters[4] = SpotsX;
            Parameters[5] = SpotsY;

            Compute(6, Parameters);

            var output = Phase();

            var phase = new PhaseOutput(output, width * height);

            // Free resources
            Release();

            DLLLoader.FreeLibrary(pLibrary);

            return(phase);
        }

        var length = Width * Height > 0 ? Width * Height : 256 * 256;

        return(new PhaseOutput(length));
    }
Example #5
0
    unsafe public static IntensityOutput ComputeIntensity(string dll)
    {
        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));

        if (File.Exists(file))
        {
            IntPtr pLibrary   = DLLLoader.LoadLibrary(file);
            IntPtr pCompute   = DLLLoader.GetProcAddress(pLibrary, "Compute");
            IntPtr pIntensity = DLLLoader.GetProcAddress(pLibrary, "Intensity");
            IntPtr pRelease   = DLLLoader.GetProcAddress(pLibrary, "Release");

            var Compute   = DLLLoader.LoadFunction <FCompute>(pCompute);
            var Intensity = DLLLoader.LoadFunction <FIntensity>(pIntensity);
            var Release   = DLLLoader.LoadFunction <FRelease>(pRelease);

            var target  = Common.PreparePixbuf(Target);
            var targetx = Target.Width;
            var targety = Target.Height;

            var z          = Z;
            var wavelength = Wavelength;
            var pitch      = Pitch;

            void **Parameters = stackalloc void *[6];

            Parameters[0] = target;
            Parameters[1] = &targetx;
            Parameters[2] = &targety;
            Parameters[3] = &z;
            Parameters[4] = &wavelength;
            Parameters[5] = &pitch;

            Compute(6, Parameters);

            var output = Intensity();

            var intensity = new IntensityOutput(output, targetx * targety);

            // Free resources
            Release();

            DLLLoader.FreeLibrary(pLibrary);

            return(intensity);
        }

        var length = Target != null ? Target.Width * Target.Height : 256 * 256;

        return(new IntensityOutput(length));
    }
Example #6
0
    unsafe public static string GetDescription(string dll)
    {
        IntPtr pLibrary = Common.OSTest.IsWindows() ? DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.dll", dll)) : (Common.OSTest.IsRunningOnMac() ? DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.dylib", dll)) : DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.so", dll)));

        IntPtr pDescription = DLLLoader.GetProcAddress(pLibrary, "Description");

        var Description = DLLLoader.LoadFunction <FDescription>(pDescription);

        var description = Common.OSTest.IsWindows() ? Marshal.PtrToStringAnsi((IntPtr)Description()) : Marshal.PtrToStringAuto((IntPtr)Description());

        DLLLoader.FreeLibrary(pLibrary);

        return(description);
    }
Example #7
0
    unsafe public static string GetName(string dll)
    {
        IntPtr pLibrary = Common.OSTest.IsWindows() ? DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.dll", dll)) : (Common.OSTest.IsRunningOnMac() ? DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.dylib", dll)) : DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.so", dll)));

        IntPtr pName = DLLLoader.GetProcAddress(pLibrary, "Name");

        var Name = DLLLoader.LoadFunction <FName>(pName);

        var name = Common.OSTest.IsWindows() ? Marshal.PtrToStringAnsi((IntPtr)Name()) : Marshal.PtrToStringAuto((IntPtr)Name());

        DLLLoader.FreeLibrary(pLibrary);

        return(name);
    }
Example #8
0
    unsafe public static Pixbuf ApplyFilter(string dll, Pixbuf input, int scale, bool threshold)
    {
        IntPtr pLibrary = Common.OSTest.IsWindows() ? DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.dll", dll)) : (Common.OSTest.IsRunningOnMac() ? DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.dylib", dll)) : DLLLoader.LoadLibrary(String.Format("./libpixel++{0}.so", dll)));

        IntPtr pSizeX     = DLLLoader.GetProcAddress(pLibrary, "SizeX");
        IntPtr pSizeY     = DLLLoader.GetProcAddress(pLibrary, "SizeY");
        IntPtr pThreshold = DLLLoader.GetProcAddress(pLibrary, "Threshold");
        IntPtr pApply     = DLLLoader.GetProcAddress(pLibrary, "Apply");
        IntPtr pImage     = DLLLoader.GetProcAddress(pLibrary, "Image");
        IntPtr pRelease   = DLLLoader.GetProcAddress(pLibrary, "Release");

        var SizeX     = DLLLoader.LoadFunction <FSizeX>(pSizeX);
        var SizeY     = DLLLoader.LoadFunction <FSizeY>(pSizeY);
        var Threshold = DLLLoader.LoadFunction <FThreshold>(pThreshold);
        var Apply     = DLLLoader.LoadFunction <FApply>(pApply);
        var Image     = DLLLoader.LoadFunction <FImage>(pImage);
        var Release   = DLLLoader.LoadFunction <FRelease>(pRelease);

        var target  = Common.PreparePixbuf(input);
        var targetx = input.Width;
        var targety = input.Height;

        int    sizex, sizey;
        byte * filtered;
        Pixbuf output;

        void **Parameters = stackalloc void *[4];

        Parameters[0] = target;
        Parameters[1] = &targetx;
        Parameters[2] = &targety;
        Parameters[3] = &scale;

        Apply(4, Parameters);

        filtered = Image();

        sizex = SizeX();
        sizey = SizeY();

        output = Common.InitializePixbuf(sizex, sizey);

        Common.Copy(output, filtered);

        Release();

        DLLLoader.FreeLibrary(pLibrary);

        return(output);
    }
Example #9
0
    unsafe public static PhaseOutput ComputePhase(string dll)
    {
        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));

        if (File.Exists(file))
        {
            IntPtr pLibrary = DLLLoader.LoadLibrary(file);
            IntPtr pCompute = DLLLoader.GetProcAddress(pLibrary, "Compute");
            IntPtr pPhase   = DLLLoader.GetProcAddress(pLibrary, "Phase");
            IntPtr pRelease = DLLLoader.GetProcAddress(pLibrary, "Release");

            var Compute = DLLLoader.LoadFunction <FCompute>(pCompute);
            var Phase   = DLLLoader.LoadFunction <FPhase>(pPhase);
            var Release = DLLLoader.LoadFunction <FRelease>(pRelease);

            void **Parameters = stackalloc void *[5];

            var width      = Width;
            var height     = Height;
            var z          = Z;
            var wavelength = Wavelength;
            var pitch      = Pitch;

            Parameters[0] = &width;
            Parameters[1] = &height;
            Parameters[2] = &z;
            Parameters[3] = &wavelength;
            Parameters[4] = &pitch;

            Compute(5, Parameters);

            var output = Phase();

            var phase = new PhaseOutput(output, width * height);

            // Free resources
            Release();

            DLLLoader.FreeLibrary(pLibrary);

            return(phase);
        }

        var length = Width * Height > 0 ? Width * Height : 256 * 256;

        return(new PhaseOutput(length));
    }
Example #10
0
    unsafe public static PhaseOutput ComputePhase(string dll)
    {
        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));

        if (File.Exists(file))
        {
            IntPtr pLibrary = DLLLoader.LoadLibrary(file);
            IntPtr pCompute = DLLLoader.GetProcAddress(pLibrary, "Compute");
            IntPtr pPhase   = DLLLoader.GetProcAddress(pLibrary, "Phase");
            IntPtr pRelease = DLLLoader.GetProcAddress(pLibrary, "Release");

            var Compute = DLLLoader.LoadFunction <FCompute>(pCompute);
            var Phase   = DLLLoader.LoadFunction <FPhase>(pPhase);
            var Release = DLLLoader.LoadFunction <FRelease>(pRelease);

            var target  = Common.PreparePixbuf(Target);
            var targetx = Target.Width;
            var targety = Target.Height;

            var iterations = Iterations;

            void **Parameters = stackalloc void *[4];

            Parameters[0] = target;
            Parameters[1] = &targetx;
            Parameters[2] = &targety;
            Parameters[3] = &iterations;

            Compute(4, Parameters);

            var output = Phase();

            var phase = new PhaseOutput(output, targetx * targety);

            // Free resources
            Release();

            DLLLoader.FreeLibrary(pLibrary);

            return(phase);
        }

        var length = Target != null ? Target.Width * Target.Height : 256 * 256;

        return(new PhaseOutput(length));
    }
Example #11
0
 static LLVMMethods()
 {
     DLLLoader.AddDefaultX86X64SearchPath();
 }