public void FromVector4(Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Max; this.R = (ushort)MathF.Round(vector.X); this.G = (ushort)MathF.Round(vector.Y); this.B = (ushort)MathF.Round(vector.Z); }
private static ushort Pack(ref Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One); return((ushort)((((int)Math.Round(vector.W * 15F) & 0x0F) << 12) | (((int)Math.Round(vector.X * 15F) & 0x0F) << 8) | (((int)Math.Round(vector.Y * 15F) & 0x0F) << 4) | ((int)Math.Round(vector.Z * 15F) & 0x0F))); }
public void FromVector4(Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One); this.R = vector.X; this.G = vector.Y; this.B = vector.Z; this.A = vector.W; }
public Cmyk(Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Min, Max); this.C = vector.X; this.M = vector.Y; this.Y = vector.Z; this.K = vector.W; }
private static ushort Pack(ref Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One); return((ushort)( (((int)Math.Round(vector.X * 31F) & 0x1F) << 10) | (((int)Math.Round(vector.Y * 31F) & 0x1F) << 5) | (((int)Math.Round(vector.Z * 31F) & 0x1F) << 0) | (((int)Math.Round(vector.W) & 0x1) << 15))); }
private static uint Pack(ref Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, Vector4.One) * Multiplier; return((uint)( (((int)Math.Round(vector.X) & 0x03FF) << 0) | (((int)Math.Round(vector.Y) & 0x03FF) << 10) | (((int)Math.Round(vector.Z) & 0x03FF) << 20) | (((int)Math.Round(vector.W) & 0x03) << 30))); }
private void Pack(ref Vector4 vector) { vector *= MaxBytes; vector += Half; vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, MaxBytes); this.R = (byte)vector.X; this.G = (byte)vector.Y; this.B = (byte)vector.Z; }
public void Invoke(int y, Span <Vector4> span) { Span <TPixel> rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length); PixelOperations <TPixel> .Instance.ToVector4(this.configuration, rowSpan, span); Vector4Utilities.Transform(span, ref Unsafe.AsRef(this.matrix)); PixelOperations <TPixel> .Instance.FromVector4Destructive(this.configuration, span, rowSpan); }
private static uint Pack(ref Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, MinusOne, Vector4.One) * Half; uint byte4 = ((uint)MathF.Round(vector.X) & 0xFF) << 0; uint byte3 = ((uint)MathF.Round(vector.Y) & 0xFF) << 8; uint byte2 = ((uint)MathF.Round(vector.Z) & 0xFF) << 16; uint byte1 = ((uint)MathF.Round(vector.W) & 0xFF) << 24; return(byte4 | byte3 | byte2 | byte1); }
internal static void ApplyBackwardConversionModifiers(Span <Vector4> vectors, PixelConversionModifiers modifiers) { if (modifiers.IsDefined(PixelConversionModifiers.Premultiply)) { Vector4Utilities.UnPremultiply(vectors); } if (modifiers.IsDefined(PixelConversionModifiers.SRgbCompand)) { SRgbCompanding.Compress(vectors); } }
private static ulong Pack(ref Vector4 vector) { vector = Vector4Utilities.FastClamp(vector, Min, Max); // Clamp the value between min and max values ulong word4 = ((ulong)Math.Round(vector.X) & 0xFFFF) << 0x00; ulong word3 = ((ulong)Math.Round(vector.Y) & 0xFFFF) << 0x10; ulong word2 = ((ulong)Math.Round(vector.Z) & 0xFFFF) << 0x20; ulong word1 = ((ulong)Math.Round(vector.W) & 0xFFFF) << 0x30; return(word4 | word3 | word2 | word1); }
private static ulong Pack(ref Vector4 vector) { vector *= Max; vector = Vector4Utilities.FastClamp(vector, Min, Max); // Round rather than truncate. ulong word4 = ((ulong)MathF.Round(vector.X) & 0xFFFF) << 0x00; ulong word3 = ((ulong)MathF.Round(vector.Y) & 0xFFFF) << 0x10; ulong word2 = ((ulong)MathF.Round(vector.Z) & 0xFFFF) << 0x20; ulong word1 = ((ulong)MathF.Round(vector.W) & 0xFFFF) << 0x30; return(word4 | word3 | word2 | word1); }
private static uint Pack(ref Vector4 vector) { const float Max = 255F; // Clamp the value between min and max values vector = Vector4Utilities.FastClamp(vector, Vector4.Zero, new Vector4(Max)); uint byte4 = (uint)Math.Round(vector.X) & 0xFF; uint byte3 = ((uint)Math.Round(vector.Y) & 0xFF) << 0x8; uint byte2 = ((uint)Math.Round(vector.Z) & 0xFF) << 0x10; uint byte1 = ((uint)Math.Round(vector.W) & 0xFF) << 0x18; return(byte4 | byte3 | byte2 | byte1); }
public void UnPremultiply_VectorSpan(int length) { var rnd = new Random(42); Vector4[] source = rnd.GenerateRandomVectorArray(length, 0, 1); Vector4[] expected = source.Select(v => { Vector4Utilities.UnPremultiply(ref v); return(v); }).ToArray(); Vector4Utilities.UnPremultiply(source); Assert.Equal(expected, source, this.approximateFloatComparer); }
/// <summary> /// Level shift by +maximum/2, clip to [0, maximum] /// </summary> public void NormalizeColorsInplace(float maximum) { var CMin4 = new Vector4(0F); var CMax4 = new Vector4(maximum); var COff4 = new Vector4(MathF.Ceiling(maximum / 2)); this.V0L = Vector4Utilities.FastClamp(this.V0L + COff4, CMin4, CMax4); this.V0R = Vector4Utilities.FastClamp(this.V0R + COff4, CMin4, CMax4); this.V1L = Vector4Utilities.FastClamp(this.V1L + COff4, CMin4, CMax4); this.V1R = Vector4Utilities.FastClamp(this.V1R + COff4, CMin4, CMax4); this.V2L = Vector4Utilities.FastClamp(this.V2L + COff4, CMin4, CMax4); this.V2R = Vector4Utilities.FastClamp(this.V2R + COff4, CMin4, CMax4); this.V3L = Vector4Utilities.FastClamp(this.V3L + COff4, CMin4, CMax4); this.V3R = Vector4Utilities.FastClamp(this.V3R + COff4, CMin4, CMax4); this.V4L = Vector4Utilities.FastClamp(this.V4L + COff4, CMin4, CMax4); this.V4R = Vector4Utilities.FastClamp(this.V4R + COff4, CMin4, CMax4); this.V5L = Vector4Utilities.FastClamp(this.V5L + COff4, CMin4, CMax4); this.V5R = Vector4Utilities.FastClamp(this.V5R + COff4, CMin4, CMax4); this.V6L = Vector4Utilities.FastClamp(this.V6L + COff4, CMin4, CMax4); this.V6R = Vector4Utilities.FastClamp(this.V6R + COff4, CMin4, CMax4); this.V7L = Vector4Utilities.FastClamp(this.V7L + COff4, CMin4, CMax4); this.V7R = Vector4Utilities.FastClamp(this.V7R + COff4, CMin4, CMax4); }