/// <summary>Reads metadata from an <see cref="Stream"/>.</summary>
        /// <param name="stream">A stream from which the file data may be read.  The stream must be positioned at the beginning of the file's data.</param>
        /// <returns>A list of <see cref="Directory"/> instances containing the various types of metadata found within the file's data.</returns>
        /// <exception cref="ImageProcessingException">The file type is unknown, or processing errors occurred.</exception>
        /// <exception cref="System.IO.IOException"/>
        public static DirectoryList ReadMetadata(Stream stream)
        {
            var fileType = FileTypeDetector.DetectFileType(stream);

            var directories = new List <Directory>();

            directories.AddRange(fileType switch
            {
                FileType.Arw => TiffMetadataReader.ReadMetadata(stream),
                FileType.Avi => AviMetadataReader.ReadMetadata(stream),
                FileType.Bmp => BmpMetadataReader.ReadMetadata(stream),
                FileType.Crx => QuickTimeMetadataReader.ReadMetadata(stream),
                FileType.Cr2 => TiffMetadataReader.ReadMetadata(stream),
                FileType.Eps => EpsMetadataReader.ReadMetadata(stream),
                FileType.Gif => GifMetadataReader.ReadMetadata(stream),
                FileType.Ico => IcoMetadataReader.ReadMetadata(stream),
                FileType.Jpeg => JpegMetadataReader.ReadMetadata(stream),
                FileType.Mp3 => Mp3MetadataReader.ReadMetadata(stream),
                FileType.Nef => TiffMetadataReader.ReadMetadata(stream),
                FileType.Netpbm => new Directory[] { NetpbmMetadataReader.ReadMetadata(stream) },
                FileType.Orf => TiffMetadataReader.ReadMetadata(stream),
                FileType.Pcx => new Directory[] { PcxMetadataReader.ReadMetadata(stream) },
                FileType.Png => PngMetadataReader.ReadMetadata(stream),
                FileType.Psd => PsdMetadataReader.ReadMetadata(stream),
                FileType.QuickTime => QuickTimeMetadataReader.ReadMetadata(stream),
                FileType.Raf => RafMetadataReader.ReadMetadata(stream),
                FileType.Rw2 => TiffMetadataReader.ReadMetadata(stream),
                FileType.Tga => TgaMetadataReader.ReadMetadata(stream),
                FileType.Tiff => TiffMetadataReader.ReadMetadata(stream),
                FileType.Wav => WavMetadataReader.ReadMetadata(stream),
                FileType.WebP => WebPMetadataReader.ReadMetadata(stream),

                FileType.Unknown => throw new ImageProcessingException("File format could not be determined"),
                _ => Enumerable.Empty <Directory>()
            });
Beispiel #2
0
        ReadMetadata([NotNull] Stream stream)
        {
            var fileType = FileTypeDetector.DetectFileType(stream);

            switch (fileType)
            {
            case FileType.Jpeg:
                return(JpegMetadataReader.ReadMetadata(stream));

            case FileType.Tiff:
            case FileType.Arw:
            case FileType.Cr2:
            case FileType.Nef:
            case FileType.Orf:
            case FileType.Rw2:
                return(TiffMetadataReader.ReadMetadata(stream));

            case FileType.Psd:
                return(PsdMetadataReader.ReadMetadata(stream));

            case FileType.Png:
                return(PngMetadataReader.ReadMetadata(stream));

            case FileType.Bmp:
                return(new Directory[] { BmpMetadataReader.ReadMetadata(stream) });

            case FileType.Gif:
                return(GifMetadataReader.ReadMetadata(stream));

            case FileType.Ico:
                return(IcoMetadataReader.ReadMetadata(stream));

            case FileType.Pcx:
                return(new Directory[] { PcxMetadataReader.ReadMetadata(stream) });

            case FileType.Riff:
                return(WebPMetadataReader.ReadMetadata(stream));

            case FileType.Raf:
                return(RafMetadataReader.ReadMetadata(stream));

            case FileType.QuickTime:
                return(QuickTimeMetadataReader.ReadMetadata(stream));

            case FileType.Netpbm:
                return(new Directory[] { NetpbmMetadataReader.ReadMetadata(stream) });
            }

            throw new ImageProcessingException("File format is not supported");
        }
        public static Com.Drew.Metadata.Metadata ReadMetadata([NotNull] InputStream inputStream)
        {
            BufferedInputStream bufferedInputStream = inputStream is BufferedInputStream ? (BufferedInputStream)inputStream : new BufferedInputStream(inputStream);
            FileType            fileType            = FileTypeDetector.DetectFileType(bufferedInputStream) ?? FileType.Unknown;

            if (fileType == FileType.Jpeg)
            {
                return(JpegMetadataReader.ReadMetadata(bufferedInputStream));
            }
            if (fileType == FileType.Tiff || fileType == FileType.Arw || fileType == FileType.Cr2 || fileType == FileType.Nef || fileType == FileType.Orf || fileType == FileType.Rw2)
            {
                return(TiffMetadataReader.ReadMetadata(bufferedInputStream));
            }
            if (fileType == FileType.Psd)
            {
                return(PsdMetadataReader.ReadMetadata(bufferedInputStream));
            }
            if (fileType == FileType.Png)
            {
                return(PngMetadataReader.ReadMetadata(bufferedInputStream));
            }
            if (fileType == FileType.Bmp)
            {
                return(BmpMetadataReader.ReadMetadata(bufferedInputStream));
            }
            if (fileType == FileType.Gif)
            {
                return(GifMetadataReader.ReadMetadata(bufferedInputStream));
            }
            if (fileType == FileType.Ico)
            {
                return(IcoMetadataReader.ReadMetadata(bufferedInputStream));
            }
            if (fileType == FileType.Pcx)
            {
                return(PcxMetadataReader.ReadMetadata(bufferedInputStream));
            }
            if (fileType == FileType.Riff)
            {
                return(WebpMetadataReader.ReadMetadata(bufferedInputStream));
            }
            throw new ImageProcessingException("File format is not supported");
        }
        public static Com.Drew.Metadata.Metadata ReadMetadata(InputStream inputStream)
        {
            InputStream bufferedInputStream = inputStream is BufferedInputStream ? inputStream : new BufferedInputStream(inputStream);
            int         magicNumber         = PeekMagicNumber(bufferedInputStream);

            if (magicNumber == -1)
            {
                throw new ImageProcessingException("Could not determine file's magic number.");
            }
            // This covers all JPEG files
            if ((magicNumber & JpegFileMagicNumber) == JpegFileMagicNumber)
            {
                return(JpegMetadataReader.ReadMetadata(bufferedInputStream));
            }
            // This covers all TIFF and camera RAW files
            if (magicNumber == IntelTiffMagicNumber || magicNumber == MotorolaTiffMagicNumber)
            {
                return(TiffMetadataReader.ReadMetadata(bufferedInputStream));
            }
            // This covers PSD files
            // TODO we should really check all 4 bytes of the PSD magic number
            if (magicNumber == PsdMagicNumber)
            {
                return(PsdMetadataReader.ReadMetadata(bufferedInputStream));
            }
            // This covers BMP files
            if (magicNumber == PngMagicNumber)
            {
                return(PngMetadataReader.ReadMetadata(bufferedInputStream));
            }
            // This covers BMP files
            if (magicNumber == BmpMagicNumber)
            {
                return(BmpMetadataReader.ReadMetadata(bufferedInputStream));
            }
            // This covers GIF files
            if (magicNumber == GifMagicNumber)
            {
                return(GifMetadataReader.ReadMetadata(bufferedInputStream));
            }
            throw new ImageProcessingException("File format is not supported");
        }
Beispiel #5
0
        /// <summary>Reads metadata from an <see cref="Stream"/>.</summary>
        /// <param name="stream">A stream from which the file data may be read.  The stream must be positioned at the beginning of the file's data.</param>
        /// <returns>A list of <see cref="Directory"/> instances containing the various types of metadata found within the file's data.</returns>
        /// <exception cref="ImageProcessingException">The file type is unknown, or processing errors occurred.</exception>
        /// <exception cref="System.IO.IOException"/>
        public static DirectoryList ReadMetadata(Stream stream)
        {
            var fileType = FileTypeDetector.DetectFileType(stream);

            var fileTypeDirectory = new FileTypeDirectory(fileType);

            switch (fileType)
            {
            case FileType.Jpeg:
                return(Append(JpegMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Tiff:
            case FileType.Arw:
            case FileType.Cr2:
            case FileType.Nef:
            case FileType.Orf:
            case FileType.Rw2:
                return(Append(TiffMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Psd:
                return(Append(PsdMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Png:
                return(Append(PngMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Bmp:
                return(Append(BmpMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Gif:
                return(Append(GifMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Ico:
                return(Append(IcoMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Pcx:
                return(new Directory[] { PcxMetadataReader.ReadMetadata(stream), fileTypeDirectory });

            case FileType.WebP:
                return(Append(WebPMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Avi:
                return(Append(AviMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Wav:
                return(Append(WavMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Raf:
                return(Append(RafMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.QuickTime:
            case FileType.Crx:
                return(Append(QuickTimeMetadataReader.ReadMetadata(stream), fileTypeDirectory));

            case FileType.Netpbm:
                return(new Directory[] { NetpbmMetadataReader.ReadMetadata(stream), fileTypeDirectory });

            case FileType.Unknown:
                throw new ImageProcessingException("File format could not be determined");

            case FileType.Riff:
            case FileType.Crw:
            default:
                throw new ImageProcessingException("File format is not supported");
            }