Ejemplo n.º 1
0
 public BitMapSkipper(IBitmap bitmap, List<Point2D> points)
 {
     FromVectors(points);
     CreateScans();
     FillScans(points);
     FormatScans(bitmap);
 }
Ejemplo n.º 2
0
 public void DrawImage(IBitmap source, double opacity, Rect sourceRect, Rect destRect)
 {
     var impl = (BitmapImpl) source.PlatformImpl;
     var s = SkRect.FromRect(sourceRect);
     var d = SkRect.FromRect(destRect);
     MethodTable.Instance.DrawImage(Handle, impl.Handle, (float) opacity, ref s, ref d);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bitmap"></param>
        public VideoTrack(IBitmap bitmap)
        {
            Contract.Requires(bitmap != null);

            this.dimensions = new Size(bitmap.Width, bitmap.Height);
            this.format = bitmap.Format;
        }
Ejemplo n.º 4
0
        public static Bitmap Fill(IBitmap contraints, VectorInt2 p)
        {
            var result = new Bitmap(contraints.Size);
            FillCell(contraints, result, p);

            return result;
        }
 public ActionSheetOptionViewModel(bool visible, string text, Action action, IBitmap image = null)
 {
     this.Text = text;
     this.Action = new Command(action);
     this.Visible = visible ? Visibility.Visible : Visibility.Collapsed;
     this.ItemIcon = image;
 }
Ejemplo n.º 6
0
		public void Release(IBitmap bitmap)
		{
			if (!MathUtils.IsPowerOf2(bitmap.Width) ||
			    !MathUtils.IsPowerOf2(bitmap.Height)) return;

			getPool(bitmap.Width, bitmap.Height).Release(bitmap);
		}
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Layer"/> class.
        /// </summary>
        /// <param name="owner"></param>
        internal Layer(Image owner)
        {
            Contract.Requires(owner != null);

            this.owner = owner;
            this.content = owner.Format.CreateBitmap(owner.Size);
            this.mask = owner.Format.CreateBitmap(owner.Size);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Copy Constructor. Deep copy.
 /// </summary>
 /// <param name="copy"></param>
 public Bitmap(IBitmap copy)
     : this(copy.Size.X, copy.Size.Y)
 {
     for (int cy = 0; cy < copy.Size.Y; cy++)
         for (int cx = 0; cx < copy.Size.X; cx++)
         {
             this[cx, cy] = copy[cx, cy];
         }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Init from a bitmap, setting on true positions to <paramref name="Value"/>
 /// </summary>
 /// <param name="Bitmap"></param>
 /// <param name="Value"></param>
 public Matrix(IBitmap Bitmap, float Value)
 {
     Size = Bitmap.Size;
     for (int ccx = 0; ccx < Width; ccx++)
         for (int ccy = 0; ccy < Height; ccy++)
         {
             if (Bitmap[ccx, ccy]) this[ccx, ccy] = Value;
         }
 }
Ejemplo n.º 10
0
        public GLImage(IBitmap bitmap, string id, ITexture texture, ISpriteSheet spriteSheet, ILoadImageConfig loadConfig)
		{
			OriginalBitmap = bitmap;
			Width = bitmap.Width;
			Height = bitmap.Height;
			ID = id;
			Texture = texture;
			SpriteSheet = spriteSheet;
			LoadConfig = loadConfig;
		}
Ejemplo n.º 11
0
        public IObject GetDrawable(IArea area, IBitmap bg)
		{
            IWalkBehindArea walkBehind = area.GetComponent<IWalkBehindArea>();
            if (walkBehind == null) return null;
			AreaKey key = new AreaKey (area, bg);
			IObject obj = _objects.GetOrAdd(key, () => createObject());
			obj.Z = walkBehind.Baseline == null ? area.Mask.MinY : walkBehind.Baseline.Value;
			obj.Image = _images.GetOrAdd(key, () => createImage(area, bg));
			return obj;
		}
Ejemplo n.º 12
0
 public void DrawImage(IBitmap source, double opacity, Rect sourceRect, Rect destRect)
 {
     var impl = (BitmapImpl)source.PlatformImpl;
     var s = sourceRect.ToSKRect();
     var d = destRect.ToSKRect();
     using (var paint = new SKPaint()
             { Color = new SKColor(255, 255, 255, (byte)(255 * opacity)) })
     {
         Canvas.DrawBitmap(impl.Bitmap, s, d, paint);
     }
 }
Ejemplo n.º 13
0
 private void InvertBitmap(IBitmap bitmap)
 {
     for (int y = 0; y < bitmap.Height; y++)
         for (int x = 0; x < bitmap.Width; x++)
         {
             var px = bitmap[x, y];
             px.Red = 1.0f - px.Red;
             px.Green = 1.0f - px.Green;
             px.Blue = 1.0f - px.Blue;
             bitmap[x, y] = px;
         }
 }
Ejemplo n.º 14
0
        public SkyBox(IBitmap neg_x, IBitmap pos_x, IBitmap neg_y, IBitmap pos_y, IBitmap neg_z, IBitmap pos_z)
        {
            _config = Constants.Kernel.Get<RenderConfig>();
			
            ITextureAtlasFactory atlasFactory = Constants.Kernel.Get<ITextureAtlasFactory>();
            _atlas = atlasFactory.CreateTextureAtlas(new Size(_config.MaxTextureSize,_config.MaxTextureSize/2), new Size(_config.MaxTextureSize / 4, _config.MaxTextureSize / 4), 1);
            _neg_x = _atlas.AddSubImage(neg_x);
            _pos_x = _atlas.AddSubImage(pos_x);
            _pos_y = _atlas.AddSubImage(pos_y);
            _neg_y = _atlas.AddSubImage(neg_y);
            _pos_z = _atlas.AddSubImage(pos_z);
            _neg_z = _atlas.AddSubImage(neg_z);
        }
Ejemplo n.º 15
0
        public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl = bitmap.PlatformImpl as BitmapImpl;
            var size = new Size(impl.PixelWidth, impl.PixelHeight);
            var scaleX = destRect.Size.Width / sourceRect.Size.Width;
            var scaleY = destRect.Size.Height / sourceRect.Size.Height;

            _context.Save();
            _context.Scale(scaleX, scaleY);
            Gdk.CairoHelper.SetSourcePixbuf(_context, impl.Surface, (int)sourceRect.X, (int)sourceRect.Y);
            _context.Rectangle(sourceRect.ToCairo());
            _context.Fill();
            _context.Restore();
        }
Ejemplo n.º 16
0
        private static void FillCell(IBitmap contraints, IBitmap result, VectorInt2 p)
        {
            if (p.X < 0 || p.Y < 0) return;
            if (p.X > contraints.Size.X || p.Y > contraints.Size.Y) return;

            if (contraints[p]) return;
            if (result[p]) return;

            result[p] = true;

            FillCell(contraints, result, p + VectorInt2.Up);
            FillCell(contraints, result, p + VectorInt2.Down);
            FillCell(contraints, result, p + VectorInt2.Left);
            FillCell(contraints, result, p + VectorInt2.Right);
        }
Ejemplo n.º 17
0
        public GLTexture2D(string name, IBitmap bmp, bool genmipmaps = false, bool linearfilter = false, OpenTK.Graphics.OpenGL.PixelFormat sourceformat = OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelInternalFormat destformat = PixelInternalFormat.Rgba, PixelType sourcetype = PixelType.UnsignedByte)
            : base(name, TextureTarget.Texture2D, bmp.Width, bmp.Height)
        {
            tex = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, tex);

            reattempt_load:
            try {
                /*BitmapData bmpdata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                GL.TexImage2D(TextureTarget.Texture2D, 0, destformat, bmpdata.Width, bmpdata.Height, 0, sourceformat, sourcetype, bmpdata.Scan0);
                bmp.UnlockBits(bmpdata);*/
                bmp.TexImage2D(destformat);
            }
            catch(OutOfMemoryException) {
                GC.WaitForPendingFinalizers();
                goto reattempt_load;
            }

            if(genmipmaps)
            {
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                if(linearfilter)
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                }
                else
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.NearestMipmapNearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                }
            }
            else
            {
                if(linearfilter)
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                }
                else
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                }
            }
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
        }
Ejemplo n.º 18
0
 public RGBLuminanceSource(IBitmap d, int W, int H)
     : base(W, H) {
     int width = __width = W;
     int height = __height = H;
     // In order to measure pure decoding speed, we convert the entire image to a greyscale array
     // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
     luminances = new sbyte[width * height];
     //if (format == PixelFormat.Format8bppIndexed)
     {
         Color c;
         for (int y = 0; y < height; y++) {
             int offset = y * width;
             for (int x = 0; x < width; x++) {
                 c = d.GetPixel(x, y);
                 luminances[offset + x] = (sbyte)(((int)c.R) << 16 | ((int)c.G) << 8 | ((int)c.B));
             }
         }
     }
 }
Ejemplo n.º 19
0
        public static Map<float> AverageOver(Map<float> input, IBitmap within, IBitmap start)
        {
            var res = new Map<float>(input);
            var done = new Bitmap(start);
            var hit = false;
            do
            {
                hit = false;
                foreach (var pos in done.TruePositions())
                {
                    foreach (var dir in VectorInt2.Directions)
                    {
                        var p = pos + dir;
                        if (within[p] && !done[p])
                        {
                            float cc = 0;
                            float total = 0;
                            foreach (var around in VectorInt2.Directions)
                            {
                                var x = p + around;
                                if (within[x]) cc++;
                                if (done[x])
                                {
                                    total += res[x];
                                }
                            }
                            if (cc > 0)
                            {
                                res[p] = total / cc;
                                done[p] = true;
                                hit = true;
                                break;
                            }

                        }
                    }
                }
            } while (hit);

            return res;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Draws a bitmap image.
        /// </summary>
        /// <param name="source">The bitmap image.</param>
        /// <param name="opacity">The opacity to draw with.</param>
        /// <param name="sourceRect">The rect in the image to draw.</param>
        /// <param name="destRect">The rect in the output to draw to.</param>
        public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
			var impl = bitmap.PlatformImpl as BitmapImpl;
			var size = new Size(impl.PixelWidth, impl.PixelHeight);
			var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);

			_context.Save();

			Gdk.CairoHelper.SetSourcePixbuf (
				_context, 
				impl, 
				-sourceRect.X + destRect.X, 
				-sourceRect.Y + destRect.Y);
			impl.Scale (impl, (int)destRect.X, (int)destRect.Y, (int)destRect.Width, (int)destRect.Height, 0, 0, scale.X, scale.Y, Gdk.InterpType.Bilinear);

			_context.PushGroup ();
			_context.Rectangle (destRect.ToCairo ());
			_context.Fill ();
			_context.PopGroupToSource ();
			_context.PaintWithAlpha (opacityOverride);		
			_context.Restore();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Draws a bitmap image.
        /// </summary>
        /// <param name="source">The bitmap image.</param>
        /// <param name="opacity">The opacity to draw with.</param>
        /// <param name="sourceRect">The rect in the image to draw.</param>
        /// <param name="destRect">The rect in the output to draw to.</param>
        public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl = bitmap.PlatformImpl as BitmapImpl;
            var size = new Size(impl.PixelWidth, impl.PixelHeight);
            var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);

            _context.Save();
            _context.Scale(scale.X, scale.Y);
            destRect /= scale;

			if (opacityOverride < 1.0f) {
				_context.PushGroup ();
				Gdk.CairoHelper.SetSourcePixbuf (
					_context, 
					impl.Surface, 
					-sourceRect.X + destRect.X, 
					-sourceRect.Y + destRect.Y);

				_context.Rectangle (destRect.ToCairo ());
				_context.Fill ();
				_context.PopGroupToSource ();
				_context.PaintWithAlpha (opacityOverride);
			} else {
				_context.PushGroup ();
				Gdk.CairoHelper.SetSourcePixbuf (
					_context, 
					impl.Surface, 
					-sourceRect.X + destRect.X, 
					-sourceRect.Y + destRect.Y);

				_context.Rectangle (destRect.ToCairo ());
				_context.Fill ();
				_context.PopGroupToSource ();
				_context.PaintWithAlpha (opacityOverride);			
			}
            _context.Restore();
        }
Ejemplo n.º 22
0
 public static IBitmap FillRectangle(this IBitmap bitmap, int left, int top, int width, int height, byte colour)
 {
     bitmap.Bitmap.FillRectangle(left, top, width, height, colour);
     return(bitmap);
 }
Ejemplo n.º 23
0
 public static IBitmap DrawRectangle(this IBitmap bitmap, Point point, Size size, byte colour = 5) => DrawRectangle3D(bitmap, point.X, point.Y, size.Width, size.Height, colour, colour);
Ejemplo n.º 24
0
 public static IBitmap DrawRectangle3D(this IBitmap bitmap, Rectangle rectangle, byte colourLight    = 15, byte colourDark = 8) => DrawRectangle3D(bitmap, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, colourLight, colourDark);
Ejemplo n.º 25
0
 public static IBitmap DrawLine(this IBitmap bitmap, Point from, Point to, byte colour) => DrawLine(bitmap, from.X, from.Y, to.X, to.Y, colour = 5);
Ejemplo n.º 26
0
 public Cursor(IBitmap cursor, PixelPoint hotSpot)
     : this(GetCursorFactory().CreateCursor(cursor.PlatformImpl.Item, hotSpot))
 {
 }
Ejemplo n.º 27
0
 protected Texture CreateTexture(IBitmap bitmap) => new Texture(_renderer, bitmap?.Palette, bitmap?.Bitmap);
Ejemplo n.º 28
0
 void FormatScans(IBitmap bitmap) {
     for (int index = 0; index < scans.Length; ++index) {
         scans[index].Sort();
         FormatScan(bitmap, index);
     }
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Converts a <see cref="BitmapSource"/> to a splat <see cref="IBitmap"/>.
 /// </summary>
 /// <param name="value">The native bitmap to convert from.</param>
 /// <returns>A <see cref="IBitmap"/> bitmap.</returns>
 public static BitmapSource ToNative(this IBitmap value)
 {
     return(((BitmapSourceBitmap)value).Inner);
 }
Ejemplo n.º 30
0
        private IImage createImage(IBitmap bg)
        {
            var bitmap = bg.ApplyArea(_area);

            return(_factory.Graphics.LoadImage(bitmap));
        }
Ejemplo n.º 31
0
 public IGraphics FromImage(IBitmap bitmap) => Graphics.FromImage(bitmap);
Ejemplo n.º 32
0
        public void DrawBitmap(IBitmap bitmap, CanvasPointF pointF)
        {
            CheckUsability();

            _graphics.DrawImage((Bitmap)bitmap.EngineElement, pointF.ToGdiPointF());
        }
Ejemplo n.º 33
0
 public WindowIcon(IBitmap bitmap)
 {
     PlatformImpl = AvaloniaLocator.Current.GetService <IPlatformIconLoader>().LoadIcon(bitmap.PlatformImpl.Item);
 }
Ejemplo n.º 34
0
 public IBitmap Transform(IBitmap source)
 {
     throw new Exception(DoNotReference);
 }
Ejemplo n.º 35
0
 public static Bitmap ToNative(this IBitmap This)
 {
     return(((BitmapBitmap)This).inner);
 }
Ejemplo n.º 36
0
 public static Vector2[] CreateFromBitmap(IBitmap bitmap) {
     return Reduce(CreateFromBitmap(bitmap, GetFirst(bitmap)));
 }
Ejemplo n.º 37
0
        public static void SaveTiff16(string outputFilename, IBitmap <ushort> bitmap)
        {
            var bitmap2 = bitmap.Convert((p) => { return((ushort)(p - short.MinValue)); });

            SaveTiff16(outputFilename, bitmap2);
        }
Ejemplo n.º 38
0
    private static List<Vector2> CreateFromBitmap(IBitmap bitmap, Vector2 first) {
        Vector2 current = first;
        Vector2 last = first - new Vector2(0, 1);
        List<Vector2> result = new List<Vector2>();
        
        do {
            result.Add(current);
            current = GetNextVertex(bitmap, current, last);
            last = result[result.Count - 1];
        } while (current != first);

        if (result.Count < 3) { 
            throw new ArgumentException("The image has an area with less then 3 pixels (possibly an artifact).", "bitmap"); 
        }

        return result;
    }
Ejemplo n.º 39
0
 public static Vector2D[] CreateFromBitmap(IBitmap bitmap)
 {
     return(Reduce(CreateFromBitmap(bitmap, GetFirst(bitmap))));
 }
Ejemplo n.º 40
0
 private static IEnumerable<Vector2> GetFirsts(IBitmap bitmap, List<BitMapSkipper> skippers) {
     for (int x = bitmap.Width - 1; x > -1; --x) {
         for (int y = 0; y < bitmap.Height; ++y) {
             if (bitmap[x, y]) {
                 bool contains = false;
                 Vector2 result = new Vector2(x, y);
                 for (int index = 0; index < skippers.Count; ++index) {
                     float nextY;
                     if (skippers[index].TryGetSkip(result, out nextY)) {
                         contains = true;
                         y = (int)nextY;
                         break;
                     }
                 }
                 if (!contains) {
                     yield return result;
                 }
             }
         }
     }
 }
Ejemplo n.º 41
0
 public static IBitmap DrawRectangle3D(this IBitmap bitmap, Point point, Size size, byte colourLight = 15, byte colourDark = 8) => DrawRectangle3D(bitmap, point.X, point.Y, size.Width, size.Height, colourLight, colourDark);
Ejemplo n.º 42
0
 public static IBitmap FillRectangle(this IBitmap bitmap, Point point, Size size, byte colour) => FillRectangle(bitmap, point.X, point.Y, size.Width, size.Height, colour);
Ejemplo n.º 43
0
 public static IBitmap DrawRectangle(this IBitmap bitmap, int left = 0, int top = 0, int width = -1, int height = -1, byte colour = 5) => DrawRectangle3D(bitmap, left, top, width, height, colour, colour);
Ejemplo n.º 44
0
 public IBitmap Transform(IBitmap sourceBitmap, string path, ImageSource source, bool isPlaceholder, string key)
 {
     throw new Exception(Common.DoNotReferenceMessage);
 }
Ejemplo n.º 45
0
 public static IBitmap DrawRectangle(this IBitmap bitmap, Rectangle rectangle, byte colour    = 5) => DrawRectangle3D(bitmap, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, colour, colour);
        protected async override Task <WriteableBitmap> GenerateImageAsync(string path, ImageSource source, Stream imageData, ImageInformation imageInformation, bool enableTransformations, bool isPlaceholder)
        {
            BitmapHolder imageIn = null;

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

            ThrowIfCancellationRequested();

            try
            {
                // Special case to handle WebP decoding on Windows
                string ext = null;
                if (!string.IsNullOrWhiteSpace(path))
                {
                    if (source == ImageSource.Url && Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute))
                    {
                        ext = Path.GetExtension(new Uri(path).LocalPath).ToLowerInvariant();
                    }
                    else
                    {
                        ext = Path.GetExtension(path).ToLowerInvariant();
                    }
                }

                bool allowUpscale = Parameters.AllowUpscale ?? Configuration.AllowUpscale;
                if (source != ImageSource.Stream && ext == ".webp")
                {
                    throw new NotImplementedException("Webp is not implemented on Windows");
                }
                else if (enableTransformations && Parameters.Transformations != null && Parameters.Transformations.Count > 0)
                {
                    imageIn = await imageData.ToBitmapHolderAsync(Parameters.DownSampleSize, Parameters.DownSampleUseDipUnits, Parameters.DownSampleInterpolationMode, allowUpscale, imageInformation).ConfigureAwait(false);
                }
                else
                {
                    return(await imageData.ToBitmapImageAsync(Parameters.DownSampleSize, Parameters.DownSampleUseDipUnits, Parameters.DownSampleInterpolationMode, allowUpscale, imageInformation).ConfigureAwait(false));
                }
            }
            finally
            {
                imageData?.Dispose();
            }

            ThrowIfCancellationRequested();

            if (enableTransformations && Parameters.Transformations != null && Parameters.Transformations.Count > 0)
            {
                var transformations = Parameters.Transformations.ToList();

                await _decodingLock.WaitAsync().ConfigureAwait(false); // Applying transformations is both CPU and memory intensive

                try
                {
                    foreach (var transformation in transformations)
                    {
                        ThrowIfCancellationRequested();

                        var old = imageIn;

                        try
                        {
                            IBitmap bitmapHolder = transformation.Transform(imageIn, path, source, isPlaceholder, Key);
                            imageIn = bitmapHolder.ToNative();
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(string.Format("Transformation failed: {0}", transformation.Key), ex);
                            throw;
                        }
                        finally
                        {
                            if (old != null && old != imageIn && old.PixelData != imageIn.PixelData)
                            {
                                old.FreePixels();
                                old = null;
                            }
                        }
                    }
                }
                finally
                {
                    _decodingLock.Release();
                }
            }

            try
            {
                return(await imageIn.ToBitmapImageAsync());
            }
            finally
            {
                imageIn.FreePixels();
                imageIn = null;
            }
        }
Ejemplo n.º 47
0
        protected virtual void AddActionSheetOption(ActionSheetOption opt, UIAlertController controller, UIAlertActionStyle style, IBitmap image = null)
        {
            var alertAction = UIAlertAction.Create(opt.Text, style, x => opt.Action?.Invoke());

            if (opt.ItemIcon == null && image != null)
            {
                opt.ItemIcon = image;
            }

            if (opt.ItemIcon != null)
            {
                alertAction.SetValueForKey(opt.ItemIcon.ToNative(), new NSString("image"));
            }

            controller.AddAction(alertAction);
        }
Ejemplo n.º 48
0
 public override void ShowImage(IBitmap image, string message, int timeoutMillis)
 {
     BTProgressHUD.ShowImage(image.ToNative(), message, timeoutMillis);
     //this.ShowWithOverlay(timeoutMillis, () => BTProgressHUD.ShowImage(image.ToNative(), message, timeoutMillis));
 }
Ejemplo n.º 49
0
 public IBitmap Transform(IBitmap source)
 {
     throw new Exception(Common.DoNotReferenceMessage);
 }
        protected async override Task <WriteableBitmap> GenerateImageAsync(string path, ImageSource source, Stream imageData, ImageInformation imageInformation, bool enableTransformations, bool isPlaceholder)
        {
            BitmapHolder imageIn = null;

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

            ThrowIfCancellationRequested();

            try
            {
                bool allowUpscale = Parameters.AllowUpscale ?? Configuration.AllowUpscale;
                if (source != ImageSource.Stream && imageInformation.Type == ImageInformation.ImageType.WEBP)
                {
                    throw new NotImplementedException("Webp is not implemented on Windows");
                }
                else if (enableTransformations && Parameters.Transformations != null && Parameters.Transformations.Count > 0)
                {
                    imageIn = await imageData.ToBitmapHolderAsync(Parameters.DownSampleSize, Parameters.DownSampleUseDipUnits, Parameters.DownSampleInterpolationMode, allowUpscale, imageInformation).ConfigureAwait(false);
                }
                else
                {
                    return(await imageData.ToBitmapImageAsync(Parameters.DownSampleSize, Parameters.DownSampleUseDipUnits, Parameters.DownSampleInterpolationMode, allowUpscale, imageInformation).ConfigureAwait(false));
                }
            }
            finally
            {
                imageData.TryDispose();
            }

            ThrowIfCancellationRequested();

            if (enableTransformations && Parameters.Transformations != null && Parameters.Transformations.Count > 0)
            {
                var transformations = Parameters.Transformations.ToList();

                await _decodingLock.WaitAsync(CancellationTokenSource.Token).ConfigureAwait(false); // Applying transformations is both CPU and memory intensive

                ThrowIfCancellationRequested();

                try
                {
                    foreach (var transformation in transformations)
                    {
                        ThrowIfCancellationRequested();

                        var old = imageIn;

                        try
                        {
                            IBitmap bitmapHolder = transformation.Transform(imageIn, path, source, isPlaceholder, Key);
                            imageIn = bitmapHolder.ToNative();
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(string.Format("Transformation failed: {0}", transformation.Key), ex);
                            throw;
                        }
                        finally
                        {
                            if (old != null && old != imageIn && old.PixelData != imageIn.PixelData)
                            {
                                old.FreePixels();
                                old = null;
                            }
                        }
                    }
                }
                finally
                {
                    _decodingLock.Release();
                }
            }

            try
            {
                return(await imageIn.ToBitmapImageAsync());
            }
            finally
            {
                imageIn.FreePixels();
                imageIn = null;
            }
        }
Ejemplo n.º 51
0
 public ActionSheetOption(string text, Action action = null, IBitmap icon = null) {
     this.Text = text;
     this.Action = action;
     this.ItemIcon = icon;
 }
Ejemplo n.º 52
0
        /// <summary>
        /// Draws a bitmap image.
        /// </summary>
        /// <param name="source">The bitmap image.</param>
        /// <param name="opacity">The opacity to draw with.</param>
        /// <param name="sourceRect">The rect in the image to draw.</param>
        /// <param name="destRect">The rect in the output to draw to.</param>
        /// <param name="bitmapInterpolationMode">The bitmap interpolation mode.</param>
        public void DrawImage(IBitmap source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = default)
        {
            Contract.Requires <ArgumentNullException>(source != null);

            PlatformImpl.DrawImage(source.PlatformImpl, opacity, sourceRect, destRect, bitmapInterpolationMode);
        }
Ejemplo n.º 53
0
 void FormatScan(IBitmap bitmap, int x) {
     List<float> scan = scans[x];
     List<float> newScan = new List<float>();
     bool inPoly = false;
     for (int index = 0; index < scan.Count; ++index) {
         float y = scan[index];
         if (!inPoly) {
             newScan.Add(y);
         }
         bool value = bitmap[(int)(x + xMin), (int)y + 1];
         if (value) {
             inPoly = true;
         }
         else {
             newScan.Add(y);
             inPoly = false;
         }
     }
     //if (newScan.Count % 2 != 0) { throw new Exception(); }
     scans[x] = newScan;
 }
Ejemplo n.º 54
0
        public void RenderAreaSymbol(RenderContext renderContext, Display display, int priority, IBitmap symbol, PolylineContainer way)
        {
            Point centerPosition = way.CenterAbsolute;

            renderContext.labels.Add(new SymbolContainer(centerPosition, display, priority, symbol));
        }
Ejemplo n.º 55
0
 public static Vector2[][] CreateManyFromBitmap(IBitmap bitmap) {
     List<BitMapSkipper> skippers = new List<BitMapSkipper>();
     List<Vector2[]> result = new List<Vector2[]>();
     foreach (Vector2 first in GetFirsts(bitmap, skippers)) {
         List<Vector2> points = CreateFromBitmap(bitmap, first);
         BitMapSkipper skipper = new BitMapSkipper(bitmap, points);
         skippers.Add(skipper);
         result.Add(Reduce(points));
     }
     return result.ToArray();
 }
Ejemplo n.º 56
0
        public void RenderPointOfInterestSymbol(RenderContext renderContext, Display display, int priority, IBitmap symbol, PointOfInterest poi)
        {
            Point poiPosition = MercatorProjection.GetPixelAbsolute(poi.Position, renderContext.rendererJob.tile.MapSize);

            renderContext.labels.Add(new SymbolContainer(poiPosition, display, priority, symbol));
        }
Ejemplo n.º 57
0
 private static Vector2 GetFirst(IBitmap bitmap) {
     for (int x = bitmap.Width - 1; x > -1; --x) {
         for (int y = 0; y < bitmap.Height; ++y) {
             if (bitmap[x, y]) {
                 return new Vector2(x, y);
             }
         }
     }
     throw new ArgumentException("TODO", "bitmap");
 }
Ejemplo n.º 58
0
 public void RenderWaySymbol(RenderContext renderContext, Display display, int priority, IBitmap symbol, float dy, bool alignCenter, bool repeat, float repeatGap, float repeatStart, bool rotate, PolylineContainer way)
 {
     WayDecorator.RenderSymbol(symbol, display, priority, dy, alignCenter, repeat, repeatGap, repeatStart, rotate, way.CoordinatesAbsolute, renderContext.labels);
 }
Ejemplo n.º 59
0
    private static Vector2 GetNextVertex(IBitmap bitmap, Vector2 current, Vector2 last) {
        int offset = 0;
        Vector2 point;

        for (int index = 0; index < bitmapPoints.Length; ++index) {
            point = current + bitmapPoints[index];
            if (point == last) {
                offset = index + 1;
                break;
            }
        }

        for (int index = 0; index < bitmapPoints.Length; ++index) {
            point = current + bitmapPoints[(index + offset) % bitmapPoints.Length];
            if (point.x >= 0 && point.x < bitmap.Width &&
                point.y >= 0 && point.y < bitmap.Height &&
                bitmap[(int)point.x, (int)point.y]) {
                return point;
            }
        }

        throw new ArgumentException("The image has an area with less then 3 pixels (possibly an artifact).", "bitmap");
    }
Ejemplo n.º 60
0
        public static Path ConvertSolutionNodeToPath(SolverNode node, IBitmap walls, Puzzle puzzle)
        {
            if (node.Evaluator.GetType() == typeof(ReverseEvaluator))
            {
                var pathToRoot = node.PathToRoot().ToList();
                pathToRoot.Reverse();

                var offset = GeneralHelper.OffsetWalk(pathToRoot).ToList();


                var r  = new Path();
                var cc = 0;

                // PuzzleStart to First Push
                var b     = walls.BitwiseOR(puzzle.ToMap(puzzle.Definition.AllCrates));
                var f     = puzzle.Player.Position;
                var t     = pathToRoot[0].PlayerAfter;
                var first = PathFinder.Find(b, f, t);
                if (first == null)
                {
                    //throw new Exception(string.Format("Bad Path at INIT. {0} => {1}. This is an indicator or a FALSE positive. Ie. An invalid start position.\n{2}", f, t, b)); // Not solution
                    return(null);
                }
                r.AddRange(first);

                foreach (var pair in offset)
                {
                    if (pair.Item2.Parent == null)
                    {
                        break;
                    }

                    r.Add(pair.Item1.PlayerBefore - pair.Item1.PlayerAfter);
                    var boundry = walls.BitwiseOR(pair.Item2.CrateMap);
                    var start   = pair.Item1.PlayerBefore;
                    var end     = pair.Item2.PlayerAfter;
                    var walk    = PathFinder.Find(boundry, start, end);
                    if (walk == null)
                    {
                        throw new Exception($"Bad Path at step {cc}\n");               // Not solution
                    }
                    r.AddRange(walk);

                    //Console.WriteLine("PAIR: {0}", cc);
                    //Console.WriteLine("{0} => {1}", pair.Item1.PlayerBefore, pair.Item1.PlayerAfter);
                    //Console.WriteLine(pair.Item1.ToStringDebug());
                    //Console.WriteLine("{0} => {1}", pair.Item2.PlayerBefore, pair.Item2.PlayerAfter);
                    //Console.WriteLine(pair.Item2.ToStringDebug());

                    //var debug = boundry.ToCharMap();
                    //debug[start] = 'S';
                    //debug[end] = 'E';
                    //var d = debug.ToString();
                    //Console.WriteLine(d);
                    //Console.WriteLine(r);
                    cc++;
                }

                if (pathToRoot.Count > 1)
                {
                    var last = pathToRoot[pathToRoot.Count - 2];
                    r.Add(last.PlayerBefore - last.PlayerAfter);
                }


                return(r);
            }

            return(ConvertForwardNodeToPath(node, walls));
        }