Ejemplo n.º 1
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);
        }
        protected override void OnPostExecute(out ErrorCode error, params object[] args)
        {
            ClBuffer <short> destination = (ClBuffer <short>)args[1];

            EnqueueReadBuffer(destination.GetClMem, destination.GetBuffer(), out error);
        }