CSPspEmu.Core.Utils.PixelFormatDecoder.Decode_COMPRESSED_DXT1 C# (CSharp) Method

Decode_COMPRESSED_DXT1() private method

private Decode_COMPRESSED_DXT1 ( ) : void
return void
        private unsafe void Decode_COMPRESSED_DXT1()
        {
            var Colors = new OutputPixel[4];

            for (int y = 0, ni = 0; y < Height; y += 4)
            {
                for (int x = 0; x < Width; x += 4, ni++)
                {
                    var Block = ((Dxt1Block*)InputByte)[ni];

                    Colors[0] = Decode_RGBA_5650_Pixel(Block.Color0).Transform((R, G, B, A) => OutputPixel.FromRGBA(B, G, R, A));
                    Colors[1] = Decode_RGBA_5650_Pixel(Block.Color1).Transform((R, G, B, A) => OutputPixel.FromRGBA(B, G, R, A));

                    if (Block.Color0 > Block.Color1)
                    {
                        Colors[2] = OutputPixel.OperationPerComponent(Colors[0], Colors[1], (a, b) => { return (byte)(((a * 2) / 3) + ((b * 1) / 3)); });
                        Colors[3] = OutputPixel.OperationPerComponent(Colors[0], Colors[1], (a, b) => { return (byte)(((a * 1) / 3) + ((b * 2) / 3)); });
                    }
                    else
                    {
                        Colors[2] = OutputPixel.OperationPerComponent(Colors[0], Colors[1], (a, b) => { return (byte)(((a * 1) / 2) + ((b * 1) / 2)); });
                        Colors[3] = OutputPixel.FromRGBA(0, 0, 0, 0);
                    }

                    for (int y2 = 0, no = 0; y2 < 4; y2++)
                    {
                        for (int x2 = 0; x2 < 4; x2++, no++)
                        {
                            var Color = ((Block.ColorLookup >> (2 * no)) & 0x3);

                            int rx = (x + x2);
                            int ry = (y + y2);
                            int n = ry * Width + rx;

                            Output[n] = Colors[Color];
                        }
                    }
                }
            }
        }

Usage Example

Example #1
0
        static public void Decode(GuPixelFormats PixelFormat, void *Input, OutputPixel *Output, int Width, int Height, void *Palette = null, GuPixelFormats PaletteType = GuPixelFormats.NONE, int PaletteCount = 0, int PaletteStart = 0, int PaletteShift = 0, int PaletteMask = 0xFF, int StrideWidth = -1)
        {
            if (StrideWidth == -1)
            {
                StrideWidth = GetPixelsSize(PixelFormat, Width);
            }
            var PixelFormatInt     = (int)PixelFormat;
            var PixelFormatDecoder = new PixelFormatDecoder()
            {
                _Input       = Input,
                InputByte    = (byte *)Input,
                InputShort   = (ushort *)Input,
                InputInt     = (uint *)Input,
                Output       = Output,
                StrideWidth  = StrideWidth,
                Width        = Width,
                Height       = Height,
                Palette      = Palette,
                PaletteType  = PaletteType,
                PaletteCount = PaletteCount,
                PaletteStart = PaletteStart,
                PaletteShift = PaletteShift,
                PaletteMask  = PaletteMask,
            };

            //Console.WriteLine(PixelFormat);
            switch (PixelFormat)
            {
            case GuPixelFormats.RGBA_5650: PixelFormatDecoder.Decode_RGBA_5650(); break;

            case GuPixelFormats.RGBA_5551: PixelFormatDecoder.Decode_RGBA_5551(); break;

            case GuPixelFormats.RGBA_4444: PixelFormatDecoder.Decode_RGBA_4444(); break;

            case GuPixelFormats.RGBA_8888: PixelFormatDecoder.Decode_RGBA_8888(); break;

            case GuPixelFormats.PALETTE_T4: PixelFormatDecoder.Decode_PALETTE_T4(); break;

            case GuPixelFormats.PALETTE_T8: PixelFormatDecoder.Decode_PALETTE_T8(); break;

            case GuPixelFormats.PALETTE_T16: PixelFormatDecoder.Decode_PALETTE_T16(); break;

            case GuPixelFormats.PALETTE_T32: PixelFormatDecoder.Decode_PALETTE_T32(); break;

            case GuPixelFormats.COMPRESSED_DXT1: PixelFormatDecoder.Decode_COMPRESSED_DXT1(); break;

            case GuPixelFormats.COMPRESSED_DXT3: PixelFormatDecoder.Decode_COMPRESSED_DXT3(); break;

            case GuPixelFormats.COMPRESSED_DXT5: PixelFormatDecoder.Decode_COMPRESSED_DXT5(); break;

            default: throw(new InvalidOperationException());
            }
            //DecoderCallbackTable[PixelFormatInt](Input, Output, PixelCount, Width, Palette, PaletteType, PaletteCount, PaletteStart, PaletteShift, PaletteMask);
        }
All Usage Examples Of CSPspEmu.Core.Utils.PixelFormatDecoder::Decode_COMPRESSED_DXT1