Example #1
0
 public Task <IImageInfo> IdentifyAsync(Stream stream, CancellationToken cancellationToken)
 {
     if (!stream.CanSeek)
     {
         throw new InvalidOperationException("TIFF stream must be seekable.");
     }
     return(IdentifyCoreAsync(TiffFileContentSource.Create(stream, true), cancellationToken));
 }
Example #2
0
 public Task <Image <TPixel> > DecodeAsync <TPixel>(Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel <TPixel>
 {
     if (!stream.CanSeek)
     {
         throw new InvalidOperationException("TIFF stream must be seekable.");
     }
     return(DecodeCoreAsync <TPixel>(TiffFileContentSource.Create(stream, true), cancellationToken));
 }
        public static IEnumerable <object[]> GetContentSources()
        {
            // Reference content
            string file = @"Assets/PhotometricInterpretation/flower-minisblack-big-endian.tif";

            byte[] referenceContent = File.ReadAllBytes(file);
            byte[] clonedContent    = new byte[2000 + referenceContent.Length];
            referenceContent.CopyTo(clonedContent, 1000);

            // File source
            yield return(new object[]
            {
                referenceContent,
                TiffFileContentSource.Create(file, preferAsync: true)
            });

            // Stream source
            yield return(new object[]
            {
                referenceContent,
                TiffFileContentSource.Create(new MemoryStream(clonedContent, 1000, referenceContent.Length, writable: false), leaveOpen: true)
            });

            // ReadOnlyMemory source
            yield return(new object[]
            {
                referenceContent,
                TiffFileContentSource.Create(clonedContent.AsMemory(1000, referenceContent.Length))
            });

            // byte[] source
            yield return(new object[]
            {
                referenceContent,
                TiffFileContentSource.Create(clonedContent, 1000, referenceContent.Length)
            });

            var mmf = MemoryMappedFile.CreateFromFile(file, FileMode.Open, null, 0, MemoryMappedFileAccess.Read);

            byte[] mmfContent;
            using (MemoryMappedViewStream mmfStream = mmf.CreateViewStream(0, 0, MemoryMappedFileAccess.Read))
            {
                mmfContent = new byte[mmfStream.Length];
                mmfStream.Read(mmfContent, 0, mmfContent.Length);
            }

            // Memory-mapped file source
            yield return(new object[]
            {
                mmfContent,
                TiffFileContentSource.Create(mmf, leaveOpen: false)
            });
        }