Ejemplo n.º 1
0
        public void ShouldCreateFormatsWithPalette()
        {
            var colors  = Enumerable.Repeat(Color.Red.WithoutName(), 256);
            var format  = new PixelFormatInfo(PixelFormat.Format_INDEX8);
            var palette = new Palette(colors);

            format.Palette = palette;

            format.Format.Should().Be(PixelFormat.Format_INDEX8);
            format.Palette.Should().Be(palette);

            var sameFormat = new PixelFormatInfo(format.Handle);

            format.Should().BeEquivalentTo(sameFormat, options);
            format.Dispose();
            // sameFormat.Palette.Dispose();
        }
Ejemplo n.º 2
0
        public void ShouldCreateFormatsWithoutPalette()
        {
            var format = new PixelFormatInfo(PixelFormat.Format_RGBA8888);

            format.Format.Should().Be(PixelFormat.Format_RGBA8888);
            Assert.Null(format.Palette);
            format.BitsPerPixel.Should().Be(32);
            format.BytesPerPixel.Should().Be(4);
            unchecked
            {
                format.MaskR.Should().Be((int)0xFF000000);
                format.MaskG.Should().Be((int)0x00FF0000);
                format.MaskB.Should().Be((int)0x0000FF00);
                format.MaskA.Should().Be((int)0x000000FF);
            }

            var sameFormat = new PixelFormatInfo(format.Handle);

            format.Should().BeEquivalentTo(sameFormat, options);
            format.Dispose();
        }
Ejemplo n.º 3
0
        public static byte[] Deswizzle(byte[] data, int width, int height, int numMipMaps, string pixelFormatName)
        {
            PixelFormatInfo info = new PixelFormatInfo();
            bool found = false;
            foreach (PixelFormatInfo i in PixelFormatInfos)
            {
                if (i.Name == pixelFormatName)
                {
                    found = true;
                    info = i;
                    break;
                }
            }

            if (!found)
                return data;

            int bytesPerBlock = info.BytesPerBlock;
            int curAddr = 0;
            for (int i = 0; i < numMipMaps; i++)
            {
                int width1 = Align(width, info.X360AlignX);
                int height1 = Align(height, info.X360AlignY);

                int size = (width1 / info.BlockSizeX) * (height1 / info.BlockSizeY) * bytesPerBlock;

                byte[] mipMapData = new byte[size];
                Array.Copy(data, curAddr, mipMapData, 0, size);
                mipMapData = UntileCompressedX360Texture(mipMapData, width1, width, height1, info.BlockSizeX, info.BlockSizeY, info.BytesPerBlock);
                Array.Copy(mipMapData, 0, data, curAddr, size);

                curAddr += size;
                width /= 2;
                height /= 2;
            }

            return data;
        }