Skip to content

Commit e314305

Browse files
committed
Add enum for RecordNumber
1 parent a58d8d5 commit e314305

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Collections.ObjectModel;
88
using System.Text;
9+
using SixLabors.ImageSharp.Metadata.Profiles.IPTC;
910

1011
namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
1112
{
@@ -265,7 +266,7 @@ public void UpdateData()
265266
{
266267
// Envelope Record.
267268
this.Data[i++] = IptcTagMarkerByte;
268-
this.Data[i++] = 1; // Envelope
269+
this.Data[i++] = (byte)IptcRecordNumber.Envelope;
269270
this.Data[i++] = IptcEnvelopeCodedCharacterSet;
270271
this.Data[i++] = (byte)(CodedCharacterSetUtf8Value.Length >> 8);
271272
this.Data[i++] = (byte)CodedCharacterSetUtf8Value.Length;
@@ -293,7 +294,7 @@ public void UpdateData()
293294
// | | | octet 4(most significant bit) always will be 0. |
294295
// +-----------+----------------+---------------------------------------------------------------------------------+
295296
this.Data[i++] = IptcTagMarkerByte;
296-
this.Data[i++] = 2; // Application
297+
this.Data[i++] = (byte)IptcRecordNumber.Application;
297298
this.Data[i++] = (byte)value.Tag;
298299
this.Data[i++] = (byte)(value.Length >> 8);
299300
this.Data[i++] = (byte)value.Length;
@@ -327,7 +328,7 @@ private void Initialize()
327328
bool isValidRecordNumber = recordNumber is >= 1 and <= 9;
328329
var tag = (IptcTag)this.Data[offset++];
329330
bool isValidEntry = isValidTagMarker && isValidRecordNumber;
330-
bool isApplicationRecord = recordNumber == 0x02;
331+
bool isApplicationRecord = recordNumber == (byte)IptcRecordNumber.Application;
331332

332333
uint byteCount = BinaryPrimitives.ReadUInt16BigEndian(this.Data.AsSpan(offset, 2));
333334
offset += 2;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
namespace SixLabors.ImageSharp.Metadata.Profiles.IPTC
5+
{
6+
/// <summary>
7+
/// Enum for the different record types of a IPTC value.
8+
/// </summary>
9+
internal enum IptcRecordNumber : byte
10+
{
11+
/// <summary>
12+
/// A Envelope Record.
13+
/// </summary>
14+
Envelope = 0x01,
15+
16+
/// <summary>
17+
/// A Application Record.
18+
/// </summary>
19+
Application = 0x02
20+
}
21+
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public void Encode_PreservesIptcProfile()
3838
{
3939
// arrange
4040
using var input = new Image<Rgba32>(1, 1);
41-
input.Metadata.IptcProfile = new IptcProfile();
42-
input.Metadata.IptcProfile.SetValue(IptcTag.Byline, "unit_test");
41+
var expectedProfile = new IptcProfile();
42+
expectedProfile.SetValue(IptcTag.Country, "ESPAÑA");
43+
expectedProfile.SetValue(IptcTag.City, "unit-test-city");
44+
input.Metadata.IptcProfile = expectedProfile;
4345

4446
// act
4547
using var memStream = new MemoryStream();
@@ -50,7 +52,7 @@ public void Encode_PreservesIptcProfile()
5052
using var output = Image.Load<Rgba32>(memStream);
5153
IptcProfile actual = output.Metadata.IptcProfile;
5254
Assert.NotNull(actual);
53-
IEnumerable<IptcValue> values = input.Metadata.IptcProfile.Values;
55+
IEnumerable<IptcValue> values = expectedProfile.Values;
5456
Assert.Equal(values, actual.Values);
5557
}
5658

0 commit comments

Comments
 (0)