Browse Source

Add documentation to all elements.

pull/1570/head
Andrew Wilkinson 9 years ago
parent
commit
fdcd483e58
  1. 52
      src/ImageSharp/Formats/Tiff/Constants/TiffCompression.cs
  2. 2
      src/ImageSharp/Formats/Tiff/Constants/TiffConstants.cs
  3. 15
      src/ImageSharp/Formats/Tiff/Constants/TiffExtraSamples.cs
  4. 9
      src/ImageSharp/Formats/Tiff/Constants/TiffFillOrder.cs
  5. 27
      src/ImageSharp/Formats/Tiff/Constants/TiffNewSubfileType.cs
  6. 33
      src/ImageSharp/Formats/Tiff/Constants/TiffOrientation.cs
  7. 53
      src/ImageSharp/Formats/Tiff/Constants/TiffPhotometricInterpretation.cs
  8. 11
      src/ImageSharp/Formats/Tiff/Constants/TiffPlanarConfiguration.cs
  9. 13
      src/ImageSharp/Formats/Tiff/Constants/TiffResolutionUnit.cs
  10. 13
      src/ImageSharp/Formats/Tiff/Constants/TiffSubfileType.cs
  11. 581
      src/ImageSharp/Formats/Tiff/Constants/TiffTags.cs
  12. 15
      src/ImageSharp/Formats/Tiff/Constants/TiffThreshholding.cs
  13. 51
      src/ImageSharp/Formats/Tiff/Constants/TiffType.cs
  14. 292
      src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs
  15. 2
      src/ImageSharp/Formats/Tiff/TiffEncoder.cs
  16. 14
      src/ImageSharp/Formats/Tiff/TiffIfd/TiffIfd.cs
  17. 24
      src/ImageSharp/Formats/Tiff/TiffIfd/TiffIfdEntry.cs

52
src/ImageSharp/Formats/Tiff/Constants/TiffCompression.cs

@ -10,28 +10,64 @@ namespace ImageSharp.Formats
/// </summary>
internal enum TiffCompression
{
// TIFF baseline compression types
/// <summary>
/// No compression.
/// </summary>
None = 1,
/// <summary>
/// CCITT Group 3 1-Dimensional Modified Huffman run-length encoding.
/// </summary>
Ccitt1D = 2,
PackBits = 32773,
// TIFF Extension compression types
/// <summary>
/// PackBits compression
/// </summary>
PackBits = 32773,
/// <summary>
/// T4-encoding: CCITT T.4 bi-level encoding (see Section 11 of the TIFF 6.0 specification).
/// </summary>
CcittGroup3Fax = 3,
/// <summary>
/// T6-encoding: CCITT T.6 bi-level encoding (see Section 11 of the TIFF 6.0 specification).
/// </summary>
CcittGroup4Fax = 4,
/// <summary>
/// LZW compression (see Section 13 of the TIFF 6.0 specification).
/// </summary>
Lzw = 5,
OldJpeg = 6,
// Technote 2
/// <summary>
/// JPEG compression - obsolete (see Section 22 of the TIFF 6.0 specification).
/// </summary>
OldJpeg = 6,
/// <summary>
/// JPEG compression (see TIFF Specification, supplement 2).
/// </summary>
Jpeg = 7,
/// <summary>
/// Deflate compression, using zlib data format (see TIFF Specification, supplement 2).
/// </summary>
Deflate = 8,
OldDeflate = 32946,
// TIFF-F/FX Extension
/// <summary>
/// Deflate compression - old.
/// </summary>
OldDeflate = 32946,
/// <summary>
/// ITU-T Rec. T.82 coding, applying ITU-T Rec. T.85 (JBIG) (see RFC2301).
/// </summary>
ItuTRecT82 = 9,
/// <summary>
/// ITU-T Rec. T.43 representation, using ITU-T Rec. T.82 (JBIG) (see RFC2301).
/// </summary>
ItuTRecT43 = 10
}
}

2
src/ImageSharp/Formats/Tiff/Constants/TiffConstants.cs

@ -39,7 +39,7 @@ namespace ImageSharp.Formats
/// Size (in bytes) of the Short and SShort data types
/// </summary>
public const int SizeOfShort = 2;
/// <summary>
/// Size (in bytes) of the Long and SLong data types
/// </summary>

15
src/ImageSharp/Formats/Tiff/Constants/TiffExtraSamples.cs

@ -6,14 +6,23 @@
namespace ImageSharp.Formats
{
/// <summary>
/// Enumeration representing the possible uses of extra-samples in TIFF format files.
/// Enumeration representing the possible uses of extra components in TIFF format files.
/// </summary>
internal enum TiffExtraSamples
{
// TIFF baseline ExtraSample values
/// <summary>
/// Unspecified data.
/// </summary>
Unspecified = 0,
/// <summary>
/// Associated alpha data (with pre-multiplied color).
/// </summary>
AssociatedAlpha = 1,
/// <summary>
/// Unassociated alpha data.
/// </summary>
UnassociatedAlpha = 2
}
}

9
src/ImageSharp/Formats/Tiff/Constants/TiffFillOrder.cs

@ -10,9 +10,14 @@ namespace ImageSharp.Formats
/// </summary>
internal enum TiffFillOrder
{
// TIFF baseline FillOrder values
/// <summary>
/// Pixels with lower column values are stored in the higher-order bits of the byte.
/// </summary>
MostSignificantBitFirst = 1,
/// <summary>
/// Pixels with lower column values are stored in the lower-order bits of the byte.
/// </summary>
LeastSignificantBitFirst = 2
}
}

27
src/ImageSharp/Formats/Tiff/Constants/TiffNewSubfileType.cs

@ -13,19 +13,34 @@ namespace ImageSharp.Formats
[Flags]
internal enum TiffNewSubfileType
{
// TIFF baseline subfile types
/// <summary>
/// A full-resolution image.
/// </summary>
FullImage = 0x0000,
/// <summary>
/// Reduced-resolution version of another image in this TIFF file.
/// </summary>
Preview = 0x0001,
/// <summary>
/// A single page of a multi-page image.
/// </summary>
SinglePage = 0x0002,
TransparencyMask = 0x0004,
// DNG Specification subfile types
/// <summary>
/// A transparency mask for another image in this TIFF file.
/// </summary>
TransparencyMask = 0x0004,
/// <summary>
/// Alternative reduced-resolution version of another image in this TIFF file (see DNG specification).
/// </summary>
AlternativePreview = 0x10000,
// TIFF-F/FX Specification subfile types
/// <summary>
/// Mixed raster content (see RFC2301).
/// </summary>
MixedRasterContent = 0x0008
}
}

33
src/ImageSharp/Formats/Tiff/Constants/TiffOrientation.cs

@ -10,15 +10,44 @@ namespace ImageSharp.Formats
/// </summary>
internal enum TiffOrientation
{
// TIFF baseline Orientation values
/// <summary>
/// The 0th row and 0th column represent the visual top and left-hand side of the image respectively.
/// </summary>
TopLeft = 1,
/// <summary>
/// The 0th row and 0th column represent the visual top and right-hand side of the image respectively.
/// </summary>
TopRight = 2,
/// <summary>
/// The 0th row and 0th column represent the visual bottom and right-hand side of the image respectively.
/// </summary>
BottomRight = 3,
/// <summary>
/// The 0th row and 0th column represent the visual bottom and left-hand side of the image respectively.
/// </summary>
BottomLeft = 4,
/// <summary>
/// The 0th row and 0th column represent the visual left-hand side and top of the image respectively.
/// </summary>
LeftTop = 5,
/// <summary>
/// The 0th row and 0th column represent the visual right-hand side and top of the image respectively.
/// </summary>
RightTop = 6,
/// <summary>
/// The 0th row and 0th column represent the visual right-hand side and bottom of the image respectively.
/// </summary>
RightBottom = 7,
/// <summary>
/// The 0th row and 0th column represent the visual left-hand side and bottom of the image respectively.
/// </summary>
LeftBottom = 8
}
}

53
src/ImageSharp/Formats/Tiff/Constants/TiffPhotometricInterpretation.cs

@ -10,31 +10,64 @@ namespace ImageSharp.Formats
/// </summary>
internal enum TiffPhotometricInterpretation
{
// TIFF baseline color spaces
/// <summary>
/// Bilevel and grayscale: 0 is imaged as white. The maximum value is imaged as black.
/// </summary>
WhiteIsZero = 0,
/// <summary>
/// Bilevel and grayscale: 0 is imaged as black. The maximum value is imaged as white.
/// </summary>
BlackIsZero = 1,
/// <summary>
/// RGB
/// </summary>
Rgb = 2,
/// <summary>
/// Palette Color
/// </summary>
PaletteColor = 3,
TransparencyMask = 4,
// TIFF Extension color spaces
/// <summary>
/// A transparency mask
/// </summary>
TransparencyMask = 4,
/// <summary>
/// Separated: usually CMYK (see Section 16 of the TIFF 6.0 specification).
/// </summary>
Separated = 5,
/// <summary>
/// YCbCr (see Section 21 of the TIFF 6.0 specification).
/// </summary>
YCbCr = 6,
CieLab = 8,
// TIFF TechNote 1
/// <summary>
/// 1976 CIE L*a*b* (see Section 23 of the TIFF 6.0 specification).
/// </summary>
CieLab = 8,
/// <summary>
/// ICC L*a*b* (see TIFF Specification, supplement 1).
/// </summary>
IccLab = 9,
// TIFF-F/FX Specification
/// <summary>
/// ITU L*a*b* (see RFC2301).
/// </summary>
ItuLab = 10,
// DNG Specification
/// <summary>
/// Color Filter Array (see the DNG specification).
/// </summary>
ColorFilterArray = 32803,
/// <summary>
/// Linear Raw (see the DNG specification).
/// </summary>
LinearRaw = 34892
}
}

11
src/ImageSharp/Formats/Tiff/Constants/TiffPlanarConfiguration.cs

@ -6,13 +6,18 @@
namespace ImageSharp.Formats
{
/// <summary>
/// Enumeration representing the planar configuration types defined by the Tiff file-format.
/// Enumeration representing how the components of each pixel are stored the Tiff file-format.
/// </summary>
internal enum TiffPlanarConfiguration
{
// TIFF baseline PlanarConfiguration values
/// <summary>
/// Chunky format.
/// </summary>
Chunky = 1,
/// <summary>
/// Planar format.
/// </summary>
Planar = 2
}
}

13
src/ImageSharp/Formats/Tiff/Constants/TiffResolutionUnit.cs

@ -10,10 +10,19 @@ namespace ImageSharp.Formats
/// </summary>
internal enum TiffResolutionUnit
{
// TIFF baseline ResolutionUnit values
/// <summary>
/// No absolute unit of measurement.
/// </summary>
None = 1,
/// <summary>
/// Inch.
/// </summary>
Inch = 2,
/// <summary>
/// Centimeter.
/// </summary>
Centimeter = 2
}
}

13
src/ImageSharp/Formats/Tiff/Constants/TiffSubfileType.cs

@ -10,10 +10,19 @@ namespace ImageSharp.Formats
/// </summary>
internal enum TiffSubfileType
{
// TIFF baseline subfile types
/// <summary>
/// Full-resolution image data.
/// </summary>
FullImage = 1,
/// <summary>
/// Reduced-resolution image data.
/// </summary>
Preview = 2,
/// <summary>
/// A single page of a multi-page image.
/// </summary>
SinglePage = 3
}
}

581
src/ImageSharp/Formats/Tiff/Constants/TiffTags.cs

@ -10,196 +10,709 @@ namespace ImageSharp.Formats
/// </summary>
internal class TiffTags
{
// Section 8: Baseline Fields
/// <summary>
/// Artist (see Section 8: Baseline Fields).
/// </summary>
public const int Artist = 315;
/// <summary>
/// BitsPerSample (see Section 8: Baseline Fields).
/// </summary>
public const int BitsPerSample = 258;
/// <summary>
/// CellLength (see Section 8: Baseline Fields).
/// </summary>
public const int CellLength = 265;
/// <summary>
/// CellWidth (see Section 8: Baseline Fields).
/// </summary>
public const int CellWidth = 264;
/// <summary>
/// ColorMap (see Section 8: Baseline Fields).
/// </summary>
public const int ColorMap = 320;
/// <summary>
/// Compression (see Section 8: Baseline Fields).
/// </summary>
public const int Compression = 259;
/// <summary>
/// Copyright (see Section 8: Baseline Fields).
/// </summary>
public const int Copyright = 33432;
/// <summary>
/// DateTime (see Section 8: Baseline Fields).
/// </summary>
public const int DateTime = 306;
/// <summary>
/// ExtraSamples (see Section 8: Baseline Fields).
/// </summary>
public const int ExtraSamples = 338;
/// <summary>
/// FillOrder (see Section 8: Baseline Fields).
/// </summary>
public const int FillOrder = 266;
/// <summary>
/// FreeByteCounts (see Section 8: Baseline Fields).
/// </summary>
public const int FreeByteCounts = 289;
/// <summary>
/// FreeOffsets (see Section 8: Baseline Fields).
/// </summary>
public const int FreeOffsets = 288;
/// <summary>
/// GrayResponseCurve (see Section 8: Baseline Fields).
/// </summary>
public const int GrayResponseCurve = 291;
/// <summary>
/// GrayResponseUnit (see Section 8: Baseline Fields).
/// </summary>
public const int GrayResponseUnit = 290;
/// <summary>
/// HostComputer (see Section 8: Baseline Fields).
/// </summary>
public const int HostComputer = 316;
/// <summary>
/// ImageDescription (see Section 8: Baseline Fields).
/// </summary>
public const int ImageDescription = 270;
/// <summary>
/// ImageLength (see Section 8: Baseline Fields).
/// </summary>
public const int ImageLength = 257;
/// <summary>
/// ImageWidth (see Section 8: Baseline Fields).
/// </summary>
public const int ImageWidth = 256;
/// <summary>
/// Make (see Section 8: Baseline Fields).
/// </summary>
public const int Make = 271;
/// <summary>
/// MaxSampleValue (see Section 8: Baseline Fields).
/// </summary>
public const int MaxSampleValue = 281;
/// <summary>
/// MinSampleValue (see Section 8: Baseline Fields).
/// </summary>
public const int MinSampleValue = 280;
/// <summary>
/// Model (see Section 8: Baseline Fields).
/// </summary>
public const int Model = 272;
/// <summary>
/// NewSubfileType (see Section 8: Baseline Fields).
/// </summary>
public const int NewSubfileType = 254;
/// <summary>
/// Orientation (see Section 8: Baseline Fields).
/// </summary>
public const int Orientation = 274;
/// <summary>
/// PhotometricInterpretation (see Section 8: Baseline Fields).
/// </summary>
public const int PhotometricInterpretation = 262;
/// <summary>
/// PlanarConfiguration (see Section 8: Baseline Fields).
/// </summary>
public const int PlanarConfiguration = 284;
/// <summary>
/// ResolutionUnit (see Section 8: Baseline Fields).
/// </summary>
public const int ResolutionUnit = 296;
/// <summary>
/// RowsPerStrip (see Section 8: Baseline Fields).
/// </summary>
public const int RowsPerStrip = 278;
/// <summary>
/// SamplesPerPixel (see Section 8: Baseline Fields).
/// </summary>
public const int SamplesPerPixel = 277;
/// <summary>
/// Software (see Section 8: Baseline Fields).
/// </summary>
public const int Software = 305;
/// <summary>
/// StripByteCounts (see Section 8: Baseline Fields).
/// </summary>
public const int StripByteCounts = 279;
/// <summary>
/// StripOffsets (see Section 8: Baseline Fields).
/// </summary>
public const int StripOffsets = 273;
/// <summary>
/// SubfileType (see Section 8: Baseline Fields).
/// </summary>
public const int SubfileType = 255;
/// <summary>
/// Threshholding (see Section 8: Baseline Fields).
/// </summary>
public const int Threshholding = 263;
/// <summary>
/// XResolution (see Section 8: Baseline Fields).
/// </summary>
public const int XResolution = 282;
public const int YResolution = 283;
// Section 11: CCITT Bilevel Encodings
/// <summary>
/// YResolution (see Section 8: Baseline Fields).
/// </summary>
public const int YResolution = 283;
/// <summary>
/// T4Options (see Section 11: CCITT Bilevel Encodings).
/// </summary>
public const int T4Options = 292;
public const int T6Options = 293;
// Section 12: Document Storage and Retrieval
/// <summary>
/// T6Options (see Section 11: CCITT Bilevel Encodings).
/// </summary>
public const int T6Options = 293;
/// <summary>
/// DocumentName (see Section 12: Document Storage and Retrieval).
/// </summary>
public const int DocumentName = 269;
/// <summary>
/// PageName (see Section 12: Document Storage and Retrieval).
/// </summary>
public const int PageName = 285;
/// <summary>
/// PageNumber (see Section 12: Document Storage and Retrieval).
/// </summary>
public const int PageNumber = 297;
/// <summary>
/// XPosition (see Section 12: Document Storage and Retrieval).
/// </summary>
public const int XPosition = 286;
public const int YPosition = 287;
// Section 14: Differencing Predictor
/// <summary>
/// YPosition (see Section 12: Document Storage and Retrieval).
/// </summary>
public const int YPosition = 287;
/// <summary>
/// Predictor (see Section 14: Differencing Predictor).
/// </summary>
public const int Predictor = 317;
// Section 15: Tiled Images
/// <summary>
/// TileWidth (see Section 15: Tiled Images).
/// </summary>
public const int TileWidth = 322;
/// <summary>
/// TileLength (see Section 15: Tiled Images).
/// </summary>
public const int TileLength = 323;
/// <summary>
/// TileOffsets (see Section 15: Tiled Images).
/// </summary>
public const int TileOffsets = 324;
public const int TileByteCounts = 325;
// Section 16: CMYK Images
/// <summary>
/// TileByteCounts (see Section 15: Tiled Images).
/// </summary>
public const int TileByteCounts = 325;
/// <summary>
/// InkSet (see Section 16: CMYK Images).
/// </summary>
public const int InkSet = 332;
/// <summary>
/// NumberOfInks (see Section 16: CMYK Images).
/// </summary>
public const int NumberOfInks = 334;
/// <summary>
/// InkNames (see Section 16: CMYK Images).
/// </summary>
public const int InkNames = 333;
/// <summary>
/// DotRange (see Section 16: CMYK Images).
/// </summary>
public const int DotRange = 336;
public const int TargetPrinter = 337;
// Section 17: Halftone Hints
/// <summary>
/// TargetPrinter (see Section 16: CMYK Images).
/// </summary>
public const int TargetPrinter = 337;
/// <summary>
/// HalftoneHints (see Section 17: Halftone Hints).
/// </summary>
public const int HalftoneHints = 321;
// Section 19: Data Sample Format
/// <summary>
/// SampleFormat (see Section 19: Data Sample Format).
/// </summary>
public const int SampleFormat = 339;
/// <summary>
/// SMinSampleValue (see Section 19: Data Sample Format).
/// </summary>
public const int SMinSampleValue = 340;
public const int SMaxSampleValue = 341;
// Section 20: RGB Image Colorimetry
/// <summary>
/// SMaxSampleValue (see Section 19: Data Sample Format).
/// </summary>
public const int SMaxSampleValue = 341;
/// <summary>
/// WhitePoint (see Section 20: RGB Image Colorimetry).
/// </summary>
public const int WhitePoint = 318;
/// <summary>
/// PrimaryChromaticities (see Section 20: RGB Image Colorimetry).
/// </summary>
public const int PrimaryChromaticities = 319;
/// <summary>
/// TransferFunction (see Section 20: RGB Image Colorimetry).
/// </summary>
public const int TransferFunction = 301;
/// <summary>
/// TransferRange (see Section 20: RGB Image Colorimetry).
/// </summary>
public const int TransferRange = 342;
public const int ReferenceBlackWhite = 532;
// Section 21: YCbCr Images
/// <summary>
/// ReferenceBlackWhite (see Section 20: RGB Image Colorimetry).
/// </summary>
public const int ReferenceBlackWhite = 532;
/// <summary>
/// YCbCrCoefficients (see Section 21: YCbCr Images).
/// </summary>
public const int YCbCrCoefficients = 529;
/// <summary>
/// YCbCrSubSampling (see Section 21: YCbCr Images).
/// </summary>
public const int YCbCrSubSampling = 530;
public const int YCbCrPositioning = 531;
// Section 22: JPEG Compression
/// <summary>
/// YCbCrPositioning (see Section 21: YCbCr Images).
/// </summary>
public const int YCbCrPositioning = 531;
/// <summary>
/// JpegProc (see Section 22: JPEG Compression).
/// </summary>
public const int JpegProc = 512;
/// <summary>
/// JpegInterchangeFormat (see Section 22: JPEG Compression).
/// </summary>
public const int JpegInterchangeFormat = 513;
/// <summary>
/// JpegInterchangeFormatLength (see Section 22: JPEG Compression).
/// </summary>
public const int JpegInterchangeFormatLength = 514;
/// <summary>
/// JpegRestartInterval (see Section 22: JPEG Compression).
/// </summary>
public const int JpegRestartInterval = 515;
/// <summary>
/// JpegLosslessPredictors (see Section 22: JPEG Compression).
/// </summary>
public const int JpegLosslessPredictors = 517;
/// <summary>
/// JpegPointTransforms (see Section 22: JPEG Compression).
/// </summary>
public const int JpegPointTransforms = 518;
/// <summary>
/// JpegQTables (see Section 22: JPEG Compression).
/// </summary>
public const int JpegQTables = 519;
/// <summary>
/// JpegDCTables (see Section 22: JPEG Compression).
/// </summary>
public const int JpegDCTables = 520;
public const int JpegACTables = 521;
// TIFF Supplement 1: Adobe Pagemaker 6.0
/// <summary>
/// JpegACTables (see Section 22: JPEG Compression).
/// </summary>
public const int JpegACTables = 521;
/// <summary>
/// SubIFDs (see TIFF Supplement 1: Adobe Pagemaker 6.0).
/// </summary>
public const int SubIFDs = 330;
/// <summary>
/// ClipPath (see TIFF Supplement 1: Adobe Pagemaker 6.0).
/// </summary>
public const int ClipPath = 343;
/// <summary>
/// XClipPathUnits (see TIFF Supplement 1: Adobe Pagemaker 6.0).
/// </summary>
public const int XClipPathUnits = 344;
/// <summary>
/// YClipPathUnits (see TIFF Supplement 1: Adobe Pagemaker 6.0).
/// </summary>
public const int YClipPathUnits = 345;
/// <summary>
/// Indexed (see TIFF Supplement 1: Adobe Pagemaker 6.0).
/// </summary>
public const int Indexed = 346;
/// <summary>
/// ImageID (see TIFF Supplement 1: Adobe Pagemaker 6.0).
/// </summary>
public const int ImageID = 32781;
public const int OpiProxy = 351;
// TIFF Supplement 2: Adobe Photoshop
/// <summary>
/// OpiProxy (see TIFF Supplement 1: Adobe Pagemaker 6.0).
/// </summary>
public const int OpiProxy = 351;
/// <summary>
/// ImageSourceData (see TIFF Supplement 2: Adobe Photoshop).
/// </summary>
public const int ImageSourceData = 37724;
// TIFF/EP Specification: Additional Tags
/// <summary>
/// JPEGTables (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int JPEGTables = 0x015B;
/// <summary>
/// CFARepeatPatternDim (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int CFARepeatPatternDim = 0x828D;
/// <summary>
/// BatteryLevel (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int BatteryLevel = 0x828F;
/// <summary>
/// Interlace (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int Interlace = 0x8829;
/// <summary>
/// TimeZoneOffset (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int TimeZoneOffset = 0x882A;
/// <summary>
/// SelfTimerMode (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int SelfTimerMode = 0x882B;
/// <summary>
/// Noise (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int Noise = 0x920D;
/// <summary>
/// ImageNumber (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int ImageNumber = 0x9211;
/// <summary>
/// SecurityClassification (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int SecurityClassification = 0x9212;
/// <summary>
/// ImageHistory (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int ImageHistory = 0x9213;
public const int TiffEPStandardID = 0x9216;
// TIFF-F/FX Specification (http://www.ietf.org/rfc/rfc2301.txt)
/// <summary>
/// TiffEPStandardID (see TIFF/EP Specification: Additional Tags).
/// </summary>
public const int TiffEPStandardID = 0x9216;
/// <summary>
/// BadFaxLines (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int BadFaxLines = 326;
/// <summary>
/// CleanFaxData (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int CleanFaxData = 327;
/// <summary>
/// ConsecutiveBadFaxLines (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int ConsecutiveBadFaxLines = 328;
/// <summary>
/// GlobalParametersIFD (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int GlobalParametersIFD = 400;
/// <summary>
/// ProfileType (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int ProfileType = 401;
/// <summary>
/// FaxProfile (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int FaxProfile = 402;
/// <summary>
/// CodingMethod (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int CodingMethod = 403;
/// <summary>
/// VersionYear (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int VersionYear = 404;
/// <summary>
/// ModeNumber (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int ModeNumber = 405;
/// <summary>
/// Decode (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int Decode = 433;
/// <summary>
/// DefaultImageColor (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int DefaultImageColor = 434;
/// <summary>
/// StripRowCounts (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int StripRowCounts = 559;
public const int ImageLayer = 34732;
// Embedded Metadata
/// <summary>
/// ImageLayer (see RFC2301: TIFF-F/FX Specification).
/// </summary>
public const int ImageLayer = 34732;
/// <summary>
/// Xmp (Embedded Metadata).
/// </summary>
public const int Xmp = 700;
/// <summary>
/// Iptc (Embedded Metadata).
/// </summary>
public const int Iptc = 33723;
/// <summary>
/// Photoshop (Embedded Metadata).
/// </summary>
public const int Photoshop = 34377;
/// <summary>
/// ExifIFD (Embedded Metadata).
/// </summary>
public const int ExifIFD = 34665;
/// <summary>
/// GpsIFD (Embedded Metadata).
/// </summary>
public const int GpsIFD = 34853;
public const int InteroperabilityIFD = 40965;
// Other Private TIFF tags (http://www.awaresystems.be/imaging/tiff/tifftags/private.html)
/// <summary>
/// InteroperabilityIFD (Embedded Metadata).
/// </summary>
public const int InteroperabilityIFD = 40965;
/// <summary>
/// WangAnnotation (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int WangAnnotation = 32932;
/// <summary>
/// MDFileTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int MDFileTag = 33445;
/// <summary>
/// MDScalePixel (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int MDScalePixel = 33446;
/// <summary>
/// MDColorTable (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int MDColorTable = 33447;
/// <summary>
/// MDLabName (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int MDLabName = 33448;
/// <summary>
/// MDSampleInfo (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int MDSampleInfo = 33449;
/// <summary>
/// MDPrepDate (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int MDPrepDate = 33450;
/// <summary>
/// MDPrepTime (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int MDPrepTime = 33451;
/// <summary>
/// MDFileUnits (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int MDFileUnits = 33452;
/// <summary>
/// ModelPixelScaleTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int ModelPixelScaleTag = 33550;
/// <summary>
/// IngrPacketDataTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int IngrPacketDataTag = 33918;
/// <summary>
/// IngrFlagRegisters (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int IngrFlagRegisters = 33919;
/// <summary>
/// IrasBTransformationMatrix (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int IrasBTransformationMatrix = 33920;
/// <summary>
/// ModelTiePointTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int ModelTiePointTag = 33922;
/// <summary>
/// ModelTransformationTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int ModelTransformationTag = 34264;
/// <summary>
/// IccProfile (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int IccProfile = 34675;
/// <summary>
/// GeoKeyDirectoryTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int GeoKeyDirectoryTag = 34735;
/// <summary>
/// GeoDoubleParamsTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int GeoDoubleParamsTag = 34736;
/// <summary>
/// GeoAsciiParamsTag (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int GeoAsciiParamsTag = 34737;
/// <summary>
/// HylaFAXFaxRecvParams (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int HylaFAXFaxRecvParams = 34908;
/// <summary>
/// HylaFAXFaxSubAddress (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int HylaFAXFaxSubAddress = 34909;
/// <summary>
/// HylaFAXFaxRecvTime (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int HylaFAXFaxRecvTime = 34910;
/// <summary>
/// GdalMetadata (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int GdalMetadata = 42112;
/// <summary>
/// GdalNodata (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int GdalNodata = 42113;
/// <summary>
/// OceScanjobDescription (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int OceScanjobDescription = 50215;
/// <summary>
/// OceApplicationSelector (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int OceApplicationSelector = 50216;
/// <summary>
/// OceIdentificationNumber (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int OceIdentificationNumber = 50217;
/// <summary>
/// OceImageLogicCharacteristics (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int OceImageLogicCharacteristics = 50218;
/// <summary>
/// AliasLayerMetadata (Other Private TIFF tags : see http://www.awaresystems.be/imaging/tiff/tifftags/private.html).
/// </summary>
public const int AliasLayerMetadata = 50784;
}
}

15
src/ImageSharp/Formats/Tiff/Constants/TiffThreshholding.cs

@ -6,14 +6,23 @@
namespace ImageSharp.Formats
{
/// <summary>
/// Enumeration representing the threshholding types defined by the Tiff file-format.
/// Enumeration representing the threshholding applied to image data defined by the Tiff file-format.
/// </summary>
internal enum TiffThreshholding
{
// TIFF baseline Threshholding values
/// <summary>
/// No dithering or halftoning.
/// </summary>
None = 1,
/// <summary>
/// An ordered dither or halftone technique.
/// </summary>
Ordered = 2,
/// <summary>
/// A randomized process such as error diffusion.
/// </summary>
Random = 3
}
}

51
src/ImageSharp/Formats/Tiff/Constants/TiffType.cs

@ -10,18 +10,69 @@ namespace ImageSharp.Formats
/// </summary>
internal enum TiffType
{
/// <summary>
/// Unsigned 8-bit integer.
/// </summary>
Byte = 1,
/// <summary>
/// ASCII formatted text.
/// </summary>
Ascii = 2,
/// <summary>
/// Unsigned 16-bit integer.
/// </summary>
Short = 3,
/// <summary>
/// Unsigned 32-bit integer.
/// </summary>
Long = 4,
/// <summary>
/// Unsigned rational number.
/// </summary>
Rational = 5,
/// <summary>
/// Signed 8-bit integer.
/// </summary>
SByte = 6,
/// <summary>
/// Undefined data type.
/// </summary>
Undefined = 7,
/// <summary>
/// Signed 16-bit integer.
/// </summary>
SShort = 8,
/// <summary>
/// Signed 32-bit integer.
/// </summary>
SLong = 9,
/// <summary>
/// Signed rational number.
/// </summary>
SRational = 10,
/// <summary>
/// Single precision (4-byte) IEEE format.
/// </summary>
Float = 11,
/// <summary>
/// Double precision (8-byte) IEEE format.
/// </summary>
Double = 12,
/// <summary>
/// Reference to an IFD.
/// </summary>
Ifd = 13
}
}

292
src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs

@ -28,6 +28,12 @@ namespace ImageSharp.Formats
this.options = options ?? new DecoderOptions();
}
/// <summary>
/// Initializes a new instance of the <see cref="TiffDecoderCore" /> class.
/// </summary>
/// <param name="stream">The input stream.</param>
/// <param name="isLittleEndian">A flag indicating if the file is encoded in little-endian or big-endian format.</param>
/// <param name="options">The decoder options.</param>
public TiffDecoderCore(Stream stream, bool isLittleEndian, IDecoderOptions options)
: this(options)
{
@ -45,6 +51,13 @@ namespace ImageSharp.Formats
/// </summary>
public bool IsLittleEndian { get; private set; }
/// <summary>
/// Calculates the size (in bytes) of the data contained within an IFD entry.
/// </summary>
/// <param name="entry">The IFD entry to calculate the size for.</param>
/// <returns>The size of the data (in bytes).</returns>
public static uint GetSizeOfData(TiffIfdEntry entry) => SizeOfDataType(entry.Type) * entry.Count;
/// <summary>
/// Decodes the image from the specified <see cref="Stream"/> and sets
/// the data to image.
@ -69,6 +82,13 @@ namespace ImageSharp.Formats
{
}
/// <summary>
/// Reads the TIFF header from the input stream.
/// </summary>
/// <returns>The byte offset to the first IFD in the file.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the TIFF file header is invalid.
/// </exception>
public uint ReadHeader()
{
byte[] headerBytes = new byte[TiffConstants.SizeOfTiffHeader];
@ -97,6 +117,11 @@ namespace ImageSharp.Formats
return firstIfdOffset;
}
/// <summary>
/// Reads a <see cref="TiffIfd"/> from the input stream.
/// </summary>
/// <param name="offset">The byte offset within the file to find the IFD.</param>
/// <returns>A <see cref="TiffIfd"/> containing the retrieved data.</returns>
public TiffIfd ReadIfd(uint offset)
{
this.InputStream.Seek(offset, SeekOrigin.Begin);
@ -125,24 +150,11 @@ namespace ImageSharp.Formats
return new TiffIfd(entries, nextIfdOffset);
}
private void ReadBytes(byte[] buffer, int count)
{
int offset = 0;
while (count > 0)
{
int bytesRead = this.InputStream.Read(buffer, offset, count);
if (bytesRead == 0)
{
break;
}
offset += bytesRead;
count -= bytesRead;
}
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as an array of bytes.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
public byte[] ReadBytes(ref TiffIfdEntry entry)
{
uint byteLength = GetSizeOfData(entry);
@ -160,6 +172,15 @@ namespace ImageSharp.Formats
return entry.Value;
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as an unsigned integer value.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="uint"/>, or if
/// there is an array of items.
/// </exception>
public uint ReadUnsignedInteger(ref TiffIfdEntry entry)
{
if (entry.Count != 1)
@ -180,6 +201,15 @@ namespace ImageSharp.Formats
}
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as a signed integer value.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to an <see cref="int"/>, or if
/// there is an array of items.
/// </exception>
public int ReadSignedInteger(ref TiffIfdEntry entry)
{
if (entry.Count != 1)
@ -200,6 +230,14 @@ namespace ImageSharp.Formats
}
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as an array of unsigned integer values.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="uint"/>.
/// </exception>
public uint[] ReadUnsignedIntegerArray(ref TiffIfdEntry entry)
{
byte[] bytes = this.ReadBytes(ref entry);
@ -244,6 +282,14 @@ namespace ImageSharp.Formats
return result;
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as an array of signed integer values.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to an <see cref="int"/>.
/// </exception>
public int[] ReadSignedIntegerArray(ref TiffIfdEntry entry)
{
byte[] bytes = this.ReadBytes(ref entry);
@ -288,6 +334,14 @@ namespace ImageSharp.Formats
return result;
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as a <see cref="string"/> value.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="string"/>.
/// </exception>
public string ReadString(ref TiffIfdEntry entry)
{
if (entry.Type != TiffType.Ascii)
@ -305,6 +359,15 @@ namespace ImageSharp.Formats
return Encoding.UTF8.GetString(bytes, 0, (int)entry.Count - 1);
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as a <see cref="Rational"/> value.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="Rational"/>, or if
/// there is an array of items.
/// </exception>
public Rational ReadUnsignedRational(ref TiffIfdEntry entry)
{
if (entry.Count != 1)
@ -315,6 +378,15 @@ namespace ImageSharp.Formats
return this.ReadUnsignedRationalArray(ref entry)[0];
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as a <see cref="SignedRational"/> value.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="SignedRational"/>, or if
/// there is an array of items.
/// </exception>
public SignedRational ReadSignedRational(ref TiffIfdEntry entry)
{
if (entry.Count != 1)
@ -325,6 +397,14 @@ namespace ImageSharp.Formats
return this.ReadSignedRationalArray(ref entry)[0];
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as an array of <see cref="Rational"/> values.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="Rational"/>.
/// </exception>
public Rational[] ReadUnsignedRationalArray(ref TiffIfdEntry entry)
{
if (entry.Type != TiffType.Rational)
@ -338,13 +418,21 @@ namespace ImageSharp.Formats
for (int i = 0; i < result.Length; i++)
{
uint numerator = this.ToUInt32(bytes, i * TiffConstants.SizeOfRational);
uint denominator = this.ToUInt32(bytes, i * TiffConstants.SizeOfRational + TiffConstants.SizeOfLong);
uint denominator = this.ToUInt32(bytes, (i * TiffConstants.SizeOfRational) + TiffConstants.SizeOfLong);
result[i] = new Rational(numerator, denominator);
}
return result;
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as an array of <see cref="SignedRational"/> values.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="SignedRational"/>.
/// </exception>
public SignedRational[] ReadSignedRationalArray(ref TiffIfdEntry entry)
{
if (entry.Type != TiffType.SRational)
@ -358,13 +446,22 @@ namespace ImageSharp.Formats
for (int i = 0; i < result.Length; i++)
{
int numerator = this.ToInt32(bytes, i * TiffConstants.SizeOfRational);
int denominator = this.ToInt32(bytes, i * TiffConstants.SizeOfRational + TiffConstants.SizeOfLong);
int denominator = this.ToInt32(bytes, (i * TiffConstants.SizeOfRational) + TiffConstants.SizeOfLong);
result[i] = new SignedRational(numerator, denominator);
}
return result;
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as a <see cref="float"/> value.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="float"/>, or if
/// there is an array of items.
/// </exception>
public float ReadFloat(ref TiffIfdEntry entry)
{
if (entry.Count != 1)
@ -380,6 +477,15 @@ namespace ImageSharp.Formats
return this.ToSingle(entry.Value, 0);
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as a <see cref="double"/> value.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="double"/>, or if
/// there is an array of items.
/// </exception>
public double ReadDouble(ref TiffIfdEntry entry)
{
if (entry.Count != 1)
@ -390,6 +496,14 @@ namespace ImageSharp.Formats
return this.ReadDoubleArray(ref entry)[0];
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as an array of <see cref="float"/> values.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="float"/>.
/// </exception>
public float[] ReadFloatArray(ref TiffIfdEntry entry)
{
if (entry.Type != TiffType.Float)
@ -408,6 +522,14 @@ namespace ImageSharp.Formats
return result;
}
/// <summary>
/// Reads the data from a <see cref="TiffIfdEntry"/> as an array of <see cref="double"/> values.
/// </summary>
/// <param name="entry">The <see cref="TiffIfdEntry"/> to read.</param>
/// <returns>The data.</returns>
/// <exception cref="ImageFormatException">
/// Thrown if the data-type specified by the file cannot be converted to a <see cref="double"/>.
/// </exception>
public double[] ReadDoubleArray(ref TiffIfdEntry entry)
{
if (entry.Type != TiffType.Double)
@ -426,11 +548,77 @@ namespace ImageSharp.Formats
return result;
}
/// <summary>
/// Calculates the size (in bytes) for the specified TIFF data-type.
/// </summary>
/// <param name="type">The data-type to calculate the size for.</param>
/// <returns>The size of the data-type (in bytes).</returns>
private static uint SizeOfDataType(TiffType type)
{
switch (type)
{
case TiffType.Byte:
case TiffType.Ascii:
case TiffType.SByte:
case TiffType.Undefined:
return 1u;
case TiffType.Short:
case TiffType.SShort:
return 2u;
case TiffType.Long:
case TiffType.SLong:
case TiffType.Float:
case TiffType.Ifd:
return 4u;
case TiffType.Rational:
case TiffType.SRational:
case TiffType.Double:
return 8u;
default:
return 0u;
}
}
/// <summary>
/// Reads a sequence of bytes from the input stream into a buffer.
/// </summary>
/// <param name="buffer">A buffer to store the retrieved data.</param>
/// <param name="count">The number of bytes to read.</param>
private void ReadBytes(byte[] buffer, int count)
{
int offset = 0;
while (count > 0)
{
int bytesRead = this.InputStream.Read(buffer, offset, count);
if (bytesRead == 0)
{
break;
}
offset += bytesRead;
count -= bytesRead;
}
}
/// <summary>
/// Converts buffer data into an <see cref="sbyte"/> using the correct endianness.
/// </summary>
/// <param name="bytes">The buffer.</param>
/// <param name="offset">The byte offset within the buffer.</param>
/// <returns>The converted value.</returns>
private sbyte ToSByte(byte[] bytes, int offset)
{
return (sbyte)bytes[offset];
}
/// <summary>
/// Converts buffer data into an <see cref="short"/> using the correct endianness.
/// </summary>
/// <param name="bytes">The buffer.</param>
/// <param name="offset">The byte offset within the buffer.</param>
/// <returns>The converted value.</returns>
private short ToInt16(byte[] bytes, int offset)
{
if (this.IsLittleEndian)
@ -443,6 +631,12 @@ namespace ImageSharp.Formats
}
}
/// <summary>
/// Converts buffer data into an <see cref="int"/> using the correct endianness.
/// </summary>
/// <param name="bytes">The buffer.</param>
/// <param name="offset">The byte offset within the buffer.</param>
/// <returns>The converted value.</returns>
private int ToInt32(byte[] bytes, int offset)
{
if (this.IsLittleEndian)
@ -455,21 +649,45 @@ namespace ImageSharp.Formats
}
}
/// <summary>
/// Converts buffer data into a <see cref="byte"/> using the correct endianness.
/// </summary>
/// <param name="bytes">The buffer.</param>
/// <param name="offset">The byte offset within the buffer.</param>
/// <returns>The converted value.</returns>
private byte ToByte(byte[] bytes, int offset)
{
return bytes[offset];
}
/// <summary>
/// Converts buffer data into a <see cref="uint"/> using the correct endianness.
/// </summary>
/// <param name="bytes">The buffer.</param>
/// <param name="offset">The byte offset within the buffer.</param>
/// <returns>The converted value.</returns>
private uint ToUInt32(byte[] bytes, int offset)
{
return (uint)this.ToInt32(bytes, offset);
}
/// <summary>
/// Converts buffer data into a <see cref="ushort"/> using the correct endianness.
/// </summary>
/// <param name="bytes">The buffer.</param>
/// <param name="offset">The byte offset within the buffer.</param>
/// <returns>The converted value.</returns>
private ushort ToUInt16(byte[] bytes, int offset)
{
return (ushort)this.ToInt16(bytes, offset);
}
/// <summary>
/// Converts buffer data into a <see cref="float"/> using the correct endianness.
/// </summary>
/// <param name="bytes">The buffer.</param>
/// <param name="offset">The byte offset within the buffer.</param>
/// <returns>The converted value.</returns>
private float ToSingle(byte[] bytes, int offset)
{
byte[] buffer = new byte[4];
@ -483,6 +701,12 @@ namespace ImageSharp.Formats
return BitConverter.ToSingle(buffer, 0);
}
/// <summary>
/// Converts buffer data into a <see cref="double"/> using the correct endianness.
/// </summary>
/// <param name="bytes">The buffer.</param>
/// <param name="offset">The byte offset within the buffer.</param>
/// <returns>The converted value.</returns>
private double ToDouble(byte[] bytes, int offset)
{
byte[] buffer = new byte[8];
@ -495,33 +719,5 @@ namespace ImageSharp.Formats
return BitConverter.ToDouble(buffer, 0);
}
public static uint GetSizeOfData(TiffIfdEntry entry) => SizeOfDataType(entry.Type) * entry.Count;
private static uint SizeOfDataType(TiffType type)
{
switch (type)
{
case TiffType.Byte:
case TiffType.Ascii:
case TiffType.SByte:
case TiffType.Undefined:
return 1u;
case TiffType.Short:
case TiffType.SShort:
return 2u;
case TiffType.Long:
case TiffType.SLong:
case TiffType.Float:
case TiffType.Ifd:
return 4u;
case TiffType.Rational:
case TiffType.SRational:
case TiffType.Double:
return 8u;
default:
return 0u;
}
}
}
}

2
src/ImageSharp/Formats/Tiff/TiffEncoder.cs

@ -33,8 +33,6 @@ namespace ImageSharp.Formats
where TColor : struct, IPixel<TColor>
{
throw new NotImplementedException();
// TiffEncoderCore encode = new TiffEncoderCore(options);
// encode.Encode(image, stream);
}
}
}

14
src/ImageSharp/Formats/Tiff/TiffIfd/TiffIfd.cs

@ -6,13 +6,25 @@
namespace ImageSharp.Formats
{
/// <summary>
/// Data structure for holding details of each TIFF IFD
/// Data structure for holding details of each TIFF IFD.
/// </summary>
internal struct TiffIfd
{
/// <summary>
/// An array of the entries within this IFD.
/// </summary>
public TiffIfdEntry[] Entries;
/// <summary>
/// Offset (in bytes) to the next IFD, or zero if this is the last IFD.
/// </summary>
public uint NextIfdOffset;
/// <summary>
/// Initializes a new instance of the <see cref="TiffIfd" /> class.
/// </summary>
/// <param name="entries">An array of the entries within the IFD.</param>
/// <param name="nextIfdOffset">Offset (in bytes) to the next IFD, or zero if this is the last IFD.</param>
public TiffIfd(TiffIfdEntry[] entries, uint nextIfdOffset)
{
this.Entries = entries;

24
src/ImageSharp/Formats/Tiff/TiffIfd/TiffIfdEntry.cs

@ -6,15 +6,37 @@
namespace ImageSharp.Formats
{
/// <summary>
/// Data structure for holding details of each TIFF IFD entry
/// Data structure for holding details of each TIFF IFD entry.
/// </summary>
internal struct TiffIfdEntry
{
/// <summary>
/// The Tag ID for this entry. See <see cref="TiffTags"/> for typical values.
/// </summary>
public ushort Tag;
/// <summary>
/// The data-type of this entry.
/// </summary>
public TiffType Type;
/// <summary>
/// The number of array items in this entry, or one if only a single value.
/// </summary>
public uint Count;
/// <summary>
/// The raw byte data for this entry.
/// </summary>
public byte[] Value;
/// <summary>
/// Initializes a new instance of the <see cref="TiffIfdEntry" /> class.
/// </summary>
/// <param name="tag">The Tag ID for this entry.</param>
/// <param name="type">The data-type of this entry.</param>
/// <param name="count">The number of array items in this entry.</param>
/// <param name="value">The raw byte data for this entry.</param>
public TiffIfdEntry(ushort tag, TiffType type, uint count, byte[] value)
{
this.Tag = tag;

Loading…
Cancel
Save