Example #1
0
        /// <summary>
        /// Extracts every TexImage included in the array.
        /// </summary>
        /// <param name="array">The array.</param>
        /// <param name="minimumMipmapSize">The minimum size of the smallest mipmap.</param>
        /// <returns>The list of TexImage corresponding to each element of the texture array.</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(TexImage array, 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 ArrayExtractionRequest(minimumMipmapSize);

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

            ExecuteRequest(array, request);

            return request.Textures;
        }
Example #2
0
        /// <summary>
        /// Extracts the TexImage corresponding to the specified indice in the given texture array.
        /// </summary>
        /// <param name="array">The array.</param>
        /// <param name="indice">The indice.</param>
        /// <param name="minimumMipmapSize">The minimum size of the smallest mipmap.</param>
        /// <returns>The TexImage texture corresponding to the specified indice</returns>
        /// <exception cref="TextureToolsException">
        /// The indice you entered is not valid.
        /// or
        /// The minimup Mipmap size can't be negative. Put 0 or 1 for a complete Mipmap chain.
        /// </exception>
        public TexImage Extract(TexImage array, int indice, int minimumMipmapSize = 1)
        {
            if (indice < 0 || indice > array.ArraySize-1)
            {
                Log.Error("The indice you entered is not valid.");
                throw new TextureToolsException("The indice you entered is not valid.");
            }

            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 ArrayExtractionRequest(indice, minimumMipmapSize);

            ExecuteRequest(array, request);

            return request.Texture;
        }
        public void ExtractTest(string arrayFile, int indice)
        {
            TexImage array = TestTools.Load(dxtLib, arrayFile);

            var request = new ArrayExtractionRequest(indice, 16);
            library.Execute(array, request);
            array.CurrentLibrary = library;

            var extracted = request.Texture;

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

            extracted.Dispose();

            array.Dispose();
        }
Example #4
0
        /// <summary>
        /// Extracts one or every texture from a texture array.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="request">The request.</param>
        private void Extract(TexImage image, ArrayExtractionRequest request)
        {
            int subImageCount = image.SubImageArray.Length / image.ArraySize;

            // Retrieving the mipmap count and the subimage count corresponding to the minimum mipmap size requested
            int subImageCountWanted = 0;
            int newMipMapCount = 0;
            int curDepth = image.Depth == 1 ? 1 : image.Depth << 1;
            for (int i = 0; i < image.MipmapCount; ++i)
            {
                curDepth = curDepth > 1 ? curDepth >>= 1 : curDepth;

                if (image.SubImageArray[subImageCountWanted].Width <= request.MinimumMipMapSize || image.SubImageArray[subImageCountWanted].Height <= request.MinimumMipMapSize)
                {
                    subImageCountWanted += curDepth;
                    ++newMipMapCount;
                    break;
                }
                ++newMipMapCount;
                subImageCountWanted += curDepth;
            }

            if (request.Indice != -1)
            {
                Log.Info("Extracting texture " + request.Indice + " from the texture array ...");

                request.Texture = (TexImage)image.Clone(false);
                request.Texture.ArraySize = 1;
                request.Texture.MipmapCount = newMipMapCount;

                request.Texture.SubImageArray = new TexImage.SubImage[subImageCountWanted];

                int dataSize = 0;
                for (int i = 0; i < subImageCountWanted; ++i)
                {
                    request.Texture.SubImageArray[i] = image.SubImageArray[request.Indice * subImageCount + i];
                    dataSize += request.Texture.SubImageArray[i].SlicePitch;
                }

                request.Texture.Data = request.Texture.SubImageArray[0].Data;
                request.Texture.DataSize = dataSize;
            }
            else
            {
                Log.Info("Extracting each texture from the texture array ...");

                TexImage texture;
                for (int i = 0; i < image.ArraySize; ++i)
                {
                    texture = (TexImage)image.Clone(false);
                    texture.ArraySize = 1;
                    texture.SubImageArray = new TexImage.SubImage[subImageCountWanted];
                    texture.MipmapCount = newMipMapCount;

                    int dataSize = 0;
                    for (int j = 0; j < subImageCountWanted; ++j)
                    {
                        texture.SubImageArray[j] = image.SubImageArray[i * subImageCount + j];
                        dataSize += texture.SubImageArray[j].SlicePitch;
                    }

                    texture.Data = texture.SubImageArray[0].Data;
                    texture.DataSize = dataSize;

                    request.Textures.Add(texture);
                }
            }
        }
        public void ExtractAllTest(string file1, string file2)
        {
            var list = new List<TexImage>();
            for (int i = 0; i < 5; ++i)
            {
                var temp = new TexImage();
                fiLib.Execute(temp, new LoadingRequest(Module.PathToInputImages + file1, false));
                temp.Name = Path.GetFileName(file1);
                list.Add(temp);
                //Console.WriteLine("ExtractAll_" + Path.GetFileName(file1) + "." + TestTools.ComputeSHA1(temp.Data, temp.DataSize));

                temp = new TexImage();
                fiLib.Execute(temp, new LoadingRequest(Module.PathToInputImages + file2, false));
                temp.Name = Path.GetFileName(file2);
                list.Add(temp);
                //Console.WriteLine("ExtractAll_" + Path.GetFileName(file2) + "." + TestTools.ComputeSHA1(temp.Data, temp.DataSize));
            }

            var array = new TexImage();
            library.Execute(array, new ArrayCreationRequest(list));

            var request = new ArrayExtractionRequest(0);
            library.Execute(array, request);
            library.EndLibrary(array);

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

            for(int i = 0; i < array.ArraySize; ++i)
            {
                var temp = request.Textures[i];
                Assert.IsTrue(TestTools.ComputeSHA1(temp.Data, temp.DataSize).Equals(TestTools.GetInstance().Checksum["ExtractAll_" + list[i].Name]));
                temp.Dispose();
            }

            array.Dispose();

            foreach (var image in list)
            {
                image.Dispose();
            }
        }