public CVPixelBufferAttributes (CVPixelFormatType pixelFormatType, Size size)
			 : this ()
		{
			PixelFormatType = pixelFormatType;
			Width = size.Width;
			Height = size.Height;
		}
Ejemplo n.º 2
0
        public CVPixelBuffer(int width, int height, CVPixelFormatType pixelFormatType, NSDictionary pixelBufferAttributes)
        {
            IntPtr pixelBufferOut = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (IntPtr)));
            CVReturn ret = CVPixelBufferCreate (IntPtr.Zero, (IntPtr) width, (IntPtr) height, pixelFormatType, pixelBufferAttributes.Handle, pixelBufferOut);

            if (ret != CVReturn.Success) {
                Marshal.FreeHGlobal (pixelBufferOut);
                throw new Exception ("CVPixelBufferCreate returned: " + ret);
            }

            this.handle = Marshal.ReadIntPtr (pixelBufferOut);
            Marshal.FreeHGlobal (pixelBufferOut);
        }
Ejemplo n.º 3
0
			/* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut);// __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

		public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
		{
			CVReturn status;
			return Create (width, height, pixelFormatType, data, bytesPerRow, pixelBufferAttributes, out status);
		}
Ejemplo n.º 4
0
 public CVPixelBuffer(nint width, nint height, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
     : this(width, height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
 {
 }
Ejemplo n.º 5
0
 public CVPixelBuffer(System.Drawing.Size size, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
     : this(size.Width, size.Height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
 {
 }
 public AVVideoSettings(CVPixelFormatType formatType)
 {
     PixelFormat = formatType;
 }
Ejemplo n.º 7
0
 public CVPixelBuffer(int width, int height, CVPixelFormatType pixelFormatType)
     : this(width, height, pixelFormatType, (NSDictionary)null)
 {
 }
Ejemplo n.º 8
0
            /* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut);             // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

        public static CVPixelBuffer Create(nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
        {
            CVReturn status;

            return(Create(width, height, pixelFormatType, planes, planeWidths, planeHeights, planeBytesPerRow, pixelBufferAttributes, out status));
        }
Ejemplo n.º 9
0
 extern static CVReturn CVPixelBufferCreate(
     /* CFAllocatorRef __nullable */ IntPtr allocator, /* size_t */ nint width, /* size_t */ nint height,
     /* OSType */ CVPixelFormatType pixelFormatType,
     /* CFDictionaryRef __nullable */ IntPtr pixelBufferAttributes,
     /* CVPixelBufferRef __nullable * __nonnull */ out IntPtr pixelBufferOut);
Ejemplo n.º 10
0
		public CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormat)
			: this (width, height, pixelFormat, (NSDictionary) null)
		{
		}
Ejemplo n.º 11
0
		public CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
			: this (width, height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
		{
		}
Ejemplo n.º 12
0
		public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status)
		{
			IntPtr handle;
			IntPtr[] addresses;
			PlaneData data;
			GCHandle data_handle;

			if (planes == null)
				throw new ArgumentNullException (nameof (planes));

			if (planeWidths == null)
				throw new ArgumentNullException (nameof (planeWidths));

			if (planeHeights == null)
				throw new ArgumentNullException (nameof (planeHeights));

			if (planeBytesPerRow == null)
				throw new ArgumentNullException (nameof (planeBytesPerRow));

			var planeCount = planes.Length;

			if (planeWidths.Length != planeCount)
				throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeWidths does not match the number of planes");
			
			if (planeHeights.Length != planeCount)
				throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeHeights does not match the number of planes");

			if (planeBytesPerRow.Length != planeCount)
				throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeBytesPerRow does not match the number of planes");

			addresses = new IntPtr [planeCount];
			data = new PlaneData ();
			data.dataHandles = new GCHandle [planeCount];
			for (int i = 0; i < planeCount; i++) {
				data.dataHandles[i] = GCHandle.Alloc (planes [i], GCHandleType.Pinned);
				addresses[i] = data.dataHandles[i].AddrOfPinnedObject ();
			}
			data_handle = GCHandle.Alloc (data);

			status = CVPixelBufferCreateWithPlanarBytes (IntPtr.Zero, 
			                                             width, height, pixelFormatType, IntPtr.Zero, 0, 
			                                             planeCount, addresses, planeWidths, planeHeights, planeBytesPerRow, 
			                                             releasePlanarBytesCallback, GCHandle.ToIntPtr (data_handle), 
			                                             DictionaryContainerHelper.GetHandle (pixelBufferAttributes), out handle);

			if (status != CVReturn.Success) {
				data_handle.Free ();
				return null;
			}

			return new CVPixelBuffer (handle, true);
		}
Ejemplo n.º 13
0
		extern static CVReturn CVPixelBufferCreate (
			/* CFAllocatorRef __nullable */ IntPtr allocator, /* size_t */ nint width, /* size_t */ nint height, 
			/* OSType */ CVPixelFormatType pixelFormatType,
			/* CFDictionaryRef __nullable */ IntPtr pixelBufferAttributes,
			/* CVPixelBufferRef __nullable * __nonnull */ out IntPtr pixelBufferOut);
Ejemplo n.º 14
0
			/* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut); // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

		public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
		{
			CVReturn status;
			return Create (width, height, pixelFormatType, planes, planeWidths, planeHeights, planeBytesPerRow, pixelBufferAttributes, out status);
		}
Ejemplo n.º 15
0
		static extern CVReturn CVPixelBufferCreateWithPlanarBytes (
			/* CFAllocatorRef CV_NULLABLE */ IntPtr allocator,
			/* size_t */ nint width,
			/* size_t */ nint height,
			/* OSType */ CVPixelFormatType pixelFormatType,
			/* void * CV_NULLABLE */ IntPtr dataPtr, /* pass a pointer to a plane descriptor block, or NULL /*
			/* size_t */ nint dataSize, /* pass size if planes are contiguous, NULL if not */
			/* size_t */ nint numberOfPlanes,
			/* void *[] CV_NULLABLE */ IntPtr[] planeBaseAddress,
			/* size_t[] */ nint [] planeWidth,
			/* size_t[] */ nint [] planeHeight,
			/* size_t[] */ nint [] planeBytesPerRow,
			CVPixelBufferReleasePlanarBytesCallback /* CV_NULLABLE */ releaseCallback,
			/* void * CV_NULLABLE */ IntPtr releaseRefCon,
			/* CFDictionaryRef CV_NULLABLE */ IntPtr pixelBufferAttributes,
			/* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut); // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);
Ejemplo n.º 16
0
		public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status)
		{
			IntPtr handle;
			GCHandle gchandle;

			if (data == null)
				throw new ArgumentNullException (nameof (data));

			if (data.Length < height * bytesPerRow)
				throw new ArgumentOutOfRangeException (nameof (data), "The length of data is smaller than height * bytesPerRow");

			gchandle = GCHandle.Alloc (data, GCHandleType.Pinned);

			status = CVPixelBufferCreateWithBytes (IntPtr.Zero, width, height, pixelFormatType, gchandle.AddrOfPinnedObject (), bytesPerRow, releaseBytesCallback, GCHandle.ToIntPtr (gchandle), DictionaryContainerHelper.GetHandle (pixelBufferAttributes), out handle);

			if (status != CVReturn.Success) {
				gchandle.Free ();
				return null;
			}

			return new CVPixelBuffer (handle, true);
		}
Ejemplo n.º 17
0
 static extern CVReturn CVPixelBufferCreate(IntPtr allocator, IntPtr width, IntPtr height, CVPixelFormatType pixelFormatType, IntPtr pixelBufferAttributes, IntPtr pixelBufferOut);
Ejemplo n.º 18
0
 public static bool IsCompressedPixelFormatAvailable(this CVPixelFormatType type)
 => CVIsCompressedPixelFormatAvailable((uint)type);
Ejemplo n.º 19
0
		CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormatType, NSDictionary pixelBufferAttributes)
		{
			if (width <= 0)
				throw new ArgumentOutOfRangeException ("width");

			if (height <= 0)
				throw new ArgumentOutOfRangeException ("height");

			CVReturn ret = CVPixelBufferCreate (IntPtr.Zero, width, height, pixelFormatType,
				pixelBufferAttributes == null ? IntPtr.Zero : pixelBufferAttributes.Handle, out handle);

			if (ret != CVReturn.Success)
				throw new ArgumentException (ret.ToString ());
		}
Ejemplo n.º 20
0
 public CVPixelBufferAttributes(CVPixelFormatType pixelFormatType, nint width, nint height)
     : this()
 {
     PixelFormatType = pixelFormatType;
     Width = width;
     Height = height;
 }
Ejemplo n.º 21
0
        public static CVPixelBuffer Create(nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status)
        {
            IntPtr handle;

            IntPtr[]  addresses;
            PlaneData data;
            GCHandle  data_handle;

            if (planes == null)
            {
                throw new ArgumentNullException(nameof(planes));
            }

            if (planeWidths == null)
            {
                throw new ArgumentNullException(nameof(planeWidths));
            }

            if (planeHeights == null)
            {
                throw new ArgumentNullException(nameof(planeHeights));
            }

            if (planeBytesPerRow == null)
            {
                throw new ArgumentNullException(nameof(planeBytesPerRow));
            }

            var planeCount = planes.Length;

            if (planeWidths.Length != planeCount)
            {
                throw new ArgumentOutOfRangeException(nameof(planeWidths), "The length of planeWidths does not match the number of planes");
            }

            if (planeHeights.Length != planeCount)
            {
                throw new ArgumentOutOfRangeException(nameof(planeWidths), "The length of planeHeights does not match the number of planes");
            }

            if (planeBytesPerRow.Length != planeCount)
            {
                throw new ArgumentOutOfRangeException(nameof(planeWidths), "The length of planeBytesPerRow does not match the number of planes");
            }

            addresses        = new IntPtr [planeCount];
            data             = new PlaneData();
            data.dataHandles = new GCHandle [planeCount];
            for (int i = 0; i < planeCount; i++)
            {
                data.dataHandles[i] = GCHandle.Alloc(planes [i], GCHandleType.Pinned);                  // This can't use unsafe code because we need to get the pointer for an unbound number of objects.
                addresses[i]        = data.dataHandles[i].AddrOfPinnedObject();
            }
            data_handle = GCHandle.Alloc(data);

            IntPtr data_handle_ptr = GCHandle.ToIntPtr(data_handle);

            status = CVPixelBufferCreateWithPlanarBytes(IntPtr.Zero,
                                                        width, height, pixelFormatType, IntPtr.Zero, 0,
                                                        planeCount, addresses, planeWidths, planeHeights, planeBytesPerRow,
                                                        releasePlanarBytesCallback, data_handle_ptr,
                                                        DictionaryContainerHelper.GetHandle(pixelBufferAttributes), out handle);

            if (status != CVReturn.Success)
            {
                ReleasePlanarBytesCallback(data_handle_ptr, IntPtr.Zero, 0, 0, IntPtr.Zero);
                return(null);
            }

            return(new CVPixelBuffer(handle, true));
        }
Ejemplo n.º 22
0
 public CVPixelBufferAttributes(CVPixelFormatType pixelFormatType, System.Drawing.Size size)
     : this(pixelFormatType, size.Width, size.Height)
 {
 }
Ejemplo n.º 23
0
 public CVPixelBuffer(Size size, CVPixelFormatType pixelFormat)
     : this(size.Width, size.Height, pixelFormat, null)
 {
 }
Ejemplo n.º 24
0
 public static NSDictionary Create(CVPixelFormatType pixelFormat)
 {
     return Runtime.GetNSObject<NSDictionary> (CVPixelFormatDescriptionCreateWithPixelFormatType (IntPtr.Zero, (int) pixelFormat));
 }
Ejemplo n.º 25
0
 extern static CVReturn CVPixelBufferCreate(IntPtr allocator, IntPtr width, IntPtr height, CVPixelFormatType pixelFormatType, IntPtr pixelBufferAttributes, IntPtr pixelBufferOut);
Ejemplo n.º 26
0
        public static void Register(NSDictionary description, CVPixelFormatType pixelFormat)
        {
            if (description == null)
                throw new ArgumentNullException ("description");

            CVPixelFormatDescriptionRegisterDescriptionWithPixelFormatType (description.Handle, (int) pixelFormat);
        }
Ejemplo n.º 27
0
 public static NSDictionary Create(CVPixelFormatType pixelFormat)
 {
     return(Runtime.GetNSObject <NSDictionary> (CVPixelFormatDescriptionCreateWithPixelFormatType(IntPtr.Zero, (int)pixelFormat)));
 }
Ejemplo n.º 28
0
		public CVPixelBuffer (Size size, CVPixelFormatType pixelFormat)
			: this (size.Width, size.Height, pixelFormat, null)
		{
		}
Ejemplo n.º 29
0
 public CVPixelBuffer(System.Drawing.Size size, CVPixelFormatType pixelFormat)
     : this(size.Width, size.Height, pixelFormat, (NSDictionary)null)
 {
 }
Ejemplo n.º 30
0
		public CVPixelBuffer (int width, int height, CVPixelFormatType pixelFormatType, NSDictionary pixelBufferAttributes)
		{
			if (width <= 0)
				throw new ArgumentOutOfRangeException ("width");

			if (height <= 0)
				throw new ArgumentOutOfRangeException ("height");

			IntPtr pixelBufferOut = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (IntPtr)));
			CVReturn ret = CVPixelBufferCreate (IntPtr.Zero, (IntPtr) width, (IntPtr) height, pixelFormatType,
				pixelBufferAttributes == null ? IntPtr.Zero : pixelBufferAttributes.Handle, pixelBufferOut);

			if (ret != CVReturn.Success) {
				Marshal.FreeHGlobal (pixelBufferOut);
				throw new ArgumentException (ret.ToString ());
			}

			this.handle = Marshal.ReadIntPtr (pixelBufferOut);
			Marshal.FreeHGlobal (pixelBufferOut);
		}
Ejemplo n.º 31
0
            /* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut);            // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

        public static CVPixelBuffer Create(nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
        {
            CVReturn status;

            return(Create(width, height, pixelFormatType, data, bytesPerRow, pixelBufferAttributes, out status));
        }
Ejemplo n.º 32
0
		static extern CVReturn CVPixelBufferCreateWithBytes (
			/* CFAllocatorRef CV_NULLABLE */ IntPtr allocator,
			/* size_t */ nint width,
			/* size_t */ nint height,
			/* OSType */ CVPixelFormatType pixelFormatType,
			/* void * CV_NONNULL */ IntPtr baseAddress,
			/* size_t */ nint bytesPerRow,
			CVPixelBufferReleaseBytesCallback /* CV_NULLABLE */ releaseCallback,
			/* void * CV_NULLABLE */ IntPtr releaseRefCon,
			/* CFDictionaryRef CV_NULLABLE */ IntPtr pixelBufferAttributes,
			/* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut);// __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);
Ejemplo n.º 33
0
		public CVPixelBuffer (Size size, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
			: this (size.Width, size.Height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
		{
		}
Ejemplo n.º 34
0
        public override void DidOutputSampleBuffer(AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection)
        {
            Console.WriteLine("Got Sample Fromn Buffer");
            lock (FaceDetectionViewController.lockerobj) {
                if (!FaceDetectionViewController.processingFaceDetection || isProcessingBuffer)
                {
                    sampleBuffer.Dispose();
                    return;
                }
                isProcessingBuffer = true;
            }

            try {
                CIImage ciImage       = null;
                CGRect  cleanAperture = default(CGRect);
                using (sampleBuffer) {
                    //CVPixelBuffer renderedOutputPixelBuffer = null;

                    byte[] managedArray;
                    int    width;
                    int    height;
                    int    bytesPerRow;

                    using (var pixelBuffer = sampleBuffer.GetImageBuffer() as CVPixelBuffer) {
                        pixelBuffer.Lock(CVPixelBufferLock.None);

                        CVPixelFormatType ft = pixelBuffer.PixelFormatType;

                        IntPtr baseAddress = pixelBuffer.BaseAddress;
                        bytesPerRow = (int)pixelBuffer.BytesPerRow;

                        width  = (int)pixelBuffer.Width;
                        height = (int)pixelBuffer.Height;

                        //managedArray = new byte[width * height];
                        managedArray = new byte[pixelBuffer.Height * pixelBuffer.BytesPerRow];
                        Marshal.Copy(baseAddress, managedArray, 0, managedArray.Length);


                        pixelBuffer.Unlock(CVPixelBufferLock.None);
                    }
                    sampleBuffer.Dispose();

                    //int bytesPerPixel = 4;
                    //int bytesPerRow = bytesPerPixel * width;
                    int bitsPerComponent = 8;
                    //CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();

                    //CGContext context = new CGBitmapContext(managedArray, width, height,
                    //bitsPerComponent, bytesPerRow, colorSpace,
                    //CGBitmapFlags.PremultipliedLast | CGBitmapFlags.ByteOrder32Big);


                    var flags = CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Little;
                    // Create a CGImage on the RGB colorspace from the configured parameter above
                    using (var cs = CGColorSpace.CreateDeviceRGB()) {
                        using (var context = new CGBitmapContext(managedArray, width, height, bitsPerComponent, bytesPerRow, cs, (CGImageAlphaInfo)flags)) {
                            ciImage = context.ToImage();

                            //using (CGImage cgImage = context.ToImage()) {
                            //    //pixelBuffer.Unlock(CVPixelBufferLock.None);

                            //    //return UIImage.FromImage(cgImage);
                            //}

                            context.Dispose();
                        }
                    }

                    //var a = new CMSampleBuffer.;
                    //using () {

                    //}

                    //UIImage image = GetImageFromSampleBuffer(sampleBuffer);

                    //if (!FaceMainController.isFaceRegistered || isProcessing)

                    //{
                    //    //      Console.WriteLine("OutputDelegate - Exit (isProcessing: " + DateTime.Now);
                    //    sampleBuffer.Dispose();
                    //    Console.WriteLine("processing..");

                    //    return;
                    //}


                    //Console.WriteLine("IsProcessing: ");

                    //isProcessing = true;
                    connection.VideoOrientation        = AVCaptureVideoOrientation.Portrait;
                    connection.VideoScaleAndCropFactor = 1.0f;

                    //var bufferCopy = sampleBuffer.c

                    //UIImage image = GetImageFromSampleBuffer(sampleBuffer);

                    //ciImage = CIImage.FromCGImage(image.CGImage);

                    //cleanAperture = sampleBuffer.GetVideoFormatDescription().GetCleanAperture(false);
                }
                /*For Face Detection using iOS APIs*/
                //DispatchQueue.MainQueue.DispatchAsync(() =>
                using (ciImage) {
                    if (ciImage != null)
                    {
                        drawFacesCallback(UIImage.FromImage(ciImage), cleanAperture);
                    }
                }

                isProcessingBuffer = false;

                //Console.WriteLine(ciImage);
                //Task.Run(async () => {
                //    try {
                //        //if (ViewController.IsFaceDetected)
                //        //{
                //        Console.WriteLine("face detected: ");

                //        imageAnalyzer = new ImageAnalyzer(() => Task.FromResult<Stream>(image.ResizeImageWithAspectRatio(300, 400).AsPNG().AsStream()));
                //        await ProcessCameraCapture(imageAnalyzer);
                //        //}

                //    }

                //    finally {
                //        imageAnalyzer = null;
                //        isProcessing = false;
                //        Console.WriteLine("OUT ");

                //    }

                //});
            }
            catch (Exception ex) {
                Console.Write(ex);
            }
            finally {
                sampleBuffer.Dispose();
            }
        }
Ejemplo n.º 35
0
 public AVVideoSettings(CVPixelFormatType formatType)
 {
     PixelFormat = formatType;
 }
 public CVPixelBufferAttributes(CVPixelFormatType pixelFormatType, System.Drawing.Size size)
     : this(pixelFormatType, size.Width, size.Height)
 {
 }
Ejemplo n.º 37
0
 public CVPixelBuffer(nint width, nint height, CVPixelFormatType pixelFormat)
     : this(width, height, pixelFormat, (NSDictionary?)null)
 {
 }
Ejemplo n.º 38
0
		public CVPixelBuffer (System.Drawing.Size size, CVPixelFormatType pixelFormat)
			: this (size.Width, size.Height, pixelFormat, (NSDictionary) null)
		{
		}