From 1ddff93c3a41324bbdcec540f41db9d7b563b305 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 18 Apr 2017 16:16:35 +1000 Subject: [PATCH] Delete Rgba32 --- src/ImageSharp/Colors/PackedPixel/Rgba32.cs | 398 -------------------- 1 file changed, 398 deletions(-) delete mode 100644 src/ImageSharp/Colors/PackedPixel/Rgba32.cs diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba32.cs b/src/ImageSharp/Colors/PackedPixel/Rgba32.cs deleted file mode 100644 index 727d91c93..000000000 --- a/src/ImageSharp/Colors/PackedPixel/Rgba32.cs +++ /dev/null @@ -1,398 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System.Numerics; - using System.Runtime.CompilerServices; - - /// - /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. - /// The color components are stored in red, green, blue, and alpha order. - /// - /// - /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, - /// as it avoids the need to create new values for modification operations. - /// - public struct Rgba32 : IPixel, IPackedVector - { - /// - /// The shift count for the red component - /// - private const int RedShift = 0; - - /// - /// The shift count for the green component - /// - private const int GreenShift = 8; - - /// - /// The shift count for the blue component - /// - private const int BlueShift = 16; - - /// - /// The shift count for the alpha component - /// - private const int AlphaShift = 24; - - /// - /// The maximum byte value. - /// - private static readonly Vector4 MaxBytes = new Vector4(255); - - /// - /// The half vector value. - /// - private static readonly Vector4 Half = new Vector4(0.5F); - - /// - /// The packed value. - /// - private uint packedValue; - - /// - /// Initializes a new instance of the struct. - /// - /// The red component. - /// The green component. - /// The blue component. - /// The alpha component. - public Rgba32(byte r, byte g, byte b, byte a = 255) - { - this.packedValue = Pack(r, g, b, a); - } - - /// - /// Initializes a new instance of the struct. - /// - /// The red component. - /// The green component. - /// The blue component. - /// The alpha component. - public Rgba32(float r, float g, float b, float a = 1) - { - this.packedValue = Pack(r, g, b, a); - } - - /// - /// Initializes a new instance of the struct. - /// - /// - /// The vector containing the components for the packed vector. - /// - public Rgba32(Vector3 vector) - { - this.packedValue = Pack(ref vector); - } - - /// - /// Initializes a new instance of the struct. - /// - /// - /// The vector containing the components for the packed vector. - /// - public Rgba32(Vector4 vector) - { - this.packedValue = Pack(ref vector); - } - - /// - /// Initializes a new instance of the struct. - /// - /// - /// The packed value. - /// - public Rgba32(uint packed) - { - this.packedValue = packed; - } - - /// - /// Gets or sets the red component. - /// - public byte R - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return (byte)(this.packedValue >> RedShift); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.packedValue = this.packedValue & 0xFFFFFF00 | (uint)value << RedShift; - } - } - - /// - /// Gets or sets the green component. - /// - public byte G - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return (byte)(this.packedValue >> GreenShift); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << GreenShift; - } - } - - /// - /// Gets or sets the blue component. - /// - public byte B - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return (byte)(this.packedValue >> BlueShift); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << BlueShift; - } - } - - /// - /// Gets or sets the alpha component. - /// - public byte A - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return (byte)(this.packedValue >> AlphaShift); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << AlphaShift; - } - } - - /// - public uint PackedValue - { - get => this.packedValue; - - set => this.packedValue = value; - } - - /// - /// Compares two objects for equality. - /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the parameter is equal to the parameter; otherwise, false. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(Rgba32 left, Rgba32 right) - { - return left.packedValue == right.packedValue; - } - - /// - /// Compares two objects for equality. - /// - /// The on the left side of the operand. - /// The on the right side of the operand. - /// - /// True if the parameter is not equal to the parameter; otherwise, false. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(Rgba32 left, Rgba32 right) - { - return left.packedValue != right.packedValue; - } - - /// - /// Creates a new instance of the struct. - /// - /// - /// The hexadecimal representation of the combined color components arranged - /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax. - /// - /// - /// The . - /// - public static Rgba32 FromHex(string hex) - { - return ColorBuilder.FromHex(hex); - } - - /// - public BulkPixelOperations CreateBulkOperations() => new BulkPixelOperations(); - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromBytes(byte x, byte y, byte z, byte w) - { - this.packedValue = Pack(x, y, z, w); - } - - /// - /// Converts the value of this instance to a hexadecimal string. - /// - /// A hexadecimal string representation of the value. - public string ToHex() - { - uint hexOrder = Pack(this.A, this.B, this.G, this.R); - return hexOrder.ToString("X8"); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzBytes(byte[] bytes, int startIndex) - { - bytes[startIndex] = this.R; - bytes[startIndex + 1] = this.G; - bytes[startIndex + 2] = this.B; - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToXyzwBytes(byte[] bytes, int startIndex) - { - bytes[startIndex] = this.R; - bytes[startIndex + 1] = this.G; - bytes[startIndex + 2] = this.B; - bytes[startIndex + 3] = this.A; - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxBytes(byte[] bytes, int startIndex) - { - bytes[startIndex] = this.B; - bytes[startIndex + 1] = this.G; - bytes[startIndex + 2] = this.R; - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToZyxwBytes(byte[] bytes, int startIndex) - { - bytes[startIndex] = this.B; - bytes[startIndex + 1] = this.G; - bytes[startIndex + 2] = this.R; - bytes[startIndex + 3] = this.A; - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void PackFromVector4(Vector4 vector) - { - this.packedValue = Pack(ref vector); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector4 ToVector4() - { - return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes; - } - - /// - public override bool Equals(object obj) - { - return (obj is Rgba32) && this.Equals((Rgba32)obj); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Rgba32 other) - { - return this.packedValue == other.packedValue; - } - - /// - /// Gets a string representation of the packed vector. - /// - /// A string representation of the packed vector. - public override string ToString() - { - return this.ToVector4().ToString(); - } - - /// - public override int GetHashCode() - { - return this.packedValue.GetHashCode(); - } - - /// - /// Packs a into a uint. - /// - /// The vector containing the values to pack. - /// The containing the packed values. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(ref Vector4 vector) - { - vector *= MaxBytes; - vector += Half; - vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes); - return (uint)(((byte)vector.X << RedShift) - | ((byte)vector.Y << GreenShift) - | ((byte)vector.Z << BlueShift) - | (byte)vector.W << AlphaShift); - } - - /// - /// Packs a into a uint. - /// - /// The vector containing the values to pack. - /// The containing the packed values. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(ref Vector3 vector) - { - Vector4 value = new Vector4(vector, 1); - return Pack(ref value); - } - - /// - /// Packs the four floats into a . - /// - /// The x-component - /// The y-component - /// The z-component - /// The w-component - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(float x, float y, float z, float w) - { - Vector4 value = new Vector4(x, y, z, w); - return Pack(ref value); - } - - /// - /// Packs the four floats into a . - /// - /// The x-component - /// The y-component - /// The z-component - /// The w-component - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(byte x, byte y, byte z, byte w) - { - return (uint)(x << RedShift | y << GreenShift | z << BlueShift | w << AlphaShift); - } - } -} \ No newline at end of file