Browse Source

refactored ToRgba32() on most pixel types

af/merge-core
Anton Firszov 8 years ago
parent
commit
7caf6642f4
  1. 6
      src/ImageSharp/PixelFormats/Alpha8.cs
  2. 8
      src/ImageSharp/PixelFormats/Argb32.cs
  3. 8
      src/ImageSharp/PixelFormats/Bgr24.cs
  4. 5
      src/ImageSharp/PixelFormats/Bgr565.cs
  5. 8
      src/ImageSharp/PixelFormats/Bgra32.cs
  6. 5
      src/ImageSharp/PixelFormats/Bgra4444.cs
  7. 5
      src/ImageSharp/PixelFormats/Bgra5551.cs
  8. 5
      src/ImageSharp/PixelFormats/Byte4.cs
  9. 5
      src/ImageSharp/PixelFormats/HalfSingle.cs
  10. 5
      src/ImageSharp/PixelFormats/HalfVector2.cs
  11. 5
      src/ImageSharp/PixelFormats/HalfVector4.cs
  12. 18
      src/ImageSharp/PixelFormats/IPixel.cs
  13. 5
      src/ImageSharp/PixelFormats/NormalizedByte2.cs
  14. 5
      src/ImageSharp/PixelFormats/NormalizedByte4.cs
  15. 5
      src/ImageSharp/PixelFormats/NormalizedShort2.cs
  16. 5
      src/ImageSharp/PixelFormats/NormalizedShort4.cs
  17. 5
      src/ImageSharp/PixelFormats/Rg32.cs
  18. 5
      src/ImageSharp/PixelFormats/Rgba1010102.cs
  19. 5
      src/ImageSharp/PixelFormats/RgbaVector.cs
  20. 5
      src/ImageSharp/PixelFormats/Short2.cs
  21. 5
      src/ImageSharp/PixelFormats/Short4.cs

6
src/ImageSharp/PixelFormats/Alpha8.cs

@ -105,7 +105,11 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(0, 0, 0, this.PackedValue); public void ToRgba32(ref Rgba32 dest)
{
dest = default;
dest.A = this.PackedValue;
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

8
src/ImageSharp/PixelFormats/Argb32.cs

@ -250,7 +250,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.R, this.G, this.B, this.A); public void ToRgba32(ref Rgba32 dest)
{
dest.R = this.R;
dest.G = this.G;
dest.B = this.B;
dest.A = this.A;
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

8
src/ImageSharp/PixelFormats/Bgr24.cs

@ -151,7 +151,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.R, this.G, this.B, byte.MaxValue); public void ToRgba32(ref Rgba32 dest)
{
dest.R = this.R;
dest.G = this.G;
dest.B = this.B;
dest.A = byte.MaxValue;
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/Bgr565.cs

@ -113,7 +113,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

8
src/ImageSharp/PixelFormats/Bgra32.cs

@ -206,7 +206,13 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.R, this.G, this.B, this.A); public void ToRgba32(ref Rgba32 dest)
{
dest.R = this.R;
dest.G = this.G;
dest.B = this.B;
dest.A = this.A;
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/Bgra4444.cs

@ -116,7 +116,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/Bgra5551.cs

@ -117,7 +117,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/Byte4.cs

@ -117,7 +117,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/HalfSingle.cs

@ -106,7 +106,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/HalfVector2.cs

@ -117,7 +117,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/HalfVector4.cs

@ -125,7 +125,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

18
src/ImageSharp/PixelFormats/IPixel.cs

@ -100,8 +100,8 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary> /// <summary>
/// Expands the packed representation into an <see cref="Rgba32"/>. /// Expands the packed representation into an <see cref="Rgba32"/>.
/// </summary> /// </summary>
/// <returns>The <see cref="Rgba32"/>.</returns> /// <param name="dest">The reference to the destination <see cref="Rgba32"/> pixel</param>
Rgba32 ToRgba32(); void ToRgba32(ref Rgba32 dest);
/// <summary> /// <summary>
/// Packs the pixel from an <see cref="Rgb48"/> value. /// Packs the pixel from an <see cref="Rgb48"/> value.
@ -115,4 +115,18 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="source">The <see cref="Rgba64"/> value.</param> /// <param name="source">The <see cref="Rgba64"/> value.</param>
void PackFromRgba64(Rgba64 source); void PackFromRgba64(Rgba64 source);
} }
/// <summary>
/// Temporary extension methods for compatibility
/// </summary>
internal static class PixelExtensions
{
public static Rgba32 ToRgba32<TPixel>(this TPixel pixel)
where TPixel : struct, IPixel<TPixel>
{
Rgba32 result = default;
pixel.ToRgba32(ref result);
return result;
}
}
} }

5
src/ImageSharp/PixelFormats/NormalizedByte2.cs

@ -107,7 +107,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/NormalizedByte4.cs

@ -128,7 +128,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/NormalizedShort2.cs

@ -123,7 +123,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/NormalizedShort4.cs

@ -130,7 +130,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/Rg32.cs

@ -111,7 +111,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/Rgba1010102.cs

@ -117,7 +117,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/RgbaVector.cs

@ -152,7 +152,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/Short2.cs

@ -129,7 +129,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

5
src/ImageSharp/PixelFormats/Short4.cs

@ -134,7 +134,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Rgba32 ToRgba32() => new Rgba32(this.ToScaledVector4()); public void ToRgba32(ref Rgba32 dest)
{
dest.PackFromScaledVector4(this.ToScaledVector4());
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

Loading…
Cancel
Save