private static unsafe int MapOutputRectToInputRects(IntPtr thisObject, Rect *outputRect, Rect *pInputRects, int inputRectsCount) { try { var inputRects = new Rect[inputRectsCount]; Unsafe.CopyBlock( Unsafe.AsPointer(ref inputRects[0]), pInputRects, (uint)(sizeof(Rect) * inputRectsCount)); ID2D1Transform @this = (ID2D1Transform)ToShadow <ID2D1TransformShadow>(thisObject).Callback; @this.MapOutputRectToInputRects(*outputRect, inputRects); Unsafe.CopyBlock( pInputRects, Unsafe.AsPointer(ref inputRects[0]), (uint)(sizeof(Rect) * inputRectsCount)); return(Result.Ok.Code); } catch (Exception __exception__) { return(Result.GetResultFromException(__exception__).Code); } }
/// <summary>Clip the polyline to viewport, using specified clipping rectangle</summary> public static eClipResult clip(this iPolylinePath source, iPolylinePath dest, Rect clipRect, Matrix3x2 transform, float strokeWidth = 0) { unsafe { Rect *clip = &clipRect; source.clip(strokeWidth, ref transform, (IntPtr)clip, dest, out var res); return(res); } }
/// <summary>Tessellate splines and clip the result to viewport, using specified clipping rectangle</summary> public static eClipResult buildClippedPolylines(this iPathGeometry path, iPolylinePath poly, Rect clipRect, Matrix3x2 transform, float precision, float strokeWidth = 0) { unsafe { Rect *clip = &clipRect; path.buildPolylines(precision, strokeWidth, ref transform, (IntPtr)clip, poly, out var res); return(res); } }
public unsafe static Rect[] PtrToRectArray(IntPtr ptr, int size) { var rects = new Rect[size]; Rect *rectPtr = (Rect *)ptr; for (var i = 0; i < size; i++) { rects[i] = Marshal.PtrToStructure <Rect>((IntPtr)rectPtr++); } return(rects); }
public static unsafe Rect SplitHorizontal(ref Rect rect, int separation) { Rect rect2 = rect; Rect *rectPtr1 = &rect2; rectPtr1.xMax -= (rect.width / 2f) + separation; Rect rect3 = rect; Rect *rectPtr2 = &rect3; rectPtr2.xMin += (rect.width / 2f) + separation; rect = rect2; return(rect3); }
internal unsafe static extern int MilUtility_PolygonBounds( MilMatrix3x2D *pWorldMatrix, MIL_PEN_DATA *pPenData, double *pDashArray, Point *pPoints, byte *pTypes, UInt32 pointCount, UInt32 segmentCount, MilMatrix3x2D *pGeometryMatrix, double rTolerance, bool fRelative, bool fSkipHollows, Rect *pBounds);
public static unsafe Rect SplitVertical(ref Rect rect, int separation) { Rect rect2 = rect; Rect *rectPtr1 = &rect2; rectPtr1.yMax -= (rect.height / 2f) + separation; Rect rect3 = rect; Rect *rectPtr2 = &rect3; rectPtr2.yMin += (rect.height / 2f) + separation; rect = rect2; return(rect3); }
public static Rect[] PtrToRectArray(MpRectVector rectVectorPtr) { var rectVector = Marshal.PtrToStructure <RectVector>(rectVectorPtr); var rects = new Rect[rectVector.size]; unsafe { Rect *rectPtr = (Rect *)rectVector.rects; for (var i = 0; i < rects.Length; i++) { rects[i] = Marshal.PtrToStructure <Rect>((IntPtr)rectPtr++); } } return(rects); }
public void RawApiFrontalFaceDetector() { const string imagePath = "images\\lenna.bmp"; IntPtr detector = IntPtr.Zero; IntPtr image = IntPtr.Zero; IntPtr dets = IntPtr.Zero; try { detector = NativeMethods.dlib_get_frontal_face_detector(); image = NativeMethods.dlib_array2d_uchar_new(); NativeMethods.dlib_load_image_array2d_uchar(image, imagePath); NativeMethods.dlib_pyramid_up_array2d_uchar(image); dets = NativeMethods.vector_Rect_new1(); NativeMethods.dlib_frontal_face_detector_operator(detector, image, 0, dets); unsafe { Rect *rectangles = (Rect *)NativeMethods.vector_Rect_getPointer(dets).ToPointer(); long count = NativeMethods.vector_Rect_getSize(dets).ToInt64(); for (int i = 0; i < count; i++) { Console.WriteLine(rectangles[i]); } } } finally { if (image != IntPtr.Zero) { NativeMethods.dlib_array2d_uchar_delete(image); } if (detector != IntPtr.Zero) { NativeMethods.dlib_frontal_face_detector_delete(detector); } if (dets != IntPtr.Zero) { NativeMethods.vector_Rect_delete(dets); } } }
public System.Drawing.Rectangle[] DetectFaces(MatrixRgbPixel inputImage) { var ret = new System.Drawing.Rectangle[0]; try { dets = NativeMethods.vector_Rect_new1(); NativeMethods.dlib_dnn_mmod_face_detection_operator(detector, inputImage.DlibMatrixRgbPixel, dets); unsafe { Trace.Assert(dets != null && dets != IntPtr.Zero); long count = NativeMethods.vector_Rect_getSize(dets).ToInt64(); // If it does not return ret here, exception occurs. if (count == 0) { return(ret); } Rect *rectangles = (Rect *)NativeMethods.vector_Rect_getPointer(dets).ToPointer(); ret = new System.Drawing.Rectangle[count]; for (int i = 0; i < count; i++) { var src = rectangles[i]; ret[i] = new System.Drawing.Rectangle(src.X, src.Y, src.Width, src.Height); } } } catch (Exception ex) { #if DEBUG Debugger.Break(); #endif Console.WriteLine(ex.Message); } finally { ReleaseDets(); } return(ret); }
public static extern int GetDisplayUsableBounds(int displayIndex, Rect *rect);
/// <summary> /// Remove this rect from the other rect and return the up to four remaining pieces /// destRects must have enough space for four rectangles /// Returns the number of pieces other was broken up into. /// </summary> public unsafe int RemoveFrom(Rect other, Rect *destRects) { if (Disjoint(other)) { destRects[0] = other; return(1); } if (ContainsInclusive(other)) { return(0); } // Always split like this: // +--------------+ // | 0 | // |----+----+----| // | 1 |this| 2 | // |----+----+----| // | 3 | // +--------------| // Then, only accept non-empty sub-rects // This will create three sub rects even when 2 would be enough int n = 0; destRects[n].x = other.x; destRects[n].y = other.y; destRects[n].width = other.width; destRects[n].height = math.min(y - other.y, other.height); if (!destRects[n].IsEmpty()) { n++; } destRects[n].x = other.x; destRects[n].y = y; destRects[n].width = math.min(x - other.x, other.width); destRects[n].height = math.min(height, other.height); if (!destRects[n].IsEmpty()) { n++; } destRects[n].x = x + width; destRects[n].y = y; destRects[n].width = math.min((other.x + other.width) - (x + width), other.width); destRects[n].height = math.min(height, other.height); if (!destRects[n].IsEmpty()) { n++; } destRects[n].x = x; destRects[n].y = y + height; destRects[n].width = other.width; destRects[n].height = (other.y + other.height) - (y + height); if (!destRects[n].IsEmpty()) { n++; } Assert.IsTrue(n == 3); return(n); }
internal static extern unsafe IntPtr Constructor(IntPtr pThis, Rect *rect, IntPtr pName, int unk1, int unk2);
public static extern int SDL_FillRect( Surface dst, /*const*/ Rect *rect, UInt32 color );
private static unsafe int MapInvalidRect(IntPtr thisObject, int inputIndex, Rect *invalidInputRect, Rect *invalidOutputRect) { try { ID2D1Transform @this = (ID2D1Transform)ToShadow <ID2D1TransformShadow>(thisObject).Callback; @this.MapInvalidRect(inputIndex, *invalidInputRect, out *invalidOutputRect); return(Result.Ok.Code); } catch (Exception __exception__) { return(Result.GetResultFromException(__exception__).Code); } }
public static extern SDL_Bool SDL_SetClipRect( Surface surface, /*const*/ Rect *rect );
public static extern int SDL_BlitScaled( Surface src, /* const*/ Rect *srcrect, Surface dst, Rect *dstrect );
private static extern unsafe bool ovrHmd_AttachToWindow(IntPtr hmd, IntPtr hwnd, Rect *destMirrorRect, Rectangle *sourceRenderTargetRect);
public static extern int SDL_LowerBlitScaled( Surface surface, Rect *srcrect, Surface dst, Rect *dstrect );
public static unsafe object ToObject(Type type, Value *value) { if (value == null || value->IsNull) { return(null); } if (value->boxed_valuetype.IsAllocated) { return(value->boxed_valuetype.Target); } if (value->IsGCHandle) { IntPtr managed_object = value->u.p; GCHandle handle = GCHandle.FromIntPtr(managed_object); return(handle.Target); } switch (value->Kind) { case Kind.INVALID: return(null); case Kind.DEPENDENCYPROPERTY: return(DependencyProperty.Lookup(value->u.p)); case Kind.BOOL: return(value->u.i32 != 0); case Kind.DOUBLE: return(value->u.d); case Kind.FLOAT: return(value->u.f); case Kind.UINT64: return(value->u.ui64); case Kind.INT64: return(value->u.i64); case Kind.TIMESPAN: return(new TimeSpan(value->u.i64)); case Kind.CURSORTYPE: return(Cursors.FromEnum((CursorType)value->u.i32)); case Kind.TEXTDECORATIONS: return((value->u.i32 == (int)TextDecorationKind.Underline) ? TextDecorations.Underline : null); case Kind.INT32: return(value->u.i32); case Kind.UINT32: return(value->u.ui32); case Kind.CHAR: return((char)value->u.ui32); case Kind.SURFACE: return(NativeDependencyObjectHelper.FromIntPtr(value->u.p)); case Kind.STRING: { return(Marshal.PtrToStringAuto(value->u.p)); } case Kind.URI: return(UriHelper.FromNativeUri(value->u.p)); case Kind.XMLLANGUAGE: { string str = Marshal.PtrToStringAuto(value->u.p); return(XmlLanguage.GetLanguage(str)); } case Kind.FONTFAMILY: { UnmanagedFontFamily *family = (UnmanagedFontFamily *)value->u.p; return(new FontFamily(family == null ? null : Marshal.PtrToStringAuto(family->source))); } case Kind.FONTSTRETCH: { UnmanagedFontStretch *stretch = (UnmanagedFontStretch *)value->u.p; return(new FontStretch(stretch == null ? FontStretchKind.Normal : stretch->stretch)); } case Kind.FONTSTYLE: { UnmanagedFontStyle *style = (UnmanagedFontStyle *)value->u.p; return(new FontStyle(style == null ? FontStyleKind.Normal : style->style)); } case Kind.FONTWEIGHT: { UnmanagedFontWeight *weight = (UnmanagedFontWeight *)value->u.p; return(new FontWeight(weight == null ? FontWeightKind.Normal : weight->weight)); } case Kind.FONTSOURCE: { UnmanagedFontSource * fs = (UnmanagedFontSource *)value->u.p; ManagedStreamCallbacks callbacks; GlyphTypeface typeface; StreamWrapper wrapper; switch (fs->type) { case FontSourceType.ManagedStream: callbacks = (ManagedStreamCallbacks)Marshal.PtrToStructure(fs->source.stream, typeof(ManagedStreamCallbacks)); wrapper = (StreamWrapper)GCHandle.FromIntPtr(callbacks.handle).Target; return(new FontSource(wrapper.stream)); case FontSourceType.GlyphTypeface: typeface = new GlyphTypeface(fs->source.typeface); return(new FontSource(typeface)); default: throw new Exception(String.Format("Do not know how to create a FontSource of type {0}", fs->type.ToString())); } } case Kind.GLYPHTYPEFACE: { return(new GlyphTypeface(value->u.p)); } case Kind.PROPERTYPATH: { UnmanagedPropertyPath *propertypath = (UnmanagedPropertyPath *)value->u.p; if (propertypath == null) { return(new PropertyPath(null)); } if (propertypath->property != IntPtr.Zero) { return(null); } return(new PropertyPath(Marshal.PtrToStringAuto(propertypath->pathString), Marshal.PtrToStringAuto(propertypath->expandedPathString))); } case Kind.POINT: { Point *point = (Point *)value->u.p; return((point == null) ? new Point(0, 0) : *point); } case Kind.RECT: { Rect *rect = (Rect *)value->u.p; return((rect == null) ? new Rect(0, 0, 0, 0) : *rect); } case Kind.SIZE: { Size *size = (Size *)value->u.p; return((size == null) ? new Size(0, 0) : *size); } case Kind.CORNERRADIUS: { CornerRadius *corner = (CornerRadius *)value->u.p; return((corner == null) ? new CornerRadius(0) : *corner); } case Kind.AUDIOFORMAT: { UnmanagedAudioFormat *format = (UnmanagedAudioFormat *)value->u.p; return((format == null) ? new AudioFormat() : format->ToAudioFormat()); } case Kind.VIDEOFORMAT: { UnmanagedVideoFormat *format = (UnmanagedVideoFormat *)value->u.p; return((format == null) ? new VideoFormat() : format->ToVideoFormat()); } case Kind.THICKNESS: { Thickness *thickness = (Thickness *)value->u.p; return((thickness == null) ? new Thickness(0) : *thickness); } case Kind.COLOR: { UnmanagedColor *color = (UnmanagedColor *)value->u.p; if (color == null) { return(new Color()); } return(color->ToColor()); } case Kind.MATRIX: case Kind.UNMANAGEDMATRIX: { return(new Matrix(value->u.p)); } case Kind.MATRIX3D: case Kind.UNMANAGEDMATRIX3D: { return(new Matrix3D(value->u.p)); } case Kind.STYLUSPOINT: case Kind.UNMANAGEDSTYLUSPOINT: { var kind = value->Kind; var ptr = value->u.p; var x = (double)Value.ToObject(typeof(double), NativeMethods.dependency_object_get_value(ptr, UnmanagedStylusPoint.XProperty.Native)); var y = (double)Value.ToObject(typeof(double), NativeMethods.dependency_object_get_value(ptr, UnmanagedStylusPoint.YProperty.Native)); var pressure = (double)Value.ToObject(typeof(double), NativeMethods.dependency_object_get_value(ptr, UnmanagedStylusPoint.PressureFactorProperty.Native)); return(new StylusPoint { X = x, Y = y, PressureFactor = (float)pressure }); } case Kind.DURATION: { Duration *duration = (Duration *)value->u.p; return((duration == null) ? Duration.Automatic : *duration); } case Kind.KEYTIME: { KeyTime *keytime = (KeyTime *)value->u.p; return((keytime == null) ? KeyTime.FromTimeSpan(TimeSpan.Zero) : *keytime); } case Kind.GRIDLENGTH: { GridLength *gridlength = (GridLength *)value->u.p; return((gridlength == null) ? new GridLength() : *gridlength); } case Kind.REPEATBEHAVIOR: { RepeatBehavior *repeat = (RepeatBehavior *)value->u.p; return((repeat == null) ? new RepeatBehavior() : *repeat); } case Kind.MEDIAATTRIBUTE_COLLECTION: { IntPtr p = value->u.p; if (p == IntPtr.Zero) { return(null); } int count = NativeMethods.collection_get_count(p); var dict = new Dictionary <string, string> (); for (int i = 0; i < count; i++) { IntPtr map = NativeMethods.collection_get_value_at(p, i); if (map == IntPtr.Zero) { continue; } Value *attribute = (Value *)map; if (attribute->Kind != Kind.MEDIAATTRIBUTE || attribute->u.p == IntPtr.Zero) { continue; } string name = NativeMethods.media_attribute_get_name(attribute->u.p); string val = NativeMethods.media_attribute_get_value(attribute->u.p); dict.Add(name, val); } return(dict); } case Kind.MANAGEDTYPEINFO: { ManagedTypeInfo *type_info = (ManagedTypeInfo *)value->u.p; if (type_info == null) { return(null); } return(Deployment.Current.Types.KindToType(type_info->Kind)); } default: Type tt = Deployment.Current.Types.KindToType(value->Kind); if (tt != null && tt.IsEnum) { return(Enum.ToObject(tt, value->u.i32)); } break; } if (NativeMethods.type_is_event_object(value->Kind)) { if (value->u.p == IntPtr.Zero) { return(null); } return(NativeDependencyObjectHelper.Lookup(value->u.p)); } throw new Exception(String.Format("Do not know how to convert {0} {1}. Managed type: {2}", value->Kind, (int)value->Kind, Deployment.Current.Types.KindToType(value->Kind))); }
public static extern unsafe bool InvalidateRect( WindowHandle hWnd, Rect *lpRect, bool bErase);
internal static extern unsafe IntPtr Constructor(IntPtr pThis, Rect *rect, IntPtr string1, IntPtr string2, WindowStyle windowStyle, WindowFlags flags);
public static extern void SDL_SetInputRect(Rect *rect);
public static extern void SetTextInputRect(Rect *rect);
public void RawApiFrontalFaceDetectorUsingMemoryInput() { const string imagePath = "images\\lenna.bmp"; var imageBytes = File.ReadAllBytes(imagePath); IntPtr detector = IntPtr.Zero; IntPtr dets = IntPtr.Zero; try { using (var window = new ImageWindow()) using (var image = new Array2dUchar()) { Console.WriteLine($"Size: ({image.Width},{image.Height})"); Trace.Assert(image.Width == 0 && image.Height == 0); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); NativeMethods.dlib_load_bmp_array2d_uchar(image.DlibArray2dUchar, imageBytes, new IntPtr(imageBytes.Length)); Console.WriteLine($"Size: ({image.Width},{image.Height})"); Trace.Assert(image.Width == 512 && image.Height == 480); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); image.SetBitmap(new System.Drawing.Bitmap(imagePath)); Console.WriteLine($"Size: ({image.Width},{image.Height})"); Trace.Assert(image.Width == 512 && image.Height == 480); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); image.PyramidUp(); Console.WriteLine($"Size: ({image.Width},{image.Height})"); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); detector = NativeMethods.dlib_get_frontal_face_detector(); dets = NativeMethods.vector_Rect_new1(); NativeMethods.dlib_frontal_face_detector_operator(detector, image.DlibArray2dUchar, -0.5, dets); unsafe { Rect *rectangles = (Rect *)NativeMethods.vector_Rect_getPointer(dets).ToPointer(); long count = NativeMethods.vector_Rect_getSize(dets).ToInt64(); for (int i = 0; i < count; i++) { Console.WriteLine(rectangles[i]); } } } } finally { if (detector != IntPtr.Zero) { NativeMethods.dlib_frontal_face_detector_delete(detector); } if (dets != IntPtr.Zero) { NativeMethods.vector_Rect_delete(dets); } } }
public void RawApiDnnMmodDetectionUsingMemoryInput() { const string imagePath = "images\\lenna.bmp"; if (IntPtr.Size == 4) { return; } var imageBytes = File.ReadAllBytes(imagePath); IntPtr detector = IntPtr.Zero; IntPtr dets = IntPtr.Zero; try { using (var window = new ImageWindow()) using (var image = new MatrixRgbPixel()) { Console.WriteLine($"Size: ({image.Width},{image.Height})"); Trace.Assert(image.Width == 0 && image.Height == 0); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); NativeMethods.dlib_load_bmp_matrix_rgbpixel(image.DlibMatrixRgbPixel, imageBytes, new IntPtr(imageBytes.Length)); Trace.Assert(image.Width == 512 && image.Height == 480); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); image.SetBitmap(new System.Drawing.Bitmap(imagePath)); Console.WriteLine($"Size: ({image.Width},{image.Height})"); Trace.Assert(image.Width == 512 && image.Height == 480); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); image.PyramidUp(); Console.WriteLine($"Size: ({image.Width},{image.Height})"); window.SetImage(image); OpenCvSharp.Cv2.WaitKey(Cv2WaitKeyDelay); dets = NativeMethods.vector_Rect_new1(); detector = NativeMethods.dlib_dnn_mmod_face_detection_construct("D:/Data/Dlib/mmod_human_face_detector.dat"); NativeMethods.dlib_dnn_mmod_face_detection_operator(detector, image.DlibMatrixRgbPixel, dets); long count = NativeMethods.vector_Rect_getSize(dets).ToInt64(); if (count > 0) { unsafe { Rect *rectangles = (Rect *)NativeMethods.vector_Rect_getPointer(dets).ToPointer(); for (int i = 0; i < count; i++) { Console.WriteLine(rectangles[i]); } } } } } finally { if (detector != IntPtr.Zero) { NativeMethods.dlib_dnn_mmod_face_detection_delete(detector); } if (dets != IntPtr.Zero) { NativeMethods.vector_Rect_delete(dets); } } }
public static extern unsafe bool ValidateRect( WindowHandle hWnd, Rect *lpRect);
unsafe internal static extern bool EnumDisplayMonitors( [In] IntPtr deviceContextHandle, [In] Rect *clipRect, [In, MarshalAs(UnmanagedType.FunctionPtr)] MonitorEnumProc callback, [In] IntPtr data );
public static extern unsafe int core_Mat_nGetRect(IntPtr obj, int row, int col, Rect *vals, int valsLength);
internal static extern unsafe IntPtr Constructor(IntPtr pThis, Rect *rect, IntPtr pName, int garbage1, int garbage2, int garbage3, int garbage4, int garbage5, int garbage6, int unk1, int unk2, int unk3);