Browse Source

Add enum for RecordNumber

pull/2213/head
Brian Popow 4 years ago
parent
commit
e314305d96
  1. 7
      src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs
  2. 21
      src/ImageSharp/Metadata/Profiles/IPTC/IptcRecordNumber.cs
  3. 8
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.Metadata.cs

7
src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs

@ -6,6 +6,7 @@ using System.Buffers.Binary;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Text; using System.Text;
using SixLabors.ImageSharp.Metadata.Profiles.IPTC;
namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
{ {
@ -265,7 +266,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
{ {
// Envelope Record. // Envelope Record.
this.Data[i++] = IptcTagMarkerByte; this.Data[i++] = IptcTagMarkerByte;
this.Data[i++] = 1; // Envelope this.Data[i++] = (byte)IptcRecordNumber.Envelope;
this.Data[i++] = IptcEnvelopeCodedCharacterSet; this.Data[i++] = IptcEnvelopeCodedCharacterSet;
this.Data[i++] = (byte)(CodedCharacterSetUtf8Value.Length >> 8); this.Data[i++] = (byte)(CodedCharacterSetUtf8Value.Length >> 8);
this.Data[i++] = (byte)CodedCharacterSetUtf8Value.Length; this.Data[i++] = (byte)CodedCharacterSetUtf8Value.Length;
@ -293,7 +294,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
// | | | octet 4(most significant bit) always will be 0. | // | | | octet 4(most significant bit) always will be 0. |
// +-----------+----------------+---------------------------------------------------------------------------------+ // +-----------+----------------+---------------------------------------------------------------------------------+
this.Data[i++] = IptcTagMarkerByte; this.Data[i++] = IptcTagMarkerByte;
this.Data[i++] = 2; // Application this.Data[i++] = (byte)IptcRecordNumber.Application;
this.Data[i++] = (byte)value.Tag; this.Data[i++] = (byte)value.Tag;
this.Data[i++] = (byte)(value.Length >> 8); this.Data[i++] = (byte)(value.Length >> 8);
this.Data[i++] = (byte)value.Length; this.Data[i++] = (byte)value.Length;
@ -327,7 +328,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
bool isValidRecordNumber = recordNumber is >= 1 and <= 9; bool isValidRecordNumber = recordNumber is >= 1 and <= 9;
var tag = (IptcTag)this.Data[offset++]; var tag = (IptcTag)this.Data[offset++];
bool isValidEntry = isValidTagMarker && isValidRecordNumber; bool isValidEntry = isValidTagMarker && isValidRecordNumber;
bool isApplicationRecord = recordNumber == 0x02; bool isApplicationRecord = recordNumber == (byte)IptcRecordNumber.Application;
uint byteCount = BinaryPrimitives.ReadUInt16BigEndian(this.Data.AsSpan(offset, 2)); uint byteCount = BinaryPrimitives.ReadUInt16BigEndian(this.Data.AsSpan(offset, 2));
offset += 2; offset += 2;

21
src/ImageSharp/Metadata/Profiles/IPTC/IptcRecordNumber.cs

@ -0,0 +1,21 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Metadata.Profiles.IPTC
{
/// <summary>
/// Enum for the different record types of a IPTC value.
/// </summary>
internal enum IptcRecordNumber : byte
{
/// <summary>
/// A Envelope Record.
/// </summary>
Envelope = 0x01,
/// <summary>
/// A Application Record.
/// </summary>
Application = 0x02
}
}

8
tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.Metadata.cs

@ -38,8 +38,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
// arrange // arrange
using var input = new Image<Rgba32>(1, 1); using var input = new Image<Rgba32>(1, 1);
input.Metadata.IptcProfile = new IptcProfile(); var expectedProfile = new IptcProfile();
input.Metadata.IptcProfile.SetValue(IptcTag.Byline, "unit_test"); expectedProfile.SetValue(IptcTag.Country, "ESPAÑA");
expectedProfile.SetValue(IptcTag.City, "unit-test-city");
input.Metadata.IptcProfile = expectedProfile;
// act // act
using var memStream = new MemoryStream(); using var memStream = new MemoryStream();
@ -50,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
using var output = Image.Load<Rgba32>(memStream); using var output = Image.Load<Rgba32>(memStream);
IptcProfile actual = output.Metadata.IptcProfile; IptcProfile actual = output.Metadata.IptcProfile;
Assert.NotNull(actual); Assert.NotNull(actual);
IEnumerable<IptcValue> values = input.Metadata.IptcProfile.Values; IEnumerable<IptcValue> values = expectedProfile.Values;
Assert.Equal(values, actual.Values); Assert.Equal(values, actual.Values);
} }

Loading…
Cancel
Save