コード例 #1
0
        private void OrignalFilenameSelectButton_Click(object sender, EventArgs e)
        {
            string filename = ImageFormRef.OpenFilenameDialogFullColor(this);

            if (filename == "")
            {
                return;
            }

            this.OrignalFilename.Text = filename;
        }
コード例 #2
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            if (!InputFormRef.CheckWriteProtectionID00())
            {
                return;
            }

            string imagefilename = ImageFormRef.OpenFilenameDialogFullColor(this);

            if (imagefilename == "")
            {
                return;
            }

            Bitmap fullColor = ImageUtil.OpenLowBitmap(imagefilename); //bitmapそのものの色で開く.

            if (fullColor == null)
            {
                return;
            }

            if (fullColor.Width == 128 && fullColor.Height == 112)
            {
                Bitmap seetbitmap;
                if (ImageUtil.Is16ColorBitmap(fullColor))
                {
                    seetbitmap = ImageUtil.OpenBitmap(imagefilename); //16色に変換して開く.
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                    seetbitmap = ImageUtil.ConvertPaletteTransparentUI(seetbitmap);
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                }
                else
                {//取り込めないので提案をする.
                    ImagePortraitImporterForm f = (ImagePortraitImporterForm)InputFormRef.JumpFormLow <ImagePortraitImporterForm>();
                    f.SetOrignalImage(fullColor
                                      , 0, 0, (int)this.B12.Value, (int)this.B13.Value);
                    f.ShowDialog();

                    seetbitmap = f.GetResultBitmap();
                    if (seetbitmap == null)
                    {
                        fullColor.Dispose();
                        return;
                    }
                    if (f.IsDetailMode())
                    {
                        U.ForceUpdate(this.B12, f.GetMouthBlockX());
                        U.ForceUpdate(this.B13, f.GetMouthBlockY());
                    }
                }

                Bitmap seet;
                Bitmap map_face;
                BuildPortraitSeetFE6(seetbitmap, out seet, out map_face);

                byte[] seet_image = ImageUtil.ImageToByte16Tile(seet, seet.Width, seet.Height);
                seet_image = U.subrange(seet_image, 0, (uint)(seet_image.Length - (3 * (8 * 8 / 2) * 8))); //FE6の場合データサイズがさらに小さくなる
                byte[] map_face_image = ImageUtil.ImageToByte16Tile(map_face, map_face.Width, map_face.Height);
                byte[] palette        = ImageUtil.ImageToPalette(seet, 1);


                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    //画像等データの書き込み
                    Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                    this.InputFormRef.WriteImageData(this.D0, seet_image, true, undodata);      //FE6は顔画像も圧縮する
                    this.InputFormRef.WriteImageData(this.D4, map_face_image, false, undodata); //FE6のマップ顔は無圧縮
                    this.InputFormRef.WriteImageData(this.D8, palette, false, undodata);
                    Program.Undo.Push(undodata);
                }

                //ポインタの書き込み
                this.WriteButton.PerformClick();
            }
            else if (fullColor.Width == 80 &&
                     (fullColor.Height == 80 || fullColor.Height == 72))
            {
                Bitmap seetbitmap = ImageUtil.OpenBitmap(imagefilename); //16色に変換して開く.
                if (seetbitmap == null)
                {
                    fullColor.Dispose();
                    return;
                }
                seetbitmap = ImageUtil.ConvertPaletteTransparentUI(seetbitmap);
                if (seetbitmap == null)
                {
                    fullColor.Dispose();
                    return;
                }

                byte[] class_image = ImageUtil.ImageToByte16Tile(seetbitmap, seetbitmap.Width, seetbitmap.Height);
                byte[] palette     = ImageUtil.ImageToPalette(seetbitmap, 1);

                using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
                {
                    //画像等データの書き込み
                    Undo.UndoData undodata = Program.Undo.NewUndoData(this);
                    this.InputFormRef.WriteImageData(this.D0, class_image, true, undodata); //クラス画像は圧縮されている.
                    this.InputFormRef.WriteImageData(this.D8, palette, false, undodata);
                    Program.Undo.Push(undodata);
                }

                //顔パラメーターは使わないので0を入れる.
                U.ForceUpdate(this.D4, 0);
                U.ForceUpdate(this.B12, 0);
                U.ForceUpdate(this.B13, 0);

                //ポインタの書き込み
                this.WriteButton.PerformClick();
            }
            else
            {
                R.ShowStopError("画像サイズが正しくありません。\r\n顔画像ならば、128x112 \r\nクラス画像ならば 80x80 である必要があります。\r\n\r\n選択された画像のサイズ Width:{0} Height:{1}", fullColor.Width, fullColor.Height, Width, Height);
            }
        }
コード例 #3
0
        public bool MakePaletteBitmapToUIEx(int palette_index, Bitmap hintBitmap)
        {
            Debug.Assert(ImageUtil.Is16ColorBitmap(hintBitmap));

            string imagefilename = ImageFormRef.OpenFilenameDialogFullColor(this.SelfForm);

            if (imagefilename == "")
            {
                return(false);
            }

            Bitmap fullColor = ImageUtil.OpenLowBitmap(imagefilename); //bitmapそのものの色で開く.

            if (fullColor == null)
            {
                return(false);
            }

            Bitmap bitmap;

            if (palette_index <= 0)
            {
                if (!ImageUtil.Is16ColorBitmap(fullColor))
                {
                    R.ShowStopError("パレット数が正しくありません。\r\n{1}種類以下(16色*{1}種類) でなければなりません。\r\n\r\n選択された画像のパレット種類:{0}種類", palette_index, "fullcolor");
                    fullColor.Dispose();
                    return(false);
                }
                bitmap = ImageUtil.OpenBitmap(imagefilename); //16色に変換して開く.
                if (bitmap == null)
                {
                    fullColor.Dispose();
                    return(false);
                }
                if (ImageUtil.IsFullColorBitmap(fullColor) ||
                    !ImageUtil.CheckPaletteTransparent(bitmap))
                {//パレットではない画像なので何かしらの変換が必要
                    if (hintBitmap == null ||
                        (hintBitmap.Width != fullColor.Width && hintBitmap.Height != fullColor.Height))
                    {
                        DialogResult dr = R.ShowNoYes("この画像のパレットは破壊されています。\r\n復元しようとしましたが、元画像と異なる画像のため、復元できませんでした。\r\n無視して強引にインポートすることは可能ですが、継続しますか?");
                        if (dr == DialogResult.No)
                        {
                            fullColor.Dispose();
                            bitmap.Dispose();
                            return(false);
                        }
                    }
                    else
                    {//壊れたパレットを復元します.
                        Bitmap recolor = ImageUtil.ReColorPaletteWithHint(bitmap, hintBitmap);

                        ErrorPaletteMissMatchForm f = (ErrorPaletteMissMatchForm)InputFormRef.JumpFormLow <ErrorPaletteMissMatchForm>();
                        f.SetOrignalImage(bitmap, hintBitmap);
                        f.SetReOrderImage1(recolor, hintBitmap);
                        f.ShowDialog();
                        bitmap = f.GetResultBitmap();
                        if (bitmap == null)
                        {
                            fullColor.Dispose();
                            return(false);
                        }
                    }
                }
            }
            else
            {                                                 //16色以上
                bitmap = ImageUtil.OpenBitmap(imagefilename); //16色に変換して開く.
                if (bitmap == null)
                {
                    fullColor.Dispose();
                    return(false);
                }

                int bitmap_palette_count = ImageUtil.GetPalette16Count(bitmap);
                if (bitmap_palette_count > palette_index)
                {
                    R.ShowStopError("パレット数が正しくありません。\r\n{1}種類以下(16色*{1}種類) でなければなりません。\r\n\r\n選択された画像のパレット種類:{0}種類", bitmap_palette_count, palette_index);
                    fullColor.Dispose();
                    bitmap.Dispose();
                    return(false);
                }

                if (ImageUtil.IsFullColorBitmap(fullColor))
                {//パレットではない画像なので何かしらの変換が必要
                    if (hintBitmap == null ||
                        (hintBitmap.Width != fullColor.Width && hintBitmap.Height != fullColor.Height))
                    {
                        DialogResult dr = R.ShowNoYes("この画像のパレットは破壊されています。\r\n復元しようとしましたが、元画像と異なる画像のため、復元できませんでした。\r\n無視して強引にインポートすることは可能ですが、継続しますか?");
                        if (dr == DialogResult.No)
                        {
                            fullColor.Dispose();
                            bitmap.Dispose();
                            return(false);
                        }
                    }
                    else
                    {//壊れたパレットを復元します.
                        Bitmap recolor = ImageUtil.ReColorPaletteWithHint(bitmap, hintBitmap);

                        ErrorPaletteMissMatchForm f = (ErrorPaletteMissMatchForm)InputFormRef.JumpFormLow <ErrorPaletteMissMatchForm>();
                        f.SetOrignalImage(bitmap, hintBitmap);
                        f.SetReOrderImage1(recolor, hintBitmap);
                        f.ShowDialog();
                        bitmap = f.GetResultBitmap();
                        if (bitmap == null)
                        {
                            fullColor.Dispose();
                            return(false);
                        }
                    }
                }
            }

            MakePaletteBitmapToUI(bitmap, palette_index);
            fullColor.Dispose();
            bitmap.Dispose();
            return(true);
        }
コード例 #4
0
        public static bool ImportBorder(Form self, uint origin_x, uint origin_y, out byte[] out_image, out byte[] out_oam)
        {
            out_image = null;
            out_oam   = null;
            string imagefilename = ImageFormRef.OpenFilenameDialogFullColor(self);

            if (imagefilename == "")
            {
                R.ShowStopError("ファイルがありません。\r\nファイル名:{0}", imagefilename);
                return(false);
            }
            string name_filename = MakeBorderNameImageFileName(imagefilename);

            if (!File.Exists(name_filename))
            {
                R.ShowStopError("ファイルがありません。\r\nファイル名:{0}", name_filename);
                return(false);
            }
            string basedir = Path.GetDirectoryName(imagefilename);

            List <uint> battleOAMSplit = new List <uint>();

            ImageUtilOAM.ImportOAM oam = new ImageUtilOAM.ImportOAM();
            oam.SetIsBorderAPOAM(true);
            oam.SetBaseDir(basedir);
            oam.MakeBorderAP(imagefilename);
            battleOAMSplit.Add(oam.GetOAMByteCount());
            oam.MakeBorderAP(name_filename);
            oam.Term();
            battleOAMSplit.Add(oam.GetOAMByteCount());

            List <ImageUtilOAM.image_data> images = oam.GetImages();

            if (images.Count >= 2)
            {
                R.ShowStopError("画像が大きすぎて、256x160のシートに入りきりませんでした");
                return(false);
            }

            byte[] battleOAM = oam.GetRightToLeftOAM();

            List <uint> apOAMSplit = new List <uint>();

            byte[] apOAM = BattleOAMToAPOAM(battleOAM, battleOAMSplit, origin_x, origin_y, apOAMSplit);
            if (apOAM == null)
            {
                return(false);
            }

            List <byte> newOam = new List <byte>();

            //ap_data header
            U.append_u16(newOam, 4); //ap_data header SHORT (frame_list - ap_data)
            U.append_u16(newOam, 8); //ap_data header SHORT (anim_list - ap_data)
            //frame_list
            uint addr_frame_list = (uint)newOam.Count;

            U.append_u16(newOam, 0); //SHORT (frame_0 - frame_list)
            U.append_u16(newOam, 0); //SHORT (frame_1 - frame_list)
            //anim_list
            uint addr_anim_list = (uint)newOam.Count;

            U.append_u16(newOam, 0); //SHORT (anim_0 - anim_list)
            U.append_u16(newOam, 0); //SHORT (anim_1 - anim_list)
            //frame_0
            uint addr_frame_0 = (uint)newOam.Count;

            U.append_u16(newOam, apOAMSplit[0] / 6); // oam entries
            for (uint i = 0; i < apOAMSplit[0]; i++)
            {
                U.append_u8(newOam, apOAM[i]);  // oam entries
            }
            //frame_1
            uint addr_frame_1 = (uint)newOam.Count;

            U.append_u16(newOam, (apOAMSplit[1] - apOAMSplit[0]) / 6); // oam entries
            for (uint i = apOAMSplit[0]; i < apOAMSplit[1]; i++)
            {
                U.append_u8(newOam, apOAM[i]); // oam entries
            }
            //anim_0:
            uint addr_anim_0 = (uint)newOam.Count;

            U.append_u16(newOam, 4); U.append_u16(newOam, 0);
            U.append_u16(newOam, 0);  U.append_u16(newOam, 0xffff);// loop back to start
            //anim_1:
            uint addr_anim_1 = (uint)newOam.Count;

            U.append_u16(newOam, 4); U.append_u16(newOam, 1);
            U.append_u16(newOam, 0); U.append_u16(newOam, 0xffff);// loop back to start

            out_oam = newOam.ToArray();
            //フレームの位置を書き込む
            U.write_u16(out_oam, 4, addr_frame_0 - addr_frame_list); //SHORT  (frame_0 - frame_list)
            U.write_u16(out_oam, 6, addr_frame_1 - addr_frame_list); //SHORT  (frame_1 - frame_list)
            U.write_u16(out_oam, 8, addr_anim_0 - addr_anim_list);   //SHORT  (anim_0 - anim_list)
            U.write_u16(out_oam, 10, addr_anim_1 - addr_anim_list);  //SHORT (anim_1 - anim_list)

            out_image = LZ77.decompress(images[0].data, 0);
            return(true);
        }