public void ShouldTrimTheBackground() { using (var image = new MagickImage("xc:fuchsia", 50, 50)) { ColorAssert.Equal(MagickColors.Fuchsia, image, 0, 0); ColorAssert.Equal(MagickColors.Fuchsia, image, 49, 49); image.Extent(100, 60, Gravity.Center, MagickColors.Gold); Assert.Equal(100, image.Width); Assert.Equal(60, image.Height); ColorAssert.Equal(MagickColors.Gold, image, 0, 0); ColorAssert.Equal(MagickColors.Fuchsia, image, 50, 30); image.Trim(); Assert.Equal(50, image.Width); Assert.Equal(50, image.Height); ColorAssert.Equal(MagickColors.Fuchsia, image, 0, 0); ColorAssert.Equal(MagickColors.Fuchsia, image, 49, 49); } }
public void Test_OptimizePlus() { using (MagickImageCollection collection = new MagickImageCollection()) { ExceptionAssert.Throws <InvalidOperationException>(delegate() { collection.OptimizePlus(); }); collection.Add(new MagickImage(MagickColors.Red, 11, 11)); /* the second image will not be removed if it is a duplicate so we * need to add an extra one. */ collection.Add(new MagickImage(MagickColors.Red, 11, 11)); collection.Add(new MagickImage(MagickColors.Red, 11, 11)); MagickImage image = new MagickImage(MagickColors.Red, 11, 11); using (var pixels = image.GetPixels()) { pixels.Set(5, 5, new QuantumType[] { 0, Quantum.Max, 0 }); } collection.Add(image); collection.OptimizePlus(); Assert.AreEqual(3, collection.Count); Assert.AreEqual(1, collection[1].Width); Assert.AreEqual(1, collection[1].Height); Assert.AreEqual(-1, collection[1].Page.X); Assert.AreEqual(-1, collection[1].Page.Y); ColorAssert.AreEqual(MagickColors.Red, collection[1], 0, 0); Assert.AreEqual(1, collection[2].Width); Assert.AreEqual(1, collection[2].Height); Assert.AreEqual(5, collection[2].Page.X); Assert.AreEqual(5, collection[2].Page.Y); ColorAssert.AreEqual(MagickColors.Lime, collection[2], 0, 0); } }
public void ShouldCorrectlyOptimizeTheImages() { using (IMagickImageCollection collection = new MagickImageCollection()) { collection.Add(new MagickImage(MagickColors.Red, 11, 11)); var image = new MagickImage(MagickColors.Red, 11, 11); using (var pixels = image.GetPixels()) { pixels.SetPixel(5, 5, new QuantumType[] { 0, Quantum.Max, 0 }); } collection.Add(image); collection.Optimize(); Assert.AreEqual(1, collection[1].Width); Assert.AreEqual(1, collection[1].Height); Assert.AreEqual(5, collection[1].Page.X); Assert.AreEqual(5, collection[1].Page.Y); ColorAssert.AreEqual(MagickColors.Lime, collection[1], 0, 0); } }
public void Test_FillRule() { using (IMagickImage image = new MagickImage(MagickColors.SkyBlue, 100, 60)) { Assert.AreEqual(FillRule.EvenOdd, image.Settings.FillRule); image.Settings.FillRule = FillRule.Nonzero; image.Settings.FillColor = MagickColors.White; image.Settings.StrokeColor = MagickColors.Black; image.Draw(new DrawablePath( new PathMoveToAbs(40, 10), new PathLineToAbs(20, 20), new PathLineToAbs(70, 50), new PathClose(), new PathMoveToAbs(20, 40), new PathLineToAbs(70, 40), new PathLineToAbs(90, 10), new PathClose())); ColorAssert.AreEqual(MagickColors.White, image, 50, 30); } }
public void ShouldAddCorrectLineBreaks2() { var caption = "caption:tex1_124x40_3a277be1b9da51b7_2d0d8f84dc3ccc36_8"; var readSettings = new MagickReadSettings { BackgroundColor = MagickColors.Transparent, FontPointsize = 39, FillColor = MagickColors.Red, TextUnderColor = MagickColors.Green, TextGravity = Gravity.Center, Width = 450, }; using (var image = new MagickImage(caption, readSettings)) { ColorAssert.Equal(MagickColors.Green, image, 170, 67); ColorAssert.Equal(MagickColors.Red, image, 444, 26); ColorAssert.Equal(MagickColors.Red, image, 395, 55); ColorAssert.Equal(MagickColors.Red, image, 231, 116); ColorAssert.Equal(new MagickColor("#0000"), image, 170, 93); } }
public void ShouldCopyTheAlphaChannelWithCopyAlpha() { var readSettings = new MagickReadSettings() { BackgroundColor = MagickColors.None, FillColor = MagickColors.White, FontPointsize = 100, }; using (IMagickImage image = new MagickImage("label:Test", readSettings)) { using (IMagickImage alpha = image.Clone()) { alpha.Alpha(AlphaOption.Extract); alpha.Shade(130, 30); alpha.Composite(image, CompositeOperator.CopyAlpha); ColorAssert.AreEqual(new MagickColor("#7fff7fff7fff0000"), alpha, 0, 0); ColorAssert.AreEqual(new MagickColor("#7fff7fff7fffffff"), alpha, 30, 30); } } }
public void ShouldModulateImage() { using (var image = new MagickImage(Files.TestPNG)) { image.Modulate(new Percentage(70), new Percentage(30)); #if Q8 ColorAssert.Equal(new MagickColor("#743e3e"), image, 25, 70); ColorAssert.Equal(new MagickColor("#0b0b0b"), image, 25, 40); ColorAssert.Equal(new MagickColor("#1f3a1f"), image, 75, 70); ColorAssert.Equal(new MagickColor("#5a5a5a"), image, 75, 40); ColorAssert.Equal(new MagickColor("#3e3e74"), image, 125, 70); ColorAssert.Equal(new MagickColor("#a8a8a8"), image, 125, 40); #else ColorAssert.Equal(new MagickColor(OpenCLValue.Get("#72803da83da8", "#747a3eb83eb8")), image, 25, 70); ColorAssert.Equal(new MagickColor(OpenCLValue.Get("#0b2d0b2d0b2d", "#0b5f0b5f0b5f")), image, 25, 40); ColorAssert.Equal(new MagickColor(OpenCLValue.Get("#1ef3397a1ef3", "#1f7c3a781f7c")), image, 75, 70); ColorAssert.Equal(new MagickColor(OpenCLValue.Get("#592d592d592d", "#5ab75ab75ab7")), image, 75, 40); ColorAssert.Equal(new MagickColor(OpenCLValue.Get("#3da83da87280", "#3eb83eb8747a")), image, 125, 70); ColorAssert.Equal(new MagickColor(OpenCLValue.Get("#a5aea5aea5ae", "#a88ba88ba88b")), image, 125, 40); #endif } }
public void Test_Transparent() { MagickColor transparent = null; Color transparentColor = transparent; Assert.AreEqual(Color.Empty, transparentColor); transparent = MagickColors.Transparent; ColorAssert.IsTransparent(transparent.A); ColorAssert.AreEqual(Color.Transparent, transparent); transparent = new MagickColor("transparent"); ColorAssert.IsTransparent(transparent.A); ColorAssert.AreEqual(Color.Transparent, transparent); transparentColor = transparent; Assert.AreEqual(Color.Transparent.R, transparentColor.R); Assert.AreEqual(Color.Transparent.G, transparentColor.G); Assert.AreEqual(Color.Transparent.B, transparentColor.B); Assert.AreEqual(Color.Transparent.A, transparentColor.A); }
public void ShouldApplyTheOperatorToTheImages() { using (var collection = new MagickImageCollection()) { collection.Read(Files.RoseSparkleGIF); collection.Complex(new ComplexSettings { ComplexOperator = ComplexOperator.Conjugate, }); Assert.Equal(2, collection.Count); #if Q8 ColorAssert.Equal(new MagickColor("#abb4ba01"), collection[1], 10, 10); #elif Q16 ColorAssert.Equal(new MagickColor("#aaabb3b4b9ba0001"), collection[1], 10, 10); #else collection[1].Clamp(); ColorAssert.Equal(new MagickColor("#0000000000000000"), collection[1], 10, 10); #endif } }
public void Test_ComplementaryColor() { ColorRGB color = MagickColors.Red; ColorRGB complementary = color.ComplementaryColor(); ColorAssert.AreEqual(MagickColors.Aqua, complementary); color = MagickColors.Lime; complementary = color.ComplementaryColor(); ColorAssert.AreEqual(MagickColors.Fuchsia, complementary); color = MagickColors.Black; complementary = color.ComplementaryColor(); ColorAssert.AreEqual(MagickColors.Black, complementary); color = MagickColors.White; complementary = color.ComplementaryColor(); ColorAssert.AreEqual(MagickColors.White, complementary); color = new MagickColor("#aabbcc"); complementary = color.ComplementaryColor(); ColorAssert.AreEqual(new MagickColor("#ccbbaa"), complementary); color = new MagickColor(4, 1, 3); complementary = color.ComplementaryColor(); ColorAssert.AreEqual(new MagickColor(1, 4, 1), complementary); color = new MagickColor("#9aa01e"); complementary = color.ComplementaryColor(); #if Q8 ColorAssert.AreEqual(new MagickColor("#231ea0"), complementary); #elif Q16 || Q16HDRI ColorAssert.AreEqual(new MagickColor("#24231e1ea0a0"), complementary); #else #error Not implemented! #endif }
public void ShouldAddCorrectLineBreaks6() { var caption = "caption:AAA"; var readSettings = new MagickReadSettings() { BackgroundColor = MagickColors.Transparent, FontPointsize = 72, TextGravity = Gravity.West, FillColor = MagickColors.Black, Width = 40, }; using (IMagickImage image = new MagickImage(caption, readSettings)) { Assert.AreEqual(249, image.Height); ColorAssert.AreEqual(MagickColors.Black, image, 39, 47); ColorAssert.AreEqual(new MagickColor("#0000"), image, 39, 66); ColorAssert.AreEqual(MagickColors.Black, image, 39, 129); ColorAssert.AreEqual(new MagickColor("#0000"), image, 39, 148); ColorAssert.AreEqual(MagickColors.Black, image, 39, 211); ColorAssert.AreEqual(new MagickColor("#0000"), image, 39, 230); } }
public void ShouldMergeTheImages() { using (IMagickImageCollection collection = new MagickImageCollection()) { collection.Read(Files.RoseSparkleGIF); collection.Complex(new ComplexSettings() { Operator = ComplexOperator.Conjugate, SignalToNoiseRatio = 5.5, }); Assert.AreEqual(2, collection.Count); collection[1].Clamp(); #if Q8 ColorAssert.AreEqual(new MagickColor("#db638b"), collection[1], 10, 10); #elif Q16 || Q16HDRI ColorAssert.AreEqual(new MagickColor("#2c2c2b2b2b2b"), collection[1], 10, 10); #else #error Not implemented! #endif } }
public void ShouldReduceTheColors() { using (var collection = new MagickImageCollection()) { collection.Add(Files.FujiFilmFinePixS1ProJPG); QuantizeSettings settings = new QuantizeSettings { Colors = 3, }; collection.Quantize(settings); #if Q8 ColorAssert.Equal(new MagickColor("#2b414f"), collection[0], 120, 140); ColorAssert.Equal(new MagickColor("#7b929f"), collection[0], 95, 140); ColorAssert.Equal(new MagickColor("#44739f"), collection[0], 300, 150); #else ColorAssert.Equal(new MagickColor("#2af841624f09"), collection[0], 120, 140); ColorAssert.Equal(new MagickColor("#7b3c92b69f5a"), collection[0], 95, 140); ColorAssert.Equal(new MagickColor("#44bc73059f70"), collection[0], 300, 150); #endif } }
public void Constructor_WithColor_ColorPropertyIsCorrect() { DrawableBorderColor borderColor = new DrawableBorderColor(Color.GreenYellow); ColorAssert.AreEqual(MagickColors.GreenYellow, borderColor.Color); }
public void Test_Constructor_Color() { DrawableStrokeColor strokeColor = new DrawableStrokeColor(Color.GhostWhite); ColorAssert.AreEqual(MagickColors.GhostWhite, strokeColor.Color); }
public void Constructor_WithColor_ColorPropertyIsCorrect() { DrawableFillColor fillColor = new DrawableFillColor(Color.DarkKhaki); ColorAssert.AreEqual(MagickColors.DarkKhaki, fillColor.Color); }
public void Equals_MagickColorTransparent_EqualToColorTransparent() { MagickColor transparent = MagickColors.Transparent; ColorAssert.AreEqual(Color.Transparent, transparent); }
public void Equals_MagickColorWithConstructedWithStringSetToTransparent_EqualToColorTransparent() { MagickColor transparent = new MagickColor("transparent"); ColorAssert.AreEqual(Color.Transparent, transparent); }
public void Test_Constructor_Color() { DrawableTextUnderColor textUnderColor = new DrawableTextUnderColor(Color.Violet); ColorAssert.AreEqual(MagickColors.Violet, textUnderColor.Color); }
public void Constructor_WithColor_ColorPropertyIsCorrect() { DrawableTextUnderColor textUnderColor = new DrawableTextUnderColor(Color.Violet); ColorAssert.AreEqual(MagickColors.Violet, textUnderColor.Color); }
public void Test_Constructor_Color() { DrawableBorderColor borderColor = new DrawableBorderColor(Color.GreenYellow); ColorAssert.AreEqual(MagickColors.GreenYellow, borderColor.Color); }
public void Test_Constructor_Color() { DrawableFillColor fillColor = new DrawableFillColor(Color.DarkKhaki); ColorAssert.AreEqual(MagickColors.DarkKhaki, fillColor.Color); }
public void Test_Color() { ColorRGB fuchsia = new ColorRGB(Color.Fuchsia); ColorAssert.AreEqual(fuchsia, MagickColors.Fuchsia); }
public void Constructor_WithSystemDrawingColor_IsEqualToMagickColor() { ColorRGB fuchsia = new ColorRGB(Color.Fuchsia); ColorAssert.AreEqual(fuchsia, MagickColors.Fuchsia); }
public void ShouldSetTheProperties() { DrawableStrokeColor strokeColor = new DrawableStrokeColor(Color.GhostWhite); ColorAssert.AreEqual(MagickColors.GhostWhite, strokeColor.Color); }
public void Constructor_WithColor_ColorPropertyIsCorrect() { DrawableStrokeColor strokeColor = new DrawableStrokeColor(Color.GhostWhite); ColorAssert.AreEqual(MagickColors.GhostWhite, strokeColor.Color); }
public void ShouldSetTheProperties() { DrawableTextUnderColor textUnderColor = new DrawableTextUnderColor(Color.Violet); ColorAssert.AreEqual(MagickColors.Violet, textUnderColor.Color); }
public void ConvertWithString_TypeIsMagickColor_ReturnsValue() { MagickColor value = MagickConverter.Convert <MagickColor>("#fff"); ColorAssert.AreEqual(MagickColors.White, value); }
public void Test_Properties() { using (MagickImage image = new MagickImage()) { MagickSettings settings = image.Settings; Assert.AreEqual(true, settings.Adjoin); settings.Adjoin = false; Assert.AreEqual(false, settings.Adjoin); MagickColor alphaColor = new MagickColor("#bd"); ColorAssert.AreEqual(alphaColor, settings.AlphaColor); alphaColor = MagickColors.Tan; settings.AlphaColor = alphaColor; ColorAssert.AreEqual(alphaColor, settings.AlphaColor); MagickColor backgroundColor = new MagickColor("white"); ColorAssert.AreEqual(backgroundColor, settings.BackgroundColor); backgroundColor = new MagickColor("purple"); settings.BackgroundColor = backgroundColor; ColorAssert.AreEqual(backgroundColor, settings.BackgroundColor); MagickColor borderColor = new MagickColor("#df"); ColorAssert.AreEqual(borderColor, settings.BorderColor); borderColor = new MagickColor("orange"); settings.BorderColor = borderColor; ColorAssert.AreEqual(borderColor, settings.BorderColor); Assert.AreEqual(ColorSpace.Undefined, settings.ColorSpace); settings.ColorSpace = ColorSpace.CMYK; Assert.AreEqual(ColorSpace.CMYK, settings.ColorSpace); Assert.AreEqual(ColorType.Undefined, settings.ColorType); settings.ColorType = ColorType.ColorSeparation; Assert.AreEqual(ColorType.ColorSeparation, settings.ColorType); Assert.AreEqual(CompressionMethod.Undefined, settings.CompressionMethod); settings.CompressionMethod = CompressionMethod.BZip; Assert.AreEqual(CompressionMethod.BZip, settings.CompressionMethod); Assert.AreEqual(false, settings.Debug); settings.Debug = true; Assert.AreEqual(true, settings.Debug); settings.Debug = false; PointD density = new PointD(72); Assert.AreEqual(density, settings.Density); density = new PointD(100); settings.Density = density; Assert.AreEqual(density, settings.Density); density = new PointD(50, 10); settings.Density = density; Assert.AreEqual(density, settings.Density); Assert.AreEqual(Endian.Undefined, settings.Endian); settings.Endian = Endian.MSB; Assert.AreEqual(Endian.MSB, settings.Endian); MagickColor fillColor = MagickColors.Black; ColorAssert.AreEqual(fillColor, settings.FillColor); fillColor = new MagickColor("purple"); settings.FillColor = fillColor; ColorAssert.AreEqual(fillColor, settings.FillColor); using (MagickImage fillPattern = new MagickImage(Files.CirclePNG)) { Assert.AreEqual(null, settings.FillPattern); settings.FillPattern = fillPattern; Assert.AreEqual(fillPattern, settings.FillPattern); } Assert.AreEqual(FillRule.EvenOdd, settings.FillRule); settings.FillRule = FillRule.Nonzero; Assert.AreEqual(FillRule.Nonzero, settings.FillRule); Assert.AreEqual(null, settings.Font); settings.Font = "Comic Sans"; Assert.AreEqual("Comic Sans", settings.Font); Assert.AreEqual(null, settings.FontFamily); settings.FontFamily = "Trajan"; Assert.AreEqual("Trajan", settings.FontFamily); Assert.AreEqual(0, settings.FontPointsize); settings.FontPointsize = 60; Assert.AreEqual(60, settings.FontPointsize); Assert.AreEqual(FontStyleType.Undefined, settings.FontStyle); settings.FontStyle = FontStyleType.Oblique; Assert.AreEqual(FontStyleType.Oblique, settings.FontStyle); Assert.AreEqual(FontWeight.Undefined, settings.FontWeight); settings.FontWeight = FontWeight.ExtraBold; Assert.AreEqual(FontWeight.ExtraBold, settings.FontWeight); Assert.AreEqual(MagickFormat.Unknown, settings.Format); settings.Format = MagickFormat.WebP; Assert.AreEqual(MagickFormat.WebP, settings.Format); MagickGeometry page = new MagickGeometry(0, 0, 0, 0); Assert.AreEqual(page, settings.Page); page = new MagickGeometry(0, 0, 10, 10); settings.Page = page; Assert.AreEqual(page, settings.Page); Assert.AreEqual(true, settings.StrokeAntiAlias); settings.StrokeAntiAlias = false; Assert.AreEqual(false, settings.StrokeAntiAlias); MagickColor strokeColor = new MagickColor(0, 0, 0, 0); ColorAssert.AreEqual(strokeColor, settings.StrokeColor); strokeColor = MagickColors.Fuchsia; settings.StrokeColor = strokeColor; ColorAssert.AreEqual(strokeColor, settings.StrokeColor); Assert.AreEqual(null, settings.StrokeDashArray); double[] dashArray = new double[] { 1.0, 2.0, 3.0 }; settings.StrokeDashArray = dashArray; CollectionAssert.AreEqual(dashArray, settings.StrokeDashArray); Assert.AreEqual(0, settings.StrokeDashOffset); settings.StrokeDashOffset = 5; Assert.AreEqual(5, settings.StrokeDashOffset); Assert.AreEqual(LineCap.Butt, settings.StrokeLineCap); settings.StrokeLineCap = LineCap.Round; Assert.AreEqual(LineCap.Round, settings.StrokeLineCap); Assert.AreEqual(LineJoin.Miter, settings.StrokeLineJoin); settings.StrokeLineJoin = LineJoin.Round; Assert.AreEqual(LineJoin.Round, settings.StrokeLineJoin); Assert.AreEqual(10, settings.StrokeMiterLimit); settings.StrokeMiterLimit = 8; Assert.AreEqual(8, settings.StrokeMiterLimit); using (MagickImage strokePattern = new MagickImage(Files.MagickNETIconPNG)) { Assert.AreEqual(null, settings.StrokePattern); settings.StrokePattern = strokePattern; Assert.AreEqual(strokePattern, settings.StrokePattern); } Assert.AreEqual(1, settings.StrokeWidth); settings.StrokeWidth = 9.5; Assert.AreEqual(9.5, settings.StrokeWidth); Assert.AreEqual(true, settings.TextAntiAlias); settings.TextAntiAlias = false; Assert.AreEqual(false, settings.TextAntiAlias); Assert.AreEqual(TextDirection.Undefined, settings.TextDirection); settings.TextDirection = TextDirection.RightToLeft; Assert.AreEqual(TextDirection.RightToLeft, settings.TextDirection); Assert.AreEqual(null, settings.TextEncoding); settings.TextEncoding = Encoding.Unicode; Assert.AreEqual(Encoding.Unicode, settings.TextEncoding); Assert.AreEqual(Gravity.Undefined, settings.TextGravity); settings.TextGravity = Gravity.North; Assert.AreEqual(Gravity.North, settings.TextGravity); Assert.AreEqual(0, settings.TextInterlineSpacing); settings.TextInterlineSpacing = 3.4; Assert.AreEqual(3.4, settings.TextInterlineSpacing); Assert.AreEqual(0, settings.TextInterwordSpacing); settings.TextInterwordSpacing = 7.8; Assert.AreEqual(7.8, settings.TextInterwordSpacing); Assert.AreEqual(0, settings.TextKerning); settings.TextKerning = 6.2; Assert.AreEqual(6.2, settings.TextKerning); MagickColor underColor = new MagickColor(0, 0, 0, 0); ColorAssert.AreEqual(underColor, settings.TextUnderColor); underColor = new MagickColor("yellow"); settings.TextUnderColor = underColor; ColorAssert.AreEqual(underColor, settings.TextUnderColor); Assert.AreEqual(false, settings.Verbose); settings.Verbose = true; Assert.AreEqual(true, settings.Verbose); } }
public void ShouldSetTheProperties() { DrawableBorderColor borderColor = new DrawableBorderColor(Color.GreenYellow); ColorAssert.AreEqual(MagickColors.GreenYellow, borderColor.Color); }