예제 #1
0
        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;
        }
예제 #2
0
        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;
        }