mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
36 changed files with 827 additions and 379 deletions
@ -0,0 +1,40 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
|
||||
|
using SixLabors.ImageSharp.ColorSpaces.Companding; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.PixelFormats |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Flags responsible to select additional operations which could be effitiently applied in
|
||||
|
/// <see cref="PixelOperations{TPixel}.ToVector4(SixLabors.ImageSharp.Configuration,System.ReadOnlySpan{TPixel},System.Span{System.Numerics.Vector4},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
|
||||
|
/// or
|
||||
|
/// <see cref="PixelOperations{TPixel}.FromVector4Destructive(SixLabors.ImageSharp.Configuration,System.Span{System.Numerics.Vector4},System.Span{TPixel},SixLabors.ImageSharp.PixelFormats.PixelConversionModifiers)"/>
|
||||
|
/// knowing the pixel type.
|
||||
|
/// </summary>
|
||||
|
[Flags] |
||||
|
internal enum PixelConversionModifiers |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// No special operation is selected
|
||||
|
/// </summary>
|
||||
|
None = 0, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Select <see cref="IPixel.ToScaledVector4"/> and <see cref="IPixel.FromScaledVector4"/> instead the standard (non scaled) variants.
|
||||
|
/// </summary>
|
||||
|
Scale = 1 << 0, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Enable alpha premultiplication / unpremultiplication
|
||||
|
/// </summary>
|
||||
|
Premultiply = 1 << 1, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Enable SRGB companding (defined in <see cref="SRgbCompanding"/>).
|
||||
|
/// </summary>
|
||||
|
SRgbCompand = 1 << 2, |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.PixelFormats |
||||
|
{ |
||||
|
internal static class PixelConversionModifiersExtensions |
||||
|
{ |
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public static bool IsDefined(this PixelConversionModifiers modifiers, PixelConversionModifiers expected) => |
||||
|
(modifiers & expected) == expected; |
||||
|
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public static PixelConversionModifiers Remove( |
||||
|
this PixelConversionModifiers modifiers, |
||||
|
PixelConversionModifiers removeThis) => |
||||
|
modifiers & ~removeThis; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
using SixLabors.ImageSharp.ColorSpaces.Companding; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.PixelFormats.Utils |
||||
|
{ |
||||
|
internal static partial class Vector4Converters |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Apply modifiers used requested by ToVector4() conversion.
|
||||
|
/// </summary>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
internal static void ApplyForwardConversionModifiers(Span<Vector4> vectors, PixelConversionModifiers modifiers) |
||||
|
{ |
||||
|
if (modifiers.IsDefined(PixelConversionModifiers.SRgbCompand)) |
||||
|
{ |
||||
|
SRgbCompanding.Expand(vectors); |
||||
|
} |
||||
|
|
||||
|
if (modifiers.IsDefined(PixelConversionModifiers.Premultiply)) |
||||
|
{ |
||||
|
Vector4Utils.Premultiply(vectors); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Apply modifiers used requested by FromVector4() conversion.
|
||||
|
/// </summary>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
internal static void ApplyBackwardConversionModifiers(Span<Vector4> vectors, PixelConversionModifiers modifiers) |
||||
|
{ |
||||
|
if (modifiers.IsDefined(PixelConversionModifiers.Premultiply)) |
||||
|
{ |
||||
|
Vector4Utils.UnPremultiply(vectors); |
||||
|
} |
||||
|
|
||||
|
if (modifiers.IsDefined(PixelConversionModifiers.SRgbCompand)) |
||||
|
{ |
||||
|
SRgbCompanding.Compress(vectors); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using Xunit; |
||||
|
using Xunit.Abstractions; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations |
||||
|
{ |
||||
|
public partial class PixelOperationsTests |
||||
|
{ |
||||
|
public class Rgb24OperationsTests : PixelOperationsTests<Rgb24> |
||||
|
{ |
||||
|
public Rgb24OperationsTests(ITestOutputHelper output) |
||||
|
: base(output) |
||||
|
{ |
||||
|
this.HasAlpha = false; |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void IsSpecialImplementation() => Assert.IsType<Rgb24.PixelOperations>(PixelOperations<Rgb24>.Instance); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1 +1 @@ |
|||||
Subproject commit c4098e463ab0e7128ae196b7f963369271df8fd3 |
Subproject commit 9d71985545bb827270ca34af3f78e4c220560ef1 |
||||
Loading…
Reference in new issue