public static Npck ChangeTextureImages(EmguImage[] images, int[] frames, Palette palOut, Npck original) { // Get an original texture file to get images and the texture to modify long start = original[0].Position; Btx0 oriTexture = new Btx0(original[0]); original[0].Position = start; Btx0 newTexture = new Btx0(original[0]); original[0].Position = start; // Create importer and remove all images TextureImporter importer = new TextureImporter(newTexture); importer.RemoveImages(); // Add images from arguments or original texture if not presents. List <int> frameList = frames.ToList(); for (int i = 0; i < oriTexture.NumTextures; i++) { int idx = frameList.IndexOf(i); // Set quantization to original palette or argument palette Color[] originalPalette = oriTexture.GetPalette(i).GetPalette(0); if (idx != -1 && palOut != null) { importer.Quantization = new FixedPaletteQuantization(palOut.GetPalette(idx)); } else { importer.Quantization = new FixedPaletteQuantization(originalPalette); } // Keep original color format and name string name = oriTexture.GetTextureName(i); importer.Format = oriTexture.GetImage(i).Format; // Keep original unknown values int[] texUnks = oriTexture.GetTextureUnknowns(i); int[] palUnks = oriTexture.GetPaletteUnknowns(i); // Import :D if (idx != -1) { importer.AddImage(images[idx], name, texUnks, palUnks, originalPalette); } else { importer.AddImage(oriTexture.CreateBitmap(i), name, texUnks, palUnks); } } // Write the new texture file MemoryStream textureStream = new MemoryStream(); newTexture.Write(textureStream); textureStream.Position = 0; // Create a copy of the NPCK from the original Npck npck = new Npck(); npck.AddSubfile(textureStream); for (int i = 1; i < 6; i++) { npck.AddSubfile(original[i]); } return(npck); }
public static Npck ChangeTextureImages(EmguImage[] images, int[] frames, Palette palOut, Npck original) { // Get an original texture file to get images and the texture to modify long start = original[0].Position; Btx0 oriTexture = new Btx0(original[0]); original[0].Position = start; Btx0 newTexture = new Btx0(original[0]); original[0].Position = start; // Create importer and remove all images TextureImporter importer = new TextureImporter(newTexture); importer.RemoveImages(); // Add images from arguments or original texture if not presents. List<int> frameList = frames.ToList(); for (int i = 0; i < oriTexture.NumTextures; i++) { int idx = frameList.IndexOf(i); // Set quantization to original palette or argument palette Color[] originalPalette = oriTexture.GetPalette(i).GetPalette(0); if (idx != -1 && palOut != null) importer.Quantization = new FixedPaletteQuantization(palOut.GetPalette(idx)); else importer.Quantization = new FixedPaletteQuantization(originalPalette); // Keep original color format and name string name = oriTexture.GetTextureName(i); importer.Format = oriTexture.GetImage(i).Format; // Keep original unknown values int[] texUnks = oriTexture.GetTextureUnknowns(i); int[] palUnks = oriTexture.GetPaletteUnknowns(i); // Import :D if (idx != -1) importer.AddImage(images[idx], name, texUnks, palUnks, originalPalette); else importer.AddImage(oriTexture.CreateBitmap(i), name, texUnks, palUnks); } // Write the new texture file MemoryStream textureStream = new MemoryStream(); newTexture.Write(textureStream); textureStream.Position = 0; // Create a copy of the NPCK from the original Npck npck = new Npck(); npck.AddSubfile(textureStream); for (int i = 1; i < 6; i++) npck.AddSubfile(original[i]); return npck; }