Beispiel #1
0
        private void ToLabPixels(Bitmap image)
        {
            PixelTypeInfo pixelInfo = PixelInfo.GetPixelTypeInfo(image);

            if (pixelInfo.GetBytesForColor(RGBAColor.RGB) != 1)
            {
                throw new Exception("Pixeltype is not supported.");
            }
            Rectangle  imageSize          = new Rectangle(0, 0, image.Width, image.Height);
            BitmapData originalBitmapData = image.LockBits(imageSize, ImageLockMode.ReadOnly, image.PixelFormat);

            unsafe
            {
                byte *rowPtr = (byte *)originalBitmapData.Scan0;
                int   index  = 0;

                for (int y = 0; y < originalBitmapData.Height; y++)
                {
                    byte *pixelPtr = rowPtr;

                    for (int x = 0; x < originalBitmapData.Width; x++)
                    {
                        RGBPixels[index + 0] = pixelPtr[(int)RGBAColor.Red];
                        RGBPixels[index + 1] = pixelPtr[(int)RGBAColor.Green];
                        RGBPixels[index + 2] = pixelPtr[(int)RGBAColor.Blue];

                        index    += 3;
                        pixelPtr += 3;
                    }

                    rowPtr += originalBitmapData.Stride;
                }
            }
            image.UnlockBits(originalBitmapData);

            if (UseGaussBlur)
            {
                gpuAccel.Invoke("GaussianBlur", 0, ImageWidth * ImageHeight, RGBPixels, GaussedRGBPixels, ImageWidth, ImageHeight);
                var t = RGBPixels;
                RGBPixels        = GaussedRGBPixels;
                GaussedRGBPixels = t;
            }
            gpuAccel.Invoke("RGBToLab", 0, LabPixels.Length / 3, RGBPixels, LabPixels, 255f);
            gpuAccel.Invoke("LabDistances", 0, ImageWidth * ImageHeight, LabPixels, LabDistances, ImageWidth, ImageHeight, MaxColorDistanceForMatch);
            if (UseNoiseRemoval)
            {
                gpuAccel.Invoke("RemoveNoise", 0, ImageWidth * ImageHeight, LabDistances, ImageWidth, ImageHeight);
            }
        }
Beispiel #2
0
        static void Run(string[] args)
        {
            int[]  Primes = Enumerable.Range(2, 1000000).ToArray();
            EasyCL cl     = new EasyCL();

            cl.Accelerator = Accelerator.Gpu;               //You can also set the accelerator after loading the kernel
            cl.LoadKernel(IsPrime);                         //Load kernel string here, (Compiles in the background)
            cl.Invoke("GetIfPrime", Primes.Length, Primes); //Call Function By Name With Parameters
                                                            //Primes now contains all Prime Numbers
        }
Beispiel #3
0
        void RunCPU(int[] WorkSet)
        {
            base.WriteMessage("\nRun on CPU: " + AcceleratorDevice.CPU.ToString());
            EasyCL cl = new EasyCL()
            {
                Accelerator = AcceleratorDevice.CPU
            };

            cl.LoadKernel(IsPrime);
            cl.Invoke("GetIfPrime", 0, 1, WorkSet);    //OpenCL uses a Cache. Real speed after that
            Stopwatch time = Stopwatch.StartNew();

            cl.Invoke("GetIfPrime", 0, WorkSet.Length, WorkSet);

            time.Stop();
            double performance = WorkSet.Length / (1000000.0 * time.Elapsed.TotalSeconds);

            base.WriteMessage("\t" + performance.ToString("0.00") + " MegaPrimes/Sec");
        }