Beispiel #1
0
        public XF(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                xpck = new XPCK(input);

                //get xi image to bmp
                xi  = new IMGC(xpck.Files[0].FileData);
                bmp = xi.Image;

                //decompress fnt.bin
                var tempCharSizeInfo = new List <CharSizeInfo>();
                using (var fntR = new BinaryReaderX(xpck.Files[1].FileData, true))
                {
                    xfheader = fntR.ReadStruct <XFHeader>();

                    fntR.BaseStream.Position = xfheader.table0Offset << 2;
                    t0Comp = (Level5.Method)(fntR.ReadInt32() & 0x7);
                    fntR.BaseStream.Position -= 4;
                    tempCharSizeInfo          = new BinaryReaderX(new MemoryStream(Level5.Decompress(fntR.BaseStream))).ReadMultiple <CharSizeInfo>(xfheader.table0EntryCount);

                    fntR.BaseStream.Position = xfheader.table1Offset << 2;
                    t1Comp = (Level5.Method)(fntR.ReadInt32() & 0x7);
                    fntR.BaseStream.Position -= 4;
                    dicGlyphLarge             = new BinaryReaderX(new MemoryStream(Level5.Decompress(fntR.BaseStream))).ReadMultiple <CharacterMap>(xfheader.table1EntryCount).ToDictionary(x => x.code_point);

                    fntR.BaseStream.Position = xfheader.table2Offset << 2;
                    t2Comp = (Level5.Method)(fntR.ReadInt32() & 0x7);
                    fntR.BaseStream.Position -= 4;
                    dicGlyphSmall             = new BinaryReaderX(new MemoryStream(Level5.Decompress(fntR.BaseStream))).ReadMultiple <CharacterMap>(xfheader.table2EntryCount).ToDictionary(x => x.code_point);
                }

                #region Expand charsizeinfo
                lstCharSizeInfoLarge = new Dictionary <char, CharSizeInfo>();
                lstCharSizeInfoSmall = new Dictionary <char, CharSizeInfo>();
                foreach (var dic in dicGlyphLarge)
                {
                    lstCharSizeInfoLarge.Add(dic.Value.code_point, new CharSizeInfo
                    {
                        offset_x    = tempCharSizeInfo[dic.Value.CharSizeInfoIndex].offset_x,
                        offset_y    = tempCharSizeInfo[dic.Value.CharSizeInfoIndex].offset_y,
                        char_width  = tempCharSizeInfo[dic.Value.CharSizeInfoIndex].char_width,
                        char_height = tempCharSizeInfo[dic.Value.CharSizeInfoIndex].char_height
                    });
                }
                foreach (var dic in dicGlyphSmall)
                {
                    lstCharSizeInfoSmall.Add(dic.Value.code_point, new CharSizeInfo
                    {
                        offset_x    = tempCharSizeInfo[dic.Value.CharSizeInfoIndex].offset_x,
                        offset_y    = tempCharSizeInfo[dic.Value.CharSizeInfoIndex].offset_y,
                        char_width  = tempCharSizeInfo[dic.Value.CharSizeInfoIndex].char_width,
                        char_height = tempCharSizeInfo[dic.Value.CharSizeInfoIndex].char_height
                    });
                }
                #endregion

                var bmpInfo = new BitmapInfo(bmp);

                image_0 = bmpInfo.CreateChannelBitmap(BitmapInfo.Channel.Red);
                image_1 = bmpInfo.CreateChannelBitmap(BitmapInfo.Channel.Green);
                image_2 = bmpInfo.CreateChannelBitmap(BitmapInfo.Channel.Blue);
            }
        }
Beispiel #2
0
        public XF(Stream input)
        {
            using (var br = new BinaryReaderX(input))
            {
                //load files
                xpck = new XPCK(input);

                //get xi image to bmp
                xi  = new IMGC(xpck.Files[0].FileData);
                bmp = xi.Image;

                //decompress fnt.bin
                var tempCharSizeInfo = new List <CharSizeInfo>();
                var largeChars       = new List <CharacterMap>();
                var smallChars       = new List <CharacterMap>();
                using (var fntR = new BinaryReaderX(xpck.Files[1].FileData, true))
                {
                    Header = fntR.ReadType <XFHeader>();

                    fntR.BaseStream.Position = Header.table0Offset << 2;
                    t0Comp = (Level5.Method)(fntR.ReadInt32() & 0x7);
                    fntR.BaseStream.Position -= 4;
                    tempCharSizeInfo          = new BinaryReaderX(new MemoryStream(Level5.Decompress(fntR.BaseStream))).ReadMultiple <CharSizeInfo>(Header.table0EntryCount);

                    fntR.BaseStream.Position = Header.table1Offset << 2;
                    t1Comp = (Level5.Method)(fntR.ReadInt32() & 0x7);
                    fntR.BaseStream.Position -= 4;
                    largeChars = new BinaryReaderX(new MemoryStream(Level5.Decompress(fntR.BaseStream))).ReadMultiple <CharacterMap>(Header.table1EntryCount);

                    fntR.BaseStream.Position = Header.table2Offset << 2;
                    t2Comp = (Level5.Method)(fntR.ReadInt32() & 0x7);
                    fntR.BaseStream.Position -= 4;
                    smallChars = new BinaryReaderX(new MemoryStream(Level5.Decompress(fntR.BaseStream))).ReadMultiple <CharacterMap>(Header.table2EntryCount);
                }

                Textures = new List <Bitmap>();
                var bmpInfo = new BitmapInfo(bmp);
                Textures.Add(bmpInfo.CreateChannelBitmap(BitmapInfo.Channel.Red));
                Textures.Add(bmpInfo.CreateChannelBitmap(BitmapInfo.Channel.Green));
                Textures.Add(bmpInfo.CreateChannelBitmap(BitmapInfo.Channel.Blue));

                //Add Characters
                Characters = new List <XFCharacter>();
                foreach (var glyph in largeChars)
                {
                    var newChar = new XFCharacter
                    {
                        Character      = glyph.code_point,
                        TextureID      = (int)glyph.ColorChannel,
                        GlyphX         = (int)glyph.ImageOffsetX,
                        GlyphY         = (int)glyph.ImageOffsetY,
                        GlyphWidth     = tempCharSizeInfo[(int)glyph.CharSizeInfoIndex].glyph_width,
                        GlyphHeight    = tempCharSizeInfo[(int)glyph.CharSizeInfoIndex].glyph_height,
                        CharacterWidth = (int)glyph.CharWidth,
                        OffsetX        = tempCharSizeInfo[(int)glyph.CharSizeInfoIndex].offset_x,
                        OffsetY        = tempCharSizeInfo[(int)glyph.CharSizeInfoIndex].offset_y,
                    };
                    Characters.Add(newChar);
                }

                /*foreach (var glyph in smallChars)
                 *  Characters.Add(new XFCharacter
                 *  {
                 *      Character = glyph.code_point,
                 *      TextureID = (int)glyph.ColorChannel,
                 *      GlyphX = (int)glyph.ImageOffsetX,
                 *      GlyphY = (int)glyph.ImageOffsetY,
                 *      GlyphWidth = tempCharSizeInfo[(int)glyph.CharSizeInfoIndex].glyph_width,
                 *      GlyphHeight = tempCharSizeInfo[(int)glyph.CharSizeInfoIndex].glyph_height,
                 *      CharacterWidth = (int)glyph.CharWidth,
                 *      OffsetX = tempCharSizeInfo[(int)glyph.CharSizeInfoIndex].offset_x,
                 *      OffsetY = tempCharSizeInfo[(int)glyph.CharSizeInfoIndex].offset_y,
                 *  });*/

                //Add Textures
            }
        }