Beispiel #1
0
 public void abort()
 {
     req?.Abort();
     req = null;
     requestHandle?.Dispose();
     requestHandle = null;
 }
Beispiel #2
0
 public void PushMulti(T[] values)
 {
     using (DisposableHandle valuesHandle = DisposableHandle.Alloc(values))
     {
         InternalPushMulti(InnerPointer, valuesHandle, values.Length);
     }
 }
 public DataVector32 OverrideData(float[] data)
 {
     using (var intPtr = new DisposableHandle(GCHandle.Alloc(data, GCHandleType.Pinned)))
     {
         Unwrap(DataVector32Native.OverrideData(_native, intPtr.IntPtr, (ulong)data.Length));
         return(this);
     }
 }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public Point[] ToArray()
 {
     Point[] pointsArray = new Point[Count];
     using (DisposableHandle arrayHandle = DisposableHandle.Alloc(pointsArray))
     {
         VectorOfPointCopyData(InnerPointer, arrayHandle);
     }
     return(pointsArray);
 }
Beispiel #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="values"></param>
 public void Push(int[] values)
 {
     if (values != null && values.Length > 0)
     {
         using (DisposableHandle valueHandle = DisposableHandle.Alloc(values))
         {
             VectorOfIntPushMulti(InnerPointer, valueHandle, values.Length);
         }
     }
 }
        public ComplexStatistics32[] ComplexStatisticsSplit(int length)
        {
            var result = new ComplexStatistics32[length];

            using (var intPtr = new DisposableHandle(GCHandle.Alloc(result, GCHandleType.Pinned)))
            {
                var code = DataVector32Native.ComplexStatisticsSplit(_native, intPtr.IntPtr, (ulong)length);
                CheckResultCode(code);
                return(result);
            }
        }
Beispiel #7
0
        public T[] ToArray()
        {
            T[] data = new T[Count];

            using (DisposableHandle arrayHandle = DisposableHandle.Alloc(data))
            {
                DataCopy(InnerPointer, arrayHandle);
            }

            return(data);
        }
Beispiel #8
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public int[] ToArray()
 {
     int[] outputArray = new int[Count];
     if (outputArray.Length > 0)
     {
         using (DisposableHandle arrayHandle = DisposableHandle.Alloc(outputArray))
         {
             VectorOfIntCopyData(InnerPointer, arrayHandle);
         }
     }
     return(outputArray);
 }
Beispiel #9
0
        protected override void Get(ReactContext context, AssetReferenceType realType, object realValue, Action <Texture2D> callback)
        {
            if (realType == AssetReferenceType.Url)
            {
                webDeferred = new DisposableHandle(context.Dispatcher, context.Dispatcher.StartDeferred(GetTexture(realValue as string, callback)));
            }
            else if (realType == AssetReferenceType.Data)
            {
                var    base64   = realValue as string;
                byte[] fileData = Convert.FromBase64String(base64);
                var    texture  = new Texture2D(1, 1);
                texture.LoadImage(fileData);
                callback(texture);
            }
            else if (realType == AssetReferenceType.File)
            {
                var       filePath = realValue as string;
                Texture2D texture  = null;
                byte[]    fileData;

                if (File.Exists(filePath))
                {
                    fileData = File.ReadAllBytes(filePath);
                    texture  = new Texture2D(1, 1);
                    texture.LoadImage(fileData);
                }
                callback(texture);
            }
            else if (realType == AssetReferenceType.Procedural)
            {
                var color = ParserMap.ColorConverter.Convert(realValue);

                if (color is Color c)
                {
                    var t = new Texture2D(1, 1);
                    t.SetPixel(0, 0, c);
                    t.Apply();
                    callback(t);
                }
                else
                {
                    callback(null);
                }
            }
            else
            {
                base.Get(context, realType, realValue, callback);
            }
        }
        public void WritePixels(Array pixelsArray)
        {
            if (pixelsArray == null)
            {
                throw new ArgumentNullException("pixelsArray");
            }

            Type itemType = pixelsArray.GetType().GetElementType();
            int  itemSize = Marshal.SizeOf(itemType);

            int arrayRank = pixelsArray.Rank, counter = 0, bytesCount = 0, arraySize = 0;

            for (; counter < arrayRank; counter += 1)
            {
                arraySize   = pixelsArray.GetLength(counter);
                bytesCount += arraySize * itemSize;
            }

            using (DisposableHandle arrayHandle = DisposableHandle.Alloc(pixelsArray))
            {
                NTInvoke.CopyUnmanagedMemory(RawDataPtr, arrayHandle, bytesCount);
            }
        }
Beispiel #11
0
        internal unsafe static void Main(string[] args)
        {
            try
            {
                int    pixelsCount = 1 << 18;
                uint[] pixelsArray = new uint[65536];

                using (DisposableHandle handle = DisposableHandle.Alloc(pixelsArray))
                {
                    NTInvoke.SetUnmanagedMemory(handle, 255, pixelsCount);
                }

                byte[] outputData = null;

                MCvScalar redColor   = MCvScalarExtensions.FromColor(Colors.Red);
                MCvScalar greenColor = MCvScalarExtensions.FromColor(Colors.Green);

                using (PresentationImage prImage = new PresentationImage(256, 256))
                {
                    prImage.WritePixels(pixelsArray);

                    FontFace[] faces = new FontFace[]
                    {
                        FontFace.HersheyComplex,
                        FontFace.HersheyComplexSmall,
                        FontFace.HersheyDuplex,
                        FontFace.HersheyPlain,
                        FontFace.HersheyScriptComplex,
                        FontFace.HersheyScriptSimplex,
                        FontFace.HersheySimplex,
                        FontFace.HersheyTriplex
                    };

                    Parallel.For(0, 8, (int index) =>
                    {
                        Point drawPoint   = new Point(10, 30 + 30 * index);
                        FontFace drawFace = faces[index];

                        string outputText = Enum.GetName(typeof(FontFace), drawFace);

                        CvInvoke.DrawText(prImage, outputText, drawPoint, drawFace, 1.0D, redColor, 1);
                    });

                    outputData = CvInvoke.Imencode(prImage, ImageEncoding.Jpeg, new int[] { 95 });
                }

                if (outputData != null && outputData.Length > 0)
                {
                    using (MemoryStream dataStream = new MemoryStream(outputData))
                    {
                        JpegBitmapDecoder decoder = new JpegBitmapDecoder(dataStream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnLoad);
                        BitmapFrame       frame   = decoder.Frames[0];

                        Window imageWindow = new Window()
                        {
                            Height                = 300.0D,
                            Width                 = 500.0D,
                            Title                 = "Image window",
                            ResizeMode            = ResizeMode.CanResize,
                            WindowStartupLocation = WindowStartupLocation.CenterScreen
                        };
                        imageWindow.Content = new Image()
                        {
                            Source = frame
                        };
                        new Application().Run(imageWindow);
                    }
                }
            }
            catch (Exception exc)
            {
                Debug.WriteLine("\tCatched exception: {0}\r\n{1}", exc.Message, exc);
            }
            finally
            {
                Debug.WriteLine("\tData released succesfully.");
            }
        }
Beispiel #12
0
        public void send(object o)
        {
            var args = o as Jint.Native.Object.ObjectInstance;

            options = extractOptions(args);
            url     = new Uri(origin + options["url"]);

            req           = UnityWebRequest.Get(url);
            requestHandle = new DisposableHandle(context.Dispatcher, context.Dispatcher.StartDeferred(
                                                     ReactScript.WatchWebRequest(req, responseCallback, errorCallback)));

            // TODO: implement methods, headers and other options

            //req.Method = options["method"];

            // add custom headers
            //if (headers.Count != 0)
            //{
            //    foreach (string key in headers.Keys)
            //    {
            //        if (headers[key] == null)
            //            continue;

            //        switch (key.ToLower())
            //        {
            //            // in silverlight 3, these are set by the web browser that hosts the Silverlight application.
            //            // http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=vs.95%29.aspx
            //            case "connection":
            //            case "content-length":
            //            case "expect":
            //            case "if-modified-since":
            //            case "referer":
            //            case "transfer-encoding":
            //            case "user-agent":
            //                break;

            //            // in silverlight this isn't supported, can not find reference to why not
            //            case "range":
            //                break;

            //            // in .NET Framework 3.5 and below, these are set by the system.
            //            // http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=VS.90%29.aspx
            //            case "date":
            //            case "host":
            //                break;

            //            case "accept":
            //                req.Accept = (string)headers[key];
            //                break;

            //            case "content-type":
            //                req.ContentType = headers[key];
            //                break;
            //            default:
            //                req.Headers[key] = (string)headers[key];
            //                break;
            //        }
            //    }
            //}

            //req.ContentLength = 0;
            //req.ContentType = options["mimeType"];
        }