private void Dispose(bool disposing) { if (disposing) { DisposableUtil.Free <EditableDataWorkItemQueue <PointInt32> >(ref this.workItemQueue); Work.QueueDisposeStream((IEnumerable <IDisposable>) this.tileBuffers.SelectMany <IBitmap <ColorPbgra32> >()); this.tileBuffers = null; this.source = null; } }
public CanvasViewModel3d( IBitmapSource bitmapSource, IScene3D scene3D, ILogger logger, IDispatcherWrapper dispatcherWrapper) { _bitmapSource = bitmapSource; _scene3D = scene3D; _logger = logger; _dispatcherWrapper = dispatcherWrapper; }
public CancellableBitmapSource(IBitmapSource <TPixel> source, Func <RectInt32, IEnumerable <RectInt32> > sourceRectSplitter, Action <RectInt32> rectCompletedCallback, ICancellationToken cancelToken) { Validate.Begin().IsNotNull <IBitmapSource <TPixel> >(source, "source").IsNotNull <Func <RectInt32, IEnumerable <RectInt32> > >(sourceRectSplitter, "sourceRectSplitter").IsNotNull <ICancellationToken>(cancelToken, "cancelToken").Check(); this.source = source.CreateRef <TPixel>(); this.sourceSize = this.source.Size; this.sourceRectSplitter = sourceRectSplitter; this.rectCompletedCallback = rectCompletedCallback; this.cancelToken = cancelToken; TPixel local = default(TPixel); this.bytesPerPixel = local.BytesPerPixel; }
public CanvasViewModel( ILogger logger, IScenePersistenceService scenePersistenceService, IPerformanceProfiler performanceProfiler, IScene2D scene, IBitmapSource bitmapSource, IDispatcherWrapper dispatcherWrapper) { _logger = logger; _scenePersistenceService = scenePersistenceService; _performanceProfiler = performanceProfiler; _scene = scene; _bitmapSource = bitmapSource; _dispatcherWrapper = dispatcherWrapper; }
private static IBitmapSource <ColorPbgra32> CreateBufferedTileScaler(IImagingFactory imagingFactory, IBitmapSource <ColorBgra32> source, int dstWidth, int dstHeight, BitmapInterpolationMode interpolationMode) { IBitmapSource <ColorPbgra32> source5; using (IBitmap <ColorBgra32> bitmap = BitmapAllocator.Bgra32.Allocate <ColorBgra32>(source.Size.Width, imagingFactory.GetBufferBitmapHeight(source, 7), AllocationOptions.Default)) { using (IBitmapSource <ColorBgra32> source2 = imagingFactory.CreateBufferedBitmap <ColorBgra32>(source, bitmap, 7)) { using (IBitmapSource <ColorPbgra32> source3 = imagingFactory.CreateFormatConvertedBitmap <ColorPbgra32>(source2)) { source5 = imagingFactory.CreateBitmapScaler <ColorPbgra32>(source3, dstWidth, dstHeight, interpolationMode); } } } return(source5); }
public DocumentCanvasTileCache(DocumentCanvasLayer owner, IBitmapSource <ColorBgra32> source, int sourceTileEdgeLog2, int mipLevel, bool highQuality) { Validate.Begin().IsNotNull <DocumentCanvasLayer>(owner, "owner").IsNotNull <IBitmapSource <ColorBgra32> >(source, "source").Check(); if (sourceTileEdgeLog2 < 0) { ExceptionUtil.ThrowArgumentOutOfRangeException("sourceTileEdgeLog2"); } if (mipLevel < 0) { ExceptionUtil.ThrowArgumentOutOfRangeException("mipLevel"); } this.syncContext = SynchronizationContext.Current; this.owner = owner; this.source = source; this.sourceSize = this.source.Size; this.sourceBounds = this.source.Bounds(); this.isHighQuality = highQuality; this.tileMathHelper = new PaintDotNet.Rendering.TileMathHelper(this.sourceSize.Width, this.sourceSize.Height, sourceTileEdgeLog2); this.mipLevel = mipLevel; this.tileIsValid = ArrayUtil.Create2D <bool>(this.tileMathHelper.TileRows, this.tileMathHelper.TileColumns); this.invalidTileOffsets = new DequeSet <PointInt32>(); this.tileBuffers = ArrayUtil.Create2D <IBitmap <ColorPbgra32> >(this.tileMathHelper.TileRows, this.tileMathHelper.TileColumns); for (int i = 0; i < this.tileMathHelper.TileRows; i++) { for (int j = 0; j < this.tileMathHelper.TileColumns; j++) { this.invalidTileOffsets.TryEnqueue(new PointInt32(j, i)); } } this.tilesRenderQueue = new DequeSet <PointInt32>(); this.tilesRenderingSet = new HashSet <PointInt32>(); this.tilesRenderingCancelledSet = new ConcurrentSet <PointInt32>(); this.tilesRenderedQueue = new ConcurrentDequeDictionary <PointInt32, RenderedTileInfo>(); this.processTileRenderQueueCallback = new SendOrPostCallback(this.ProcessTileRenderQueueCallback); this.processTileRenderedQueueCallback = new SendOrPostCallback(this.ProcessTileRenderedQueueCallback); this.workItemDispatcher = WorkItemDispatcher.Default; this.workItemQueue = new EditableDataWorkItemQueue <PointInt32>(this.workItemDispatcher, new Action <PointInt32>(this.RenderTileWorkItem)); }
/// <summary> /// Puts the remote call party on hold. /// </summary> public async void PutOnHold(IBitmapSource bmpSource) { await m_userAgent.PutOnHold(); AudioOptions audioOnHold = (!MediaSession.HasAudio) ? null : new AudioOptions { AudioSource = AudioSourcesEnum.Music }; VideoOptions videoOnHold = null; if (MediaSession.HasVideo) { if (bmpSource != null) { videoOnHold = new VideoOptions { VideoSource = VideoSourcesEnum.ExternalBitmap, BitmapSource = bmpSource }; } else { videoOnHold = new VideoOptions { VideoSource = VideoSourcesEnum.TestPattern, SourceFile = RtpAVSession.VIDEO_ONHOLD_TESTPATTERN, SourceFramesPerSecond = VIDEO_ONHOLD_FRAMES_PER_SECOND }; } } await MediaSession.SetSources(audioOnHold, videoOnHold); // At this point we could stop listening to the remote party's RTP and play something // else and also stop sending our microphone output and play some music. StatusMessage(this, "Local party put on hold"); }
public static int GetBufferBitmapHeight(this IImagingFactory factory, IBitmapSource source, int maxBufferHeightLog2 = 7) => Math.Min(((int)1) << maxBufferHeightLog2, source.Size.Height);
public static IBitmapSource <TPixel> CreateFormatConvertedBitmap <TPixel>(this IImagingFactory factory, IBitmapSource source, BitmapDitherType dither, IPalette palette, double alphaThresholdPercent, BitmapPaletteType paletteTranslate) where TPixel : struct, INaturalPixelInfo { TPixel local = default(TPixel); return((IBitmapSource <TPixel>)factory.CreateFormatConvertedBitmap(source, local.PixelFormat, dither, palette, alphaThresholdPercent, paletteTranslate)); }
public static IBitmapSource CreateFormatConvertedBitmap(this IImagingFactory factory, IBitmapSource source, PixelFormat dstFormat) => factory.CreateFormatConvertedBitmap(source, dstFormat, BitmapDitherType.None, null, 0.0, BitmapPaletteType.Custom);
public static IBitmapSource <TPixel> CreateFormatConvertedBitmap <TPixel>(this IImagingFactory factory, IBitmapSource source) where TPixel : struct, INaturalPixelInfo => factory.CreateFormatConvertedBitmap <TPixel>(source, BitmapDitherType.None, null, 0.0, BitmapPaletteType.Custom);
public static IBitmapSource <TPixel> CreateBufferedBitmap <TPixel>(this IImagingFactory factory, IBitmapSource <TPixel> source, IBitmap <TPixel> buffer = null, int maxBufferHeightLog2 = 7) where TPixel : struct, INaturalPixelInfo => ((IBitmapSource <TPixel>)factory.CreateBufferedBitmap(source, buffer, maxBufferHeightLog2));
public IBitmapSource CreateBufferedBitmap(IBitmapSource source, IBitmap buffer, int maxBufferHeightLog2) => base.innerRefT.CreateBufferedBitmap(source, buffer, maxBufferHeightLog2);
private unsafe void RenderTileWorkItem(PointInt32 tileOffset) { IBitmap <ColorPbgra32> bitmap; bool isCancelled = false; bool flag = false; Exception error = null; isCancelled |= this.IsTileRenderingCancelled(tileOffset); if (isCancelled) { bitmap = null; } else { RectInt32 tileSourceRect = this.tileMathHelper.GetTileSourceRect(tileOffset); SizeInt32 tileBufferSize = this.GetTileBufferSize(tileOffset); bitmap = RetryManager.Eval <IBitmap <ColorPbgra32> >(3, () => BitmapAllocator.Pbgra32.Allocate(tileBufferSize, AllocationOptions.Default), delegate(Exception _) { CleanupManager.RequestCleanup(); Thread.Sleep(200); CleanupManager.WaitForPendingCleanup(); }, delegate(AggregateException ex) { throw new AggregateException($"could not allocate a bitmap of size {tileBufferSize.Width} x {tileBufferSize.Height}", ex).Flatten(); }); if (this.source != null) { try { isCancelled |= this.IsTileRenderingCancelled(tileOffset); if (!isCancelled) { using (IBitmapLock <ColorPbgra32> @lock = bitmap.Lock <ColorPbgra32>(BitmapLockOptions.ReadWrite)) { if (this.mipLevel == 0) { this.source.CopyPixels(new RectInt32?(tileSourceRect), @lock); RenderingKernels.ConvertBgra32ToPbgra32((uint *)@lock.Scan0, tileBufferSize.Width, tileBufferSize.Height, @lock.Stride); flag = true; } else { BitmapInterpolationMode linear; if (!this.isHighQuality) { linear = BitmapInterpolationMode.Linear; } else if (this.mipLevel == 1) { linear = BitmapInterpolationMode.Linear; } else { linear = BitmapInterpolationMode.Fant; } IImagingFactory instance = ImagingFactory.Instance; ICancellationToken cancelToken = CancellationTokenUtil.Create((Func <bool>)(() => (isCancelled | this.IsTileRenderingCancelled(tileOffset)))); int copyHeightLog2 = Math.Max(3, 7 - this.mipLevel); using (ClippedBitmapSource <ColorBgra32> source2 = new ClippedBitmapSource <ColorBgra32>(this.source, tileSourceRect)) { using (CancellableBitmapSource <ColorBgra32> source3 = new CancellableBitmapSource <ColorBgra32>(source2, r => this.tileMathHelper.EnumerateTilesClippedToSourceRect(r), null, cancelToken)) { using (IBitmapSource <ColorPbgra32> source4 = CreateBufferedTileScaler(instance, source3, tileBufferSize.Width, tileBufferSize.Height, linear)) { using (CancellableBitmapSource <ColorPbgra32> source5 = new CancellableBitmapSource <ColorPbgra32>(source4, r => TileRectSplitter(r, ((int)1) << copyHeightLog2), null, cancelToken)) { try { source5.CopyPixels <ColorPbgra32>(@lock); flag = true; } catch (OperationCanceledException exception2) { error = exception2; isCancelled = true; } catch (Exception exception3) { error = exception3; throw; } } } } } } isCancelled |= this.IsTileRenderingCancelled(tileOffset); if (isCancelled) { flag = false; } } if (!flag) { DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref bitmap); } } } catch (OperationCanceledException exception4) { error = exception4; isCancelled = true; } catch (Exception exception5) { error = exception5; isCancelled |= this.IsTileRenderingCancelled(tileOffset); if (!isCancelled) { using (IDrawingContext context = DrawingContext.FromBitmap(bitmap, FactorySource.PerThread)) { context.Clear(new ColorRgba128Float?((ColorRgba128Float)Colors.White)); string text = exception5.ToString(); using (ISystemFonts fonts = new SystemFonts(true)) { TextLayout textLayout = UIText.CreateLayout(context, text, fonts.Caption, null, HotkeyRenderMode.Ignore, (double)bitmap.Size.Width, 65535.0); textLayout.FontSize *= 0.6; textLayout.WordWrapping = WordWrapping.Wrap; context.DrawTextLayout(PointDouble.Zero, textLayout, SolidColorBrushCache.Get((ColorRgba128Float)Colors.Black), DrawTextOptions.None); } } flag = true; } } } } isCancelled |= this.IsTileRenderingCancelled(tileOffset); if (isCancelled) { DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref bitmap); } RenderedTileInfo info = new RenderedTileInfo(bitmap, !isCancelled && (bitmap > null), error); if (!this.tilesRenderedQueue.TryEnqueue(tileOffset, info)) { ExceptionUtil.ThrowInternalErrorException("Could not enqueue to this.tilesRenderedQueue"); } if (Interlocked.Exchange(ref this.isProcessTileRenderedQueueQueued, 1) == 0) { this.syncContext.Post(this.processTileRenderedQueueCallback); } }
public IDeviceBitmap CreateDeviceBitmapFromBitmap(IBitmapSource bitmapSource, BitmapProperties?bitmapProperties) => base.innerRefT.CreateDeviceBitmapFromBitmap(bitmapSource, bitmapProperties);
public static IBitmapSource CreateRef(this IBitmapSource objectRef) => ((IBitmapSource)objectRef.CreateRef(typeof(IBitmapSource)));
public static IBitmapSource <TPixel> CreateRef <TPixel>(this IBitmapSource <TPixel> objectRef) where TPixel : struct, INaturalPixelInfo => ((IBitmapSource <TPixel>)objectRef.CreateRef(typeof(IBitmapSource <TPixel>)));
public BitmapSourceProxy(IBitmapSource <TPixel> objectRef, ObjectRefProxyOptions proxyOptions) : base(objectRef, proxyOptions) { }
public void WriteSource(IBitmapSource bitmapSource, RectInt32?rect) { base.innerRefT.WriteSource(bitmapSource, rect); }
public IBitmapSource CreateInstance(IBitmapSource source, PixelFormat dstFormat, BitmapDitherType dither, IPalette palette, double alphaThresholdPercent, BitmapPaletteType paletteTranslate) => base.innerRefT.CreateInstance(source, dstFormat, dither, palette, alphaThresholdPercent, paletteTranslate);
public IBitmapSource CreateBitmapScaler(IBitmapSource source, int dstWidth, int dstHeight, BitmapInterpolationMode mode) => base.innerRefT.CreateBitmapScaler(source, dstWidth, dstHeight, mode);
public IBitmap CreateBitmapFromSource(IBitmapSource bitmapSource, BitmapCreateCacheOption option) => base.innerRefT.CreateBitmapFromSource(bitmapSource, option);
public IBitmap CreateBitmapFromSourceRect(IBitmapSource bitmapSource, RectInt32 sourceRect) => base.innerRefT.CreateBitmapFromSourceRect(bitmapSource, sourceRect);
public static IBitmapSource <TPixel> CreateBitmapScaler <TPixel>(this IImagingFactory factory, IBitmapSource <TPixel> source, int dstWidth, int dstHeight, BitmapInterpolationMode mode) where TPixel : struct, INaturalPixelInfo => ((IBitmapSource <TPixel>)factory.CreateBitmapScaler(source, dstWidth, dstHeight, mode));
public static IBitmapSource <TPixel> CreateBitmapClipper <TPixel>(this IImagingFactory factory, IBitmapSource <TPixel> source, RectInt32 rect) where TPixel : struct, INaturalPixelInfo => ((IBitmapSource <TPixel>)factory.CreateBitmapClipper(source, rect));
public IBitmapSource CreateColorTransformedBitmap(IBitmapSource source, IColorContext sourceContext, IColorContext dstContext, PixelFormat dstPixelFormat) => base.innerRefT.CreateColorTransformedBitmap(source, sourceContext, dstContext, dstPixelFormat);
public ClippedBitmapSource(IBitmapSource <TPixel> source, RectInt32 sourceRect) { Validate.Begin().IsNotNull <IBitmapSource <TPixel> >(source, "source").Check().IsTrue(source.Bounds().Contains(sourceRect), "source.Bounds().Contains(sourceRect)").Check(); this.source = source.CreateRef <TPixel>(); this.sourceRect = sourceRect; }
public static IBitmapSource <TPixel> CreateBitmapFlipRotator <TPixel>(this IImagingFactory factory, IBitmapSource <TPixel> source, BitmapTransformOptions options) where TPixel : struct, INaturalPixelInfo => ((IBitmapSource <TPixel>)factory.CreateBitmapFlipRotator(source, options));
public static IBitmap <TPixel> CreateBitmapFromSourceRect <TPixel>(this IImagingFactory factory, IBitmapSource <TPixel> source, RectInt32 sourceRect) where TPixel : struct, INaturalPixelInfo => ((IBitmap <TPixel>)factory.CreateBitmapFromSourceRect(source, sourceRect));
public IBitmapSource CreateBitmapFlipRotator(IBitmapSource source, BitmapTransformOptions options) => base.innerRefT.CreateBitmapFlipRotator(source, options);