Browse Source

renaming, cosmetics

pull/1935/head
Ildar Khayrutdinov 4 years ago
parent
commit
2e219ed69c
  1. 3
      src/ImageSharp/Metadata/Profiles/Exif/ExifConstants.cs
  2. 4
      src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs
  3. 4
      src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs
  4. 18
      src/ImageSharp/Metadata/Profiles/Exif/Values/EncodedString.cs
  5. 6
      src/ImageSharp/Metadata/Profiles/Exif/Values/EncodedStringCode.cs
  6. 14
      src/ImageSharp/Metadata/Profiles/Exif/Values/ExifEncodedString.cs
  7. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs
  8. 2
      tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs

3
src/ImageSharp/Metadata/Profiles/Exif/ExifConstants.cs

@ -32,7 +32,8 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
0x2A
};
public static Encoding DefaultAsciiEncoding => Encoding.UTF8;
// UTF-8 is better than ASCII, UTF-8 encodes the ASCII codes the same way
public static Encoding DefaultEncoding => Encoding.UTF8;
public static Encoding JIS0208Encoding => Encoding.GetEncoding(932);

4
src/ImageSharp/Metadata/Profiles/Exif/ExifReader.cs

@ -252,7 +252,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
buffer = buffer.Slice(0, nullCharIndex);
}
return ExifConstants.DefaultAsciiEncoding.GetString(buffer);
return ExifConstants.DefaultEncoding.GetString(buffer);
}
private object ConvertValue(ExifDataType dataType, ReadOnlySpan<byte> buffer, bool isArray)
@ -364,7 +364,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
if (ExifConstants.TryDetect(buffer, out EncodedStringCode code))
{
string text = ExifConstants.GetEncoding(code).GetString(buffer.Slice(ExifConstants.CharacterCodeBytesLength));
return new EncodedString(text, code);
return new EncodedString(code, text);
}
return buffer.ToArray();

4
src/ImageSharp/Metadata/Profiles/Exif/ExifWriter.cs

@ -276,7 +276,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
if (exifValue.DataType == ExifDataType.Ascii)
{
return (uint)ExifConstants.DefaultAsciiEncoding.GetByteCount((string)value) + 1;
return (uint)ExifConstants.DefaultEncoding.GetByteCount((string)value) + 1;
}
if (value is EncodedString encodedString)
@ -378,7 +378,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
switch (dataType)
{
case ExifDataType.Ascii:
offset = Write(ExifConstants.DefaultAsciiEncoding.GetBytes((string)value), destination, offset);
offset = Write(ExifConstants.DefaultEncoding.GetBytes((string)value), destination, offset);
destination[offset] = 0;
return offset + 1;
case ExifDataType.Byte:

18
src/ImageSharp/Metadata/Profiles/Exif/Values/EncodedString.cs

@ -13,32 +13,32 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
/// <summary>
/// Initializes a new instance of the <see cref="EncodedString" /> struct.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="text">The text value.</param>
public EncodedString(string text)
: this(text, EncodedStringCode.Unicode)
: this(EncodedStringCode.Unicode, text)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="EncodedString" /> struct.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="code">The code.</param>
public EncodedString(string text, EncodedStringCode code)
/// <param name="code">The character code.</param>
/// <param name="text">The text value.</param>
public EncodedString(EncodedStringCode code, string text)
{
this.Text = text;
this.Code = code;
}
/// <summary>
/// Gets the text.
/// Gets the character ode.
/// </summary>
public string Text { get; }
public EncodedStringCode Code { get; }
/// <summary>
/// Gets the character ode.
/// Gets the text.
/// </summary>
public EncodedStringCode Code { get; }
public string Text { get; }
/// <inheritdoc/>
public override bool Equals(object obj) => obj is EncodedString other && this.Equals(other);

6
src/ImageSharp/Metadata/Profiles/Exif/Values/EncodedStringCode.cs

@ -4,17 +4,17 @@
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
/// <summary>
/// The 8-byte The character code enum.
/// The 8-byte character code enum.
/// </summary>
public enum EncodedStringCode
{
/// <summary>
/// The ASCII ITU-T T.50 IA5 character code.
/// The ASCII (ITU-T T.50 IA5) character code.
/// </summary>
ASCII,
/// <summary>
/// The JIS X208-1990 character code.
/// The JIS (X208-1990) character code.
/// </summary>
JIS,

14
src/ImageSharp/Metadata/Profiles/Exif/Values/ExifEncodedString.cs

@ -33,17 +33,13 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
return true;
}
switch (value)
if (value is string stringValue)
{
case string stringValue:
this.Value = new EncodedString(stringValue);
return true;
case byte[] bytes:
this.Value = new EncodedString(ExifConstants.DefaultAsciiEncoding.GetString(bytes));
return true;
default:
return false;
this.Value = new EncodedString(stringValue);
return true;
}
return false;
}
public override IExifValue DeepClone() => new ExifEncodedString(this);

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs

@ -301,7 +301,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
exif.SetValue(ExifTag.XPAuthor, Encoding.GetEncoding("UCS-2").GetBytes("Dan Petitt"));
exif.SetValue(ExifTag.XPTitle, Encoding.GetEncoding("UCS-2").GetBytes("A bit of test metadata for image title"));
exif.SetValue(ExifTag.UserComment, new EncodedString("A bit of normal comment text", EncodedStringCode.ASCII));
exif.SetValue(ExifTag.UserComment, new EncodedString(EncodedStringCode.ASCII, "A bit of normal comment text"));
exif.SetValue(ExifTag.GPSDateStamp, "2022-01-06");
exif.SetValue(ExifTag.XPKeywords, new byte[] { 0x41, 0x53, 0x43, 0x49, 0x49, 00, 00, 00, 0x41, 0x41, 0x41 });

2
tests/ImageSharp.Tests/Metadata/Profiles/Exif/Values/ExifValuesTests.cs

@ -602,7 +602,7 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Exif.Values
[MemberData(nameof(EncodedStringTags))]
public void ExifEncodedStringTests(ExifTag tag)
{
var expected = new EncodedString("test string", EncodedStringCode.JIS);
var expected = new EncodedString(EncodedStringCode.JIS, "test string");
ExifValue value = ExifValues.Create(tag);
Assert.False(value.TrySetValue(123));

Loading…
Cancel
Save