Example #1
0
        public Bitmap ToBitmap()
        {
            var bitmap = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);

            bitmap.LockBitsUnlock(PixelFormat.Format32bppArgb, (bitmapData) =>
            {
                var count  = Width * Height;
                var output = (OutputPixel *)bitmapData.Scan0;
                PixelFormatDecoder.Decode(
                    GuPixelFormat,
                    Address,
                    output,
                    Width,
                    Height,
                    ignoreAlpha: true
                    );

                for (var n = 0; n < count; n++)
                {
                    var color   = output[n];
                    output[n].R = color.B;
                    output[n].G = color.G;
                    output[n].B = color.R;
                    output[n].A = 0xFF;
                }
            });
            return(bitmap);
        }
Example #2
0
 public PspBitmap(GuPixelFormats pixelFormat, int width, int height, byte *address, int bytesPerLine = -1)
 {
     GuPixelFormat = pixelFormat;
     Width         = width;
     Height        = height;
     Address       = address;
     BitsPerPixel  = PixelFormatDecoder.GetPixelsBits(pixelFormat);
     ColorFormat   = PixelFormatDecoder.ColorFormatFromPixelFormat(pixelFormat);
     if (bytesPerLine < 0)
     {
         BytesPerLine = PixelFormatDecoder.GetPixelsSize(GuPixelFormat, width);
     }
     else
     {
         BytesPerLine = bytesPerLine;
     }
 }
Example #3
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);
        }
Example #4
0
 private int GetOffset(int x, int y)
 {
     return(y * BytesPerLine + PixelFormatDecoder.GetPixelsSize(GuPixelFormat, x));
 }