public void SameColorSpaceCreatedDifferentWaysAreTheSameObject() { var colorspace1 = SKColorSpace.CreateSrgbLinear(); Assert.Equal("SkiaSharp.SKColorSpace+SKColorSpaceStatic", colorspace1.GetType().FullName); Assert.Equal(2, colorspace1.GetReferenceCount()); var colorspace2 = SKColorSpace.CreateRgb(SKNamedGamma.Linear, SKColorSpaceGamut.Srgb); Assert.Equal("SkiaSharp.SKColorSpace+SKColorSpaceStatic", colorspace2.GetType().FullName); Assert.Equal(2, colorspace2.GetReferenceCount()); Assert.Same(colorspace1, colorspace2); var colorspace3 = SKColorSpace.CreateRgb( new SKColorSpaceTransferFn { A = 0.6f, B = 0.5f, C = 0.4f, D = 0.3f, E = 0.2f, F = 0.1f }, SKMatrix44.CreateIdentity()); Assert.NotSame(colorspace1, colorspace3); colorspace3.Dispose(); Assert.True(colorspace3.IsDisposed); Assert.Equal(2, colorspace1.GetReferenceCount()); colorspace2.Dispose(); Assert.False(colorspace2.IsDisposed); Assert.Equal(2, colorspace1.GetReferenceCount()); colorspace1.Dispose(); Assert.False(colorspace1.IsDisposed); Assert.Equal(2, colorspace1.GetReferenceCount()); }
public unsafe void ReferencesCountedCorrectly() { var colorspace = SKColorSpace.CreateRgb( new SKColorSpaceTransferFn { A = 0.1f, B = 0.2f, C = 0.3f, D = 0.4f, E = 0.5f, F = 0.6f }, SKMatrix44.CreateIdentity()); var handle = colorspace.Handle; Assert.Equal(1, handle.GetReferenceCount(false)); var info = new SKImageInfo(1, 1, SKImageInfo.PlatformColorType, SKAlphaType.Premul, colorspace); Assert.Equal(1, handle.GetReferenceCount(false)); var pixels = new byte[info.BytesSize]; fixed(byte *p = pixels) { var pixmap = new SKPixmap(info, (IntPtr)p); Assert.Equal(2, handle.GetReferenceCount(false)); pixmap.Dispose(); Assert.Equal(1, handle.GetReferenceCount(false)); } GC.KeepAlive(colorspace); }
private static void Main(string[] args) { Console.WriteLine($"Generated class {typeof(Camera)} from Svg file."); Console.WriteLine($"Generated class {typeof(Tiger)} from Svg file."); Console.WriteLine($"Generated class {typeof(Ellipse)} from Svg file."); Console.WriteLine($"Generated class {typeof(Rect)} from Svg file."); Console.WriteLine($"Generated class {typeof(Svg_pservers_pattern_01_b)} from Svg file."); var sw = new Stopwatch(); sw.Start(); using var cameraStream = File.OpenWrite("__AJ_Digital_Camera.png"); Camera.Picture.ToImage(cameraStream, SKColors.Transparent, SKEncodedImageFormat.Png, 100, 1, 1, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul, SKColorSpace.CreateRgb(SKColorSpaceTransferFn.Srgb, SKColorSpaceXyz.Srgb)); sw.Stop(); Console.WriteLine($"Created __AJ_Digital_Camera.png in {sw.Elapsed.TotalMilliseconds}ms"); sw.Reset(); sw.Start(); using var tigerStream = File.OpenWrite("__tiger.png"); Tiger.Picture.ToImage(tigerStream, SKColors.Transparent, SKEncodedImageFormat.Png, 100, 1, 1, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul, SKColorSpace.CreateRgb(SKColorSpaceTransferFn.Srgb, SKColorSpaceXyz.Srgb)); sw.Stop(); Console.WriteLine($"Created __tiger.png in {sw.Elapsed.TotalMilliseconds}ms"); sw.Reset(); sw.Start(); using var ellipseStream = File.OpenWrite("e-ellipse-001.png"); Ellipse.Picture.ToImage(ellipseStream, SKColors.Transparent, SKEncodedImageFormat.Png, 100, 1, 1, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul, SKSvgSettings.s_srgb); sw.Stop(); Console.WriteLine($"Created e-ellipse-001.png in {sw.Elapsed.TotalMilliseconds}ms"); sw.Reset(); sw.Start(); using var rectStream = File.OpenWrite("e-rect-001.png"); Rect.Picture.ToImage(rectStream, SKColors.Transparent, SKEncodedImageFormat.Png, 100, 1, 1, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul, SKSvgSettings.s_srgb); sw.Stop(); Console.WriteLine($"Created e-rect-001.png in {sw.Elapsed.TotalMilliseconds}ms"); sw.Reset(); sw.Start(); using var patternStream = File.OpenWrite("pservers-pattern-01-b.png"); Svg_pservers_pattern_01_b.Picture.ToImage(patternStream, SKColors.Transparent, SKEncodedImageFormat.Png, 100, 1, 1, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul, SKSvgSettings.s_srgb); sw.Stop(); Console.WriteLine($"Created pservers-pattern-01-b.png in {sw.Elapsed.TotalMilliseconds}ms"); }
public void ImageInfoColorSpaceIsReferencedCorrectly() { VerifyImmediateFinalizers(); var img = DoWork(out var colorspaceHandle); CollectGarbage(); Assert.Equal(1, colorspaceHandle.GetReferenceCount(true)); Check(); CollectGarbage(); Assert.Equal(1, colorspaceHandle.GetReferenceCount(true)); void Check() { var peek = img.PeekPixels(); Assert.Equal(2, colorspaceHandle.GetReferenceCount(true)); // get the info and color space var info1 = peek.Info; var cs1 = info1.ColorSpace; Assert.Equal(3, colorspaceHandle.GetReferenceCount(true)); Assert.NotNull(cs1); // get the info and color space again and make sure we are all using the same things var info2 = peek.Info; var cs2 = info2.ColorSpace; Assert.Equal(3, colorspaceHandle.GetReferenceCount(true)); Assert.NotNull(cs2); Assert.Same(cs1, cs2); } SKImage DoWork(out IntPtr handle) { var colorspace = SKColorSpace.CreateRgb( new SKColorSpaceTransferFn { A = 0.6f, B = 0.5f, C = 0.4f, D = 0.3f, E = 0.2f, F = 0.1f }, SKMatrix44.CreateIdentity()); Assert.NotNull(colorspace); handle = colorspace.Handle; Assert.Equal(1, handle.GetReferenceCount(true)); var info = new SKImageInfo(100, 100, SKImageInfo.PlatformColorType, SKAlphaType.Premul, colorspace); Assert.Equal(1, handle.GetReferenceCount(true)); var image = SKImage.Create(info); Assert.Equal(2, handle.GetReferenceCount(true)); return(image); } }
public void ColorSpaceIsNotDisposedPrematurely() { VerifyImmediateFinalizers(); var img = DoWork(out var colorSpaceHandle, out var weakColorspace); CheckBeforeCollection(colorSpaceHandle); CheckExistingImage(3, img, colorSpaceHandle); CollectGarbage(); Assert.Null(weakColorspace.Target); Assert.Equal(1, colorSpaceHandle.GetReferenceCount(true)); CheckExistingImage(2, img, colorSpaceHandle); CollectGarbage(); Assert.Null(weakColorspace.Target); Assert.Equal(1, colorSpaceHandle.GetReferenceCount(true)); CollectGarbage(); Assert.Equal(1, colorSpaceHandle.GetReferenceCount(true)); GC.KeepAlive(img); void CheckBeforeCollection(IntPtr csh) { Assert.NotNull(weakColorspace.Target); Assert.Equal(2, csh.GetReferenceCount(true)); } void CheckExistingImage(int expected, SKImage image, IntPtr csh) { var peek = image.PeekPixels(); Assert.Equal(expected, csh.GetReferenceCount(true)); var info = peek.Info; Assert.Equal(3, csh.GetReferenceCount(true)); var cs = info.ColorSpace; Assert.Equal(3, csh.GetReferenceCount(true)); Assert.NotNull(cs); } SKImage DoWork(out IntPtr handle, out WeakReference weak) { var colorspace = SKColorSpace.CreateRgb( new SKColorSpaceTransferFn { A = 0.1f, B = 0.2f, C = 0.3f, D = 0.4f, E = 0.5f, F = 0.6f }, SKMatrix44.CreateIdentity()); Assert.NotNull(colorspace); handle = colorspace.Handle; weak = new WeakReference(colorspace); Assert.Equal(1, handle.GetReferenceCount(true)); var info = new SKImageInfo(100, 100, SKImageInfo.PlatformColorType, SKAlphaType.Premul, colorspace); Assert.Equal(1, handle.GetReferenceCount(true)); var image = SKImage.Create(info); Assert.Equal(2, handle.GetReferenceCount(true)); return(image); } }