Skip to content

Commit 522a879

Browse files
committed
Avoid using defaults, because of issue with netcore2.1 in Release mode
1 parent 0ae95f1 commit 522a879

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero16TiffColor{TPixel}.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ internal class BlackIsZero16TiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
2525
/// <inheritdoc/>
2626
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
2727
{
28+
// Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those,
29+
// we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623
30+
L16 l16 = TiffUtils.L16Default;
2831
var color = default(TPixel);
32+
color.FromVector4(TiffUtils.Vector4Default);
2933

3034
int offset = 0;
31-
32-
var l16 = default(L16);
3335
for (int y = top; y < top + height; y++)
3436
{
3537
Span<TPixel> pixelRow = pixels.GetRowSpan(y);

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb161616TiffColor{TPixel}.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ internal class Rgb161616TiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
2525
/// <inheritdoc/>
2626
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
2727
{
28+
// Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those,
29+
// we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623
30+
Rgba64 rgba = TiffUtils.Rgba64Default;
2831
var color = default(TPixel);
32+
color.FromVector4(TiffUtils.Vector4Default);
2933

3034
int offset = 0;
3135

32-
var rgba = default(Rgba64);
3336
for (int y = top; y < top + height; y++)
3437
{
3538
Span<TPixel> pixelRow = pixels.GetRowSpan(y);

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb16PlanarTiffColor{TPixel}.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.Buffers;
5+
using System.Numerics;
56
using SixLabors.ImageSharp.Formats.Tiff.Utils;
67
using SixLabors.ImageSharp.Memory;
78
using SixLabors.ImageSharp.PixelFormats;
@@ -25,14 +26,17 @@ internal class Rgb16PlanarTiffColor<TPixel> : TiffBasePlanarColorDecoder<TPixel>
2526
/// <inheritdoc/>
2627
public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
2728
{
29+
// Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those,
30+
// we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623
31+
Rgba64 rgba = TiffUtils.Rgba64Default;
2832
var color = default(TPixel);
33+
color.FromVector4(TiffUtils.Vector4Default);
2934

3035
System.Span<byte> redData = data[0].GetSpan();
3136
System.Span<byte> greenData = data[1].GetSpan();
3237
System.Span<byte> blueData = data[2].GetSpan();
3338

3439
int offset = 0;
35-
var rgba = default(Rgba64);
3640
for (int y = top; y < top + height; y++)
3741
{
3842
System.Span<TPixel> pixelRow = pixels.GetRowSpan(y);

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero16TiffColor{TPixel}.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ internal class WhiteIsZero16TiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
2525
/// <inheritdoc/>
2626
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
2727
{
28+
// Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those,
29+
// we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623
30+
L16 l16 = TiffUtils.L16Default;
2831
var color = default(TPixel);
32+
color.FromVector4(TiffUtils.Vector4Default);
2933

3034
int offset = 0;
31-
32-
var l16 = default(L16);
3335
for (int y = top; y < top + height; y++)
3436
{
3537
Span<TPixel> pixelRow = pixels.GetRowSpan(y);

src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Buffers.Binary;
6+
using System.Numerics;
67
using System.Runtime.CompilerServices;
78
using SixLabors.ImageSharp.PixelFormats;
89

@@ -13,6 +14,12 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils
1314
/// </summary>
1415
internal static class TiffUtils
1516
{
17+
public static Vector4 Vector4Default { get; } = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
18+
19+
public static Rgba64 Rgba64Default { get; } = new Rgba64(0, 0, 0, 0);
20+
21+
public static L16 L16Default { get; } = new L16(0);
22+
1623
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1724
public static ushort ConvertToShortBigEndian(ReadOnlySpan<byte> buffer) =>
1825
BinaryPrimitives.ReadUInt16BigEndian(buffer);

0 commit comments

Comments
 (0)