Exemplo n.º 1
0
        public static void Run(TextWriter log, ComputeContext context)
        {
            StartTest(log, "Image test");

            try
            {
                log.Write("Creating command queue... ");
                ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
                log.WriteLine("done.");

                int width = 16;
                int height = 16;

                log.Write("Creating first bitmap and drawing shapes... ");
                Bitmap firstBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                Graphics graphics = Graphics.FromImage(firstBitmap);
                graphics.FillEllipse(Brushes.Red, 0, 0, width / 2, height / 2);
                graphics.FillRectangle(Brushes.Green, width / 2 + 1, 0, width / 2, height / 2);
                graphics.FillRectangle(Brushes.Blue, width / 2 + 1, height / 2 + 1, width / 2, height / 2);
                log.WriteLine("done.");

                log.Write("Creating OpenCL image object from first bitmap... ");
                ComputeImage2D clImage = new ComputeImage2D(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, firstBitmap);
                log.WriteLine("done.");

                log.Write("Creating second bitmap... ");
                Bitmap secondBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                BitmapData bmpData = secondBitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, secondBitmap.PixelFormat);
                log.WriteLine("done.");

                log.Write("Reading from OpenCL image object... ");
                commands.ReadFromImage(clImage, bmpData.Scan0, true, null);
                log.WriteLine("done.");

                secondBitmap.UnlockBits(bmpData);

                log.Write("Comparing bitmaps... ");
                for (int i = 0; i < width; i++)
                    for (int j = 0; j < height; j++)
                        if (firstBitmap.GetPixel(i, j) != secondBitmap.GetPixel(i, j))
                            throw new Exception("Image data mismatch!");
                log.WriteLine("passed.");
            }
            catch (Exception e)
            {
                log.WriteLine(e.ToString());
            }

            EndTest(log, "Image test");
        }
Exemplo n.º 2
0
                /// <summary>Unsafe allocation of memory</summary>
                /// <param name="p">Pointer to data</param>
                /// <param name="DataType">Data type: float, uint8 (byte), int32, etc.</param>
                private unsafe void CLMalloc(void* p, ComputeImageChannelType DataType)
                {
                    ComputeImageFormat format = new ComputeImageFormat(ComputeImageChannelOrder.Rgba, DataType);

                    if (OriginalVarLength != 4 * width * height) throw new Exception("Vector length should be 4*width*height");

                    VarPointer = new ComputeImage2D(Program.Context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, format, width, height, 0, new IntPtr(p));
                }
Exemplo n.º 3
0
        private void createSharedTexture()
        {
            // create a texture to render to.
            _renderTextureID = createBlankTexture(ClientBounds);

            // Create OpenCL image for kernel to write to
            _renderTarget = ComputeImage2D.CreateFromGLTexture2D(_commandQueue.Context, ComputeMemoryFlags.ReadWrite, (int)TextureTarget.Texture2D, 0, _renderTextureID);
            _sharedObjects.Add(_renderTarget);
        }