static ImageUtilOAM.animedata ImportObjImageToData(string imagefilename
                                                           , string basedir
                                                           , Dictionary <string, ImageUtilOAM.animedata> animeDic
                                                           , ImageUtilOAM.ImportOAM oam
                                                           , ref uint image_number
                                                           , out string errormessage
                                                           )
        {
            string key = "OBJ" + imagefilename;

            ImageUtilOAM.animedata magic_animedata;
            if (animeDic.ContainsKey(key))
            {
                errormessage = "";

                magic_animedata = animeDic[key];
                return(magic_animedata);
            }
            string hash = ImageUtil.HashBitmap(imagefilename, basedir);

            magic_animedata = ImageUtilOAM.FindHash(hash, animeDic);
            if (magic_animedata != null)
            {
                errormessage = "";
                return(magic_animedata);
            }


            Bitmap loadbitmap = ImageUtil.OpenBitmap(ImageUtilMagicFEditor.GetFullPath(imagefilename, basedir), null, out errormessage);

            if (loadbitmap == null)
            {
                return(null);
            }

            int width  = ImageUtilMagicFEditor.SRC_OBJ_SEAT_TILE_WIDTH * 8 - 16;
            int height = ImageUtilMagicFEditor.SRC_OBJ_SEAT_TILE_HEIGHT * 8;

            if (loadbitmap.Width < width || loadbitmap.Height < height)
            {
                errormessage = R.Error("画像サイズが正しくありません。\r\nWidth:{2} Height:{3} でなければなりません。\r\n\r\n選択された画像のサイズ Width:{0} Height:{1}", loadbitmap.Width, loadbitmap.Height, width, height, imagefilename);
                loadbitmap.Dispose();
                return(null);
            }

            magic_animedata = oam.MakeMagicAnime(imagefilename);
            if (magic_animedata == null)
            {
                errormessage = oam.ErrorMessage;
                loadbitmap.Dispose();
                return(null);
            }
            magic_animedata.image_number = image_number++;
            magic_animedata.imageHash    = hash;

            animeDic[key] = magic_animedata;
            errormessage  = "";
            loadbitmap.Dispose();
            return(magic_animedata);
        }
        static ImageUtilOAM.animedata ImportBGImageToData(string imagefilename
                                                          , string basedir
                                                          , Dictionary <string, ImageUtilOAM.animedata> animeDic
                                                          , List <ImageUtilOAM.image_data> imagesData
                                                          , out string errormessage
                                                          )
        {
            string key = "BG" + imagefilename;

            ImageUtilOAM.animedata magic_animedata;
            if (animeDic.ContainsKey(key))
            {
                errormessage    = "";
                magic_animedata = animeDic[key];
                return(magic_animedata);
            }

            string hash = ImageUtil.HashBitmap(imagefilename, basedir);

            magic_animedata = ImageUtilOAM.FindHash(hash, animeDic);
            if (magic_animedata != null)
            {
                errormessage = "";
                return(magic_animedata);
            }

            magic_animedata = new ImageUtilOAM.animedata();
            string bgfilename = ImageUtilMagicFEditor.GetFullPath(imagefilename, basedir);
            Bitmap loadbitmap = ImageUtil.OpenBitmap(bgfilename, null, out errormessage);

            if (loadbitmap == null)
            {
                return(null);
            }

//            int width = ImageUtilMagicFEditor.SRC_BG_SEAT_TILE_WIDTH * 8;
//            int height = ImageUtilMagicFEditor.SRC_BG_SEAT_TILE_HEIGHT * 8;
            int width  = 240;
            int height = 160;

            if (loadbitmap.Width < width || loadbitmap.Height < height)
            {
                if ((loadbitmap.Width >= 240 && loadbitmap.Width <= 264) &&
                    (loadbitmap.Height >= 64 && loadbitmap.Height < 160))
                {
                    height = 64;
                    //FEditor Magic
                    Log.Notify("これはFEditorの小さいBG形式です。");
                }
                else if ((loadbitmap.Width >= 240 && loadbitmap.Width <= 264) &&
                         loadbitmap.Height == 160)
                {//CSA Creator
                }
                else
                {
                    errormessage = R.Error("画像サイズが正しくありません。\r\n{4}\r\nWidth:{2} Height:{3} でなければなりません。\r\n\r\n選択された画像のサイズ Width:{0} Height:{1}", loadbitmap.Width, loadbitmap.Height, width, height, imagefilename);
                    loadbitmap.Dispose();
                    return(null);
                }
            }

            Bitmap savebitmap = ImageUtil.Copy(loadbitmap, 0, 0, width, height);

            byte[] image; //画像
            byte[] tsa;   //TSA
            string error_string = ImageUtil.ImageToBytePackedTSA(savebitmap, savebitmap.Width, savebitmap.Height, 0, out image, out tsa);

            if (error_string != "")
            {
                errormessage = error_string;
                loadbitmap.Dispose();
                return(null);
            }

            //画像の高さを記録. BGは、FEditor=64   Scale Creator=160 と、違う.
            magic_animedata.height = height;
            //ハッシュ値
            magic_animedata.imageHash = hash;

            //画像
            magic_animedata.image_pointer = (uint)imagesData.Count;
            ImageUtilOAM.image_data image_data = new ImageUtilOAM.image_data();
            image_data.data = image;
            image_data.data = LZ77.compress(image_data.data);
            imagesData.Add(image_data);

            //パレット
            magic_animedata.palette_pointer = (uint)imagesData.Count;
            ImageUtilOAM.image_data palette_data = new ImageUtilOAM.image_data();
            palette_data.data = ImageUtil.ImageToPalette(savebitmap);
            imagesData.Add(palette_data);

            //TSA
            magic_animedata.tsa_pointer = (uint)imagesData.Count;
            ImageUtilOAM.image_data tsa_data = new ImageUtilOAM.image_data();
            tsa_data.data = tsa;
            tsa_data.data = LZ77.compress(tsa_data.data);
            imagesData.Add(tsa_data);


            animeDic[key] = magic_animedata;
            errormessage  = "";
            loadbitmap.Dispose();
            return(magic_animedata);
        }