mirror of https://github.com/SixLabors/ImageSharp
6 changed files with 242 additions and 107 deletions
@ -0,0 +1,130 @@ |
|||
// <auto-generated />
|
|||
|
|||
// <copyright file="PixelOperations{TPixel}.Generated.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System; |
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
using ImageSharp.Memory; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <content>
|
|||
/// Provides optimized overrides for bulk operations.
|
|||
/// </content>
|
|||
public partial struct Rgba32 |
|||
{ |
|||
internal partial class PixelOperations : PixelOperations<Rgba32> |
|||
{ |
|||
|
|||
/// <inheritdoc />
|
|||
internal override void PackFromRgb24(Span<Rgb24> source, Span<Rgba32> destPixels, int count) |
|||
{ |
|||
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|||
|
|||
ref Rgb24 sourceRef = ref source.DangerousGetPinnableReference(); |
|||
ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference(); |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); |
|||
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); |
|||
Unsafe.As<Rgba32, Rgb24>(ref dp) = sp; dp.A = 255; |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
internal override void ToRgb24(Span<Rgba32> sourcePixels, Span<Rgb24> dest, int count) |
|||
{ |
|||
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count); |
|||
|
|||
ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference(); |
|||
ref Rgb24 destRef = ref dest.DangerousGetPinnableReference(); |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); |
|||
ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); |
|||
dp = Unsafe.As<Rgba32, Rgb24>(ref sp); |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
internal override void PackFromBgr24(Span<Bgr24> source, Span<Rgba32> destPixels, int count) |
|||
{ |
|||
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|||
|
|||
ref Bgr24 sourceRef = ref source.DangerousGetPinnableReference(); |
|||
ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference(); |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); |
|||
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); |
|||
dp.Bgr = sp; dp.A = 255; |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
internal override void ToBgr24(Span<Rgba32> sourcePixels, Span<Bgr24> dest, int count) |
|||
{ |
|||
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count); |
|||
|
|||
ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference(); |
|||
ref Bgr24 destRef = ref dest.DangerousGetPinnableReference(); |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); |
|||
ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); |
|||
dp = sp.Bgr; |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
internal override void PackFromBgra32(Span<Bgra32> source, Span<Rgba32> destPixels, int count) |
|||
{ |
|||
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|||
|
|||
ref Bgra32 sourceRef = ref source.DangerousGetPinnableReference(); |
|||
ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference(); |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); |
|||
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); |
|||
dp = sp.ToRgba32(); |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
internal override void ToBgra32(Span<Rgba32> sourcePixels, Span<Bgra32> dest, int count) |
|||
{ |
|||
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count); |
|||
|
|||
ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference(); |
|||
ref Bgra32 destRef = ref dest.DangerousGetPinnableReference(); |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); |
|||
ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); |
|||
dp = sp.ToBgra32(); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,99 @@ |
|||
<# |
|||
// <copyright file="Rgba32.PixelOperations.Generated.tt" company="James Jackson-South"> |
|||
// Copyright (c) James Jackson-South and contributors. |
|||
// Licensed under the Apache License, Version 2.0. |
|||
// </copyright> |
|||
#> |
|||
<#@ template debug="false" hostspecific="false" language="C#" #> |
|||
<#@ assembly name="System.Core" #> |
|||
<#@ import namespace="System.Linq" #> |
|||
<#@ import namespace="System.Text" #> |
|||
<#@ import namespace="System.Collections.Generic" #> |
|||
<#@ output extension=".cs" #> |
|||
<# |
|||
|
|||
void GeneratePackFromMethod(string pixelType, string converterCode) |
|||
{ |
|||
#> |
|||
|
|||
/// <inheritdoc /> |
|||
internal override void PackFrom<#=pixelType#>(Span<<#=pixelType#>> source, Span<Rgba32> destPixels, int count) |
|||
{ |
|||
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|||
|
|||
ref <#=pixelType#> sourceRef = ref source.DangerousGetPinnableReference(); |
|||
ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference(); |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
ref <#=pixelType#> sp = ref Unsafe.Add(ref sourceRef, i); |
|||
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); |
|||
<#=converterCode#> |
|||
} |
|||
} |
|||
|
|||
<# |
|||
} |
|||
|
|||
void GenerateConvertToMethod(string pixelType, string converterCode) |
|||
{ |
|||
#> |
|||
|
|||
/// <inheritdoc /> |
|||
internal override void To<#=pixelType#>(Span<Rgba32> sourcePixels, Span<<#=pixelType#>> dest, int count) |
|||
{ |
|||
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count); |
|||
|
|||
ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference(); |
|||
ref <#=pixelType#> destRef = ref dest.DangerousGetPinnableReference(); |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); |
|||
ref <#=pixelType#> dp = ref Unsafe.Add(ref destRef, i); |
|||
<#=converterCode#> |
|||
} |
|||
} |
|||
|
|||
<# |
|||
} |
|||
|
|||
#> |
|||
// <auto-generated /> |
|||
|
|||
// <copyright file="PixelOperations{TPixel}.Generated.cs" company="James Jackson-South"> |
|||
// Copyright (c) James Jackson-South and contributors. |
|||
// Licensed under the Apache License, Version 2.0. |
|||
// </copyright> |
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System; |
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
using ImageSharp.Memory; |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
/// <content> |
|||
/// Provides optimized overrides for bulk operations. |
|||
/// </content> |
|||
public partial struct Rgba32 |
|||
{ |
|||
internal partial class PixelOperations : PixelOperations<Rgba32> |
|||
{ |
|||
<# |
|||
GeneratePackFromMethod("Rgb24", "Unsafe.As<Rgba32, Rgb24>(ref dp) = sp; dp.A = 255;"); |
|||
GenerateConvertToMethod("Rgb24", "dp = Unsafe.As<Rgba32, Rgb24>(ref sp);"); |
|||
|
|||
GeneratePackFromMethod("Bgr24", "dp.Bgr = sp; dp.A = 255;"); |
|||
GenerateConvertToMethod("Bgr24", "dp = sp.Bgr;"); |
|||
|
|||
GeneratePackFromMethod("Bgra32", "dp = sp.ToRgba32();"); |
|||
GenerateConvertToMethod("Bgra32", "dp = sp.ToBgra32();"); |
|||
#> |
|||
|
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue