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

Decode_COMPRESSED_DXT3() private method

DXT2 and DXT3 (collectively also known as Block Compression 2 or BC2) converts 16 input pixels (corresponding to a 4x4 pixel block) into 128 bits of output, consisting of 64 bits of alpha channel data (4 bits for each pixel) followed by 64 bits of color data, encoded the same way as DXT1 (with the exception that the 4 color version of the DXT1 algorithm is always used instead of deciding which version to use based on the relative values of and ). In DXT2, the color data is interpreted as being premultiplied by alpha, in DXT3 it is interpreted as not having been premultiplied by alpha. Typically DXT2/3 are well suited to images with sharp alpha transitions, between translucent and opaque areas.
private Decode_COMPRESSED_DXT3 ( ) : void
return void
        private unsafe void Decode_COMPRESSED_DXT3()
        {
            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 = ((Dxt3Block*)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));
                    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)); });

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

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

                            Output[n] = Colors[Color];
                            Output[n].A = (byte)((Alpha * 0xFF) / 0xF);
                        }
                    }
                }
            }
        }

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_DXT3