Exemplo n.º 1
0
 public void MetadataProfiles <TPixel>(TestImageProvider <TPixel> provider, bool ignoreMetadata)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage(new TiffDecoder()
     {
         IgnoreMetadata = ignoreMetadata
     }))
     {
         TiffMetadata       meta = image.Metadata.GetTiffMetadata();
         ImageFrameMetadata rootFrameMetaData = image.Frames.RootFrame.Metadata;
         Assert.NotNull(meta);
         if (ignoreMetadata)
         {
             Assert.Null(rootFrameMetaData.XmpProfile);
             Assert.Null(rootFrameMetaData.ExifProfile);
         }
         else
         {
             Assert.NotNull(rootFrameMetaData.XmpProfile);
             Assert.NotNull(rootFrameMetaData.ExifProfile);
             Assert.Equal(2599, rootFrameMetaData.XmpProfile.Length);
             Assert.Equal(26, rootFrameMetaData.ExifProfile.Values.Count);
         }
     }
 }
Exemplo n.º 2
0
        public void TiffMetadata_CloneIsDeep()
        {
            var meta = new TiffMetadata
            {
                ByteOrder = ByteOrder.BigEndian,
            };

            var clone = (TiffMetadata)meta.DeepClone();

            clone.ByteOrder = ByteOrder.LittleEndian;

            Assert.False(meta.ByteOrder == clone.ByteOrder);
        }
Exemplo n.º 3
0
        public void Identify_DetectsCorrectByteOrder(string imagePath, ByteOrder expectedByteOrder)
        {
            var testFile = TestFile.Create(imagePath);

            using var stream = new MemoryStream(testFile.Bytes, false);

            IImageInfo imageInfo = Image.Identify(stream);

            Assert.NotNull(imageInfo);
            TiffMetadata tiffMetadata = imageInfo.Metadata.GetTiffMetadata();

            Assert.NotNull(tiffMetadata);
            Assert.Equal(expectedByteOrder, tiffMetadata.ByteOrder);
        }
Exemplo n.º 4
0
        public void Identify_DetectsCorrectBitPerPixel(string imagePath, int expectedBitsPerPixel)
        {
            var testFile = TestFile.Create(imagePath);

            using var stream = new MemoryStream(testFile.Bytes, false);

            IImageInfo imageInfo = Image.Identify(stream);

            Assert.NotNull(imageInfo);
            TiffMetadata tiffMetadata = imageInfo.Metadata.GetTiffMetadata();

            Assert.NotNull(tiffMetadata);
            Assert.Equal(expectedBitsPerPixel, imageInfo.PixelType.BitsPerPixel);
        }
Exemplo n.º 5
0
        public void Identify(string imagePath, int expectedPixelSize, int expectedWidth, int expectedHeight, double expectedHResolution, double expectedVResolution, PixelResolutionUnit expectedResolutionUnit)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                IImageInfo info = Image.Identify(stream);

                Assert.Equal(expectedPixelSize, info.PixelType?.BitsPerPixel);
                Assert.Equal(expectedWidth, info.Width);
                Assert.Equal(expectedHeight, info.Height);
                Assert.NotNull(info.Metadata);
                Assert.Equal(expectedHResolution, info.Metadata.HorizontalResolution);
                Assert.Equal(expectedVResolution, info.Metadata.VerticalResolution);
                Assert.Equal(expectedResolutionUnit, info.Metadata.ResolutionUnits);

                TiffMetadata tiffmeta = info.Metadata.GetTiffMetadata();
                Assert.NotNull(tiffmeta);
                Assert.Equal(TiffFormatType.BigTIFF, tiffmeta.FormatType);
            }
        }
Exemplo n.º 6
0
        public void SubfileType <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage(TiffDecoder))
            {
                TiffMetadata meta = image.Metadata.GetTiffMetadata();
                Assert.NotNull(meta);

                Assert.Equal(2, image.Frames.Count);

                ExifProfile frame0Exif = image.Frames[0].Metadata.ExifProfile;
                Assert.Equal(TiffNewSubfileType.FullImage, (TiffNewSubfileType)frame0Exif.GetValue(ExifTag.SubfileType).Value);
                Assert.Equal(255, image.Frames[0].Width);
                Assert.Equal(255, image.Frames[0].Height);

                ExifProfile frame1Exif = image.Frames[1].Metadata.ExifProfile;
                Assert.Equal(TiffNewSubfileType.Preview, (TiffNewSubfileType)frame1Exif.GetValue(ExifTag.SubfileType).Value);
                Assert.Equal(255, image.Frames[1].Width);
                Assert.Equal(255, image.Frames[1].Height);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TiffMetadata"/> class.
 /// </summary>
 /// <param name="other">The metadata to create an instance from.</param>
 private TiffMetadata(TiffMetadata other) => this.ByteOrder = other.ByteOrder;
Exemplo n.º 8
0
        public void BaselineTags <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage(TiffDecoder))
            {
                ImageFrame <TPixel> rootFrame = image.Frames.RootFrame;
                Assert.Equal(32, rootFrame.Width);
                Assert.Equal(32, rootFrame.Height);
                Assert.NotNull(rootFrame.Metadata.XmpProfile);
                Assert.Equal(2599, rootFrame.Metadata.XmpProfile.Length);

                ExifProfile       exifProfile       = rootFrame.Metadata.ExifProfile;
                TiffFrameMetadata tiffFrameMetadata = rootFrame.Metadata.GetTiffMetadata();
                Assert.NotNull(exifProfile);

                // The original exifProfile has 30 values, but 4 of those values will be stored in the TiffFrameMetaData
                // and removed from the profile on decode.
                Assert.Equal(26, exifProfile.Values.Count);
                Assert.Equal(TiffBitsPerPixel.Bit4, tiffFrameMetadata.BitsPerPixel);
                Assert.Equal(TiffCompression.Lzw, tiffFrameMetadata.Compression);
                Assert.Equal("This is Название", exifProfile.GetValue(ExifTag.ImageDescription).Value);
                Assert.Equal("This is Изготовитель камеры", exifProfile.GetValue(ExifTag.Make).Value);
                Assert.Equal("This is Модель камеры", exifProfile.GetValue(ExifTag.Model).Value);
                Assert.Equal("IrfanView", exifProfile.GetValue(ExifTag.Software).Value);
                Assert.Null(exifProfile.GetValue(ExifTag.DateTime)?.Value);
                Assert.Equal("This is author1;Author2", exifProfile.GetValue(ExifTag.Artist).Value);
                Assert.Null(exifProfile.GetValue(ExifTag.HostComputer)?.Value);
                Assert.Equal("This is Авторские права", exifProfile.GetValue(ExifTag.Copyright).Value);
                Assert.Equal(4, exifProfile.GetValue(ExifTag.Rating).Value);
                Assert.Equal(75, exifProfile.GetValue(ExifTag.RatingPercent).Value);
                var expectedResolution = new Rational(10000, 1000, simplify: false);
                Assert.Equal(expectedResolution, exifProfile.GetValue(ExifTag.XResolution).Value);
                Assert.Equal(expectedResolution, exifProfile.GetValue(ExifTag.YResolution).Value);
                Assert.Equal(new Number[] { 8u }, exifProfile.GetValue(ExifTag.StripOffsets)?.Value, new NumberComparer());
                Assert.Equal(new Number[] { 297u }, exifProfile.GetValue(ExifTag.StripByteCounts)?.Value, new NumberComparer());
                Assert.Null(exifProfile.GetValue(ExifTag.ExtraSamples)?.Value);
                Assert.Equal(32u, exifProfile.GetValue(ExifTag.RowsPerStrip).Value);
                Assert.Null(exifProfile.GetValue(ExifTag.SampleFormat));
                Assert.Equal(TiffPredictor.None, tiffFrameMetadata.Predictor);
                Assert.Equal(PixelResolutionUnit.PixelsPerInch, UnitConverter.ExifProfileToResolutionUnit(exifProfile));
                ushort[] colorMap = exifProfile.GetValue(ExifTag.ColorMap)?.Value;
                Assert.NotNull(colorMap);
                Assert.Equal(48, colorMap.Length);
                Assert.Equal(10537, colorMap[0]);
                Assert.Equal(14392, colorMap[1]);
                Assert.Equal(58596, colorMap[46]);
                Assert.Equal(3855, colorMap[47]);
                Assert.Equal(TiffPhotometricInterpretation.PaletteColor, tiffFrameMetadata.PhotometricInterpretation);
                Assert.Equal(1u, exifProfile.GetValue(ExifTag.SamplesPerPixel).Value);

                ImageMetadata imageMetaData = image.Metadata;
                Assert.NotNull(imageMetaData);
                Assert.Equal(PixelResolutionUnit.PixelsPerInch, imageMetaData.ResolutionUnits);
                Assert.Equal(10, imageMetaData.HorizontalResolution);
                Assert.Equal(10, imageMetaData.VerticalResolution);

                TiffMetadata tiffMetaData = image.Metadata.GetTiffMetadata();
                Assert.NotNull(tiffMetaData);
                Assert.Equal(ByteOrder.LittleEndian, tiffMetaData.ByteOrder);
            }
        }