Ejemplo n.º 1
0
        public unsafe void TestWriteAndRead(string name)
        {
            var headerReader       = new TexHeaderReader();
            var mipmapDecompressor = new TexMipmapDecompressor();
            var mipmapReader       = new TexImageReader(mipmapDecompressor);
            var containerReader    = new TexImageContainerReader(mipmapReader);
            var frameInfoReader    = new TexFrameInfoContainerReader();

            mipmapReader.DecompressMipmapBytes = false;

            Native.RePKG.SetTexReader(new TexReader(headerReader, containerReader, frameInfoReader));

            // Load file
            var path         = $"{TestHelper.BasePath}\\{TexDecompressingTests.InputDirectoryName}\\{name}.tex";
            var inputBytes   = File.ReadAllBytes(path);
            var pin          = GCHandle.Alloc(inputBytes, GCHandleType.Pinned);
            var bytesPointer = (byte *)pin.AddrOfPinnedObject().ToPointer();

            // Read tex
            var ctex = Native.RePKG.tex_load(bytesPointer, inputBytes.Length);

            if (ctex == null)
            {
                throw new Exception(Marshal.PtrToStringAnsi(new IntPtr(Native.RePKG.get_last_error())));
            }

            using (var environment = Native.RePKG.GetEnvironmentFor(ctex))
            {
                var wrappedCTex = new WCTex(ctex, environment);

                // Write tex
                var memoryStream = new MemoryStream(inputBytes.Length);
                var writer       = new BinaryWriter(memoryStream, Encoding.UTF8);
                TexWriter.Default.WriteTo(writer, wrappedCTex);
                var outputBytes = memoryStream.ToArray();

                // Verify
                Assert.AreEqual(inputBytes.Length, outputBytes.Length, "Written tex size doesn't match input size");

                for (var i = 0; i < inputBytes.Length; i++)
                {
                    if (inputBytes[i] == outputBytes[i])
                    {
                        continue;
                    }

                    throw new Exception(
                              $"Rewritten tex bytes are not the same at index: {i}\r\n" +
                              $"Expected: {inputBytes[i]}\r\n" +
                              $"Actual: {outputBytes[i]}");
                }
            }
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            // Reader
            var headerReader       = new TexHeaderReader();
            var mipmapDecompressor = new TexMipmapDecompressor();
            var mipmapReader       = new TexImageReader(mipmapDecompressor);
            var containerReader    = new TexImageContainerReader(mipmapReader);
            var frameInfoReader    = new TexFrameInfoContainerReader();

            mipmapReader.DecompressMipmapBytes = false;
            mipmapReader.ReadMipmapBytes       = true;

            _reader = new TexReader(headerReader, containerReader, frameInfoReader);

            // Writer
            _writer = TexWriter.Default;
        }