internal readonly uint GetColor(Vector2U position)
        {
            var  alphaValue = (byte)(AlphaBlock[position.Y] >> (int)(position.X * 4) & 0b1111);
            uint alpha      = alphaValue * 0b10001u << 24;

            return(Color.GetColorDXT3(position) | alpha);
        }
        internal readonly uint GetColorDXT3(Vector2U position)
        {
            var code = GetCode(position);

            switch (code)
            {
            case 0:
                return(color0.AsPacked);

            case 1:
                return(color1.AsPacked);

            case 2: {
                var b = (uint)(color0.B + color1.B) >> 1;
                var g = (uint)(color0.G + color1.G) >> 1;
                var r = (uint)(color0.R + color1.R) >> 1;
                return(Pack(b, g, r));
            }

            default:
            case 3: {
                return(0U);
            }
            }
        }
        // Returns the color, hopefully, as ABGR
        internal readonly uint GetColor(Vector2U position)
        {
            if (color0.Packed > color1.Packed)
            {
                var code = GetCode(position);
                switch (code)
                {
                case 0:
                    return(color0.AsPacked);

                case 1:
                    return(color1.AsPacked);

                case 2: {
                    var b = (2U * color0.B + color1.B) / 3U;
                    var g = (2U * color0.G + color1.G) / 3U;
                    var r = (2U * color0.R + color1.R) / 3U;
                    return(Pack(b, g, r));
                }

                default:
                case 3: {
                    var b = (color0.B + 2U * color1.B) / 3U;
                    var g = (color0.G + 2U * color1.G) / 3U;
                    var r = (color0.R + 2U * color1.R) / 3U;
                    return(Pack(b, g, r));
                }
                }
            }
            else
            {
                return(GetColorDXT3(position));
            }
        }
예제 #4
0
 /// <summary>
 /// Reads <see cref="Vector2U"/> instances from the current stream and returns them.
 /// </summary>
 /// <param name="self">The extended <see cref="BinaryDataReader"/>.</param>
 /// <param name="count">The number of instances to read.</param>
 /// <returns>The <see cref="Vector2U"/> instances.</returns>
 public static IList <Vector2U> ReadVector2Us(this BinaryDataReader self, int count)
 {
     Vector2U[] values = new Vector2U[count];
     for (int i = 0; i < count; i++)
     {
         values[i] = self.ReadVector2U();
     }
     return(values);
 }
 /// <summary>
 /// Writes a <see cref="Vector2U"/> instance into the current stream.
 /// </summary>
 /// <param name="self">The extended <see cref="BinaryDataWriter"/>.</param>
 /// <param name="value">The <see cref="Vector2U"/> instance.</param>
 public static void Write(this BinaryDataWriter self, Vector2U value)
 {
     self.Write(value.X);
     self.Write(value.Y);
 }
        private readonly byte GetCode(Vector2U position)
        {
            var code = codes[position.Y];

            return((byte)((byte)(code >> (int)(position.X << 1)) & 0b11));
        }
    internal static Span <byte> Decode(ReadOnlySpan <byte> data, Vector2I size, SurfaceFormat format)
    {
        Vector2U uSize = size;

        if (!IsBlockMultiple(uSize))
        {
            throw new ArgumentException($"{nameof(size)}: {uSize} not block multiple");
        }

        switch (format)
        {
        case SurfaceFormat.Dxt1: {
            var blocks        = data.Cast <ColorBlock>();
            var outData       = SpanExt.Make <byte>((int)uSize.Area);
            var outDataPacked = outData.Cast <uint>();

            var widthBlocks = uSize.Width >> 2;

            uint blockIndex = 0;
            foreach (var block in blocks)
            {
                var index   = blockIndex++;
                var xOffset = (index & widthBlocks - 1) << 2;
                var yOffset = index / widthBlocks << 2;

                for (uint y = 0; y < 4; ++y)
                {
                    var yOffsetInternal = yOffset + y;
                    for (uint x = 0; x < 4; ++x)
                    {
                        var xOffsetInternal = xOffset + x;
                        var offset          = yOffsetInternal * uSize.Width + xOffsetInternal;
                        outDataPacked[(int)offset] = block.GetColor((x, y)) | 0xFF000000U;
                    }
                }
            }

            return(outData);
        }

        case SurfaceFormat.Dxt3: {
            var blocks        = data.Cast <ColorBlockDxt3>();
            var outData       = SpanExt.Make <byte>((int)uSize.Area * sizeof(uint));
            var outDataPacked = outData.Cast <uint>();

            var widthBlocks = uSize.Width >> 2;

            uint blockIndex = 0;
            foreach (var block in blocks)
            {
                var index   = blockIndex++;
                var xOffset = (index & widthBlocks - 1) << 2;
                var yOffset = index / widthBlocks << 2;

                for (uint y = 0; y < 4; ++y)
                {
                    var yOffsetInternal = yOffset + y;
                    for (uint x = 0; x < 4; ++x)
                    {
                        var xOffsetInternal = xOffset + x;
                        var offset          = yOffsetInternal * uSize.Width + xOffsetInternal;
                        outDataPacked[(int)offset] = block.GetColor((x, y));
                    }
                }
            }

            return(outData);
        }

        default:
            throw new ArgumentOutOfRangeException(nameof(format));
        }
    }
예제 #8
0
 internal static void WriteVector2U(this Stream self, Vector2U value)
 {
     self.WriteUInt32(value.X);
     self.WriteUInt32(value.Y);
 }
예제 #9
0
        // ---- METHODS ------------------------------------------------------------------------------------------------

        void IData <Circuit> .Load(DataLoader <Circuit> loader, object parameter)
        {
            Unknown1 = loader.ReadUInt32();
            Unknown2 = loader.ReadVector2U();
            Unknown3 = loader.ReadVector2U();
        }