Browse Source

- Return default values, if compression, photometricInterpretation or rowsPerStrip is not present.

- Throw Exception, if width or height is not set
pull/1570/head
Brian Popow 5 years ago
parent
commit
7152238573
  1. 2
      src/ImageSharp/Formats/Tga/README.md
  2. 5
      src/ImageSharp/Formats/Tiff/Constants/TiffConstants.cs
  3. 1
      src/ImageSharp/Formats/Tiff/README.md
  4. 7
      src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs
  5. 70
      src/ImageSharp/Formats/Tiff/TiffFrameMetadata.cs

2
src/ImageSharp/Formats/README.md → src/ImageSharp/Formats/Tga/README.md

@ -1,4 +1,4 @@
# Encoder/Decoder for true vision targa files
# Encoder/Decoder for true vision targa files
Useful links for reference:

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

@ -35,6 +35,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Constants
/// </summary>
public const ushort HeaderMagicNumber = 42;
/// <summary>
/// RowsPerStrip default value, which is effectively infinity.
/// </summary>
public const int RowsPerStripInfinity = 2147483647;
/// <summary>
/// Size (in bytes) of the TIFF file header.
/// </summary>

1
src/ImageSharp/Formats/Tiff/README.md

@ -32,7 +32,6 @@
- NB: Need to handle this for both planar and chunky data
- If the SampleFormat field is present and not 1 - fail gracefully if you cannot handle this
- Compression=None should treat 16/32-BitsPerSample for all samples as SHORT/LONG (for byte order and padding rows)
- RowsPerStrip should default to 2^32-1 (effectively infinity) to store the image as a single strip
- Check Planar format data - is this encoded as strips in order RGBRGBRGB or RRRGGGBBB?
- Make sure we ignore any strips that are not needed for the image (if too many are present)

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

@ -34,11 +34,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff
/// </summary>
private BufferedReadStream inputStream;
/// <summary>
/// RowsPerStrip default value, which is effectively infinity.
/// </summary>
private const int RowsPerStripInfinity = 2147483647;
/// <summary>
/// Initializes a new instance of the <see cref="TiffDecoderCore" /> class.
/// </summary>
@ -287,7 +282,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff
where TPixel : unmanaged, IPixel<TPixel>
{
// If the rowsPerStrip has the default value, which is effectively infinity. That is, the entire image is one strip.
if (rowsPerStrip == RowsPerStripInfinity)
if (rowsPerStrip == TiffConstants.RowsPerStripInfinity)
{
rowsPerStrip = frame.Height;
}

70
src/ImageSharp/Formats/Tiff/TiffFrameMetadata.cs

@ -54,12 +54,36 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff
/// <summary>
/// Gets the number of columns in the image, i.e., the number of pixels per row.
/// </summary>
public Number Width => this.ExifProfile.GetValue(ExifTag.ImageWidth).Value;
public Number Width
{
get
{
IExifValue<Number> width = this.ExifProfile.GetValue(ExifTag.ImageWidth);
if (width == null)
{
TiffThrowHelper.ThrowImageFormatException("The TIFF image is missing the ImageWidth");
}
return width.Value;
}
}
/// <summary>
/// Gets the number of rows of pixels in the image.
/// </summary>
public Number Height => this.ExifProfile.GetValue(ExifTag.ImageLength).Value;
public Number Height
{
get
{
IExifValue<Number> height = this.ExifProfile.GetValue(ExifTag.ImageLength);
if (height == null)
{
TiffThrowHelper.ThrowImageFormatException("The TIFF image is missing the ImageLength");
}
return height.Value;
}
}
/// <summary>
/// Gets the number of bits per component.
@ -104,12 +128,36 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff
/// Gets the compression scheme used on the image data.
/// </summary>
/// <value>The compression scheme used on the image data.</value>
public TiffCompression Compression => (TiffCompression)this.ExifProfile.GetValue(ExifTag.Compression).Value;
public TiffCompression Compression
{
get
{
IExifValue<ushort> compression = this.ExifProfile.GetValue(ExifTag.Compression);
if (compression == null)
{
return TiffCompression.None;
}
return (TiffCompression)compression.Value;
}
}
/// <summary>
/// Gets the color space of the image data.
/// </summary>
public TiffPhotometricInterpretation PhotometricInterpretation => (TiffPhotometricInterpretation)this.ExifProfile.GetValue(ExifTag.PhotometricInterpretation).Value;
public TiffPhotometricInterpretation PhotometricInterpretation
{
get
{
IExifValue<ushort> photometricInterpretation = this.ExifProfile.GetValue(ExifTag.PhotometricInterpretation);
if (photometricInterpretation == null)
{
return TiffPhotometricInterpretation.WhiteIsZero;
}
return (TiffPhotometricInterpretation)photometricInterpretation.Value;
}
}
/// <summary>
/// Gets the logical order of bits within a byte.
@ -156,7 +204,19 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff
/// <summary>
/// Gets the number of rows per strip.
/// </summary>
public Number RowsPerStrip => this.ExifProfile.GetValue(ExifTag.RowsPerStrip).Value;
public Number RowsPerStrip
{
get
{
IExifValue<Number> rowsPerStrip = this.ExifProfile.GetValue(ExifTag.RowsPerStrip);
if (rowsPerStrip == null)
{
return TiffConstants.RowsPerStripInfinity;
}
return rowsPerStrip.Value;
}
}
/// <summary>
/// Gets for each strip, the number of bytes in the strip after compression.

Loading…
Cancel
Save