… | |
… | |
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_jumptable_section(const psiconv_buffer buf,int lev, |
|
|
27 | psiconv_u32 off, int *length, |
|
|
28 | psiconv_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 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 jumptable section " |
|
|
55 | "(total length: %08x)", len); |
|
|
56 | |
|
|
57 | return res; |
|
|
58 | } |
|
|
59 | |
|
|
60 | static int decode_byte(int lev, psiconv_u32 off, |
|
|
61 | psiconv_paint_data_section data, int *pixelnr, |
|
|
62 | psiconv_u8 byte, int bits_per_pixel, int linelen, |
|
|
63 | int *linepos,int picsize) |
|
|
64 | { |
|
|
65 | int mask = (bits_per_pixel << 1) -1; |
|
|
66 | int i; |
|
|
67 | if (*linepos < (data->xsize + (8/bits_per_pixel) - 1) / (8/bits_per_pixel)) |
|
|
68 | for (i = 0; i < 8/bits_per_pixel; i ++) { |
|
|
69 | if ((i != 0) && ((*pixelnr % (data->xsize)) == 0)) { |
|
|
70 | psiconv_debug(lev+1,off,"Skipping padding: %02x",byte); |
|
|
71 | i = 8; |
|
|
72 | } else if (*pixelnr >= picsize) { |
|
|
73 | psiconv_warn(lev+1,off,"Corrupted picture data!"); |
|
|
74 | psiconv_debug(lev+1,off,"Trying to write a pixel too far"); |
|
|
75 | return -1; |
|
|
76 | } else { |
|
|
77 | data->red[*pixelnr] = data->green[*pixelnr] = data->blue[*pixelnr] = |
|
|
78 | ((float) (byte & mask)) / ((1 << bits_per_pixel) -1); |
|
|
79 | psiconv_debug(lev+1,off,"Pixel %04x: (%04x,%04x) value %02x, color %f", |
|
|
80 | *pixelnr,*pixelnr % data->xsize,*pixelnr / data->xsize, byte&mask, data->red[*pixelnr]); |
|
|
81 | byte = byte >> bits_per_pixel; |
|
|
82 | (*pixelnr) ++; |
|
|
83 | } |
|
|
84 | } |
|
|
85 | else |
|
|
86 | psiconv_debug(lev+1,off,"Skipping padding byte"); |
|
|
87 | (*linepos) ++; |
|
|
88 | if (*linepos == linelen) |
|
|
89 | *linepos = 0; |
|
|
90 | return 0; |
|
|
91 | } |
|
|
92 | |
25 | |
93 | |
26 | int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, |
94 | int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, |
27 | psiconv_u32 off, int *length, |
95 | psiconv_u32 off, int *length, |
28 | psiconv_paint_data_section *result) |
96 | psiconv_paint_data_section *result) |
29 | { |
97 | { |
30 | int res = 0; |
98 | int res = 0; |
31 | int len = 0; |
99 | int len = 0; |
|
|
100 | int read_err = 0; |
32 | psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr; |
101 | psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr,linelen; |
33 | psiconv_u8 marker; |
102 | psiconv_u8 marker; |
34 | int i; |
103 | int i,leng; |
|
|
104 | psiconv_u32 bits_per_pixel,compression; |
|
|
105 | int linepos = 0; |
35 | |
106 | |
36 | psiconv_progress(lev+1,off,"Going to read a paint data section"); |
107 | psiconv_progress(lev+1,off,"Going to read a paint data section"); |
37 | (*result) = malloc(sizeof(**result)); |
108 | (*result) = malloc(sizeof(**result)); |
38 | |
109 | |
39 | psiconv_progress(lev+2,off+len,"Going to read section size"); |
110 | psiconv_progress(lev+2,off+len,"Going to read section size"); |
… | |
… | |
41 | psiconv_debug(lev+2,off+len,"Section size: %08x",size); |
112 | psiconv_debug(lev+2,off+len,"Section size: %08x",size); |
42 | len += 4; |
113 | len += 4; |
43 | |
114 | |
44 | psiconv_progress(lev+2,off+len,"Going to read pixel data offset"); |
115 | psiconv_progress(lev+2,off+len,"Going to read pixel data offset"); |
45 | offset = psiconv_read_u32(buf,lev+2,off+len); |
116 | offset = psiconv_read_u32(buf,lev+2,off+len); |
46 | if (size != 0x28) { |
117 | if (offset != 0x28) { |
47 | psiconv_warn(lev+2,off+len, |
118 | psiconv_warn(lev+2,off+len, |
48 | "Paint data section data offset has unexpected value"); |
119 | "Paint data section data offset has unexpected value"); |
49 | psiconv_debug(lev+2,off+len, |
120 | psiconv_debug(lev+2,off+len, |
50 | "Data offset: read %08x, expected %08x",offset,0x28); |
121 | "Data offset: read %08x, expected %08x",offset,0x28); |
|
|
122 | res = -1; |
51 | } |
123 | } |
52 | len += 4; |
124 | len += 4; |
53 | |
125 | |
54 | psiconv_progress(lev+2,off+len,"Going to read picture X size"); |
126 | psiconv_progress(lev+2,off+len,"Going to read picture X size"); |
55 | (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len); |
127 | (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len); |
… | |
… | |
61 | psiconv_debug(lev+2,off+len,"Picture Y size: %08x:",(*result)->ysize); |
133 | psiconv_debug(lev+2,off+len,"Picture Y size: %08x:",(*result)->ysize); |
62 | len += 4; |
134 | len += 4; |
63 | |
135 | |
64 | picsize = (*result)->ysize * (*result)->xsize; |
136 | picsize = (*result)->ysize * (*result)->xsize; |
65 | |
137 | |
|
|
138 | psiconv_progress(lev+2,off+len,"Going to read the real picture x size"); |
|
|
139 | (*result)->pic_xsize = psiconv_read_length(buf,lev+2,off+len,&leng); |
|
|
140 | psiconv_debug(lev+2,off+len,"Picture x size: %f",(*result)->pic_xsize); |
|
|
141 | len += leng; |
|
|
142 | |
|
|
143 | psiconv_progress(lev+2,off+len,"Going to read the real picture y size"); |
|
|
144 | (*result)->pic_ysize = psiconv_read_length(buf,lev+2,off+len,&leng); |
|
|
145 | psiconv_debug(lev+2,off+len,"Picture y size: %f",(*result)->pic_ysize); |
|
|
146 | len += leng; |
|
|
147 | |
66 | psiconv_progress(lev+2,off+len,"Going to read 6 unused longs"); |
148 | psiconv_progress(lev+2,off+len,"Going to read the number of bits per pixel"); |
|
|
149 | bits_per_pixel=psiconv_read_u32(buf,lev+2,off+len); |
|
|
150 | if (bits_per_pixel > 8) { |
|
|
151 | psiconv_warn(lev+2,off+len,"Picture has too many colors"); |
|
|
152 | psiconv_debug(lev+2,off+len,"Read %d colorbits",bits_per_pixel); |
|
|
153 | res = -1; |
|
|
154 | bits_per_pixel = 2; |
|
|
155 | } |
|
|
156 | psiconv_debug(lev+2,off+len,"Bits per pixel: %d",bits_per_pixel); |
|
|
157 | len += 4; |
|
|
158 | |
67 | for (i = 0 ; i < 6; i++) { |
159 | for (i = 0 ; i < 2; i++) { |
68 | temp = psiconv_read_u32(buf,lev+2,off+len); |
160 | temp = psiconv_read_u32(buf,lev+2,off+len); |
69 | if (temp != 0x00) { |
161 | if (temp != 00) { |
70 | psiconv_warn(lev+2,off+len, |
162 | psiconv_warn(lev+2,off+len, |
71 | "Paint data section prologue has unknown values"); |
163 | "Paint data section prologue has unknown values"); |
72 | psiconv_debug(lev+2,off+len, |
164 | psiconv_debug(lev+2,off+len, |
73 | "offset %02x: read %08x, expected %08x",i,temp,0x00); |
165 | "offset %02x: read %08x, expected %08x",i,temp, 0x00); |
|
|
166 | res = -1; |
74 | } |
167 | } |
75 | len += 4; |
168 | len += 4; |
76 | } |
169 | } |
|
|
170 | |
|
|
171 | psiconv_progress(lev+2,off+len, |
|
|
172 | "Going to read whether RLE compression is used"); |
|
|
173 | compression=psiconv_read_u32(buf,lev+2,off+len); |
|
|
174 | if (compression > 1) { |
|
|
175 | psiconv_warn(lev+2,off+len,"Paint data section has unknown " |
|
|
176 | "compression type, assuming RLE"); |
|
|
177 | psiconv_debug(lev+2,off+len,"Read compression type %d",compression); |
|
|
178 | compression = 1; |
|
|
179 | } |
|
|
180 | psiconv_debug(lev+2,off+len,"Compression: %s",compression?"RLE":"none"); |
77 | |
181 | |
78 | (*result)->red = malloc(sizeof(float) * picsize); |
182 | (*result)->red = malloc(sizeof(float) * picsize); |
79 | (*result)->green = malloc(sizeof(float) * picsize); |
183 | (*result)->green = malloc(sizeof(float) * picsize); |
80 | (*result)->blue = malloc(sizeof(float) * picsize); |
184 | (*result)->blue = malloc(sizeof(float) * picsize); |
81 | len = offset; |
185 | len = offset; |
82 | datasize = size - len; |
186 | datasize = size - len; |
83 | |
187 | |
84 | psiconv_progress(lev+2,off+len,"Going to read the pixel data"); |
188 | psiconv_progress(lev+2,off+len,"Going to read the pixel data"); |
85 | pixelnr = 0; |
189 | pixelnr = 0; |
86 | datanr = 0; |
190 | datanr = 0; |
87 | while ((datanr < datasize) && (pixelnr < picsize)) { |
191 | if (!compression) { |
|
|
192 | linelen = datasize / (*result)->ysize; |
|
|
193 | psiconv_debug(lev+3,off+len,"Line length: %04x bytes",linelen); |
|
|
194 | while((datanr < datasize)) { |
|
|
195 | temp = psiconv_read_u8(buf,lev+2,off+len+datanr); |
|
|
196 | if (decode_byte(lev+3,off+len+datanr,*result,&pixelnr,temp,bits_per_pixel, |
|
|
197 | linelen,&linepos,picsize)) { |
|
|
198 | read_err = 1; |
|
|
199 | res = -1; |
|
|
200 | break; |
|
|
201 | } |
|
|
202 | datanr++; |
|
|
203 | } |
|
|
204 | } else { |
|
|
205 | psiconv_progress(lev+2,off+len,"First pass: determining line length"); |
|
|
206 | datanr = 0; |
|
|
207 | i = 0; |
|
|
208 | while (datanr < datasize) { |
88 | marker = psiconv_read_u8(buf,lev+3,off+len+datanr); |
209 | marker = psiconv_read_u8(buf,lev+3,off+len+datanr); |
|
|
210 | if (marker >= 0x80) { |
|
|
211 | datanr += 0x100 - marker + 1; |
|
|
212 | i += 0x100 - marker; |
|
|
213 | } else { |
|
|
214 | datanr += 2; |
|
|
215 | i += marker + 1; |
|
|
216 | } |
|
|
217 | } |
|
|
218 | linelen = i / (*result)->ysize; |
|
|
219 | datanr=0; |
|
|
220 | psiconv_debug(lev+2,off+len,"Linelen: %04x bytes",linelen); |
|
|
221 | while((datanr < datasize)) { |
|
|
222 | marker = psiconv_read_u8(buf,lev+3,off+len+datanr); |
|
|
223 | psiconv_debug(lev+3,off+len+datanr, |
|
|
224 | "Pixelnr %08x, Datanr %08x: Read marker %02x", |
|
|
225 | pixelnr,datanr,marker); |
|
|
226 | datanr ++; |
|
|
227 | if (marker >= 0x80) { |
|
|
228 | /* 0x100 - marker bytes of data follow */ |
|
|
229 | for (i = 0; i < 0x100-marker; i++,datanr++) { |
|
|
230 | if (datanr >= datasize) { |
|
|
231 | psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); |
|
|
232 | psiconv_debug(lev+3,off+len+datanr, |
|
|
233 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
|
|
234 | "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, |
|
|
235 | datanr,marker); |
|
|
236 | read_err = 1; |
|
|
237 | res = -1; |
|
|
238 | break; |
|
|
239 | } |
|
|
240 | temp = psiconv_read_u8(buf,lev+2,off+len+datanr); |
|
|
241 | if (decode_byte(lev+2,off+len+datanr,*result,&pixelnr,temp, |
|
|
242 | bits_per_pixel,linelen,&linepos,picsize)) { |
|
|
243 | res = -1; |
|
|
244 | read_err = 1; |
|
|
245 | break; |
|
|
246 | } |
|
|
247 | } |
|
|
248 | } else { |
|
|
249 | if (datanr >= datasize) { |
|
|
250 | psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); |
|
|
251 | psiconv_debug(lev+3,off+len+datanr, |
|
|
252 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
|
|
253 | "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, |
|
|
254 | datanr,marker); |
|
|
255 | read_err = 1; |
|
|
256 | res = -1; |
|
|
257 | } else { |
|
|
258 | temp = psiconv_read_u8(buf,lev+3,off+len+datanr); |
|
|
259 | for (i = 0; i <= marker; i++) { |
|
|
260 | if (decode_byte(lev+2,off+len+datanr,*result,&pixelnr,temp, |
|
|
261 | bits_per_pixel,linelen,&linepos,picsize)) { |
|
|
262 | read_err = 1; |
|
|
263 | res = -1; |
|
|
264 | break; |
|
|
265 | } |
|
|
266 | } |
|
|
267 | datanr ++; |
|
|
268 | } |
|
|
269 | } |
|
|
270 | } |
|
|
271 | } |
|
|
272 | |
|
|
273 | if (linepos >= ((*result)->xsize + (8/bits_per_pixel) - 1) / |
|
|
274 | (8/bits_per_pixel)) |
|
|
275 | datanr += (linelen - linepos); |
|
|
276 | |
|
|
277 | if (!read_err && ((datanr != datasize) || (pixelnr != picsize))) { |
|
|
278 | psiconv_warn(lev+2,off+len,"Corrupted picture data!"); |
89 | psiconv_debug(lev+3,off+len+datanr, |
279 | psiconv_debug(lev+3,off+len+datanr, |
90 | "Pixelnr %08x, Datanr %08x: Read marker %02x", |
|
|
91 | pixelnr,datanr,marker); |
|
|
92 | datanr ++; |
|
|
93 | if (marker >= 0x80) { |
|
|
94 | /* 0x100 - marker bytes of data follow */ |
|
|
95 | if ((0x100 - marker + datanr > datasize) || |
|
|
96 | ((0x100 - marker) * 4 + pixelnr > picsize)) { |
|
|
97 | psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); |
|
|
98 | psiconv_debug(lev+3,off+len+datanr, |
|
|
99 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
280 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
100 | "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, |
281 | "Datanr: %08x",picsize,datasize,pixelnr,datanr); |
101 | datanr,marker); |
282 | res = -1; |
102 | } else { |
|
|
103 | for (i = 0; i < 0x100-marker; i++) { |
|
|
104 | temp = psiconv_read_u8(buf,lev+3,off+len+datanr+i); |
|
|
105 | (*result)->red[pixelnr + i*4] = |
|
|
106 | (*result)->green[pixelnr + i*4] = |
|
|
107 | (*result)->blue[pixelnr + i*4] = |
|
|
108 | (temp & 0x03) * (1.0/3.0); |
|
|
109 | (*result)->red[pixelnr + i*4 + 1] = |
|
|
110 | (*result)->green[pixelnr + i*4 +1] = |
|
|
111 | (*result)->blue[pixelnr + i*4 + 1] = |
|
|
112 | ((temp >> 2) & 0x03) * (1.0/3.0); |
|
|
113 | (*result)->red[pixelnr + i*4 + 2] = |
|
|
114 | (*result)->green[pixelnr + i*4 +2] = |
|
|
115 | (*result)->blue[pixelnr + i*4 + 2] = |
|
|
116 | ((temp >> 4) & 0x03) * (1.0/3.0); |
|
|
117 | (*result)->red[pixelnr + i*4 + 3] = |
|
|
118 | (*result)->green[pixelnr + i*4 +3] = |
|
|
119 | (*result)->blue[pixelnr + i*4 + 3] = |
|
|
120 | ((temp >> 6) & 0x03) * (1.0/3.0); |
|
|
121 | } |
|
|
122 | } |
|
|
123 | pixelnr += (0x100 - marker) * 4; |
|
|
124 | datanr += (0x100 - marker); |
|
|
125 | } else { /* marker < 0x080 */ |
|
|
126 | if ((datanr + 1 > datasize) || |
|
|
127 | (marker * 4 + pixelnr > picsize)) { |
|
|
128 | psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); |
|
|
129 | psiconv_debug(lev+3,off+len+datanr, |
|
|
130 | "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," |
|
|
131 | "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, |
|
|
132 | datanr,marker); |
|
|
133 | } else { |
|
|
134 | temp = psiconv_read_u8(buf,lev+3,off+len+datanr); |
|
|
135 | for (i = 0; i < marker; i++) { |
|
|
136 | (*result)->red[pixelnr + i*4] = |
|
|
137 | (*result)->green[pixelnr + i*4] = |
|
|
138 | (*result)->blue[pixelnr + i*4] = |
|
|
139 | (temp & 0x03) * (1.0/3.0); |
|
|
140 | (*result)->red[pixelnr + i*4 + 1] = |
|
|
141 | (*result)->green[pixelnr + i*4 +1] = |
|
|
142 | (*result)->blue[pixelnr + i*4 + 1] = |
|
|
143 | ((temp >> 2) & 0x03) * (1.0/3.0); |
|
|
144 | (*result)->red[pixelnr + i*4 + 2] = |
|
|
145 | (*result)->green[pixelnr + i*4 +2] = |
|
|
146 | (*result)->blue[pixelnr + i*4 + 2] = |
|
|
147 | ((temp >> 4) & 0x03) * (1.0/3.0); |
|
|
148 | (*result)->red[pixelnr + i*4 + 3] = |
|
|
149 | (*result)->green[pixelnr + i*4 +3] = |
|
|
150 | (*result)->blue[pixelnr + i*4 + 3] = |
|
|
151 | ((temp >> 6) & 0x03) * (1.0/3.0); |
|
|
152 | } |
|
|
153 | } |
|
|
154 | pixelnr += marker * 4; |
|
|
155 | datanr += 1; |
|
|
156 | } |
283 | } |
157 | } |
284 | |
158 | len += datanr; |
285 | len += datanr; |
159 | |
286 | |
160 | if (length) |
287 | if (length) |
161 | *length = len; |
288 | *length = len; |
162 | |
289 | |
163 | psiconv_progress(lev+1,off+len-1,"End of paint data section " |
290 | psiconv_progress(lev+1,off+len-1,"End of paint data section " |
164 | "(total length: %08x", len); |
291 | "(total length: %08x)", len); |
165 | |
292 | |
166 | return res; |
293 | return res; |
167 | } |
294 | } |
168 | |
295 | |
|
|
296 | int psiconv_parse_sketch_section(const psiconv_buffer buf, int lev, |
|
|
297 | psiconv_u32 off, int *length, int is_object, |
|
|
298 | psiconv_sketch_section *result) |
|
|
299 | { |
|
|
300 | int res=0; |
|
|
301 | int len=0; |
|
|
302 | psiconv_u32 temp; |
|
|
303 | int leng; |
|
|
304 | int i; |
169 | |
305 | |
|
|
306 | psiconv_progress(lev+1,off,"Going to read the sketch section"); |
|
|
307 | *result = malloc(sizeof(**result)); |
|
|
308 | |
|
|
309 | if (!is_object) { |
|
|
310 | psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); |
|
|
311 | (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
312 | psiconv_debug(lev+2,off+len,"Form hor. size: %04x", |
|
|
313 | (*result)->form_xsize); |
|
|
314 | len += 0x02; |
|
|
315 | psiconv_progress(lev+2,off+len,"Going to read the form ver. size"); |
|
|
316 | (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
317 | psiconv_debug(lev+2,off+len,"Form ver. size: %04x", |
|
|
318 | (*result)->form_ysize); |
|
|
319 | len += 0x02; |
|
|
320 | psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset"); |
|
|
321 | (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len); |
|
|
322 | psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", |
|
|
323 | (*result)->picture_x_offset); |
|
|
324 | len += 0x02; |
|
|
325 | psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset"); |
|
|
326 | (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len); |
|
|
327 | psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", |
|
|
328 | (*result)->picture_y_offset); |
|
|
329 | len += 0x02; |
|
|
330 | psiconv_progress(lev+2,off+len,"Going to skip 5 words of zeros"); |
|
|
331 | for (i = 0; i < 5; i++) { |
|
|
332 | temp = psiconv_read_u16(buf,lev+2,off+len); |
|
|
333 | if (temp != 0) { |
|
|
334 | psiconv_warn(lev+2,off+len, |
|
|
335 | "Unexpected value in sketch section preamble"); |
|
|
336 | psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i, |
|
|
337 | temp,0); |
|
|
338 | res = -1; |
|
|
339 | } |
|
|
340 | off += 0x02; |
|
|
341 | } |
|
|
342 | } else { |
|
|
343 | psiconv_progress(lev+2,off+len,"Going to read the displayed hor. size"); |
|
|
344 | (*result)->picture_xsize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
345 | psiconv_debug(lev+2,off+len,"Displayed hor. size: %04x", |
|
|
346 | (*result)->picture_xsize); |
|
|
347 | len += 0x02; |
|
|
348 | psiconv_progress(lev+2,off+len,"Going to read the displayed ver. size"); |
|
|
349 | (*result)->picture_ysize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
350 | psiconv_debug(lev+2,off+len,"Displayed ver. size: %04x", |
|
|
351 | (*result)->picture_ysize); |
|
|
352 | len += 0x02; |
|
|
353 | |
|
|
354 | psiconv_progress(lev+2,off+len,"Going to skip 2 words of zeros"); |
|
|
355 | for (i = 0; i < 2; i++) { |
|
|
356 | temp = psiconv_read_u16(buf,lev+2,off+len); |
|
|
357 | if (temp != 0) { |
|
|
358 | psiconv_warn(lev+2,off+len, |
|
|
359 | "Unexpected value in sketch section preamble"); |
|
|
360 | psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i, |
|
|
361 | temp,0); |
|
|
362 | res = -1; |
|
|
363 | } |
|
|
364 | off += 0x02; |
|
|
365 | } |
|
|
366 | psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset"); |
|
|
367 | (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len); |
|
|
368 | psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", |
|
|
369 | (*result)->picture_x_offset); |
|
|
370 | len += 0x02; |
|
|
371 | psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset"); |
|
|
372 | (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len); |
|
|
373 | psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", |
|
|
374 | (*result)->picture_y_offset); |
|
|
375 | len += 0x02; |
|
|
376 | psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); |
|
|
377 | (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
378 | psiconv_debug(lev+2,off+len,"Form hor. size: %04x", |
|
|
379 | (*result)->form_xsize); |
|
|
380 | len += 0x02; |
|
|
381 | psiconv_progress(lev+2,off+len,"Going to read the form ver. size"); |
|
|
382 | (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
383 | psiconv_debug(lev+2,off+len,"Form ver. size: %04x", |
|
|
384 | (*result)->form_ysize); |
|
|
385 | len += 0x02; |
|
|
386 | psiconv_progress(lev+2,off+len,"Going to skip 1 zero word"); |
|
|
387 | temp = psiconv_read_u16(buf,lev+2,off+len); |
|
|
388 | if (temp != 0) { |
|
|
389 | psiconv_warn(lev+2,off+len, |
|
|
390 | "Unexpected value in sketch section preamble"); |
|
|
391 | psiconv_debug(lev+2,off+len,"Read %04x, expected %04x",i, temp,0); |
|
|
392 | res = -1; |
|
|
393 | } |
|
|
394 | off += 0x02; |
|
|
395 | } |
|
|
396 | |
|
|
397 | psiconv_progress(lev+2,off+len,"Going to read the picture data"); |
|
|
398 | res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng, |
|
|
399 | &((*result)->picture)); |
|
|
400 | off += leng; |
|
|
401 | if (!is_object) { |
|
|
402 | (*result)->picture_xsize = (*result)->picture->xsize; |
|
|
403 | (*result)->picture_ysize = (*result)->picture->ysize; |
|
|
404 | } |
|
|
405 | |
|
|
406 | psiconv_progress(lev+2,off+len,"Going to read the hor. magnification"); |
|
|
407 | (*result)->magnification_x = psiconv_read_u16(buf,lev+2,off + len) / 1000.0; |
|
|
408 | psiconv_debug(lev+2,off+len,"Form hor. magnification: %f", |
|
|
409 | (*result)->magnification_x); |
|
|
410 | len += 0x02; |
|
|
411 | psiconv_progress(lev+2,off+len,"Going to read the ver. magnification"); |
|
|
412 | (*result)->magnification_y = psiconv_read_u16(buf,lev+2,off + len) / 1000.0; |
|
|
413 | psiconv_debug(lev+2,off+len,"Form ver. magnification: %f", |
|
|
414 | (*result)->magnification_y); |
|
|
415 | len += 0x02; |
|
|
416 | |
|
|
417 | psiconv_progress(lev+2,off+len,"Going to read the left cut"); |
|
|
418 | temp = psiconv_read_u32(buf,lev+2,off + len); |
|
|
419 | (*result)->cut_left = (temp * 6.0) / (*result)->picture_xsize; |
|
|
420 | psiconv_debug(lev+2,off+len,"Left cut: raw %08x, real: %f", |
|
|
421 | temp,(*result)->cut_left); |
|
|
422 | len += 0x04; |
|
|
423 | psiconv_progress(lev+2,off+len,"Going to read the right cut"); |
|
|
424 | temp = psiconv_read_u32(buf,lev+2,off + len); |
|
|
425 | (*result)->cut_right = (temp * 6.0) / (*result)->picture_xsize; |
|
|
426 | psiconv_debug(lev+2,off+len,"Right cut: raw %08x, real: %f", |
|
|
427 | temp,(*result)->cut_right); |
|
|
428 | len += 0x04; |
|
|
429 | psiconv_progress(lev+2,off+len,"Going to read the top cut"); |
|
|
430 | temp = psiconv_read_u32(buf,lev+2,off + len); |
|
|
431 | (*result)->cut_top = (temp * 6.0) / (*result)->picture_ysize; |
|
|
432 | psiconv_debug(lev+2,off+len,"Top cut: raw %08x, real: %f", |
|
|
433 | temp,(*result)->cut_top); |
|
|
434 | len += 0x04; |
|
|
435 | psiconv_progress(lev+2,off+len,"Going to read the bottom cut"); |
|
|
436 | temp = psiconv_read_u32(buf,lev+2,off + len); |
|
|
437 | (*result)->cut_bottom = (temp * 6.0) / (*result)->picture_ysize; |
|
|
438 | psiconv_debug(lev+2,off+len,"Bottom cut: raw %08x, real: %f", |
|
|
439 | temp,(*result)->cut_bottom); |
|
|
440 | len += 0x04; |
|
|
441 | |
|
|
442 | if (length) |
|
|
443 | *length = len; |
|
|
444 | |
|
|
445 | psiconv_progress(lev,off+len-1, |
|
|
446 | "End of sketch section (total length: %08x)", len); |
|
|
447 | |
|
|
448 | return res; |
|
|
449 | } |
|
|
450 | |
|
|
451 | |
|
|
452 | int psiconv_parse_clipart_section(const psiconv_buffer buf,int lev, |
|
|
453 | psiconv_u32 off, int *length, |
|
|
454 | psiconv_clipart_section *result) |
|
|
455 | { |
|
|
456 | int res=0; |
|
|
457 | int len=0; |
|
|
458 | int leng; |
|
|
459 | psiconv_u32 temp; |
|
|
460 | |
|
|
461 | psiconv_progress(lev+1,off+len,"Going to read the clipart section"); |
|
|
462 | *result = malloc(sizeof(**result)); |
|
|
463 | |
|
|
464 | psiconv_progress(lev+2,off+len,"Going to read the section ID"); |
|
|
465 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
466 | if (temp != PSICONV_ID_CLIPART_ITEM) { |
|
|
467 | psiconv_warn(lev+2,off+len, |
|
|
468 | "Unexpected value in clipart section preamble"); |
|
|
469 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, |
|
|
470 | PSICONV_ID_CLIPART_ITEM); |
|
|
471 | res = -1; |
|
|
472 | } else |
|
|
473 | psiconv_debug(lev+2,off+len,"Clipart ID: %08x", temp); |
|
|
474 | off += 4; |
|
|
475 | |
|
|
476 | psiconv_progress(lev+2,off+len,"Going to read an unknown long"); |
|
|
477 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
478 | if (temp != 0x02) { |
|
|
479 | psiconv_warn(lev+2,off+len, |
|
|
480 | "Unexpected value in clipart section preamble"); |
|
|
481 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, |
|
|
482 | 0x02); |
|
|
483 | res = -1; |
|
|
484 | } else |
|
|
485 | psiconv_debug(lev+2,off+len,"First unknown long: %08x", temp); |
|
|
486 | off += 4; |
|
|
487 | |
|
|
488 | psiconv_progress(lev+2,off+len,"Going to read a second unknown long"); |
|
|
489 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
490 | if (temp != 0) { |
|
|
491 | psiconv_warn(lev+2,off+len, |
|
|
492 | "Unexpected value in clipart section preamble"); |
|
|
493 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, 0); |
|
|
494 | res = -1; |
|
|
495 | } else |
|
|
496 | psiconv_debug(lev+2,off+len,"Second unknown long: %08x", temp); |
|
|
497 | off += 4; |
|
|
498 | |
|
|
499 | psiconv_progress(lev+2,off+len,"Going to read a third unknown long"); |
|
|
500 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
501 | if (temp != 0) { |
|
|
502 | psiconv_warn(lev+2,off+len, |
|
|
503 | "Unexpected value in clipart section preamble"); |
|
|
504 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, 0); |
|
|
505 | res = -1; |
|
|
506 | } else |
|
|
507 | psiconv_debug(lev+2,off+len,"Third unknown long: %08x", temp); |
|
|
508 | off += 4; |
|
|
509 | |
|
|
510 | psiconv_progress(lev+2,off+len,"Going to read a fourth unknown long"); |
|
|
511 | temp = psiconv_read_u32(buf,lev+2,off+len); |
|
|
512 | if ((temp != 0x0c) && (temp != 0x08)) { |
|
|
513 | psiconv_warn(lev+2,off+len, |
|
|
514 | "Unexpected value in clipart section preamble"); |
|
|
515 | psiconv_debug(lev+2,off+len,"Read %08x, expected %08x or %08x",temp, |
|
|
516 | 0x0c, 0x08); |
|
|
517 | res = -1; |
|
|
518 | } else |
|
|
519 | psiconv_debug(lev+2,off+len,"Fourth unknown long: %08x", temp); |
|
|
520 | off += 4; |
|
|
521 | |
|
|
522 | psiconv_progress(lev+2,off+len,"Going to read the Paint Data Section"); |
|
|
523 | res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng, |
|
|
524 | &((*result)->picture)); |
|
|
525 | len += leng; |
|
|
526 | |
|
|
527 | if (length) |
|
|
528 | *length = len; |
|
|
529 | |
|
|
530 | psiconv_progress(lev,off+len-1, |
|
|
531 | "End of clipart section (total length: %08x)", len); |
|
|
532 | |
|
|
533 | return res; |
|
|
534 | } |