public void CanFinalizeShortTag() { var artist = "Bob"; var tag = new Tag <char> { DataType = TagDataType.ASCII, ID = (ushort)BaselineTags.Artist, Length = (uint)artist.Length + 1, Values = artist.ToASCIIArray() }; using (var stream = new TiffStreamWriter()) { stream.WriteDWord(1); stream.WriteTagPlaceholder(tag); stream.FinalizeTag(tag); var data = stream.ToArray(); Assert.Equal(4u, tag.Offset); Assert.Equal(4u, tag.Length); Assert.Equal(16, data.Length); Assert.Equal(artist, Encoding.ASCII.GetString(tag.RawValue).Trim('\0')); } }
public void CanWriteTagPlaceholder() { var tag = new Tag { DataType = TagDataType.Short, ID = (ushort)BaselineTags.BitsPerSample, Length = 1 }; using (var stream = new TiffStreamWriter()) { stream.WriteTagPlaceholder(tag); var data = stream.ToArray(); Assert.True(data.SequenceEqual(new byte[] { 0x02, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })); } using (var stream = new TiffStreamWriter(forceBigEndian: true)) { stream.WriteTagPlaceholder(tag); var data = stream.ToArray(); Assert.True(data.SequenceEqual(new byte[] { 0x01, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 })); } }
public void CanFinalizeLongTag() { var artist = "Ansel Adams"; var tag = new Tag <char> { DataType = TagDataType.ASCII, ID = (ushort)BaselineTags.Artist, Length = (uint)artist.Length + 1, Values = artist.ToASCIIArray() }; using (var stream = new TiffStreamWriter()) { stream.WriteDWord(1); stream.WriteTagPlaceholder(tag); stream.FinalizeTag(tag); var data = stream.ToArray(); Assert.Equal(4u, tag.Offset); Assert.Equal(12u, tag.Length); Assert.Equal(28, data.Length); Assert.True(tag.RawValue.SequenceEqual(BitConverter.GetBytes(16u))); } }
public void WriteTagPlaceholderUpdatesOffset() { var tag = new Tag { DataType = TagDataType.ASCII, ID = (ushort)BaselineTags.Artist, Length = 1 }; using (var stream = new TiffStreamWriter()) { stream.WriteTagPlaceholder(tag); stream.WriteTagPlaceholder(tag); Assert.Equal(24, stream.Length); Assert.Equal(12u, tag.Offset); } }