예제 #1
0
        public void LoadFont(string fontName)
        {
            byte[]       dest;
            FileStream   fs    = File.Open(fontName, FileMode.Open, FileAccess.Read);
            BinaryReader br    = new BinaryReader(fs);
            FontInfo     fInfo = new FontInfo(br);

            br.BaseStream.Seek(fInfo.cfont_offset, SeekOrigin.Begin);
            dest = DecompressTexture(br, fInfo);
            File.WriteAllBytes("font.bin", dest);
            TextureEncoder tenc   = new TextureEncoder();
            int            width  = 480;
            int            height = width * 6;
            Bitmap         bm     = tenc.get4Bpp(width,
                                                 height,
                                                 (int)fInfo.t_width,
                                                 (int)fInfo.t_height,
                                                 dest,
                                                 fInfo.palette_data,
                                                 EndianType.BIG);

            bm.Save("font.png");
        }
예제 #2
0
        public void buildCompress(List <PFontGlyph> pglyphs, FontInfo fInfo, out byte[] dst)
        {
            dst = null;
            int            wndLen         = 0;
            int            decLen         = 0;
            int            compressedsize = 0;
            TextureEncoder encoder        = new TextureEncoder();

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.Write(new byte[0x20]);
                    bw.Write(fInfo.dictData);
                    int        seek_ori = (int)bw.BaseStream.Position;
                    List <int> ptr      = new List <int>();

                    //bw.Write(new byte[(pglyphs.Count + 1) * 4]);
                    MemoryStream mem = new MemoryStream();
                    for (int i = pglyphs.Count - 1; i >= 0; i--)
                    {
                        PFontGlyph glyph = pglyphs[i];
                        byte[]     input = encoder.create4Bpp(glyph.bitmap, fInfo.t_width, fInfo.t_height, encoder.getPS2PaletteData(fInfo.palette_data), EndianType.LITTLE);
                        mem.Write(input, 0, input.Length);
                        decLen = (int)mem.Position;
                    }
                    mem.Position      = 0;
                    int[,] Dictionary = Compression.ReadDict(fInfo.dictData);
                    int          DictPart      = Compression.FindDictPart(Dictionary);
                    MemoryStream FONT_COMPRESS = new MemoryStream();

                    bool boolean = true;
                    while (boolean)
                    {
                        if (mem.Position == mem.Length)
                        {
                            boolean = false;
                        }
                        else
                        {
                            int s4 = mem.ReadByte();
                            int i  = 1;

                            while (Dictionary[i, 1] != s4)
                            {
                                i++;
                                if (Dictionary[i - 1, 1] == 0)
                                {
                                    if ((s4 >> 4) > ((s4 << 4) >> 4))
                                    {
                                        s4 = s4 - (1 << 4);
                                    }
                                    else
                                    {
                                        s4 = s4 - 1;
                                    }
                                    i = 1;
                                }
                            }
                            int v0 = i;
                            while (v0 != 0)
                            {
                                v0 = Compression.FindDictIndex(v0, Dictionary, DictPart, ref FONT_COMPRESS);
                            }
                        }
                    }

                    int          GlyphSize            = 0;
                    MemoryStream FONT_COMPRESS_BUFFER = new MemoryStream();
                    do
                    {
                        int    i   = 0;
                        string str = "";
                        while ((i < 8) & (FONT_COMPRESS.Position != 0))
                        {
                            FONT_COMPRESS.Position--;
                            str = Convert.ToString(FONT_COMPRESS.ReadByte()) + str;
                            FONT_COMPRESS.Position--;
                            i++;
                        }
                        str = str.PadLeft(8, '0');
                        FONT_COMPRESS_BUFFER.WriteByte(Convert.ToByte(str, 2));
                        GlyphSize++;
                    } while (FONT_COMPRESS.Position != 0);

                    FONT_COMPRESS_BUFFER.WriteByte(0);
                    GlyphSize++;
                    byte[] positions;
                    wndLen = Compression.WriteGlyphPosition(FONT_COMPRESS_BUFFER, Dictionary, fInfo, out positions);

                    byte[] comp = FONT_COMPRESS_BUFFER.ToArray();
                    compressedsize = comp.Length;

                    bw.Write(positions);
                    bw.Write(comp);

                    bw.Seek(0, SeekOrigin.Begin);
                    bw.Write((Int32)0x20);
                    bw.Write((Int32)fInfo.dictData.Length);
                    bw.Write((Int32)compressedsize);
                    bw.Write((Int32)wndLen);
                    bw.Write((Int32)fInfo.t_length);
                    bw.Write((Int32)positions.Length / 4);
                    bw.Write((Int32)positions.Length);
                    bw.Write((Int32)decLen);
                }
                dst = ms.ToArray();
            }
        }