private LayerContext CreateFakeLayerContext(Layer backgroundLayer, IImageProvider backgroundImage, Layer layer)
 {
     var invariants = new LayerContext.Invariants(backgroundLayer, new MaybeTask<IImageProvider>(backgroundImage), new Size(0, 0));
     var layerContext = new LayerContext(invariants, backgroundLayer, layer, 1);
     layerContext.PreviousImage = layerContext.BackgroundImage;
     return layerContext;
 }
 private LayerContext CreateFakeLayerContext(Layer layer)
 {
     var backgroundImage = new ColorImageSource(BackgroundLayerSize, Colors.AliceBlue);
     var backgroundLayer = new Layer(LayerStyle.Normal(), backgroundImage, BackgroundLayerSize);
     var invariants = new LayerContext.Invariants(backgroundLayer, new MaybeTask<IImageProvider>(backgroundImage), new Size(0, 0));
     var layerContext = new LayerContext(invariants, backgroundLayer, layer, 1);
     layerContext.PreviousImage = layerContext.BackgroundImage;
     return layerContext;
 }
 private IImageProvider CreateTestEffect(LayerContext layerContext)
 {
     return new FilterEffect() 
     {
         Filters = new IFilter[] 
         { 
             new ReframingFilter(new Rect(new Point(0,0), layerContext.BackgroundLayer.ImageSize), 0.0) 
         } 
     };
 }
        /// <summary>
        /// Resolve a MaybeTask&lt;IImageProvider&gt; that represents the whole layer stack.
        /// </summary>
        /// <param name="backgroundImage">A MaybeTask&lt;IImageProvider&gt; resulting in the image to use for the background layer.</param>
        /// <param name="backgroundImageSize">Optionally, the size of the background image. If omitted, the natural size of the source will be used, but the size will not available in the LayerLinkingContext for lazy resolvers.</param>
        /// <param name="renderSizeHint">Optionally, the size of image that the layer stack will be rendered to. Note that this is just a hint, the resulting <see cref="IImageProvider" /> should also be rendered at this size by the user.</param>
        /// <returns>An IImageProvider that represents the whole layer stack.</returns>
        public MaybeTask <IImageProvider> ToImageProvider(MaybeTask <IImageProvider> backgroundImage, Size backgroundImageSize = default(Size), Size renderSizeHint = default(Size))
        {
            var backgroundLayer = GetActiveBackgroundLayer(backgroundImage, backgroundImageSize);

            var layerContextInvariants = new LayerContext.Invariants(backgroundLayer, backgroundImage, renderSizeHint);

            var layerContexts = new LayerContext[Count];

            layerContexts[0] = new LayerContext(layerContextInvariants, null, backgroundLayer, 0);

            backgroundImage = backgroundLayer.GetImageProvider(layerContexts[0]);

            var currentImage = backgroundImage;

            for (int layerIndex = 1; layerIndex < layerContexts.Length; ++layerIndex)
            {
                Debug.WriteLine("Resolving layer " + layerIndex);

                var context = new LayerContext(layerContextInvariants, layerContexts[layerIndex - 1].CurrentLayer, this[layerIndex], layerIndex);

                context.PreviousImage = currentImage;

                currentImage = context.CurrentLayer.GetImageProvider(context);
                Debug.Assert(!currentImage.IsEmpty, "Resolved imageprovider is null.");

                // Bind the previous image as the source of the current one.
                currentImage = LayerSource.Bind(currentImage, context.PreviousImage);

                // If blending is used, wrap the current image in a BlendEffect and bind the source to it as well.
                var blendedCurrentImage = LayerBlend.Apply(context, currentImage);
                if (!blendedCurrentImage.IsEmpty)
                {
                    blendedCurrentImage = LayerSource.Bind(blendedCurrentImage, context.PreviousImage);
                    currentImage        = blendedCurrentImage;
                }

                layerContexts[layerIndex] = context;
            }

            Debug.WriteLine("Resolved final image provider.");

            return(currentImage);
        }
 private Task<IImageProvider> CreateTestImageProviderAsync(LayerContext layerContext)
 {
     return Task.Factory.StartNew<IImageProvider>(() => (IImageProvider)new ColorImageSource(layerContext.BackgroundLayer.ImageSize, Colors.Red), TaskCreationOptions.LongRunning);
 }
 private IImageProvider CreateTestImageProvider(LayerContext layerContext)
 {
     return new ColorImageSource(layerContext.BackgroundLayer.ImageSize, Colors.Red);
 }
 private Task<IImageProvider> CreateTestEffectAsync(LayerContext layerContext)
 {
     return Task.Factory.StartNew<IImageProvider>(() => new FilterEffect() { Filters = new IFilter[] { new ReframingFilter(new Rect(new Point(0, 0), layerContext.BackgroundLayer.ImageSize), 0.0) } });
 }
 private IImageProvider CreateTestEffect(LayerContext layerContext)
 {
     return new ReframingEffect(new Rect(new Point(0,0), layerContext.BackgroundLayer.ImageSize), 0.0);
 }