private static IReadOnlyList <IImageProvider> CreateFramedAnimation(IReadOnlyList <IImageProvider> images, Rect animationBounds, int w, int h) { List <IImageProvider> framedAnimation = new List <IImageProvider>(); foreach (IImageProvider frame in images) { FilterEffect cropFilterEffect = new FilterEffect(frame); cropFilterEffect.Filters = new List <IFilter>() { new CropFilter(animationBounds) }; FilterEffect blendFilterEffect = new FilterEffect(images[0]); BlendFilter blendFilter = new BlendFilter(); blendFilter.ForegroundSource = cropFilterEffect; blendFilter.Level = 1.0; blendFilter.BlendFunction = BlendFunction.Normal; blendFilter.TargetArea = new Rect( animationBounds.Left / w, animationBounds.Top / h, animationBounds.Width / w, animationBounds.Height / h ); blendFilterEffect.Filters = new List <IFilter>() { blendFilter }; framedAnimation.Add(blendFilterEffect); } return(framedAnimation); }
private static IReadOnlyList <IImageProvider> CreateFramedAnimation(IReadOnlyList <IImageProvider> images, Rect animationBounds, int w, int h) { List <IImageProvider> framedAnimation = new List <IImageProvider>(); WriteableBitmap maskBitmap = new WriteableBitmap(w, h); var backgroundRectangle = new Rectangle { Fill = new SolidColorBrush(Colors.Black), Width = w, Height = h, }; maskBitmap.Render(backgroundRectangle, new TranslateTransform()); var foregroundRectangle = new Rectangle { Fill = new SolidColorBrush(Colors.White), Width = animationBounds.Width, Height = animationBounds.Height, }; TranslateTransform foregroundTranslate = new TranslateTransform { X = animationBounds.X, Y = animationBounds.Y }; maskBitmap.Render(foregroundRectangle, foregroundTranslate); maskBitmap.Invalidate(); foreach (IImageProvider frame in images) { FilterEffect filterEffect = new FilterEffect(images[0]); BlendFilter blendFilter = new BlendFilter(frame, BlendFunction.Normal, 1.0) { MaskSource = new BitmapImageSource(maskBitmap.AsBitmap()) }; filterEffect.Filters = new List <IFilter>() { blendFilter }; framedAnimation.Add(filterEffect); } return(framedAnimation); }
public FloatingImage Filter(BlendFilter Filter, FloatingImage Image) { int Width = _Pixels.GetLength(0); int Height = _Pixels.GetLength(1); FloatingColor[,] NewPixels = new FloatingColor[Width, Height]; for (int i = 0; i < Width; ++i) { for (int j = 0; j < Height; ++j) { NewPixels[i, j] = Filter.Filter(this[i, j], Image[i, j]); } } return(new FloatingImage() { _Pixels = NewPixels }); }
public Brush(int Radius, Interpolator.InterpolatorFunction Interpolator, BlendFilter BlendMode, FloatingColor Color) { this.Radius = Radius; int Width = Radius * 2 + 1; this.Color = Color; this.BlendMode = BlendMode; Matrix = new float[Width, Width]; for (int i = 0; i < Width; ++i) { for (int j = 0; j < Width; ++j) { int X = i - Radius; int Y = j - Radius; double Dist = Math.Sqrt(X * X + Y * Y) / Radius; if (Dist > 1) { Dist = 1; } Matrix[i, j] = (float)Interpolator(Dist); } } }
private async Task <IVideoEffectDefinition> CreateEffectDefinitionAsync(VideoEncodingProperties props) { switch (EffectType.SelectedIndex) { case 0: return(new LumiaEffectDefinition(() => { return new IFilter[] { new AntiqueFilter(), new FlipFilter(FlipMode.Horizontal) }; })); case 1: IBuffer shaderY = await PathIO.ReadBufferAsync("ms-appx:///Invert_093_NV12_Y.cso"); IBuffer shaderUV = await PathIO.ReadBufferAsync("ms-appx:///Invert_093_NV12_UV.cso"); return(new ShaderEffectDefinitionNv12(shaderY, shaderUV)); case 2: IBuffer shader = await PathIO.ReadBufferAsync("ms-appx:///Invert_093_RGB32.cso"); return(new ShaderEffectDefinitionBgrx8(shader)); case 3: // Select the largest centered square area in the input video uint inputWidth = props.Width; uint inputHeight = props.Height; uint outputLength = Math.Min(inputWidth, inputHeight); Rect cropArea = new Rect( (float)((inputWidth - outputLength) / 2), (float)((inputHeight - outputLength) / 2), (float)outputLength, (float)outputLength ); var definition = new LumiaEffectDefinition(new FilterChainFactory(() => { var filters = new List <IFilter>(); filters.Add(new CropFilter(cropArea)); return(filters); })); definition.InputWidth = inputWidth; definition.InputHeight = inputHeight; definition.OutputWidth = outputLength; definition.OutputHeight = outputLength; return(definition); case 4: return(new SquareEffectDefinition()); case 5: var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/traffic.png")); var foreground = new StorageFileImageSource(file); return(new LumiaEffectDefinition(() => { #pragma warning disable 618 var filter = new BlendFilter(foreground); filter.TargetOutputOption = OutputOption.PreserveAspectRatio; filter.TargetArea = new Rect(0, 0, .4, .4); return new IFilter[] { filter }; })); case 6: return(new LumiaEffectDefinition(() => { return new AnimatedWarp(); })); case 7: return(new LumiaEffectDefinition(() => { return new BitmapEffect(); })); case 8: return(new LumiaEffectDefinition(() => { return new BitmapEffect2(); })); case 9: return(new CanvasEffectDefinition(() => { return new CanvasEffect(); })); default: throw new ArgumentException("Invalid effect type"); } }
private static IReadOnlyList<IImageProvider> CreateFramedAnimation(IReadOnlyList<IImageProvider> images, Rect animationBounds, int w, int h) { List<IImageProvider> framedAnimation = new List<IImageProvider>(); WriteableBitmap maskBitmap = new WriteableBitmap(w, h); var backgroundRectangle = new Rectangle { Fill = new SolidColorBrush(Colors.Black), Width = w, Height = h, }; maskBitmap.Render(backgroundRectangle, new TranslateTransform()); var foregroundRectangle = new Rectangle { Fill = new SolidColorBrush(Colors.White), Width = animationBounds.Width, Height = animationBounds.Height, }; TranslateTransform foregroundTranslate = new TranslateTransform { X = animationBounds.X, Y = animationBounds.Y }; maskBitmap.Render(foregroundRectangle, foregroundTranslate); maskBitmap.Invalidate(); foreach (IImageProvider frame in images) { FilterEffect filterEffect = new FilterEffect(images[0]); BlendFilter blendFilter = new BlendFilter(frame, BlendFunction.Normal, 1.0) { MaskSource = new BitmapImageSource(maskBitmap.AsBitmap()) }; filterEffect.Filters = new List<IFilter>() { blendFilter }; framedAnimation.Add(filterEffect); } return framedAnimation; }
private async void AttemptUpdatePreviewAsync2() { if (!Processing) { Processing = true; Model.OriginalImage.Position = 0; using (var source = new StreamImageSource(Model.OriginalImage)) using (var segmenter = new InteractiveForegroundSegmenter(source)) using (var annotationsSource = new BitmapImageSource(Model.AnnotationsBitmap)) { segmenter.Quality = 0.5; segmenter.Source = source; segmenter.AnnotationsSource = annotationsSource; var foregroundColor = Model.ForegroundBrush.Color; var backgroundColor = Model.BackgroundBrush.Color; segmenter.ForegroundColor = Windows.UI.Color.FromArgb(foregroundColor.A, foregroundColor.R, foregroundColor.G, foregroundColor.B); segmenter.BackgroundColor = Windows.UI.Color.FromArgb(backgroundColor.A, backgroundColor.R, backgroundColor.G, backgroundColor.B); do { _processingPending = false; var previewBitmap = new WriteableBitmap((int)Model.AnnotationsBitmap.Dimensions.Width, (int)Model.AnnotationsBitmap.Dimensions.Height); using (var backgroundSource = new StreamImageSource(Model.OriginalImage2)) using (var filterEffect = new FilterEffect(backgroundSource)) using (var blendFilter = new BlendFilter(source)) using (var renderer = new WriteableBitmapRenderer(filterEffect, previewBitmap)) { blendFilter.BlendFunction = BlendFunction.Normal; blendFilter.MaskSource = segmenter; filterEffect.Filters = new IFilter[] { blendFilter }; try { await renderer.RenderAsync(); } catch { } var wb = previewBitmap; var fileStream = new MemoryStream(); wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 100, 100); fileStream.Seek(0, SeekOrigin.Begin); var effect = new LensBlurEffect(new StreamImageSource(fileStream), new LensBlurPredefinedKernel(LensBlurPredefinedKernelShape.Circle, 10)); var renderer2 = new WriteableBitmapRenderer(effect, previewBitmap); effect.KernelMap = segmenter; try { await renderer2.RenderAsync(); } catch { } PreviewImage.Source = previewBitmap; wb = previewBitmap; fileStream = new MemoryStream(); wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 100, 100); fileStream.Seek(0, SeekOrigin.Begin); // var m = new MediaLibrary(); // m.SavePictureToCameraRoll("test", fileStream); Model.MixedStream = fileStream; // Model.MixedStream = ConvertToStream(previewBitmap); previewBitmap.Invalidate(); } } while (_processingPending); } Processing = false; } else { _processingPending = true; } }
private static IReadOnlyList<IImageProvider> CreateFramedAnimation(IReadOnlyList<IImageProvider> images, Rect animationBounds, int w, int h) { List<IImageProvider> framedAnimation = new List<IImageProvider>(); foreach (IImageProvider frame in images) { FilterEffect cropFilterEffect = new FilterEffect(frame); cropFilterEffect.Filters = new List<IFilter>() { new CropFilter(animationBounds) }; FilterEffect blendFilterEffect = new FilterEffect(images[0]); BlendFilter blendFilter = new BlendFilter(); blendFilter.ForegroundSource = cropFilterEffect; blendFilter.Level = 1.0; blendFilter.BlendFunction = BlendFunction.Normal; blendFilter.TargetArea = new Rect( animationBounds.Left / w, animationBounds.Top / h, animationBounds.Width / w, animationBounds.Height / h ); blendFilterEffect.Filters = new List<IFilter>() { blendFilter }; framedAnimation.Add(blendFilterEffect); } return framedAnimation; }
private async Task<IVideoEffectDefinition> CreateEffectDefinitionAsync(VideoEncodingProperties props) { switch (EffectType.SelectedIndex) { case 0: return new LumiaEffectDefinition(() => { return new IFilter[] { new AntiqueFilter(), new FlipFilter(FlipMode.Horizontal) }; }); case 1: IBuffer shaderY = await PathIO.ReadBufferAsync("ms-appx:///Invert_093_NV12_Y.cso"); IBuffer shaderUV = await PathIO.ReadBufferAsync("ms-appx:///Invert_093_NV12_UV.cso"); return new ShaderEffectDefinitionNv12(shaderY, shaderUV); case 2: IBuffer shader = await PathIO.ReadBufferAsync("ms-appx:///Invert_093_RGB32.cso"); return new ShaderEffectDefinitionBgrx8(shader); case 3: // Select the largest centered square area in the input video uint inputWidth = props.Width; uint inputHeight = props.Height; uint outputLength = Math.Min(inputWidth, inputHeight); Rect cropArea = new Rect( (float)((inputWidth - outputLength) / 2), (float)((inputHeight - outputLength) / 2), (float)outputLength, (float)outputLength ); var definition = new LumiaEffectDefinition(new FilterChainFactory(() => { var filters = new List<IFilter>(); filters.Add(new CropFilter(cropArea)); return filters; })); definition.InputWidth = inputWidth; definition.InputHeight = inputHeight; definition.OutputWidth = outputLength; definition.OutputHeight = outputLength; return definition; case 4: return new SquareEffectDefinition(); case 5: var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/traffic.png")); var foreground = new StorageFileImageSource(file); return new LumiaEffectDefinition(() => { #pragma warning disable 618 var filter = new BlendFilter(foreground); filter.TargetOutputOption = OutputOption.PreserveAspectRatio; filter.TargetArea = new Rect(0, 0, .4, .4); return new IFilter[] { filter }; }); case 6: return new LumiaEffectDefinition(() => { return new AnimatedWarp(); }); case 7: return new LumiaEffectDefinition(() => { return new BitmapEffect(); }); case 8: return new LumiaEffectDefinition(() => { return new BitmapEffect2(); }); case 9: return new CanvasEffectDefinition(() => { return new CanvasEffect(); }); default: throw new ArgumentException("Invalid effect type"); } }
private static State <FilterChainState, IEnumerable <XElement> > BuildBlendFilter(BlendFilter blendFilter, CoordinatesConverter converter) { var builder = XElementBuilder.WithName("feBlend") .Add( new XAttribute("mode", blendFilter.BlendModeSvgName)); return(BuildTwoInputFilter(builder, blendFilter.Source2, converter)); }