Exemplo n.º 1
0
        public ComputeImage3D(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, int width, int height, int depth, long rowPitch, long slicePitch, IntPtr data)
            : base(context, flags)
        {
            Handle = CL12.CreateImage3D(context.Handle, flags, ref format, new IntPtr(width), new IntPtr(height), new IntPtr(depth), new IntPtr(rowPitch), new IntPtr(slicePitch), data, out var error);
            ComputeException.ThrowOnError(error);

            Init();
        }
        /// <summary>
        /// Creates a new <see cref="ComputeImage3D"/>.
        /// </summary>
        /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage3D"/> is created. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage3D"/>. </param>
        /// <param name="format"> A structure that describes the format properties of the <see cref="ComputeImage3D"/>. </param>
        /// <param name="width"> The width of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="height"> The height of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="depth"> The depth of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="rowPitch"> The size in bytes of each row of elements of the <see cref="ComputeImage3D"/>. If <paramref name="rowPitch"/> is zero, OpenCL will compute the proper value based on <see cref="ComputeImage.Width"/> and <see cref="ComputeImage.ElementSize"/>. </param>
        /// <param name="slicePitch"> The size in bytes of each 2D slice in the <see cref="ComputeImage3D"/>. If <paramref name="slicePitch"/> is zero, OpenCL will compute the proper value based on <see cref="ComputeImage.RowPitch"/> and <see cref="ComputeImage.Height"/>. </param>
        /// <param name="data"> The data to initialize the <see cref="ComputeImage3D"/>. Can be <c>IntPtr.Zero</c>. </param>
        public ComputeImage3D(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, int width, int height, int depth, long rowPitch, long slicePitch, IntPtr data)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            Handle = CL10.CreateImage3D(context.Handle, flags, ref format, new IntPtr(width), new IntPtr(height), new IntPtr(depth), new IntPtr(rowPitch), new IntPtr(slicePitch), data, out error);
            ComputeException.ThrowOnError(error);

            Init();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new <see cref="ComputeImage"/>.
        /// </summary>
        /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage"/> is created. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage"/>. </param>
        /// <param name="format"> A structure that describes the format properties of the <see cref="ComputeImage"/>. </param>
        /// <param name="imageDescription"> A structure that describes the <see cref="ComputeImage"/>. </param>
        /// <param name="data"> The data to initialize the <see cref="ComputeImage"/>. Can be <c>IntPtr.Zero</c>. </param>
        public ComputeImage(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, ComputeImageDescription imageDescription, IntPtr data)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            Handle = CLInterface.CL12.CreateImage(context.Handle, flags, ref format, ref imageDescription, data, out error);
            ComputeException.ThrowOnError(error);

            Init();
        }
Exemplo n.º 4
0
        /*
         * ///<summary>
         * /// Creates a new <see cref="ComputeImage2D"/> from a <c>Bitmap</c>.
         * ///</summary>
         * ///<para name = "context"> A valid <see cref = "ComputeContext"/> in which the <see cref = "ComputeImage 2 D"/> is created. </param>
         * ///<para name = "flags"> A bit-field that is used to specify allocation and usage information about the <see cref = "ComputeImage 2 D"/>. </param>
         * /// <param name="bitmap"> The bitmap to use. </param>
         * /// <remarks> Note that only bitmaps with <c>Format32bppArgb</c> pixel format are currently supported. </remarks>
         * public ComputeImage2D(ComputeContext context, ComputeMemoryFlags flags, Bitmap bitmap)
         *  :base(context, flags)
         * {
         *  unsafe
         *  {
         *      if(bitmap.PixelFormat != PixelFormat.Format32bppArgb)
         *          throw new ArgumentException("Pixel format not supported.");
         *
         *      //ComputeImageFormat format = Tools.ConvertImageFormat(bitmap.PixelFormat);
         *      ComputeImageFormat format = new ComputeImageFormat(ComputeImageChannelOrder.Bgra, ComputeImageChannelType.UnsignedInt8);
         *      BitmapData bitmapData = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat);
         *
         *      try
         *      {
         *          ComputeErrorCode error = ComputeErrorCode.Success;
         *          Handle = CL12.CreateImage2D(
         *              context.Handle,
         *              flags,
         *              &format,
         *              new IntPtr(bitmap.Width),
         *              new IntPtr(bitmap.Height),
         *              new IntPtr(bitmapData.Stride),
         *              bitmapData.Scan0,
         *              &error);
         *          ComputeException.ThrowOnError(error);
         *      }
         *      finally
         *      {
         *          bitmap.UnlockBits(bitmapData);
         *      }
         *
         *      Init();
         *  }
         * }*/

        ///<summary>
        ///Creates a new <see cref = "ComputeImage 2 D"/>.
        ///</summary>
        ///<para name = "context"> A valid <see cref = "ComputeContext"/> in which the <see cref = "ComputeImage 2 D"/> is created. </param>
        ///<para name = "flags"> A bit-field that is used to specify allocation and usage information about the <see cref = "ComputeImage 2 D"/>. </param>
        ///<param name = "format"> A structure that describes the format properties of the <see cref = "ComputeImage 2 D"/>. </param>
        ///<param name = "width"> The width of the <see cref = "ComputeImage 2 D"/> in pixels. </param>
        ///<param name = "height"> The height of the <see cref = "ComputeImage 2 D"/> in pixels. </param>
        ///<para name = "rowPitch">> ​​The size in bytes of each row of elements of the <see cref = "ComputeImage2D"/>. If <paramref name = "rowPitch"/> is zero, OpenCL will compute the proper value based on   <see cref = "ComputeImage.Width"/> and <see cref = "ComputeImage.ElementSize"/>. </param>
        ///<param name = "data"> The data to initialize the <see cref = "ComputeImage 2 D"/>. Can be <c> IntPtr.Zero </c>. </param>
        public ComputeImage2D(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, int width, int height, long rowPitch, IntPtr data)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;

            Handle = CL12.CreateImage2D(context.Handle, flags, ref format, new IntPtr(width), new IntPtr(height), new IntPtr(rowPitch), data, out error);
            ComputeException.ThrowOnError(error);

            Init();
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="flags"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected static ICollection <ComputeImageFormat> GetSupportedFormats(ComputeContext context, ComputeMemoryFlags flags, ComputeMemoryType type)
        {
            ComputeErrorCode error = CL12.GetSupportedImageFormats(context.Handle, flags, type, 0, null, out var formatCountRet);

            ComputeException.ThrowOnError(error);

            ComputeImageFormat[] formats = new ComputeImageFormat[formatCountRet];
            error = CL12.GetSupportedImageFormats(context.Handle, flags, type, formatCountRet, formats, out formatCountRet);
            ComputeException.ThrowOnError(error);

            return(new Collection <ComputeImageFormat>(formats));
        }
 /// <summary>
 /// Converts a compute image format to cloo image format
 /// </summary>
 /// <param name="imageFormat">compute image format</param>
 /// <returns>cloo image format</returns>
 /// <exception cref="NotSupportedException">Specified image format is not supported by OpenClooVision</exception>
 public static ClooImageFormat ToClooImageFormat(ComputeImageFormat imageFormat)
 {
     switch (imageFormat.ChannelType)
     {
         case ComputeImageChannelType.Float:
             {
                 if (imageFormat.ChannelOrder == ComputeImageChannelOrder.A) return ClooImageFormat.FloatA;
                 if (imageFormat.ChannelOrder == ComputeImageChannelOrder.Rgba) return ClooImageFormat.FloatRgbA;
                 break;
             }
         case ComputeImageChannelType.UnsignedInt8:
             {
                 if (imageFormat.ChannelOrder == ComputeImageChannelOrder.A) return ClooImageFormat.ByteA;
                 if (imageFormat.ChannelOrder == ComputeImageChannelOrder.Rgba) return ClooImageFormat.ByteRgbA;
                 break;
             }
         case ComputeImageChannelType.UnsignedInt32:
             {
                 if (imageFormat.ChannelOrder == ComputeImageChannelOrder.A) return ClooImageFormat.UIntA;
                 break;
             }
     }
     throw new NotSupportedException("Specified image format is not supported by OpenClooVision");
 }
Exemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="flags"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected static ICollection<ComputeImageFormat> GetSupportedFormats(ComputeContext context, ComputeMemoryFlags flags, ComputeMemoryType type)
        {
            int formatCountRet = 0;
            ComputeErrorCode error = CL12.GetSupportedImageFormats(context.Handle, flags, type, 0, null, out formatCountRet);
            ComputeException.ThrowOnError(error);

            ComputeImageFormat[] formats = new ComputeImageFormat[formatCountRet];
            error = CL12.GetSupportedImageFormats(context.Handle, flags, type, formatCountRet, formats, out formatCountRet);
            ComputeException.ThrowOnError(error);

            return new Collection<ComputeImageFormat>(formats);
        }
Exemplo n.º 8
0
        protected static ICollection<ComputeImageFormat> GetSupportedFormats(ComputeContext context, ComputeMemoryFlags flags, ComputeMemoryType type)
        {
            unsafe
            {
                int formatCountRet = 0;
                ComputeErrorCode error = CL10.GetSupportedImageFormats(context.Handle, flags, type, 0, null, &formatCountRet);
                ComputeException.ThrowOnError(error);

                ComputeImageFormat[] formats = new ComputeImageFormat[formatCountRet];
                fixed (ComputeImageFormat* formatsPtr = formats)
                {
                    error = CL10.GetSupportedImageFormats(context.Handle, flags, type, formatCountRet, formatsPtr, null);
                    ComputeException.ThrowOnError(error);
                }

                return new Collection<ComputeImageFormat>(formats);
            }
        }
Exemplo n.º 9
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));
                }