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.Equal(TestTools.GetInstance().Checksum["ArrayTexLibrary_Extract_" + arrayFile], TestTools.ComputeSHA1(extracted.Data, extracted.DataSize)); extracted.Dispose(); array.Dispose(); }
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(); } }
/// <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); } } }