|
发表于 2014-6-2 17:03:11
|
显示全部楼层
本帖最后由 meigen 于 2014-10-10 20:19 编辑
$ w* R* R7 Y& t8 D! ^+ d6 a* V/ V; M( P3 U" _! y8 F& v' y
接14楼,单色图的提取稍微麻烦些,他里面只有数据部分而缺少文件头,这个是比较头疼的事情
! P/ R) R8 U8 v- K先用ebdump提取出词典文本(本文),然后在里面获取单色图的代码(<1F44>开头,<1F64>结尾)( o% q. S2 G0 N) D% A3 h
可以看到6 ^0 f. X1 R- `3 p; [8 R6 w& u# H
<1F44><0001><w=200,h=256>xxx<1F64>[0001A4BD:0027]' N- k2 Z% f5 W |; o
这里的w=200,h=256表示图片的尺寸,这个参数后面会用到2 [( F) |1 C3 V" t: J
然后<1F64>后面的这一段[0001A4BD:0027]就是单色图数据地址了
T2 u4 m1 x \) |先写个Demo 把所有地址都提取出来,顺便排一下序,去掉重复:- T1 ^0 N+ ]6 o6 _2 |8 C5 q5 |
- static void getMonoTag(String f) {" a2 X5 Q W$ M+ [6 O/ L( {) T% u8 D
- try {
$ O% S& _+ R% U+ b - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));, q& @( e9 w9 A. m. @
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f+".mono.txt"), "UTF-8"));( o j4 ^; }/ T2 ~
- String line; A$ @ g( d% \8 Y: ^- K" ]
- ArrayList<String> monos = new ArrayList<String>();
! ~% E; K5 n. Y: m! g1 w - while (((line = reader.readLine()) != null)) {7 s6 H, U/ W9 ~8 }; t7 C& N: n
- while (line.contains("<1F64>")) {
- E& \+ \. h4 S) C - line = line.substring(line.indexOf("<1F64>") + 6); r' e- M& O7 K# Y% F$ l
- monos.add(line.substring(0, 15));, r" v4 }* _3 ^. J! l. {; T6 N
- }
. o7 m8 k, V% y+ u0 J+ x, I' O - }" s! B& E6 X3 Z
- reader.close();
* O e8 f* J1 n0 _; C7 J - String[] monoa = new String[monos.size()];9 T& \ n# h0 c& @/ a% v9 Y
- monos.toArray(monoa);6 }8 z' y& t* y. `1 ]% N, W" a, [
- Arrays.sort(monoa);
w2 Q2 y+ S) q) z - String last = "";9 c4 N9 r6 l* U
- for (int i=0; i<monoa.length; i++) {/ ]! ]# B6 y' l
- if (!monoa[i].equals(last))
" d4 Q! S3 C) g" x) Z/ v* } - writer.write(monoa[i] + "\r\n");& {; Y2 G; J ~; v" k
- last = monoa[i];
6 a$ u0 K1 c9 X7 @ - }
* w# a" h& O6 D' A/ S - writer.close();7 o0 @( }# r$ [3 [# }6 j
- } catch (Exception e) {7 [- ]( W; u; j1 b
- e.printStackTrace();, K# K" c3 ]/ y0 D" w4 T
- }
) w3 L- G3 ?* l3 b7 X. O. Q - }
复制代码 6 t0 R0 u1 }! }
得到了一个.mono.txt的文件8 h4 y" X2 Z2 B& Q/ |& Z, F8 r
然后开始提取:+ Z: i/ c* i& B4 l7 Z2 @$ h9 g: B
上面有提到w=200,h=256这两个参数,不过epwing好像弄反了,200是高,256是宽。 - -; c7 Q r( _: r `& I
提取过程中需要手动加上图像的文件头,可自行百度bmp文件格式: p* }1 T" v( P# c! O2 k7 y2 ?
- static final int WIDTH = 256;# c9 n+ y v( J+ [+ |9 y# u' ?
- static final int HEIGHT = 200;
, v9 _ z- n. v - static final int WIDTH2 = 32;0 Y0 F& H u+ b+ z$ ]( \" G3 ]
- static final int SIZE = WIDTH2 * HEIGHT;; o1 S0 T) `+ z i
- static final int FILE_LEN = SIZE + 62;
. x$ L9 v) u3 [7 h6 g, r - static byte[] filehead = {0x42, 0x4d,
# D$ s: j; H& M - (byte) (FILE_LEN & 0xff), (byte) ((FILE_LEN >> 8) & 0xff), (byte) ((FILE_LEN >> 16) & 0xff), (byte) ((FILE_LEN >> 24) & 0xff),& U6 Z( l5 A! a+ z: S4 I
- 0, 0, 0, 0, 0x3e, 0, 0, 0};. u' p4 |) H5 d6 Q* S3 K' }
- static byte[] infohead = {0x28, 0, 0, 0,. N/ `' x) f+ o2 C" U( z% m0 T: m( z
- (byte) (WIDTH & 0xff), (byte) ((WIDTH >> 8) & 0xff), (byte) ((WIDTH >> 16) & 0xff), (byte) ((WIDTH >> 24) & 0xff),
5 l; U! {1 x* X4 Y' j* n6 T- Y - (byte) (HEIGHT & 0xff), (byte) ((HEIGHT >> 8) & 0xff), (byte) ((HEIGHT >> 16) & 0xff), (byte) ((HEIGHT >> 24) & 0xff),
) N9 u/ }$ P8 V; W* z$ _6 E - 1, 0, 1, 0, 0, 0, 0, 0,, ?4 I& l% w) a
- (byte) (SIZE & 0xff), (byte) ((SIZE >> 8) & 0xff), (byte) ((SIZE >> 16) & 0xff), (byte) ((SIZE >> 24) & 0xff),
& M+ ~$ r' V3 R# ^ - 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0};" m* q. j1 g+ \ R9 @1 V
- static void getMonoPic(String f, String m) {# p3 w/ N( b1 B2 {7 O
- try {
! i, X$ H. W& T* P0 ? - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));
; y' k- C8 M# ^ U - BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(m+".txt"), "UTF-8"));; n% ]' c. U1 J: F
- OutputStream out = null;
, e/ ]+ m' \: f2 b5 j+ |+ D - String line = "";
! z" w' c( i7 \+ Y4 x- { - String line2 = reader2.readLine();
; j8 H) V7 ]( U1 }0 l3 Z - int block = 0;
9 J( q, Y5 @2 v: ^# c- s& F6 H! E - int block2 = Integer.parseInt(line2.substring(1, 9), 16);
4 F/ l2 r( i* D- W1 K - int offs = Integer.parseInt(line2.substring(10, 14), 16);
2 q7 ^8 p K( _1 v/ W( Y" ~ - byte[] temp = new byte[2048];) _6 Z0 a9 L. Q; v
- byte[] data = new byte[WIDTH2 * HEIGHT];
% G3 u6 m0 G8 v5 E1 K+ \3 t- r* R - int[] idxs = new int[WIDTH2 * HEIGHT];
6 e U' o. w) ]$ H& u4 F% s" l - for (int i=0; i<HEIGHT; i++) {2 N% U. T( l- G& K4 o
- idxs[i * WIDTH2] = (HEIGHT - 1 - i) * WIDTH2;8 e# B5 E# p0 [! a
- for (int j=1; j<WIDTH2; j++)+ O9 h( R5 `' |$ n* {# I
- idxs[i * WIDTH2 + j] = idxs[i * WIDTH2 + j - 1] + 1;# n+ W) L2 n/ I' ]) V
- }
- P* d% }- F' l- d3 ~9 C6 t - int idx = 0;0 h f5 P" l. X) S3 U% D$ g p
- int didx = 0;
. y' c% M+ n& W' n1 D; e1 Q - while (((line = reader.readLine()) != null)) {
' ~& l7 z( u4 H: j# V/ ]2 p% Q - if(line.startsWith("block")) {' o, z$ g5 L4 j2 G' p
- block = Integer.parseInt(line.substring(6, 11), 16);7 `7 G/ i c: a! a6 V' T/ B& z% S2 `
- idx = 0;/ ]: C/ e9 z4 K& @
- }
# A1 l5 ~; M5 k6 H- M: T - if(line.startsWith("0")) {
9 d& T) [9 k6 ?3 a0 ^) b - for(int i=0; i<16; i++) {$ C/ N# i0 x$ ~/ [, K- y
- int a = CHARS.indexOf(line.charAt(5+3*i));% R% D! {/ t2 k3 u. q$ O
- int b = CHARS.indexOf(line.charAt(6+3*i));
& V) c2 }; H' W; W$ z6 C" {' ` - temp[idx++] = (byte) (a << 4 | b);
* r; H9 {7 h" z8 a8 N% B - }
- G# e1 W/ j2 i - }
+ j, C, B% E0 d9 @ - if (idx == 2048) {+ @2 j; b! U% l# A
- if(block < block2) continue;% Y( A! t0 a; j$ K. ^
- int start = offs;& |. [( E) k8 k
- if(didx != 0) start = 0;
" W* y5 F, A' b2 V - for(int i=0; i<2048; i++) {
0 v, F! x$ @0 ~ - if(i >= start)
# h' Q. D) v4 i+ A9 O - data[idxs[didx++]] = temp[i];9 W* X; w) F- U5 W
- if(didx == WIDTH2 * HEIGHT) {
* B. \8 e9 m7 k1 U( q - System.out.println(toHex(block2)+"."+toHex(offs));# M: D, ]" q. y# h* s! { A
- out = new BufferedOutputStream(new FileOutputStream("pic/"+toHex(block2)+toHex(offs)+".bmp"));/ {- T4 K( _. A! m; B5 d
- out.write(filehead);: a" l. j- z& R1 [. C, h
- out.write(infohead);
9 C* n; M- |* T6 c- q - out.write(data);3 b, n/ { ?8 w# Q1 d" r! d" V
- out.flush();0 N+ v+ C8 Q) e4 S' \/ s6 _* F
- out.close();: v- G2 k/ k0 I" D
- line2 = reader2.readLine();) Y" m' E Y3 E4 `$ {* t' w
- if(line2 == null || line2.equals("")) {
+ ^& s. S6 N9 S& g% B% \ - reader.close();5 Y/ K6 e h) ^# q0 q L
- reader2.close();, m$ c& Z P, y( ]/ J
- return;
1 p! [$ @$ g/ C3 d - }
% a: \8 y+ n2 L+ q, W7 t - block2 = Integer.parseInt(line2.substring(1, 9), 16);
! t% o p* H6 ] - offs = Integer.parseInt(line2.substring(10, 14), 16);( }: S; I4 E8 o( x' ~; K. ~
- didx = 0;6 @8 e( N& \2 i+ H% H
- }; L/ X: I' H! i1 R2 t
- }7 Y, Y I: {% R4 b0 a" B& |7 e
- idx = 0; C0 Q, R9 M, s4 W! C! {6 z- O
- } Q7 j7 r: A( }1 s
- }0 \3 ]+ \, E* ~' |
- reader.close();, B7 ~- m& {; r6 A1 j2 i! Q9 m
- reader2.close();
8 A- Z7 c) E; w: e- ~8 T) y - } catch (Exception e) {# l; z" P: a+ a* n0 W( n$ U
- e.printStackTrace();: N7 w% b% m2 b4 x. \( A# s
- }2 D0 W8 r! |( p3 z T
- }
复制代码 2 X5 B9 I! j. ^+ Z7 H
待编辑...9 q; M& ^1 ?0 V' ~ o
2 P* T6 r# w( Z2 n1 ]* t! _
回15楼: |0 S4 W. P; |; L4 C7 X4 a6 t1 q
, S% c8 v9 c# `/ Z. l* j代码有一些要改动的地方, 我完善一下就传附件& g; F4 a/ k* l; l: e) u- G
另外用英文说明这...{:11_336:} 8 b3 t0 n$ Q7 b. D
我先用中文注释一下, 然后再慢慢翻译 |
评分
-
1
查看全部评分
-
|