Exemple #1
0
        public static async Task <TiffIfd?> ReadNextIfdAsync(TiffIfd ifd, Stream stream, ByteOrder byteOrder)
        {
            if (ifd.NextIfdReference == null)
            {
                return(null);
            }

            var nextIfd = await ReadIfdAsync(ifd.NextIfdReference.Value, stream, byteOrder);

            return(nextIfd);
        }
Exemple #2
0
        private static Task <string> ReadStringAsync(TiffIfd ifd, ushort tag, Stream stream, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, tag);

            if (entry == null)
            {
                return(Task.FromResult <string>(null));
            }
            else
            {
                return(entry.Value.ReadStringAsync(stream, byteOrder));
            }
        }
Exemple #3
0
        public static async Task <TiffIfdReference[]> ReadSubIfdReferencesAsync(TiffIfd ifd, Stream stream, ByteOrder byteOrder)
        {
            var subIfdsEntry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.SubIFDs);

            if (subIfdsEntry != null)
            {
                return(await subIfdsEntry.Value.ReadIfdReferenceArrayAsync(stream, byteOrder));
            }
            else
            {
                return(Array.Empty <TiffIfdReference>());
            }
        }
Exemple #4
0
        public static Task <uint[]> ReadBitsPerSampleAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.BitsPerSample);

            if (entry == null)
            {
                return(Task.FromResult(new uint[] { 1 }));
            }
            else
            {
                return(entry.Value.ReadIntegerArrayAsync(stream, byteOrder));
            }
        }
Exemple #5
0
        private async static Task <Rational?> ReadRationalAsync(TiffIfd ifd, ushort tag, Stream stream, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, tag);

            if (entry == null)
            {
                return(null);
            }
            else
            {
                return(await entry.Value.ReadRationalAsync(stream, byteOrder));
            }
        }
Exemple #6
0
        public static double GetGrayResponseUnit(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.GrayResponseUnit);

            if (entry == null)
            {
                return(0.01);
            }
            else
            {
                var value = entry.Value.GetInteger(byteOrder);
                return(Math.Pow(10, -value));
            }
        }
Exemple #7
0
        public async static Task <DateTimeOffset?> ReadDateTimeAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.DateTime);

            if (entry == null)
            {
                return(null);
            }
            else
            {
                var str = await entry.Value.ReadStringAsync(stream, byteOrder);

                return(DateTimeOffset.ParseExact(str, "yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal));
            }
        }
Exemple #8
0
        public async static Task <TiffExtraSamples[]> ReadExtraSamplesAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.ExtraSamples);

            if (entry == null)
            {
                return(new TiffExtraSamples[0]);
            }
            else
            {
                var values = await entry.Value.ReadIntegerArrayAsync(stream, byteOrder);

                var result = new TiffExtraSamples[values.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    result[i] = (TiffExtraSamples)values[i];
                }

                return(result);
            }
        }
Exemple #9
0
 public static Task <string> ReadCopyrightAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder) => ReadStringAsync(ifd, TiffTags.Copyright, stream, byteOrder);
Exemple #10
0
 public static Task <uint[]> ReadColorMapAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder) => ReadIntegerArrayAsync(ifd, TiffTags.ColorMap, stream, byteOrder);
Exemple #11
0
        public static TiffCompression GetCompression(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.Compression);

            return(entry == null ? TiffCompression.None : (TiffCompression)entry.Value.GetInteger(byteOrder));
        }
Exemple #12
0
 public static Task <uint[]> ReadGrayResponseCurveAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder) => ReadIntegerArrayAsync(ifd, TiffTags.GrayResponseCurve, stream, byteOrder);
Exemple #13
0
 public static uint GetSamplesPerPixel(this TiffIfd ifd, ByteOrder byteOrder) => GetInteger(ifd, TiffTags.SamplesPerPixel, byteOrder) ?? 1;
Exemple #14
0
        // Helper functions

        private static uint?GetInteger(TiffIfd ifd, ushort tag, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, tag);

            return(entry?.GetInteger(byteOrder));
        }
Exemple #15
0
 public static int SizeOfIfd(TiffIfd ifd) => ifd.Entries.Length * SIZEOF_IFDENTRY + 6;
Exemple #16
0
        public static TiffThreshholding GetThreshholding(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.Threshholding);

            return(entry == null ? TiffThreshholding.None : (TiffThreshholding)entry.Value.GetInteger(byteOrder));
        }
Exemple #17
0
 public static Task <Rational?> ReadYResolutionAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder) => ReadRationalAsync(ifd, TiffTags.YResolution, stream, byteOrder);
Exemple #18
0
        public static TiffSubfileType?GetSubfileType(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.SubfileType);

            return(entry == null ? null : (TiffSubfileType?)entry.Value.GetInteger(byteOrder));
        }
Exemple #19
0
 public static Task <uint[]> ReadStripByteCountsAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder) => ReadIntegerArrayAsync(ifd, TiffTags.StripByteCounts, stream, byteOrder);
Exemple #20
0
 public static Task <string> ReadSoftwareAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder) => ReadStringAsync(ifd, TiffTags.Software, stream, byteOrder);
Exemple #21
0
        public static TiffFillOrder GetFillOrder(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.FillOrder);

            return(entry == null ? TiffFillOrder.MostSignificantBitFirst : (TiffFillOrder)entry.Value.GetInteger(byteOrder));
        }
Exemple #22
0
        public static TiffPhotometricInterpretation?GetPhotometricInterpretation(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.PhotometricInterpretation);

            return(entry == null ? null : (TiffPhotometricInterpretation?)entry.Value.GetInteger(byteOrder));
        }
Exemple #23
0
 public static Task <uint[]> ReadFreeOffsetsAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder) => ReadIntegerArrayAsync(ifd, TiffTags.FreeOffsets, stream, byteOrder);
Exemple #24
0
        public static TiffResolutionUnit GetResolutionUnit(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.ResolutionUnit);

            return(entry == null ? TiffResolutionUnit.Inch : (TiffResolutionUnit)entry.Value.GetInteger(byteOrder));
        }
Exemple #25
0
        public static TiffOrientation GetOrientation(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.Orientation);

            return(entry == null ? TiffOrientation.TopLeft : (TiffOrientation)entry.Value.GetInteger(byteOrder));
        }
Exemple #26
0
 public static uint GetRowsPerStrip(this TiffIfd ifd, ByteOrder byteOrder) => GetInteger(ifd, TiffTags.RowsPerStrip, byteOrder) ?? UInt32.MaxValue;
Exemple #27
0
        public static TiffIfdEntry?GetTiffIfdEntry(TiffIfd ifd, ushort tag)
        {
            var entry = ifd.Entries.FirstOrDefault <TiffIfdEntry>(e => e.Tag == tag);

            return(entry.Tag == 0 ? (TiffIfdEntry?)null : entry);
        }
Exemple #28
0
 public static uint?GetCellWidth(this TiffIfd ifd, ByteOrder byteOrder) => GetInteger(ifd, TiffTags.CellWidth, byteOrder);
Exemple #29
0
        // Baseline TIFF fields

        public static Task <string> ReadArtistAsync(this TiffIfd ifd, Stream stream, ByteOrder byteOrder) => ReadStringAsync(ifd, TiffTags.Artist, stream, byteOrder);
Exemple #30
0
        public static TiffPlanarConfiguration GetPlanarConfiguration(this TiffIfd ifd, ByteOrder byteOrder)
        {
            var entry = TiffReader.GetTiffIfdEntry(ifd, TiffTags.PlanarConfiguration);

            return(entry == null ? TiffPlanarConfiguration.Chunky : (TiffPlanarConfiguration)entry.Value.GetInteger(byteOrder));
        }