Ejemplo n.º 1
0
        public void ConvertFromAl(AlImage image, Stream destStream)
        {
            List <byte[]> mips;

            if (image.PixelFormat == "ETC1")
            {
                mips = image.Mipmaps;
            }
            else if (image.PixelFormat == "EC1A")
            {
                // Give first half of the mips
                mips = new List <byte[]>();
                foreach (var mip in image.Mipmaps)
                {
                    byte[] newMip = new byte[mip.Length / 2];
                    Buffer.BlockCopy(mip, 0, newMip, 0, newMip.Length);
                    mips.Add(newMip);
                }
            }
            else
            {
                throw new ArgumentException("Pixel format not supported.", nameof(image));
            }
            var ktx = KtxCreator.Create(GlDataType.Compressed, GlPixelFormat.GL_RGB, GlInternalFormat.GL_ETC1_RGB8_OES,
                                        image.Width, image.Height, mips, new Dictionary <string, MetadataValue>());

            KtxWriter.WriteTo(ktx, destStream);
        }
Ejemplo n.º 2
0
        public void ValidityWithValidSamplesTest()
        {
            // Arrange
            byte[] inputBytes1 = File.ReadAllBytes(CommonFiles.validSample1Filename);
            byte[] inputBytes2 = File.ReadAllBytes(CommonFiles.validSample2Filename);
            byte[] inputBytes3 = File.ReadAllBytes(CommonFiles.validSample3Filename);
            byte[] inputBytes4 = File.ReadAllBytes(CommonFiles.validSample4Filename);

            MemoryStream msWriter1 = new MemoryStream();
            MemoryStream msWriter2 = new MemoryStream();
            MemoryStream msWriter3 = new MemoryStream();
            MemoryStream msWriter4 = new MemoryStream();

            // Act
            KtxStructure ktxStructure1 = null;
            KtxStructure ktxStructure2 = null;
            KtxStructure ktxStructure3 = null;
            KtxStructure ktxStructure4 = null;

            using (MemoryStream msReader = new MemoryStream(inputBytes1))
            {
                ktxStructure1 = KtxLoader.LoadInput(msReader);
            }

            using (MemoryStream msReader = new MemoryStream(inputBytes2))
            {
                ktxStructure2 = KtxLoader.LoadInput(msReader);
            }

            using (MemoryStream msReader = new MemoryStream(inputBytes3))
            {
                ktxStructure3 = KtxLoader.LoadInput(msReader);
            }

            using (MemoryStream msReader = new MemoryStream(inputBytes4))
            {
                ktxStructure4 = KtxLoader.LoadInput(msReader);
            }

            KtxWriter.WriteTo(ktxStructure1, msWriter1);
            KtxWriter.WriteTo(ktxStructure2, msWriter2);
            KtxWriter.WriteTo(ktxStructure3, msWriter3);
            KtxWriter.WriteTo(ktxStructure4, msWriter4);

            // Assert
            CollectionAssert.AreEqual(inputBytes1, msWriter1.ToArray());
            CollectionAssert.AreEqual(inputBytes2, msWriter2.ToArray());
            CollectionAssert.AreEqual(inputBytes3, msWriter3.ToArray());
            CollectionAssert.AreEqual(inputBytes4, msWriter4.ToArray());
        }
Ejemplo n.º 3
0
        public void NullOrInvalidInputsTest()
        {
            // Arrange
            KtxStructure structure = null;

            MemoryStream msWriter             = new MemoryStream();
            MemoryStream msWriterNonWriteable = new MemoryStream(new byte[] { 0 }, writable: false);

            // Act
            using (FileStream input = new FileStream(CommonFiles.validSample1Filename, FileMode.Open))
            {
                structure = KtxLoader.LoadInput(input);
            }

            // Assert
            Assert.Throws <NullReferenceException>(() => { KtxWriter.WriteTo(null, msWriter); });
            Assert.Throws <NullReferenceException>(() => { KtxWriter.WriteTo(structure, null); });
            Assert.Throws <ArgumentException>(() => { KtxWriter.WriteTo(structure, msWriterNonWriteable); });
        }
Ejemplo n.º 4
0
        public void ConvertFromAlAlt(AlImage image, Stream destStream)
        {
            if (image.PixelFormat != "EC1A")
            {
                throw new ArgumentException("Pixel format does not have alternate representation.", nameof(image));
            }

            // Give second half of the mips
            var mips = new List <byte[]>();

            foreach (var mip in image.Mipmaps)
            {
                byte[] newMip = new byte[mip.Length / 2];
                Buffer.BlockCopy(mip, newMip.Length, newMip, 0, newMip.Length);
                mips.Add(newMip);
            }

            var ktx = KtxCreator.Create(GlDataType.Compressed, GlPixelFormat.GL_RGB, GlInternalFormat.GL_ETC1_RGB8_OES,
                                        image.Width, image.Height, mips, new Dictionary <string, MetadataValue>());

            KtxWriter.WriteTo(ktx, destStream);
        }