Exemple #1
0
        private void numFile_ValueChanged(object sender, EventArgs e)
        {
            int i = (int)numFile.Value;

            if (palettes[i] == null)
            {
                palettes[i] = Save_File(palettes_[i]);
            }

            BinaryReader br = new BinaryReader(File.OpenRead(palettes[i]));

            br.BaseStream.Position = 0x3340;
            Color[][] pal = new Color[1][] { Actions.BGR555ToColor(br.ReadBytes(0x40)) };
            br.Close();

            palette = new RawPalette(pal, false, ColorFormat.colors16);

            if (imgs[i] == null)
            {
                imgs[i] = Save_File(imgs_[i]);
            }

            numSprite.Maximum = (new FileInfo(imgs[i]).Length / 0x200) - 1;
            label4.Text       = "of " + numSprite.Maximum.ToString();
            if (numSprite.Value != 0)
            {
                numSprite.Value = 0;
            }
            else
            {
                numSprite_ValueChanged(null, null);
            }
        }
Exemple #2
0
        public void Get_Image(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            // Palette
            uint num_colors = br.ReadUInt32();

            Color[][] colors = new Color[1][];
            colors[0] = Actions.BGR555ToColor(br.ReadBytes((int)num_colors * 2));

            // Image data
            uint num_tiles = /*(ushort)*/ br.ReadUInt32();

            byte[] tiles = br.ReadBytes((int)num_tiles * 0x40);

            // Map Info
            ushort width  = (ushort)(br.ReadUInt16() * 8);
            ushort height = (ushort)(br.ReadUInt16() * 8);

            NTFS[] map = new NTFS[width * height / 0x40];

            for (int i = 0; i < map.Length; i++)
            {
                map[i] = Actions.MapInfo(br.ReadUInt16());
            }

            br.Close();

            palette = new RawPalette(colors, true, ColorFormat.colors256);
            image   = new RawImage(tiles, TileForm.Horizontal, ColorFormat.colors256, width, height, true);
            Set_Map(map, true, width, height);
        }
        public override void Write(string fileOut, ImageBase image, PaletteBase palette)
        {
            Update_Struct();
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            // Common header
            bw.Write(nscr.header.id);
            bw.Write(nscr.header.endianess);
            bw.Write(nscr.header.constant);
            bw.Write(nscr.header.file_size);
            bw.Write(nscr.header.header_size);
            bw.Write(nscr.header.nSection);

            // SCRN section
            bw.Write(nscr.nrcs.id);
            bw.Write(nscr.nrcs.section_size);
            bw.Write(nscr.nrcs.width);
            bw.Write(nscr.nrcs.height);
            bw.Write(nscr.nrcs.padding);
            bw.Write(nscr.nrcs.data_size);

            for (int i = 0; i < nscr.nrcs.mapData.Length; i++)
            {
                int npalette = nscr.nrcs.mapData[i].nPalette << 12;
                int yFlip    = nscr.nrcs.mapData[i].yFlip << 11;
                int xFlip    = nscr.nrcs.mapData[i].xFlip << 10;
                int data     = npalette + yFlip + xFlip + nscr.nrcs.mapData[i].nTile;
                bw.Write((ushort)data);
            }

            bw.Flush();
            bw.Close();
        }
Exemple #4
0
        public override void Write(string fileout, PaletteBase palette)
        {
            this.palette = palette;
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileout));

            // Header
            bw.Write((ushort)(FormatColor == ColorFormat.colors256 ? 0x01 : 0x00));
            bw.Write((ushort)Width);
            bw.Write((ushort)Height);
            bw.Write((ushort)0x00);

            // Palette section
            bw.Write(Actions.ColorToBGR555(palette.Palette[0]));

            // Tile section
            if (FormatColor == ColorFormat.colors16)
            {
                bw.Write(Ekona.Helper.BitsConverter.BytesToBit4(Tiles));
            }
            else
            {
                bw.Write(Tiles);
            }

            bw.Flush();
            bw.Close();
        }
Exemple #5
0
        public override void Read(string file)
        {
            BinaryReader br        = new BinaryReader(File.OpenRead(file));
            uint         file_size = (uint)br.BaseStream.Length;

            // Read header values
            ushort      depth   = br.ReadUInt16();
            ushort      width   = br.ReadUInt16();
            ushort      height  = br.ReadUInt16();
            ushort      unknown = br.ReadUInt16();
            ColorFormat format  = (depth == 0x01) ? ColorFormat.colors256 : ColorFormat.colors16;

            // Palette
            int palette_length = (depth == 0x01) ? 0x200 : 0x20;

            Color[][] colors = new Color[1][];
            colors[0] = Actions.BGR555ToColor(br.ReadBytes(palette_length));
            palette   = new RawPalette(colors, false, format);

            // Tiles
            int tiles_length = width * height;

            if (depth == 0)
            {
                tiles_length /= 2;
            }
            Byte[] tiles = br.ReadBytes(tiles_length);

            br.Close();
            Set_Tiles(tiles, width, height, format, TileForm.Lineal, true);
        }
Exemple #6
0
        public override void Read(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            dsig = new sDSIG();

            dsig.id   = br.ReadChars(4);
            dsig.type = br.ReadByte();
            if (dsig.type != 0x02)
            {
                dsig.unk4 = br.ReadByte();
            }
            dsig.num_colors = br.ReadByte(); // Number of palettes of 16 colors
            dsig.unk1       = br.ReadByte();
            dsig.unk2       = br.ReadUInt16();
            dsig.unk3       = br.ReadUInt16();

            ColorFormat depth = (dsig.unk1 == 0 ? ColorFormat.colors16 : ColorFormat.colors256);

            if (dsig.unk1 != 0)
            {
                System.Windows.Forms.MessageBox.Show("Found different depth!");
            }
            TileForm form = (dsig.unk4 == 0x10 ? TileForm.Horizontal : TileForm.Lineal);

            Color[] colors = Actions.BGR555ToColor(br.ReadBytes(dsig.num_colors * 2));
            palette = new RawPalette(colors, false, depth, FileName);

            byte[] tiles = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
            Set_Tiles(tiles, 0x100, 0xc0, depth, form, false);

            br.Close();
        }
        public override void Read(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            uint header = br.ReadUInt32();
            uint block2 = br.ReadUInt32();
            uint block3 = br.ReadUInt32();
            uint block4 = br.ReadUInt32();
            uint block5 = br.ReadUInt32();
            uint block6 = br.ReadUInt32();
            uint block1 = br.ReadUInt32();

            // Palette
            br.BaseStream.Position = block5;
            uint block_size = br.ReadUInt32();
            uint pal_length = br.ReadUInt32();
            uint unknown    = pal_length & 0xFF;

            pal_length = pal_length >> 8;
            ColorFormat depth = (pal_length < 0x200 ? ColorFormat.colors16 : ColorFormat.colors256);

            isPalette = false;

            if (pal_length > 0)
            {
                int       num_colors = (depth == ColorFormat.colors16 ? 0x10 : 0x100);
                Color[][] colors     = new Color[pal_length / (num_colors * 2)][];
                for (int i = 0; i < colors.Length; i++)
                {
                    colors[i] = Actions.BGR555ToColor(br.ReadBytes((int)(num_colors * 2)));
                }
                palette   = new RawPalette(colors, false, depth, fileName);
                isPalette = true;
            }

            int width, height;

            width  = 0x100;
            height = 0xc0;

            // Tile data
            br.BaseStream.Position = block6;
            block_size             = br.ReadUInt32();
            uint tile_length = br.ReadUInt32();
            uint compression = pal_length & 0xFF;

            tile_length = tile_length >> 8;
            if (compression == 0x10)
            {
                Console.WriteLine("Tiles use LZSS compression");
            }

            Byte[] tiles = br.ReadBytes((int)tile_length);
            image = new RawImage(tiles, TileForm.Horizontal, depth, width, height, false, fileName);

            br.Close();
        }
        public override void Read(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            uint header = br.ReadUInt32();

            uint        pal_length  = br.ReadUInt32();
            uint        tile_length = br.ReadUInt32();
            uint        map_length  = br.ReadUInt32();
            ColorFormat depth       = (pal_length < 0x200 ? ColorFormat.colors16 : ColorFormat.colors256);

            isMap = true;

            int width, height;

            if (header == 0x18)
            {
                width  = (ushort)br.ReadUInt32();
                height = (ushort)br.ReadUInt32();
            }
            else
            {
                width  = 0x200;
                height = 0xc0;
                isMap  = false;
            }

            // Palette
            int num_colors = (depth == ColorFormat.colors16 ? 0x10 : 0x100);

            Color[][] colors = new Color[pal_length / (num_colors * 2)][];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = Actions.BGR555ToColor(br.ReadBytes((int)(num_colors * 2)));
            }
            palette = new RawPalette(colors, false, depth, fileName);

            // Tile data
            Byte[] tiles = br.ReadBytes((int)tile_length);
            image = new RawImage(tiles, TileForm.Horizontal, depth, width, height, false, fileName);

            // Map
            if (isMap)
            {
                NTFS[] maps = new NTFS[map_length / 2];
                for (int i = 0; i < maps.Length; i++)
                {
                    maps[i] = Actions.MapInfo(br.ReadUInt16());
                }
                Set_Map(maps, false);
            }

            br.Close();
        }
Exemple #9
0
 // Use this for initialization
 void Start()
 {
     InitEasyTouch();
     if (Application.loadedLevelName == "TestPaletteTouch")
     {
         m_pattle = PaletteTouch.Instance();
     }
     else
     {
         m_pattle = PaletteTouchUGUI.Instance();
     }
 }
        public AnimationControl(IPluginHost pluginHost, NANR ani)
        {
            InitializeComponent();
            Read_Language();

            this.pluginHost = pluginHost;
            this.palette    = pluginHost.Get_Palette();
            this.image      = pluginHost.Get_Image();
            this.sprite     = pluginHost.Get_Sprite();
            this.ani        = ani;
            isAni           = true;

            if (ani.Struct.abnk.nBanks == 0)
            {
                MessageBox.Show("No animations.");
                isAni                      = false;
                tempo.Enabled              = false;
                comboAni.Enabled           = false;
                btnNext.Enabled            = false;
                btnPlay.Enabled            = false;
                btnPrevious.Enabled        = false;
                btnSave.Enabled            = false;
                btnStop.Enabled            = false;
                txtTime.Enabled            = false;
                checkCeldas.Enabled        = false;
                checkEntorno.Enabled       = false;
                checkImage.Enabled         = false;
                checkNumeros.Enabled       = false;
                checkTransparencia.Enabled = false;
            }


            for (int i = 0; i < ani.Names.Length; i++)
            {
                comboAni.Items.Add(ani.Names[i]);
            }
            if (isAni)
            {
                comboAni.SelectedIndex = 0;
            }

            ShowInfo();
            Get_Ani();

            tempo.Stop();
            tempo.Interval = Convert.ToInt32(txtTime.Text);

            if (isAni)
            {
                aniBox.Image = bitAni[0];
            }
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DevExpress.Xpf.Charts.CustomPalette chartPalette = new DevExpress.Xpf.Charts.CustomPalette();
            PaletteBase          palette     = (values[0] == null) ? null : (PaletteBase)values[0];
            CountryStatisticInfo countryInfo = (values[0] == null) ? null : (CountryStatisticInfo)values[1];

            if (countryInfo != null && countryInfo.Shape != null)
            {
                int index = Int16.Parse(countryInfo.Shape.Attributes["MAP_COLOR"].Value.ToString());
                chartPalette.Colors.Add(palette[index]);
            }
            return(chartPalette);
        }
Exemple #12
0
        public OAMEditor(XElement langxml, Bank bank, SpriteBase sprite, ImageBase image, PaletteBase palette)
        {
            InitializeComponent();
            this.bank = bank;
            numOAM.Maximum = bank.oams.Length - 1;

            preview = true;
            this.sprite = sprite;
            this.image = image;
            this.palette = palette;

            Read_Language(langxml);
        }
Exemple #13
0
        public OAMEditor(XElement langxml, Bank bank, SpriteBase sprite, ImageBase image, PaletteBase palette)
        {
            InitializeComponent();
            this.bank      = bank;
            numOAM.Maximum = bank.oams.Length - 1;

            preview      = true;
            this.sprite  = sprite;
            this.image   = image;
            this.palette = palette;

            Read_Language(langxml);
        }
        public override void Read(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            ushort       h  = br.ReadUInt16();

            if (h == 0x10 || h == 0x12 || h == 0x18 || h == 0x1A)
            {
                br.Close();
                Read12(fileIn);
                return;
            }
            br.BaseStream.Position = 0;

            uint info_offset = br.ReadUInt32();
            uint data_size   = br.ReadUInt32();

            byte[] data;

            if ((data_size >> 31) == 1)
            {
                // Data encoded
                data_size = data_size & 0xFFFFFF;
                data      = br.ReadBytes((int)data_size);

                Encryption enc = new Encryption(data);
                data = enc.Decrypt();
            }
            else
            {
                data = br.ReadBytes((int)data_size);
            }

            br.BaseStream.Position = info_offset + 4;
            uint pal_offset = br.ReadUInt32();
            uint unk_offset = br.ReadUInt32();

            // Get palette
            br.BaseStream.Position = pal_offset + 4;
            Color[] colors = Actions.BGR555ToColor(br.ReadBytes(0x200));
            pal = new RawPalette(new Color[][] { colors }, false, ColorFormat.colors256);

            // Unknown (probably like a map)
            br.BaseStream.Position = unk_offset;
            int width  = br.ReadByte() * 8;
            int height = br.ReadByte() * 8;

            img   = new RawImage(data, TileForm.Horizontal, ColorFormat.colors256, width, height, false);
            ismap = false;

            br.Close();
        }
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            PaletteBase chartColors = (PaletteBase)value;

            DevExpress.Xpf.Map.ColorCollection mapColors = new DevExpress.Xpf.Map.ColorCollection();
            DoubleCollection rangeStops = (DoubleCollection)parameter;
            int colorsCount             = (int)(rangeStops[rangeStops.Count - 1] - rangeStops[0]) + 1;

            for (int i = 0; i < colorsCount; i++)
            {
                mapColors.Add(chartColors[i]);
            }
            return(mapColors);
        }
Exemple #16
0
        private void btnExtract_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog o = new FolderBrowserDialog();

            o.Description         = "Select the folder to save the sprites.";
            o.ShowNewFolderButton = true;
            if (o.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            this.Cursor = Cursors.WaitCursor;
            string folderOut = o.SelectedPath + Path.DirectorySeparatorChar;

            for (int i = 0; i < imgs.Length; i++)
            {
                if (palettes[i] == null)
                {
                    palettes[i] = Save_File(palettes_[i]);
                }

                BinaryReader br = new BinaryReader(File.OpenRead(palettes[i]));
                br.BaseStream.Position = 0x3340;
                Color[][] pal = new Color[1][] { Actions.BGR555ToColor(br.ReadBytes(0x40)) };
                br.Close();

                palette = new RawPalette(pal, false, ColorFormat.colors16);

                if (imgs[i] == null)
                {
                    imgs[i] = Save_File(imgs_[i]);
                }

                uint max_imgs = (uint)(new FileInfo(imgs[i]).Length / 0x200);


                br = new BinaryReader(File.OpenRead(imgs[i]));
                for (int j = 0; j < max_imgs; j++)
                {
                    br.BaseStream.Position = j * 0x200;
                    byte[] tiles = br.ReadBytes(0x200);

                    ImageBase image = new RawImage(tiles, TileForm.Lineal, ColorFormat.colors16, 0x20, 0x20, false);
                    image.Get_Image(palette).Save(folderOut + "Sprite" + i.ToString() + '_' + j.ToString() + ".png");
                }
                br.Close();
            }
            this.Cursor = Cursors.Default;
        }
Exemple #17
0
        public override void Write(string fileout, ImageBase image, PaletteBase palette)
        {
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileout));

            bw.Write((ushort)(Width / 0x08));
            bw.Write((ushort)(Height / 0x08));

            for (int i = 0; i < Map.Length; i++)
            {
                bw.Write(Actions.MapInfo(Map[i]));
            }

            bw.Flush();
            bw.Close();
        }
Exemple #18
0
        public OAMEditor(XElement langxml, Bank bank, SpriteBase sprite, ImageBase image, PaletteBase palette)
        {
            InitializeComponent();
            this.bank         = bank;
            numOAM.Maximum    = bank.oams.Length - 1;
            numOffset.Maximum = (bank.data_size == 0)
                ? image.Tiles.Length / (0x20 << (int)sprite.BlockSize) - 1
                : bank.data_size / (0x20 << (int)sprite.BlockSize) - 1;

            preview      = true;
            this.sprite  = sprite;
            this.image   = image;
            this.palette = palette;

            Read_Language(langxml);
        }
Exemple #19
0
        public OAMEditor(string langxml, Bank bank, SpriteBase sprite, ImageBase image, PaletteBase palette)
        {
            InitializeComponent();
            this.bank = bank;
            numOAM.Maximum = bank.oams.Length - 1;
            numOffset.Maximum = (bank.data_size == 0)
                ? image.Tiles.Length / (0x20 << (int)sprite.BlockSize) - 1
                : bank.data_size / (0x20 << (int)sprite.BlockSize) - 1;

            preview = true;
            this.sprite = sprite;
            this.image = image;
            this.palette = palette;

            Read_Language(langxml);
        }
        public override void Write(string fileOut, PaletteBase palette)
        {
            if (depth != FormatColor)
            {
                throw new NotImplementedException("The current file doesn't support this depth");
            }

            // Update the struct
            cgx.size_tiles = (uint)Tiles.Length;
            if (depth == Ekona.Images.ColorFormat.colors16)
            {
                cgx.num_tiles = cgx.size_tiles / 0x20;
            }
            else
            {
                cgx.num_tiles = cgx.size_tiles / 0x40;
            }
            cgx.palColors      = (uint)palette.NumberOfColors;
            cgx.palOffset      = 0x30 + cgx.size_tiles;
            cgx.unknonwnOffset = cgx.palOffset + cgx.palColors * 2;

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            bw.Write(cgx.type);
            bw.Write(cgx.unknown1);
            bw.Write(cgx.unknown2);
            bw.Write(cgx.unknown3);

            bw.Write(cgx.unknown4);
            bw.Write(cgx.size_tiles);
            bw.Write(cgx.unknown5);
            bw.Write(cgx.num_tiles);

            bw.Write(cgx.palColors);
            bw.Write(cgx.tileOffset);
            bw.Write(cgx.palOffset);
            bw.Write(cgx.unknonwnOffset);

            bw.Write(Tiles);
            for (int i = 0; i < palette.NumberOfPalettes; i++)
            {
                bw.Write(Actions.ColorToBGR555(palette.Palette[i]));
            }

            bw.Flush();
            bw.Close();
        }
Exemple #21
0
        public override void Write(string fileout, PaletteBase palette)
        {
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileout));

            ushort num_tiles = (ushort)(Tiles.Length / 0x20);

            if (FormatColor == ColorFormat.colors256)
            {
                num_tiles /= 2;
            }

            bw.Write(num_tiles);
            bw.Write((ushort)(FormatColor == Ekona.Images.ColorFormat.colors16 ? 0x00 : 0x01));
            bw.Write(Tiles);

            bw.Flush();
            bw.Close();
        }
Exemple #22
0
        public override void Read(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            // Header
            uint paletaOffset = br.ReadUInt32() * 4;
            uint tileOffset   = br.ReadUInt32() * 4;
            uint mapOffset    = br.ReadUInt32() * 4;

            // Paleta
            br.BaseStream.Position = paletaOffset;
            uint pCabeceraSize = br.ReadUInt32() * 4;
            uint pSize         = br.ReadUInt32() * 4;

            Color[][] colors = new Color[1][];
            colors[0] = Actions.BGR555ToColor(br.ReadBytes((int)(pSize - 0x08)));
            palette   = new RawPalette(colors, false, ColorFormat.colors256);

            // Image data
            br.BaseStream.Position = tileOffset;
            uint tCabeceraSize = br.ReadUInt32() * 4;
            uint tSize         = br.ReadUInt32() * 4;

            byte[] tiles = br.ReadBytes((int)(tSize - 0x08));
            image = new RawImage(tiles, TileForm.Horizontal, ColorFormat.colors256, 256, 192, false);

            // Map
            br.BaseStream.Position = mapOffset;
            uint mCabeceraSize = br.ReadUInt32() * 4;
            uint mSize         = br.ReadUInt32() * 4;

            ushort width  = br.ReadUInt16();
            ushort height = br.ReadUInt16();

            NTFS[] map = new NTFS[(mSize - 0x08) / 2];
            for (int i = 0; i < map.Length; i++)
            {
                map[i] = Actions.MapInfo(br.ReadUInt16());
            }

            br.Close();
            Set_Map(map, false, width * 8, height * 8);
        }
Exemple #23
0
        public override void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));

            ushort      num_tiles = br.ReadUInt16();
            ushort      depth     = br.ReadUInt16();
            ColorFormat format    = (depth == 0x01 ? ColorFormat.colors256 : ColorFormat.colors16);

            if (br.BaseStream.Length - 4 == num_tiles * 0x40)
            {
                format = ColorFormat.colors256;
            }

            Byte[] tiles = br.ReadBytes(num_tiles * (0x20 + 0x20 * depth));

            int width = 64;

            if (num_tiles == 0x10)
            {
                width = 32;
            }
            int height = tiles.Length / width;

            if (depth == 0)
            {
                height *= 2;
            }

            br.Close();
            Set_Tiles(tiles, width, height, format, TileForm.Horizontal, true);
            pluginHost.Set_Image(this);

            // If the image is 8bpp, convert to 8bpp the palette (4bpp per default)
            PaletteBase palette = pluginHost.Get_Palette();

            if (palette.Loaded && format == ColorFormat.colors256)
            {
                palette.Depth = ColorFormat.colors256;
                pluginHost.Set_Palette(palette);
            }
        }
        public override void Write(string fileOut, PaletteBase palette)
        {
            Update_Struct();
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            // Common header
            bw.Write(ncgr.header.id);
            bw.Write(ncgr.header.endianess);
            bw.Write(ncgr.header.constant);
            bw.Write(ncgr.header.file_size);
            bw.Write(ncgr.header.header_size);
            bw.Write(ncgr.header.nSection);

            // RAHC section
            bw.Write(ncgr.rahc.id);
            bw.Write(ncgr.rahc.size_section);
            bw.Write(ncgr.rahc.nTilesY);
            bw.Write(ncgr.rahc.nTilesX);
            bw.Write((uint)(ncgr.rahc.depth));
            bw.Write(ncgr.rahc.unknown1);
            bw.Write(ncgr.rahc.unknown2);
            bw.Write(ncgr.rahc.tiledFlag);
            bw.Write(ncgr.rahc.size_tiledata);
            bw.Write(ncgr.rahc.unknown3);
            bw.Write(ncgr.rahc.data);

            // SOPC section
            if (ncgr.header.nSection == 2)
            {
                bw.Write(ncgr.sopc.id);
                bw.Write(ncgr.sopc.size_section);
                bw.Write(ncgr.sopc.unknown1);
                bw.Write(ncgr.sopc.charSize);
                bw.Write(ncgr.sopc.nChar);
            }

            bw.Flush();
            bw.Close();
        }
        public override void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));

            char[] id       = br.ReadChars(4);
            uint   unknown1 = br.ReadUInt32();  // Usually is 0x00
            uint   unknown2 = br.ReadUInt32();  // Usually is 0x00
            uint   unknown3 = br.ReadUInt32();  // Usually is 0x00

            uint format       = br.ReadUInt32();
            uint tile_size    = br.ReadUInt32();
            uint header_size  = br.ReadUInt32();
            uint palette_size = br.ReadUInt32();

            uint palette_offset = br.ReadUInt32();
            uint unknown4       = br.ReadUInt32();
            uint unknown_offset = br.ReadUInt32();
            uint unknown5       = br.ReadUInt32();

            transparency = (br.ReadUInt32() == 0x00 ? false : true);
            transparency = false;

            int  width    = (int)Math.Pow(2, (double)(br.ReadUInt16() + 3));
            int  height   = (int)Math.Pow(2, (double)(br.ReadUInt16() + 3));
            uint unknown6 = br.ReadUInt32();

            byte[] data = br.ReadBytes((int)tile_size);


            br.BaseStream.Position = palette_offset;
            Color[][] palette = new Color[1][];
            palette[0] = Actions.BGR555ToColor(br.ReadBytes((int)palette_size));

            br.Close();

            Set_Tiles(data, width, height, (ColorFormat)format, TileForm.Lineal, false);
            pb = new RawPalette(palette, false, ColorFormat.colors256);
        }
        public override void Write(string fileOut, ImageBase image, PaletteBase palette)
        {
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            bw.Write(scx.type);
            bw.Write(scx.unknown1);
            bw.Write(scx.unknown2);
            bw.Write(scx.unknown3);
            bw.Write(scx.unknown4);

            bw.Write((ushort)Width);
            bw.Write((ushort)Height);
            bw.Write(Map.Length * 2);
            bw.Write(Map.Length * 2);

            for (int i = 0; i < Map.Length; i++)
            {
                bw.Write(Actions.MapInfo(Map[i]));
            }

            bw.Flush();
            bw.Close();
        }
 public override void Write(string fileOut, ImageBase image, PaletteBase palette)
 {
     throw new NotImplementedException();
 }
 public void Set_Palette(PaletteBase palette)
 {
     this.palette = palette;
 }
Exemple #29
0
        public override void Read(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            if (new String(br.ReadChars(2)) != "BM")
                throw new NotSupportedException();

            br.BaseStream.Position = 0x0A;
            uint offsetImagen = br.ReadUInt32();

            br.BaseStream.Position += 0x04;
            uint width = br.ReadUInt32();
            uint height = br.ReadUInt32();

            br.BaseStream.Position += 0x02;
            uint bpp = br.ReadUInt16();
            ColorFormat format;
            if (bpp == 0x04)
                format = Images.ColorFormat.colors16;
            else if (bpp == 0x08)
                format = Images.ColorFormat.colors256;
            else
                throw new NotSupportedException();

            uint compression = br.ReadUInt32();
            uint data_size = br.ReadUInt32();

            br.BaseStream.Position += 0x8;
            uint num_colors = br.ReadUInt32();

            if (num_colors == 0x00)
                num_colors = (uint)(bpp == 0x04 ? 0x10 : 0x0100);

            br.BaseStream.Position += 0x04;
            Color[][] colors = new Color[1][];
            colors[0] = new Color[num_colors];
            for (int i = 0; i < num_colors; i++)
            {
                Byte[] color = br.ReadBytes(4);
                colors[0][i] = Color.FromArgb(color[2], color[1], color[0]);
            }
            // Get the colors with BGR555 encoding (not all colours from bitmap are allowed)
            byte[] temp = Actions.ColorToBGR555(colors[0]);
            colors[0] = Actions.BGR555ToColor(temp);
            palette = new RawPalette(colors, false, format);

            byte[] tiles = new byte[width * height];
            br.BaseStream.Position = offsetImagen;

            switch (bpp)
            {
                case 4:
                    int divisor = (int)width / 2;
                    if (width % 4 != 0)
                    {
                        int res;
                        Math.DivRem((int)width / 2, 4, out res);
                        divisor = (int)width / 2 + (4 - res);
                    }

                    tiles = new byte[tiles.Length * 2];
                    for (int h = (int)height - 1; h >= 0; h--)
                    {
                        for (int w = 0; w < width; w += 2)
                        {
                            byte b = br.ReadByte();
                            tiles[w + h * width] = (byte)(b >> 4);

                            if (w + 1 != width)
                                tiles[w + 1 + h * width] = (byte)(b & 0xF);
                        }
                        br.ReadBytes((int)(divisor - ((float)width / 2)));
                    }
                    tiles = Helper.BitsConverter.Bits4ToByte(tiles);
                    break;
                case 8:
                    divisor = (int)width;
                    if (width % 4 != 0)
                    {
                        int res;
                        Math.DivRem((int)width, 4, out res);
                        divisor = (int)width + (4 - res);
                    }

                    for (int h = (int)height - 1; h >= 0; h--)
                    {
                        for (int w = 0; w < width; w++)
                        {
                            tiles[w + h * width] = br.ReadByte();
                        }
                        br.ReadBytes(divisor - (int)width);
                    }
                    break;
            }

            br.Close();
            Set_Tiles(tiles, (int)width, (int)height, format, Images.TileForm.Lineal, false);
        }
Exemple #30
0
 public override void Write(string fileOut, PaletteBase palette)
 {
     throw new NotImplementedException();
 }
Exemple #31
0
        public override void Write(string fileOut, ImageBase image, PaletteBase palette)
        {
            if (image.FormatColor != ColorFormat.colors256)
            {
                throw new Exception("Only 256 colors (16Bpp) images support!");
            }

            NTFS[] map            = base.Map;
            byte[] tiles          = image.Tiles;
            byte[] colorsData     = Actions.ColorToBGR555(palette.Palette[0]);
            int    srcColorsCount = palette.Original.Length / 2;

            if (srcColorsCount != palette.NumberOfColors || !Actions.Compare_Array(palette.Original, colorsData))
            {
                // Replaced palette
                if (srcColorsCount <= palette.NumberOfColors &&
                    MessageBox.Show(
                        "The changed palette has more colors than the original.\r\n"
                        + "In some cases this can lead to an incorrect display of the game.\r\n\r\n"
                        + "Try to force swap at the original palette?",
                        "Layton Image Import",
                        MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    // Force swaping to the Original palette
                    Color[] colors = Actions.BGR555ToColor(palette.Original);
                    Actions.Swap_Palette(ref tiles, colors, palette.Palette[0], ColorFormat.colors256, decimal.MaxValue);
                    colorsData         = palette.Original;
                    palette.Palette[0] = colors;
                }
                else
                {
                    // Add transparent color to the Replaced palette
                    byte[] newColorsData = new byte[colorsData.Length + 2];
                    Array.Copy(palette.Original, 0, newColorsData, 0, 2);
                    Array.Copy(colorsData, 0, newColorsData, 2, colorsData.Length);
                    colorsData = newColorsData;

                    Color[] newColors = new Color[palette.Palette[0].Length + 1];
                    newColors[0] = Actions.BGR555ToColor(palette.Original[0], palette.Original[1]);
                    Array.Copy(palette.Palette[0], 0, newColors, 1, palette.Palette[0].Length);
                    palette.Palette[0] = newColors;

                    for (long i = 0; i < tiles.LongLength; i++)
                    {
                        tiles[i]++;
                    }
                }
            }

            // Write data
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            bw.BaseStream.SetLength(0);
            bw.Write((uint)(colorsData.LongLength / 2));
            bw.Write(colorsData);
            bw.Write((uint)(tiles.LongLength / 0x40));
            bw.Write(tiles);
            bw.Write((ushort)(image.Width / 8));
            bw.Write((ushort)(image.Height / 8));
            for (int i = 0; i < map.Length; i++)
            {
                bw.Write(Actions.MapInfo(map[i]));
            }
            bw.Close();

            // Compress data
            string compressedFile = this.pluginHost.Get_TempFile();

            this.pluginHost.Compress(fileOut, compressedFile, FormatCompress.LZ10);

            bw = new BinaryWriter(File.OpenWrite(fileOut));
            bw.BaseStream.SetLength(0);
            bw.Write(2);
            bw.Write(File.ReadAllBytes(compressedFile));
            bw.Close();
            File.Delete(compressedFile);
        }
 public override void Write(string fileOut, ImageBase image, PaletteBase palette)
 {
 }
Exemple #33
0
        public void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));

            // Header
            uint        paletaOffset = br.ReadUInt32() * 4;
            uint        tileOffset   = br.ReadUInt32() * 4;
            uint        mapOffset    = br.ReadUInt32() * 4;
            ColorFormat depth;

            br.BaseStream.Position = mapOffset;
            if (br.ReadUInt32() == 0x01)
            {
                depth = ColorFormat.colors256;
            }
            else
            {
                depth = ColorFormat.colors16;
            }

            // Palette
            Color[][] colors;
            if (paletaOffset == 0x00) // No palette
            {
                depth  = ColorFormat.colors16;
                colors = new Color[defaultPaletteData.Length / 0x20][];

                for (int i = 0; i < colors.Length; i++)
                {
                    Byte[] data = new Byte[0x20];
                    Array.Copy(defaultPaletteData, i * 0x20, data, 0, 0x20);
                    colors[i] = Actions.BGR555ToColor(data);
                }
                goto Tile;
            }

            br.BaseStream.Position = paletaOffset;
            uint pCabeceraSize = br.ReadUInt32() * 4;
            uint pSize         = br.ReadUInt32() * 4;

            if (pSize - 0x08 == 0x0200)
            {
                depth = ColorFormat.colors256;
            }
            else if (pSize - 0x08 == 0x20)
            {
                depth = ColorFormat.colors16;
            }

            colors = new Color[depth == ColorFormat.colors16 ? (pSize - 0x08) / 0x20 : 1][];
            uint pal_length = (depth == ColorFormat.colors16) ? 0x20 : pSize - 0x08;

            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = Actions.BGR555ToColor(br.ReadBytes((int)pal_length));
            }

            // Tile data
Tile:
            br.BaseStream.Position = tileOffset;
            uint tCabeceraSize = br.ReadUInt32() * 4;
            uint tSize         = br.ReadUInt32() * 4;

            byte[] tiles = br.ReadBytes((int)(tSize - 0x08));
            image = new RawImage(tiles, TileForm.Horizontal, depth, 0x40, tiles.Length / 0x40, false, fileName);

            // Map
            if (mapOffset == 0x00)
            {
                hasMap = false;
                goto End;
            }

            hasMap = true;
            br.BaseStream.Position = mapOffset;
            uint mCabeceraSize = br.ReadUInt32() * 4;

            uint[] mSize = new uint[(int)mCabeceraSize / 4];
            for (int i = 0; i < mSize.Length; i++)
            {
                mSize[i] = (br.ReadUInt32() * 4) - mCabeceraSize - 4;
            }

            maps = new MapBase[mSize.Length];
            for (int i = 0; i < maps.Length; i++)
            {
                ushort width  = (ushort)(br.ReadUInt16() * 8);
                ushort height = (ushort)(br.ReadUInt16() * 8);

                NTFS[] map;
                if (i != 0)
                {
                    map = new NTFS[((mSize[i] - mSize[i - 1]) - 4) / 2];
                }
                else
                {
                    map = new NTFS[(mSize[i] - 4) / 2];
                }

                for (int j = 0; j < map.Length; j++)
                {
                    map[j] = Actions.MapInfo(br.ReadUInt16());
                }

                maps[i] = new RawMap(map, width, height, false, fileName);
            }

End:
            br.Close();

            palette = new RawPalette(colors, false, depth, fileName);
        }
Exemple #34
0
 public override void Write(string fileOut, PaletteBase palette)
 {
     Console.WriteLine("Write Tiles - NCCG");
 }