public CVPixelBufferAttributes (CVPixelFormatType pixelFormatType, Size size) : this () { PixelFormatType = pixelFormatType; Width = size.Width; Height = size.Height; }
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); }
/* 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); }
public CVPixelBuffer(nint width, nint height, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes) : this(width, height, pixelFormatType, attributes == null ? null : attributes.Dictionary) { }
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; }
public CVPixelBuffer(int width, int height, CVPixelFormatType pixelFormatType) : this(width, height, pixelFormatType, (NSDictionary)null) { }
/* 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)); }
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);
public CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormat) : this (width, height, pixelFormat, (NSDictionary) null) { }
public CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes) : this (width, height, pixelFormatType, attributes == null ? null : attributes.Dictionary) { }
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); }
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);
/* 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); }
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);
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); }
static extern CVReturn CVPixelBufferCreate(IntPtr allocator, IntPtr width, IntPtr height, CVPixelFormatType pixelFormatType, IntPtr pixelBufferAttributes, IntPtr pixelBufferOut);
public static bool IsCompressedPixelFormatAvailable(this CVPixelFormatType type) => CVIsCompressedPixelFormatAvailable((uint)type);
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 ()); }
public CVPixelBufferAttributes(CVPixelFormatType pixelFormatType, nint width, nint height) : this() { PixelFormatType = pixelFormatType; Width = width; Height = height; }
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)); }
public CVPixelBufferAttributes(CVPixelFormatType pixelFormatType, System.Drawing.Size size) : this(pixelFormatType, size.Width, size.Height) { }
public CVPixelBuffer(Size size, CVPixelFormatType pixelFormat) : this(size.Width, size.Height, pixelFormat, null) { }
public static NSDictionary Create(CVPixelFormatType pixelFormat) { return Runtime.GetNSObject<NSDictionary> (CVPixelFormatDescriptionCreateWithPixelFormatType (IntPtr.Zero, (int) pixelFormat)); }
extern static CVReturn CVPixelBufferCreate(IntPtr allocator, IntPtr width, IntPtr height, CVPixelFormatType pixelFormatType, IntPtr pixelBufferAttributes, IntPtr pixelBufferOut);
public static void Register(NSDictionary description, CVPixelFormatType pixelFormat) { if (description == null) throw new ArgumentNullException ("description"); CVPixelFormatDescriptionRegisterDescriptionWithPixelFormatType (description.Handle, (int) pixelFormat); }
public static NSDictionary Create(CVPixelFormatType pixelFormat) { return(Runtime.GetNSObject <NSDictionary> (CVPixelFormatDescriptionCreateWithPixelFormatType(IntPtr.Zero, (int)pixelFormat))); }
public CVPixelBuffer (Size size, CVPixelFormatType pixelFormat) : this (size.Width, size.Height, pixelFormat, null) { }
public CVPixelBuffer(System.Drawing.Size size, CVPixelFormatType pixelFormat) : this(size.Width, size.Height, pixelFormat, (NSDictionary)null) { }
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); }
/* 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)); }
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);
public CVPixelBuffer (Size size, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes) : this (size.Width, size.Height, pixelFormatType, attributes == null ? null : attributes.Dictionary) { }
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(); } }
public CVPixelBuffer(nint width, nint height, CVPixelFormatType pixelFormat) : this(width, height, pixelFormat, (NSDictionary?)null) { }
public CVPixelBuffer (System.Drawing.Size size, CVPixelFormatType pixelFormat) : this (size.Width, size.Height, pixelFormat, (NSDictionary) null) { }