Exemple #1
0
    public static TTLP Seccion_PLTT(ref BinaryReader br)
    {
        TTLP ttlp     = new TTLP();
        long position = br.BaseStream.Position;

        ttlp.ID     = br.ReadChars(4);
        ttlp.length = br.ReadUInt32();
        ttlp.depth  = (br.ReadUInt16() == 3) ? ColorDepth.Depth4Bit : ColorDepth.Depth8Bit;
        br.ReadUInt16();
        ttlp.unknown1      = br.ReadUInt32();
        ttlp.paletteLength = br.ReadUInt32();
        uint num2 = br.ReadUInt32();

        ttlp.nColors  = (ttlp.depth == ColorDepth.Depth4Bit) ? 0x10 : (ttlp.paletteLength / 2);
        ttlp.palettes = new NTFP[ttlp.paletteLength / (ttlp.nColors * 2)];
        if ((ttlp.paletteLength > ttlp.length) || (ttlp.paletteLength == 0))
        {
            ttlp.palettes = new NTFP[ttlp.length / (ttlp.nColors * 2)];
        }
        br.BaseStream.Position = 0x18 + num2;
        for (int i = 0; i < ttlp.palettes.Length; i++)
        {
            ttlp.palettes[i] = Paleta_NTFP(ref br, ttlp.nColors);
        }
        return(ttlp);
    }
Exemple #2
0
        public override void Read(string fileIn)
        {
            nclr = new sNCLR();

            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            // Generic header
            nclr.header.id = br.ReadChars(4);
            nclr.header.endianess = br.ReadUInt16();
            if (nclr.header.endianess == 0xFFFE)
                nclr.header.id.Reverse<char>();
            nclr.header.constant = br.ReadUInt16();
            nclr.header.file_size = br.ReadUInt32();
            nclr.header.header_size = br.ReadUInt16();
            nclr.header.nSection = br.ReadUInt16();

            // PLTT section
            TTLP pltt = new TTLP();

            pltt.ID = br.ReadChars(4);
            pltt.length = br.ReadUInt32();
            pltt.depth = (ColorFormat)br.ReadUInt16();
            pltt.unknown1 = br.ReadUInt16();
            pltt.unknown2 = br.ReadUInt32();

            pltt.pal_length = br.ReadUInt32();
            if (pltt.pal_length == 0 || pltt.pal_length > pltt.length)
                pltt.pal_length = pltt.length - 0x18;

            uint colors_startOffset = br.ReadUInt32();
            pltt.num_colors = (uint)((pltt.depth == ColorFormat.colors16) ? 0x10 : 0x100);
            if (pltt.pal_length / 2 < pltt.num_colors)
                pltt.num_colors = pltt.pal_length / 2;
            pltt.palettes = new Color[pltt.pal_length / (pltt.num_colors * 2)][];

            br.BaseStream.Position = 0x18 + colors_startOffset;
            for (int i = 0; i < pltt.palettes.Length; i++)
                pltt.palettes[i] = Actions.BGR555ToColor(br.ReadBytes((int)pltt.num_colors * 2));

            nclr.pltt = pltt;

            // PMCP section
            if (nclr.header.nSection == 1 || br.BaseStream.Position >= br.BaseStream.Length)
                goto End;

            PMCP pmcp = new PMCP();
            pmcp.ID = br.ReadChars(4);
            pmcp.blockSize = br.ReadUInt32();
            pmcp.unknown1 = br.ReadUInt16();
            pmcp.unknown2 = br.ReadUInt16();
            pmcp.unknown3 = br.ReadUInt32();
            pmcp.first_palette_num = br.ReadUInt16();

            nclr.pmcp = pmcp;

            End:
            br.Close();
            Set_Palette(pltt.palettes, pltt.depth, true);
        }
        public override void Read(string fileIn)
        {
            nclr = new sNCLR();

            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            // Generic header
            nclr.header.id        = br.ReadChars(4);
            nclr.header.endianess = br.ReadUInt16();
            if (nclr.header.endianess == 0xFFFE)
            {
                nclr.header.id.Reverse <char>();
            }
            nclr.header.constant    = br.ReadUInt16();
            nclr.header.file_size   = br.ReadUInt32();
            nclr.header.header_size = br.ReadUInt16();
            nclr.header.nSection    = br.ReadUInt16();

            // PLTT section
            TTLP pltt = new TTLP();

            pltt.ID       = br.ReadChars(4);
            pltt.length   = br.ReadUInt32();
            pltt.depth    = (ColorFormat)br.ReadUInt16();
            pltt.unknown1 = br.ReadUInt16();
            pltt.unknown2 = br.ReadUInt32();

            pltt.pal_length = br.ReadUInt32();
            if (pltt.pal_length == 0 || pltt.pal_length > pltt.length)
            {
                pltt.pal_length = pltt.length - 0x18;
            }

            uint colors_startOffset = br.ReadUInt32();

            pltt.num_colors = (uint)((pltt.depth == ColorFormat.colors16) ? 0x10 : 0x100);
            if (pltt.pal_length / 2 < pltt.num_colors)
            {
                pltt.num_colors = pltt.pal_length / 2;
            }
            pltt.palettes = new Color[pltt.pal_length / (pltt.num_colors * 2)][];

            br.BaseStream.Position = 0x18 + colors_startOffset;
            for (int i = 0; i < pltt.palettes.Length; i++)
            {
                pltt.palettes[i] = Actions.BGR555ToColor(br.ReadBytes((int)pltt.num_colors * 2));
            }

            nclr.pltt = pltt;

            // PMCP section
            if (nclr.header.nSection == 1 || br.BaseStream.Position >= br.BaseStream.Length)
            {
                goto End;
            }

            PMCP pmcp = new PMCP();

            pmcp.ID                = br.ReadChars(4);
            pmcp.blockSize         = br.ReadUInt32();
            pmcp.unknown1          = br.ReadUInt16();
            pmcp.unknown2          = br.ReadUInt16();
            pmcp.unknown3          = br.ReadUInt32();
            pmcp.first_palette_num = br.ReadUInt16();

            nclr.pmcp = pmcp;

End:
            br.Close();
            Set_Palette(pltt.palettes, pltt.depth, true);
        }