forked from fiigii/PacketTracer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorPacket.cs
More file actions
58 lines (46 loc) · 2.12 KB
/
ColorPacket.cs
File metadata and controls
58 lines (46 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
using static System.Runtime.Intrinsics.X86.Avx;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics;
using System.Runtime.CompilerServices;
using ColorPacket256 = VectorPacket256;
internal static class ColorPacket256Helper
{
private static readonly Vector256<float> One = Vector256.Create(1.0f);
private static readonly Vector256<float> Max = Vector256.Create(255.0f);
public static Int32RGBPacket256 ConvertToIntRGB(this VectorPacket256 colors)
{
var rsMask = Compare(colors.Xs, One, FloatComparisonMode.OrderedGreaterThanNonSignaling);
var gsMask = Compare(colors.Ys, One, FloatComparisonMode.OrderedGreaterThanNonSignaling);
var bsMask = Compare(colors.Zs, One, FloatComparisonMode.OrderedGreaterThanNonSignaling);
var rs = BlendVariable(colors.Xs, One, rsMask);
var gs = BlendVariable(colors.Ys, One, gsMask);
var bs = BlendVariable(colors.Zs, One, bsMask);
var rsInt = ConvertToVector256Int32(Multiply(rs, Max));
var gsInt = ConvertToVector256Int32(Multiply(gs, Max));
var bsInt = ConvertToVector256Int32(Multiply(bs, Max));
return new Int32RGBPacket256(rsInt, gsInt, bsInt);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorPacket256 Times(ColorPacket256 left, ColorPacket256 right)
{
return new VectorPacket256(Multiply(left.Xs, right.Xs), Multiply(left.Ys, right.Ys), Multiply(left.Zs, right.Zs));
}
public static readonly ColorPacket256 BackgroundColor = new ColorPacket256(Vector256<float>.Zero);
public static readonly ColorPacket256 DefaultColor = new ColorPacket256(Vector256<float>.Zero);
}
internal struct Int32RGBPacket256
{
public Vector256<int> Rs;
public Vector256<int> Gs;
public Vector256<int> Bs;
public Int32RGBPacket256(Vector256<int> rs, Vector256<int> gs, Vector256<int> bs)
{
Rs = rs;
Gs = gs;
Bs = bs;
}
}