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); } }
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); } } }