Ejemplo n.º 1
0
        /*
         * /// <summary>
         * /// Creates a new <see cref="ComputeImage2D"/> from a <c>Bitmap</c>.
         * /// </summary>
         * /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage2D"/> is created. </param>
         * /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage2D"/>. </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 = CL10.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="ComputeImage2D"/>.
        /// </summary>
        /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage2D"/> is created. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage2D"/>. </param>
        /// <param name="format"> A structure that describes the format properties of the <see cref="ComputeImage2D"/>. </param>
        /// <param name="width"> The width of the <see cref="ComputeImage2D"/> in pixels. </param>
        /// <param name="height"> The height of the <see cref="ComputeImage2D"/> in pixels. </param>
        /// <param 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="ComputeImage2D"/>. Can be <c>IntPtr.Zero</c>. </param>
        public ComputeImage2D(IComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, int width, int height, long rowPitch, IntPtr data)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;

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

            Init();
        }
Ejemplo n.º 2
0
        /*
         * /// <summary>
         * /// Creates a new <see cref="OpenCLImage2D"/> from a <c>Bitmap</c>.
         * /// </summary>
         * /// <param name="context"> A valid <see cref="OpenCLContext"/> in which the <see cref="OpenCLImage2D"/> is created. </param>
         * /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="OpenCLImage2D"/>. </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 OpenCLImage2D(OpenCLContext context, OpenCLMemoryFlags flags, Bitmap bitmap)
         *  :base(context, flags)
         * {
         *  unsafe
         *  {
         *      if(bitmap.PixelFormat != PixelFormat.Format32bppArgb)
         *          throw new ArgumentException("Pixel format not supported.");
         *
         *      //OpenCLImageFormat format = Tools.ConvertImageFormat(bitmap.PixelFormat);
         *      OpenCLImageFormat format = new OpenCLImageFormat(OpenCLImageChannelOrder.Bgra, OpenCLImageChannelType.UnsignedInt8);
         *      BitmapData bitmapData = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat);
         *
         *      try
         *      {
         *          OpenCLErrorCode error = OpenCLErrorCode.Success;
         *          Handle = CL10.CreateImage2D(
         *              context.Handle,
         *              flags,
         *              &format,
         *              new IntPtr(bitmap.Width),
         *              new IntPtr(bitmap.Height),
         *              new IntPtr(bitmapData.Stride),
         *              bitmapData.Scan0,
         *              &error);
         *          OpenCLException.ThrowOnError(error);
         *      }
         *      finally
         *      {
         *          bitmap.UnlockBits(bitmapData);
         *      }
         *
         *      Init();
         *  }
         * }*/

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

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

            Init();
        }