Skip to content

Commit

Permalink
Merge branch 'main' into cq6
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon authored Feb 19, 2024
2 parents 51ff3ee + 3ee6d56 commit 17327ad
Show file tree
Hide file tree
Showing 29 changed files with 541 additions and 366 deletions.
155 changes: 75 additions & 80 deletions MetadataExtractor/Formats/Exif/ExifTiffHandler.cs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion MetadataExtractor/Formats/Flir/FlirReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ public IEnumerable<Directory> Extract(IndexedReader reader)
var tm = dateTimeReader.GetUInt32();
var ss = dateTimeReader.GetUInt32() & 0xffff;
var tz = dateTimeReader.GetInt16();
directory.Set(TagDateTimeOriginal, new DateTimeOffset(DateUtil.FromUnixTime(tm - tz * 60).AddSeconds(ss / 1000d), TimeSpan.FromMinutes(tz)));
directory.Set(TagDateTimeOriginal, new DateTimeOffset(
dateTime: DateUtil.FromUnixTime(tm - tz * 60).AddSeconds(ss / 1000d),
offset: TimeSpan.FromMinutes(tz)));

directory.Set(TagFocusStepCount, reader2.GetUInt16(TagFocusStepCount));
directory.Set(TagFocusDistance, reader2.GetFloat32(TagFocusDistance));
Expand Down
2 changes: 1 addition & 1 deletion MetadataExtractor/Formats/Gif/GifReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private static byte[] GatherBytes(SequentialReader reader, byte firstLength)

while (length > 0)
{
reader.GetBytes(buffer.AsSpan().Slice(0, length));
reader.GetBytes(buffer.AsSpan(0, length));

stream.Write(buffer, 0, length);

Expand Down
2 changes: 1 addition & 1 deletion MetadataExtractor/Formats/Jpeg/JpegSegmentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public static bool CanContainMetadata(this JpegSegmentType type)

/// <summary>Gets JPEG segment types that might contain metadata.</summary>
#if NET5_0_OR_GREATER
public static IReadOnlyList<JpegSegmentType> CanContainMetadataTypes { get; } = Enum.GetValues<JpegSegmentType>().Cast<JpegSegmentType>().Where(type => type.CanContainMetadata()).ToList();
public static IReadOnlyList<JpegSegmentType> CanContainMetadataTypes { get; } = Enum.GetValues<JpegSegmentType>().Where(type => type.CanContainMetadata()).ToList();
#else
public static IReadOnlyList<JpegSegmentType> CanContainMetadataTypes { get; } = Enum.GetValues(typeof(JpegSegmentType)).Cast<JpegSegmentType>().Where(type => type.CanContainMetadata()).ToList();
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ void MoovHandler(AtomCallbackArgs a)
case "uuid":
{
ReadOnlySpan<byte> cr3 = [0x85, 0xc0, 0xb6, 0x87, 0x82, 0x0f, 0x11, 0xe0, 0x81, 0x11, 0xf4, 0xce, 0x46, 0x2b, 0x6a, 0x48];
var uuid = a.Reader.GetBytes(cr3.Length);
if (cr3.SequenceEqual(uuid))
Span<byte> actual = stackalloc byte[cr3.Length];
a.Reader.GetBytes(actual);
if (cr3.SequenceEqual(actual))
{
QuickTimeReader.ProcessAtoms(stream, UuidHandler, a.BytesLeft);
}
Expand Down
16 changes: 3 additions & 13 deletions MetadataExtractor/Formats/QuickTime/QuickTimeReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using MetadataExtractor.Formats.Iso14496;

namespace MetadataExtractor.Formats.QuickTime
{
/// <summary>
Expand Down Expand Up @@ -43,19 +45,7 @@ public sealed class AtomCallbackArgs(uint type, long size, Stream stream, long s
/// <summary>
/// Gets the string representation of this atom's type.
/// </summary>
public string TypeString
{
get
{
var bytes = BitConverter.GetBytes(Type);
Array.Reverse(bytes);
#if NETSTANDARD1_3
return Encoding.UTF8.GetString(bytes);
#else
return Encoding.ASCII.GetString(bytes);
#endif
}
}
public string TypeString => TypeStringConverter.ToTypeString(Type);

/// <summary>
/// Computes the number of bytes remaining in the atom, given the <see cref="Stream"/> position.
Expand Down
12 changes: 7 additions & 5 deletions MetadataExtractor/Formats/QuickTime/QuickTimeReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ public static string Get4ccString(this SequentialReader reader)
// https://en.wikipedia.org/wiki/FourCC

Span<byte> bytes = stackalloc byte[4];
Span<char> chars = stackalloc char[4];

reader.GetBytes(bytes);

// NOTE we cannot just use Encoding.ASCII here, as that can replace certain non-printable characters with '?'
chars[0] = (char)bytes[0];
chars[1] = (char)bytes[1];
chars[2] = (char)bytes[2];
chars[3] = (char)bytes[3];
Span<char> chars =
[
(char)bytes[0],
(char)bytes[1],
(char)bytes[2],
(char)bytes[3]
];

#if NET462 || NETSTANDARD1_3
fixed (char* pChars = chars)
Expand Down
30 changes: 15 additions & 15 deletions MetadataExtractor/Formats/Tiff/TiffDataFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ public enum TiffDataFormatCode : ushort
public sealed class TiffDataFormat
{
#pragma warning disable format
public static readonly TiffDataFormat Int8U = new("BYTE", TiffDataFormatCode.Int8U, 1);
public static readonly TiffDataFormat String = new("STRING", TiffDataFormatCode.String, 1);
public static readonly TiffDataFormat Int16U = new("USHORT", TiffDataFormatCode.Int16U, 2);
public static readonly TiffDataFormat Int32U = new("ULONG", TiffDataFormatCode.Int32U, 4);
public static readonly TiffDataFormat RationalU = new("URATIONAL", TiffDataFormatCode.RationalU, 8);
public static readonly TiffDataFormat Int8S = new("SBYTE", TiffDataFormatCode.Int8S, 1);
public static readonly TiffDataFormat Undefined = new("UNDEFINED", TiffDataFormatCode.Undefined, 1);
public static readonly TiffDataFormat Int16S = new("SSHORT", TiffDataFormatCode.Int16S, 2);
public static readonly TiffDataFormat Int32S = new("SLONG", TiffDataFormatCode.Int32S, 4);
public static readonly TiffDataFormat RationalS = new("SRATIONAL", TiffDataFormatCode.RationalS, 8);
public static readonly TiffDataFormat Single = new("SINGLE", TiffDataFormatCode.Single, 4);
public static readonly TiffDataFormat Double = new("DOUBLE", TiffDataFormatCode.Double, 8);
public static readonly TiffDataFormat Int8U = new("BYTE", TiffDataFormatCode.Int8U, componentSizeBytes: 1);
public static readonly TiffDataFormat String = new("STRING", TiffDataFormatCode.String, componentSizeBytes: 1);
public static readonly TiffDataFormat Int16U = new("USHORT", TiffDataFormatCode.Int16U, componentSizeBytes: 2);
public static readonly TiffDataFormat Int32U = new("ULONG", TiffDataFormatCode.Int32U, componentSizeBytes: 4);
public static readonly TiffDataFormat RationalU = new("URATIONAL", TiffDataFormatCode.RationalU, componentSizeBytes: 8);
public static readonly TiffDataFormat Int8S = new("SBYTE", TiffDataFormatCode.Int8S, componentSizeBytes: 1);
public static readonly TiffDataFormat Undefined = new("UNDEFINED", TiffDataFormatCode.Undefined, componentSizeBytes: 1);
public static readonly TiffDataFormat Int16S = new("SSHORT", TiffDataFormatCode.Int16S, componentSizeBytes: 2);
public static readonly TiffDataFormat Int32S = new("SLONG", TiffDataFormatCode.Int32S, componentSizeBytes: 4);
public static readonly TiffDataFormat RationalS = new("SRATIONAL", TiffDataFormatCode.RationalS, componentSizeBytes: 8);
public static readonly TiffDataFormat Single = new("SINGLE", TiffDataFormatCode.Single, componentSizeBytes: 4);
public static readonly TiffDataFormat Double = new("DOUBLE", TiffDataFormatCode.Double, componentSizeBytes: 8);

// From BigTIFF
public static readonly TiffDataFormat Int64U = new("ULONG8", TiffDataFormatCode.Int64U, 8);
public static readonly TiffDataFormat Int64S = new("SLONG8", TiffDataFormatCode.Int64S, 8);
public static readonly TiffDataFormat Ifd8 = new("IFD8", TiffDataFormatCode.Ifd8, 8);
public static readonly TiffDataFormat Int64U = new("ULONG8", TiffDataFormatCode.Int64U, componentSizeBytes: 8);
public static readonly TiffDataFormat Int64S = new("SLONG8", TiffDataFormatCode.Int64S, componentSizeBytes: 8);
public static readonly TiffDataFormat Ifd8 = new("IFD8", TiffDataFormatCode.Ifd8, componentSizeBytes: 8);
#pragma warning restore format

public static TiffDataFormat? FromTiffFormatCode(TiffDataFormatCode tiffFormatCode, bool isBigTiff)
Expand Down
Loading

0 comments on commit 17327ad

Please sign in to comment.