Browse Source

Avoid using defaults, because of issue with netcore2.1 in Release mode

pull/1720/head
Brian Popow 5 years ago
parent
commit
522a879a18
  1. 6
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero16TiffColor{TPixel}.cs
  2. 5
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb161616TiffColor{TPixel}.cs
  3. 6
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb16PlanarTiffColor{TPixel}.cs
  4. 6
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero16TiffColor{TPixel}.cs
  5. 7
      src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs

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

@ -25,11 +25,13 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
/// <inheritdoc/> /// <inheritdoc/>
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height) public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
{ {
// Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those,
// we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623
L16 l16 = TiffUtils.L16Default;
var color = default(TPixel); var color = default(TPixel);
color.FromVector4(TiffUtils.Vector4Default);
int offset = 0; int offset = 0;
var l16 = default(L16);
for (int y = top; y < top + height; y++) for (int y = top; y < top + height; y++)
{ {
Span<TPixel> pixelRow = pixels.GetRowSpan(y); Span<TPixel> pixelRow = pixels.GetRowSpan(y);

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

@ -25,11 +25,14 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
/// <inheritdoc/> /// <inheritdoc/>
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height) public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
{ {
// Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those,
// we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623
Rgba64 rgba = TiffUtils.Rgba64Default;
var color = default(TPixel); var color = default(TPixel);
color.FromVector4(TiffUtils.Vector4Default);
int offset = 0; int offset = 0;
var rgba = default(Rgba64);
for (int y = top; y < top + height; y++) for (int y = top; y < top + height; y++)
{ {
Span<TPixel> pixelRow = pixels.GetRowSpan(y); Span<TPixel> pixelRow = pixels.GetRowSpan(y);

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

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Buffers; using System.Buffers;
using System.Numerics;
using SixLabors.ImageSharp.Formats.Tiff.Utils; using SixLabors.ImageSharp.Formats.Tiff.Utils;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -25,14 +26,17 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
/// <inheritdoc/> /// <inheritdoc/>
public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels, int left, int top, int width, int height) public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
{ {
// Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those,
// we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623
Rgba64 rgba = TiffUtils.Rgba64Default;
var color = default(TPixel); var color = default(TPixel);
color.FromVector4(TiffUtils.Vector4Default);
System.Span<byte> redData = data[0].GetSpan(); System.Span<byte> redData = data[0].GetSpan();
System.Span<byte> greenData = data[1].GetSpan(); System.Span<byte> greenData = data[1].GetSpan();
System.Span<byte> blueData = data[2].GetSpan(); System.Span<byte> blueData = data[2].GetSpan();
int offset = 0; int offset = 0;
var rgba = default(Rgba64);
for (int y = top; y < top + height; y++) for (int y = top; y < top + height; y++)
{ {
System.Span<TPixel> pixelRow = pixels.GetRowSpan(y); System.Span<TPixel> pixelRow = pixels.GetRowSpan(y);

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

@ -25,11 +25,13 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
/// <inheritdoc/> /// <inheritdoc/>
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height) public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
{ {
// Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those,
// we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623
L16 l16 = TiffUtils.L16Default;
var color = default(TPixel); var color = default(TPixel);
color.FromVector4(TiffUtils.Vector4Default);
int offset = 0; int offset = 0;
var l16 = default(L16);
for (int y = top; y < top + height; y++) for (int y = top; y < top + height; y++)
{ {
Span<TPixel> pixelRow = pixels.GetRowSpan(y); Span<TPixel> pixelRow = pixels.GetRowSpan(y);

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

@ -3,6 +3,7 @@
using System; using System;
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -13,6 +14,12 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils
/// </summary> /// </summary>
internal static class TiffUtils internal static class TiffUtils
{ {
public static Vector4 Vector4Default { get; } = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
public static Rgba64 Rgba64Default { get; } = new Rgba64(0, 0, 0, 0);
public static L16 L16Default { get; } = new L16(0);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ushort ConvertToShortBigEndian(ReadOnlySpan<byte> buffer) => public static ushort ConvertToShortBigEndian(ReadOnlySpan<byte> buffer) =>
BinaryPrimitives.ReadUInt16BigEndian(buffer); BinaryPrimitives.ReadUInt16BigEndian(buffer);

Loading…
Cancel
Save