コード例 #1
0
        private unsafe static byte[] Read4Bpp(IAMemory Memory, Texture Texture)
        {
            int Width  = Texture.Width;
            int Height = Texture.Height;

            byte[] Output = new byte[Width * Height * 4];

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 4);

            (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition(
                Memory,
                Texture.Position);

            fixed(byte *BuffPtr = Output)
            {
                long OutOffs = 0;

                for (int Y = 0; Y < Height; Y++)
                {
                    for (int X = 0; X < Width; X++)
                    {
                        long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                        int Pixel = CpuMem.ReadInt32Unchecked(Position + Offset);

                        *(int *)(BuffPtr + OutOffs) = Pixel;

                        OutOffs += 4;
                    }
                }
            }

            return(Output);
        }
コード例 #2
0
        private unsafe static byte[] Read8Bpt4x4(IAMemory Memory, Texture Texture)
        {
            int Width  = (Texture.Width + 3) / 4;
            int Height = (Texture.Height + 3) / 4;

            byte[] Output = new byte[Width * Height * 8];

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 8);

            (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition(
                Memory,
                Texture.Position);

            fixed(byte *BuffPtr = Output)
            {
                long OutOffs = 0;

                for (int Y = 0; Y < Height; Y++)
                {
                    for (int X = 0; X < Width; X++)
                    {
                        long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                        long Tile = CpuMem.ReadInt64Unchecked(Position + Offset);

                        *(long *)(BuffPtr + OutOffs) = Tile;

                        OutOffs += 8;
                    }
                }
            }

            return(Output);
        }
コード例 #3
0
        private unsafe static void Write4Bpp(IAMemory Memory, Texture Texture, byte[] Data)
        {
            int Width  = Texture.Width;
            int Height = Texture.Height;

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 4);

            (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition(
                Memory,
                Texture.Position);

            fixed(byte *BuffPtr = Data)
            {
                long InOffs = 0;

                for (int Y = 0; Y < Height; Y++)
                {
                    for (int X = 0; X < Width; X++)
                    {
                        long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                        int Pixel = *(int *)(BuffPtr + InOffs);

                        CpuMem.WriteInt32Unchecked(Position + Offset, Pixel);

                        InOffs += 4;
                    }
                }
            }
        }
コード例 #4
0
        private unsafe static byte[] Read5551(IAMemory Memory, Texture Texture)
        {
            int Width  = Texture.Width;
            int Height = Texture.Height;

            byte[] Output = new byte[Width * Height * 2];

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 2);

            (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition(
                Memory,
                Texture.Position);

            fixed(byte *BuffPtr = Output)
            {
                long OutOffs = 0;

                for (int Y = 0; Y < Height; Y++)
                {
                    for (int X = 0; X < Width; X++)
                    {
                        long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                        uint Pixel = (uint)CpuMem.ReadInt16Unchecked(Position + Offset);

                        Pixel = (Pixel & 0x001f) << 11 |
                                (Pixel & 0x03e0) << 1 |
                                (Pixel & 0x7c00) >> 9 |
                                (Pixel & 0x8000) >> 15;

                        *(short *)(BuffPtr + OutOffs) = (short)Pixel;

                        OutOffs += 2;
                    }
                }
            }

            return(Output);
        }
コード例 #5
0
        private unsafe static byte[] Read16Bpp(IAMemory Memory, Texture Texture)
        {
            int Width  = Texture.Width;
            int Height = Texture.Height;

            byte[] Output = new byte[Width * Height * 16];

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 16);

            (AMemory CpuMem, long Position) = TextureHelper.GetMemoryAndPosition(
                Memory,
                Texture.Position);

            fixed(byte *BuffPtr = Output)
            {
                long OutOffs = 0;

                for (int Y = 0; Y < Height; Y++)
                {
                    for (int X = 0; X < Width; X++)
                    {
                        long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                        long PxLow  = CpuMem.ReadInt64Unchecked(Position + Offset + 0);
                        long PxHigh = CpuMem.ReadInt64Unchecked(Position + Offset + 8);

                        *(long *)(BuffPtr + OutOffs + 0) = PxLow;
                        *(long *)(BuffPtr + OutOffs + 8) = PxHigh;

                        OutOffs += 16;
                    }
                }
            }

            return(Output);
        }