Ejemplo n.º 1
0
        protected override void OnPostExecute(out ErrorCode error, params object[] args)
        {
            ClImage2D destination = (ClImage2D)args[1];

            byte[] outputData = new byte[destination.Size];
            EnqueueReadImage(destination.GetClMem, outputData, out error);
            if (error != ErrorCode.Success)
            {
                return;
            }

            destination.WriteToOriginalBitmap(outputData);
        }
Ejemplo n.º 2
0
        public String GenerateUnicode(Bitmap source, String spacingChar)
        {
            //Check status
            if (IsErrorOccurred())
            {
                return(String.Empty);
            }

            //Create Cl memory
            ClImage2D        srcMem             = new ClImage2D(source, context, IOMode.ReadOnly, ChannelType.RGBA32bpp, out error);
            int              totalUnicodeLength = (srcMem.Width / 2 + 2) * (srcMem.Height / 4);
            ClBuffer <short> dstMem             = new ClBuffer <short>(context, totalUnicodeLength, out error);

            //Check error
            if (!srcMem.Ready || !dstMem.Ready || IsErrorOccurred())
            {
                srcMem.Dispose();
                dstMem.Dispose();
                return(String.Empty);
            }

            //Run kernel
            kernelGenerateUnicode.ExecuteKernel(out error, new object[] { srcMem, dstMem });
            if (IsErrorOccurred())
            {
                return(String.Empty);
            }

            //Marshaling unicode data.
            IntPtr stream = Marshal.AllocHGlobal(totalUnicodeLength * 2);

            Marshal.Copy(dstMem.GetBuffer(), 0, stream, totalUnicodeLength);
            string result = Marshal.PtrToStringUni(stream, totalUnicodeLength);

            //Replace spacing char
            result = result.Replace(((char)0x2800).ToString(), spacingChar);

            //Clean up
            srcMem.Dispose();
            dstMem.Dispose();

            return(result);
        }
Ejemplo n.º 3
0
        private void ImgToImgKernel(ClKernel kernel, Bitmap source, Bitmap destination, params object[] extra)
        {
            //Check status
            if (error != ErrorCode.Success)
            {
                return;
            }

            //Create Cl memory
            ClImage2D srcMem = new ClImage2D(source, context, IOMode.ReadOnly, ChannelType.RGBA32bpp, out error);
            ClImage2D dstMem = new ClImage2D(destination, context, IOMode.WriteOnly, ChannelType.RGBA32bpp, out error);

            //Check error
            if (!srcMem.Ready || !dstMem.Ready || IsErrorOccurred())
            {
                srcMem.Dispose();
                dstMem.Dispose();
                if (error != ErrorCode.Success)
                {
                    return;
                }
            }

            //Create argument list
            object[] argList = new object[2 + extra.Length];
            argList[0] = srcMem;
            argList[1] = dstMem;
            extra.CopyTo(argList, 2);

            //Run kernel
            kernel.ExecuteKernel(out error, argList);
            if (error != ErrorCode.Success)
            {
                return;
            }

            //Clean up
            srcMem.Dispose();
            dstMem.Dispose();
        }