Exemplo n.º 1
0
 public void abort()
 {
     req?.Abort();
     req = null;
     requestHandle?.Dispose();
     requestHandle = null;
 }
Exemplo n.º 2
0
 public void PushMulti(T[] values)
 {
     using (DisposableHandle valuesHandle = DisposableHandle.Alloc(values))
     {
         InternalPushMulti(InnerPointer, valuesHandle, values.Length);
     }
 }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        public T[] ToArray()
        {
            T[] data = new T[Count];

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

            return(data);
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 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.");
            }
        }
Exemplo n.º 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"];
        }