Skip to content

Commit

Permalink
Merge pull request #405 from drewnoakes/reduce-reader-get-byte-overhead
Browse files Browse the repository at this point in the history
Reduce overhead reading byte/sbyte arrays from IndexedReader
  • Loading branch information
drewnoakes authored Feb 6, 2024
2 parents f48737f + f2c7446 commit 1837bff
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions MetadataExtractor/Formats/Tiff/TiffReader.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 System.Runtime.InteropServices;

namespace MetadataExtractor.Formats.Tiff
{
/// <summary>
Expand Down Expand Up @@ -384,8 +386,8 @@ private static void ProcessTag(ITiffHandler handler, int tagId, int tagValueOffs
else
{
var array = new sbyte[componentCount];
for (var i = 0; i < componentCount; i++)
array[i] = reader.GetSByte(tagValueOffset + i);
var bytes = MemoryMarshal.Cast<sbyte, byte>(array);
reader.GetBytes(tagValueOffset, bytes);
handler.SetInt8SArray(tagId, array);
}
break;
Expand All @@ -399,8 +401,7 @@ private static void ProcessTag(ITiffHandler handler, int tagId, int tagValueOffs
else
{
var array = new byte[componentCount];
for (var i = 0; i < componentCount; i++)
array[i] = reader.GetByte(tagValueOffset + i);
reader.GetBytes(tagValueOffset, array);
handler.SetInt8UArray(tagId, array);
}
break;
Expand Down

0 comments on commit 1837bff

Please sign in to comment.