Example #1
0
        private void saveHpl_Click(object sender, EventArgs e)
        {
            DialogResult result = saveHplDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string filePath = saveHplDialog.FileName;
                try
                {
                    FileStream  fs       = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                    Hpal        hpalOut  = palFpac.palettes[(int)selectPalette.Value].subs[(int)selectSub.Value];
                    List <byte> hpalOutB = new List <byte>(hpalOut.header.Count + hpalOut.colorData.Count);
                    hpalOutB.AddRange(hpalOut.header);
                    hpalOutB.AddRange(hpalOut.colorData);
                    fs.Write(hpalOutB.ToArray(), 0, hpalOutB.Count);
                    fs.Close();
                }
                catch (IOException) { }
            }
        }
Example #2
0
        private void fromPng_Click(object sender, EventArgs e)
        {
            DialogResult result = openPngDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                string filePath = openPngDialog1.FileName;
                try
                {
                    Bitmap png1 = (Bitmap)Image.FromFile(filePath);

                    result = openPngDialog2.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        filePath = openPngDialog2.FileName;
                        try
                        {
                            Bitmap png2 = (Bitmap)Image.FromFile(filePath);

                            if (png1.Size == png2.Size)
                            {
                                Hpal tempHpal      = new Hpal(new List <byte>());
                                int  colorsChanged = 0;
                                if (fileType == ftFpac)
                                {
                                    tempHpal = palFpac.palettes[(int)selectPalette.Value].subs[(int)selectSub.Value];
                                }
                                else if (fileType == ftHpal)
                                {
                                    tempHpal = hpalFromOpen;
                                }

                                List <Thread> threads = new List <Thread>(tempHpal.colorData.Count / 4);
                                for (int i = 0; i < tempHpal.colorData.Count / 4; i++)
                                {
                                    List <byte> targetColor = tempHpal.colorData.Skip(i * 4).Take(3).ToList();

                                    for (int j = 0; j < png1.Height; j++)
                                    {
                                        for (int k = 0; k < png1.Width; k++)
                                        {
                                            if (png1.GetPixel(k, j).R == targetColor[2] &&
                                                png1.GetPixel(k, j).G == targetColor[1] &&
                                                png1.GetPixel(k, j).B == targetColor[0])
                                            {
                                                Color newColor = png2.GetPixel(k, j);
                                                tempHpal.colorData[i * 4]     = newColor.B;
                                                tempHpal.colorData[i * 4 + 1] = newColor.G;
                                                tempHpal.colorData[i * 4 + 2] = newColor.R;
                                                colorsChanged++;
                                                k = png1.Width;
                                                j = png1.Height;
                                            }
                                        }
                                    }
                                }

                                if (fileType == ftFpac)
                                {
                                    palFpac.palettes[(int)selectPalette.Value].subs[(int)selectSub.Value] = tempHpal;
                                }
                                else if (fileType == ftHpal)
                                {
                                    hpalFromOpen = tempHpal;
                                }

                                MessageBox.Show("Palette imported, " + colorsChanged.ToString() + " colors changed.");
                            }
                            else
                            {
                                currentFilePath.Text = strPngMismatch;
                            }
                        }
                        catch (IOException) { }
                    }
                }
                catch (IOException) { }
            }
        }
Example #3
0
        private void openPac_Click(object sender, EventArgs e)
        {
            DialogResult result = openPalPacDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string filePath = openPalPacDialog.FileName;
                try
                {
                    FileStream fs        = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                    byte[]     fileDataB = new byte[fs.Length];
                    fs.Read(fileDataB, 0, (int)(fs.Length));
                    fs.Flush();
                    fs.Close();
                    fileData = new List <byte>(fileDataB);

                    byte[] fileHead = fileData.Take(4).ToArray();
                    byte[] hexFPAC  = { 0x46, 0x50, 0x41, 0x43 };
                    byte[] hexHPAL  = { 0x48, 0x50, 0x41, 0x4C };
                    if (fileHead.SequenceEqual(hexFPAC))
                    {
                        byte[] temp  = fileData.Skip(4).Take(4).ToArray();
                        byte[] temp2 = fileData.Skip(32 + 16 + 8).Take(4).ToArray();
                        palFpac  = new PalFpac(BitConverter.ToInt32(temp, 0), BitConverter.ToInt32(temp2, 0), fileData);
                        fileType = ftFpac;
                    }
                    else if (fileHead.SequenceEqual(hexHPAL))
                    {
                        hpalFromOpen = new Hpal(fileData);
                        fileType     = ftHpal;
                    }

                    if (fileType == ftFpac)
                    {
                        savePac.Enabled        = true;
                        saveHpl.Enabled        = true;
                        importHpl.Enabled      = true;
                        currentFilePath.Text   = filePath;
                        selectPalette.Enabled  = true;
                        selectSub.Enabled      = true;
                        selectColor.Enabled    = true;
                        applyColor.Enabled     = true;
                        valueR.Enabled         = true;
                        valueG.Enabled         = true;
                        valueB.Enabled         = true;
                        buttonColorSel.Enabled = true;
                        enablePreview.Enabled  = false;
                        fromPng.Enabled        = true;

                        treeView1.Nodes.Clear();

                        for (int i = 0; i < palFpac.palettes.Count; i++)
                        {
                            treeView1.Nodes.Add(i.ToString());
                            for (int j = 0; j < palFpac.palettes[i].subs.Count; j++)
                            {
                                treeView1.Nodes[i].Nodes.Add(j.ToString());
                                for (int k = 0; k < palFpac.palettes[i].subs[j].colorData.Count / 4; k++)
                                {
                                    treeView1.Nodes[i].Nodes[j].Nodes.Add(k.ToString());
                                }
                            }
                        }

                        updateMaxPal();
                        updateColorFromFpac();
                    }
                    else if (fileType == ftHpal)
                    {
                        savePac.Enabled        = true;
                        saveHpl.Enabled        = false;
                        importHpl.Enabled      = false;
                        currentFilePath.Text   = filePath;
                        selectPalette.Enabled  = false;
                        selectSub.Enabled      = false;
                        selectColor.Enabled    = true;
                        applyColor.Enabled     = true;
                        valueR.Enabled         = true;
                        valueG.Enabled         = true;
                        valueB.Enabled         = true;
                        buttonColorSel.Enabled = true;
                        enablePreview.Enabled  = false;
                        fromPng.Enabled        = true;

                        treeView1.Nodes.Clear();

                        for (int i = 0; i < hpalFromOpen.colorData.Count / 4; i++)
                        {
                            treeView1.Nodes.Add(i.ToString());
                        }

                        updateMaxCol();
                        updateColor();
                    }
                    else
                    {
                        currentFilePath.Text = strWrongFormat;
                    }
                }
                catch (IOException) { }
            }
        }