Example #1
0
        /// <summary>
        /// Extracts every TexImage included in the atlas.
        /// </summary>
        /// <param name="atlas">The atlas.</param>
        /// <param name="minimumMipmapSize">The minimum size of the smallest mipmap.</param>
        /// <returns>The list of TexImage corresponding to each texture composing the atlas.</returns>
        /// <exception cref="TextureToolsException">The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.</exception>
        public List<TexImage> ExtractAll(TexAtlas atlas, int minimumMipmapSize = 1)
        {
            if (minimumMipmapSize < 0)
            {
                Log.Error("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.");
                throw new TextureToolsException("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.");
            }

            var request = new AtlasExtractionRequest(minimumMipmapSize);

            if (atlas.Format.IsCompressed())
            {
                Log.Warning("You can't extract a texture from a compressed atlas. The atlas will be decompressed first..");
                Decompress(atlas, atlas.Format.IsSRgb());
            }

            ExecuteRequest(atlas, request);

            return request.Textures;
        }
Example #2
0
        /// <summary>
        /// Extracts the TexImage corresponding to the specified name in the given atlas.
        /// </summary>
        /// <param name="atlas">The atlas.</param>
        /// <param name="name">The texture name.</param>
        /// <param name="minimumMipmapSize">The minimum size of the smallest mipmap.</param>
        /// <returns>The TexImage texture corresponding to the specified name</returns>
        /// <exception cref="TextureToolsException">
        /// You must enter a texture name to extract.
        /// or
        /// The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.
        /// </exception>
        public TexImage Extract(TexAtlas atlas, string name, int minimumMipmapSize = 1)
        {
            if (name == null || name.Equals(""))
            {
                Log.Error("You must enter a texture name to extract.");
                throw new TextureToolsException("You must enter a texture name to extract.");
            }

            if (minimumMipmapSize < 0)
            {
                Log.Error("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.");
                throw new TextureToolsException("The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.");
            }

            var request = new AtlasExtractionRequest(name, minimumMipmapSize);

            if (atlas.Format.IsCompressed())
            {
                Decompress(atlas, atlas.Format.IsSRgb());
            }

            ExecuteRequest(atlas, request);

            return request.Texture;
        }
        public void ExtractAllTest(string directory)
        {
            string path = TestTools.InputTestFolder + directory;
            string[] fileList = Directory.GetFiles(path);
            var list = new List<TexImage>(fileList.Length);

            foreach (string filePath in fileList)
            {
                var temp = Load(fiLib, filePath);
                list.Add(temp);
                //Console.WriteLine("ExtractAll_" + Path.GetFileName(filePath) + "." + TestTools.ComputeSHA1(temp.Data, temp.DataSize));
            }

            var atlas = new TexAtlas();

            library.Execute(atlas, new AtlasCreationRequest(list));

            var request = new AtlasExtractionRequest(0);
            library.Execute(atlas, request);
            library.EndLibrary(atlas);

            Assert.IsTrue(list.Count == request.Textures.Count);

            foreach (var image in request.Textures)
            {
                Assert.IsTrue(TestTools.ComputeSHA1(image.Data, image.DataSize).Equals(TestTools.GetInstance().Checksum["ExtractAll_" + image.Name]));
                image.Dispose();
            }

            atlas.Dispose();

            foreach (var image in list)
            {
                image.Dispose();
            }
        }
        public void ExtractTest(string atlasFile, string extractedName)
        {
            TexAtlas atlas = new TexAtlas(TexAtlas.TexLayout.Import(TestTools.InputTestFolder+Path.GetFileNameWithoutExtension(atlasFile) + TexAtlas.TexLayout.Extension), TestTools.Load(dxtLib, atlasFile));

            var request = new AtlasExtractionRequest(extractedName, 16);
            library.Execute(atlas, request);
            atlas.CurrentLibrary = library;

            var extracted = request.Texture;

            string nameWOExtension = Path.GetFileNameWithoutExtension(extractedName);

            //Console.WriteLine("AtlasTexLibrary_Extract_" + nameWOExtension + ".dds." + TestTools.ComputeSHA1(extracted.Data, extracted.DataSize));
            Assert.IsTrue(TestTools.ComputeSHA1(extracted.Data, extracted.DataSize).Equals(TestTools.GetInstance().Checksum["AtlasTexLibrary_Extract_" + nameWOExtension + ".dds"]));

            extracted.Dispose();

            atlas.Dispose();
        }
        /// <summary>
        /// Extracts the specified TexImage from the atlas.
        /// </summary>
        /// <param name="atlas">The atlas.</param>
        /// <param name="request">The request.</param>
        private void Extract(TexAtlas atlas, AtlasExtractionRequest request)
        {
            if (request.Name != null)
            {
                Log.Info("Extracting " + request.Name + " from atlas ...");

                if (!atlas.Layout.TexList.ContainsKey(request.Name))
                {
                    Log.Error("The request texture name " + request.Name + " doesn't exist in this atlas.");
                    throw new TextureToolsException("The request texture name " + request.Name + " doesn't exist in this atlas.");
                }
                request.Texture.Name = request.Name;
                ExtractTexture(atlas, request.Texture, atlas.Layout.TexList[request.Name], request.MinimumMipMapSize);
            }
            else
            {
                Log.Info("Extracting textures from atlas ...");

                TexImage texture;
                foreach (KeyValuePair<string, TexAtlas.TexLayout.Position> entry in atlas.Layout.TexList)
                {
                    texture = new TexImage();
                    texture.Name = entry.Key;
                    request.Textures.Add(texture);
                    ExtractTexture(atlas, texture, entry.Value, request.MinimumMipMapSize);
                }
            }
        }