Пример #1
0
        private ComputeImage2D CreateImageFromBitmap(string file, ComputeContext ctx, ComputeMemoryFlags flags)
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException();
            }

            unsafe
            {
                var bitmap = new Bitmap(file);
                if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
                {
                    throw new ArgumentException("Pixel format not supported.");
                }

                //ComputeImageFormat format = Tools.ConvertImageFormat(bitmap.PixelFormat);
                ComputeImageFormat format     = new ComputeImageFormat(ComputeImageChannelOrder.Rgba, ComputeImageChannelType.UnsignedInt8);
                BitmapData         bitmapData = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.ReadWrite, bitmap.PixelFormat);
                ComputeImage2D     image;
                try
                {
                    image = new ComputeImage2D(ctx, flags, format, bitmapData.Width, bitmapData.Height,
                                               bitmapData.Stride, bitmapData.Scan0);
                    dstBytes = new char[bitmapData.Width * bitmapData.Height * 4];
                }
                finally
                {
                    bitmap.UnlockBits(bitmapData);
                }
                return(image);
            }
        }
Пример #2
0
 public extern static CLMemoryHandle CreateImage2D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_row_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret);
 public ManagedComputeImage2D(
     ComputeContext context,
     ComputeMemoryFlags flags,
     ComputeImageFormat format,
     int width,
     int height,
     long rowPitch,
     IntPtr data)
     : base(context, flags, format, width, height, rowPitch, data)
 {
 }
Пример #4
0
 public new static CLMemoryHandle CreateImage2D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_row_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret)
 {
     Trace.WriteLine("WARNING! clCreateImage2D has been deprecated in OpenCL 1.2.");
     return(CL11.CreateImage2D(context, flags, ref image_format, image_width, image_height, image_row_pitch, host_ptr, out errcode_ret));
 }
Пример #5
0
 public new static CLMemoryHandle CreateImage3D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_depth,
     IntPtr image_row_pitch,
     IntPtr image_slice_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret)
 {
     RILogManager.Default?.SendTrace("WARNING! clCreateImage3D has been deprecated in OpenCL 1.2.");
     return(CL11.CreateImage3D(context, flags, ref image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, out errcode_ret));
 }
Пример #6
0
        private void InitializeImageFieds()
        {
            int ImageVectorSizeInFloats = Width * Height * 4;

            CurrImageVector = new float[ImageVectorSizeInFloats];
            NextImageVector = new float[ImageVectorSizeInFloats];

            unsafe
            {
                fixed(float *imgPtr = CurrImageVector)
                {
                    ComputeImageFormat format = new ComputeImageFormat(ComputeImageChannelOrder.Rgba, ComputeImageChannelType.Float);

                    CurrImage = new ComputeImage2D(Ctx, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, format, Width, Height, Width * 4 * sizeof(float), (IntPtr)imgPtr);
                    NextImage = new ComputeImage2D(Ctx, ComputeMemoryFlags.ReadWrite, format, Width, Height, 0, IntPtr.Zero);
                }
            }
        }
Пример #7
0
 CLMemoryHandle ICL10.CreateImage3D(CLContextHandle context, ComputeMemoryFlags flags, ref ComputeImageFormat image_format,
                                    IntPtr image_width, IntPtr image_height, IntPtr image_depth, IntPtr image_row_pitch,
                                    IntPtr image_slice_pitch, IntPtr host_ptr, out ComputeErrorCode errcode_ret)
 {
     return CreateImage3D(context, flags, ref image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, out errcode_ret);
 }
Пример #8
0
 public static extern CLMemoryHandle CreateImage3D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_depth,
     IntPtr image_row_pitch,
     IntPtr image_slice_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret);
Пример #9
0
 public CLMemoryHandle CreateImage2D(CLContextHandle context, ComputeMemoryFlags flags, ref ComputeImageFormat image_format, IntPtr image_width, IntPtr image_height, IntPtr image_row_pitch, IntPtr host_ptr, out ComputeErrorCode errcode_ret)
 {
     return StaticCreateImage2D(context, flags,ref image_format, image_width, image_height, image_row_pitch, host_ptr, out errcode_ret);
 }
Пример #10
0
 public CLMemoryHandle CreateImage(CLContextHandle context, ComputeMemoryFlags flags, ref ComputeImageFormat image_format, ref ComputeImageDescription image_desc, IntPtr host_ptr, out ComputeErrorCode errcode_ret)
 {
     throw new NotImplementedException();
 }
Пример #11
0
 public static extern CLMemoryHandle StaticCreateImage(CLContextHandle context, ComputeMemoryFlags flags, ref ComputeImageFormat image_format, ref ComputeImageDescription image_desc, IntPtr host_ptr, out ComputeErrorCode errcode_ret);
Пример #12
0
 new CLMemoryHandle CreateImage3D(CLContextHandle context, ComputeMemoryFlags flags, ref ComputeImageFormat image_format, IntPtr image_width, IntPtr image_height, IntPtr image_depth, IntPtr image_row_pitch, IntPtr image_slice_pitch, IntPtr host_ptr, out ComputeErrorCode errcode_ret)
 {
     Trace.WriteLine("WARNING! CreateImage3D has been deprecated in OpenCL 1.2.");
     return CL11.StaticCreateImage3D(context, flags, ref image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, out errcode_ret);
 }
Пример #13
0
 public static unsafe extern ComputeErrorCode GetSupportedImageFormats(
     IntPtr context,
     ComputeMemoryFlags flags,
     ComputeMemoryType image_type,
     Int32 num_entries,
     ComputeImageFormat* image_formats,
     Int32* num_image_formats);
Пример #14
0
 public static unsafe extern IntPtr CreateImage3D(
     IntPtr context,
     ComputeMemoryFlags flags,
     ComputeImageFormat* image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_depth,
     IntPtr image_row_pitch,
     IntPtr image_slice_pitch,
     /* void* */ IntPtr host_ptr,
     ComputeErrorCode* errcode_ret);
Пример #15
0
        public static void CLApply2DLUT(ComputeContext context)
        {
            ComputeImageFormat format = new ComputeImageFormat(ComputeImageChannelOrder.Bgra, ComputeImageChannelType.UnsignedInt8);
            var startTime             = LLTools.TimestampMS();

            #region Visible / Temporary Source
            BitmapData     bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
            ComputeImage2D source0    = new ComputeImage2D(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, format, bmp.Width, bmp.Height, bitmapData.Stride, bitmapData.Scan0);
            bmp.UnlockBits(bitmapData);
            #endregion
            #region Infrared Source
            bitmapData = irBmp.LockBits(new Rectangle(0, 0, irBmp.Width, irBmp.Height), ImageLockMode.ReadOnly, irBmp.PixelFormat);
            ComputeImage2D source1 = new ComputeImage2D(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, format, irBmp.Width, irBmp.Height, bitmapData.Stride, bitmapData.Scan0);
            irBmp.UnlockBits(bitmapData);
            #endregion
            #region Output
            ComputeImage2D output = new ComputeImage2D(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.AllocateHostPointer, format, bmp.Width, bmp.Height, 0, IntPtr.Zero);
            #endregion
            #region Variable Initialization
            ComputeEventList    eventList = new ComputeEventList();
            ComputeCommandQueue commands  = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);
            #region Apply Curve
            applyCurveKernel.SetMemoryArgument(0, source0);
            applyCurveKernel.SetMemoryArgument(1, output);
            applyCurveKernel.SetMemoryArgument(2, curveLutBuffer);
            #endregion
            #region Apply LUT 2D
            apply2DLUTKernel.SetMemoryArgument(0, source1);
            apply2DLUTKernel.SetMemoryArgument(1, output);
            apply2DLUTKernel.SetMemoryArgument(2, source0);
            apply2DLUTKernel.SetMemoryArgument(3, lut2DBuffer);
            #endregion
            #region Reprojection
            var latRangeBuff = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, latRange);
            var lonRangeBuff = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, lonRange);
            var coverageBuff = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, coverage);
            var trimBuff     = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, trim);
            var sizeBuff     = new ComputeBuffer <uint>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, size);
            reprojectKernel.SetMemoryArgument(0, source0);
            reprojectKernel.SetMemoryArgument(1, output);
            reprojectKernel.SetValueArgument(2, satelliteLongitude);
            reprojectKernel.SetValueArgument(3, coff);
            reprojectKernel.SetValueArgument(4, cfac);
            reprojectKernel.SetValueArgument(5, loff);
            reprojectKernel.SetValueArgument(6, lfac);
            reprojectKernel.SetValueArgument(7, (uint)(fixAspect ? 1 : 0));
            reprojectKernel.SetValueArgument(8, aspectRatio);
            reprojectKernel.SetMemoryArgument(9, latRangeBuff);
            reprojectKernel.SetMemoryArgument(10, lonRangeBuff);
            reprojectKernel.SetMemoryArgument(11, coverageBuff);
            reprojectKernel.SetMemoryArgument(12, trimBuff);
            reprojectKernel.SetMemoryArgument(13, sizeBuff);
            #endregion
            #endregion
            #region Run Pipeline
            UIConsole.Log("Executing curve kernel");
            commands.Execute(applyCurveKernel, null, new long[] { bmp.Width, bmp.Height }, null, eventList);
            UIConsole.Log("Executing LUT2D kernel");
            commands.Execute(apply2DLUTKernel, null, new long[] { bmp.Width, bmp.Height }, null, eventList);
            UIConsole.Log("Executing kernel");
            commands.Execute(reprojectKernel, null, new long[] { bmp.Width, bmp.Height }, null, eventList);
            #endregion
            #region Dump Bitmap
            UIConsole.Log("Dumping bitmap");
            Bitmap     obmp    = new Bitmap(bmp.Width, bmp.Height, bmp.PixelFormat);
            BitmapData bmpData = obmp.LockBits(new Rectangle(0, 0, obmp.Width, obmp.Height), ImageLockMode.ReadWrite, obmp.PixelFormat);
            commands.ReadFromImage(output, bmpData.Scan0, true, null);
            obmp.UnlockBits(bmpData);

            var delta = LLTools.TimestampMS() - startTime;
            UIConsole.Log($"Took {delta} ms to Apply Curve -> Apply Lut2D (FalseColor) -> Reproject");
            UIConsole.Log("Saving bitmap");
            obmp.Save("teste.png");
            UIConsole.Log("Done");
            bmp.Save("original.png");
            #endregion
        }
Пример #16
0
 ComputeErrorCode ICL10.GetSupportedImageFormats(CLContextHandle context, ComputeMemoryFlags flags,
                                                 ComputeMemoryType image_type, int num_entries,
                                                 ComputeImageFormat[] image_formats, out int num_image_formats)
 {
     return GetSupportedImageFormats(context, flags, image_type, num_entries, image_formats, out num_image_formats);
 }
Пример #17
0
 CLMemoryHandle ICL10.CreateImage3D(CLContextHandle context, ComputeMemoryFlags flags, ref ComputeImageFormat image_format,
                                    IntPtr image_width, IntPtr image_height, IntPtr image_depth, IntPtr image_row_pitch,
                                    IntPtr image_slice_pitch, IntPtr host_ptr, out ComputeErrorCode errcode_ret)
 {
     return(CreateImage3D(context, flags, ref image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, out errcode_ret));
 }