mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.4 KiB
78 lines
2.4 KiB
// Copyright (c) Six Labors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using SixLabors.ImageSharp.Formats.Tiff.Constants;
|
|
using SixLabors.ImageSharp.Memory;
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Tiff
|
|
{
|
|
internal class EntryReader : BaseExifReader
|
|
{
|
|
public EntryReader(Stream stream, ByteOrder byteOrder, MemoryAllocator allocator)
|
|
: base(stream, allocator) =>
|
|
this.IsBigEndian = byteOrder == ByteOrder.BigEndian;
|
|
|
|
public List<IExifValue> Values { get; } = new();
|
|
|
|
public ulong NextIfdOffset { get; private set; }
|
|
|
|
public void ReadTags(bool isBigTiff, ulong ifdOffset)
|
|
{
|
|
if (!isBigTiff)
|
|
{
|
|
this.ReadValues(this.Values, (uint)ifdOffset);
|
|
this.NextIfdOffset = this.ReadUInt32();
|
|
|
|
this.ReadSubIfd(this.Values);
|
|
}
|
|
else
|
|
{
|
|
this.ReadValues64(this.Values, ifdOffset);
|
|
this.NextIfdOffset = this.ReadUInt64();
|
|
|
|
//// this.ReadSubIfd64(this.Values);
|
|
}
|
|
}
|
|
|
|
public void ReadBigValues() => this.ReadBigValues(this.Values);
|
|
}
|
|
|
|
internal class HeaderReader : BaseExifReader
|
|
{
|
|
public HeaderReader(Stream stream, ByteOrder byteOrder)
|
|
: base(stream, null) =>
|
|
this.IsBigEndian = byteOrder == ByteOrder.BigEndian;
|
|
|
|
public bool IsBigTiff { get; private set; }
|
|
|
|
public ulong FirstIfdOffset { get; private set; }
|
|
|
|
public void ReadFileHeader()
|
|
{
|
|
ushort magic = this.ReadUInt16();
|
|
if (magic == TiffConstants.HeaderMagicNumber)
|
|
{
|
|
this.IsBigTiff = false;
|
|
this.FirstIfdOffset = this.ReadUInt32();
|
|
return;
|
|
}
|
|
else if (magic == TiffConstants.BigTiffHeaderMagicNumber)
|
|
{
|
|
this.IsBigTiff = true;
|
|
|
|
ushort bytesize = this.ReadUInt16();
|
|
ushort reserve = this.ReadUInt16();
|
|
if (bytesize == TiffConstants.BigTiffBytesize && reserve == 0)
|
|
{
|
|
this.FirstIfdOffset = this.ReadUInt64();
|
|
return;
|
|
}
|
|
}
|
|
|
|
TiffThrowHelper.ThrowInvalidHeader();
|
|
}
|
|
}
|
|
}
|
|
|