Ejemplo n.º 1
0
        public override void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));

            cgx = new sCGx();

            cgx.type     = br.ReadChars(4); // CG4
            cgx.unknown1 = br.ReadUInt32();
            cgx.unknown2 = br.ReadUInt32();
            cgx.unknown3 = br.ReadUInt32();    // Usually 0

            cgx.unknown4   = br.ReadUInt32();  // Usually 0
            cgx.size_tiles = br.ReadUInt32();
            cgx.unknown5   = br.ReadUInt32();
            cgx.num_tiles  = br.ReadUInt32();

            cgx.palColors      = br.ReadUInt32();
            cgx.tileOffset     = br.ReadUInt32();
            cgx.palOffset      = br.ReadUInt32();
            cgx.unknonwnOffset = br.ReadUInt32();    // If 0, it doesn't exist

            // Read tiles
            br.BaseStream.Position = cgx.tileOffset;
            int tile_size = (depth == ColorFormat.colors16 ? 0x20 : 0x40);

            Byte[] tiles = br.ReadBytes((int)cgx.num_tiles * tile_size);
            Set_Tiles(tiles, WIDTH, (int)(tiles.Length / WIDTH), depth, TileForm.Horizontal, false);
            if (depth == Ekona.Images.ColorFormat.colors16)
            {
                Height *= 2;
            }

            // Read palette
            br.BaseStream.Position = cgx.palOffset;
            Color[][] colors;
            if (depth == Ekona.Images.ColorFormat.colors16)
            {
                colors = new Color[cgx.palColors / 0x10][];
                for (int i = 0; i < colors.Length; i++)
                {
                    colors[i] = Actions.BGR555ToColor(br.ReadBytes(32));
                }
            }
            else
            {
                colors    = new Color[1][];
                colors[0] = Actions.BGR555ToColor(br.ReadBytes((int)cgx.palColors * 2));
            }
            PaletteBase palette = new RawPalette(colors, false, depth);

            br.BaseStream.Position = cgx.unknonwnOffset;
            cgx.unknown            = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));

            br.Close();
        }
Ejemplo n.º 2
0
Archivo: CGx.cs Proyecto: MetLob/tinke
        public override void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));
            cgx = new sCGx();

            cgx.type = br.ReadChars(4);  // CG4
            cgx.unknown1 = br.ReadUInt32();
            cgx.unknown2 = br.ReadUInt32();
            cgx.unknown3 = br.ReadUInt32();    // Usually 0

            cgx.unknown4 = br.ReadUInt32();    // Usually 0
            cgx.size_tiles = br.ReadUInt32();
            cgx.unknown5 = br.ReadUInt32();
            cgx.num_tiles = br.ReadUInt32();

            cgx.palColors = br.ReadUInt32();
            cgx.tileOffset = br.ReadUInt32();
            cgx.palOffset = br.ReadUInt32();
            cgx.unknonwnOffset = br.ReadUInt32();    // If 0, it doesn't exist

            // Read tiles
            br.BaseStream.Position = cgx.tileOffset;
            int tile_size = (depth == ColorFormat.colors16 ? 0x20 : 0x40);
            Byte[] tiles = br.ReadBytes((int)cgx.num_tiles * tile_size);
            Set_Tiles(tiles, WIDTH, (int)(tiles.Length / WIDTH), depth, TileForm.Horizontal, false);
            if (depth == Ekona.Images.ColorFormat.colors16)
                Height *= 2;

            // Read palette
            br.BaseStream.Position = cgx.palOffset;
            Color[][] colors;
            if (depth == Ekona.Images.ColorFormat.colors16)
            {
                colors = new Color[cgx.palColors / 0x10][];
                for (int i = 0; i < colors.Length; i++)
                    colors[i] = Actions.BGR555ToColor(br.ReadBytes(32));
            }
            else
            {
                colors = new Color[1][];
                colors[0] = Actions.BGR555ToColor(br.ReadBytes((int)cgx.palColors * 2));
            }
            PaletteBase palette = new RawPalette(colors, false, depth);

            br.BaseStream.Position = cgx.unknonwnOffset;
            cgx.unknown = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));

            br.Close();
        }