Exemplo n.º 1
0
        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (trigger == false)
            {
                return;
            }
            if (int.Parse(texSize.Text.Split('x')[0]) * int.Parse(texSize.Text.Split('x')[1]) * int.Parse(comboBpp.Text) > 32768)
            {
                texBytes.ForeColor = Color.Red;
            }
            else
            {
                texBytes.ForeColor = Color.Black;
            }
            texBytes.Text = ((int.Parse(texSize.Text.Split('x')[0]) * int.Parse(texSize.Text.Split('x')[1]) * int.Parse(comboBpp.Text)) / 8).ToString() + " Bytes";
            int    x          = (int.Parse(texSize.Text.Split('x')[0]));
            int    y          = (int.Parse(texSize.Text.Split('x')[1]));
            Bitmap imagething = new Bitmap(x, y);

            texconv.textureGraphics = Graphics.FromImage(imagething);
            Bitmap             imagefile = new Bitmap(Path.GetDirectoryName(File.ReadAllLines("settings.bmfo")[0]) + "\\" + comboTexture.Text);
            Image <Bgra, byte> image     = new Image <Bgra, byte>(Path.GetDirectoryName(File.ReadAllLines("settings.bmfo")[0]) + "\\" + comboTexture.Text);

            double[] b = new double[imagefile.Height * imagefile.Width];
            double[] g = new double[imagefile.Height * imagefile.Width];
            double[] r = new double[imagefile.Height * imagefile.Width];
            double[] a = new double[imagefile.Height * imagefile.Width];
            y = imagefile.Height - 1;
            if (flipUVsToolStripMenuItem.Checked)
            {
                y = 0;
            }
            x = 0;
            for (int xy = 0; xy < imagefile.Height * imagefile.Width; xy++)
            {
                if (x == imagefile.Width)
                {
                    if (flipUVsToolStripMenuItem.Checked)
                    {
                        y += 2;
                    }
                    y--;
                    x = 0;
                }
                Bgra pixel = image[y, x];
                b[xy] = pixel.Blue;
                g[xy] = pixel.Green;
                r[xy] = pixel.Red;
                a[xy] = pixel.Alpha;
                x++;
            }
            double[][] rgba = { r, g, b, a }; fixCI();
            for (int xy = 0; xy < imagefile.Height * imagefile.Width; xy++)
            {
                texconv.CalculateTex(rgba, comboFormat.Text, int.Parse(comboBpp.Text), xy, true, texSize.Text);
            }
            texturePreview.Image = imagething;
            if (comboFormat.Text == "YUV")
            {
                if (comboBpp.Text != "16")
                {
                    MessageBox.Show("Invalid BPP for the selected format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    comboBpp.Text = "16";
                }
            }
            if (comboFormat.Text == "RGBA")
            {
                if (comboBpp.Text == "4" || comboBpp.Text == "8")
                {
                    MessageBox.Show("Invalid BPP for the selected format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    comboBpp.Text = "16";
                }
            }
            if (comboFormat.Text == "I")
            {
                if (comboBpp.Text == "32" || comboBpp.Text == "16")
                {
                    MessageBox.Show("Invalid BPP for the selected format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    comboBpp.Text = "4";
                }
            }
            if (comboFormat.Text == "IA")
            {
                if (comboBpp.Text == "32")
                {
                    MessageBox.Show("Invalid BPP for the selected format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    comboBpp.Text = "4";
                }
            }
            if (comboFormat.Text == "CI")
            {
                if (comboBpp.Text == "32" || comboBpp.Text == "16")
                {
                    MessageBox.Show("Invalid BPP for the selected format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    comboBpp.Text = "4";
                }
            }
            string[] formats;
            try { formats = File.ReadAllLines("settings.bmfo")[3].Split(); } catch { return; }
            formats[comboTexture.SelectedIndex] = comboFormat.Text + comboBpp.Text;
            string[] lines = File.ReadAllLines("settings.bmfo");
            lines[3] = string.Join(" ", formats);
            File.WriteAllLines("settings.bmfo", lines);
        }