… | |
… | |
20 | #include "config.h" |
20 | #include "config.h" |
21 | #include <stdlib.h> |
21 | #include <stdlib.h> |
22 | |
22 | |
23 | #include "data.h" |
23 | #include "data.h" |
24 | #include "parse_routines.h" |
24 | #include "parse_routines.h" |
|
|
25 | |
|
|
26 | int psiconv_parse_mbm_jumptable_section(const psiconv_buffer buf,int lev, |
|
|
27 | psiconv_u32 off, int *length, |
|
|
28 | psiconv_mbm_jumptable_section *result) |
|
|
29 | { |
|
|
30 | int res = 0; |
|
|
31 | int len = 0; |
|
|
32 | psiconv_u32 listlen,temp; |
|
|
33 | int i; |
|
|
34 | |
|
|
35 | psiconv_progress(lev+1,off+len,"Going to read the mbm jumptable section"); |
|
|
36 | (*result) = psiconv_list_new(sizeof(psiconv_u32)); |
|
|
37 | |
|
|
38 | psiconv_progress(lev+2,off+len,"Going to read the list length"); |
|
|
39 | listlen = psiconv_read_u32(buf,lev+2,off+len); |
|
|
40 | psiconv_debug(lev+2,off+len,"List length: %08x",listlen); |
|
|
41 | len += 4; |
|
|
42 | |
|
|
43 | psiconv_progress(lev+2,off+len,"Going to read the list"); |
|
|
44 | for (i = 0; i < listlen; i++) { |
|
|
45 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
46 | psiconv_list_add(*result,&temp); |
|
|
47 | psiconv_debug(lev+3,off+len,"Offset: %08x",temp); |
|
|
48 | len += 4; |
|
|
49 | } |
|
|
50 | |
|
|
51 | if (length) |
|
|
52 | *length = len; |
|
|
53 | |
|
|
54 | psiconv_progress(lev+1,off+len-1,"End of mbm jumptable section " |
|
|
55 | "(total length: %08x)", len); |
|
|
56 | |
|
|
57 | return res; |
|
|
58 | } |
25 | |
59 | |
26 | int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, |
60 | int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, |
27 | psiconv_u32 off, int *length, |
61 | psiconv_u32 off, int *length, |
28 | psiconv_paint_data_section *result) |
62 | psiconv_paint_data_section *result) |
29 | { |
63 | { |
30 | int res = 0; |
64 | int res = 0; |
31 | int len = 0; |
65 | int len = 0; |
|
|
66 | int read_err = 0; |
32 | psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr; |
67 | psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr,linelen; |
33 | psiconv_u8 marker; |
68 | psiconv_u8 marker; |
34 | int i; |
69 | int i; |
35 | |
70 | |
36 | psiconv_progress(lev+1,off,"Going to read a paint data section"); |
71 | psiconv_progress(lev+1,off,"Going to read a paint data section"); |
37 | (*result) = malloc(sizeof(**result)); |
72 | (*result) = malloc(sizeof(**result)); |
… | |
… | |
41 | psiconv_debug(lev+2,off+len,"Section size: %08x",size); |
76 | psiconv_debug(lev+2,off+len,"Section size: %08x",size); |
42 | len += 4; |
77 | len += 4; |
43 | |
78 | |
44 | psiconv_progress(lev+2,off+len,"Going to read pixel data offset"); |
79 | psiconv_progress(lev+2,off+len,"Going to read pixel data offset"); |
45 | offset = psiconv_read_u32(buf,lev+2,off+len); |
80 | offset = psiconv_read_u32(buf,lev+2,off+len); |
46 | if (size != 0x28) { |
81 | if (offset != 0x28) { |
47 | psiconv_warn(lev+2,off+len, |
82 | psiconv_warn(lev+2,off+len, |
48 | "Paint data section data offset has unexpected value"); |
83 | "Paint data section data offset has unexpected value"); |
49 | psiconv_debug(lev+2,off+len, |
84 | psiconv_debug(lev+2,off+len, |
50 | "Data offset: read %08x, expected %08x",offset,0x28); |
85 | "Data offset: read %08x, expected %08x",offset,0x28); |
|
|
86 | res = -1; |
51 | } |
87 | } |
52 | len += 4; |
88 | len += 4; |
53 | |
89 | |
54 | psiconv_progress(lev+2,off+len,"Going to read picture X size"); |
90 | psiconv_progress(lev+2,off+len,"Going to read picture X size"); |
55 | (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len); |
91 | (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len); |
… | |
… | |
59 | psiconv_progress(lev+2,off+len,"Going to read picture Y size"); |
95 | psiconv_progress(lev+2,off+len,"Going to read picture Y size"); |
60 | (*result)->ysize = psiconv_read_u32(buf,lev+2,off+len); |
96 | (*result)->ysize = psiconv_read_u32(buf,lev+2,off+len); |
61 | psiconv_debug(lev+2,off+len,"Picture Y size: %08x:",(*result)->ysize); |
97 | psiconv_debug(lev+2,off+len,"Picture Y size: %08x:",(*result)->ysize); |
62 | len += 4; |
98 | len += 4; |
63 | |
99 | |
64 | picsize = (*result)->ysize * (*result)->xsize; |
100 | picsize = (*result)->ysize * (*result)->xsize * 2; |
|
|
101 | linelen = (*result)->xsize; |
65 | |
102 | |
66 | psiconv_progress(lev+2,off+len,"Going to read 6 unused longs"); |
103 | psiconv_progress(lev+2,off+len,"Going to read 6 unused longs"); |
67 | for (i = 0 ; i < 6; i++) { |
104 | for (i = 0 ; i < 6; i++) { |
68 | temp = psiconv_read_u32(buf,lev+2,off+len); |
105 | temp = psiconv_read_u32(buf,lev+2,off+len); |
69 | if (temp != 0x00) { |
106 | if (temp != 0x00) { |
70 | psiconv_warn(lev+2,off+len, |
107 | psiconv_warn(lev+2,off+len, |
71 | "Paint data section prologue has unknown values"); |
108 | "Paint data section prologue has unknown values"); |
72 | psiconv_debug(lev+2,off+len, |
109 | psiconv_debug(lev+2,off+len, |
73 | "offset %02x: read %08x, expected %08x",i,temp,0x00); |
110 | "offset %02x: read %08x, expected %08x",i,temp,0x00); |
|
|
111 | res = -1; |
74 | } |
112 | } |
75 | len += 4; |
113 | len += 4; |
76 | } |
114 | } |
77 | |
115 | |
78 | (*result)->red = malloc(sizeof(float) * picsize); |
116 | (*result)->red = malloc(sizeof(float) * picsize); |
… | |
… | |
97 | psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); |
135 | psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); |
98 | psiconv_debug(lev+3,off+len+datanr, |
136 | psiconv_debug(lev+3,off+len+datanr, |
99 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
137 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
100 | "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, |
138 | "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, |
101 | datanr,marker); |
139 | datanr,marker); |
|
|
140 | res = -1; |
|
|
141 | read_err = 1; |
102 | } else { |
142 | } else { |
103 | for (i = 0; i < 0x100-marker; i++) { |
143 | for (i = 0; i < 0x100-marker; i++) { |
104 | temp = psiconv_read_u8(buf,lev+3,off+len+datanr+i); |
144 | temp = psiconv_read_u8(buf,lev+3,off+len+datanr+i); |
105 | (*result)->red[pixelnr + i*4] = |
145 | (*result)->red[pixelnr + i*4] = |
106 | (*result)->green[pixelnr + i*4] = |
146 | (*result)->green[pixelnr + i*4] = |
… | |
… | |
128 | psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); |
168 | psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); |
129 | psiconv_debug(lev+3,off+len+datanr, |
169 | psiconv_debug(lev+3,off+len+datanr, |
130 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
170 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
131 | "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, |
171 | "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, |
132 | datanr,marker); |
172 | datanr,marker); |
|
|
173 | res = -1; |
|
|
174 | read_err = 1; |
133 | } else { |
175 | } else { |
134 | temp = psiconv_read_u8(buf,lev+3,off+len+datanr); |
176 | temp = psiconv_read_u8(buf,lev+3,off+len+datanr); |
135 | for (i = 0; i < marker; i++) { |
177 | for (i = 0; i < marker; i++) { |
136 | (*result)->red[pixelnr + i*4] = |
178 | (*result)->red[pixelnr + i*4] = |
137 | (*result)->green[pixelnr + i*4] = |
179 | (*result)->green[pixelnr + i*4] = |
138 | (*result)->blue[pixelnr + i*4] = |
180 | (*result)->blue[pixelnr + i*4] = |
139 | (temp & 0x03) * (1.0/3.0); |
181 | (temp & 0x03) * (1.0/3.0); |
140 | (*result)->red[pixelnr + i*4 + 1] = |
182 | (*result)->red[pixelnr + i*4 + 1] = |
… | |
… | |
153 | } |
195 | } |
154 | pixelnr += marker * 4; |
196 | pixelnr += marker * 4; |
155 | datanr += 1; |
197 | datanr += 1; |
156 | } |
198 | } |
157 | } |
199 | } |
|
|
200 | if (!read_err && ((datanr != datasize) || (pixelnr != picsize))) { |
|
|
201 | psiconv_warn(lev+2,off+len,"Corrupted picture data!"); |
|
|
202 | psiconv_debug(lev+3,off+len+datanr, |
|
|
203 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
|
|
204 | "Datanr: %08x",picsize,datasize,pixelnr,datanr); |
|
|
205 | res = -1; |
|
|
206 | } |
|
|
207 | |
158 | len += datanr; |
208 | len += datanr; |
159 | |
209 | |
160 | if (length) |
210 | if (length) |
161 | *length = len; |
211 | *length = len; |
162 | |
212 | |
163 | psiconv_progress(lev+1,off+len-1,"End of paint data section " |
213 | psiconv_progress(lev+1,off+len-1,"End of paint data section " |
164 | "(total length: %08x", len); |
214 | "(total length: %08x)", len); |
165 | |
215 | |
166 | return res; |
216 | return res; |
167 | } |
217 | } |
168 | |
218 | |
169 | |
219 | |