Advertisement
mkv

C# pbm decode / gocr cache explorer

mkv
Sep 10th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace textblit
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         Ptn[] ptn;
  22.         private class Ptn
  23.         {
  24.             public string fn;
  25.             public string asc;
  26.             public Ptn(string f, string a)
  27.             {
  28.                 fn = f;
  29.                 asc = a;
  30.             }
  31.         }
  32.  
  33.         private void Form1_Load(object sender, EventArgs e)
  34.         {
  35.             Timer t = new Timer();
  36.             t.Interval = 100;
  37.             t.Start();
  38.             t.Tick += t_Tick;
  39.         }
  40.  
  41.         void t_Tick(object sender, EventArgs e)
  42.         {
  43.             ((Timer)sender).Stop();
  44.             gp.BackgroundImage = null;
  45.             List<Ptn> lptn = new List<Ptn>();
  46.             string[] strs = System.IO.File.ReadAllLines(@"C:\inc\b64\db\dbdb.lst");
  47.             foreach (string str in strs)
  48.             {
  49.                 int i = str.IndexOf(' ');
  50.                 string a = str.Substring(i + 1);
  51.                 lptn.Add(new Ptn(str.Substring(0, i),
  52.                     a.Length == 1 ? a :
  53.                     a[0] == '"' ? a.Substring(1, a.Length - 2) :
  54.                     ((char)Convert.ToInt32(a, 16)).ToString()));
  55.             }
  56.             ptn = lptn.ToArray();
  57.             Array.Sort(ptn, (x,y) =>
  58.                 x.asc.Length == 1 && y.asc.Length == 1 ? x.asc[0] - y.asc[0] :
  59.                 x.asc.Length == y.asc.Length ? x.asc.CompareTo(y.asc) :
  60.                 x.asc.Length - y.asc.Length);
  61.             set(0);
  62.         }
  63.         void fuck()
  64.         {
  65.             Bitmap bsrc = new Bitmap("src.png");
  66.             Bitmap bout = new Bitmap(bsrc.Width * 2, bsrc.Height, bsrc.PixelFormat);
  67.             BitmapData dsrc = bsrc.LockBits(new Rectangle(0, 0, bsrc.Width, bsrc.Height), ImageLockMode.ReadOnly, bsrc.PixelFormat);
  68.             BitmapData dout = bsrc.LockBits(new Rectangle(0, 0, bout.Width, bout.Height), ImageLockMode.WriteOnly, bout.PixelFormat);
  69.             int sz = dsrc.Stride * dsrc.Height;
  70.             byte[] ci = new byte[dsrc.Stride];
  71.             byte[] co = new byte[dout.Stride];
  72.             for (int x = 0; x < ci.Length; x++) ci[x] = 255;
  73.             for (int x = 0; x < co.Length; x++) co[x] = 255;
  74.             for (int y = 0; y < bsrc.Height; y++)
  75.             {
  76.                 System.Runtime.InteropServices.Marshal.Copy(dsrc.Scan0, ci, dsrc.Stride * y, dsrc.Stride);
  77.                 for (int x = 0; x < bsrc.Width; x++)
  78.                 {
  79.                     co[x] = ci[x];
  80.                 }
  81.                 System.Runtime.InteropServices.Marshal.Copy(co, 0, dout.Scan0 + dout.Stride * y, dout.Stride);
  82.             }
  83.             bsrc.UnlockBits(dsrc);
  84.             bout.UnlockBits(dout);
  85.             bout.Save("test.bmp");
  86.         }
  87.  
  88.         private void gn_KeyDown(object sender, KeyEventArgs e)
  89.         {
  90.             int i = 0;
  91.             try
  92.             {
  93.                 i = Convert.ToInt32(gn.Text);
  94.                 if (e.KeyCode == Keys.Down) i--;
  95.                 if (e.KeyCode == Keys.Up) i++;
  96.                 set(i);
  97.             }
  98.             catch { }
  99.         }
  100.  
  101.         private void gs_KeyUp(object sender, KeyEventArgs e)
  102.         {
  103.             int dir = 0;
  104.             int ofs = 0;
  105.             Int32.TryParse(gn.Text, out ofs);
  106.             if (e.KeyCode == Keys.Down) dir--;
  107.             if (e.KeyCode == Keys.Up) dir++;
  108.             if (dir != 0)
  109.             {
  110.                 for (ofs += dir; dir > 0 ? ofs < ptn.Length : ofs > 1; ofs += dir)
  111.                 {
  112.                     if (gs.Text == ptn[ofs].asc)
  113.                     {
  114.                         set(ofs);
  115.                         return;
  116.                     }
  117.                 }
  118.             }
  119.             if (e.KeyCode == Keys.Enter)
  120.             {
  121.                 ptn[ofs].asc = gs.Text;
  122.                 set(ofs);
  123.             }
  124.         }
  125.  
  126.         void set(int i)
  127.         {
  128.             byte[] data = System.IO.File.ReadAllBytes(@"C:\inc\b64\db\db" + ptn[i].fn);
  129.             gn.Text = i.ToString();
  130.             gt.Text = gs.Text = ptn[i].asc;
  131.             gs.SelectionStart = gs.Text.Length;
  132.             label1.Text = ptn[i].fn;
  133.             string res = null;
  134.             int a = 3;
  135.             for (; a < 90; a++)
  136.             {
  137.                 if (data[a] == '\n')
  138.                 {
  139.                     res = Encoding.UTF8.GetString(data, 3, a - 3);
  140.                     break;
  141.                 }
  142.             }
  143.             if (string.IsNullOrEmpty(res)) return;
  144.             string[] ress = res.Split(' ');
  145.             Bitmap bm = new Bitmap(
  146.                 Convert.ToInt32(ress[0]),
  147.                 Convert.ToInt32(ress[1]));
  148.  
  149.             int x = 0, y = 0; //a--;
  150.             while (++a < data.Length)
  151.             {
  152.                 for (int n = 7; n >= 0; n--)
  153.                 {
  154.                     bool black = (data[a] & (1 << n)) == 0;
  155.                     bm.SetPixel(x, y, black ? Color.Black : Color.White);
  156.                     if (++x >= bm.Width)
  157.                     {
  158.                         x = 0;
  159.                         n = 0;
  160.                         if (++y >= bm.Height)
  161.                         {
  162.                             goto lolgoto;
  163.                         }
  164.                     }
  165.                 }
  166.             }
  167.        
  168.         lolgoto:
  169.             if (gp.BackgroundImage != null)
  170.                 gp.BackgroundImage.Dispose();
  171.             gp.BackgroundImage = bm;
  172.         }
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement