Skip to content

Commit d3f8157

Browse files
committed
WIP
1 parent a760533 commit d3f8157

File tree

6 files changed

+780
-742
lines changed

6 files changed

+780
-742
lines changed

MetadataExtractor/ExifTags.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static class ExifTags
4848
/// <remarks>
4949
/// Usually this value is '8,8,8'.
5050
/// </remarks>
51-
public static readonly TiffUInt16ArrayTag BitsPerSample = new(0x0102, "Bits Per Sample", expectedCount: 3, describer: static (ints, _) => ints.Length == 3 ? $"{string.Join(",", ints)} bits/component/pixel" : null);
51+
public static readonly TiffUInt16ArrayTag BitsPerSample = new(0x0102, "Bits Per Sample", expectedCount: 3, describer: static (values, _) => values.Length == 3 ? $"{string.Join(",", values)} bits/component/pixel" : null);
5252

5353
public static readonly TiffMappedUInt16Tag Compression = new(0x0103, "Compression", new Dictionary<int, string>
5454
{
@@ -231,13 +231,13 @@ public static class ExifTags
231231
/// <summary>The matrix coefficients used for transformation from RGB to YCbCr image data.</summary>
232232
public static readonly TiffURationalArrayTag YCbCrCoefficients = new(0x0211, "YCbCr Coefficients", 3);
233233

234-
public static readonly TiffUInt16ArrayTag YCbCrSubsampling = new(0x0212, "YCbCr Subsampling", 2, (ints, provider) =>
234+
public static readonly TiffUInt16ArrayTag YCbCrSubsampling = new(0x0212, "YCbCr Subsampling", 2, (values, _) =>
235235
{
236-
if (ints.Length == 2)
236+
if (values.Length == 2)
237237
{
238-
if (ints[0] == 2 && ints[1] == 1)
238+
if (values[0] == 2 && values[1] == 1)
239239
return "YCbCr4:2:2";
240-
if (ints[0] == 2 && ints[1] == 2)
240+
if (values[0] == 2 && values[1] == 2)
241241
return "YCbCr4:2:0";
242242
}
243243
return null;
@@ -250,8 +250,8 @@ public static class ExifTags
250250
});
251251

252252
public static readonly TiffURationalArrayTag ReferenceBlackWhite = new(0x0214, "Reference Black White", 6,
253-
(values, provider) => values.Length == 6
254-
? string.Format(provider, "[{0},{1},{2}] [{3},{4},{5}]", values[0], values[1], values[2], values[3], values[4], values[5])
253+
(values, format) => values.Length == 6
254+
? string.Format(format, "[{0},{1},{2}] [{3},{4},{5}]", values[0], values[1], values[2], values[3], values[4], values[5])
255255
: null);
256256

257257
public static readonly TiffUInt16Tag RelatedImageFileFormat = new(0x1000, "Related Image File Format");
@@ -274,7 +274,7 @@ public static class ExifTags
274274

275275
/// <summary>Exposure time (reciprocal of shutter speed).</summary>
276276
/// <remarks>Unit is second.</remarks>
277-
public static readonly TiffURationalTag ExposureTime = new(0x829A, "Exposure Time", (value, format) => $"{value.ToSimpleString()} sec");
277+
public static readonly TiffURationalTag ExposureTime = new(0x829A, "Exposure Time", (value, _) => $"{value.ToSimpleString()} sec");
278278

279279
/// <summary>The actual F-number(F-stop) of lens when the image was taken.</summary>
280280
public static readonly TiffURationalTag FNumber = new(0x829D, "F-Number",
@@ -412,7 +412,7 @@ public static class ExifTags
412412

413413
/// <summary>The distance autofocus focused to.</summary>
414414
/// <remarks>Tends to be less accurate as distance increases.</remarks>
415-
public static readonly TiffRationalTag SubjectDistance = new(0x9206, "Subject Distance", (value, format) => $"{value.ToDouble():0.0##} metres");
415+
public static readonly TiffRationalTag SubjectDistance = new(0x9206, "Subject Distance", (value, _) => $"{value.ToDouble():0.0##} metres");
416416

417417
/// <summary>Exposure metering method.</summary>
418418
public static readonly TiffMappedUInt16Tag MeteringMode = new(0x9207, "Metering Mode", new Dictionary<int, string>
@@ -527,7 +527,7 @@ public static class ExifTags
527527
/// The component count for this tag includes all of the bytes needed for the makernote.
528528
/// </remarks>
529529
// TODO should this be public? probably shouldn't be storing the byte array for makernotes, unless it's unknown (in which case it's in a makernote directory)
530-
public static readonly TiffByteArrayTag Makernote = new TiffByteArrayTag(0x927C, "Makernote");
530+
public static readonly TiffUInt8ArrayTag Makernote = new TiffUInt8ArrayTag(0x927C, "Makernote");
531531

532532
public static readonly TiffStringTag UserComment = new(0x9286, "User Comment", DescribeUserComment);
533533

@@ -538,19 +538,19 @@ public static class ExifTags
538538
public static readonly TiffUInt16Tag SubsecondTimeDigitized = new(0x9292, "Subsecond Time Digitized");
539539

540540
/// <summary>The image title, as used by Windows XP.</summary>
541-
public static readonly TiffStringTag WinTitle = new(0x9C9B, "Windows XP Title", Encoding.Unicode);
541+
public static readonly TiffStringTag WinTitle = new(0x9C9B, "Windows XP Title", expectedEncoding: Encoding.Unicode);
542542

543543
/// <summary>The image comment, as used by Windows XP.</summary>
544-
public static readonly TiffStringTag WinComment = new(0x9C9C, "Windows XP Comment", Encoding.Unicode);
544+
public static readonly TiffStringTag WinComment = new(0x9C9C, "Windows XP Comment", expectedEncoding: Encoding.Unicode);
545545

546546
/// <summary>The image author, as used by Windows XP (called Artist in the Windows shell).</summary>
547-
public static readonly TiffStringTag WinAuthor = new(0x9C9D, "Windows XP Author", Encoding.Unicode);
547+
public static readonly TiffStringTag WinAuthor = new(0x9C9D, "Windows XP Author", expectedEncoding: Encoding.Unicode);
548548

549549
/// <summary>The image keywords, as used by Windows XP.</summary>
550-
public static readonly TiffStringTag WinKeywords = new(0x9C9E, "Windows XP Keywords", Encoding.Unicode);
550+
public static readonly TiffStringTag WinKeywords = new(0x9C9E, "Windows XP Keywords", expectedEncoding: Encoding.Unicode);
551551

552552
/// <summary>The image subject, as used by Windows XP.</summary>
553-
public static readonly TiffStringTag WinSubject = new(0x9C9F, "Windows XP Subject", Encoding.Unicode);
553+
public static readonly TiffStringTag WinSubject = new(0x9C9F, "Windows XP Subject", expectedEncoding: Encoding.Unicode);
554554

555555
public static readonly TiffUInt16ArrayTag FlashpixVersion = new(0xA000, "Flashpix Version", expectedCount: 4, describer: (values, p) => DescribeVersion(values, 2));
556556

@@ -818,7 +818,7 @@ public static class ExifTags
818818

819819
private static string DescribeFocalLength(double mm, IFormatProvider? format) => string.Format(format, "{0:0.#} mm", mm);
820820

821-
private static string DescribePixels(int i, IFormatProvider? format) => string.Format(format, "{0} pixel{1}", i, i == 1 ? "" : "s");
821+
private static string DescribePixels(ushort i, IFormatProvider? format) => string.Format(format, "{0} pixel{1}", i, i == 1 ? "" : "s");
822822

823823
private static string? DescribeVersion(IReadOnlyList<int>? components, int majorDigits)
824824
{
@@ -840,7 +840,7 @@ public static class ExifTags
840840
return version.ToString();
841841
}
842842

843-
private static string? DescribeUserComment(byte[] bytes)
843+
private static string? DescribeUserComment(byte[] bytes, IFormatProvider? format)
844844
{
845845
if (bytes.Length == 0)
846846
return string.Empty;
@@ -862,12 +862,10 @@ public static class ExifTags
862862
if (bytes.Length >= 10)
863863
{
864864
// TODO no guarantee bytes after the UTF8 name are valid UTF8 -- only read as many as needed
865-
var firstTenBytesString = Encoding.UTF8.GetString(bytes, 0, 10);
865+
string firstTenBytesString = Encoding.UTF8.GetString(bytes, 0, 10);
866866
// try each encoding name
867-
foreach (var pair in encodingMap)
867+
foreach ((string? encodingName, Encoding? encoding) in encodingMap)
868868
{
869-
var encodingName = pair.Key;
870-
var encoding = pair.Value;
871869
if (firstTenBytesString.StartsWith(encodingName))
872870
{
873871
// skip any null or blank characters commonly present after the encoding name, up to a limit of 10 from the start

MetadataExtractor/Formats/Png/PngChunkReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class PngChunkReader
1313

1414
/// <exception cref="PngProcessingException"/>
1515
/// <exception cref="System.IO.IOException"/>
16-
public IEnumerable<PngChunk> Extract(SequentialReader reader, ICollection<PngChunkType>? desiredChunkTypes)
16+
public IReadOnlyList<PngChunk> Extract(SequentialReader reader, ICollection<PngChunkType>? desiredChunkTypes)
1717
{
1818
//
1919
// PNG DATA STREAM

MetadataExtractor/MetadataExtractor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Camera manufacturer specific support exists for Agfa, Canon, Casio, DJI, Epson,
2727
</ItemGroup>
2828

2929
<ItemGroup>
30+
<PackageReference Include="System.Memory" Version="4.5.4" />
3031
<PackageReference Include="XmpCore" Version="6.1.10.1" />
3132
</ItemGroup>
3233

0 commit comments

Comments
 (0)