|
|
发表于 2014-6-2 17:03:11
|
显示全部楼层
本帖最后由 meigen 于 2014-10-10 20:19 编辑 - p+ L+ h: q" g4 w
: D d( k; k- a, }( A7 }
接14楼,单色图的提取稍微麻烦些,他里面只有数据部分而缺少文件头,这个是比较头疼的事情
- W) w1 }/ O' a$ k先用ebdump提取出词典文本(本文),然后在里面获取单色图的代码(<1F44>开头,<1F64>结尾)! X- H/ W$ f4 H! O
可以看到% x2 o" [" {6 ]$ K
<1F44><0001><w=200,h=256>xxx<1F64>[0001A4BD:0027], n8 S* b* w3 |, `2 ?" E0 C. \
这里的w=200,h=256表示图片的尺寸,这个参数后面会用到" ?4 ^( W" ^' z& X
然后<1F64>后面的这一段[0001A4BD:0027]就是单色图数据地址了
+ Z0 w! {$ W& V5 m! p4 V9 e7 o M4 y先写个Demo 把所有地址都提取出来,顺便排一下序,去掉重复:+ M% C. f# h2 A
- static void getMonoTag(String f) {1 B* a( f6 N" k: R. z! _' ^8 Y1 g8 S
- try {/ X' }( J2 v4 S7 H, c
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));
. R2 Y) ~5 t5 _" o - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f+".mono.txt"), "UTF-8"));! N( h& b- V: {
- String line;
/ X9 Y# P5 I2 l/ S7 q! { - ArrayList<String> monos = new ArrayList<String>();; W: u$ k! t3 e# d: T/ f
- while (((line = reader.readLine()) != null)) {: w1 b! K# E, ~1 i. t/ l
- while (line.contains("<1F64>")) {
' t+ S% P% u# P - line = line.substring(line.indexOf("<1F64>") + 6);
" m- c: s% O6 _' M; s# S* ` - monos.add(line.substring(0, 15));
; z1 \5 h/ d6 y' j' q4 H - }; R; W) H/ C7 B8 C; z- \# `$ [* A6 }
- }
l( S, n; X# k- b% C+ F: \ - reader.close();: }5 ?8 [) V! ^
- String[] monoa = new String[monos.size()];3 |# x. i8 A+ h+ ~5 v4 O# T' Z
- monos.toArray(monoa);
M/ V8 q- {4 [7 ?/ O - Arrays.sort(monoa);
4 b L2 R9 B, t7 b' p/ m - String last = "";
: M% J$ r5 {8 {+ c* J$ o - for (int i=0; i<monoa.length; i++) {
( q: `/ i5 |1 g7 c - if (!monoa[i].equals(last))% R0 ?7 b8 q5 z: J+ R) z h" H" a
- writer.write(monoa[i] + "\r\n");
. w% k# O# B& @, Y, m$ v - last = monoa[i];
! v* k9 h( \, T. Z3 F0 p - }
5 }/ x! z* L' K - writer.close();
' S/ J$ l0 i2 R$ j. e# ~9 f8 z3 ] - } catch (Exception e) {' R/ _ y; K/ D( n
- e.printStackTrace();
$ C) l$ V0 ~& j: u1 b) | - }% o" t, h1 q/ w6 [: S7 r& Y( m
- }
复制代码 : B+ ?9 @" W, N! Q) O
得到了一个.mono.txt的文件: W6 @2 j1 D3 G+ @
然后开始提取:% r9 Q G! t8 ]
上面有提到w=200,h=256这两个参数,不过epwing好像弄反了,200是高,256是宽。 - -
/ H" {1 T5 J5 R+ a提取过程中需要手动加上图像的文件头,可自行百度bmp文件格式
T* ]4 V* ]0 @( f, {- static final int WIDTH = 256;
4 q1 B+ n! N6 G# K8 f - static final int HEIGHT = 200;
# v" H6 I% L; a, m; I - static final int WIDTH2 = 32;/ k+ k; d: X+ g, i: {
- static final int SIZE = WIDTH2 * HEIGHT;9 ?6 E4 e! E- N9 `4 B+ z* V
- static final int FILE_LEN = SIZE + 62;& k4 _/ D# D0 {+ N+ D# o
- static byte[] filehead = {0x42, 0x4d,
$ W0 N; V- u. k9 r( }! K" x5 Z - (byte) (FILE_LEN & 0xff), (byte) ((FILE_LEN >> 8) & 0xff), (byte) ((FILE_LEN >> 16) & 0xff), (byte) ((FILE_LEN >> 24) & 0xff),
& R# l& o8 g5 _ - 0, 0, 0, 0, 0x3e, 0, 0, 0};" Z% f; i' o5 R; f/ F3 G; {6 ~! _
- static byte[] infohead = {0x28, 0, 0, 0,
5 o2 ]5 _. \- v0 }$ n - (byte) (WIDTH & 0xff), (byte) ((WIDTH >> 8) & 0xff), (byte) ((WIDTH >> 16) & 0xff), (byte) ((WIDTH >> 24) & 0xff),
1 N1 L- |3 `6 Y4 @/ }) N! ^ - (byte) (HEIGHT & 0xff), (byte) ((HEIGHT >> 8) & 0xff), (byte) ((HEIGHT >> 16) & 0xff), (byte) ((HEIGHT >> 24) & 0xff),1 Q: Q6 G7 f5 R
- 1, 0, 1, 0, 0, 0, 0, 0,
" k/ D4 f0 X6 i4 {6 R# e2 R - (byte) (SIZE & 0xff), (byte) ((SIZE >> 8) & 0xff), (byte) ((SIZE >> 16) & 0xff), (byte) ((SIZE >> 24) & 0xff),2 N* t/ r; p) H$ z5 k3 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};
. G! q" x1 j, G3 Q/ D - static void getMonoPic(String f, String m) {
$ f. B) R% [( x - try {+ {/ R @: w7 J3 v/ g1 @0 ^/ k
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f+".txt"), "Shift_JIS"));* A N; R& R: X! g K+ `( }
- BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(m+".txt"), "UTF-8"));
. S4 z) G8 n) D% ]8 ` - OutputStream out = null;
w. G2 n; M7 M' A1 O1 ]0 P; |, A - String line = "";4 m4 G/ C$ r a1 C' ]
- String line2 = reader2.readLine();
( K% o4 q" I% _; g' ~! n: W$ C+ S - int block = 0;7 n. B8 W" b+ Y. {
- int block2 = Integer.parseInt(line2.substring(1, 9), 16);" e5 O# r+ {7 v6 a
- int offs = Integer.parseInt(line2.substring(10, 14), 16);
+ j9 `3 u, _0 u; U$ n7 B& X! h! E; w - byte[] temp = new byte[2048];
3 g6 ]+ |8 w) y) X! ] - byte[] data = new byte[WIDTH2 * HEIGHT];0 q) n/ y3 k; ~9 N7 y
- int[] idxs = new int[WIDTH2 * HEIGHT];9 b1 z: Z2 P) u0 n) Q
- for (int i=0; i<HEIGHT; i++) {: e7 z; P0 U6 M- M
- idxs[i * WIDTH2] = (HEIGHT - 1 - i) * WIDTH2;
2 \' e$ N4 L) w- v8 ^5 } - for (int j=1; j<WIDTH2; j++)! K9 E& T# Y# X7 c" h7 m4 ]
- idxs[i * WIDTH2 + j] = idxs[i * WIDTH2 + j - 1] + 1;/ E- _3 Z0 B4 ^
- }9 E6 {8 u0 S0 ~: Q
- int idx = 0;4 t7 ]" f. j( x
- int didx = 0;
, @; K# M6 s# a - while (((line = reader.readLine()) != null)) {
1 d: T1 ^3 _7 m x - if(line.startsWith("block")) {! x$ l0 U, E) M6 ]8 R
- block = Integer.parseInt(line.substring(6, 11), 16);+ ~1 N- ?9 j7 _" k
- idx = 0;
# E6 q% i. z$ D/ g - }
( d: S' F; l# i _9 F+ b& ?$ G# g - if(line.startsWith("0")) {
/ a5 i, X9 u( X( V1 w - for(int i=0; i<16; i++) {: ^3 B+ D* Q9 I3 X2 `8 }" c
- int a = CHARS.indexOf(line.charAt(5+3*i));
$ c. f1 _# d: B. K" m - int b = CHARS.indexOf(line.charAt(6+3*i));, g6 n7 h* B. o) T
- temp[idx++] = (byte) (a << 4 | b);
* i2 P8 Y( ]& k* c8 B% ? - }
# _2 Y ]5 L' X: |) c2 H3 U - }; B1 {$ R" w) j! E
- if (idx == 2048) {
: Y% ?$ W3 Z0 k0 W0 t - if(block < block2) continue;
; Y, ]) P: [! H, X+ b - int start = offs;! `/ G% R. G: ~! ~2 A! d& q8 U
- if(didx != 0) start = 0;
; I) O- T( {5 B# ^* c. S - for(int i=0; i<2048; i++) {. q3 C4 @, s/ V( t$ d$ ~9 F; T' b
- if(i >= start)8 S: r; e4 Q5 k' B) [
- data[idxs[didx++]] = temp[i];
" G2 t. f, D3 X# T+ r - if(didx == WIDTH2 * HEIGHT) {
' \: B+ ]( Y. d T+ ^8 F1 k - System.out.println(toHex(block2)+"."+toHex(offs));) M5 j8 p" i3 v: J! g- @
- out = new BufferedOutputStream(new FileOutputStream("pic/"+toHex(block2)+toHex(offs)+".bmp"));
4 ^; w" S) F! O& D4 L( a4 d - out.write(filehead);6 t5 ?* T+ P3 \1 o2 v2 \% v8 a
- out.write(infohead);
. E% Q6 W8 L& E& `6 e; M! M - out.write(data);) I) B; o0 }" b W7 w' l
- out.flush();
% S- F& d5 b2 Z' f) V. y - out.close();
3 P; ?) R9 ]+ m& ]) f Z$ m - line2 = reader2.readLine();
% _5 {! K6 ]& y5 Y - if(line2 == null || line2.equals("")) {
/ `5 T+ `, x$ y - reader.close();1 ?0 G5 ]3 }7 k, l) `2 S* V' D
- reader2.close();
; w5 B o, m, b$ A- V1 { F; _" j - return;" w5 d; @" j, \3 n9 g f
- }
( j5 Q3 L) d8 ?1 d3 \1 J; f - block2 = Integer.parseInt(line2.substring(1, 9), 16);1 x7 P+ ~; W3 H4 s j$ ?
- offs = Integer.parseInt(line2.substring(10, 14), 16);. v* a8 D/ l. m6 |3 g
- didx = 0;
1 B. t9 t% V) g" F' E" Y - }
, \ j+ v& ~4 W, k5 V - }
3 y( g3 G% D$ g - idx = 0;
+ S5 b% Y6 r2 A; j6 |: N! S - }
9 f. D4 |* @3 R3 p n - }! f6 s) V7 K) X
- reader.close();
3 N' F- a- l5 t% O+ E3 ]" Y - reader2.close();
% @9 \) R6 [# g. h6 A) N$ u - } catch (Exception e) {
! S" Q; c* D' p# Z- [1 Z$ D8 M - e.printStackTrace();
2 Q2 F: }, f# [& @ - }
0 y4 ~- t7 W1 i, X; \. Z - }
复制代码
* @2 e+ \6 i$ Z1 Y待编辑...
+ Y k/ V1 H: E7 L! M0 {* x" v& I/ r- W* q
回15楼:9 A5 K# H& e. w$ c* _& ~0 X S
, x/ w/ G% Q8 \6 v代码有一些要改动的地方, 我完善一下就传附件' J K; [' @( J6 H# l1 e
另外用英文说明这...{:11_336:} K4 x. L/ }4 C( X7 J X* V
我先用中文注释一下, 然后再慢慢翻译 |
评分
-
1
查看全部评分
-
|