Ejemplo n.º 1
0
            public void AddPalette(Palette palette, string name)
            {
                // Get palette data and add it
                List <byte> palData = new List <byte>(palette.GetPalette(0).ToBgr555());
                int         offset  = SubArraySearch(this.PaletteData, palData);

                // If not all colors are found... Add all
                int subOffset = palData.Count - (this.PaletteData.Count - offset);

                if (subOffset > 0)
                {
                    offset = this.PaletteData.Count;
                }

                // Add colors
                this.PaletteData.AddRange(palData);
                while (this.PaletteData.Count % 8 != 0)
                {
                    this.PaletteData.Add(0x00);
                }

                // Create palette info and add it
                Tex0.PaletteDataInfo palInfo = new Tex0.PaletteDataInfo();
                palInfo.Name   = name;
                palInfo.Offset = (uint)offset;
                this.PaletteInfo.AddElement(palInfo);
            }
Ejemplo n.º 2
0
        public EmguImage CreateBitmap(int texIdx, Palette palette)
        {
            // Get image
            EmguImage img = this.images[texIdx].CreateBitmap(palette, 0);

            // Set transparent color
            if (this.tex0.TextureInfo.Data[texIdx].Color0)
            {
                Color transparent = palette.GetPalette(0)[0];
                var   mask        = img.InRange(transparent, transparent);
                img.SetValue(0, mask);
            }

            return(img);
        }
Ejemplo n.º 3
0
        public EmguImage CreateBitmap(Palette palette, int paletteIndex)
        {
            if (!this.Format.IsIndexed())
            {
                Console.WriteLine("##WARNING## The palette is not required.");
                return(this.CreateBitmap());
            }

            EmguImage bmp = new EmguImage(this.width, this.height);

            bmp.SetPixels(
                0,
                0,
                this.width,
                this.height,
                InfoToIndexedColors(this.data, palette.GetPalette(paletteIndex))
                );

            return(bmp);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        public EmguImage CreateBitmap(Palette palette, int paletteIndex)
        {
            if (!this.Format.IsIndexed()) {
                Console.WriteLine("##WARNING## The palette is not required.");
                return this.CreateBitmap();
            }

            EmguImage bmp = new EmguImage(this.width, this.height);
            bmp.SetPixels(
                0,
                0,
                this.width,
                this.height,
                InfoToIndexedColors(this.data, palette.GetPalette(paletteIndex))
            );

            return bmp;
        }