Esempio n. 1
0
        public byte[] Save(IEnumerable <Color> colors)
        {
            if (Width <= 0 || Height <= 0)
            {
                throw new InvalidDataException("Height and Width has to be set for ASTC.");
            }

            CreateTempPNG("tmp.png", colors);

            var wrapper = new ASTCContext();
            var result  = wrapper.Encode("tmp.png", "tmp.astc", _blockMode);

            if (result == ConvertImageResult.Error)
            {
                return(null);
            }

            File.Delete("tmp.png");

            byte[] encodedData;
            using (var br = new BinaryReader(File.OpenRead("tmp.astc")))
            {
                br.BaseStream.Position += 12;
                encodedData             = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
            }
            File.Delete("tmp.astc");

            return(encodedData);
        }
Esempio n. 2
0
        public byte[] Save(IEnumerable <Color> colors)
        {
            if (Width < 0 || Height < 0)
            {
                throw new InvalidDataException("Height and Width has to be set for ASTC.");
            }

            CreateTempPNG("tmp.png", colors);

            var wrapper = new ASTCContext();

            wrapper.Encode("tmp.png", "tmp.astc", _blockMode);
            File.Delete("tmp.png");

            byte[] encodedData = null;
            using (var br = new BinaryReaderX(File.OpenRead("tmp.astc")))
            {
                br.ReadType <ASTCFileHeader>();
                encodedData = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
            }
            File.Delete("tmp.astc");

            return(encodedData);
        }