public async Task RenderWithBackgroundPassedInConstructor() { var backgroundImage = new ColorImageSource(new Size(100, 100), Color.FromArgb(255, 128, 128, 128)); var layerList = new LayerList(backgroundImage, backgroundImage.ImageSize, new Layer[] { new Layer(LayerStyle.Add(), context => new ColorImageSource(context.BackgroundLayer.ImageSize, Color.FromArgb(255, 32, 16, 8))) }); var layersEffect = await layerList.ToImageProvider().AsTask(); var bitmapRenderer = new BitmapRenderer(layersEffect); var renderedBitmap = await bitmapRenderer.RenderAsync(); var pixels = renderedBitmap.Buffers[0].Buffer.ToArray(); Assert.AreEqual(136, pixels[0]); Assert.AreEqual(144, pixels[1]); Assert.AreEqual(160, pixels[2]); Assert.AreEqual(255, pixels[3]); }
public async Task RenderWithBackgroundAndDifferentRenderSizePassedInToImageProvider() { var layerList = new LayerList(new Layer[] { new Layer(LayerStyle.Add(), context => new ColorImageSource(context.BackgroundLayer.ImageSize, Color.FromArgb(255, 32, 16, 8))) }); var backgroundImage = new ColorImageSource(new Size(100, 100), Color.FromArgb(255, 128, 128, 128)); var layersEffect = await layerList.ToImageProvider(backgroundImage, backgroundImage.Size, new Size(50, 50)).AsTask(); var bitmap = new Bitmap(new Size(50, 50), ColorMode.Bgra8888); await layersEffect.GetBitmapAsync(bitmap, OutputOption.PreserveAspectRatio); var pixels = bitmap.Buffers[0].Buffer.ToArray(); Assert.AreEqual(135, pixels[0]); Assert.AreEqual(143, pixels[1]); Assert.AreEqual(159, pixels[2]); Assert.AreEqual(255, pixels[3]); }
public async Task RenderWithBackgroundPassedInToImageProvider() { var layerList = new LayerList(new Layer[] { new Layer(LayerStyle.Add(), context => new ColorImageSource(context.BackgroundLayer.ImageSize, Color.FromArgb(255, 32, 16, 8))) }); var backgroundImage = new ColorImageSource(new Size(100, 100), Color.FromArgb(255, 128, 128, 128)); var layersEffect = await layerList.ToImageProvider(backgroundImage, backgroundImage.Size).AsTask(); var renderedBitmap = await layersEffect.GetBitmapAsync(null, OutputOption.PreserveAspectRatio); Assert.AreEqual(new Size(100, 100), renderedBitmap.Dimensions); var pixels = renderedBitmap.Buffers[0].Buffer.ToArray(); Assert.AreEqual(135, pixels[0]); Assert.AreEqual(143, pixels[1]); Assert.AreEqual(160, pixels[2]); Assert.AreEqual(255, pixels[3]); }
public void FactoryMethodsGiveCorrectBlendFunction() { Assert.AreEqual(BlendFunction.Normal, LayerStyle.Normal().BlendFunction); Assert.AreEqual(BlendFunction.Add, LayerStyle.Add().BlendFunction); Assert.AreEqual(BlendFunction.Color, LayerStyle.Color().BlendFunction); Assert.AreEqual(BlendFunction.Colorburn, LayerStyle.Colorburn().BlendFunction); Assert.AreEqual(BlendFunction.Colordodge, LayerStyle.Colordodge().BlendFunction); Assert.AreEqual(BlendFunction.Darken, LayerStyle.Darken().BlendFunction); Assert.AreEqual(BlendFunction.Difference, LayerStyle.Difference().BlendFunction); Assert.AreEqual(BlendFunction.Exclusion, LayerStyle.Exclusion().BlendFunction); Assert.AreEqual(BlendFunction.Hardlight, LayerStyle.Hardlight().BlendFunction); Assert.AreEqual(BlendFunction.Hue, LayerStyle.Hue().BlendFunction); Assert.AreEqual(BlendFunction.Lighten, LayerStyle.Lighten().BlendFunction); Assert.AreEqual(BlendFunction.Lineardodge, LayerStyle.Lineardodge().BlendFunction); Assert.AreEqual(BlendFunction.Linearlight, LayerStyle.Linearlight().BlendFunction); Assert.AreEqual(BlendFunction.Multiply, LayerStyle.Multiply().BlendFunction); Assert.AreEqual(BlendFunction.Overlay, LayerStyle.Overlay().BlendFunction); Assert.AreEqual(BlendFunction.Screen, LayerStyle.Screen().BlendFunction); Assert.AreEqual(BlendFunction.Softlight, LayerStyle.Softlight().BlendFunction); Assert.AreEqual(BlendFunction.Vividlight, LayerStyle.Vividlight().BlendFunction); }
public void FactoryMethodsGiveCorrectOpacity() { Assert.AreEqual(0.4, LayerStyle.Normal(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Add(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Color(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Colorburn(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Colordodge(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Darken(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Difference(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Exclusion(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Hardlight(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Hue(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Lighten(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Lineardodge(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Linearlight(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Multiply(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Overlay(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Screen(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Softlight(0.4).Opacity); Assert.AreEqual(0.4, LayerStyle.Vividlight(0.4).Opacity); }
public void FactoryMethodsGiveCorrectTargetArea() { Rect rect = new Rect(1, 2, 3, 4); Assert.AreEqual(rect, LayerStyle.Normal(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Add(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Color(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Colorburn(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Colordodge(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Darken(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Difference(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Exclusion(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Hardlight(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Hue(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Lighten(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Lineardodge(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Linearlight(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Multiply(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Overlay(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Screen(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Softlight(1.0, null, rect).TargetArea); Assert.AreEqual(rect, LayerStyle.Vividlight(1.0, null, rect).TargetArea); }
public void FactoryMethodsGiveCorrectMask() { var mask = new ColorImageSource(new Size(100, 100), Colors.AliceBlue); Assert.AreSame(mask, LayerStyle.Normal(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Add(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Color(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Colorburn(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Colordodge(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Darken(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Difference(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Exclusion(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Hardlight(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Hue(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Lighten(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Lineardodge(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Linearlight(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Multiply(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Overlay(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Screen(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Softlight(1.0, mask).MaskResolver(null).Result); Assert.AreSame(mask, LayerStyle.Vividlight(1.0, mask).MaskResolver(null).Result); }