public void TestClone() { TexImage clone = (TexImage)image.Clone(); Assert.IsTrue(image.Equals(clone)); clone.Dispose(); }
/// <summary> /// Inserts the specified node. /// </summary> /// <param name="node">The node.</param> /// <param name="tex">The tex.</param> /// <returns></returns> private bool Insert(Node node, TexImage tex) { if (node.IsEmpty() && node.IsLeaf()) { if (node.Width < tex.Width || node.Height < tex.Height) { return(false); } else if (node.Width == tex.Width && node.Height == tex.Height) { node.Texture = (TexImage)tex.Clone(false); return(true); } if (node.Width - tex.Width >= node.Height - tex.Height) { node.Left = new Node(node.X, node.Y, tex.Width, node.Height); node.Right = new Node(node.X + tex.Width, node.Y, node.Width - tex.Width, node.Height); return(Insert(node.Left, tex)); } else { node.Left = new Node(node.X, node.Y, node.Width, tex.Height); node.Right = new Node(node.X, node.Y + tex.Height, node.Width, node.Height - tex.Height); return(Insert(node.Left, tex)); } } else if (!node.IsLeaf()) { return(Insert(node.Left, tex) || Insert(node.Right, tex)); } else { return(false); } }
/// <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); } } }
/// <summary> /// Inserts the specified node. /// </summary> /// <param name="node">The node.</param> /// <param name="tex">The tex.</param> /// <returns></returns> private bool Insert(Node node, TexImage tex) { if (node.IsEmpty() && node.IsLeaf()) { if (node.Width < tex.Width || node.Height < tex.Height) { return false; } else if (node.Width == tex.Width && node.Height == tex.Height) { node.Texture = (TexImage)tex.Clone(false); return true; } if (node.Width - tex.Width >= node.Height - tex.Height) { node.Left = new Node(node.X, node.Y, tex.Width, node.Height); node.Right = new Node(node.X + tex.Width, node.Y, node.Width - tex.Width, node.Height); return Insert(node.Left, tex); } else { node.Left = new Node(node.X, node.Y, node.Width, tex.Height); node.Right = new Node(node.X, node.Y + tex.Height, node.Width, node.Height - tex.Height); return Insert(node.Left, tex); } } else if (!node.IsLeaf()) { return Insert(node.Left, tex) || Insert(node.Right, tex); } else { return false; } }