… | |
… | |
240 | |
240 | |
241 | return res; |
241 | return res; |
242 | } |
242 | } |
243 | |
243 | |
244 | |
244 | |
|
|
245 | |
|
|
246 | |
|
|
247 | int psiconv_parse_sketch_section(const psiconv_buffer buf, int lev, |
|
|
248 | psiconv_u32 off, int *length, int is_object, |
|
|
249 | psiconv_sketch_section *result) |
|
|
250 | { |
|
|
251 | int res=0; |
|
|
252 | int len=0; |
|
|
253 | psiconv_u32 temp; |
|
|
254 | int leng; |
|
|
255 | int i; |
|
|
256 | |
|
|
257 | psiconv_progress(lev+1,off,"Going to read the sketch section"); |
|
|
258 | *result = malloc(sizeof(**result)); |
|
|
259 | |
|
|
260 | if (!is_object) { |
|
|
261 | psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); |
|
|
262 | (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
263 | psiconv_debug(lev+2,off+len,"Form hor. size: %04x", |
|
|
264 | (*result)->form_xsize); |
|
|
265 | len += 0x02; |
|
|
266 | psiconv_progress(lev+2,off+len,"Going to read the form ver. size"); |
|
|
267 | (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
268 | psiconv_debug(lev+2,off+len,"Form ver. size: %04x", |
|
|
269 | (*result)->form_ysize); |
|
|
270 | len += 0x02; |
|
|
271 | psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset"); |
|
|
272 | (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len); |
|
|
273 | psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", |
|
|
274 | (*result)->picture_x_offset); |
|
|
275 | len += 0x02; |
|
|
276 | psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset"); |
|
|
277 | (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len); |
|
|
278 | psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", |
|
|
279 | (*result)->picture_y_offset); |
|
|
280 | len += 0x02; |
|
|
281 | psiconv_progress(lev+2,off+len,"Going to skip 5 words of zeros"); |
|
|
282 | for (i = 0; i < 5; i++) { |
|
|
283 | temp = psiconv_read_u16(buf,lev+2,off+len); |
|
|
284 | if (temp != 0) { |
|
|
285 | psiconv_warn(lev+2,off+len, |
|
|
286 | "Unexpected value in sketch section preamble"); |
|
|
287 | psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i, |
|
|
288 | temp,0); |
|
|
289 | res = -1; |
|
|
290 | } |
|
|
291 | off += 0x02; |
|
|
292 | } |
|
|
293 | } else { |
|
|
294 | psiconv_progress(lev+2,off+len,"Going to read the displayed hor. size"); |
|
|
295 | (*result)->picture_xsize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
296 | psiconv_debug(lev+2,off+len,"Displayed hor. size: %04x", |
|
|
297 | (*result)->picture_xsize); |
|
|
298 | len += 0x02; |
|
|
299 | psiconv_progress(lev+2,off+len,"Going to read the displayed ver. size"); |
|
|
300 | (*result)->picture_ysize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
301 | psiconv_debug(lev+2,off+len,"Displayed ver. size: %04x", |
|
|
302 | (*result)->picture_ysize); |
|
|
303 | len += 0x02; |
|
|
304 | |
|
|
305 | psiconv_progress(lev+2,off+len,"Going to skip 2 words of zeros"); |
|
|
306 | for (i = 0; i < 2; i++) { |
|
|
307 | temp = psiconv_read_u16(buf,lev+2,off+len); |
|
|
308 | if (temp != 0) { |
|
|
309 | psiconv_warn(lev+2,off+len, |
|
|
310 | "Unexpected value in sketch section preamble"); |
|
|
311 | psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i, |
|
|
312 | temp,0); |
|
|
313 | res = -1; |
|
|
314 | } |
|
|
315 | off += 0x02; |
|
|
316 | } |
|
|
317 | psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset"); |
|
|
318 | (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len); |
|
|
319 | psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x", |
|
|
320 | (*result)->picture_x_offset); |
|
|
321 | len += 0x02; |
|
|
322 | psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset"); |
|
|
323 | (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len); |
|
|
324 | psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x", |
|
|
325 | (*result)->picture_y_offset); |
|
|
326 | len += 0x02; |
|
|
327 | psiconv_progress(lev+2,off+len,"Going to read the form hor. size"); |
|
|
328 | (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
329 | psiconv_debug(lev+2,off+len,"Form hor. size: %04x", |
|
|
330 | (*result)->form_xsize); |
|
|
331 | len += 0x02; |
|
|
332 | psiconv_progress(lev+2,off+len,"Going to read the form ver. size"); |
|
|
333 | (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len); |
|
|
334 | psiconv_debug(lev+2,off+len,"Form ver. size: %04x", |
|
|
335 | (*result)->form_ysize); |
|
|
336 | len += 0x02; |
|
|
337 | psiconv_progress(lev+2,off+len,"Going to skip 1 zero word"); |
|
|
338 | temp = psiconv_read_u16(buf,lev+2,off+len); |
|
|
339 | if (temp != 0) { |
|
|
340 | psiconv_warn(lev+2,off+len, |
|
|
341 | "Unexpected value in sketch section preamble"); |
|
|
342 | psiconv_debug(lev+2,off+len,"Read %04x, expected %04x",i, temp,0); |
|
|
343 | res = -1; |
|
|
344 | } |
|
|
345 | off += 0x02; |
|
|
346 | } |
|
|
347 | |
|
|
348 | psiconv_progress(lev+2,off+len,"Going to read the picture data"); |
|
|
349 | res |= psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng, |
|
|
350 | &((*result)->picture)); |
|
|
351 | off += leng; |
|
|
352 | if (!is_object) { |
|
|
353 | (*result)->picture_xsize = (*result)->picture->xsize; |
|
|
354 | (*result)->picture_ysize = (*result)->picture->ysize; |
|
|
355 | } |
|
|
356 | |
|
|
357 | psiconv_progress(lev+2,off+len,"Going to read the hor. magnification"); |
|
|
358 | (*result)->magnification_x = psiconv_read_u16(buf,lev+2,off + len) / 1000.0; |
|
|
359 | psiconv_debug(lev+2,off+len,"Form hor. magnification: %f", |
|
|
360 | (*result)->magnification_x); |
|
|
361 | len += 0x02; |
|
|
362 | psiconv_progress(lev+2,off+len,"Going to read the ver. magnification"); |
|
|
363 | (*result)->magnification_y = psiconv_read_u16(buf,lev+2,off + len) / 1000.0; |
|
|
364 | psiconv_debug(lev+2,off+len,"Form ver. magnification: %f", |
|
|
365 | (*result)->magnification_y); |
|
|
366 | len += 0x02; |
|
|
367 | |
|
|
368 | psiconv_progress(lev+2,off+len,"Going to read the left cut"); |
|
|
369 | temp = psiconv_read_u32(buf,lev+2,off + len); |
|
|
370 | (*result)->cut_left = (temp * 6.0) / (*result)->picture_xsize; |
|
|
371 | psiconv_debug(lev+2,off+len,"Left cut: raw %08x, real: %f", |
|
|
372 | temp,(*result)->cut_left); |
|
|
373 | len += 0x04; |
|
|
374 | psiconv_progress(lev+2,off+len,"Going to read the right cut"); |
|
|
375 | temp = psiconv_read_u32(buf,lev+2,off + len); |
|
|
376 | (*result)->cut_right = (temp * 6.0) / (*result)->picture_xsize; |
|
|
377 | psiconv_debug(lev+2,off+len,"Right cut: raw %08x, real: %f", |
|
|
378 | temp,(*result)->cut_right); |
|
|
379 | len += 0x04; |
|
|
380 | psiconv_progress(lev+2,off+len,"Going to read the top cut"); |
|
|
381 | temp = psiconv_read_u32(buf,lev+2,off + len); |
|
|
382 | (*result)->cut_top = (temp * 6.0) / (*result)->picture_ysize; |
|
|
383 | psiconv_debug(lev+2,off+len,"Top cut: raw %08x, real: %f", |
|
|
384 | temp,(*result)->cut_top); |
|
|
385 | len += 0x04; |
|
|
386 | psiconv_progress(lev+2,off+len,"Going to read the bottom cut"); |
|
|
387 | temp = psiconv_read_u32(buf,lev+2,off + len); |
|
|
388 | (*result)->cut_bottom = (temp * 6.0) / (*result)->picture_ysize; |
|
|
389 | psiconv_debug(lev+2,off+len,"Bottom cut: raw %08x, real: %f", |
|
|
390 | temp,(*result)->cut_bottom); |
|
|
391 | len += 0x04; |
|
|
392 | |
|
|
393 | if (length) |
|
|
394 | *length = len; |
|
|
395 | |
|
|
396 | psiconv_progress(lev,off+len-1, |
|
|
397 | "End of sketch section (total length: %08x)", len); |
|
|
398 | |
|
|
399 | return res; |
|
|
400 | } |
|
|
401 | |