Exemplo n.º 1
0
        /// <exception cref="Com.Drew.Imaging.Jpeg.JpegProcessingException"/>
        /// <exception cref="System.IO.IOException"/>
        public static void Process([NotNull] Com.Drew.Metadata.Metadata metadata, [NotNull] InputStream inputStream, [CanBeNull] Iterable <JpegSegmentMetadataReader> readers)
        {
            if (readers == null)
            {
                readers = AllReaders;
            }
            ICollection <JpegSegmentType> segmentTypes = new HashSet <JpegSegmentType>();

            foreach (JpegSegmentMetadataReader reader in readers)
            {
                foreach (JpegSegmentType type in reader.GetSegmentTypes())
                {
                    segmentTypes.Add(type);
                }
            }
            JpegSegmentData segmentData = JpegSegmentReader.ReadSegments(new Com.Drew.Lang.StreamReader(inputStream), segmentTypes.AsIterable());

            ProcessJpegSegmentData(metadata, readers, segmentData);
        }
Exemplo n.º 2
0
        public virtual void TestReadAllSegments()
        {
            JpegSegmentData segmentData = JpegSegmentReader.ReadSegments(new FilePath("Tests/Data/withExifAndIptc.jpg"), null);

            Sharpen.Tests.AreEqual(1, segmentData.GetSegmentCount(JpegSegmentType.App0));
            NUnit.Framework.CollectionAssert.AreEqual(FileUtil.ReadBytes("Tests/Data/withExifAndIptc.jpg.app0"), segmentData.GetSegment(JpegSegmentType.App0));
            NUnit.Framework.Assert.IsNull(segmentData.GetSegment(JpegSegmentType.App0, 1));
            Sharpen.Tests.AreEqual(2, segmentData.GetSegmentCount(JpegSegmentType.App1));
            NUnit.Framework.CollectionAssert.AreEqual(FileUtil.ReadBytes("Tests/Data/withExifAndIptc.jpg.app1.0"), segmentData.GetSegment(JpegSegmentType.App1, 0));
            NUnit.Framework.CollectionAssert.AreEqual(FileUtil.ReadBytes("Tests/Data/withExifAndIptc.jpg.app1.1"), segmentData.GetSegment(JpegSegmentType.App1, 1));
            NUnit.Framework.Assert.IsNull(segmentData.GetSegment(JpegSegmentType.App1, 2));
            Sharpen.Tests.AreEqual(1, segmentData.GetSegmentCount(JpegSegmentType.App2));
            NUnit.Framework.CollectionAssert.AreEqual(FileUtil.ReadBytes("Tests/Data/withExifAndIptc.jpg.app2"), segmentData.GetSegment(JpegSegmentType.App2));
            NUnit.Framework.Assert.IsNull(segmentData.GetSegment(JpegSegmentType.App2, 1));
            Sharpen.Tests.AreEqual(1, segmentData.GetSegmentCount(JpegSegmentType.Appd));
            NUnit.Framework.CollectionAssert.AreEqual(FileUtil.ReadBytes("Tests/Data/withExifAndIptc.jpg.appd"), segmentData.GetSegment(JpegSegmentType.Appd));
            NUnit.Framework.Assert.IsNull(segmentData.GetSegment(JpegSegmentType.Appd, 1));
            Sharpen.Tests.AreEqual(1, segmentData.GetSegmentCount(JpegSegmentType.Appe));
            NUnit.Framework.CollectionAssert.AreEqual(FileUtil.ReadBytes("Tests/Data/withExifAndIptc.jpg.appe"), segmentData.GetSegment(JpegSegmentType.Appe));
            NUnit.Framework.Assert.IsNull(segmentData.GetSegment(JpegSegmentType.Appe, 1));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.App3));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.App4));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.App5));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.App6));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.App7));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.App8));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.App9));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.Appa));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.Appb));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.Appc));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.Appf));
            Sharpen.Tests.AreEqual(0, segmentData.GetSegmentCount(JpegSegmentType.Com));
            Sharpen.Tests.AreEqual(4, segmentData.GetSegmentCount(JpegSegmentType.Dht));
            Sharpen.Tests.AreEqual(2, segmentData.GetSegmentCount(JpegSegmentType.Dqt));
            Sharpen.Tests.AreEqual(1, segmentData.GetSegmentCount(JpegSegmentType.Sof0));
            NUnit.Framework.Assert.IsNull(segmentData.GetSegment(JpegSegmentType.App3, 0));
        }
Exemplo n.º 3
0
        public virtual void TestLoadJpegWithoutExifDataReturnsNull()
        {
            JpegSegmentData segmentData = JpegSegmentReader.ReadSegments(new FilePath("Tests/Data/noExif.jpg"), null);

            NUnit.Framework.Assert.IsNull(segmentData.GetSegment(JpegSegmentType.App1));
        }