|
|
发表于 2014-6-2 17:03:11
|
显示全部楼层
本帖最后由 meigen 于 2014-10-10 20:19 编辑
7 [ u- z: u' X3 W G" h
9 _ @6 B* z* H6 ?1 ~; X1 L& z: J接14楼,单色图的提取稍微麻烦些,他里面只有数据部分而缺少文件头,这个是比较头疼的事情
# {# k' Q6 G" _. x+ F1 l0 [先用ebdump提取出词典文本(本文),然后在里面获取单色图的代码(<1F44>开头,<1F64>结尾)
+ G# ~ v* {* L( S8 ^; r可以看到
) I3 r9 J* i4 d. s<1F44><0001><w=200,h=256>xxx<1F64>[0001A4BD:0027]
" V6 e' M% ~7 \这里的w=200,h=256表示图片的尺寸,这个参数后面会用到
! Z8 H2 M. x5 A# _然后<1F64>后面的这一段[0001A4BD:0027]就是单色图数据地址了* w# D& A: f' j, I# N- R
先写个Demo 把所有地址都提取出来,顺便排一下序,去掉重复:) b+ d# p4 E3 ^4 T0 v; g
- static void getMonoTag(String f) {. F8 T3 r; k, t( g& b
- try {
' _% K; Z* _& h2 e* R) A, V - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));
7 J! N7 e! h% u# B( M - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f+".mono.txt"), "UTF-8"));
$ l# g, [0 J' R- Z, z# Y+ g - String line;( s3 g3 A: o0 x1 ?5 v! ]" ]0 h
- ArrayList<String> monos = new ArrayList<String>();
0 o# g9 v+ N# l# p' [ - while (((line = reader.readLine()) != null)) {
( r' T6 {* K3 c t! A6 q0 C1 d6 { - while (line.contains("<1F64>")) {) W. P8 x) @" z4 r1 P2 }4 R
- line = line.substring(line.indexOf("<1F64>") + 6);9 t' z- L# w9 g! U! A& N" B+ x7 o
- monos.add(line.substring(0, 15));4 V* V8 I/ V7 i4 b# f2 B8 t
- }" |& z+ _) }: h1 q$ x8 {# I# h& E
- }
$ u8 C# X9 ]6 u- y( u3 V) m4 z - reader.close();
2 m& [0 k& [# |/ u - String[] monoa = new String[monos.size()];
2 Y# e$ w/ q+ [8 ~2 u1 Z5 ^8 g" z - monos.toArray(monoa);, K; p( y) T; f' E6 s# R
- Arrays.sort(monoa);
0 k+ j5 E% Z: B/ n& u6 B6 O3 r% k - String last = "";' f4 J! B# O4 p* f, N! L( E
- for (int i=0; i<monoa.length; i++) {
/ F- c! R' `7 C$ o( b) e, Z - if (!monoa[i].equals(last))
; X" ?' z- f* O0 { - writer.write(monoa[i] + "\r\n"); {1 Q( D N+ N1 ^9 j& b+ E
- last = monoa[i];
) f0 b! J; ^0 k! U" y$ h6 b - }
' f: M/ Z+ P3 K( u - writer.close();
! G; A; {! M4 s - } catch (Exception e) {
6 d1 w7 h: J- t! P% Y - e.printStackTrace();( F' x% m K6 n7 |
- }
2 n. `% N6 f8 ^5 a% t- g - }
复制代码
! N3 `6 X! E( s+ K$ _! |" M得到了一个.mono.txt的文件
/ C1 O8 a* i' v t% D3 R- ~* X然后开始提取:& z% I' [! Z3 q7 a4 I
上面有提到w=200,h=256这两个参数,不过epwing好像弄反了,200是高,256是宽。 - -
& R3 g! ?5 @1 ]0 k( I8 n9 D提取过程中需要手动加上图像的文件头,可自行百度bmp文件格式) L7 |9 P! {/ m
- static final int WIDTH = 256;; K: @4 C( n4 X) T
- static final int HEIGHT = 200;
; t+ ^) D0 _$ @5 T - static final int WIDTH2 = 32;' b5 n: B+ i) b v3 ~
- static final int SIZE = WIDTH2 * HEIGHT;
# X y2 J' H" F9 y$ k - static final int FILE_LEN = SIZE + 62;& P5 \3 c# f: P& W% E7 i
- static byte[] filehead = {0x42, 0x4d,
" e" L% D4 h1 k9 m# A - (byte) (FILE_LEN & 0xff), (byte) ((FILE_LEN >> 8) & 0xff), (byte) ((FILE_LEN >> 16) & 0xff), (byte) ((FILE_LEN >> 24) & 0xff),( I- v2 L$ V, f3 N& P
- 0, 0, 0, 0, 0x3e, 0, 0, 0};. X4 {7 h2 k6 J! g9 v
- static byte[] infohead = {0x28, 0, 0, 0,/ E/ Z: @. W2 V: r
- (byte) (WIDTH & 0xff), (byte) ((WIDTH >> 8) & 0xff), (byte) ((WIDTH >> 16) & 0xff), (byte) ((WIDTH >> 24) & 0xff),0 q1 n3 X& @$ n. O0 F
- (byte) (HEIGHT & 0xff), (byte) ((HEIGHT >> 8) & 0xff), (byte) ((HEIGHT >> 16) & 0xff), (byte) ((HEIGHT >> 24) & 0xff),2 I) c5 R4 k# X& J
- 1, 0, 1, 0, 0, 0, 0, 0,
8 b5 c- h N$ u4 W, ~0 C - (byte) (SIZE & 0xff), (byte) ((SIZE >> 8) & 0xff), (byte) ((SIZE >> 16) & 0xff), (byte) ((SIZE >> 24) & 0xff),
2 k- Z" E. A. A/ U- U - 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0};
( a6 i2 r# _9 I1 R - static void getMonoPic(String f, String m) {, X5 o6 `, }. q K# e9 Y! N
- try {
/ N8 l% D( K' }! ~5 ^1 d- ` - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));
! r- q8 ^; J- e3 O) n - BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(m+".txt"), "UTF-8"));
( S7 Y8 j0 K/ F# H - OutputStream out = null;
, h @) q& F% S0 T2 R7 h - String line = "";( T- R# u# d9 R
- String line2 = reader2.readLine();
5 ^% k: U) h& B - int block = 0;8 ^+ B# w( N, X# f4 c6 T! |
- int block2 = Integer.parseInt(line2.substring(1, 9), 16);1 z& i1 X5 ^: a3 T9 ]
- int offs = Integer.parseInt(line2.substring(10, 14), 16);
' _5 v- \: y: j# S5 \; [8 I - byte[] temp = new byte[2048];
* z+ o {" x( q% q( f - byte[] data = new byte[WIDTH2 * HEIGHT];
: @# A; B; w% @4 H$ ^. l - int[] idxs = new int[WIDTH2 * HEIGHT];
- Q% P1 n" o$ M* E1 s - for (int i=0; i<HEIGHT; i++) {, e9 a% {2 i8 p) T
- idxs[i * WIDTH2] = (HEIGHT - 1 - i) * WIDTH2;& v0 C: s) D. @8 W4 C- q
- for (int j=1; j<WIDTH2; j++)
9 K9 R( C+ R. d. S$ \/ t9 |+ `8 a7 z - idxs[i * WIDTH2 + j] = idxs[i * WIDTH2 + j - 1] + 1;. d L/ g0 P- J. F3 d! |; a7 V
- } |5 _5 s( s" f* K/ M8 J
- int idx = 0;) k( k: q: D+ F; \( k/ X, t
- int didx = 0;4 i3 s1 \( U& q& Z; L# k* J$ Q
- while (((line = reader.readLine()) != null)) {; z6 A& T" [$ q" `
- if(line.startsWith("block")) {# l. V1 J' T" ]) e* G) x
- block = Integer.parseInt(line.substring(6, 11), 16);8 @: a+ I ~" E' G. c
- idx = 0;& g* I: a9 D# C L6 {2 ^7 a
- }
3 o4 U+ R) c; ? - if(line.startsWith("0")) {
' d V( j/ z+ p2 e* Q - for(int i=0; i<16; i++) {
/ F' |& U% s0 q8 x( D - int a = CHARS.indexOf(line.charAt(5+3*i));
& M8 \. R- K9 d S% [ - int b = CHARS.indexOf(line.charAt(6+3*i));1 i9 l0 }% r( Q- D/ o* ]- K" x' f1 S
- temp[idx++] = (byte) (a << 4 | b);. C) }- O; `6 ` V
- }) H8 i0 L: ~4 L+ b0 A
- }
$ b. J+ \, ^- L# e; h - if (idx == 2048) {
+ }/ z& _* C" S- V0 Q0 e - if(block < block2) continue;
7 v7 l, i+ `# d K% e6 p B$ q6 R# E- T - int start = offs;5 x6 _& b/ [( l- @8 z
- if(didx != 0) start = 0;1 u* P- l0 ~2 T+ D+ j# y7 Y$ s
- for(int i=0; i<2048; i++) {
7 S- W7 l; p) {5 L3 ~ - if(i >= start)" H8 O. y: n' l. ~
- data[idxs[didx++]] = temp[i];. g8 D4 V- G: i2 v+ W4 P+ l
- if(didx == WIDTH2 * HEIGHT) {
! f6 p# ]- C4 }/ `) i- Y - System.out.println(toHex(block2)+"."+toHex(offs));
* t# c0 k f" o7 O - out = new BufferedOutputStream(new FileOutputStream("pic/"+toHex(block2)+toHex(offs)+".bmp"));
0 j; l8 f# S$ U1 u# Z - out.write(filehead);% G" j: d# W- B
- out.write(infohead);: H/ \8 C2 x$ o
- out.write(data);1 l& }- L7 F& R- \2 L
- out.flush();, K" ~, [) {- A9 K9 S* R: ]
- out.close();9 V5 r: M0 h6 U) d2 ]
- line2 = reader2.readLine();2 z, r' r; H; o) | t
- if(line2 == null || line2.equals("")) {
3 ^0 M& V) X' N8 j - reader.close(); C. k5 M$ _% }) k6 _+ w5 S: B
- reader2.close();
0 G- r4 O0 M4 k4 U* n - return;
( L+ M$ h1 }9 k) U - }) p X! Q9 G" m6 S9 _% W- Q& B
- block2 = Integer.parseInt(line2.substring(1, 9), 16);
# b% Z, `9 p, j2 f: r - offs = Integer.parseInt(line2.substring(10, 14), 16);
. f" r. a% O; e7 p( z) v - didx = 0;" o, @) t2 ^& f( O6 U& {
- }; f, F3 f! q& n% X& p! d* y( i4 E; g
- }
# ~1 w6 W) w; p3 J$ [2 f - idx = 0;
& u! R. j' P; o - }
; O5 ]+ U/ W" v( p5 |9 \ - }2 o/ S8 G; K$ A0 g4 b4 `( e( k
- reader.close();
2 c8 v, T) O# F - reader2.close();
8 T( S5 I7 [; o; C8 o" k5 }* F - } catch (Exception e) {
0 r4 a! W! X( S( u5 V9 `1 r - e.printStackTrace();
7 Y" ?4 S$ ^. _) J5 b m - }5 [$ }1 K! `; _; r$ q
- }
复制代码 5 z# j( H @! K! C1 C
待编辑...
3 T; e4 l7 }# p( e% J/ u+ ` v0 S! s, A2 u; t2 |
回15楼:
, E- l& u. b7 T/ _. F
# j9 H# a) c" W( C9 g代码有一些要改动的地方, 我完善一下就传附件
* m3 W) K2 \3 A; L/ k) x' ]另外用英文说明这...{:11_336:} 5 D! S7 ]* |2 n( v' I# F% q H
我先用中文注释一下, 然后再慢慢翻译 |
评分
-
1
查看全部评分
-
|