public static Npck[] FromBackgroundImageShareImage(EmguImage[] images, BackgroundImporter importer) { Npck[] packs = new Npck[images.Length]; EmguImage combinedImg = images[0].Clone(); // Concatenate images for (int i = 1; i < images.Length; i++) { combinedImg = combinedImg.ConcateHorizontal(images[i]); } if (!(importer.Quantization is FixedPaletteQuantization)) { // Get quantization to share palette NdsQuantization quantization = new NdsQuantization(); quantization.Quantizate(combinedImg); importer.Quantization = new FixedPaletteQuantization(quantization.Palette); } // Get the palette and image file that it's shared MemoryStream nclrStr = new MemoryStream(); MemoryStream ncgrStr = new MemoryStream(); importer.ImportBackground(combinedImg, null, ncgrStr, nclrStr); nclrStr.Position = ncgrStr.Position = 0; // Get the array of pixel from the image file Ncgr ncgr = new Ncgr(ncgrStr); Pixel[] fullImage = ncgr.GetPixels(); ncgrStr.Position = 0; // Create packs for (int i = 0; i < images.Length; i++) { MemoryStream nscrStr = new MemoryStream(); importer.ImportBackgroundShareImage(images[i], fullImage, nscrStr); nscrStr.Position = 0; // Only first pack file has palette and image files if (i == 0) { packs[i] = Npck.FromBackgroundStreams(nscrStr, ncgrStr, nclrStr); } else { packs[i] = Npck.FromBackgroundStreams(nscrStr, null, null); } } combinedImg.Dispose(); return(packs); }
public static Npck FromBackgroundImage(EmguImage image) { MemoryStream nclrStr = new MemoryStream(); MemoryStream ncgrStr = new MemoryStream(); MemoryStream nscrStr = new MemoryStream(); BackgroundImporter importer = new BackgroundImporter(); importer.ImportBackground(image, nscrStr, ncgrStr, nclrStr); nclrStr.Position = ncgrStr.Position = nscrStr.Position = 0; return(Npck.FromBackgroundStreams(nscrStr, ncgrStr, nclrStr)); }
public static Npck[] FromBackgroundImageSharePaletteChangeDepth(string[] images, Npck original, bool partialImage = false) { EmguImage[] emguImgs = new EmguImage[images.Length]; for (int i = 0; i < images.Length; i++) { emguImgs[i] = new EmguImage(images[i]); } BackgroundImporter importer = new BackgroundImporter(); importer.SetOriginalSettings(original[6], original[1], original[0]); importer.PartialImage = partialImage; // Create packs Npck[] packs = new Npck[images.Length]; for (int i = 0; i < images.Length; i++) { MemoryStream nclrStr = new MemoryStream(); MemoryStream ncgrStr = new MemoryStream(); MemoryStream nscrStr = new MemoryStream(); if (i > 0) { importer.PaletteMode = PaletteMode.Palette16_16; importer.Format = ColorFormat.Indexed_4bpp; } importer.ImportBackground(emguImgs[i], nscrStr, ncgrStr, nclrStr); nclrStr.Position = ncgrStr.Position = nscrStr.Position = 0; // Only first pack file has palette file if (i == 0) { packs[i] = Npck.FromBackgroundStreams(nscrStr, ncgrStr, nclrStr); } else { packs[i] = Npck.FromBackgroundStreams(nscrStr, ncgrStr, null); } } // Dispose images foreach (EmguImage emgu in emguImgs) { emgu.Dispose(); } return(packs); }
public static Npck[] FromBackgroundImageSharePalette(EmguImage[] images, BackgroundImporter importer) { if (!(importer.Quantization is FixedPaletteQuantization)) { // Concatenate images EmguImage combinedImg = images[0].Clone(); for (int i = 1; i < images.Length; i++) { combinedImg = combinedImg.ConcateHorizontal(images[i]); } NdsQuantization quantization = new NdsQuantization(); quantization.Quantizate(combinedImg); importer.Quantization = new FixedPaletteQuantization(quantization.Palette); combinedImg.Dispose(); } // Create packs Npck[] packs = new Npck[images.Length]; for (int i = 0; i < images.Length; i++) { MemoryStream nclrStr = new MemoryStream(); MemoryStream ncgrStr = new MemoryStream(); MemoryStream nscrStr = new MemoryStream(); importer.ImportBackground(images[i], nscrStr, ncgrStr, nclrStr); nclrStr.Position = ncgrStr.Position = nscrStr.Position = 0; // Only first pack file has palette file if (i == 0) { packs[i] = Npck.FromBackgroundStreams(nscrStr, ncgrStr, nclrStr); } else { packs[i] = Npck.FromBackgroundStreams(nscrStr, ncgrStr, null); } } return(packs); }
public static Npck FromBackgroundImage(EmguImage image, Npck original, bool changePalette = false) { if (original[0] == null || original[1] == null) { throw new FormatException( "Can not import image.\n" + "There is not palette or image in the original pack." ); } MemoryStream nclrStr = new MemoryStream(); MemoryStream ncgrStr = new MemoryStream(); MemoryStream nscrStr = new MemoryStream(); // Import image BackgroundImporter importer = new BackgroundImporter(); importer.SetOriginalSettings(original[2], original[1], original[0], changePalette); importer.ImportBackground(image, nscrStr, ncgrStr, nclrStr); nclrStr.Position = ncgrStr.Position = nscrStr.Position = 0; return(Npck.FromBackgroundStreams(nscrStr, ncgrStr, nclrStr)); }