Example #1
0
        /*
         * public static uint EncodePixel(GuPixelFormats PixelFormat, OutputPixel Color)
         * {
         *  return ColorFormatFromPixelFormat(PixelFormat).Encode(Color.R, Color.G, Color.B, Color.A);
         * }
         *
         * public static OutputPixel DecodePixel(GuPixelFormats PixelFormat, uint Value)
         * {
         *  throw new NotImplementedException();
         * }
         */

        public static 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,
                                  bool ignoreAlpha = false)
        {
            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.Rgba5650:
                pixelFormatDecoder.Decode_RGBA_5650();
                break;

            case GuPixelFormats.Rgba5551:
                pixelFormatDecoder.Decode_RGBA_5551();
                break;

            case GuPixelFormats.Rgba4444:
                pixelFormatDecoder.Decode_RGBA_4444();
                break;

            case GuPixelFormats.Rgba8888:
                pixelFormatDecoder.Decode_RGBA_8888();
                break;

            case GuPixelFormats.PaletteT4:
                pixelFormatDecoder.Decode_PALETTE_T4();
                break;

            case GuPixelFormats.PaletteT8:
                pixelFormatDecoder.Decode_PALETTE_T8();
                break;

            case GuPixelFormats.PaletteT16:
                pixelFormatDecoder.Decode_PALETTE_T16();
                break;

            case GuPixelFormats.PaletteT32:
                pixelFormatDecoder.Decode_PALETTE_T32();
                break;

            case GuPixelFormats.CompressedDxt1:
                pixelFormatDecoder.Decode_COMPRESSED_DXT1();
                break;

            case GuPixelFormats.CompressedDxt3:
                pixelFormatDecoder.Decode_COMPRESSED_DXT3();
                break;

            case GuPixelFormats.CompressedDxt5:
                pixelFormatDecoder.Decode_COMPRESSED_DXT5();
                break;

            default: throw new InvalidOperationException();
            }
            if (ignoreAlpha)
            {
                for (int y = 0, n = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, n++)
                    {
                        output[n].A = 0xFF;
                    }
                }
            }
            //DecoderCallbackTable[PixelFormatInt](Input, Output, PixelCount, Width, Palette, PaletteType, PaletteCount, PaletteStart, PaletteShift, PaletteMask);
        }