/// <inheritdoc/> public Image <TPixel> Decode <TPixel>(BufferedReadStream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel <TPixel> { this.inputStream = stream; var reader = new DirectoryReader(stream); IEnumerable <ExifProfile> directories = reader.Read(); this.byteOrder = reader.ByteOrder; var frames = new List <ImageFrame <TPixel> >(); foreach (ExifProfile ifd in directories) { cancellationToken.ThrowIfCancellationRequested(); ImageFrame <TPixel> frame = this.DecodeFrame <TPixel>(ifd, cancellationToken); frames.Add(frame); } ImageMetadata metadata = TiffDecoderMetadataCreator.Create(frames, this.ignoreMetadata, reader.ByteOrder); // TODO: Tiff frames can have different sizes ImageFrame <TPixel> root = frames[0]; this.Dimensions = root.Size(); foreach (ImageFrame <TPixel> frame in frames) { if (frame.Size() != root.Size()) { TiffThrowHelper.ThrowNotSupported("Images with different sizes are not supported"); } } return(new Image <TPixel>(this.Configuration, metadata, frames)); }
/// <inheritdoc/> public IImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken) { this.inputStream = stream; var reader = new DirectoryReader(stream, this.Configuration.MemoryAllocator); IEnumerable <ExifProfile> directories = reader.Read(); ExifProfile rootFrameExifProfile = directories.First(); var rootMetadata = TiffFrameMetadata.Parse(rootFrameExifProfile); ImageMetadata metadata = TiffDecoderMetadataCreator.Create(reader.ByteOrder, reader.IsBigTiff, rootFrameExifProfile); int width = GetImageWidth(rootFrameExifProfile); int height = GetImageHeight(rootFrameExifProfile); return(new ImageInfo(new PixelTypeInfo((int)rootMetadata.BitsPerPixel), width, height, metadata)); }