Exemplo n.º 1
0
 public static Imgd Create(
     Size size,
     PixelFormat pixelFormat,
     byte[] data,
     byte[] clut,
     bool isSwizzled) =>
 new Imgd(size, pixelFormat, ImageDataHelpers.GetInvertedRedBlueChannels(data, size, pixelFormat), clut, isSwizzled);
Exemplo n.º 2
0
        private RawBitmap(Stream stream, int width, int height, bool is8bit, bool defaultPaletteSwitch = false)
        {
            Size        = new Size(width, height);
            PixelFormat = is8bit ? PixelFormat.Indexed8 : PixelFormat.Indexed4;

            var reader = new BinaryReader(stream);
            var bpp    = is8bit ? 8 : 4;

            _data = reader.ReadBytes(width * height * bpp / 8);

            if (bpp == 4)
            {
                ImageDataHelpers.SwapEndianIndexed4(_data);
            }

            // If we did not reached the end of the stream, then it does mean that there is a palette
            if (stream.Position < stream.Length)
            {
                _clut = reader.ReadBytes(PaletteCount * BitsPerColor / 8);
            }
            else
            {
                // Just assign a default palette
                _clut = defaultPaletteSwitch ? FontPalette2 : FontPalette1;
            }
        }
Exemplo n.º 3
0
        public static byte[] AsRgba8888(this IImageRead image)
        {
            switch (image.PixelFormat)
            {
            case PixelFormat.Indexed4:
                return(ImageDataHelpers.FromIndexed4ToBitmap32(
                           image.GetData(), image.GetClut(), Rgba));

            case PixelFormat.Indexed8:
                return(ImageDataHelpers.FromIndexed8ToBitmap32(
                           image.GetData(), image.GetClut(), Rgba));

            case PixelFormat.Rgba8888:
                return(ImageDataHelpers.FromBitmap32(image.GetData(), Bgra));

            default:
                throw new ArgumentException($"The pixel format {image.PixelFormat} is not supported.");
            }
        }
Exemplo n.º 4
0
        public void Decode4bppTest()
        {
            var actual = ImageDataHelpers.FromIndexed4ToBitmap32(Data4bpp, Clut4bpp, ImageDataHelpers.RGBA);

            Assert.Equal(ExpectedFrom4bpp, actual);
        }