From 8d4dd2ffde83b79700b9d7c59e6a6e5d87280d99 Mon Sep 17 00:00:00 2001 From: Ildar Khayrutdinov Date: Wed, 9 Dec 2020 18:15:23 +0300 Subject: [PATCH] Cleanup --- .../Tiff/__obsolete/TiffIfdEntryCreator.cs | 352 -------- .../Tiff/__obsolete/TiffMetadataNames.cs | 51 -- .../Formats/Tiff/__obsolete/TiffTagId.cs | 716 --------------- .../Formats/Tiff/__obsolete/TiffTagType.cs | 76 -- src/ImageSharp/ImageSharp.csproj | 6 - .../TestUtilities/Tiff/ITiffGenDataSource.cs | 15 - .../TestUtilities/Tiff/TiffGenDataBlock.cs | 28 - .../Tiff/TiffGenDataReference.cs | 20 - .../TestUtilities/Tiff/TiffGenEntry.cs | 204 ----- .../TestUtilities/Tiff/TiffGenExtensions.cs | 45 - .../TestUtilities/Tiff/TiffGenHeader.cs | 45 - .../TestUtilities/Tiff/TiffGenIfd.cs | 88 -- .../Tiff/TiffGenIfdExtensions.cs | 31 - .../TestUtilities/Tiff/TiffIfdParser.cs | 77 -- .../Tiff/__obsolete/TiffDecoderHeaderTests.cs | 110 --- .../__obsolete/TiffDecoderIfdEntryTests.cs | 842 ------------------ .../Tiff/__obsolete/TiffDecoderIfdTests.cs | 108 --- .../Tiff/__obsolete/TiffDecoderImageTests.cs | 510 ----------- .../__obsolete/TiffDecoderMetadataTests.cs | 134 --- .../Tiff/__obsolete/TiffEncoderIfdTests.cs | 295 ------ .../__obsolete/TiffEncoderMetadataTests.cs | 54 -- .../TiffIfd/TiffIfdEntryCreatorTests.cs | 406 --------- .../__obsolete/TiffIfd/TiffIfdEntryTests.cs | 23 - .../Tiff/__obsolete/TiffIfd/TiffIfdTests.cs | 93 -- .../TiffImageFormatDetectorTests.cs | 87 -- .../ImageSharp.Tests/ImageSharp.Tests.csproj | 6 - 26 files changed, 4422 deletions(-) delete mode 100644 src/ImageSharp/Formats/Tiff/__obsolete/TiffIfdEntryCreator.cs delete mode 100644 src/ImageSharp/Formats/Tiff/__obsolete/TiffMetadataNames.cs delete mode 100644 src/ImageSharp/Formats/Tiff/__obsolete/TiffTagId.cs delete mode 100644 src/ImageSharp/Formats/Tiff/__obsolete/TiffTagType.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/ITiffGenDataSource.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenDataBlock.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenDataReference.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenEntry.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenExtensions.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenHeader.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenIfd.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenIfdExtensions.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffIfdParser.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderHeaderTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderIfdEntryTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderIfdTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderImageTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderMetadataTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffEncoderIfdTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffEncoderMetadataTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdEntryCreatorTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdEntryTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdTests.cs delete mode 100644 tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffImageFormatDetectorTests.cs diff --git a/src/ImageSharp/Formats/Tiff/__obsolete/TiffIfdEntryCreator.cs b/src/ImageSharp/Formats/Tiff/__obsolete/TiffIfdEntryCreator.cs deleted file mode 100644 index e98a73b844..0000000000 --- a/src/ImageSharp/Formats/Tiff/__obsolete/TiffIfdEntryCreator.cs +++ /dev/null @@ -1,352 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace SixLabors.ImageSharp.Formats.Tiff -{ - /// - /// Utility class for generating TIFF IFD entries. - /// - internal static class TiffIfdEntryCreator - { - /// - /// Adds a new of type 'Byte' from a unsigned integer. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddUnsignedByte(this List entries, ushort tag, uint value) - { - TiffIfdEntryCreator.AddUnsignedByte(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'Byte' from an array of unsigned integers. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddUnsignedByte(this List entries, ushort tag, uint[] value) - { - byte[] bytes = new byte[value.Length]; - - for (int i = 0; i < value.Length; i++) - { - bytes[i] = (byte)value[i]; - } - - entries.Add(new TiffIfdEntry(tag, TiffType.Byte, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'Short' from a unsigned integer. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddUnsignedShort(this List entries, ushort tag, uint value) - { - TiffIfdEntryCreator.AddUnsignedShort(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'Short' from an array of unsigned integers. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddUnsignedShort(this List entries, ushort tag, uint[] value) - { - byte[] bytes = new byte[value.Length * TiffConstants.SizeOfShort]; - - for (int i = 0; i < value.Length; i++) - { - ToBytes((ushort)value[i], bytes, i * TiffConstants.SizeOfShort); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.Short, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'Long' from a unsigned integer. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddUnsignedLong(this List entries, ushort tag, uint value) - { - TiffIfdEntryCreator.AddUnsignedLong(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'Long' from an array of unsigned integers. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddUnsignedLong(this List entries, ushort tag, uint[] value) - { - byte[] bytes = new byte[value.Length * TiffConstants.SizeOfLong]; - - for (int i = 0; i < value.Length; i++) - { - ToBytes(value[i], bytes, i * TiffConstants.SizeOfLong); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.Long, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'SByte' from a signed integer. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddSignedByte(this List entries, ushort tag, int value) - { - TiffIfdEntryCreator.AddSignedByte(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'SByte' from an array of signed integers. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddSignedByte(this List entries, ushort tag, int[] value) - { - byte[] bytes = new byte[value.Length]; - - for (int i = 0; i < value.Length; i++) - { - bytes[i] = (byte)((sbyte)value[i]); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.SByte, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'SShort' from a signed integer. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddSignedShort(this List entries, ushort tag, int value) - { - TiffIfdEntryCreator.AddSignedShort(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'SShort' from an array of signed integers. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddSignedShort(this List entries, ushort tag, int[] value) - { - byte[] bytes = new byte[value.Length * TiffConstants.SizeOfShort]; - - for (int i = 0; i < value.Length; i++) - { - ToBytes((short)value[i], bytes, i * TiffConstants.SizeOfShort); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.SShort, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'SLong' from a signed integer. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddSignedLong(this List entries, ushort tag, int value) - { - TiffIfdEntryCreator.AddSignedLong(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'SLong' from an array of signed integers. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddSignedLong(this List entries, ushort tag, int[] value) - { - byte[] bytes = new byte[value.Length * TiffConstants.SizeOfLong]; - - for (int i = 0; i < value.Length; i++) - { - ToBytes(value[i], bytes, i * TiffConstants.SizeOfLong); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.SLong, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'Ascii' from a string. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddAscii(this List entries, ushort tag, string value) - { - byte[] bytes = Encoding.UTF8.GetBytes(value + "\0"); - - entries.Add(new TiffIfdEntry(tag, TiffType.Ascii, (uint)bytes.Length, bytes)); - } - - /// - /// Adds a new of type 'Rational' from a . - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddUnsignedRational(this List entries, ushort tag, Rational value) - { - TiffIfdEntryCreator.AddUnsignedRational(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'Rational' from an array of values. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddUnsignedRational(this List entries, ushort tag, Rational[] value) - { - byte[] bytes = new byte[value.Length * TiffConstants.SizeOfRational]; - - for (int i = 0; i < value.Length; i++) - { - int offset = i * TiffConstants.SizeOfRational; - ToBytes(value[i].Numerator, bytes, offset); - ToBytes(value[i].Denominator, bytes, offset + TiffConstants.SizeOfLong); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.Rational, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'SRational' from a . - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddSignedRational(this List entries, ushort tag, SignedRational value) - { - TiffIfdEntryCreator.AddSignedRational(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'SRational' from an array of values. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddSignedRational(this List entries, ushort tag, SignedRational[] value) - { - byte[] bytes = new byte[value.Length * TiffConstants.SizeOfRational]; - - for (int i = 0; i < value.Length; i++) - { - int offset = i * TiffConstants.SizeOfRational; - ToBytes(value[i].Numerator, bytes, offset); - ToBytes(value[i].Denominator, bytes, offset + TiffConstants.SizeOfLong); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.SRational, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'Float' from a floating-point value. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddFloat(this List entries, ushort tag, float value) - { - TiffIfdEntryCreator.AddFloat(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'Float' from an array of floating-point values. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddFloat(this List entries, ushort tag, float[] value) - { - byte[] bytes = new byte[value.Length * TiffConstants.SizeOfFloat]; - - for (int i = 0; i < value.Length; i++) - { - byte[] itemBytes = BitConverter.GetBytes(value[i]); - Array.Copy(itemBytes, 0, bytes, i * TiffConstants.SizeOfFloat, TiffConstants.SizeOfFloat); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.Float, (uint)value.Length, bytes)); - } - - /// - /// Adds a new of type 'Double' from a floating-point value. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddDouble(this List entries, ushort tag, double value) - { - TiffIfdEntryCreator.AddDouble(entries, tag, new[] { value }); - } - - /// - /// Adds a new of type 'Double' from an array of floating-point values. - /// - /// The list of to add the new entry to. - /// The tag for the resulting entry. - /// The value for the resulting entry. - public static void AddDouble(this List entries, ushort tag, double[] value) - { - byte[] bytes = new byte[value.Length * TiffConstants.SizeOfDouble]; - - for (int i = 0; i < value.Length; i++) - { - byte[] itemBytes = BitConverter.GetBytes(value[i]); - Array.Copy(itemBytes, 0, bytes, i * TiffConstants.SizeOfDouble, TiffConstants.SizeOfDouble); - } - - entries.Add(new TiffIfdEntry(tag, TiffType.Double, (uint)value.Length, bytes)); - } - - private static void ToBytes(ushort value, byte[] bytes, int offset) - { - bytes[offset + 0] = (byte)value; - bytes[offset + 1] = (byte)(value >> 8); - } - - private static void ToBytes(uint value, byte[] bytes, int offset) - { - bytes[offset + 0] = (byte)value; - bytes[offset + 1] = (byte)(value >> 8); - bytes[offset + 2] = (byte)(value >> 16); - bytes[offset + 3] = (byte)(value >> 24); - } - - private static void ToBytes(short value, byte[] bytes, int offset) - { - bytes[offset + 0] = (byte)value; - bytes[offset + 1] = (byte)(value >> 8); - } - - private static void ToBytes(int value, byte[] bytes, int offset) - { - bytes[offset + 0] = (byte)value; - bytes[offset + 1] = (byte)(value >> 8); - bytes[offset + 2] = (byte)(value >> 16); - bytes[offset + 3] = (byte)(value >> 24); - } - } -} diff --git a/src/ImageSharp/Formats/Tiff/__obsolete/TiffMetadataNames.cs b/src/ImageSharp/Formats/Tiff/__obsolete/TiffMetadataNames.cs deleted file mode 100644 index a610df8149..0000000000 --- a/src/ImageSharp/Formats/Tiff/__obsolete/TiffMetadataNames.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Formats.Tiff -{ - /// - /// Defines constants for each of the supported TIFF metadata types. - /// - public static class TiffMetadataNames - { - /// - /// Person who created the image. - /// - public const string Artist = "Artist"; - - /// - /// Copyright notice. - /// - public const string Copyright = "Copyright"; - - /// - /// Date and time of image creation. - /// - public const string DateTime = "DateTime"; - - /// - /// The computer and/or operating system in use at the time of image creation. - /// - public const string HostComputer = "HostComputer"; - - /// - /// A string that describes the subject of the image. - /// - public const string ImageDescription = "ImageDescription"; - - /// - /// The scanner/camera manufacturer. - /// - public const string Make = "Make"; - - /// - /// The scanner/camera model name or number. - /// - public const string Model = "Model"; - - /// - /// Name and version number of the software package(s) used to create the image. - /// - public const string Software = "Software"; - } -} diff --git a/src/ImageSharp/Formats/Tiff/__obsolete/TiffTagId.cs b/src/ImageSharp/Formats/Tiff/__obsolete/TiffTagId.cs deleted file mode 100644 index fe9b49ef7f..0000000000 --- a/src/ImageSharp/Formats/Tiff/__obsolete/TiffTagId.cs +++ /dev/null @@ -1,716 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Formats.Tiff -{ - /// - /// Constants representing tag IDs in the Tiff file-format. - /// - internal class TiffTags - { - /// - /// Artist (see Section 8: Baseline Fields). - /// - public const int Artist = 315; - - /// - /// BitsPerSample (see Section 8: Baseline Fields). - /// - public const int BitsPerSample = 258; - - /// - /// CellLength (see Section 8: Baseline Fields). - /// - public const int CellLength = 265; - - /// - /// CellWidth (see Section 8: Baseline Fields). - /// - public const int CellWidth = 264; - - /// - /// ColorMap (see Section 8: Baseline Fields). - /// - public const int ColorMap = 320; - - /// - /// Compression (see Section 8: Baseline Fields). - /// - public const int Compression = 259; - - /// - /// Copyright (see Section 8: Baseline Fields). - /// - public const int Copyright = 33432; - - /// - /// DateTime (see Section 8: Baseline Fields). - /// - public const int DateTime = 306; - - /// - /// ExtraSamples (see Section 8: Baseline Fields). - /// - public const int ExtraSamples = 338; - - /// - /// FillOrder (see Section 8: Baseline Fields). - /// - public const int FillOrder = 266; - - /// - /// FreeByteCounts (see Section 8: Baseline Fields). - /// - public const int FreeByteCounts = 289; - - /// - /// FreeOffsets (see Section 8: Baseline Fields). - /// - public const int FreeOffsets = 288; - - /// - /// GrayResponseCurve (see Section 8: Baseline Fields). - /// - public const int GrayResponseCurve = 291; - - /// - /// GrayResponseUnit (see Section 8: Baseline Fields). - /// - public const int GrayResponseUnit = 290; - - /// - /// HostComputer (see Section 8: Baseline Fields). - /// - public const int HostComputer = 316; - - /// - /// ImageDescription (see Section 8: Baseline Fields). - /// - public const int ImageDescription = 270; - - /// - /// ImageLength (see Section 8: Baseline Fields). - /// - public const int ImageLength = 257; - - /// - /// ImageWidth (see Section 8: Baseline Fields). - /// - public const int ImageWidth = 256; - - /// - /// Make (see Section 8: Baseline Fields). - /// - public const int Make = 271; - - /// - /// MaxSampleValue (see Section 8: Baseline Fields). - /// - public const int MaxSampleValue = 281; - - /// - /// MinSampleValue (see Section 8: Baseline Fields). - /// - public const int MinSampleValue = 280; - - /// - /// Model (see Section 8: Baseline Fields). - /// - public const int Model = 272; - - /// - /// NewSubfileType (see Section 8: Baseline Fields). - /// - public const int NewSubfileType = 254; - - /// - /// Orientation (see Section 8: Baseline Fields). - /// - public const int Orientation = 274; - - /// - /// PhotometricInterpretation (see Section 8: Baseline Fields). - /// - public const int PhotometricInterpretation = 262; - - /// - /// PlanarConfiguration (see Section 8: Baseline Fields). - /// - public const int PlanarConfiguration = 284; - - /// - /// ResolutionUnit (see Section 8: Baseline Fields). - /// - public const int ResolutionUnit = 296; - - /// - /// RowsPerStrip (see Section 8: Baseline Fields). - /// - public const int RowsPerStrip = 278; - - /// - /// SamplesPerPixel (see Section 8: Baseline Fields). - /// - public const int SamplesPerPixel = 277; - - /// - /// Software (see Section 8: Baseline Fields). - /// - public const int Software = 305; - - /// - /// StripByteCounts (see Section 8: Baseline Fields). - /// - public const int StripByteCounts = 279; - - /// - /// StripOffsets (see Section 8: Baseline Fields). - /// - public const int StripOffsets = 273; - - /// - /// SubfileType (see Section 8: Baseline Fields). - /// - public const int SubfileType = 255; - - /// - /// Threshholding (see Section 8: Baseline Fields). - /// - public const int Threshholding = 263; - - /// - /// XResolution (see Section 8: Baseline Fields). - /// - public const int XResolution = 282; - - /// - /// YResolution (see Section 8: Baseline Fields). - /// - public const int YResolution = 283; - - /// - /// T4Options (see Section 11: CCITT Bilevel Encodings). - /// - public const int T4Options = 292; - - /// - /// T6Options (see Section 11: CCITT Bilevel Encodings). - /// - public const int T6Options = 293; - - /// - /// DocumentName (see Section 12: Document Storage and Retrieval). - /// - public const int DocumentName = 269; - - /// - /// PageName (see Section 12: Document Storage and Retrieval). - /// - public const int PageName = 285; - - /// - /// PageNumber (see Section 12: Document Storage and Retrieval). - /// - public const int PageNumber = 297; - - /// - /// XPosition (see Section 12: Document Storage and Retrieval). - /// - public const int XPosition = 286; - - /// - /// YPosition (see Section 12: Document Storage and Retrieval). - /// - public const int YPosition = 287; - - /// - /// Predictor (see Section 14: Differencing Predictor). - /// - public const int Predictor = 317; - - /// - /// TileWidth (see Section 15: Tiled Images). - /// - public const int TileWidth = 322; - - /// - /// TileLength (see Section 15: Tiled Images). - /// - public const int TileLength = 323; - - /// - /// TileOffsets (see Section 15: Tiled Images). - /// - public const int TileOffsets = 324; - - /// - /// TileByteCounts (see Section 15: Tiled Images). - /// - public const int TileByteCounts = 325; - - /// - /// InkSet (see Section 16: CMYK Images). - /// - public const int InkSet = 332; - - /// - /// NumberOfInks (see Section 16: CMYK Images). - /// - public const int NumberOfInks = 334; - - /// - /// InkNames (see Section 16: CMYK Images). - /// - public const int InkNames = 333; - - /// - /// DotRange (see Section 16: CMYK Images). - /// - public const int DotRange = 336; - - /// - /// TargetPrinter (see Section 16: CMYK Images). - /// - public const int TargetPrinter = 337; - - /// - /// HalftoneHints (see Section 17: Halftone Hints). - /// - public const int HalftoneHints = 321; - - /// - /// SampleFormat (see Section 19: Data Sample Format). - /// - public const int SampleFormat = 339; - - /// - /// SMinSampleValue (see Section 19: Data Sample Format). - /// - public const int SMinSampleValue = 340; - - /// - /// SMaxSampleValue (see Section 19: Data Sample Format). - /// - public const int SMaxSampleValue = 341; - - /// - /// WhitePoint (see Section 20: RGB Image Colorimetry). - /// - public const int WhitePoint = 318; - - /// - /// PrimaryChromaticities (see Section 20: RGB Image Colorimetry). - /// - public const int PrimaryChromaticities = 319; - - /// - /// TransferFunction (see Section 20: RGB Image Colorimetry). - /// - public const int TransferFunction = 301; - - /// - /// TransferRange (see Section 20: RGB Image Colorimetry). - /// - public const int TransferRange = 342; - - /// - /// ReferenceBlackWhite (see Section 20: RGB Image Colorimetry). - /// - public const int ReferenceBlackWhite = 532; - - /// - /// YCbCrCoefficients (see Section 21: YCbCr Images). - /// - public const int YCbCrCoefficients = 529; - - /// - /// YCbCrSubSampling (see Section 21: YCbCr Images). - /// - public const int YCbCrSubSampling = 530; - - /// - /// YCbCrPositioning (see Section 21: YCbCr Images). - /// - public const int YCbCrPositioning = 531; - - /// - /// JpegProc (see Section 22: JPEG Compression). - /// - public const int JpegProc = 512; - - /// - /// JpegInterchangeFormat (see Section 22: JPEG Compression). - /// - public const int JpegInterchangeFormat = 513; - - /// - /// JpegInterchangeFormatLength (see Section 22: JPEG Compression). - /// - public const int JpegInterchangeFormatLength = 514; - - /// - /// JpegRestartInterval (see Section 22: JPEG Compression). - /// - public const int JpegRestartInterval = 515; - - /// - /// JpegLosslessPredictors (see Section 22: JPEG Compression). - /// - public const int JpegLosslessPredictors = 517; - - /// - /// JpegPointTransforms (see Section 22: JPEG Compression). - /// - public const int JpegPointTransforms = 518; - - /// - /// JpegQTables (see Section 22: JPEG Compression). - /// - public const int JpegQTables = 519; - - /// - /// JpegDCTables (see Section 22: JPEG Compression). - /// - public const int JpegDCTables = 520; - - /// - /// JpegACTables (see Section 22: JPEG Compression). - /// - public const int JpegACTables = 521; - - /// - /// SubIFDs (see TIFF Supplement 1: Adobe Pagemaker 6.0). - /// - public const int SubIFDs = 330; - - /// - /// ClipPath (see TIFF Supplement 1: Adobe Pagemaker 6.0). - /// - public const int ClipPath = 343; - - /// - /// XClipPathUnits (see TIFF Supplement 1: Adobe Pagemaker 6.0). - /// - public const int XClipPathUnits = 344; - - /// - /// YClipPathUnits (see TIFF Supplement 1: Adobe Pagemaker 6.0). - /// - public const int YClipPathUnits = 345; - - /// - /// Indexed (see TIFF Supplement 1: Adobe Pagemaker 6.0). - /// - public const int Indexed = 346; - - /// - /// ImageID (see TIFF Supplement 1: Adobe Pagemaker 6.0). - /// - public const int ImageID = 32781; - - /// - /// OpiProxy (see TIFF Supplement 1: Adobe Pagemaker 6.0). - /// - public const int OpiProxy = 351; - - /// - /// ImageSourceData (see TIFF Supplement 2: Adobe Photoshop). - /// - public const int ImageSourceData = 37724; - - /// - /// JPEGTables (see TIFF/EP Specification: Additional Tags). - /// - public const int JPEGTables = 0x015B; - - /// - /// CFARepeatPatternDim (see TIFF/EP Specification: Additional Tags). - /// - public const int CFARepeatPatternDim = 0x828D; - - /// - /// BatteryLevel (see TIFF/EP Specification: Additional Tags). - /// - public const int BatteryLevel = 0x828F; - - /// - /// Interlace (see TIFF/EP Specification: Additional Tags). - /// - public const int Interlace = 0x8829; - - /// - /// TimeZoneOffset (see TIFF/EP Specification: Additional Tags). - /// - public const int TimeZoneOffset = 0x882A; - - /// - /// SelfTimerMode (see TIFF/EP Specification: Additional Tags). - /// - public const int SelfTimerMode = 0x882B; - - /// - /// Noise (see TIFF/EP Specification: Additional Tags). - /// - public const int Noise = 0x920D; - - /// - /// ImageNumber (see TIFF/EP Specification: Additional Tags). - /// - public const int ImageNumber = 0x9211; - - /// - /// SecurityClassification (see TIFF/EP Specification: Additional Tags). - /// - public const int SecurityClassification = 0x9212; - - /// - /// ImageHistory (see TIFF/EP Specification: Additional Tags). - /// - public const int ImageHistory = 0x9213; - - /// - /// TiffEPStandardID (see TIFF/EP Specification: Additional Tags). - /// - public const int TiffEPStandardID = 0x9216; - - /// - /// BadFaxLines (see RFC2301: TIFF-F/FX Specification). - /// - public const int BadFaxLines = 326; - - /// - /// CleanFaxData (see RFC2301: TIFF-F/FX Specification). - /// - public const int CleanFaxData = 327; - - /// - /// ConsecutiveBadFaxLines (see RFC2301: TIFF-F/FX Specification). - /// - public const int ConsecutiveBadFaxLines = 328; - - /// - /// GlobalParametersIFD (see RFC2301: TIFF-F/FX Specification). - /// - public const int GlobalParametersIFD = 400; - - /// - /// ProfileType (see RFC2301: TIFF-F/FX Specification). - /// - public const int ProfileType = 401; - - /// - /// FaxProfile (see RFC2301: TIFF-F/FX Specification). - /// - public const int FaxProfile = 402; - - /// - /// CodingMethod (see RFC2301: TIFF-F/FX Specification). - /// - public const int CodingMethod = 403; - - /// - /// VersionYear (see RFC2301: TIFF-F/FX Specification). - /// - public const int VersionYear = 404; - - /// - /// ModeNumber (see RFC2301: TIFF-F/FX Specification). - /// - public const int ModeNumber = 405; - - /// - /// Decode (see RFC2301: TIFF-F/FX Specification). - /// - public const int Decode = 433; - - /// - /// DefaultImageColor (see RFC2301: TIFF-F/FX Specification). - /// - public const int DefaultImageColor = 434; - - /// - /// StripRowCounts (see RFC2301: TIFF-F/FX Specification). - /// - public const int StripRowCounts = 559; - - /// - /// ImageLayer (see RFC2301: TIFF-F/FX Specification). - /// - public const int ImageLayer = 34732; - - /// - /// Xmp (Embedded Metadata). - /// - public const int Xmp = 700; - - /// - /// Iptc (Embedded Metadata). - /// - public const int Iptc = 33723; - - /// - /// Photoshop (Embedded Metadata). - /// - public const int Photoshop = 34377; - - /// - /// ExifIFD (Embedded Metadata). - /// - public const int ExifIFD = 34665; - - /// - /// GpsIFD (Embedded Metadata). - /// - public const int GpsIFD = 34853; - - /// - /// InteroperabilityIFD (Embedded Metadata). - /// - public const int InteroperabilityIFD = 40965; - - /// - /// WangAnnotation (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int WangAnnotation = 32932; - - /// - /// MDFileTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int MDFileTag = 33445; - - /// - /// MDScalePixel (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int MDScalePixel = 33446; - - /// - /// MDColorTable (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int MDColorTable = 33447; - - /// - /// MDLabName (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int MDLabName = 33448; - - /// - /// MDSampleInfo (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int MDSampleInfo = 33449; - - /// - /// MDPrepDate (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int MDPrepDate = 33450; - - /// - /// MDPrepTime (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int MDPrepTime = 33451; - - /// - /// MDFileUnits (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int MDFileUnits = 33452; - - /// - /// ModelPixelScaleTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int ModelPixelScaleTag = 33550; - - /// - /// IngrPacketDataTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int IngrPacketDataTag = 33918; - - /// - /// IngrFlagRegisters (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int IngrFlagRegisters = 33919; - - /// - /// IrasBTransformationMatrix (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int IrasBTransformationMatrix = 33920; - - /// - /// ModelTiePointTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int ModelTiePointTag = 33922; - - /// - /// ModelTransformationTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int ModelTransformationTag = 34264; - - /// - /// IccProfile (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int IccProfile = 34675; - - /// - /// GeoKeyDirectoryTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int GeoKeyDirectoryTag = 34735; - - /// - /// GeoDoubleParamsTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int GeoDoubleParamsTag = 34736; - - /// - /// GeoAsciiParamsTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int GeoAsciiParamsTag = 34737; - - /// - /// HylaFAXFaxRecvParams (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int HylaFAXFaxRecvParams = 34908; - - /// - /// HylaFAXFaxSubAddress (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int HylaFAXFaxSubAddress = 34909; - - /// - /// HylaFAXFaxRecvTime (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int HylaFAXFaxRecvTime = 34910; - - /// - /// GdalMetadata (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int GdalMetadata = 42112; - - /// - /// GdalNodata (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int GdalNodata = 42113; - - /// - /// OceScanjobDescription (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int OceScanjobDescription = 50215; - - /// - /// OceApplicationSelector (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int OceApplicationSelector = 50216; - - /// - /// OceIdentificationNumber (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int OceIdentificationNumber = 50217; - - /// - /// OceImageLogicCharacteristics (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int OceImageLogicCharacteristics = 50218; - - /// - /// AliasLayerMetadata (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html). - /// - public const int AliasLayerMetadata = 50784; - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Tiff/__obsolete/TiffTagType.cs b/src/ImageSharp/Formats/Tiff/__obsolete/TiffTagType.cs deleted file mode 100644 index f1d0adfc23..0000000000 --- a/src/ImageSharp/Formats/Tiff/__obsolete/TiffTagType.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Formats.Tiff -{ - /// - /// Enumeration representing the data types understood by the Tiff file-format. - /// - internal enum TiffType - { - /// - /// Unsigned 8-bit integer. - /// - Byte = 1, - - /// - /// ASCII formatted text. - /// - Ascii = 2, - - /// - /// Unsigned 16-bit integer. - /// - Short = 3, - - /// - /// Unsigned 32-bit integer. - /// - Long = 4, - - /// - /// Unsigned rational number. - /// - Rational = 5, - - /// - /// Signed 8-bit integer. - /// - SByte = 6, - - /// - /// Undefined data type. - /// - Undefined = 7, - - /// - /// Signed 16-bit integer. - /// - SShort = 8, - - /// - /// Signed 32-bit integer. - /// - SLong = 9, - - /// - /// Signed rational number. - /// - SRational = 10, - - /// - /// Single precision (4-byte) IEEE format. - /// - Float = 11, - - /// - /// Double precision (8-byte) IEEE format. - /// - Double = 12, - - /// - /// Reference to an IFD. - /// - Ifd = 13 - } -} \ No newline at end of file diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 65f59331da..1d7fb2958b 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -15,12 +15,6 @@ netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.3;net472 - - - - - - diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/ITiffGenDataSource.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/ITiffGenDataSource.cs deleted file mode 100644 index 4e66879b90..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/ITiffGenDataSource.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - using System.Collections.Generic; - - /// - /// An interface for any class within the Tiff generator that produces data to be included in the file. - /// - internal interface ITiffGenDataSource - { - IEnumerable GetData(bool isLittleEndian); - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenDataBlock.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenDataBlock.cs deleted file mode 100644 index 1dd70b57b1..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenDataBlock.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - using System.Collections.Generic; - - /// - /// A utility data structure to represent an independent block of data in a Tiff file. - /// These may be located in any order within a Tiff file. - /// - internal class TiffGenDataBlock - { - public TiffGenDataBlock(byte[] bytes) - { - this.Bytes = bytes; - this.References = new List(); - } - - public byte[] Bytes { get; } - public IList References { get; } - - public void AddReference(byte[] bytes, int offset) - { - References.Add(new TiffGenDataReference(bytes, offset)); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenDataReference.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenDataReference.cs deleted file mode 100644 index 4c044ac523..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenDataReference.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - /// - /// A utility data structure to represent a reference from one block of data to another in a Tiff file. - /// - internal class TiffGenDataReference - { - public TiffGenDataReference(byte[] bytes, int offset) - { - this.Bytes = bytes; - this.Offset = offset; - } - - public byte[] Bytes { get; } - public int Offset { get; } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenEntry.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenEntry.cs deleted file mode 100644 index a652ba01bd..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenEntry.cs +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using ImageSharp.Formats.Tiff; - - /// - /// A utility data structure to represent Tiff IFD entries in unit tests. - /// - internal abstract class TiffGenEntry : ITiffGenDataSource - { - private TiffGenEntry(ushort tag, TiffType type, uint count) - { - this.Tag = tag; - this.Type = type; - this.Count = count; - } - - public uint Count { get; } - public ushort Tag { get; } - public TiffType Type { get; } - - public abstract IEnumerable GetData(bool isLittleEndian); - - public static TiffGenEntry Ascii(ushort tag, string value) - { - return new TiffGenEntryAscii(tag, value); - } - - public static TiffGenEntry Bytes(ushort tag, TiffType type, uint count, byte[] value) - { - return new TiffGenEntryBytes(tag, type, count, value); - } - - public static TiffGenEntry Integer(ushort tag, TiffType type, int value) - { - return TiffGenEntry.Integer(tag, type, new int[] { value }); - } - - public static TiffGenEntry Integer(ushort tag, TiffType type, int[] value) - { - if (type != TiffType.Byte && type != TiffType.Short && type != TiffType.Long && - type != TiffType.SByte && type != TiffType.SShort && type != TiffType.SLong) - throw new ArgumentException(nameof(type), "The specified type is not an integer type."); - - return new TiffGenEntryInteger(tag, type, value); - } - - public static TiffGenEntry Integer(ushort tag, TiffType type, uint value) - { - return TiffGenEntry.Integer(tag, type, new uint[] { value }); - } - - public static TiffGenEntry Integer(ushort tag, TiffType type, uint[] value) - { - if (type != TiffType.Byte && type != TiffType.Short && type != TiffType.Long && - type != TiffType.SByte && type != TiffType.SShort && type != TiffType.SLong) - throw new ArgumentException(nameof(type), "The specified type is not an integer type."); - - return new TiffGenEntryUnsignedInteger(tag, type, value); - } - - public static TiffGenEntry Rational(ushort tag, uint numerator, uint denominator) - { - return new TiffGenEntryRational(tag, numerator, denominator); - } - - private class TiffGenEntryAscii : TiffGenEntry - { - public TiffGenEntryAscii(ushort tag, string value) : base(tag, TiffType.Ascii, (uint)GetBytes(value).Length) - { - this.Value = value; - } - - public string Value { get; } - - public override IEnumerable GetData(bool isLittleEndian) - { - byte[] bytes = GetBytes(Value); - return new[] { new TiffGenDataBlock(bytes) }; - } - - private static byte[] GetBytes(string value) - { - return Encoding.ASCII.GetBytes($"{value}\0"); - } - } - - private class TiffGenEntryBytes : TiffGenEntry - { - public TiffGenEntryBytes(ushort tag, TiffType type, uint count, byte[] value) : base(tag, type, count) - { - this.Value = value; - } - - public byte[] Value { get; } - - public override IEnumerable GetData(bool isLittleEndian) - { - return new[] { new TiffGenDataBlock(Value) }; - } - } - - private class TiffGenEntryInteger : TiffGenEntry - { - public TiffGenEntryInteger(ushort tag, TiffType type, int[] value) : base(tag, type, (uint)value.Length) - { - this.Value = value; - } - - public int[] Value { get; } - - public override IEnumerable GetData(bool isLittleEndian) - { - byte[] bytes = GetBytes().SelectMany(b => b.WithByteOrder(isLittleEndian)).ToArray(); - return new[] { new TiffGenDataBlock(bytes) }; - } - - private IEnumerable GetBytes() - { - switch (Type) - { - case TiffType.Byte: - return Value.Select(i => new byte[] { (byte)i }); - case TiffType.Short: - return Value.Select(i => BitConverter.GetBytes((ushort)i)); - case TiffType.Long: - return Value.Select(i => BitConverter.GetBytes((uint)i)); - case TiffType.SByte: - return Value.Select(i => BitConverter.GetBytes((sbyte)i)); - case TiffType.SShort: - return Value.Select(i => BitConverter.GetBytes((short)i)); - case TiffType.SLong: - return Value.Select(i => BitConverter.GetBytes((int)i)); - default: - throw new InvalidOperationException(); - } - } - } - - private class TiffGenEntryUnsignedInteger : TiffGenEntry - { - public TiffGenEntryUnsignedInteger(ushort tag, TiffType type, uint[] value) : base(tag, type, (uint)value.Length) - { - this.Value = value; - } - - public uint[] Value { get; } - - public override IEnumerable GetData(bool isLittleEndian) - { - byte[] bytes = GetBytes().SelectMany(b => b.WithByteOrder(isLittleEndian)).ToArray(); - return new[] { new TiffGenDataBlock(bytes) }; - } - - private IEnumerable GetBytes() - { - switch (Type) - { - case TiffType.Byte: - return Value.Select(i => new byte[] { (byte)i }); - case TiffType.Short: - return Value.Select(i => BitConverter.GetBytes((ushort)i)); - case TiffType.Long: - return Value.Select(i => BitConverter.GetBytes((uint)i)); - case TiffType.SByte: - return Value.Select(i => BitConverter.GetBytes((sbyte)i)); - case TiffType.SShort: - return Value.Select(i => BitConverter.GetBytes((short)i)); - case TiffType.SLong: - return Value.Select(i => BitConverter.GetBytes((int)i)); - default: - throw new InvalidOperationException(); - } - } - } - - private class TiffGenEntryRational : TiffGenEntry - { - public TiffGenEntryRational(ushort tag, uint numerator, uint denominator) : base(tag, TiffType.Rational, 1u) - { - this.Numerator = numerator; - this.Denominator = denominator; - } - - public uint Numerator { get; } - - public uint Denominator { get; } - - public override IEnumerable GetData(bool isLittleEndian) - { - byte[] numeratorBytes = BitConverter.GetBytes(Numerator).WithByteOrder(isLittleEndian); - byte[] denominatorBytes = BitConverter.GetBytes(Denominator).WithByteOrder(isLittleEndian); - byte[] bytes = Enumerable.Concat(numeratorBytes, denominatorBytes).ToArray(); - return new[] { new TiffGenDataBlock(bytes) }; - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenExtensions.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenExtensions.cs deleted file mode 100644 index edef6c0641..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenExtensions.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - using System; - using System.IO; - using System.Linq; - - /// - /// A utility class for generating in-memory Tiff files for use in unit tests. - /// - internal static class TiffGenExtensions - { - public static byte[] ToBytes(this ITiffGenDataSource dataSource, bool isLittleEndian) - { - var dataBlocks = dataSource.GetData(isLittleEndian); - - int offset = 0; - - foreach (var dataBlock in dataBlocks) - { - byte[] offsetBytes = BitConverter.GetBytes(offset).WithByteOrder(isLittleEndian); - - foreach (var reference in dataBlock.References) - { - reference.Bytes[reference.Offset + 0] = offsetBytes[0]; - reference.Bytes[reference.Offset + 1] = offsetBytes[1]; - reference.Bytes[reference.Offset + 2] = offsetBytes[2]; - reference.Bytes[reference.Offset + 3] = offsetBytes[3]; - } - - offset += dataBlock.Bytes.Length; - } - - return dataBlocks.SelectMany(b => b.Bytes).ToArray(); - } - - public static Stream ToStream(this ITiffGenDataSource dataSource, bool isLittleEndian) - { - var bytes = dataSource.ToBytes(isLittleEndian); - return new MemoryStream(bytes); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenHeader.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenHeader.cs deleted file mode 100644 index be2784fca2..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenHeader.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - using System.Collections.Generic; - using System.Linq; - - /// - /// A utility data structure to represent a Tiff file-header. - /// - internal class TiffGenHeader : ITiffGenDataSource - { - public TiffGenHeader() - { - this.MagicNumber = 42; - } - - public ushort? ByteOrderMarker { get; set; } - public ushort MagicNumber { get; set; } - public TiffGenIfd FirstIfd { get; set; } - - public IEnumerable GetData(bool isLittleEndian) - { - ByteBuffer bytes = new ByteBuffer(isLittleEndian); - - bytes.AddUInt16(ByteOrderMarker ?? (isLittleEndian ? (ushort)0x4949 : (ushort)0x4D4D)); - bytes.AddUInt16(MagicNumber); - bytes.AddUInt32(0); - - var headerData = new TiffGenDataBlock(bytes.ToArray()); - - if (FirstIfd != null) - { - var firstIfdData = FirstIfd.GetData(isLittleEndian); - firstIfdData.First().AddReference(headerData.Bytes, 4); - return new[] { headerData }.Concat(firstIfdData); - } - else - { - return new[] { headerData }; - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenIfd.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenIfd.cs deleted file mode 100644 index 99ef0d1339..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenIfd.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Linq; - - /// - /// A utility data structure to represent Tiff IFDs in unit tests. - /// - internal class TiffGenIfd : ITiffGenDataSource - { - public TiffGenIfd() - { - this.Entries = new List(); - } - - public List Entries { get; } - public TiffGenIfd NextIfd { get; set; } - - public IEnumerable GetData(bool isLittleEndian) - { - ByteBuffer bytes = new ByteBuffer(isLittleEndian); - List dataBlocks = new List(); - List> entryReferences = new List>(); - - // Add the entry count - - bytes.AddUInt16((ushort)Entries.Count); - - // Add all IFD entries - - int entryOffset = 2; - - foreach (var entry in Entries) - { - var entryData = entry.GetData(isLittleEndian); - var entryBytes = entryData.First().Bytes; - - bytes.AddUInt16(entry.Tag); - bytes.AddUInt16((ushort)entry.Type); - bytes.AddUInt32(entry.Count); - - if (entryBytes.Length <=4) - { - bytes.AddByte(entryBytes.Length > 0 ? entryBytes[0] : (byte)0); - bytes.AddByte(entryBytes.Length > 1 ? entryBytes[1] : (byte)0); - bytes.AddByte(entryBytes.Length > 2 ? entryBytes[2] : (byte)0); - bytes.AddByte(entryBytes.Length > 3 ? entryBytes[3] : (byte)0); - - dataBlocks.AddRange(entryData.Skip(1)); - } - else - { - bytes.AddUInt32(0); - dataBlocks.AddRange(entryData); - entryReferences.Add(Tuple.Create(entryData.First(), entryOffset + 8)); - } - - entryOffset += 12; - } - - // Add reference to next IFD - - bytes.AddUInt32(0); - - // Build the data - - var ifdData = new TiffGenDataBlock(bytes.ToArray()); - - foreach (var entryReference in entryReferences) - { - entryReference.Item1.AddReference(ifdData.Bytes, entryReference.Item2); - } - - IEnumerable nextIfdData = new TiffGenDataBlock[0]; - if (NextIfd != null) - { - nextIfdData = NextIfd.GetData(isLittleEndian); - nextIfdData.First().AddReference(ifdData.Bytes, ifdData.Bytes.Length - 4); - } - - return new [] { ifdData }.Concat(dataBlocks).Concat(nextIfdData); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenIfdExtensions.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenIfdExtensions.cs deleted file mode 100644 index bfa74c3d0f..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffGenIfdExtensions.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - using System.Linq; - - /// - /// A utility class for manipulating in-memory Tiff files for use in unit tests. - /// - internal static class TiffGenIfdExtensions - { - public static TiffGenIfd WithoutEntry(this TiffGenIfd ifd, ushort tag) - { - TiffGenEntry entry = ifd.Entries.FirstOrDefault(e => e.Tag == tag); - if (entry != null) - { - ifd.Entries.Remove(entry); - } - return ifd; - } - - public static TiffGenIfd WithEntry(this TiffGenIfd ifd, TiffGenEntry entry) - { - ifd.WithoutEntry(entry.Tag); - ifd.Entries.Add(entry); - - return ifd; - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffIfdParser.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffIfdParser.cs deleted file mode 100644 index 51890204f0..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TestUtilities/Tiff/TiffIfdParser.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using ImageSharp.Formats.Tiff; - - using SixLabors.ImageSharp.Metadata.Profiles.Exif; - using Xunit; - - /// - /// A utility data structure to decode Tiff IFD entries in unit tests. - /// - internal static class TiffIfdParser - { - public static int? GetInteger(this List entries, ushort tag) - { - TiffIfdEntry entry = entries.FirstOrDefault(e => e.Tag == tag); - - if (entry.Tag == 0) - return null; - - Assert.Equal(1u, entry.Count); - - switch (entry.Type) - { - case TiffType.Byte: - return entry.Value[0]; - case TiffType.SByte: - return (sbyte)entry.Value[0]; - case TiffType.Short: - return BitConverter.ToUInt16(entry.Value, 0); - case TiffType.SShort: - return BitConverter.ToInt16(entry.Value, 0); - case TiffType.Long: - return (int)BitConverter.ToUInt32(entry.Value, 0); - case TiffType.SLong: - return BitConverter.ToInt32(entry.Value, 0); - default: - Assert.True(1 == 1, "TIFF IFD entry is not convertable to an integer."); - return null; - } - } - - public static Rational? GetUnsignedRational(this List entries, ushort tag) - { - TiffIfdEntry entry = entries.FirstOrDefault(e => e.Tag == tag); - - if (entry.Tag == 0) - return null; - - Assert.Equal(TiffType.Rational, entry.Type); - Assert.Equal(1u, entry.Count); - - uint numerator = BitConverter.ToUInt32(entry.Value, 0); - uint denominator = BitConverter.ToUInt32(entry.Value, 4); - - return new Rational(numerator, denominator); - } - - public static string GetAscii(this List entries, ushort tag) - { - TiffIfdEntry entry = entries.FirstOrDefault(e => e.Tag == tag); - - if (entry.Tag == 0) - return null; - - Assert.Equal(TiffType.Ascii, entry.Type); - - return Encoding.UTF8.GetString(entry.Value, 0, (int)entry.Count); - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderHeaderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderHeaderTests.cs deleted file mode 100644 index 275da7da1e..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderHeaderTests.cs +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System.IO; -using SixLabors.ImageSharp.Formats.Tiff; -using SixLabors.ImageSharp.PixelFormats; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffDecoderHeaderTests - { - public static object[][] IsLittleEndianValues = new[] { new object[] { false }, - new object[] { true } }; - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadHeader_ReadsEndianness(bool isLittleEndian) - { - Stream stream = new TiffGenHeader() - { - FirstIfd = new TiffGenIfd() - } - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, false, null, null); - - decoder.ReadHeader(); - - Assert.Equal(isLittleEndian, decoder.IsLittleEndian); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadHeader_ReadsFirstIfdOffset(bool isLittleEndian) - { - Stream stream = new TiffGenHeader() - { - FirstIfd = new TiffGenIfd() - } - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, false, null, null); - - uint firstIfdOffset = decoder.ReadHeader(); - - Assert.Equal(8u, firstIfdOffset); - } - - [Theory] - [InlineData(0x1234)] - [InlineData(0x4912)] - [InlineData(0x1249)] - [InlineData(0x4D12)] - [InlineData(0x124D)] - [InlineData(0x494D)] - [InlineData(0x4D49)] - public void Decode_ThrowsException_WithInvalidByteOrderMarkers(ushort byteOrderMarker) - { - Stream stream = new TiffGenHeader() - { - FirstIfd = new TiffGenIfd(), - ByteOrderMarker = byteOrderMarker - } - .ToStream(true); - - TiffDecoder decoder = new TiffDecoder(); - - ImageFormatException e = Assert.Throws(() => { decoder.Decode(Configuration.Default, stream); }); - - Assert.Equal("Invalid TIFF file header.", e.Message); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void Decode_ThrowsException_WithIncorrectMagicNumber(bool isLittleEndian) - { - Stream stream = new TiffGenHeader() - { - FirstIfd = new TiffGenIfd(), - MagicNumber = 32 - } - .ToStream(isLittleEndian); - - TiffDecoder decoder = new TiffDecoder(); - - ImageFormatException e = Assert.Throws(() => { decoder.Decode(Configuration.Default, stream); }); - - Assert.Equal("Invalid TIFF file header.", e.Message); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void Decode_ThrowsException_WithNoIfdZero(bool isLittleEndian) - { - Stream stream = new TiffGenHeader() - { - FirstIfd = null - } - .ToStream(isLittleEndian); - - TiffDecoder decoder = new TiffDecoder(); - - ImageFormatException e = Assert.Throws(() => { decoder.Decode(Configuration.Default, stream); }); - - Assert.Equal("Invalid TIFF file header.", e.Message); - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderIfdEntryTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderIfdEntryTests.cs deleted file mode 100644 index f8d41cb864..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderIfdEntryTests.cs +++ /dev/null @@ -1,842 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.IO; -using System.Linq; -using SixLabors.ImageSharp.Formats.Tiff; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffDecoderIfdEntryTests - { - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte, 1u, 1u)] - [InlineDataAttribute((ushort)TiffType.Ascii, 1u, 1u)] - [InlineDataAttribute((ushort)TiffType.Short, 1u, 2u)] - [InlineDataAttribute((ushort)TiffType.Long, 1u, 4u)] - [InlineDataAttribute((ushort)TiffType.Rational, 1u, 8u)] - [InlineDataAttribute((ushort)TiffType.SByte, 1u, 1u)] - [InlineDataAttribute((ushort)TiffType.Undefined, 1u, 1u)] - [InlineDataAttribute((ushort)TiffType.SShort, 1u, 2u)] - [InlineDataAttribute((ushort)TiffType.SLong, 1u, 4u)] - [InlineDataAttribute((ushort)TiffType.SRational, 1u, 8u)] - [InlineDataAttribute((ushort)TiffType.Float, 1u, 4u)] - [InlineDataAttribute((ushort)TiffType.Double, 1u, 8u)] - [InlineDataAttribute((ushort)TiffType.Ifd, 1u, 4u)] - [InlineDataAttribute((ushort)999, 1u, 0u)] - public void GetSizeOfData_SingleItem_ReturnsCorrectSize(ushort type, uint count, uint expectedSize) - { - TiffIfdEntry entry = new TiffIfdEntry(TiffTags.ImageWidth, (TiffType)type, count, new byte[4]); - uint size = TiffDecoderCore.GetSizeOfData(entry); - Assert.Equal(expectedSize, size); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte, 15u, 15u)] - [InlineDataAttribute((ushort)TiffType.Ascii, 20u, 20u)] - [InlineDataAttribute((ushort)TiffType.Short, 18u, 36u)] - [InlineDataAttribute((ushort)TiffType.Long, 4u, 16u)] - [InlineDataAttribute((ushort)TiffType.Rational, 9u, 72u)] - [InlineDataAttribute((ushort)TiffType.SByte, 5u, 5u)] - [InlineDataAttribute((ushort)TiffType.Undefined, 136u, 136u)] - [InlineDataAttribute((ushort)TiffType.SShort, 12u, 24u)] - [InlineDataAttribute((ushort)TiffType.SLong, 15u, 60u)] - [InlineDataAttribute((ushort)TiffType.SRational, 10u, 80u)] - [InlineDataAttribute((ushort)TiffType.Float, 2u, 8u)] - [InlineDataAttribute((ushort)TiffType.Double, 2u, 16u)] - [InlineDataAttribute((ushort)TiffType.Ifd, 10u, 40u)] - [InlineDataAttribute((ushort)999, 1050u, 0u)] - public void GetSizeOfData_Array_ReturnsCorrectSize(ushort type, uint count, uint expectedSize) - { - TiffIfdEntry entry = new TiffIfdEntry(TiffTags.ImageWidth, (TiffType)type, count, new byte[4]); - uint size = TiffDecoderCore.GetSizeOfData(entry); - Assert.Equal(expectedSize, size); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte, 1u, new byte[] { 17 }, false)] - [InlineDataAttribute((ushort)TiffType.Byte, 1u, new byte[] { 17 }, true)] - [InlineDataAttribute((ushort)TiffType.Byte, 2u, new byte[] { 17, 28 }, false)] - [InlineDataAttribute((ushort)TiffType.Byte, 2u, new byte[] { 17, 28 }, true)] - [InlineDataAttribute((ushort)TiffType.Byte, 4u, new byte[] { 17, 28, 2, 9 }, false)] - [InlineDataAttribute((ushort)TiffType.Byte, 4u, new byte[] { 17, 28, 2, 9 }, true)] - [InlineDataAttribute((ushort)TiffType.Byte, 5u, new byte[] { 17, 28, 2, 9, 13 }, false)] - [InlineDataAttribute((ushort)TiffType.Byte, 5u, new byte[] { 17, 28, 2, 9, 13 }, true)] - [InlineDataAttribute((ushort)TiffType.Byte, 10u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2, 127, 86 }, false)] - [InlineDataAttribute((ushort)TiffType.Byte, 10u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2, 127, 86 }, true)] - [InlineDataAttribute((ushort)TiffType.Short, 1u, new byte[] { 17, 28 }, false)] - [InlineDataAttribute((ushort)TiffType.Short, 1u, new byte[] { 17, 28 }, true)] - [InlineDataAttribute((ushort)TiffType.Short, 2u, new byte[] { 17, 28, 2, 9 }, false)] - [InlineDataAttribute((ushort)TiffType.Short, 2u, new byte[] { 17, 28, 2, 9 }, true)] - [InlineDataAttribute((ushort)TiffType.Short, 3u, new byte[] { 17, 28, 2, 9, 13, 37 }, false)] - [InlineDataAttribute((ushort)TiffType.Short, 3u, new byte[] { 17, 28, 2, 9, 13, 37 }, true)] - [InlineDataAttribute((ushort)TiffType.Long, 1u, new byte[] { 17, 28, 2, 9 }, false)] - [InlineDataAttribute((ushort)TiffType.Long, 1u, new byte[] { 17, 28, 2, 9 }, true)] - [InlineDataAttribute((ushort)TiffType.Long, 2u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2 }, false)] - [InlineDataAttribute((ushort)TiffType.Long, 2u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2 }, true)] - [InlineDataAttribute((ushort)TiffType.Rational, 1u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2 }, false)] - [InlineDataAttribute((ushort)TiffType.Rational, 1u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2 }, true)] - public void ReadBytes_ReturnsExpectedData(ushort type, uint count, byte[] bytes, bool isLittleEndian) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, count, bytes), isLittleEndian); - - byte[] result = decoder.ReadBytes(ref entry); - - if (bytes.Length < 4) - result = result.Take(bytes.Length).ToArray(); - - Assert.Equal(bytes, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte, 5u, new byte[] { 17, 28, 2, 9, 13 }, false)] - [InlineDataAttribute((ushort)TiffType.Byte, 5u, new byte[] { 17, 28, 2, 9, 13 }, true)] - [InlineDataAttribute((ushort)TiffType.Byte, 10u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2, 127, 86 }, false)] - [InlineDataAttribute((ushort)TiffType.Byte, 10u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2, 127, 86 }, true)] - [InlineDataAttribute((ushort)TiffType.Short, 3u, new byte[] { 17, 28, 2, 9, 13, 37 }, false)] - [InlineDataAttribute((ushort)TiffType.Short, 3u, new byte[] { 17, 28, 2, 9, 13, 37 }, true)] - [InlineDataAttribute((ushort)TiffType.Long, 2u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2 }, false)] - [InlineDataAttribute((ushort)TiffType.Long, 2u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2 }, true)] - [InlineDataAttribute((ushort)TiffType.Rational, 1u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2 }, false)] - [InlineDataAttribute((ushort)TiffType.Rational, 1u, new byte[] { 17, 28, 2, 9, 13, 37, 18, 2 }, true)] - public void ReadBytes_CachesDataLongerThanFourBytes(ushort type, uint count, byte[] bytes, bool isLittleEndian) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, count, bytes), isLittleEndian); - - Assert.Equal(4, entry.Value.Length); - - byte[] result = decoder.ReadBytes(ref entry); - - Assert.Equal(bytes.Length, entry.Value.Length); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte, true, new byte[] { 0, 1, 2, 3 }, 0)] - [InlineDataAttribute((ushort)TiffType.Byte, true, new byte[] { 1, 2, 3, 4 }, 1)] - [InlineDataAttribute((ushort)TiffType.Byte, true, new byte[] { 255, 2, 3, 4 }, 255)] - [InlineDataAttribute((ushort)TiffType.Byte, false, new byte[] { 0, 1, 2, 3 }, 0)] - [InlineDataAttribute((ushort)TiffType.Byte, false, new byte[] { 1, 2, 3, 4 }, 1)] - [InlineDataAttribute((ushort)TiffType.Byte, false, new byte[] { 255, 2, 3, 4 }, 255)] - [InlineDataAttribute((ushort)TiffType.Short, true, new byte[] { 0, 0, 2, 3 }, 0)] - [InlineDataAttribute((ushort)TiffType.Short, true, new byte[] { 1, 0, 2, 3 }, 1)] - [InlineDataAttribute((ushort)TiffType.Short, true, new byte[] { 0, 1, 2, 3 }, 256)] - [InlineDataAttribute((ushort)TiffType.Short, true, new byte[] { 2, 1, 2, 3 }, 258)] - [InlineDataAttribute((ushort)TiffType.Short, true, new byte[] { 255, 255, 2, 3 }, UInt16.MaxValue)] - [InlineDataAttribute((ushort)TiffType.Short, false, new byte[] { 0, 0, 2, 3 }, 0)] - [InlineDataAttribute((ushort)TiffType.Short, false, new byte[] { 0, 1, 2, 3 }, 1)] - [InlineDataAttribute((ushort)TiffType.Short, false, new byte[] { 1, 0, 2, 3 }, 256)] - [InlineDataAttribute((ushort)TiffType.Short, false, new byte[] { 1, 2, 2, 3 }, 258)] - [InlineDataAttribute((ushort)TiffType.Short, false, new byte[] { 255, 255, 2, 3 }, UInt16.MaxValue)] - [InlineDataAttribute((ushort)TiffType.Long, true, new byte[] { 0, 0, 0, 0 }, 0)] - [InlineDataAttribute((ushort)TiffType.Long, true, new byte[] { 1, 0, 0, 0 }, 1)] - [InlineDataAttribute((ushort)TiffType.Long, true, new byte[] { 0, 1, 0, 0 }, 256)] - [InlineDataAttribute((ushort)TiffType.Long, true, new byte[] { 0, 0, 1, 0 }, 256 * 256)] - [InlineDataAttribute((ushort)TiffType.Long, true, new byte[] { 0, 0, 0, 1 }, 256 * 256 * 256)] - [InlineDataAttribute((ushort)TiffType.Long, true, new byte[] { 1, 2, 3, 4 }, 67305985)] - [InlineDataAttribute((ushort)TiffType.Long, true, new byte[] { 255, 255, 255, 255 }, UInt32.MaxValue)] - [InlineDataAttribute((ushort)TiffType.Long, false, new byte[] { 0, 0, 0, 0 }, 0)] - [InlineDataAttribute((ushort)TiffType.Long, false, new byte[] { 0, 0, 0, 1 }, 1)] - [InlineDataAttribute((ushort)TiffType.Long, false, new byte[] { 0, 0, 1, 0 }, 256)] - [InlineDataAttribute((ushort)TiffType.Long, false, new byte[] { 0, 1, 0, 0 }, 256 * 256)] - [InlineDataAttribute((ushort)TiffType.Long, false, new byte[] { 1, 0, 0, 0 }, 256 * 256 * 256)] - [InlineDataAttribute((ushort)TiffType.Long, false, new byte[] { 4, 3, 2, 1 }, 67305985)] - [InlineDataAttribute((ushort)TiffType.Long, false, new byte[] { 255, 255, 255, 255 }, UInt32.MaxValue)] - public void ReadUnsignedInteger_ReturnsValue(ushort type, bool isLittleEndian, byte[] bytes, uint expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, bytes), isLittleEndian); - - uint result = decoder.ReadUnsignedInteger(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadUnsignedInteger_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadUnsignedInteger(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to an unsigned integer.", e.Message); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte, true)] - [InlineDataAttribute((ushort)TiffType.Short, true)] - [InlineDataAttribute((ushort)TiffType.Long, true)] - [InlineDataAttribute((ushort)TiffType.Byte, false)] - [InlineDataAttribute((ushort)TiffType.Short, false)] - [InlineDataAttribute((ushort)TiffType.Long, false)] - public void ReadUnsignedInteger_ThrowsExceptionIfCountIsNotOne(ushort type, bool isLittleEndian) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 2, new byte[4]), isLittleEndian); - - var e = Assert.Throws(() => decoder.ReadUnsignedInteger(ref entry)); - - Assert.Equal($"Cannot read a single value from an array of multiple items.", e.Message); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.SByte, true, new byte[] { 0, 1, 2, 3 }, 0)] - [InlineDataAttribute((ushort)TiffType.SByte, true, new byte[] { 1, 2, 3, 4 }, 1)] - [InlineDataAttribute((ushort)TiffType.SByte, true, new byte[] { 255, 2, 3, 4 }, -1)] - [InlineDataAttribute((ushort)TiffType.SByte, false, new byte[] { 0, 1, 2, 3 }, 0)] - [InlineDataAttribute((ushort)TiffType.SByte, false, new byte[] { 1, 2, 3, 4 }, 1)] - [InlineDataAttribute((ushort)TiffType.SByte, false, new byte[] { 255, 2, 3, 4 }, -1)] - [InlineDataAttribute((ushort)TiffType.SShort, true, new byte[] { 0, 0, 2, 3 }, 0)] - [InlineDataAttribute((ushort)TiffType.SShort, true, new byte[] { 1, 0, 2, 3 }, 1)] - [InlineDataAttribute((ushort)TiffType.SShort, true, new byte[] { 0, 1, 2, 3 }, 256)] - [InlineDataAttribute((ushort)TiffType.SShort, true, new byte[] { 2, 1, 2, 3 }, 258)] - [InlineDataAttribute((ushort)TiffType.SShort, true, new byte[] { 255, 255, 2, 3 }, -1)] - [InlineDataAttribute((ushort)TiffType.SShort, false, new byte[] { 0, 0, 2, 3 }, 0)] - [InlineDataAttribute((ushort)TiffType.SShort, false, new byte[] { 0, 1, 2, 3 }, 1)] - [InlineDataAttribute((ushort)TiffType.SShort, false, new byte[] { 1, 0, 2, 3 }, 256)] - [InlineDataAttribute((ushort)TiffType.SShort, false, new byte[] { 1, 2, 2, 3 }, 258)] - [InlineDataAttribute((ushort)TiffType.SShort, false, new byte[] { 255, 255, 2, 3 }, -1)] - [InlineDataAttribute((ushort)TiffType.SLong, true, new byte[] { 0, 0, 0, 0 }, 0)] - [InlineDataAttribute((ushort)TiffType.SLong, true, new byte[] { 1, 0, 0, 0 }, 1)] - [InlineDataAttribute((ushort)TiffType.SLong, true, new byte[] { 0, 1, 0, 0 }, 256)] - [InlineDataAttribute((ushort)TiffType.SLong, true, new byte[] { 0, 0, 1, 0 }, 256 * 256)] - [InlineDataAttribute((ushort)TiffType.SLong, true, new byte[] { 0, 0, 0, 1 }, 256 * 256 * 256)] - [InlineDataAttribute((ushort)TiffType.SLong, true, new byte[] { 1, 2, 3, 4 }, 67305985)] - [InlineDataAttribute((ushort)TiffType.SLong, true, new byte[] { 255, 255, 255, 255 }, -1)] - [InlineDataAttribute((ushort)TiffType.SLong, false, new byte[] { 0, 0, 0, 0 }, 0)] - [InlineDataAttribute((ushort)TiffType.SLong, false, new byte[] { 0, 0, 0, 1 }, 1)] - [InlineDataAttribute((ushort)TiffType.SLong, false, new byte[] { 0, 0, 1, 0 }, 256)] - [InlineDataAttribute((ushort)TiffType.SLong, false, new byte[] { 0, 1, 0, 0 }, 256 * 256)] - [InlineDataAttribute((ushort)TiffType.SLong, false, new byte[] { 1, 0, 0, 0 }, 256 * 256 * 256)] - [InlineDataAttribute((ushort)TiffType.SLong, false, new byte[] { 4, 3, 2, 1 }, 67305985)] - [InlineDataAttribute((ushort)TiffType.SLong, false, new byte[] { 255, 255, 255, 255 }, -1)] - public void ReadSignedInteger_ReturnsValue(ushort type, bool isLittleEndian, byte[] bytes, int expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, bytes), isLittleEndian); - - int result = decoder.ReadSignedInteger(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadSignedInteger_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadSignedInteger(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a signed integer.", e.Message); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.SByte, true)] - [InlineDataAttribute((ushort)TiffType.SShort, true)] - [InlineDataAttribute((ushort)TiffType.SLong, true)] - [InlineDataAttribute((ushort)TiffType.SByte, false)] - [InlineDataAttribute((ushort)TiffType.SShort, false)] - [InlineDataAttribute((ushort)TiffType.SLong, false)] - public void ReadSignedInteger_ThrowsExceptionIfCountIsNotOne(ushort type, bool isLittleEndian) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 2, new byte[4]), isLittleEndian); - - var e = Assert.Throws(() => decoder.ReadSignedInteger(ref entry)); - - Assert.Equal($"Cannot read a single value from an array of multiple items.", e.Message); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte, 1, true, new byte[] { 0, 1, 2, 3 }, new uint[] { 0 })] - [InlineDataAttribute((ushort)TiffType.Byte, 3, true, new byte[] { 0, 1, 2, 3 }, new uint[] { 0, 1, 2 })] - [InlineDataAttribute((ushort)TiffType.Byte, 7, true, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, new uint[] { 0, 1, 2, 3, 4, 5, 6 })] - [InlineDataAttribute((ushort)TiffType.Byte, 1, false, new byte[] { 0, 1, 2, 3 }, new uint[] { 0 })] - [InlineDataAttribute((ushort)TiffType.Byte, 3, false, new byte[] { 0, 1, 2, 3 }, new uint[] { 0, 1, 2 })] - [InlineDataAttribute((ushort)TiffType.Byte, 7, false, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, new uint[] { 0, 1, 2, 3, 4, 5, 6 })] - [InlineDataAttribute((ushort)TiffType.Short, 1, true, new byte[] { 1, 0, 3, 2 }, new uint[] { 1 })] - [InlineDataAttribute((ushort)TiffType.Short, 2, true, new byte[] { 1, 0, 3, 2 }, new uint[] { 1, 515 })] - [InlineDataAttribute((ushort)TiffType.Short, 3, true, new byte[] { 1, 0, 3, 2, 5, 4, 6, 7, 8 }, new uint[] { 1, 515, 1029 })] - [InlineDataAttribute((ushort)TiffType.Short, 1, false, new byte[] { 0, 1, 2, 3 }, new uint[] { 1 })] - [InlineDataAttribute((ushort)TiffType.Short, 2, false, new byte[] { 0, 1, 2, 3 }, new uint[] { 1, 515 })] - [InlineDataAttribute((ushort)TiffType.Short, 3, false, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, new uint[] { 1, 515, 1029 })] - [InlineDataAttribute((ushort)TiffType.Long, 1, true, new byte[] { 4, 3, 2, 1 }, new uint[] { 0x01020304 })] - [InlineDataAttribute((ushort)TiffType.Long, 2, true, new byte[] { 4, 3, 2, 1, 6, 5, 4, 3, 99, 99 }, new uint[] { 0x01020304, 0x03040506 })] - [InlineDataAttribute((ushort)TiffType.Long, 1, false, new byte[] { 1, 2, 3, 4 }, new uint[] { 0x01020304 })] - [InlineDataAttribute((ushort)TiffType.Long, 2, false, new byte[] { 1, 2, 3, 4, 3, 4, 5, 6, 99, 99 }, new uint[] { 0x01020304, 0x03040506 })] - public void ReadUnsignedIntegerArray_ReturnsValue(ushort type, int count, bool isLittleEndian, byte[] bytes, uint[] expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, (uint)expectedValue.Length, bytes), isLittleEndian); - - uint[] result = decoder.ReadUnsignedIntegerArray(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadUnsignedIntegerArray_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadUnsignedIntegerArray(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to an unsigned integer.", e.Message); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.SByte, 1, true, new byte[] { 0, 1, 2, 3 }, new int[] { 0 })] - [InlineDataAttribute((ushort)TiffType.SByte, 3, true, new byte[] { 0, 255, 2, 3 }, new int[] { 0, -1, 2 })] - [InlineDataAttribute((ushort)TiffType.SByte, 7, true, new byte[] { 0, 255, 2, 3, 4, 5, 6, 7, 8 }, new int[] { 0, -1, 2, 3, 4, 5, 6 })] - [InlineDataAttribute((ushort)TiffType.SByte, 1, false, new byte[] { 0, 1, 2, 3 }, new int[] { 0 })] - [InlineDataAttribute((ushort)TiffType.SByte, 3, false, new byte[] { 0, 255, 2, 3 }, new int[] { 0, -1, 2 })] - [InlineDataAttribute((ushort)TiffType.SByte, 7, false, new byte[] { 0, 255, 2, 3, 4, 5, 6, 7, 8 }, new int[] { 0, -1, 2, 3, 4, 5, 6 })] - [InlineDataAttribute((ushort)TiffType.SShort, 1, true, new byte[] { 1, 0, 3, 2 }, new int[] { 1 })] - [InlineDataAttribute((ushort)TiffType.SShort, 2, true, new byte[] { 1, 0, 255, 255 }, new int[] { 1, -1 })] - [InlineDataAttribute((ushort)TiffType.SShort, 3, true, new byte[] { 1, 0, 255, 255, 5, 4, 6, 7, 8 }, new int[] { 1, -1, 1029 })] - [InlineDataAttribute((ushort)TiffType.SShort, 1, false, new byte[] { 0, 1, 2, 3 }, new int[] { 1 })] - [InlineDataAttribute((ushort)TiffType.SShort, 2, false, new byte[] { 0, 1, 255, 255 }, new int[] { 1, -1 })] - [InlineDataAttribute((ushort)TiffType.SShort, 3, false, new byte[] { 0, 1, 255, 255, 4, 5, 6, 7, 8 }, new int[] { 1, -1, 1029 })] - [InlineDataAttribute((ushort)TiffType.SLong, 1, true, new byte[] { 4, 3, 2, 1 }, new int[] { 0x01020304 })] - [InlineDataAttribute((ushort)TiffType.SLong, 2, true, new byte[] { 4, 3, 2, 1, 255, 255, 255, 255, 99, 99 }, new int[] { 0x01020304, -1 })] - [InlineDataAttribute((ushort)TiffType.SLong, 1, false, new byte[] { 1, 2, 3, 4 }, new int[] { 0x01020304 })] - [InlineDataAttribute((ushort)TiffType.SLong, 2, false, new byte[] { 1, 2, 3, 4, 255, 255, 255, 255, 99, 99 }, new int[] { 0x01020304, -1 })] - public void ReadSignedIntegerArray_ReturnsValue(ushort type, int count, bool isLittleEndian, byte[] bytes, int[] expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, (uint)expectedValue.Length, bytes), isLittleEndian); - - int[] result = decoder.ReadSignedIntegerArray(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadSignedIntegerArray_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadSignedIntegerArray(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a signed integer.", e.Message); - } - - [Theory] - [InlineDataAttribute(true, new byte[] { 0 }, "")] - [InlineDataAttribute(true, new byte[] { (byte)'A', (byte)'B', (byte)'C', 0 }, "ABC")] - [InlineDataAttribute(true, new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', 0 }, "ABCDEF")] - [InlineDataAttribute(true, new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', 0, (byte)'E', (byte)'F', (byte)'G', (byte)'H', 0 }, "ABCD\0EFGH")] - [InlineDataAttribute(false, new byte[] { 0 }, "")] - [InlineDataAttribute(false, new byte[] { (byte)'A', (byte)'B', (byte)'C', 0 }, "ABC")] - [InlineDataAttribute(false, new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', 0 }, "ABCDEF")] - [InlineDataAttribute(false, new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', 0, (byte)'E', (byte)'F', (byte)'G', (byte)'H', 0 }, "ABCD\0EFGH")] - public void ReadString_ReturnsValue(bool isLittleEndian, byte[] bytes, string expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Ascii, (uint)bytes.Length, bytes), isLittleEndian); - - string result = decoder.ReadString(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadString_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadString(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a string.", e.Message); - } - - [Theory] - [InlineDataAttribute(true, new byte[] { (byte)'A' })] - [InlineDataAttribute(true, new byte[] { (byte)'A', (byte)'B', (byte)'C' })] - [InlineDataAttribute(true, new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F' })] - [InlineDataAttribute(true, new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', 0, (byte)'E', (byte)'F', (byte)'G', (byte)'H' })] - [InlineDataAttribute(false, new byte[] { (byte)'A' })] - [InlineDataAttribute(false, new byte[] { (byte)'A', (byte)'B', (byte)'C' })] - [InlineDataAttribute(false, new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F' })] - [InlineDataAttribute(false, new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', 0, (byte)'E', (byte)'F', (byte)'G', (byte)'H' })] - public void ReadString_ThrowsExceptionIfStringIsNotNullTerminated(bool isLittleEndian, byte[] bytes) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Ascii, (uint)bytes.Length, bytes), isLittleEndian); - - var e = Assert.Throws(() => decoder.ReadString(ref entry)); - - Assert.Equal($"The retrieved string is not null terminated.", e.Message); - } - - [Theory] - [InlineDataAttribute(true, new byte[] { 0, 0, 0, 0, 2, 0, 0, 0 }, 0, 2)] - [InlineDataAttribute(true, new byte[] { 1, 0, 0, 0, 2, 0, 0, 0 }, 1, 2)] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }, 0, 2)] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 1, 0, 0, 0, 2 }, 1, 2)] - public void ReadUnsignedRational_ReturnsValue(bool isLittleEndian, byte[] bytes, uint expectedNumerator, uint expectedDenominator) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Rational, 1, bytes), isLittleEndian); - - Rational result = decoder.ReadUnsignedRational(ref entry); - Rational expectedValue = new Rational(expectedNumerator, expectedDenominator); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute(true, new byte[] { 0, 0, 0, 0, 2, 0, 0, 0 }, 0, 2)] - [InlineDataAttribute(true, new byte[] { 1, 0, 0, 0, 2, 0, 0, 0 }, 1, 2)] - [InlineDataAttribute(true, new byte[] { 255, 255, 255, 255, 2, 0, 0, 0 }, -1, 2)] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }, 0, 2)] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 1, 0, 0, 0, 2 }, 1, 2)] - [InlineDataAttribute(false, new byte[] { 255, 255, 255, 255, 0, 0, 0, 2 }, -1, 2)] - public void ReadSignedRational_ReturnsValue(bool isLittleEndian, byte[] bytes, int expectedNumerator, int expectedDenominator) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.SRational, 1, bytes), isLittleEndian); - - SignedRational result = decoder.ReadSignedRational(ref entry); - SignedRational expectedValue = new SignedRational(expectedNumerator, expectedDenominator); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute(true, new byte[] { 0, 0, 0, 0, 2, 0, 0, 0 }, new uint[] { 0 }, new uint[] { 2 })] - [InlineDataAttribute(true, new byte[] { 1, 0, 0, 0, 2, 0, 0, 0 }, new uint[] { 1 }, new uint[] { 2 })] - [InlineDataAttribute(true, new byte[] { 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0 }, new uint[] { 1, 2 }, new uint[] { 2, 3 })] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }, new uint[] { 0 }, new uint[] { 2 })] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 1, 0, 0, 0, 2 }, new uint[] { 1 }, new uint[] { 2 })] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 3 }, new uint[] { 1, 2 }, new uint[] { 2, 3 })] - public void ReadUnsignedRationalArray_ReturnsValue(bool isLittleEndian, byte[] bytes, uint[] expectedNumerators, uint[] expectedDenominators) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Rational, (uint)expectedNumerators.Length, bytes), isLittleEndian); - - Rational[] result = decoder.ReadUnsignedRationalArray(ref entry); - Rational[] expectedValue = Enumerable.Range(0, expectedNumerators.Length).Select(i => new Rational(expectedNumerators[i], expectedDenominators[i])).ToArray(); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute(true, new byte[] { 0, 0, 0, 0, 2, 0, 0, 0 }, new int[] { 0 }, new int[] { 2 })] - [InlineDataAttribute(true, new byte[] { 1, 0, 0, 0, 2, 0, 0, 0 }, new int[] { 1 }, new int[] { 2 })] - [InlineDataAttribute(true, new byte[] { 255, 255, 255, 255, 2, 0, 0, 0 }, new int[] { -1 }, new int[] { 2 })] - [InlineDataAttribute(true, new byte[] { 255, 255, 255, 255, 2, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0 }, new int[] { -1, 2 }, new int[] { 2, 3 })] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }, new int[] { 0 }, new int[] { 2 })] - [InlineDataAttribute(false, new byte[] { 0, 0, 0, 1, 0, 0, 0, 2 }, new int[] { 1 }, new int[] { 2 })] - [InlineDataAttribute(false, new byte[] { 255, 255, 255, 255, 0, 0, 0, 2 }, new int[] { -1 }, new int[] { 2 })] - [InlineDataAttribute(false, new byte[] { 255, 255, 255, 255, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 3 }, new int[] { -1, 2 }, new int[] { 2, 3 })] - public void ReadSignedRationalArray_ReturnsValue(bool isLittleEndian, byte[] bytes, int[] expectedNumerators, int[] expectedDenominators) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.SRational, (uint)expectedNumerators.Length, bytes), isLittleEndian); - - SignedRational[] result = decoder.ReadSignedRationalArray(ref entry); - SignedRational[] expectedValue = Enumerable.Range(0, expectedNumerators.Length).Select(i => new SignedRational(expectedNumerators[i], expectedDenominators[i])).ToArray(); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadUnsignedRational_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadUnsignedRational(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a Rational.", e.Message); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadSignedRational_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadSignedRational(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a SignedRational.", e.Message); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadUnsignedRationalArray_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadUnsignedRationalArray(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a Rational.", e.Message); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadSignedRationalArray_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadSignedRationalArray(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a SignedRational.", e.Message); - } - - [Theory] - [InlineDataAttribute(false)] - [InlineDataAttribute(true)] - public void ReadUnsignedRational_ThrowsExceptionIfCountIsNotOne(bool isLittleEndian) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Rational, 2, new byte[4]), isLittleEndian); - - var e = Assert.Throws(() => decoder.ReadUnsignedRational(ref entry)); - - Assert.Equal($"Cannot read a single value from an array of multiple items.", e.Message); - } - - [Theory] - [InlineDataAttribute(false)] - [InlineDataAttribute(true)] - public void ReadSignedRational_ThrowsExceptionIfCountIsNotOne(bool isLittleEndian) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.SRational, 2, new byte[4]), isLittleEndian); - - var e = Assert.Throws(() => decoder.ReadSignedRational(ref entry)); - - Assert.Equal($"Cannot read a single value from an array of multiple items.", e.Message); - } - - [Theory] - [InlineDataAttribute(false, new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0.0F)] - [InlineDataAttribute(false, new byte[] { 0x3F, 0x80, 0x00, 0x00 }, 1.0F)] - [InlineDataAttribute(false, new byte[] { 0xC0, 0x00, 0x00, 0x00 }, -2.0F)] - [InlineDataAttribute(false, new byte[] { 0x7F, 0x7F, 0xFF, 0xFF }, float.MaxValue)] - [InlineDataAttribute(false, new byte[] { 0x7F, 0x80, 0x00, 0x00 }, float.PositiveInfinity)] - [InlineDataAttribute(false, new byte[] { 0xFF, 0x80, 0x00, 0x00 }, float.NegativeInfinity)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0.0F)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x80, 0x3F }, 1.0F)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0xC0 }, -2.0F)] - [InlineDataAttribute(true, new byte[] { 0xFF, 0xFF, 0x7F, 0x7F }, float.MaxValue)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x80, 0x7F }, float.PositiveInfinity)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x80, 0xFF }, float.NegativeInfinity)] - public void ReadFloat_ReturnsValue(bool isLittleEndian, byte[] bytes, float expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Float, 1, bytes), isLittleEndian); - - float result = decoder.ReadFloat(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadFloat_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadFloat(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a float.", e.Message); - } - - [Theory] - [InlineDataAttribute(false)] - [InlineDataAttribute(true)] - public void ReadFloat_ThrowsExceptionIfCountIsNotOne(bool isLittleEndian) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Float, 2, new byte[4]), isLittleEndian); - - var e = Assert.Throws(() => decoder.ReadFloat(ref entry)); - - Assert.Equal($"Cannot read a single value from an array of multiple items.", e.Message); - } - - [Theory] - [InlineDataAttribute(false, new byte[] { 0x00, 0x00, 0x00, 0x00 }, new float[] { 0.0F })] - [InlineDataAttribute(false, new byte[] { 0x3F, 0x80, 0x00, 0x00 }, new float[] { 1.0F })] - [InlineDataAttribute(false, new byte[] { 0xC0, 0x00, 0x00, 0x00 }, new float[] { -2.0F })] - [InlineDataAttribute(false, new byte[] { 0x7F, 0x7F, 0xFF, 0xFF }, new float[] { float.MaxValue })] - [InlineDataAttribute(false, new byte[] { 0x7F, 0x80, 0x00, 0x00 }, new float[] { float.PositiveInfinity })] - [InlineDataAttribute(false, new byte[] { 0xFF, 0x80, 0x00, 0x00 }, new float[] { float.NegativeInfinity })] - [InlineDataAttribute(false, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00 }, new float[] { 0.0F, 1.0F, -2.0F })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00 }, new float[] { 0.0F })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x80, 0x3F }, new float[] { 1.0F })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0xC0 }, new float[] { -2.0F })] - [InlineDataAttribute(true, new byte[] { 0xFF, 0xFF, 0x7F, 0x7F }, new float[] { float.MaxValue })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x80, 0x7F }, new float[] { float.PositiveInfinity })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x80, 0xFF }, new float[] { float.NegativeInfinity })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0xC0 }, new float[] { 0.0F, 1.0F, -2.0F })] - - public void ReadFloatArray_ReturnsValue(bool isLittleEndian, byte[] bytes, float[] expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Float, (uint)expectedValue.Length, bytes), isLittleEndian); - - float[] result = decoder.ReadFloatArray(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Double)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadFloatArray_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadFloatArray(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a float.", e.Message); - } - - [Theory] - [InlineDataAttribute(false, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0.0)] - [InlineDataAttribute(false, new byte[] { 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 1.0)] - [InlineDataAttribute(false, new byte[] { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 2.0)] - [InlineDataAttribute(false, new byte[] { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, -2.0)] - [InlineDataAttribute(false, new byte[] { 0x7F, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, double.MaxValue)] - [InlineDataAttribute(false, new byte[] { 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, double.PositiveInfinity)] - [InlineDataAttribute(false, new byte[] { 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, double.NegativeInfinity)] - [InlineDataAttribute(false, new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, double.NaN)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0.0)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F }, 1.0)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 }, 2.0)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0 }, -2.0)] - [InlineDataAttribute(true, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F }, double.MaxValue)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F }, double.PositiveInfinity)] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF }, double.NegativeInfinity)] - [InlineDataAttribute(true, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, double.NaN)] - public void ReadDouble_ReturnsValue(bool isLittleEndian, byte[] bytes, double expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Double, 1, bytes), isLittleEndian); - - double result = decoder.ReadDouble(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadDouble_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadDouble(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a double.", e.Message); - } - - [Theory] - [InlineDataAttribute(false)] - [InlineDataAttribute(true)] - public void ReadDouble_ThrowsExceptionIfCountIsNotOne(bool isLittleEndian) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Double, 2, new byte[4]), isLittleEndian); - - var e = Assert.Throws(() => decoder.ReadDouble(ref entry)); - - Assert.Equal($"Cannot read a single value from an array of multiple items.", e.Message); - } - - [Theory] - [InlineDataAttribute(false, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { 0.0 })] - [InlineDataAttribute(false, new byte[] { 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { 1.0 })] - [InlineDataAttribute(false, new byte[] { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { 2.0 })] - [InlineDataAttribute(false, new byte[] { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { -2.0 })] - [InlineDataAttribute(false, new byte[] { 0x7F, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, new double[] { double.MaxValue })] - [InlineDataAttribute(false, new byte[] { 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { double.PositiveInfinity })] - [InlineDataAttribute(false, new byte[] { 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { double.NegativeInfinity })] - [InlineDataAttribute(false, new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, new double[] { double.NaN })] - [InlineDataAttribute(false, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { 0.0, 1.0, -2.0 })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { 0.0 })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F }, new double[] { 1.0 })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 }, new double[] { 2.0 })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0 }, new double[] { -2.0 })] - [InlineDataAttribute(true, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F }, new double[] { double.MaxValue })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F }, new double[] { double.PositiveInfinity })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF }, new double[] { double.NegativeInfinity })] - [InlineDataAttribute(true, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, new double[] { double.NaN })] - [InlineDataAttribute(true, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0 }, new double[] { 0.0, 1.0, -2.0 })] - public void ReadDoubleArray_ReturnsValue(bool isLittleEndian, byte[] bytes, double[] expectedValue) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, TiffType.Double, (uint)expectedValue.Length, bytes), isLittleEndian); - - double[] result = decoder.ReadDoubleArray(ref entry); - - Assert.Equal(expectedValue, result); - } - - [Theory] - [InlineDataAttribute((ushort)TiffType.Byte)] - [InlineDataAttribute((ushort)TiffType.Ascii)] - [InlineDataAttribute((ushort)TiffType.Short)] - [InlineDataAttribute((ushort)TiffType.Long)] - [InlineDataAttribute((ushort)TiffType.Rational)] - [InlineDataAttribute((ushort)TiffType.SByte)] - [InlineDataAttribute((ushort)TiffType.Undefined)] - [InlineDataAttribute((ushort)TiffType.SShort)] - [InlineDataAttribute((ushort)TiffType.SLong)] - [InlineDataAttribute((ushort)TiffType.SRational)] - [InlineDataAttribute((ushort)TiffType.Float)] - [InlineDataAttribute((ushort)TiffType.Ifd)] - [InlineDataAttribute((ushort)99)] - public void ReadDoubleArray_ThrowsExceptionIfInvalidType(ushort type) - { - (TiffDecoderCore decoder, TiffIfdEntry entry) = GenerateTestIfdEntry(TiffGenEntry.Bytes(TiffTags.ImageWidth, (TiffType)type, 1, new byte[4]), true); - - var e = Assert.Throws(() => decoder.ReadDoubleArray(ref entry)); - - Assert.Equal($"A value of type '{(TiffType)type}' cannot be converted to a double.", e.Message); - } - - private (TiffDecoderCore, TiffIfdEntry) GenerateTestIfdEntry(TiffGenEntry entry, bool isLittleEndian) - { - Stream stream = new TiffGenIfd() - { - Entries = - { - entry - } - } - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfdEntry ifdEntry = decoder.ReadIfd(0).Entries[0]; - - return (decoder, ifdEntry); - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderIfdTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderIfdTests.cs deleted file mode 100644 index 97ace8bed4..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderIfdTests.cs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System.IO; -using SixLabors.ImageSharp.Formats.Tiff; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffDecoderIfdTests - { - public static object[][] IsLittleEndianValues = new[] { new object[] { false }, - new object[] { true } }; - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadIfd_ReadsNextIfdOffset_IfPresent(bool isLittleEndian) - { - Stream stream = new TiffGenIfd() - { - Entries = - { - TiffGenEntry.Integer(TiffTags.ImageWidth, TiffType.Long, 150) - }, - NextIfd = new TiffGenIfd() - } - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - Assert.Equal(18u, ifd.NextIfdOffset); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadIfd_ReadsNextIfdOffset_ZeroIfLastIfd(bool isLittleEndian) - { - Stream stream = new TiffGenIfd() - { - Entries = - { - TiffGenEntry.Integer(TiffTags.ImageWidth, TiffType.Long, 150) - } - } - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - Assert.Equal(0u, ifd.NextIfdOffset); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadIfd_ReturnsCorrectNumberOfEntries(bool isLittleEndian) - { - Stream stream = new TiffGenIfd() - { - Entries = - { - TiffGenEntry.Integer(TiffTags.ImageWidth, TiffType.Long, 150), - TiffGenEntry.Integer(TiffTags.ImageLength, TiffType.Long, 210), - TiffGenEntry.Integer(TiffTags.Orientation, TiffType.Short, 1), - TiffGenEntry.Ascii(TiffTags.Artist, "Image Artist Name"), - TiffGenEntry.Ascii(TiffTags.HostComputer, "Host Computer Name") - }, - NextIfd = new TiffGenIfd() - } - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - Assert.NotNull(ifd.Entries); - Assert.Equal(5, ifd.Entries.Length); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadIfd_ReadsRawTiffEntryData(bool isLittleEndian) - { - Stream stream = new TiffGenIfd() - { - Entries = - { - TiffGenEntry.Integer(TiffTags.ImageWidth, TiffType.Long, 150), - TiffGenEntry.Integer(TiffTags.ImageLength, TiffType.Long, 210), - TiffGenEntry.Integer(TiffTags.Orientation, TiffType.Short, 1) - }, - NextIfd = new TiffGenIfd() - } - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - TiffIfdEntry entry = ifd.Entries[1]; - - byte[] expectedData = isLittleEndian ? new byte[] { 210, 0, 0, 0 } : new byte[] { 0, 0, 0, 210 }; - - Assert.Equal(TiffTags.ImageLength, entry.Tag); - Assert.Equal(TiffType.Long, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(expectedData, entry.Value); - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderImageTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderImageTests.cs deleted file mode 100644 index 52f321a479..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderImageTests.cs +++ /dev/null @@ -1,510 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.IO; -using SixLabors.ImageSharp.Formats.Tiff; -using SixLabors.ImageSharp.PixelFormats; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffDecoderImageTests - { - public const int ImageWidth = 200; - public const int ImageHeight = 150; - - public static object[][] IsLittleEndianValues = new[] { new object[] { false }, - new object[] { true } }; - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void DecodeImage_SetsImageDimensions(bool isLittleEndian) - { - Stream stream = CreateTiffGenIfd() - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - Image image = decoder.DecodeImage(ifd); - - Assert.Equal(ImageWidth, image.Width); - Assert.Equal(ImageHeight, image.Height); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void DecodeImage_ThrowsException_WithMissingImageWidth(bool isLittleEndian) - { - Stream stream = CreateTiffGenIfd() - .WithoutEntry(TiffTags.ImageWidth) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - var e = Assert.Throws(() => decoder.DecodeImage(ifd)); - - Assert.Equal("The TIFF IFD does not specify the image dimensions.", e.Message); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void DecodeImage_ThrowsException_WithMissingImageLength(bool isLittleEndian) - { - Stream stream = CreateTiffGenIfd() - .WithoutEntry(TiffTags.ImageLength) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - var e = Assert.Throws(() => decoder.DecodeImage(ifd)); - - Assert.Equal("The TIFF IFD does not specify the image dimensions.", e.Message); - } - - [Theory] - [InlineData(false, (ushort)TiffCompression.None, (int)TiffCompressionType.None)] - [InlineData(true, (ushort)TiffCompression.None, (int)TiffCompressionType.None)] - [InlineData(false, (ushort)TiffCompression.PackBits, (int)TiffCompressionType.PackBits)] - [InlineData(true, (ushort)TiffCompression.PackBits, (int)TiffCompressionType.PackBits)] - [InlineData(false, (ushort)TiffCompression.Deflate, (int)TiffCompressionType.Deflate)] - [InlineData(true, (ushort)TiffCompression.Deflate, (int)TiffCompressionType.Deflate)] - [InlineData(false, (ushort)TiffCompression.OldDeflate, (int)TiffCompressionType.Deflate)] - [InlineData(true, (ushort)TiffCompression.OldDeflate, (int)TiffCompressionType.Deflate)] - [InlineData(false, (ushort)TiffCompression.Lzw, (int)TiffCompressionType.Lzw)] - [InlineData(true, (ushort)TiffCompression.Lzw, (int)TiffCompressionType.Lzw)] - public void ReadImageFormat_DeterminesCorrectCompressionImplementation(bool isLittleEndian, ushort compression, int compressionType) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.Compression, TiffType.Short, compression)) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal((TiffCompressionType)compressionType, decoder.CompressionType); - } - - [Theory] - [InlineData(false, (ushort)TiffCompression.Ccitt1D)] - [InlineData(false, (ushort)TiffCompression.CcittGroup3Fax)] - [InlineData(false, (ushort)TiffCompression.CcittGroup4Fax)] - [InlineData(false, (ushort)TiffCompression.ItuTRecT43)] - [InlineData(false, (ushort)TiffCompression.ItuTRecT82)] - [InlineData(false, (ushort)TiffCompression.Jpeg)] - [InlineData(false, (ushort)TiffCompression.OldJpeg)] - [InlineData(false, 999)] - [InlineData(true, (ushort)TiffCompression.Ccitt1D)] - [InlineData(true, (ushort)TiffCompression.CcittGroup3Fax)] - [InlineData(true, (ushort)TiffCompression.CcittGroup4Fax)] - [InlineData(true, (ushort)TiffCompression.ItuTRecT43)] - [InlineData(true, (ushort)TiffCompression.ItuTRecT82)] - [InlineData(true, (ushort)TiffCompression.Jpeg)] - [InlineData(true, (ushort)TiffCompression.OldJpeg)] - [InlineData(true, 999)] - public void ReadImageFormat_ThrowsExceptionForUnsupportedCompression(bool isLittleEndian, ushort compression) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.Compression, TiffType.Short, compression)) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - var e = Assert.Throws(() => decoder.ReadImageFormat(ifd)); - - Assert.Equal("The specified TIFF compression format is not supported.", e.Message); - } - - [Theory] - [InlineData(false, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 3 }, (int)TiffColorType.WhiteIsZero)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 3 }, (int)TiffColorType.WhiteIsZero)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 8 }, (int)TiffColorType.WhiteIsZero8)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 8 }, (int)TiffColorType.WhiteIsZero8)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 4 }, (int)TiffColorType.WhiteIsZero4)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 4 }, (int)TiffColorType.WhiteIsZero4)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 1 }, (int)TiffColorType.WhiteIsZero1)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 1 }, (int)TiffColorType.WhiteIsZero1)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 3 }, (int)TiffColorType.BlackIsZero)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 3 }, (int)TiffColorType.BlackIsZero)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 8 }, (int)TiffColorType.BlackIsZero8)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 8 }, (int)TiffColorType.BlackIsZero8)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 4 }, (int)TiffColorType.BlackIsZero4)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 4 }, (int)TiffColorType.BlackIsZero4)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 1 }, (int)TiffColorType.BlackIsZero1)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 1 }, (int)TiffColorType.BlackIsZero1)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 3 }, (int)TiffColorType.PaletteColor)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 3 }, (int)TiffColorType.PaletteColor)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 8 }, (int)TiffColorType.PaletteColor)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 8 }, (int)TiffColorType.PaletteColor)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 4 }, (int)TiffColorType.PaletteColor)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 4 }, (int)TiffColorType.PaletteColor)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 1 }, (int)TiffColorType.PaletteColor)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 1 }, (int)TiffColorType.PaletteColor)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 4, 4, 4 }, (int)TiffColorType.Rgb)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 4, 4, 4 }, (int)TiffColorType.Rgb)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 8, 8, 8 }, (int)TiffColorType.Rgb888)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 8, 8, 8 }, (int)TiffColorType.Rgb888)] - public void ReadImageFormat_DeterminesCorrectColorImplementation_Chunky(bool isLittleEndian, ushort photometricInterpretation, int[] bitsPerSample, int colorType) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, photometricInterpretation)) - .WithEntry(TiffGenEntry.Integer(TiffTags.PlanarConfiguration, TiffType.Short, (int)TiffPlanarConfiguration.Chunky)) - .WithEntry(TiffGenEntry.Integer(TiffTags.BitsPerSample, TiffType.Short, bitsPerSample)) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal((TiffColorType)colorType, decoder.ColorType); - } - - [Theory] - [InlineData(false, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 4, 4, 4 }, (int)TiffColorType.RgbPlanar)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 4, 4, 4 }, (int)TiffColorType.RgbPlanar)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 8, 8, 8 }, (int)TiffColorType.RgbPlanar)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 8, 8, 8 }, (int)TiffColorType.RgbPlanar)] - public void ReadImageFormat_DeterminesCorrectColorImplementation_Planar(bool isLittleEndian, ushort photometricInterpretation, int[] bitsPerSample, int colorType) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, photometricInterpretation)) - .WithEntry(TiffGenEntry.Integer(TiffTags.PlanarConfiguration, TiffType.Short, (int)TiffPlanarConfiguration.Planar)) - .WithEntry(TiffGenEntry.Integer(TiffTags.BitsPerSample, TiffType.Short, bitsPerSample)) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal((TiffColorType)colorType, decoder.ColorType); - } - - [Theory] - [InlineData(false, (ushort)TiffPhotometricInterpretation.WhiteIsZero, (int)TiffColorType.WhiteIsZero1)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.WhiteIsZero, (int)TiffColorType.WhiteIsZero1)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.BlackIsZero, (int)TiffColorType.BlackIsZero1)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.BlackIsZero, (int)TiffColorType.BlackIsZero1)] - public void ReadImageFormat_DeterminesCorrectColorImplementation_DefaultsToBilevel(bool isLittleEndian, ushort photometricInterpretation, int colorType) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, photometricInterpretation)) - .WithoutEntry(TiffTags.BitsPerSample) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal((TiffColorType)colorType, decoder.ColorType); - } - - // [Theory] - // [InlineData(false, new[] { 8 }, (int)TiffColorType.WhiteIsZero8)] - // [InlineData(true, new[] { 8 }, (int)TiffColorType.WhiteIsZero8)] - // public void ReadImageFormat_UsesDefaultColorImplementationForCcitt1D(bool isLittleEndian, int[] bitsPerSample, int colorType) - // { - // Stream stream = CreateTiffGenIfd() - // .WithEntry(TiffGenEntry.Integer(TiffTags.Compression, TiffType.Short, (int)TiffCompression.Ccitt1D)) - // .WithEntry(TiffGenEntry.Integer(TiffTags.BitsPerSample, TiffType.Short, bitsPerSample)) - // .WithoutEntry(TiffTags.PhotometricInterpretation) - // .ToStream(isLittleEndian); - - // TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - // TiffIfd ifd = decoder.ReadIfd(0); - // decoder.ReadImageFormat(ifd); - - // Assert.Equal((TiffColorType)colorType, decoder.ColorType); - // } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadImageFormat_ThrowsExceptionForMissingPhotometricInterpretation(bool isLittleEndian) - { - Stream stream = CreateTiffGenIfd() - .WithoutEntry(TiffTags.PhotometricInterpretation) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - var e = Assert.Throws(() => decoder.ReadImageFormat(ifd)); - - Assert.Equal("The TIFF photometric interpretation entry is missing.", e.Message); - } - - [Theory] - [InlineData(false, (ushort)TiffPhotometricInterpretation.CieLab)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.ColorFilterArray)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.IccLab)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.ItuLab)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.LinearRaw)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.Separated)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.TransparencyMask)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.YCbCr)] - [InlineData(false, 999)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.CieLab)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.ColorFilterArray)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.IccLab)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.ItuLab)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.LinearRaw)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.Separated)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.TransparencyMask)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.YCbCr)] - [InlineData(true, 999)] - public void ReadImageFormat_ThrowsExceptionForUnsupportedPhotometricInterpretation(bool isLittleEndian, ushort photometricInterpretation) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, photometricInterpretation)) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - var e = Assert.Throws(() => decoder.ReadImageFormat(ifd)); - - Assert.Equal("The specified TIFF photometric interpretation is not supported.", e.Message); - } - - [Theory] - [InlineData(false, new[] { 8u })] - [InlineData(true, new[] { 8u })] - [InlineData(false, new[] { 4u })] - [InlineData(true, new[] { 4u })] - [InlineData(false, new[] { 1u })] - [InlineData(true, new[] { 1u })] - // [InlineData(false, new[] { 1u, 2u, 3u })] - // [InlineData(true, new[] { 1u, 2u, 3u })] - // [InlineData(false, new[] { 8u, 8u, 8u })] - // [InlineData(true, new[] { 8u, 8u, 8u })] - public void ReadImageFormat_ReadsBitsPerSample(bool isLittleEndian, uint[] bitsPerSample) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.BitsPerSample, TiffType.Short, bitsPerSample)) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal(bitsPerSample, decoder.BitsPerSample); - } - - [Theory] - [InlineData(false, (ushort)TiffPhotometricInterpretation.WhiteIsZero)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.WhiteIsZero)] - [InlineData(false, (ushort)TiffPhotometricInterpretation.BlackIsZero)] - [InlineData(true, (ushort)TiffPhotometricInterpretation.BlackIsZero)] - public void ReadImageFormat_ReadsBitsPerSample_DefaultsToBilevel(bool isLittleEndian, ushort photometricInterpretation) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, photometricInterpretation)) - .WithoutEntry(TiffTags.BitsPerSample) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal(new[] { 1u }, decoder.BitsPerSample); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadImageFormat_ThrowsExceptionForMissingBitsPerSample(bool isLittleEndian) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, (int)TiffPhotometricInterpretation.PaletteColor)) - .WithoutEntry(TiffTags.BitsPerSample) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - var e = Assert.Throws(() => decoder.ReadImageFormat(ifd)); - - Assert.Equal("The TIFF BitsPerSample entry is missing.", e.Message); - } - - [Theory] - [InlineData(false, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new int[] { })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new int[] { })] - [InlineData(false, (ushort)TiffPhotometricInterpretation.BlackIsZero, new int[] { })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.BlackIsZero, new int[] { })] - [InlineData(false, (ushort)TiffPhotometricInterpretation.PaletteColor, new int[] { })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.PaletteColor, new int[] { })] - [InlineData(false, (ushort)TiffPhotometricInterpretation.Rgb, new int[] { })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.Rgb, new int[] { })] - [InlineData(false, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 8, 8 })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.WhiteIsZero, new[] { 8, 8 })] - [InlineData(false, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 8, 8 })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.BlackIsZero, new[] { 8, 8 })] - [InlineData(false, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 8, 8 })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.PaletteColor, new[] { 8, 8 })] - [InlineData(false, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 8 })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 8 })] - [InlineData(false, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 8, 8 })] - [InlineData(true, (ushort)TiffPhotometricInterpretation.Rgb, new[] { 8, 8 })] - public void ReadImageFormat_ThrowsExceptionForUnsupportedNumberOfSamples(bool isLittleEndian, ushort photometricInterpretation, int[] bitsPerSample) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, photometricInterpretation)) - .WithEntry(TiffGenEntry.Integer(TiffTags.BitsPerSample, TiffType.Short, bitsPerSample)) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - var e = Assert.Throws(() => decoder.ReadImageFormat(ifd)); - - Assert.Equal("The number of samples in the TIFF BitsPerSample entry is not supported.", e.Message); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadImageFormat_ReadsColorMap(bool isLittleEndian) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, (int)TiffPhotometricInterpretation.PaletteColor)) - .WithEntry(TiffGenEntry.Integer(TiffTags.ColorMap, TiffType.Short, new int[] { 10, 20, 30, 40, 50, 60 })) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal(new uint[] { 10, 20, 30, 40, 50, 60 }, decoder.ColorMap); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadImageFormat_ThrowsExceptionForMissingColorMap(bool isLittleEndian) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, (int)TiffPhotometricInterpretation.PaletteColor)) - .WithoutEntry(TiffTags.ColorMap) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - - var e = Assert.Throws(() => decoder.ReadImageFormat(ifd)); - - Assert.Equal("The TIFF ColorMap entry is missing for a pallete color image.", e.Message); - } - - [Theory] - [InlineData(false, (ushort)TiffPlanarConfiguration.Chunky)] - [InlineData(true, (ushort)TiffPlanarConfiguration.Chunky)] - [InlineData(false, (ushort)TiffPlanarConfiguration.Planar)] - [InlineData(true, (ushort)TiffPlanarConfiguration.Planar)] - public void ReadImageFormat_ReadsPlanarConfiguration(bool isLittleEndian, int planarConfiguration) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, (int)TiffPhotometricInterpretation.Rgb)) - .WithEntry(TiffGenEntry.Integer(TiffTags.BitsPerSample, TiffType.Short, new int[] { 8, 8, 8 })) - .WithEntry(TiffGenEntry.Integer(TiffTags.PlanarConfiguration, TiffType.Short, (int)planarConfiguration)) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal((TiffPlanarConfiguration)planarConfiguration, decoder.PlanarConfiguration); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void ReadImageFormat_DefaultsPlanarConfigurationToChunky(bool isLittleEndian) - { - Stream stream = CreateTiffGenIfd() - .WithEntry(TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, (int)TiffPhotometricInterpretation.Rgb)) - .WithEntry(TiffGenEntry.Integer(TiffTags.BitsPerSample, TiffType.Short, new int[] { 8, 8, 8 })) - .WithoutEntry(TiffTags.PlanarConfiguration) - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - decoder.ReadImageFormat(ifd); - - Assert.Equal(TiffPlanarConfiguration.Chunky, decoder.PlanarConfiguration); - } - - [Theory] - [InlineData((ushort)TiffColorType.WhiteIsZero, new uint[] { 1 }, 160, 80, 20 * 80)] - [InlineData((ushort)TiffColorType.WhiteIsZero, new uint[] { 1 }, 153, 80, 20 * 80)] - [InlineData((ushort)TiffColorType.WhiteIsZero, new uint[] { 3 }, 100, 80, 38 * 80)] - [InlineData((ushort)TiffColorType.WhiteIsZero, new uint[] { 4 }, 100, 80, 50 * 80)] - [InlineData((ushort)TiffColorType.WhiteIsZero, new uint[] { 4 }, 99, 80, 50 * 80)] - [InlineData((ushort)TiffColorType.WhiteIsZero, new uint[] { 8 }, 100, 80, 100 * 80)] - [InlineData((ushort)TiffColorType.PaletteColor, new uint[] { 1 }, 160, 80, 20 * 80)] - [InlineData((ushort)TiffColorType.PaletteColor, new uint[] { 1 }, 153, 80, 20 * 80)] - [InlineData((ushort)TiffColorType.PaletteColor, new uint[] { 3 }, 100, 80, 38 * 80)] - [InlineData((ushort)TiffColorType.PaletteColor, new uint[] { 4 }, 100, 80, 50 * 80)] - [InlineData((ushort)TiffColorType.PaletteColor, new uint[] { 4 }, 99, 80, 50 * 80)] - [InlineData((ushort)TiffColorType.PaletteColor, new uint[] { 8 }, 100, 80, 100 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 8, 8, 8 }, 100, 80, 300 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 4, 4 }, 100, 80, 150 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 8, 4 }, 100, 80, 200 * 80)] - public void CalculateImageBufferSize_ReturnsCorrectSize_Chunky(ushort colorType, uint[] bitsPerSample, int width, int height, int expectedResult) - { - TiffDecoderCore decoder = new TiffDecoderCore(null, null); - decoder.ColorType = (TiffColorType)colorType; - decoder.PlanarConfiguration = TiffPlanarConfiguration.Chunky; - decoder.BitsPerSample = bitsPerSample; - - int bufferSize = decoder.CalculateImageBufferSize(width, height, 0); - - Assert.Equal(expectedResult, bufferSize); - } - - [Theory] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 8, 8, 8 }, 100, 80, 0, 100 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 8, 8, 8 }, 100, 80, 1, 100 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 8, 8, 8 }, 100, 80, 2, 100 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 4, 4 }, 100, 80, 0, 50 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 4, 4 }, 100, 80, 1, 50 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 4, 4 }, 100, 80, 2, 50 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 8, 4 }, 100, 80, 0, 50 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 8, 4 }, 100, 80, 1, 100 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 8, 4 }, 100, 80, 2, 50 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 8, 4 }, 99, 80, 0, 50 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 8, 4 }, 99, 80, 1, 99 * 80)] - [InlineData((ushort)TiffColorType.Rgb, new uint[] { 4, 8, 4 }, 99, 80, 2, 50 * 80)] - - public void CalculateImageBufferSize_ReturnsCorrectSize_Planar(ushort colorType, uint[] bitsPerSample, int width, int height, int plane, int expectedResult) - { - TiffDecoderCore decoder = new TiffDecoderCore(null, null); - decoder.ColorType = (TiffColorType)colorType; - decoder.PlanarConfiguration = TiffPlanarConfiguration.Planar; - decoder.BitsPerSample = bitsPerSample; - - int bufferSize = decoder.CalculateImageBufferSize(width, height, plane); - - Assert.Equal(expectedResult, bufferSize); - } - - private TiffGenIfd CreateTiffGenIfd() - { - return new TiffGenIfd() - { - Entries = - { - TiffGenEntry.Integer(TiffTags.ImageWidth, TiffType.Long, ImageWidth), - TiffGenEntry.Integer(TiffTags.ImageLength, TiffType.Long, ImageHeight), - TiffGenEntry.Rational(TiffTags.XResolution, 100, 1), - TiffGenEntry.Rational(TiffTags.YResolution, 200, 1), - TiffGenEntry.Integer(TiffTags.ResolutionUnit, TiffType.Short, 2), - TiffGenEntry.Integer(TiffTags.PhotometricInterpretation, TiffType.Short, (int)TiffPhotometricInterpretation.WhiteIsZero), - TiffGenEntry.Integer(TiffTags.BitsPerSample, TiffType.Short, new int[] { 8 }), - TiffGenEntry.Integer(TiffTags.Compression, TiffType.Short, (int)TiffCompression.None), - TiffGenEntry.Integer(TiffTags.ColorMap, TiffType.Short, new int[256]) - } - }; - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderMetadataTests.cs deleted file mode 100644 index b36d4e02f1..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffDecoderMetadataTests.cs +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System.IO; -using SixLabors.ImageSharp.Formats.Tiff; -using SixLabors.ImageSharp.PixelFormats; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffDecoderMetadataTests - { - public static object[][] BaselineMetadataValues = new[] { new object[] { false, TiffTags.Artist, TiffMetadataNames.Artist, "My Artist Name" }, - new object[] { false, TiffTags.Copyright, TiffMetadataNames.Copyright, "My Copyright Statement" }, - new object[] { false, TiffTags.DateTime, TiffMetadataNames.DateTime, "My DateTime Value" }, - new object[] { false, TiffTags.HostComputer, TiffMetadataNames.HostComputer, "My Host Computer Name" }, - new object[] { false, TiffTags.ImageDescription, TiffMetadataNames.ImageDescription, "My Image Description" }, - new object[] { false, TiffTags.Make, TiffMetadataNames.Make, "My Camera Make" }, - new object[] { false, TiffTags.Model, TiffMetadataNames.Model, "My Camera Model" }, - new object[] { false, TiffTags.Software, TiffMetadataNames.Software, "My Imaging Software" }, - new object[] { true, TiffTags.Artist, TiffMetadataNames.Artist, "My Artist Name" }, - new object[] { true, TiffTags.Copyright, TiffMetadataNames.Copyright, "My Copyright Statement" }, - new object[] { true, TiffTags.DateTime, TiffMetadataNames.DateTime, "My DateTime Value" }, - new object[] { true, TiffTags.HostComputer, TiffMetadataNames.HostComputer, "My Host Computer Name" }, - new object[] { true, TiffTags.ImageDescription, TiffMetadataNames.ImageDescription, "My Image Description" }, - new object[] { true, TiffTags.Make, TiffMetadataNames.Make, "My Camera Make" }, - new object[] { true, TiffTags.Model, TiffMetadataNames.Model, "My Camera Model" }, - new object[] { true, TiffTags.Software, TiffMetadataNames.Software, "My Imaging Software" }}; - - [Theory] - [InlineData(false, 150u, 1u, 200u, 1u, 2u /* Inch */, 150.0, 200.0)] - [InlineData(false, 150u, 1u, 200u, 1u, 3u /* Cm */, 150.0 * 2.54, 200.0 * 2.54)] - [InlineData(false, 150u, 1u, 200u, 1u, 1u /* None */, 96.0, 96.0)] - [InlineData(false, 150u, 1u, 200u, 1u, null /* Inch */, 150.0, 200.0)] - [InlineData(false, 5u, 2u, 9u, 4u, 2u /* Inch */, 2.5, 2.25)] - [InlineData(false, null, null, null, null, null /* Inch */, 96.0, 96.0)] - [InlineData(false, 150u, 1u, null, null, 2u /* Inch */, 150.0, 96.0)] - [InlineData(false, null, null, 200u, 1u, 2u /* Inch */, 96.0, 200.0)] - [InlineData(true, 150u, 1u, 200u, 1u, 2u /* Inch */, 150.0, 200.0)] - [InlineData(true, 150u, 1u, 200u, 1u, 3u /* Cm */, 150.0 * 2.54, 200.0 * 2.54)] - [InlineData(true, 150u, 1u, 200u, 1u, 1u /* None */, 96.0, 96.0)] - [InlineData(true, 5u, 2u, 9u, 4u, 2u /* Inch */, 2.5, 2.25)] - [InlineData(true, 150u, 1u, 200u, 1u, null /* Inch */, 150.0, 200.0)] - [InlineData(true, null, null, null, null, null /* Inch */, 96.0, 96.0)] - [InlineData(true, 150u, 1u, null, null, 2u /* Inch */, 150.0, 96.0)] - [InlineData(true, null, null, 200u, 1u, 2u /* Inch */, 96.0, 200.0)] - public void ReadMetadata_SetsImageResolution(bool isLittleEndian, uint? xResolutionNumerator, uint? xResolutionDenominator, - uint? yResolutionNumerator, uint? yResolutionDenominator, uint? resolutionUnit, - double expectedHorizonalResolution, double expectedVerticalResolution) - { - TiffGenIfd ifdGen = new TiffGenIfd(); - - if (xResolutionNumerator != null) - { - ifdGen.WithEntry(TiffGenEntry.Rational(TiffTags.XResolution, xResolutionNumerator.Value, xResolutionDenominator.Value)); - } - - if (yResolutionNumerator != null) - { - ifdGen.WithEntry(TiffGenEntry.Rational(TiffTags.YResolution, yResolutionNumerator.Value, yResolutionDenominator.Value)); - } - - if (resolutionUnit != null) - { - ifdGen.WithEntry(TiffGenEntry.Integer(TiffTags.ResolutionUnit, TiffType.Short, resolutionUnit.Value)); - } - - Stream stream = ifdGen.ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - Image image = new Image(null, 20, 20); - - decoder.ReadMetadata(ifd, image); - - Assert.Equal(expectedHorizonalResolution, image.Metadata.HorizontalResolution, 10); - Assert.Equal(expectedVerticalResolution, image.Metadata.VerticalResolution, 10); - } - /* - [Theory] - [MemberData(nameof(BaselineMetadataValues))] - public void ReadMetadata_SetsAsciiMetadata(bool isLittleEndian, ushort tag, string metadataName, string metadataValue) - { - Stream stream = new TiffGenIfd() - { - Entries = - { - TiffGenEntry.Integer(TiffTags.ImageWidth, TiffType.Long, 150), - TiffGenEntry.Integer(TiffTags.ImageLength, TiffType.Long, 210), - TiffGenEntry.Ascii(tag, metadataValue), - TiffGenEntry.Integer(TiffTags.Orientation, TiffType.Short, 1) - } - } - .ToStream(isLittleEndian); - - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, null); - TiffIfd ifd = decoder.ReadIfd(0); - Image image = new Image(null, 20, 20); - - decoder.ReadMetadata(ifd, image); - var metadata = image.Metadata.Properties.FirstOrDefault(m => m.Name == metadataName).Value; - - Assert.Equal(metadataValue, metadata); - } - - [Theory] - [MemberData(nameof(BaselineMetadataValues))] - public void ReadMetadata_DoesntSetMetadataIfIgnoring(bool isLittleEndian, ushort tag, string metadataName, string metadataValue) - { - Stream stream = new TiffGenIfd() - { - Entries = - { - TiffGenEntry.Integer(TiffTags.ImageWidth, TiffType.Long, 150), - TiffGenEntry.Integer(TiffTags.ImageLength, TiffType.Long, 210), - TiffGenEntry.Ascii(tag, metadataValue), - TiffGenEntry.Integer(TiffTags.Orientation, TiffType.Short, 1) - } - } - .ToStream(isLittleEndian); - - TiffDecoder options = new TiffDecoder() { IgnoreMetadata = true }; - TiffDecoderCore decoder = new TiffDecoderCore(stream, isLittleEndian, null, options); - TiffIfd ifd = decoder.ReadIfd(0); - Image image = new Image(null, 20, 20); - - decoder.ReadMetadata(ifd, image); - var metadata = image.Metadata.Properties.FirstOrDefault(m => m.Name == metadataName).Value; - - Assert.Null(metadata); - } */ - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffEncoderIfdTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffEncoderIfdTests.cs deleted file mode 100644 index 1dfa7dc16f..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffEncoderIfdTests.cs +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using SixLabors.ImageSharp.Formats.Tiff; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffEncoderIfdTests - { - [Fact] - public void WriteIfd_DataIsCorrectLength() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(TiffTags.ImageWidth, TiffType.Long, 1, new byte[] { 1, 2, 3, 4 }), - new TiffIfdEntry(TiffTags.ImageLength, TiffType.Long, 1, new byte[] { 5, 6, 7, 8 }), - new TiffIfdEntry(TiffTags.Compression, TiffType.Long, 1, new byte[] { 9, 10, 11, 12 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - Assert.Equal(2 + 12 * 3 + 4, stream.Length); - } - - [Fact] - public void WriteIfd_WritesNumberOfEntries() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(TiffTags.ImageWidth, TiffType.Long, 1, new byte[] { 1, 2, 3, 4 }), - new TiffIfdEntry(TiffTags.ImageLength, TiffType.Long, 1, new byte[] { 5, 6, 7, 8 }), - new TiffIfdEntry(TiffTags.Compression, TiffType.Long, 1, new byte[] { 9, 10, 11, 12 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - var ifdEntryBytes = stream.ToArray().Take(2).ToArray(); - Assert.Equal(new byte[] { 3, 0 }, ifdEntryBytes); - } - - [Fact] - public void WriteIfd_ReturnsNextIfdMarker() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(TiffTags.ImageWidth, TiffType.Long, 1, new byte[] { 1, 2, 3, 4 }), - new TiffIfdEntry(TiffTags.ImageLength, TiffType.Long, 1, new byte[] { 5, 6, 7, 8 }), - new TiffIfdEntry(TiffTags.Compression, TiffType.Long, 1, new byte[] { 9, 10, 11, 12 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - long nextIfdMarker = encoder.WriteIfd(writer, entries); - Assert.Equal(2 + 12 * 3, nextIfdMarker); - } - } - - [Fact] - public void WriteIfd_WritesTagIdForEachEntry() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(10, TiffType.Long, 1, new byte[] { 1, 2, 3, 4 }), - new TiffIfdEntry(20, TiffType.Long, 1, new byte[] { 5, 6, 7, 8 }), - new TiffIfdEntry(30, TiffType.Long, 1, new byte[] { 9, 10, 11, 12 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - var ifdEntry1Bytes = stream.ToArray().Skip(2 + 12 * 0).Take(2).ToArray(); - var ifdEntry2Bytes = stream.ToArray().Skip(2 + 12 * 1).Take(2).ToArray(); - var ifdEntry3Bytes = stream.ToArray().Skip(2 + 12 * 2).Take(2).ToArray(); - - Assert.Equal(new byte[] { 10, 0 }, ifdEntry1Bytes); - Assert.Equal(new byte[] { 20, 0 }, ifdEntry2Bytes); - Assert.Equal(new byte[] { 30, 0 }, ifdEntry3Bytes); - } - - [Fact] - public void WriteIfd_WritesTypeForEachEntry() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(TiffTags.ImageWidth, TiffType.Long, 1, new byte[] { 1, 2, 3, 4 }), - new TiffIfdEntry(TiffTags.ImageLength, TiffType.Short, 2, new byte[] { 5, 6, 7, 8 }), - new TiffIfdEntry(TiffTags.Compression, TiffType.Ascii, 4, new byte[] { (byte)'A', (byte)'B', (byte)'C', 0 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - var ifdEntry1Bytes = stream.ToArray().Skip(4 + 12 * 0).Take(2).ToArray(); - var ifdEntry2Bytes = stream.ToArray().Skip(4 + 12 * 1).Take(2).ToArray(); - var ifdEntry3Bytes = stream.ToArray().Skip(4 + 12 * 2).Take(2).ToArray(); - - Assert.Equal(new byte[] { 4, 0 }, ifdEntry1Bytes); - Assert.Equal(new byte[] { 3, 0 }, ifdEntry2Bytes); - Assert.Equal(new byte[] { 2, 0 }, ifdEntry3Bytes); - } - - [Fact] - public void WriteIfd_WritesCountForEachEntry() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(TiffTags.ImageWidth, TiffType.Long, 1, new byte[] { 1, 2, 3, 4 }), - new TiffIfdEntry(TiffTags.ImageLength, TiffType.Short, 2, new byte[] { 5, 6, 7, 8 }), - new TiffIfdEntry(TiffTags.Compression, TiffType.Ascii, 4, new byte[] { (byte)'A', (byte)'B', (byte)'C', 0 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - var ifdEntry1Bytes = stream.ToArray().Skip(6 + 12 * 0).Take(4).ToArray(); - var ifdEntry2Bytes = stream.ToArray().Skip(6 + 12 * 1).Take(4).ToArray(); - var ifdEntry3Bytes = stream.ToArray().Skip(6 + 12 * 2).Take(4).ToArray(); - - Assert.Equal(new byte[] { 1, 0, 0, 0 }, ifdEntry1Bytes); - Assert.Equal(new byte[] { 2, 0, 0, 0 }, ifdEntry2Bytes); - Assert.Equal(new byte[] { 4, 0, 0, 0 }, ifdEntry3Bytes); - } - - [Fact] - public void WriteIfd_WritesDataInline() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(TiffTags.ImageWidth, TiffType.Long, 1, new byte[] { 1, 2, 3, 4 }), - new TiffIfdEntry(TiffTags.ImageLength, TiffType.Short, 2, new byte[] { 5, 6, 7, 8 }), - new TiffIfdEntry(TiffTags.Compression, TiffType.Ascii, 3, new byte[] { (byte)'A', (byte)'B', 0 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - var ifdEntry1Bytes = stream.ToArray().Skip(10 + 12 * 0).Take(4).ToArray(); - var ifdEntry2Bytes = stream.ToArray().Skip(10 + 12 * 1).Take(4).ToArray(); - var ifdEntry3Bytes = stream.ToArray().Skip(10 + 12 * 2).Take(4).ToArray(); - - Assert.Equal(new byte[] { 1, 2, 3, 4 }, ifdEntry1Bytes); - Assert.Equal(new byte[] { 5, 6, 7, 8 }, ifdEntry2Bytes); - Assert.Equal(new byte[] { (byte)'A', (byte)'B', 0, 0 }, ifdEntry3Bytes); - } - - [Fact] - public void WriteIfd_WritesDataByReference() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(TiffTags.ImageWidth, TiffType.Byte, 8, new byte[] { 1, 2, 3, 4, 4, 3, 2, 1 }), - new TiffIfdEntry(TiffTags.ImageLength, TiffType.Short, 4, new byte[] { 5, 6, 7, 8, 9, 10, 11, 12 }), - new TiffIfdEntry(TiffTags.Compression, TiffType.Ascii, 3, new byte[] { (byte)'A', (byte)'B', 0 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - writer.Write(new byte[] { 1, 2, 3, 4 }); - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - var ifdEntry1Bytes = stream.ToArray().Skip(14 + 12 * 0).Take(4).ToArray(); - var ifdEntry1Data = stream.ToArray().Skip(46).Take(8).ToArray(); - var ifdEntry2Bytes = stream.ToArray().Skip(14 + 12 * 1).Take(4).ToArray(); - var ifdEntry2Data = stream.ToArray().Skip(54).Take(8).ToArray(); - var ifdEntry3Bytes = stream.ToArray().Skip(14 + 12 * 2).Take(4).ToArray(); - - Assert.Equal(new byte[] { 46, 0, 0, 0 }, ifdEntry1Bytes); - Assert.Equal(new byte[] { 1, 2, 3, 4, 4, 3, 2, 1 }, ifdEntry1Data); - Assert.Equal(new byte[] { 54, 0, 0, 0 }, ifdEntry2Bytes); - Assert.Equal(new byte[] { 5, 6, 7, 8, 9, 10, 11, 12 }, ifdEntry2Data); - Assert.Equal(new byte[] { (byte)'A', (byte)'B', 0, 0 }, ifdEntry3Bytes); - } - - [Fact] - public void WriteIfd_WritesDataByReferenceOnWordBoundary() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(TiffTags.ImageWidth, TiffType.Byte, 8, new byte[] { 1, 2, 3, 4, 5 }), - new TiffIfdEntry(TiffTags.ImageLength, TiffType.Short, 4, new byte[] { 5, 6, 7, 8, 9, 10, 11, 12 }), - new TiffIfdEntry(TiffTags.Compression, TiffType.Ascii, 3, new byte[] { (byte)'A', (byte)'B', 0 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - writer.Write(new byte[] { 1, 2, 3, 4 }); - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - var ifdEntry1Bytes = stream.ToArray().Skip(14 + 12 * 0).Take(4).ToArray(); - var ifdEntry1Data = stream.ToArray().Skip(46).Take(5).ToArray(); - var ifdEntry2Bytes = stream.ToArray().Skip(14 + 12 * 1).Take(4).ToArray(); - var ifdEntry2Data = stream.ToArray().Skip(52).Take(8).ToArray(); - var ifdEntry3Bytes = stream.ToArray().Skip(14 + 12 * 2).Take(4).ToArray(); - - Assert.Equal(new byte[] { 46, 0, 0, 0 }, ifdEntry1Bytes); - Assert.Equal(new byte[] { 1, 2, 3, 4, 5 }, ifdEntry1Data); - Assert.Equal(new byte[] { 52, 0, 0, 0 }, ifdEntry2Bytes); - Assert.Equal(new byte[] { 5, 6, 7, 8, 9, 10, 11, 12 }, ifdEntry2Data); - Assert.Equal(new byte[] { (byte)'A', (byte)'B', 0, 0 }, ifdEntry3Bytes); - } - - [Fact] - public void WriteIfd_WritesEntriesInCorrectOrder() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List() - { - new TiffIfdEntry(10, TiffType.Long, 1, new byte[] { 1, 2, 3, 4 }), - new TiffIfdEntry(30, TiffType.Long, 1, new byte[] { 5, 6, 7, 8 }), - new TiffIfdEntry(20, TiffType.Long, 1, new byte[] { 9, 10, 11, 12 }) - }; - - using (TiffWriter writer = new TiffWriter(stream)) - { - long nextIfdMarker = encoder.WriteIfd(writer, entries); - } - - var ifdEntry1Bytes = stream.ToArray().Skip(2 + 12 * 0).Take(2).ToArray(); - var ifdEntry2Bytes = stream.ToArray().Skip(2 + 12 * 1).Take(2).ToArray(); - var ifdEntry3Bytes = stream.ToArray().Skip(2 + 12 * 2).Take(2).ToArray(); - - Assert.Equal(new byte[] { 10, 0 }, ifdEntry1Bytes); - Assert.Equal(new byte[] { 20, 0 }, ifdEntry2Bytes); - Assert.Equal(new byte[] { 30, 0 }, ifdEntry3Bytes); - } - - [Fact] - public void WriteIfd_ThrowsException_IfNoEntriesArePresent() - { - MemoryStream stream = new MemoryStream(); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List entries = new List(); - - using (TiffWriter writer = new TiffWriter(stream)) - { - ArgumentException e = Assert.Throws(() => { encoder.WriteIfd(writer, entries); }); - - Assert.Equal($"There must be at least one entry per IFD.{Environment.NewLine}Parameter name: entries", e.Message); - Assert.Equal("entries", e.ParamName); - } - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffEncoderMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffEncoderMetadataTests.cs deleted file mode 100644 index ec90381ab8..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffEncoderMetadataTests.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System.Collections.Generic; -using SixLabors.ImageSharp.Formats.Tiff; -using SixLabors.ImageSharp.PixelFormats; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffEncoderMetadataTests - { - public static object[][] BaselineMetadataValues = new[] { new object[] { TiffTags.Artist, TiffMetadataNames.Artist, "My Artist Name" }, - new object[] { TiffTags.Copyright, TiffMetadataNames.Copyright, "My Copyright Statement" }, - new object[] { TiffTags.DateTime, TiffMetadataNames.DateTime, "My DateTime Value" }, - new object[] { TiffTags.HostComputer, TiffMetadataNames.HostComputer, "My Host Computer Name" }, - new object[] { TiffTags.ImageDescription, TiffMetadataNames.ImageDescription, "My Image Description" }, - new object[] { TiffTags.Make, TiffMetadataNames.Make, "My Camera Make" }, - new object[] { TiffTags.Model, TiffMetadataNames.Model, "My Camera Model" }, - new object[] { TiffTags.Software, TiffMetadataNames.Software, "My Imaging Software" }}; - - [Fact] - public void AddMetadata_SetsImageResolution() - { - Image image = new Image(100, 100); - image.Metadata.HorizontalResolution = 40.0; - image.Metadata.VerticalResolution = 50.5; - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List ifdEntries = new List(); - encoder.AddMetadata(image, ifdEntries); - - Assert.Equal(new Rational(40, 1), ifdEntries.GetUnsignedRational(TiffTags.XResolution)); - Assert.Equal(new Rational(101, 2), ifdEntries.GetUnsignedRational(TiffTags.YResolution)); - Assert.Equal(TiffResolutionUnit.Inch, (TiffResolutionUnit?)ifdEntries.GetInteger(TiffTags.ResolutionUnit)); - } - - /* - [Theory] - [MemberData(nameof(BaselineMetadataValues))] - public void AddMetadata_SetsAsciiMetadata(ushort tag, string metadataName, string metadataValue) - { - Image image = new Image(100, 100); - image.Metadata.Properties.Add(new ImageProperty(metadataName, metadataValue)); - TiffEncoderCore encoder = new TiffEncoderCore(null); - - List ifdEntries = new List(); - encoder.AddMetadata(image, ifdEntries); - - Assert.Equal(metadataValue + "\0", ifdEntries.GetAscii(tag)); - } */ - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdEntryCreatorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdEntryCreatorTests.cs deleted file mode 100644 index c3c108e9fe..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdEntryCreatorTests.cs +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Collections.Generic; -using System.Linq; -using SixLabors.ImageSharp.Formats.Tiff; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffIfdEntryCreatorTests - { - [Theory] - [InlineDataAttribute(new byte[] { 0 }, 0)] - [InlineDataAttribute(new byte[] { 1 }, 1)] - [InlineDataAttribute(new byte[] { 255 }, 255)] - public void AddUnsignedByte_AddsSingleValue(byte[] bytes, uint value) - { - var entries = new List(); - - entries.AddUnsignedByte(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Byte, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0 }, new uint[] { 0 })] - [InlineDataAttribute(new byte[] { 0, 1, 2 }, new uint[] { 0, 1, 2 })] - [InlineDataAttribute(new byte[] { 0, 1, 2, 3, 4, 5, 6 }, new uint[] { 0, 1, 2, 3, 4, 5, 6 })] - public void AddUnsignedByte_AddsArray(byte[] bytes, uint[] value) - { - var entries = new List(); - - entries.AddUnsignedByte(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Byte, entry.Type); - Assert.Equal((uint)value.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0, 0 }, 0)] - [InlineDataAttribute(new byte[] { 1, 0 }, 1)] - [InlineDataAttribute(new byte[] { 0, 1 }, 256)] - [InlineDataAttribute(new byte[] { 2, 1 }, 258)] - [InlineDataAttribute(new byte[] { 255, 255 }, UInt16.MaxValue)] - public void AddUnsignedShort_AddsSingleValue(byte[] bytes, uint value) - { - var entries = new List(); - - entries.AddUnsignedShort(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Short, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 1, 0 }, new uint[] { 1 })] - [InlineDataAttribute(new byte[] { 1, 0, 3, 2 }, new uint[] { 1, 515 })] - [InlineDataAttribute(new byte[] { 1, 0, 3, 2, 5, 4 }, new uint[] { 1, 515, 1029 })] - public void AddUnsignedShort_AddsArray(byte[] bytes, uint[] value) - { - var entries = new List(); - - entries.AddUnsignedShort(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Short, entry.Type); - Assert.Equal((uint)value.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0, 0, 0, 0 }, 0)] - [InlineDataAttribute(new byte[] { 1, 0, 0, 0 }, 1)] - [InlineDataAttribute(new byte[] { 0, 1, 0, 0 }, 256)] - [InlineDataAttribute(new byte[] { 0, 0, 1, 0 }, 256 * 256)] - [InlineDataAttribute(new byte[] { 0, 0, 0, 1 }, 256 * 256 * 256)] - [InlineDataAttribute(new byte[] { 1, 2, 3, 4 }, 67305985)] - [InlineDataAttribute(new byte[] { 255, 255, 255, 255 }, UInt32.MaxValue)] - public void AddUnsignedLong_AddsSingleValue(byte[] bytes, uint value) - { - var entries = new List(); - - entries.AddUnsignedLong(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Long, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 4, 3, 2, 1 }, new uint[] { 0x01020304 })] - [InlineDataAttribute(new byte[] { 4, 3, 2, 1, 6, 5, 4, 3 }, new uint[] { 0x01020304, 0x03040506 })] - public void AddUnsignedLong_AddsArray(byte[] bytes, uint[] value) - { - var entries = new List(); - - entries.AddUnsignedLong(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Long, entry.Type); - Assert.Equal((uint)value.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0 }, 0)] - [InlineDataAttribute(new byte[] { 1 }, 1)] - [InlineDataAttribute(new byte[] { 255 }, -1)] - public void AddSignedByte_AddsSingleValue(byte[] bytes, int value) - { - var entries = new List(); - - entries.AddSignedByte(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.SByte, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0 }, new int[] { 0 })] - [InlineDataAttribute(new byte[] { 0, 255, 2 }, new int[] { 0, -1, 2 })] - [InlineDataAttribute(new byte[] { 0, 255, 2, 3, 4, 5, 6 }, new int[] { 0, -1, 2, 3, 4, 5, 6 })] - public void AddSignedByte_AddsArray(byte[] bytes, int[] value) - { - var entries = new List(); - - entries.AddSignedByte(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.SByte, entry.Type); - Assert.Equal((uint)value.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0, 0 }, 0)] - [InlineDataAttribute(new byte[] { 1, 0 }, 1)] - [InlineDataAttribute(new byte[] { 0, 1 }, 256)] - [InlineDataAttribute(new byte[] { 2, 1 }, 258)] - [InlineDataAttribute(new byte[] { 255, 255 }, -1)] - public void AddSignedShort_AddsSingleValue(byte[] bytes, int value) - { - var entries = new List(); - - entries.AddSignedShort(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.SShort, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 1, 0 }, new int[] { 1 })] - [InlineDataAttribute(new byte[] { 1, 0, 255, 255 }, new int[] { 1, -1 })] - [InlineDataAttribute(new byte[] { 1, 0, 255, 255, 5, 4 }, new int[] { 1, -1, 1029 })] - public void AddSignedShort_AddsArray(byte[] bytes, int[] value) - { - var entries = new List(); - - entries.AddSignedShort(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.SShort, entry.Type); - Assert.Equal((uint)value.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0, 0, 0, 0 }, 0)] - [InlineDataAttribute(new byte[] { 1, 0, 0, 0 }, 1)] - [InlineDataAttribute(new byte[] { 0, 1, 0, 0 }, 256)] - [InlineDataAttribute(new byte[] { 0, 0, 1, 0 }, 256 * 256)] - [InlineDataAttribute(new byte[] { 0, 0, 0, 1 }, 256 * 256 * 256)] - [InlineDataAttribute(new byte[] { 1, 2, 3, 4 }, 67305985)] - [InlineDataAttribute(new byte[] { 255, 255, 255, 255 }, -1)] - public void AddSignedLong_AddsSingleValue(byte[] bytes, int value) - { - var entries = new List(); - - entries.AddSignedLong(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.SLong, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 4, 3, 2, 1 }, new int[] { 0x01020304 })] - [InlineDataAttribute(new byte[] { 4, 3, 2, 1, 255, 255, 255, 255 }, new int[] { 0x01020304, -1 })] - public void AddSignedLong_AddsArray(byte[] bytes, int[] value) - { - var entries = new List(); - - entries.AddSignedLong(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.SLong, entry.Type); - Assert.Equal((uint)value.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0 }, "")] - [InlineDataAttribute(new byte[] { (byte)'A', (byte)'B', (byte)'C', 0 }, "ABC")] - [InlineDataAttribute(new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', 0 }, "ABCDEF")] - [InlineDataAttribute(new byte[] { (byte)'A', (byte)'B', (byte)'C', (byte)'D', 0, (byte)'E', (byte)'F', (byte)'G', (byte)'H', 0 }, "ABCD\0EFGH")] - public void AddAscii_AddsEntry(byte[] bytes, string value) - { - var entries = new List(); - - entries.AddAscii(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Ascii, entry.Type); - Assert.Equal((uint)bytes.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 0)] - [InlineDataAttribute(new byte[] { 2, 0, 0, 0, 1, 0, 0, 0 }, 2, 1)] - [InlineDataAttribute(new byte[] { 1, 0, 0, 0, 2, 0, 0, 0 }, 1, 2)] - public void AddUnsignedRational_AddsSingleValue(byte[] bytes, uint numerator, uint denominator) - { - var entries = new List(); - - entries.AddUnsignedRational(TiffTags.ImageWidth, new Rational(numerator, denominator)); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Rational, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, new uint[] { 0 }, new uint[] { 0 })] - [InlineDataAttribute(new byte[] { 1, 0, 0, 0, 2, 0, 0, 0 }, new uint[] { 1 }, new uint[] { 2 })] - [InlineDataAttribute(new byte[] { 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0 }, new uint[] { 1, 2 }, new uint[] { 2, 3 })] - public void AddUnsignedRational_AddsArray(byte[] bytes, uint[] numerators, uint[] denominators) - { - var entries = new List(); - Rational[] value = Enumerable.Range(0, numerators.Length).Select(i => new Rational(numerators[i], denominators[i])).ToArray(); - - entries.AddUnsignedRational(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Rational, entry.Type); - Assert.Equal((uint)numerators.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 0)] - [InlineDataAttribute(new byte[] { 2, 0, 0, 0, 1, 0, 0, 0 }, 2, 1)] - [InlineDataAttribute(new byte[] { 1, 0, 0, 0, 2, 0, 0, 0 }, 1, 2)] - [InlineDataAttribute(new byte[] { 255, 255, 255, 255, 2, 0, 0, 0 }, -1, 2)] - public void AddSignedRational_AddsSingleValue(byte[] bytes, int numerator, int denominator) - { - var entries = new List(); - - entries.AddSignedRational(TiffTags.ImageWidth, new SignedRational(numerator, denominator)); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.SRational, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, new int[] { 0 }, new int[] { 0 })] - [InlineDataAttribute(new byte[] { 2, 0, 0, 0, 1, 0, 0, 0 }, new int[] { 2 }, new int[] { 1 })] - [InlineDataAttribute(new byte[] { 1, 0, 0, 0, 2, 0, 0, 0 }, new int[] { 1 }, new int[] { 2 })] - [InlineDataAttribute(new byte[] { 255, 255, 255, 255, 2, 0, 0, 0 }, new int[] { -1 }, new int[] { 2 })] - [InlineDataAttribute(new byte[] { 255, 255, 255, 255, 2, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0 }, new int[] { -1, 2 }, new int[] { 2, 3 })] - public void AddSignedRational_AddsArray(byte[] bytes, int[] numerators, int[] denominators) - { - var entries = new List(); - SignedRational[] value = Enumerable.Range(0, numerators.Length).Select(i => new SignedRational(numerators[i], denominators[i])).ToArray(); - - entries.AddSignedRational(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.SRational, entry.Type); - Assert.Equal((uint)numerators.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00 }, 0.0F)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x80, 0x3F }, 1.0F)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0xC0 }, -2.0F)] - [InlineDataAttribute(new byte[] { 0xFF, 0xFF, 0x7F, 0x7F }, float.MaxValue)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x80, 0x7F }, float.PositiveInfinity)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x80, 0xFF }, float.NegativeInfinity)] - public void AddFloat_AddsSingleValue(byte[] bytes, float value) - { - var entries = new List(); - - entries.AddFloat(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Float, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00 }, new float[] { 0.0F })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x80, 0x3F }, new float[] { 1.0F })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0xC0 }, new float[] { -2.0F })] - [InlineDataAttribute(new byte[] { 0xFF, 0xFF, 0x7F, 0x7F }, new float[] { float.MaxValue })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x80, 0x7F }, new float[] { float.PositiveInfinity })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x80, 0xFF }, new float[] { float.NegativeInfinity })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0xC0 }, new float[] { 0.0F, 1.0F, -2.0F })] - public void AddFloat_AddsArray(byte[] bytes, float[] value) - { - var entries = new List(); - - entries.AddFloat(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Float, entry.Type); - Assert.Equal((uint)value.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0.0)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F }, 1.0)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 }, 2.0)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0 }, -2.0)] - [InlineDataAttribute(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F }, double.MaxValue)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F }, double.PositiveInfinity)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF }, double.NegativeInfinity)] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF }, double.NaN)] - public void AddDouble_AddsSingleValue(byte[] bytes, double value) - { - var entries = new List(); - - entries.AddDouble(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Double, entry.Type); - Assert.Equal(1u, entry.Count); - Assert.Equal(bytes, entry.Value); - } - - [Theory] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new double[] { 0.0 })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F }, new double[] { 1.0 })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 }, new double[] { 2.0 })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0 }, new double[] { -2.0 })] - [InlineDataAttribute(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F }, new double[] { double.MaxValue })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F }, new double[] { double.PositiveInfinity })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF }, new double[] { double.NegativeInfinity })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF }, new double[] { double.NaN })] - [InlineDataAttribute(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0 }, new double[] { 0.0, 1.0, -2.0 })] - public void AddDouble_AddsArray(byte[] bytes, double[] value) - { - var entries = new List(); - - entries.AddDouble(TiffTags.ImageWidth, value); - - var entry = entries[0]; - Assert.Equal(TiffTags.ImageWidth, entry.Tag); - Assert.Equal(TiffType.Double, entry.Type); - Assert.Equal((uint)value.Length, entry.Count); - Assert.Equal(bytes, entry.Value); - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdEntryTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdEntryTests.cs deleted file mode 100644 index f5f44b3228..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdEntryTests.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.Formats.Tiff; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffIfdEntryTests - { - [Fact] - public void Constructor_SetsProperties() - { - var entry = new TiffIfdEntry((ushort)10u, TiffType.Short, 20u, new byte[] { 2, 4, 6, 8 }); - - Assert.Equal(10u, entry.Tag); - Assert.Equal(TiffType.Short, entry.Type); - Assert.Equal(20u, entry.Count); - Assert.Equal(new byte[] { 2, 4, 6, 8 }, entry.Value); - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdTests.cs deleted file mode 100644 index 88ae289615..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffIfd/TiffIfdTests.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.Formats.Tiff; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffIfdTests - { - [Fact] - public void Constructor_SetsProperties() - { - var entries = new TiffIfdEntry[10]; - var ifd = new TiffIfd(entries, 1234u); - - Assert.Equal(entries, ifd.Entries); - Assert.Equal(1234u, ifd.NextIfdOffset); - } - - [Fact] - public void GetIfdEntry_ReturnsIfdIfExists() - { - var entries = new[] - { - new TiffIfdEntry(10, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(20, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(30, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(40, TiffType.Short, 20, new byte[4]) - }; - var ifd = new TiffIfd(entries, 1234u); - - TiffIfdEntry? entry = ifd.GetIfdEntry(30); - - Assert.True(entry.HasValue); - Assert.Equal(30, entry.Value.Tag); - } - - [Fact] - public void GetIfdEntry_ReturnsNullOtherwise() - { - var entries = new[] - { - new TiffIfdEntry(10, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(20, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(30, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(40, TiffType.Short, 20, new byte[4]) - }; - var ifd = new TiffIfd(entries, 1234u); - - TiffIfdEntry? entry = ifd.GetIfdEntry(25); - - Assert.False(entry.HasValue); - } - - [Fact] - public void TryGetIfdEntry_ReturnsIfdIfExists() - { - var entries = new[] - { - new TiffIfdEntry(10, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(20, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(30, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(40, TiffType.Short, 20, new byte[4]) - }; - var ifd = new TiffIfd(entries, 1234u); - - bool success = ifd.TryGetIfdEntry(30, out var entry); - - Assert.True(success); - Assert.Equal(30, entry.Tag); - } - - [Fact] - public void TryGetIfdEntry_ReturnsFalseOtherwise() - { - var entries = new[] - { - new TiffIfdEntry(10, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(20, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(30, TiffType.Short, 20, new byte[4]), - new TiffIfdEntry(40, TiffType.Short, 20, new byte[4]) - }; - var ifd = new TiffIfd(entries, 1234u); - - bool success = ifd.TryGetIfdEntry(25, out var entry); - - Assert.False(success); - Assert.Equal(0, entry.Tag); - } - } -} diff --git a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffImageFormatDetectorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffImageFormatDetectorTests.cs deleted file mode 100644 index 7d8cad56bf..0000000000 --- a/tests/ImageSharp.Tests/Formats/Tiff/__obsolete/TiffImageFormatDetectorTests.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System.Linq; -using SixLabors.ImageSharp.Formats.Tiff; -using Xunit; - -namespace SixLabors.ImageSharp.Tests.Formats.Tiff -{ - [Trait("Category", "Tiff")] - public class TiffImageFormatDetectorTests - { - public static object[][] IsLittleEndianValues = new[] { new object[] { false }, - new object[] { true } }; - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void DetectFormat_ReturnsTiffFormat_ForValidFile(bool isLittleEndian) - { - byte[] bytes = new TiffGenHeader() - { - FirstIfd = new TiffGenIfd() - } - .ToBytes(isLittleEndian); - - TiffImageFormatDetector formatDetector = new TiffImageFormatDetector(); - byte[] headerBytes = bytes.Take(formatDetector.HeaderSize).ToArray(); - var format = formatDetector.DetectFormat(headerBytes); - - Assert.NotNull(format); - Assert.IsType(format); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void DetectFormat_ReturnsNull_WithInvalidByteOrderMarkers(bool isLittleEndian) - { - byte[] bytes = new TiffGenHeader() - { - FirstIfd = new TiffGenIfd(), - ByteOrderMarker = 0x1234 - } - .ToBytes(isLittleEndian); - - TiffImageFormatDetector formatDetector = new TiffImageFormatDetector(); - byte[] headerBytes = bytes.Take(formatDetector.HeaderSize).ToArray(); - var format = formatDetector.DetectFormat(headerBytes); - - Assert.Null(format); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void DetectFormat_ReturnsNull_WithIncorrectMagicNumber(bool isLittleEndian) - { - byte[] bytes = new TiffGenHeader() - { - FirstIfd = new TiffGenIfd(), - MagicNumber = 32 - } - .ToBytes(isLittleEndian); - - TiffImageFormatDetector formatDetector = new TiffImageFormatDetector(); - byte[] headerBytes = bytes.Take(formatDetector.HeaderSize).ToArray(); - var format = formatDetector.DetectFormat(headerBytes); - - Assert.Null(format); - } - - [Theory] - [MemberData(nameof(IsLittleEndianValues))] - public void DetectFormat_ReturnsNull_WithShortHeader(bool isLittleEndian) - { - byte[] bytes = new TiffGenHeader() - { - FirstIfd = new TiffGenIfd() - } - .ToBytes(isLittleEndian); - - TiffImageFormatDetector formatDetector = new TiffImageFormatDetector(); - byte[] headerBytes = bytes.Take(formatDetector.HeaderSize - 1).ToArray(); - var format = formatDetector.DetectFormat(headerBytes); - - Assert.Null(format); - } - } -} diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 0d9d055f16..e9d4b031ba 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -9,12 +9,6 @@ SixLabors.ImageSharp.Tests - - - - - -