Exemple #1
0
            public void RootFrameIsFrameAtIndexZero()
            {
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { new ImageFrame <Rgba32>(Configuration.Default, 10, 10), new ImageFrame <Rgba32>(Configuration.Default, 10, 10) });

                Assert.Equal(collection.RootFrame, collection[0]);
            }
Exemple #2
0
        public ImageFrameCollectionTests()
        {
            // Needed to get English exception messages, which are checked in several tests.
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

            this.Image      = new Image <Rgba32>(10, 10);
            this.Collection = new ImageFrameCollection <Rgba32>(this.Image, 10, 10, default(Rgba32));
        }
Exemple #3
0
            public void ConstructorPopulatesFrames()
            {
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { new ImageFrame <Rgba32>(Configuration.Default, 10, 10), new ImageFrame <Rgba32>(Configuration.Default, 10, 10) });

                Assert.Equal(2, collection.Count);
            }
        public void RootFrameIsFrameAtIndexZero()
        {
            var collection = new ImageFrameCollection <Rgba32>(this.image, new[] {
                new ImageFrame <Rgba32>(10, 10),
                new ImageFrame <Rgba32>(10, 10),
            });

            Assert.Equal(collection.RootFrame, collection[0]);
        }
Exemple #5
0
            public void RemoveAtFrame_CanRemoveFrameZeroIfMultipleFramesExist()
            {
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { new ImageFrame <Rgba32>(Configuration.Default, 10, 10), new ImageFrame <Rgba32>(Configuration.Default, 10, 10) });

                collection.RemoveFrame(0);
                Assert.Equal(1, collection.Count);
            }
        public void ConstructorPopulatesFrames()
        {
            var collection = new ImageFrameCollection <Rgba32>(new[] {
                new ImageFrame <Rgba32>(10, 10),
                new ImageFrame <Rgba32>(10, 10),
            });

            Assert.Equal(2, collection.Count);
        }
        public void RemoveFrame_CanRemoveFrameZeroIfMultipleFramesExist()
        {
            var collection = new ImageFrameCollection <Rgba32>(new[] {
                new ImageFrame <Rgba32>(10, 10),
                new ImageFrame <Rgba32>(10, 10),
            });

            collection.Remove(collection[0]);
            Assert.Equal(1, collection.Count);
        }
Exemple #8
0
            public void DisposeClearsCollection()
            {
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { new ImageFrame <Rgba32>(Configuration.Default, 10, 10), new ImageFrame <Rgba32>(Configuration.Default, 10, 10) });

                collection.Dispose();

                Assert.Equal(0, collection.Count);
            }
            public void RootFrameIsFrameAtIndexZero()
            {
                using var imageFrame1 = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                using var imageFrame2 = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { imageFrame1, imageFrame2 });

                Assert.Equal(collection.RootFrame, collection[0]);
            }
            public void ConstructorPopulatesFrames()
            {
                using var imageFrame1 = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                using var imageFrame2 = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { imageFrame1, imageFrame2 });

                Assert.Equal(2, collection.Count);
            }
        public void DisposeClearsCollection()
        {
            var collection = new ImageFrameCollection <Rgba32>(new[] {
                new ImageFrame <Rgba32>(10, 10),
                new ImageFrame <Rgba32>(10, 10),
            });

            collection.Dispose();

            Assert.Equal(0, collection.Count);
        }
        public void SetFrameAtIndex_FramesNotBeNull()
        {
            var collection = new ImageFrameCollection <Rgba32>(10, 10);

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() =>
            {
                collection[0] = null;
            });

            Assert.StartsWith("Value cannot be null.", ex.Message);
        }
        public void InsertNewFrame_FramesNotBeNull()
        {
            var collection = new ImageFrameCollection <Rgba32>(10, 10);

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() =>
            {
                collection.Insert(1, null);
            });

            Assert.StartsWith("Value cannot be null.", ex.Message);
        }
 private static void ImportFrameAs <TPixel>(ImageFrameCollection source, ImageFrameCollection destination, int index)
     where TPixel : struct, IPixel <TPixel>
 {
     using (Image temp = source.CloneFrame(index))
     {
         using (Image <TPixel> temp2 = temp.CloneAs <TPixel>())
         {
             destination.AddFrame(temp2.Frames.RootFrame);
         }
     }
 }
        public void SetFrameAtIndex_FramesMustHaveSameSize()
        {
            var collection = new ImageFrameCollection <Rgba32>(10, 10);

            ArgumentException ex = Assert.Throws <ArgumentException>(() =>
            {
                collection[0] = new ImageFrame <Rgba32>(1, 1);
            });

            Assert.StartsWith("Frame must have the same dimensions as the image.", ex.Message);
        }
            public void DisposeClearsCollection()
            {
                using var imageFrame1 = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                using var imageFrame2 = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { imageFrame1, imageFrame2 });

                collection.Dispose();

                Assert.Equal(0, collection.Count);
            }
            public void RemoveAtFrame_ThrowIfRemovingLastFrame()
            {
                using var imageFrame = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { imageFrame });

                InvalidOperationException ex = Assert.Throws <InvalidOperationException>(
                    () => collection.RemoveFrame(0));

                Assert.Equal("Cannot remove last frame.", ex.Message);
            }
Exemple #18
0
        public void Constructor_FramesMustHaveSameSize()
        {
            ArgumentException ex = Assert.Throws <ArgumentException>(() =>
            {
                var collection = new ImageFrameCollection <Rgba32>(this.image, new[] {
                    new ImageFrame <Rgba32>(Configuration.Default.MemoryManager, 10, 10),
                    new ImageFrame <Rgba32>(Configuration.Default.MemoryManager, 1, 1),
                });
            });

            Assert.StartsWith("Frame must have the same dimensions as the image.", ex.Message);
        }
        public void RemoveAtFrame_ThrowIfRemovingLastFrame()
        {
            var collection = new ImageFrameCollection <Rgba32>(this.image, new[] {
                new ImageFrame <Rgba32>(10, 10)
            });

            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() =>
            {
                collection.RemoveFrame(0);
            });

            Assert.Equal("Cannot remove last frame.", ex.Message);
        }
Exemple #20
0
        public void Dispose_DisposesAllInnerFrames()
        {
            var collection = new ImageFrameCollection <Rgba32>(this.image, new[] {
                new ImageFrame <Rgba32>(Configuration.Default.MemoryManager, 10, 10),
                new ImageFrame <Rgba32>(Configuration.Default.MemoryManager, 10, 10),
            });

            IPixelSource <Rgba32>[] framesSnapShot = collection.OfType <IPixelSource <Rgba32> >().ToArray();
            collection.Dispose();

            Assert.All(framesSnapShot, f =>
            {
                // the pixel source of the frame is null after its been disposed.
                Assert.Null(f.PixelBuffer);
            });
        }
            public void CloneFrame <TPixel>(TestImageProvider <TPixel> provider)
                where TPixel : struct, IPixel <TPixel>
            {
                using (Image <TPixel> img = provider.GetImage())
                {
                    ImageFrameCollection nonGenericFrameCollection = img.Frames;

                    nonGenericFrameCollection.AddFrame(new ImageFrame <TPixel>(Configuration.Default, 10, 10)); // add a frame anyway
                    using (Image cloned = nonGenericFrameCollection.CloneFrame(0))
                    {
                        Assert.Equal(2, img.Frames.Count);

                        var expectedClone = (Image <TPixel>)cloned;

                        expectedClone.ComparePixelBufferTo(img.GetPixelSpan());
                    }
                }
            }
Exemple #22
0
            public void CloneFrame <TPixel>(TestImageProvider <TPixel> provider)
                where TPixel : unmanaged, IPixel <TPixel>
            {
                using (Image <TPixel> img = provider.GetImage())
                {
                    ImageFrameCollection nonGenericFrameCollection = img.Frames;

                    nonGenericFrameCollection.AddFrame(new ImageFrame <TPixel>(Configuration.Default, 10, 10)); // add a frame anyway
                    using (Image cloned = nonGenericFrameCollection.CloneFrame(0))
                    {
                        Assert.Equal(2, img.Frames.Count);

                        var expectedClone = (Image <TPixel>)cloned;

                        Assert.True(img.DangerousTryGetSinglePixelMemory(out Memory <TPixel> imgMem));
                        expectedClone.ComparePixelBufferTo(imgMem);
                    }
                }
            }
            public void Dispose_DisposesAllInnerFrames()
            {
                using var imageFrame1 = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                using var imageFrame2 = new ImageFrame <Rgba32>(Configuration.Default, 10, 10);
                var collection = new ImageFrameCollection <Rgba32>(
                    this.Image,
                    new[] { imageFrame1, imageFrame2 });

                IPixelSource <Rgba32>[] framesSnapShot = collection.OfType <IPixelSource <Rgba32> >().ToArray();
                collection.Dispose();

                Assert.All(
                    framesSnapShot,
                    f =>
                {
                    // The pixel source of the frame is null after its been disposed.
                    Assert.Null(f.PixelBuffer);
                });
            }
            public void ExtractFrame <TPixel>(TestImageProvider <TPixel> provider)
                where TPixel : struct, IPixel <TPixel>
            {
                using (Image <TPixel> img = provider.GetImage())
                {
                    var sourcePixelData = img.GetPixelSpan().ToArray();

                    ImageFrameCollection nonGenericFrameCollection = img.Frames;

                    nonGenericFrameCollection.AddFrame(new ImageFrame <TPixel>(Configuration.Default, 10, 10));
                    using (Image cloned = nonGenericFrameCollection.ExportFrame(0))
                    {
                        Assert.Equal(1, img.Frames.Count);

                        var expectedClone = (Image <TPixel>)cloned;
                        expectedClone.ComparePixelBufferTo(sourcePixelData);
                    }
                }
            }
Exemple #25
0
            public void ExtractFrame <TPixel>(TestImageProvider <TPixel> provider)
                where TPixel : unmanaged, IPixel <TPixel>
            {
                using (Image <TPixel> img = provider.GetImage())
                {
                    Assert.True(img.DangerousTryGetSinglePixelMemory(out Memory <TPixel> imgMem));
                    TPixel[] sourcePixelData = imgMem.ToArray();

                    ImageFrameCollection nonGenericFrameCollection = img.Frames;

                    nonGenericFrameCollection.AddFrame(new ImageFrame <TPixel>(Configuration.Default, 10, 10));
                    using (Image cloned = nonGenericFrameCollection.ExportFrame(0))
                    {
                        Assert.Equal(1, img.Frames.Count);

                        var expectedClone = (Image <TPixel>)cloned;
                        expectedClone.ComparePixelBufferTo(sourcePixelData.AsSpan());
                    }
                }
            }
        public void ImageFramesaLwaysHaveOneFrame()
        {
            var collection = new ImageFrameCollection <Rgba32>(10, 10);

            Assert.Equal(1, collection.Count);
        }
 public ImageFramesCollectionTests()
 {
     this.image      = new Image <Rgba32>(10, 10);
     this.collection = new ImageFrameCollection <Rgba32>(this.image, 10, 10);
 }