コード例 #1
0
        private void cmChangeFormat_Click(object sender, EventArgs e)
        {
            try
            {
                string tplName;
                TPL    tmpTpl = new TPL();
                Image  newImg;

                if (cbIcon.SelectedIndex == -1)
                {
                    tplName = cbBanner.SelectedItem.ToString().ToLower();
                    tmpTpl.LoadFile(bannerBin.Data[bannerBin.GetNodeIndex(tplName)]);
                }
                else
                {
                    tplName = cbIcon.SelectedItem.ToString().ToLower();
                    tmpTpl.LoadFile(iconBin.Data[iconBin.GetNodeIndex(tplName)]);
                }

                newImg = tmpTpl.ExtractTexture();
                TPL_TextureFormat tplFormat;
                TPL_PaletteFormat pFormat = TPL_PaletteFormat.RGB5A3;

                ToolStripMenuItem cmSender = sender as ToolStripMenuItem;
                switch (cmSender.Tag.ToString().ToLower())
                {
                case "i4":
                    tplFormat = TPL_TextureFormat.I4;
                    break;

                case "i8":
                    tplFormat = TPL_TextureFormat.I8;
                    break;

                case "ia4":
                    tplFormat = TPL_TextureFormat.IA4;
                    break;

                case "ia8":
                    tplFormat = TPL_TextureFormat.IA8;
                    break;

                case "rgb565":
                    tplFormat = TPL_TextureFormat.RGB565;
                    break;

                case "rgb5a3":
                    tplFormat = TPL_TextureFormat.RGB5A3;
                    break;

                case "ci8rgb5a3":
                    tplFormat = TPL_TextureFormat.CI8;
                    pFormat   = TPL_PaletteFormat.RGB5A3;
                    break;

                case "ci8rgb565":
                    tplFormat = TPL_TextureFormat.CI8;
                    pFormat   = TPL_PaletteFormat.RGB565;
                    break;

                case "ci8ia8":
                    tplFormat = TPL_TextureFormat.CI8;
                    pFormat   = TPL_PaletteFormat.IA8;
                    break;

                case "ci4rgb5a3":
                    tplFormat = TPL_TextureFormat.CI4;
                    pFormat   = TPL_PaletteFormat.RGB5A3;
                    break;

                case "ci4rgb565":
                    tplFormat = TPL_TextureFormat.CI4;
                    pFormat   = TPL_PaletteFormat.RGB565;
                    break;

                case "ci4ia8":
                    tplFormat = TPL_TextureFormat.CI4;
                    pFormat   = TPL_PaletteFormat.IA8;
                    break;

                default:
                    tplFormat = TPL_TextureFormat.RGBA8;
                    break;
                }

                if (tmpTpl.GetTextureFormat(0) == tplFormat)
                {
                    return;
                }

                tmpTpl.RemoveTexture(0);
                tmpTpl.AddTexture(newImg, tplFormat, pFormat);

                if (cbBanner.SelectedIndex != -1)
                {
                    bannerBin.ReplaceFile(bannerBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                    images[0][cbBanner.SelectedIndex].tplImage  = tmpTpl.ExtractTexture();
                    images[0][cbBanner.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                    if (images[0][cbBanner.SelectedIndex].tplFormat.StartsWith("CI"))
                    {
                        images[0][cbBanner.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                    }

                    pbPic.Image   = images[0][cbBanner.SelectedIndex].tplImage;
                    lbFormat.Text = images[0][cbBanner.SelectedIndex].tplFormat;
                    lbSize.Text   = string.Format("{0} x {1}", images[0][cbBanner.SelectedIndex].tplImage.Width, images[0][cbBanner.SelectedIndex].tplImage.Height);
                }
                else
                {
                    iconBin.ReplaceFile(iconBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                    images[1][cbIcon.SelectedIndex].tplImage  = tmpTpl.ExtractTexture();
                    images[1][cbIcon.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                    if (images[1][cbIcon.SelectedIndex].tplFormat.StartsWith("CI"))
                    {
                        images[1][cbIcon.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                    }

                    pbPic.Image   = images[1][cbIcon.SelectedIndex].tplImage;
                    lbFormat.Text = images[1][cbIcon.SelectedIndex].tplFormat;
                    lbSize.Text   = string.Format("{0} x {1}", images[1][cbIcon.SelectedIndex].tplImage.Width, images[1][cbIcon.SelectedIndex].tplImage.Height);
                }

                if (cbBanner.SelectedIndex != -1)
                {
                    cbBanner.Select();
                }
                else if (cbIcon.SelectedIndex != -1)
                {
                    cbIcon.Select();
                }

                if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8)
                {
                    lbTip.Visible = true;
                    tipTimer.Start();
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
コード例 #2
0
 private void btnRGB565_Click(object sender, System.EventArgs e)
 {
     pFormat = TPL_PaletteFormat.RGB565;
     this.Close();
 }
コード例 #3
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
        private void createFromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            tplHeader = new TPL_Header();
            tplTextureEntries = new List<TPL_TextureEntry>();
            tplTextureHeaders = new List<TPL_TextureHeader>();
            tplPaletteHeaders = new List<TPL_PaletteHeader>();
            textureData = new List<byte[]>();
            paletteData = new List<byte[]>();

            tplHeader.NumOfTextures = (uint)images.Length;

            for (int i = 0; i < images.Length; i++)
            {
                Image img = images[i];

                TPL_TextureEntry tempTexture = new TPL_TextureEntry();
                TPL_TextureHeader tempTextureHeader = new TPL_TextureHeader();
                TPL_PaletteHeader tempPaletteHeader = new TPL_PaletteHeader();
                byte[] tempTextureData = imageToTpl(img, tplFormats[i]);
                byte[] tempPaletteData = new byte[0];

                tempTextureHeader.TextureHeight = (ushort)img.Height;
                tempTextureHeader.TextureWidth = (ushort)img.Width;
                tempTextureHeader.TextureFormat = (uint)tplFormats[i];

                if (tplFormats[i] == TPL_TextureFormat.CI4 || tplFormats[i] == TPL_TextureFormat.CI8 || tplFormats[i] == TPL_TextureFormat.CI14X2)
                {
                    ColorIndexConverter cic = new ColorIndexConverter(imageToRgba(img), img.Width, img.Height, tplFormats[i], paletteFormats[i]);

                    tempTextureData = cic.Data;
                    tempPaletteData = cic.Palette;

                    tempPaletteHeader.NumberOfItems = (ushort)(tempPaletteData.Length / 2);
                    tempPaletteHeader.PaletteFormat = (uint)paletteFormats[i];
                }

                tplTextureEntries.Add(tempTexture);
                tplTextureHeaders.Add(tempTextureHeader);
                tplPaletteHeaders.Add(tempPaletteHeader);
                textureData.Add(tempTextureData);
                paletteData.Add(tempPaletteData);
            }
        }
コード例 #4
0
        private void cmFormat_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "PNG|*.png|JPG|*.jpg|GIF|*.gif|BMP|*.bmp|TPL|*.tpl|All|*.png;*.jpg;*.gif;*.bmp;*.tpl";
            ofd.FilterIndex = 6;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string tplName;
                    TPL    tmpTpl = new TPL();
                    Image  newImg;

                    if (cbIcon.SelectedIndex == -1)
                    {
                        tplName = cbBanner.SelectedItem.ToString().ToLower();
                        tmpTpl.LoadFile(bannerBin.Data[bannerBin.GetNodeIndex(tplName)]);
                    }
                    else
                    {
                        tplName = cbIcon.SelectedItem.ToString().ToLower();
                        tmpTpl.LoadFile(iconBin.Data[iconBin.GetNodeIndex(tplName)]);
                    }

                    if (!ofd.FileName.ToLower().EndsWith(".tpl"))
                    {
                        newImg = Image.FromFile(ofd.FileName);
                    }
                    else
                    {
                        TPL newTpl = TPL.Load(ofd.FileName);
                        newImg = newTpl.ExtractTexture();
                    }

                    Size tplSize = tmpTpl.GetTextureSize(0);

                    if (newImg.Width != tplSize.Width ||
                        newImg.Height != tplSize.Height)
                    {
                        newImg = resizeImage(newImg, tplSize.Width, tplSize.Height);
                    }

                    ToolStripMenuItem cmSender = sender as ToolStripMenuItem;
                    TPL_TextureFormat tplFormat;
                    TPL_PaletteFormat pFormat = TPL_PaletteFormat.RGB5A3;

                    switch (cmSender.Tag.ToString().ToLower())
                    {
                    case "i4":
                        tplFormat = TPL_TextureFormat.I4;
                        break;

                    case "i8":
                        tplFormat = TPL_TextureFormat.I8;
                        break;

                    case "ia4":
                        tplFormat = TPL_TextureFormat.IA4;
                        break;

                    case "ia8":
                        tplFormat = TPL_TextureFormat.IA8;
                        break;

                    case "rgb565":
                        tplFormat = TPL_TextureFormat.RGB565;
                        break;

                    case "rgb5a3":
                        tplFormat = TPL_TextureFormat.RGB5A3;
                        break;

                    case "ci8rgb5a3":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat   = TPL_PaletteFormat.RGB5A3;
                        break;

                    case "ci8rgb565":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat   = TPL_PaletteFormat.RGB565;
                        break;

                    case "ci8ia8":
                        tplFormat = TPL_TextureFormat.CI8;
                        pFormat   = TPL_PaletteFormat.IA8;
                        break;

                    case "ci4rgb5a3":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat   = TPL_PaletteFormat.RGB5A3;
                        break;

                    case "ci4rgb565":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat   = TPL_PaletteFormat.RGB565;
                        break;

                    case "ci4ia8":
                        tplFormat = TPL_TextureFormat.CI4;
                        pFormat   = TPL_PaletteFormat.IA8;
                        break;

                    default:
                        tplFormat = TPL_TextureFormat.RGBA8;
                        break;
                    }

                    tmpTpl.RemoveTexture(0);
                    tmpTpl.AddTexture(newImg, tplFormat, pFormat);

                    if (cbBanner.SelectedIndex != -1)
                    {
                        bannerBin.ReplaceFile(bannerBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                        images[0][cbBanner.SelectedIndex].tplImage  = tmpTpl.ExtractTexture();
                        images[0][cbBanner.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                        if (images[0][cbBanner.SelectedIndex].tplFormat.StartsWith("CI"))
                        {
                            images[0][cbBanner.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                        }

                        pbPic.Image   = images[0][cbBanner.SelectedIndex].tplImage;
                        lbFormat.Text = images[0][cbBanner.SelectedIndex].tplFormat;
                        lbSize.Text   = string.Format("{0} x {1}", images[0][cbBanner.SelectedIndex].tplImage.Width, images[0][cbBanner.SelectedIndex].tplImage.Height);
                    }
                    else
                    {
                        iconBin.ReplaceFile(iconBin.GetNodeIndex(tplName), tmpTpl.ToByteArray());
                        images[1][cbIcon.SelectedIndex].tplImage  = tmpTpl.ExtractTexture();
                        images[1][cbIcon.SelectedIndex].tplFormat = tmpTpl.GetTextureFormat(0).ToString();

                        if (images[1][cbIcon.SelectedIndex].tplFormat.StartsWith("CI"))
                        {
                            images[1][cbIcon.SelectedIndex].tplFormat += " + " + tmpTpl.GetPaletteFormat(0);
                        }

                        pbPic.Image   = images[1][cbIcon.SelectedIndex].tplImage;
                        lbFormat.Text = images[1][cbIcon.SelectedIndex].tplFormat;
                        lbSize.Text   = string.Format("{0} x {1}", images[1][cbIcon.SelectedIndex].tplImage.Width, images[1][cbIcon.SelectedIndex].tplImage.Height);
                    }

                    if (cbBanner.SelectedIndex != -1)
                    {
                        cbBanner.Select();
                    }
                    else if (cbIcon.SelectedIndex != -1)
                    {
                        cbIcon.Select();
                    }

                    if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8)
                    {
                        lbTip.Visible = true;
                        tipTimer.Start();
                    }
                }
                catch (Exception ex)
                { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
        }
コード例 #5
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
        /// <summary>
        /// Creates a TPL from multiple images.
        /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
        /// If you use a color indexed format, please provide at least one palette format.
        /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format!
        /// </summary>
        /// <param name="imagePaths"></param>
        /// <param name="tplFormats"></param>
        public void CreateFromImages(string[] imagePaths, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            if (tplFormats.Length < imagePaths.Length)
                throw new Exception("You must specify a format for each image!");

            List<Image> images = new List<Image>();
            foreach (string imagePath in imagePaths)
                images.Add(Image.FromFile(imagePath));

            createFromImages(images.ToArray(), tplFormats, paletteFormats);
        }
コード例 #6
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
        /// <summary>
        /// Creates a TPL from multiple images.
        /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
        /// If you use a color indexed format, please provide at least one palette format.
        /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format!
        /// </summary>
        /// <param name="images"></param>
        /// <param name="tplFormats"></param>
        public void CreateFromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            if (tplFormats.Length < images.Length)
                throw new Exception("You must specify a format for each image!");

            createFromImages(images, tplFormats, paletteFormats);
        }
コード例 #7
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
 /// <summary>
 /// Creates a TPL from an image.
 /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
 /// </summary>
 /// <param name="pathToImage"></param>
 /// <param name="tplFormat"></param>
 public void CreateFromImage(string pathToImage, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     CreateFromImages(new string[] { pathToImage }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat });
 }
コード例 #8
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
 /// <summary>
 /// Creates a TPL from an image.
 /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
 /// </summary>
 /// <param name="img"></param>
 /// <param name="tplFormat"></param>
 public void CreateFromImage(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     CreateFromImages(new Image[] { img }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat });
 }
コード例 #9
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
 /// <summary>
 /// Adds a Texture to the TPL.
 /// </summary>
 /// <param name="imagePath"></param>
 /// <param name="tplFormat"></param>
 public void AddTexture(string imagePath, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     Image img = Image.FromFile(imagePath);
     AddTexture(img, tplFormat, paletteFormat);
 }
コード例 #10
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
        /// <summary>
        /// Adds a Texture to the TPL.
        /// </summary>
        /// <param name="img"></param>
        /// <param name="tplFormat"></param>
        public void AddTexture(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
        {
            TPL_TextureEntry tempTexture = new TPL_TextureEntry();
            TPL_TextureHeader tempTextureHeader = new TPL_TextureHeader();
            TPL_PaletteHeader tempPaletteHeader = new TPL_PaletteHeader();
            byte[] tempTextureData = imageToTpl(img, tplFormat);
            byte[] tempPaletteData = new byte[0];

            tempTextureHeader.TextureHeight = (ushort)img.Height;
            tempTextureHeader.TextureWidth = (ushort)img.Width;
            tempTextureHeader.TextureFormat = (uint)tplFormat;

            if (tplFormat == TPL_TextureFormat.CI4 || tplFormat == TPL_TextureFormat.CI8 || tplFormat == TPL_TextureFormat.CI14X2)
            {
                ColorIndexConverter cic = new ColorIndexConverter(imageToRgba(img), img.Width, img.Height, tplFormat, paletteFormat);

                tempTextureData = cic.Data;
                tempPaletteData = cic.Palette;

                tempPaletteHeader.NumberOfItems = (ushort)(tempPaletteData.Length / 2);
                tempPaletteHeader.PaletteFormat = (uint)paletteFormat;
            }

            tplTextureEntries.Add(tempTexture);
            tplTextureHeaders.Add(tempTextureHeader);
            tplPaletteHeaders.Add(tempPaletteHeader);
            textureData.Add(tempTextureData);
            paletteData.Add(tempPaletteData);

            tplHeader.NumOfTextures++;
        }
コード例 #11
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
        public ColorIndexConverter(uint[] rgbaData, int width, int height, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat)
        {
            if (tplFormat != TPL_TextureFormat.CI4 && tplFormat != TPL_TextureFormat.CI8) // && tplFormat != TPL_TextureFormat.CI14X2)
                throw new Exception("Texture format must be either CI4 or CI8"); // or CI14X2!");
            if (paletteFormat != TPL_PaletteFormat.IA8 && paletteFormat != TPL_PaletteFormat.RGB565 && paletteFormat != TPL_PaletteFormat.RGB5A3)
                throw new Exception("Palette format must be either IA8, RGB565 or RGB5A3!");

            this.rgbaData = rgbaData;
            this.width = width;
            this.height = height;
            this.tplFormat = tplFormat;
            this.paletteFormat = paletteFormat;

            buildPalette();

            if (tplFormat == TPL_TextureFormat.CI4) toCI4();
            else if (tplFormat == TPL_TextureFormat.CI8) toCI8();
            else toCI14X2();
        }
コード例 #12
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
        /// <summary>
        /// Creates a TPL from multiple images.
        /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
        /// If you use a color indexed format, please provide at least one palette format.
        /// If you use multiple color indexed TPLs, the palette formats must have the same index as the image and tpl format!
        /// </summary>
        /// <param name="images"></param>
        /// <param name="tplFormats"></param>
        /// <returns></returns>
        public static TPL FromImages(Image[] images, TPL_TextureFormat[] tplFormats, TPL_PaletteFormat[] paletteFormats)
        {
            if (tplFormats.Length < images.Length)
                throw new Exception("You must specify a format for each image!");

            TPL tmpTpl = new TPL();
            tmpTpl.createFromImages(images, tplFormats, paletteFormats);
            return tmpTpl;
        }
コード例 #13
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
 /// <summary>
 /// Creates a TPL from an image.
 /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
 /// </summary>
 /// <param name="img"></param>
 /// <param name="tplFormat"></param>
 /// <returns></returns>
 public static TPL FromImage(Image img, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     return FromImages(new Image[] { img }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat });
 }
コード例 #14
0
ファイル: TPL.cs プロジェクト: dnasdw/showmiiwads-mod
 /// <summary>
 /// Creates a TPL from an image.
 /// Palette formats are only required for color indexed TPL formats (CI4, CI8 and CI14X2)!
 /// </summary>
 /// <param name="pathToImage"></param>
 /// <param name="tplFormat"></param>
 /// <returns></returns>
 public static TPL FromImage(string pathToImage, TPL_TextureFormat tplFormat, TPL_PaletteFormat paletteFormat = TPL_PaletteFormat.RGB5A3)
 {
     return FromImages(new string[] { pathToImage }, new TPL_TextureFormat[] { tplFormat }, new TPL_PaletteFormat[] { paletteFormat });
 }
コード例 #15
0
 private void btnRGB5A3_Click(object sender, System.EventArgs e)
 {
     pFormat = TPL_PaletteFormat.RGB5A3;
     this.Close();
 }