Esempio n. 1
0
        private void changeFile(object sender, EventArgs e)
        {
            // When the file is changed, we need to display the new file.
            string filename = CB_File.Text;
            int    entry    = -1;
            // Find entry in darc
            var darc = darcs[CB_DARC.SelectedIndex];

            for (int i = 0; i < darc.Entries.Length; i++)
            {
                if (darc.FileNameTable[i].FileName == filename)
                {
                    entry = i;
                    break;
                }
            }
            if (entry < 0)
            {
                throw new Exception("File not found!?");
            }

            // Load file
            byte[] data    = darc.Data.Skip((int)(darc.Entries[entry].DataOffset - darc.Header.FileDataOffset)).Take((int)darc.Entries[entry].DataLength).ToArray();
            BCLIM  bclim   = BCLIM.analyze(data, filename);
            Image  CropBMP = bclim.GetBitmap();

            PB_Image.Image = CropBMP;
            // store image locally for saving if need be
            currentBytes = data;

            L_Dimensions.Text = $"Dimensions: {PB_Image.Width}w && {PB_Image.Height}h";
        }
Esempio n. 2
0
        public void makeBCLIM(string path)
        {
            byte[] data = BCLIM.getBCLIM(path, CB_OutFormat.Text[0]);

            string fp = Path.GetFileNameWithoutExtension(path);

            fp = "new_" + fp.Substring(fp.IndexOf('_') + 1);
            string pp      = Path.GetDirectoryName(path);
            string newPath = Path.Combine(pp, fp + ".bclim");

            var sfd = new SaveFileDialog
            {
                FileName         = newPath,
                InitialDirectory = pp,
                Filter           = "BCLIM File|*.bclim" +
                                   "|All Files|*.*"
            };

            if (CHK_AutoSaveBCLIM.Checked || (sfd.ShowDialog() == DialogResult.OK))
            {
                File.WriteAllBytes(sfd.FileName, data);
            }

            PB_BCLIM.Image = new Bitmap(path);
            var bclim = BCLIM.analyze(sfd.FileName);

            showPaletteBox(bclim);
            GB_Details.Visible = true;
            L_Details.Text     = String.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}", Environment.NewLine,
                                               bclim.FileFormat, bclim.Width, bclim.Height, bclim.TileWidth, bclim.TileHeight);
        }
Esempio n. 3
0
        private void insertFile(string path)
        {
            if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Overwrite image?"))
            {
                return;
            }
            byte[] data = File.ReadAllBytes(path);
            byte[] bclim;

            if (Path.GetExtension(path) == ".bclim") // bclim opened
            {
                var img = BCLIM.analyze(data, path);
                if (img.Width != PB_Image.Width || img.Height != PB_Image.Height)
                {
                    WinFormsUtil.Alert("Image sizes do not match.",
                                       $"Width: {img.Width} - {PB_Image.Width}\nHeight: {img.Height} - {PB_Image.Height}");
                    return;
                }
                bclim = data;
            }
            else // image
            {
                using (Stream BitmapStream = new MemoryStream(data))
                {
                    Image img = Image.FromStream(BitmapStream);
                    if (img.Width != PB_Image.Width || img.Height != PB_Image.Height)
                    {
                        WinFormsUtil.Alert("Image sizes do not match.",
                                           $"Width: {img.Width} - {PB_Image.Width}\nHeight: {img.Height} - {PB_Image.Height}");
                        return;
                    }
                    bclim = BCLIM.IMGToBCLIM(img, '9');
                }
            }

            string filename = CB_File.Text;
            int    entry    = -1;
            // Find entry in darc
            var darc = darcs[CB_DARC.SelectedIndex];

            for (int i = 0; i < darc.Entries.Length; i++)
            {
                if (darc.FileNameTable[i].FileName == filename)
                {
                    entry = i;
                    break;
                }
            }
            if (entry < 0)
            {
                throw new Exception("File not found!?");
            }

            DARC.insertFile(ref darc, entry, bclim);
            darcs[CB_DARC.SelectedIndex] = darc;

            // Trigger reloading of the image
            changeFile(null, null);
        }
Esempio n. 4
0
        // File Generation
        public void makeBMP(string path)
        {
            BCLIM.CLIM bclim = BCLIM.analyze(path);
            GB_Details.Visible = true;
            L_Details.Text     = String.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}", Environment.NewLine,
                                               bclim.FileFormat, bclim.Width, bclim.Height, bclim.TileWidth, bclim.TileHeight);

            var img = BCLIM.makeBMP(path, CHK_AutoSavePNG.Checked, !CHK_NoCrop.Checked);

            if (img == null)
            {
                return;
            }
            showPaletteBox(bclim);
            PB_BCLIM.Image = img;
        }
Esempio n. 5
0
        private void changeFile(object sender, EventArgs e)
        {
            // When the file is changed, we need to display the new file.
            string filename = CB_File.Text;
            int    entry    = -1;
            // Find entry in darc
            var darc = darcs[CB_DARC.SelectedIndex];

            for (int i = 0; i < darc.Entries.Length; i++)
            {
                if (darc.FileNameTable[i].FileName == filename)
                {
                    entry = i;
                    break;
                }
            }
            if (entry < 0)
            {
                throw new Exception("File not found!?");
            }

            // Load file
            byte[]     data  = darc.Data.Skip((int)(darc.Entries[entry].DataOffset - darc.Header.FileDataOffset)).Take((int)darc.Entries[entry].DataLength).ToArray();
            BCLIM.CLIM bclim = BCLIM.analyze(data, filename);
            Image      img   = BCLIM.getIMG(bclim);

            Rectangle cropRect = new Rectangle(0, 0, bclim.Width, bclim.Height);
            Bitmap    CropBMP  = new Bitmap(cropRect.Width, cropRect.Height);

            using (Graphics g = Graphics.FromImage(CropBMP))
            {
                g.DrawImage(img,
                            new Rectangle(0, 0, CropBMP.Width, CropBMP.Height),
                            cropRect,
                            GraphicsUnit.Pixel);
            }

            PB_Image.Image = CropBMP;
            // store image locally for saving if need be
            currentBytes = data;

            L_Dimensions.Text = $"Dimensions: {PB_Image.Width}w && {PB_Image.Height}h";
        }
Esempio n. 6
0
        public void makeBCLIM(string path)
        {
            string fp = Path.GetFileNameWithoutExtension(path);

            fp = "new_" + fp.Substring(fp.IndexOf('_') + 1);
            string pp = Path.GetDirectoryName(path);

            var sfd = new SaveFileDialog
            {
                FileName         = fp + (SaveAsBFLIM.Checked ? ".bflim" : ".bclim"),
                InitialDirectory = pp,
                Filter           = "BCLIM File|*.bclim" +
                                   "|BFLIM FILE|*.bflim" +
                                   "|All Files|*.*"
            };

            sfd.FilterIndex = SaveAsBFLIM.Checked ? 2 : 1;

            if (CHK_AutoSaveBCLIM.Checked || (sfd.ShowDialog() == DialogResult.OK))
            {
                bool FLIM = false;
                if (sfd.FileName.EndsWith(".bflim"))
                {
                    FLIM = true;
                }
                byte[] data = BCLIM.getBCLIM(path, CB_OutFormat.Text[0], FLIM);

                File.WriteAllBytes(sfd.FileName, data);

                PB_BCLIM.Image = new Bitmap(path);
                var bclim = BCLIM.analyze(sfd.FileName);
                showPaletteBox(bclim);
                GB_Details.Visible = true;
                L_Details.Text     = String.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}", Environment.NewLine,
                                                   bclim.FileFormat, bclim.Width, bclim.Height, 4, 4);
            }
        }
Esempio n. 7
0
        public void makeBMP(string path)
        {
            PaletteBox.Visible = false;
            pictureBox1.Image  = null;
            CLIM bclim = BCLIM.analyze(path);

            if (bclim.Magic != 0x4D494C43)
            {
                System.Media.SystemSounds.Beep.Play();
                return;
            }
            // Label up.
            L_FileFormat.Text = bclim.FileFormat.ToString();
            L_Width.Text      = bclim.Width.ToString();
            L_Height.Text     = bclim.Height.ToString();
            L_TileWidth.Text  = bclim.TileWidth.ToString();
            L_TileHeight.Text = bclim.TileHeight.ToString();
            groupBox2.Visible = true;

            L_FileFormat.Text = bclim.FileFormat.ToString();

            // Interpret data.
            int f = bclim.FileFormat;

            if (f > 13)
            {
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            Bitmap img = new Bitmap(1, 1);

            if (f == 7 && BitConverter.ToUInt16(bclim.Data, 0) == 2 && 0 == 0)
            {
                // PKM XY Format 7 (Color Palette)
                img = getIMG_XY7(bclim);
            }
            else if (f == 10 || f == 11)
            {
                img = getIMG_ETC(bclim); // etc1
            }
            else
            {
                img = getIMG(bclim);
            }

            Rectangle cropRect = new Rectangle(0, 0, bclim.Width, bclim.Height);
            Bitmap    CropBMP  = new Bitmap(cropRect.Width, cropRect.Height);

            using (Graphics g = Graphics.FromImage(CropBMP))
            {
                g.DrawImage(img,
                            new Rectangle(0, 0, CropBMP.Width, CropBMP.Height),
                            cropRect,
                            GraphicsUnit.Pixel);
            }
            if (CHK_NoCrop.Checked)
            {
                pictureBox1.Image = img;
            }
            else
            {
                pictureBox1.Image = CropBMP;
            }
            if (CHK_AutoSavePNG.Checked)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    //error will throw from here
                    CropBMP.Save(ms, ImageFormat.Png);
                    byte[] data = ms.ToArray();
                    File.WriteAllBytes(bclim.FilePath + "\\" + bclim.FileName + ".png", data);
                }
            }
        }