private static void ExportTextureWithColors(string n3dPath, string outPath, string colors) { string name = Path.GetFileNameWithoutExtension(n3dPath); string path = Path.Combine(outPath, name); // Get texture file Npck pack = new Npck(n3dPath); Btx0 texture = new Btx0(pack[0]); // Parse colors string[] strColors = colors.Split(' '); Color[] newColors = new Color[strColors.Length]; for (int i = 0; i < strColors.Length; i++) { int hexColor = Convert.ToInt32(strColors[i], 16); newColors[i] = new Color(); newColors[i].Alpha = 255; newColors[i].Red = (hexColor >> 00) & 0xFF; newColors[i].Green = (hexColor >> 08) & 0xFF; newColors[i].Blue = (hexColor >> 16) & 0xFF; } // Create and export palette Palette palette = new Palette(newColors); palette.ToWinPaletteFormat(path + "_palGimp.pal", 0, true); palette.ToWinPaletteFormat(path + "_pal.pal", 0, false); palette.CreateBitmap(0).Save(path + "_pal.png"); // For each image, set new palette and export it for (int i = 0; i < texture.NumTextures; i++) { texture.CreateBitmap(i, palette).Save(path + "_" + i.ToString() + ".png"); } }
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; }
private static void SearchPalette(string packPath, string imgPath, int idx) { // Get new image EmguImage newImg = new EmguImage(imgPath); // Get original image Npck pack = new Npck(packPath); Btx0 texture = new Btx0(pack[0]); Image originalImg = texture.GetImage(idx); Pixel[] pixels = originalImg.GetPixels(); // For each pixel, set palette color in the position given by original image Color[] palette = new Color[originalImg.Format.MaxColors()]; for (int y = 0; y < newImg.Height; y++) { for (int x = 0; x < newImg.Width; x++) { // Get target color Color px = newImg[y, x]; // Get palette color index uint index = pixels[y * newImg.Width + x].Info; // If we have already set this color, and it does not match with // this pixel... Error! if (palette[index].Alpha != 0 && !palette[index].Equals(px)) { Console.WriteLine("Can not find a valid color combination"); return; } // If the color has not been set, set it! if (palette[index].Alpha == 0) { palette[index] = px; } } } // Print palette Console.WriteLine("Palette found"); string xmlColor = " <Color red=\"{0}\" green=\"{1}\" blue=\"{2}\" />"; foreach (Color c in palette) { Console.WriteLine(xmlColor, c.Red, c.Green, c.Blue); } }
private static void ExportTexture(string n3dPath, string outPath) { string filename = Path.GetFileNameWithoutExtension(n3dPath); // Get texture file Npck pack = new Npck(n3dPath); Btx0 texture = new Btx0(pack[0]); // Export images and palettes for (int i = 0; i < texture.NumTextures; i++) { string name = filename + "_" + i.ToString(); string path = Path.Combine(outPath, name); if (File.Exists(path + ".png")) { path += Path.GetRandomFileName(); } texture.CreateBitmap(i).Save(path + ".png"); texture.GetPalette(i).ToWinPaletteFormat(path + "_gimp.pal", 0, true); texture.GetPalette(i).ToWinPaletteFormat(path + ".pal", 0, false); texture.GetPalette(i).ToAcoFormat(path + ".aco", 0); } }
public TextureImporter(Btx0 texture) { this.Texture = texture; this.Format = ColorFormat.Indexed_8bpp; this.Quantization = new NdsQuantization(); }
private static void SearchPalette(string packPath, string imgPath, int idx) { // Get new image EmguImage newImg = new EmguImage(imgPath); // Get original image Npck pack = new Npck(packPath); Btx0 texture = new Btx0(pack[0]); Image originalImg = texture.GetImage(idx); Pixel[] pixels = originalImg.GetPixels(); // For each pixel, set palette color in the position given by original image Color[] palette = new Color[originalImg.Format.MaxColors()]; for (int y = 0; y < newImg.Height; y++) { for (int x = 0; x < newImg.Width; x++) { // Get target color Color px = newImg[y, x]; // Get palette color index uint index = pixels[y * newImg.Width + x].Info; // If we have already set this color, and it does not match with // this pixel... Error! if (palette[index].Alpha != 0 && !palette[index].Equals(px)) { Console.WriteLine("Can not find a valid color combination"); return; } // If the color has not been set, set it! if (palette[index].Alpha == 0) palette[index] = px; } } // Print palette Console.WriteLine("Palette found"); string xmlColor = " <Color red=\"{0}\" green=\"{1}\" blue=\"{2}\" />"; foreach (Color c in palette) Console.WriteLine(xmlColor, c.Red, c.Green, c.Blue); }
private static void ExportTextureWithColors(string n3dPath, string outPath, string colors) { string name = Path.GetFileNameWithoutExtension(n3dPath); string path = Path.Combine(outPath, name); // Get texture file Npck pack = new Npck(n3dPath); Btx0 texture = new Btx0(pack[0]); // Parse colors string[] strColors = colors.Split(' '); Color[] newColors = new Color[strColors.Length]; for (int i = 0; i < strColors.Length; i++) { int hexColor = Convert.ToInt32(strColors[i], 16); newColors[i] = new Color(); newColors[i].Alpha = 255; newColors[i].Red = (hexColor >> 00) & 0xFF; newColors[i].Green = (hexColor >> 08) & 0xFF; newColors[i].Blue = (hexColor >> 16) & 0xFF; } // Create and export palette Palette palette = new Palette(newColors); palette.ToWinPaletteFormat(path + "_palGimp.pal", 0, true); palette.ToWinPaletteFormat(path + "_pal.pal", 0, false); palette.CreateBitmap(0).Save(path + "_pal.png"); // For each image, set new palette and export it for (int i = 0; i < texture.NumTextures; i++) texture.CreateBitmap(i, palette).Save(path + "_" + i.ToString() + ".png"); }
private static void ExportTexture(string n3dPath, string outPath) { string filename = Path.GetFileNameWithoutExtension(n3dPath); // Get texture file Npck pack = new Npck(n3dPath); Btx0 texture = new Btx0(pack[0]); // Export images and palettes for (int i = 0; i < texture.NumTextures; i++) { string name = filename + "_" + i.ToString(); string path = Path.Combine(outPath, name); if (File.Exists(path + ".png")) path += Path.GetRandomFileName(); texture.CreateBitmap(i).Save(path + ".png"); texture.GetPalette(i).ToWinPaletteFormat(path + "_gimp.pal", 0, true); texture.GetPalette(i).ToWinPaletteFormat(path + ".pal", 0, false); texture.GetPalette(i).ToAcoFormat(path + ".aco", 0); } }