/[public]/psiconv/trunk/lib/psiconv/parse_image.c
ViewVC logotype

Annotation of /psiconv/trunk/lib/psiconv/parse_image.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (hide annotations)
Mon Jan 22 20:36:50 2001 UTC (23 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 23351 byte(s)
(Frodo) Another small Sheet improvement: sheet formula list

1 frodo 10 /*
2     parse_image.c - Part of psiconv, a PSION 5 file formats converter
3 frodo 63 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
4 frodo 10
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9    
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     GNU General Public License for more details.
14    
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18     */
19    
20     #include "config.h"
21 frodo 71 #include "compat.h"
22    
23 frodo 10 #include <stdlib.h>
24    
25     #include "parse_routines.h"
26 frodo 71 #include "error.h"
27 frodo 10
28 frodo 42 int psiconv_parse_jumptable_section(const psiconv_buffer buf,int lev,
29     psiconv_u32 off, int *length,
30     psiconv_jumptable_section *result)
31 frodo 12 {
32     int res = 0;
33     int len = 0;
34     psiconv_u32 listlen,temp;
35     int i;
36    
37 frodo 42 psiconv_progress(lev+1,off+len,"Going to read the jumptable section");
38 frodo 64 if (!((*result) = psiconv_list_new(sizeof(psiconv_u32))))
39     goto ERROR1;
40 frodo 12
41     psiconv_progress(lev+2,off+len,"Going to read the list length");
42 frodo 64 listlen = psiconv_read_u32(buf,lev+2,off+len,&res);
43 frodo 65 if (res)
44 frodo 64 goto ERROR2;
45 frodo 12 psiconv_debug(lev+2,off+len,"List length: %08x",listlen);
46     len += 4;
47    
48     psiconv_progress(lev+2,off+len,"Going to read the list");
49     for (i = 0; i < listlen; i++) {
50 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
51 frodo 65 if (res)
52 frodo 64 goto ERROR2;
53     if ((res = psiconv_list_add(*result,&temp)))
54     goto ERROR2;
55 frodo 12 psiconv_debug(lev+3,off+len,"Offset: %08x",temp);
56     len += 4;
57     }
58    
59     if (length)
60     *length = len;
61    
62 frodo 42 psiconv_progress(lev+1,off+len-1,"End of jumptable section "
63 frodo 13 "(total length: %08x)", len);
64 frodo 12
65 frodo 64 return 0;
66    
67     ERROR2:
68     psiconv_list_free(*result);
69     ERROR1:
70     psiconv_warn(lev+1,off,"Reading of Jumptable Section failed");
71     if (length)
72     *length = 0;
73     if (!res)
74     return -PSICONV_E_NOMEM;
75     else
76     return res;
77 frodo 12 }
78    
79 frodo 25 static int decode_byte(int lev, psiconv_u32 off,
80 frodo 97 psiconv_paint_data_section data, psiconv_u32 *pixelnr,
81 frodo 25 psiconv_u8 byte, int bits_per_pixel, int linelen,
82     int *linepos,int picsize)
83     {
84     int mask = (bits_per_pixel << 1) -1;
85     int i;
86     if (*linepos < (data->xsize + (8/bits_per_pixel) - 1) / (8/bits_per_pixel))
87     for (i = 0; i < 8/bits_per_pixel; i ++) {
88     if ((i != 0) && ((*pixelnr % (data->xsize)) == 0)) {
89     psiconv_debug(lev+1,off,"Skipping padding: %02x",byte);
90     i = 8;
91     } else if (*pixelnr >= picsize) {
92     psiconv_warn(lev+1,off,"Corrupted picture data!");
93     psiconv_debug(lev+1,off,"Trying to write a pixel too far");
94     return -1;
95     } else {
96     data->red[*pixelnr] = data->green[*pixelnr] = data->blue[*pixelnr] =
97     ((float) (byte & mask)) / ((1 << bits_per_pixel) -1);
98     psiconv_debug(lev+1,off,"Pixel %04x: (%04x,%04x) value %02x, color %f",
99 frodo 64 *pixelnr,*pixelnr % data->xsize,
100     *pixelnr / data->xsize, byte&mask, data->red[*pixelnr]);
101 frodo 25 byte = byte >> bits_per_pixel;
102     (*pixelnr) ++;
103     }
104     }
105     else
106     psiconv_debug(lev+1,off,"Skipping padding byte");
107     (*linepos) ++;
108     if (*linepos == linelen)
109     *linepos = 0;
110     return 0;
111     }
112    
113    
114 frodo 10 int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev,
115 frodo 45 psiconv_u32 off, int *length,int isclipart,
116 frodo 10 psiconv_paint_data_section *result)
117     {
118     int res = 0;
119     int len = 0;
120 frodo 13 psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr,linelen;
121 frodo 11 psiconv_u8 marker;
122 frodo 25 int i,leng;
123     psiconv_u32 bits_per_pixel,compression;
124     int linepos = 0;
125 frodo 10
126     psiconv_progress(lev+1,off,"Going to read a paint data section");
127 frodo 64 if (!((*result) = malloc(sizeof(**result))))
128     goto ERROR1;
129 frodo 10
130     psiconv_progress(lev+2,off+len,"Going to read section size");
131 frodo 64 size = psiconv_read_u32(buf,lev+2,off+len,&res);
132     if (res)
133     goto ERROR2;
134 frodo 10 psiconv_debug(lev+2,off+len,"Section size: %08x",size);
135     len += 4;
136    
137     psiconv_progress(lev+2,off+len,"Going to read pixel data offset");
138 frodo 64 offset = psiconv_read_u32(buf,lev+2,off+len,&res);
139     if (res)
140     goto ERROR2;
141 frodo 13 if (offset != 0x28) {
142 frodo 10 psiconv_warn(lev+2,off+len,
143     "Paint data section data offset has unexpected value");
144     psiconv_debug(lev+2,off+len,
145     "Data offset: read %08x, expected %08x",offset,0x28);
146 frodo 12 res = -1;
147 frodo 10 }
148     len += 4;
149    
150     psiconv_progress(lev+2,off+len,"Going to read picture X size");
151 frodo 64 (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len,&res);
152     if (res)
153     goto ERROR2;
154 frodo 10 psiconv_debug(lev+2,off+len,"Picture X size: %08x:",(*result)->xsize);
155     len += 4;
156    
157     psiconv_progress(lev+2,off+len,"Going to read picture Y size");
158 frodo 64 (*result)->ysize = psiconv_read_u32(buf,lev+2,off+len,&res);
159     if (res)
160     goto ERROR2;
161 frodo 10 psiconv_debug(lev+2,off+len,"Picture Y size: %08x:",(*result)->ysize);
162     len += 4;
163    
164 frodo 25 picsize = (*result)->ysize * (*result)->xsize;
165 frodo 10
166 frodo 25 psiconv_progress(lev+2,off+len,"Going to read the real picture x size");
167 frodo 64 (*result)->pic_xsize = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
168     if (res)
169     goto ERROR2;
170 frodo 25 psiconv_debug(lev+2,off+len,"Picture x size: %f",(*result)->pic_xsize);
171     len += leng;
172    
173     psiconv_progress(lev+2,off+len,"Going to read the real picture y size");
174 frodo 64 (*result)->pic_ysize = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
175     if (res)
176     goto ERROR2;
177 frodo 25 psiconv_debug(lev+2,off+len,"Picture y size: %f",(*result)->pic_ysize);
178     len += leng;
179    
180     psiconv_progress(lev+2,off+len,"Going to read the number of bits per pixel");
181 frodo 64 bits_per_pixel=psiconv_read_u32(buf,lev+2,off+len,&res);
182     if (res)
183     goto ERROR2;
184 frodo 25 if (bits_per_pixel > 8) {
185     psiconv_warn(lev+2,off+len,"Picture has too many colors");
186     psiconv_debug(lev+2,off+len,"Read %d colorbits",bits_per_pixel);
187 frodo 64 res = -PSICONV_E_PARSE;
188     goto ERROR2;
189 frodo 25 }
190     psiconv_debug(lev+2,off+len,"Bits per pixel: %d",bits_per_pixel);
191     len += 4;
192    
193     for (i = 0 ; i < 2; i++) {
194 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
195     if (res)
196     goto ERROR2;
197 frodo 25 if (temp != 00) {
198 frodo 10 psiconv_warn(lev+2,off+len,
199 frodo 64 "Paint data section prologue has unknown values (ignored)");
200 frodo 10 psiconv_debug(lev+2,off+len,
201 frodo 25 "offset %02x: read %08x, expected %08x",i,temp, 0x00);
202 frodo 10 }
203     len += 4;
204     }
205 frodo 25
206     psiconv_progress(lev+2,off+len,
207     "Going to read whether RLE compression is used");
208 frodo 64 compression=psiconv_read_u32(buf,lev+2,off+len,&res);
209     if (res)
210     goto ERROR2;
211 frodo 25 if (compression > 1) {
212     psiconv_warn(lev+2,off+len,"Paint data section has unknown "
213     "compression type, assuming RLE");
214     psiconv_debug(lev+2,off+len,"Read compression type %d",compression);
215     compression = 1;
216     }
217     psiconv_debug(lev+2,off+len,"Compression: %s",compression?"RLE":"none");
218 frodo 45 len += 4;
219 frodo 10
220 frodo 45 if (isclipart) {
221     psiconv_progress(lev+2,off+len,"Going to read an unknown long");
222 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
223     if (res)
224     goto ERROR2;
225 frodo 45 if (temp != 0xffffffff) {
226     psiconv_warn(lev+2,off+len,
227 frodo 64 "Paint data section prologue has unknown values (ignoring)");
228 frodo 45 psiconv_debug(lev+2,off+len,
229     "offset %02x: read %08x, expected %08x",i,temp, 0xffffffff);
230     }
231     len += 4;
232     psiconv_progress(lev+2,off+len,"Going to read a second unknown long");
233 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
234     if (res)
235     goto ERROR2;
236 frodo 45 if (temp != 0x44) {
237     psiconv_warn(lev+2,off+len,
238 frodo 64 "Paint data section prologue has unknown values (ignoring)");
239 frodo 45 psiconv_debug(lev+2,off+len,
240     "offset %02x: read %08x, expected %08x",i,temp, 0x44);
241     }
242     len += 4;
243     }
244    
245 frodo 64 if (!((*result)->red = malloc(sizeof(float) * picsize)))
246     goto ERROR2;
247     if (!((*result)->green = malloc(sizeof(float) * picsize)))
248     goto ERROR3;
249     if (!((*result)->blue = malloc(sizeof(float) * picsize)))
250     goto ERROR4;
251 frodo 10 len = offset;
252     datasize = size - len;
253 frodo 45 if (isclipart)
254     len += 8;
255 frodo 10
256 frodo 11 psiconv_progress(lev+2,off+len,"Going to read the pixel data");
257 frodo 10 pixelnr = 0;
258     datanr = 0;
259 frodo 25 if (!compression) {
260     linelen = datasize / (*result)->ysize;
261     psiconv_debug(lev+3,off+len,"Line length: %04x bytes",linelen);
262     while((datanr < datasize)) {
263 frodo 64 temp = psiconv_read_u8(buf,lev+2,off+len+datanr,&res);
264     if (res)
265     goto ERROR5;
266 frodo 25 if (decode_byte(lev+3,off+len+datanr,*result,&pixelnr,temp,bits_per_pixel,
267     linelen,&linepos,picsize)) {
268 frodo 64 res = -PSICONV_E_PARSE;
269 frodo 25 break;
270     }
271     datanr++;
272     }
273     } else {
274     psiconv_progress(lev+2,off+len,"First pass: determining line length");
275     datanr = 0;
276     i = 0;
277     while (datanr < datasize) {
278 frodo 64 marker = psiconv_read_u8(buf,lev+3,off+len+datanr,&res);
279     if (res)
280     goto ERROR5;
281 frodo 25 if (marker >= 0x80) {
282     datanr += 0x100 - marker + 1;
283     i += 0x100 - marker;
284 frodo 10 } else {
285 frodo 25 datanr += 2;
286     i += marker + 1;
287     }
288     }
289     linelen = i / (*result)->ysize;
290     datanr=0;
291     psiconv_debug(lev+2,off+len,"Linelen: %04x bytes",linelen);
292     while((datanr < datasize)) {
293 frodo 64 marker = psiconv_read_u8(buf,lev+3,off+len+datanr,&res);
294     if (res)
295     goto ERROR5;
296 frodo 25 psiconv_debug(lev+3,off+len+datanr,
297     "Pixelnr %08x, Datanr %08x: Read marker %02x",
298     pixelnr,datanr,marker);
299     datanr ++;
300     if (marker >= 0x80) {
301     /* 0x100 - marker bytes of data follow */
302     for (i = 0; i < 0x100-marker; i++,datanr++) {
303     if (datanr >= datasize) {
304 frodo 15 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data");
305     psiconv_debug(lev+3,off+len+datanr,
306     "Picsize: %08x, Datasize: %08x, Pixelnr: %08x,"
307     "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr,
308     datanr,marker);
309 frodo 64 res = -PSICONV_E_PARSE;
310 frodo 25 break;
311     }
312 frodo 64 temp = psiconv_read_u8(buf,lev+2,off+len+datanr,&res);
313     if (res)
314     goto ERROR5;
315 frodo 25 if (decode_byte(lev+2,off+len+datanr,*result,&pixelnr,temp,
316     bits_per_pixel,linelen,&linepos,picsize)) {
317 frodo 64 res = -PSICONV_E_PARSE;
318 frodo 25 break;
319 frodo 15 }
320 frodo 25 }
321     } else {
322     if (datanr >= datasize) {
323     psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data");
324     psiconv_debug(lev+3,off+len+datanr,
325     "Picsize: %08x, Datasize: %08x, Pixelnr: %08x,"
326     "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr,
327     datanr,marker);
328 frodo 64 res = -PSICONV_E_PARSE;
329 frodo 25 } else {
330 frodo 64 temp = psiconv_read_u8(buf,lev+3,off+len+datanr,&res);
331     if (res)
332     goto ERROR5;
333 frodo 25 for (i = 0; i <= marker; i++) {
334     if (decode_byte(lev+2,off+len+datanr,*result,&pixelnr,temp,
335     bits_per_pixel,linelen,&linepos,picsize)) {
336 frodo 64 res = -PSICONV_E_PARSE;
337 frodo 25 break;
338     }
339     }
340     datanr ++;
341     }
342 frodo 10 }
343     }
344     }
345 frodo 25
346     if (linepos >= ((*result)->xsize + (8/bits_per_pixel) - 1) /
347     (8/bits_per_pixel))
348     datanr += (linelen - linepos);
349    
350 frodo 64 if (res || (datanr != datasize) || (pixelnr != picsize)) {
351 frodo 12 psiconv_warn(lev+2,off+len,"Corrupted picture data!");
352     psiconv_debug(lev+3,off+len+datanr,
353     "Picsize: %08x, Datasize: %08x, Pixelnr: %08x,"
354     "Datanr: %08x",picsize,datasize,pixelnr,datanr);
355 frodo 64 goto ERROR5;
356 frodo 12 }
357    
358 frodo 10 len += datanr;
359    
360     if (length)
361     *length = len;
362    
363     psiconv_progress(lev+1,off+len-1,"End of paint data section "
364 frodo 13 "(total length: %08x)", len);
365 frodo 10
366     return res;
367 frodo 64
368     ERROR5:
369     free((*result)->blue);
370     ERROR4:
371     free((*result)->green);
372     ERROR3:
373     free((*result)->red);
374     ERROR2:
375     free (*result);
376     ERROR1:
377     psiconv_warn(lev+1,off,"Reading of Paint Data Section failed");
378     if (length)
379     *length = 0;
380     if (!res)
381     return -PSICONV_E_NOMEM;
382     else
383     return res;
384 frodo 10 }
385    
386 frodo 24 int psiconv_parse_sketch_section(const psiconv_buffer buf, int lev,
387     psiconv_u32 off, int *length, int is_object,
388     psiconv_sketch_section *result)
389     {
390     int res=0;
391     int len=0;
392     psiconv_u32 temp;
393     int leng;
394     int i;
395    
396     psiconv_progress(lev+1,off,"Going to read the sketch section");
397 frodo 64 if (!(*result = malloc(sizeof(**result))))
398     goto ERROR1;
399 frodo 24
400     if (!is_object) {
401     psiconv_progress(lev+2,off+len,"Going to read the form hor. size");
402 frodo 64 (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len,&res);
403     if (res)
404     goto ERROR2;
405 frodo 24 psiconv_debug(lev+2,off+len,"Form hor. size: %04x",
406     (*result)->form_xsize);
407     len += 0x02;
408     psiconv_progress(lev+2,off+len,"Going to read the form ver. size");
409 frodo 64 (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len,&res);
410     if (res)
411     goto ERROR2;
412 frodo 24 psiconv_debug(lev+2,off+len,"Form ver. size: %04x",
413     (*result)->form_ysize);
414     len += 0x02;
415     psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset");
416 frodo 64 (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len,&res);
417     if (res)
418     goto ERROR2;
419 frodo 24 psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x",
420     (*result)->picture_x_offset);
421     len += 0x02;
422     psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset");
423 frodo 64 (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len,&res);
424     if (res)
425     goto ERROR2;
426 frodo 24 psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x",
427     (*result)->picture_y_offset);
428     len += 0x02;
429     psiconv_progress(lev+2,off+len,"Going to skip 5 words of zeros");
430     for (i = 0; i < 5; i++) {
431 frodo 64 temp = psiconv_read_u16(buf,lev+2,off+len,&res);
432     if (res)
433     goto ERROR2;
434 frodo 24 if (temp != 0) {
435     psiconv_warn(lev+2,off+len,
436 frodo 64 "Unexpected value in sketch section preamble (ignored)");
437 frodo 24 psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i,
438     temp,0);
439     }
440     off += 0x02;
441     }
442     } else {
443     psiconv_progress(lev+2,off+len,"Going to read the displayed hor. size");
444 frodo 64 (*result)->picture_xsize = psiconv_read_u16(buf,lev+2,off + len,&res);
445     if (res)
446     goto ERROR2;
447 frodo 24 psiconv_debug(lev+2,off+len,"Displayed hor. size: %04x",
448     (*result)->picture_xsize);
449     len += 0x02;
450     psiconv_progress(lev+2,off+len,"Going to read the displayed ver. size");
451 frodo 64 (*result)->picture_ysize = psiconv_read_u16(buf,lev+2,off + len,&res);
452     if (res)
453     goto ERROR2;
454 frodo 24 psiconv_debug(lev+2,off+len,"Displayed ver. size: %04x",
455     (*result)->picture_ysize);
456     len += 0x02;
457    
458     psiconv_progress(lev+2,off+len,"Going to skip 2 words of zeros");
459     for (i = 0; i < 2; i++) {
460 frodo 64 temp = psiconv_read_u16(buf,lev+2,off+len,&res);
461     if (res)
462     goto ERROR2;
463 frodo 24 if (temp != 0) {
464     psiconv_warn(lev+2,off+len,
465 frodo 64 "Unexpected value in sketch section preamble (ignored)");
466 frodo 24 psiconv_debug(lev+2,off+len,"Word %d: Read %04x, expected %04x",i,
467     temp,0);
468     }
469     off += 0x02;
470     }
471     psiconv_progress(lev+2,off+len,"Going to read the picture hor. offset");
472 frodo 64 (*result)->picture_x_offset = psiconv_read_u16(buf,lev+2,off + len,&res);
473     if (res)
474     goto ERROR2;
475 frodo 24 psiconv_debug(lev+2,off+len,"Picture hor. offset: %04x",
476     (*result)->picture_x_offset);
477     len += 0x02;
478     psiconv_progress(lev+2,off+len,"Going to read the picture ver. offset");
479 frodo 64 (*result)->picture_y_offset = psiconv_read_u16(buf,lev+2,off + len,&res);
480     if (res)
481     goto ERROR2;
482 frodo 24 psiconv_debug(lev+2,off+len,"Picture ver. offset: %04x",
483     (*result)->picture_y_offset);
484     len += 0x02;
485     psiconv_progress(lev+2,off+len,"Going to read the form hor. size");
486 frodo 64 (*result)->form_xsize = psiconv_read_u16(buf,lev+2,off + len,&res);
487     if (res)
488     goto ERROR2;
489 frodo 24 psiconv_debug(lev+2,off+len,"Form hor. size: %04x",
490     (*result)->form_xsize);
491     len += 0x02;
492     psiconv_progress(lev+2,off+len,"Going to read the form ver. size");
493 frodo 64 (*result)->form_ysize = psiconv_read_u16(buf,lev+2,off + len,&res);
494     if (res)
495     goto ERROR2;
496 frodo 24 psiconv_debug(lev+2,off+len,"Form ver. size: %04x",
497     (*result)->form_ysize);
498     len += 0x02;
499     psiconv_progress(lev+2,off+len,"Going to skip 1 zero word");
500 frodo 64 temp = psiconv_read_u16(buf,lev+2,off+len,&res);
501     if (res)
502     goto ERROR2;
503 frodo 24 if (temp != 0) {
504     psiconv_warn(lev+2,off+len,
505 frodo 64 "Unexpected value in sketch section preamble (ignored)");
506 frodo 24 psiconv_debug(lev+2,off+len,"Read %04x, expected %04x",i, temp,0);
507     }
508     off += 0x02;
509     }
510    
511     psiconv_progress(lev+2,off+len,"Going to read the picture data");
512 frodo 64 if ((res = psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng,0,
513     &((*result)->picture))))
514     goto ERROR2;
515 frodo 24 off += leng;
516     if (!is_object) {
517     (*result)->picture_xsize = (*result)->picture->xsize;
518     (*result)->picture_ysize = (*result)->picture->ysize;
519     }
520    
521     psiconv_progress(lev+2,off+len,"Going to read the hor. magnification");
522 frodo 64 (*result)->magnification_x = psiconv_read_u16(buf,lev+2,off+len,&res)/1000.0;
523     if (res)
524     goto ERROR3;
525 frodo 24 psiconv_debug(lev+2,off+len,"Form hor. magnification: %f",
526     (*result)->magnification_x);
527     len += 0x02;
528     psiconv_progress(lev+2,off+len,"Going to read the ver. magnification");
529 frodo 64 (*result)->magnification_y = psiconv_read_u16(buf,lev+2,off+len,&res)/1000.0;
530     if (res)
531     goto ERROR3;
532 frodo 24 psiconv_debug(lev+2,off+len,"Form ver. magnification: %f",
533     (*result)->magnification_y);
534     len += 0x02;
535    
536     psiconv_progress(lev+2,off+len,"Going to read the left cut");
537 frodo 64 temp = psiconv_read_u32(buf,lev+2,off + len,&res);
538     if (res)
539     goto ERROR3;
540 frodo 24 (*result)->cut_left = (temp * 6.0) / (*result)->picture_xsize;
541     psiconv_debug(lev+2,off+len,"Left cut: raw %08x, real: %f",
542     temp,(*result)->cut_left);
543     len += 0x04;
544     psiconv_progress(lev+2,off+len,"Going to read the right cut");
545 frodo 64 temp = psiconv_read_u32(buf,lev+2,off + len,&res);
546     if (res)
547     goto ERROR3;
548 frodo 24 (*result)->cut_right = (temp * 6.0) / (*result)->picture_xsize;
549     psiconv_debug(lev+2,off+len,"Right cut: raw %08x, real: %f",
550     temp,(*result)->cut_right);
551     len += 0x04;
552     psiconv_progress(lev+2,off+len,"Going to read the top cut");
553 frodo 64 temp = psiconv_read_u32(buf,lev+2,off + len,&res);
554     if (res)
555     goto ERROR3;
556 frodo 24 (*result)->cut_top = (temp * 6.0) / (*result)->picture_ysize;
557     psiconv_debug(lev+2,off+len,"Top cut: raw %08x, real: %f",
558     temp,(*result)->cut_top);
559     len += 0x04;
560     psiconv_progress(lev+2,off+len,"Going to read the bottom cut");
561 frodo 64 temp = psiconv_read_u32(buf,lev+2,off + len,&res);
562     if (res)
563     goto ERROR3;
564 frodo 24 (*result)->cut_bottom = (temp * 6.0) / (*result)->picture_ysize;
565     psiconv_debug(lev+2,off+len,"Bottom cut: raw %08x, real: %f",
566     temp,(*result)->cut_bottom);
567     len += 0x04;
568    
569     if (length)
570     *length = len;
571    
572     psiconv_progress(lev,off+len-1,
573     "End of sketch section (total length: %08x)", len);
574    
575     return res;
576 frodo 64 ERROR3:
577     psiconv_free_paint_data_section((*result)->picture);
578     ERROR2:
579     free (*result);
580     ERROR1:
581     psiconv_warn(lev+1,off,"Reading of Sketch Section failed");
582     if (length)
583     *length = 0;
584     if (!res)
585     return -PSICONV_E_NOMEM;
586     else
587     return res;
588 frodo 24 }
589    
590 frodo 43
591     int psiconv_parse_clipart_section(const psiconv_buffer buf,int lev,
592     psiconv_u32 off, int *length,
593     psiconv_clipart_section *result)
594     {
595     int res=0;
596     int len=0;
597     int leng;
598     psiconv_u32 temp;
599    
600     psiconv_progress(lev+1,off+len,"Going to read the clipart section");
601 frodo 64 if (!(*result = malloc(sizeof(**result))))
602     goto ERROR1;
603 frodo 43
604     psiconv_progress(lev+2,off+len,"Going to read the section ID");
605 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
606     if (res)
607     goto ERROR2;
608 frodo 43 if (temp != PSICONV_ID_CLIPART_ITEM) {
609     psiconv_warn(lev+2,off+len,
610 frodo 64 "Unexpected value in clipart section preamble (ignored)");
611 frodo 43 psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp,
612     PSICONV_ID_CLIPART_ITEM);
613     } else
614     psiconv_debug(lev+2,off+len,"Clipart ID: %08x", temp);
615     off += 4;
616    
617     psiconv_progress(lev+2,off+len,"Going to read an unknown long");
618 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
619     if (res)
620     goto ERROR2;
621 frodo 43 if (temp != 0x02) {
622     psiconv_warn(lev+2,off+len,
623 frodo 64 "Unexpected value in clipart section preamble (ignored)");
624 frodo 43 psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp,
625     0x02);
626     } else
627     psiconv_debug(lev+2,off+len,"First unknown long: %08x", temp);
628     off += 4;
629    
630     psiconv_progress(lev+2,off+len,"Going to read a second unknown long");
631 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
632     if (res)
633     goto ERROR2;
634 frodo 43 if (temp != 0) {
635     psiconv_warn(lev+2,off+len,
636 frodo 64 "Unexpected value in clipart section preamble (ignored)");
637 frodo 43 psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, 0);
638     } else
639     psiconv_debug(lev+2,off+len,"Second unknown long: %08x", temp);
640     off += 4;
641    
642     psiconv_progress(lev+2,off+len,"Going to read a third unknown long");
643 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
644     if (res)
645     goto ERROR2;
646 frodo 43 if (temp != 0) {
647     psiconv_warn(lev+2,off+len,
648 frodo 64 "Unexpected value in clipart section preamble (ignored)");
649 frodo 43 psiconv_debug(lev+2,off+len,"Read %08x, expected %08x",temp, 0);
650     } else
651     psiconv_debug(lev+2,off+len,"Third unknown long: %08x", temp);
652     off += 4;
653    
654     psiconv_progress(lev+2,off+len,"Going to read a fourth unknown long");
655 frodo 64 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
656     if (res)
657     goto ERROR2;
658 frodo 43 if ((temp != 0x0c) && (temp != 0x08)) {
659     psiconv_warn(lev+2,off+len,
660 frodo 64 "Unexpected value in clipart section preamble (ignored)");
661 frodo 43 psiconv_debug(lev+2,off+len,"Read %08x, expected %08x or %08x",temp,
662     0x0c, 0x08);
663     } else
664     psiconv_debug(lev+2,off+len,"Fourth unknown long: %08x", temp);
665     off += 4;
666    
667     psiconv_progress(lev+2,off+len,"Going to read the Paint Data Section");
668 frodo 64 if ((res = psiconv_parse_paint_data_section(buf,lev+2,off+len,&leng,1,
669     &((*result)->picture))))
670     goto ERROR2;
671 frodo 43 len += leng;
672    
673     if (length)
674     *length = len;
675    
676     psiconv_progress(lev,off+len-1,
677     "End of clipart section (total length: %08x)", len);
678 frodo 64 return 0;
679 frodo 43
680 frodo 64 ERROR2:
681     free (*result);
682     ERROR1:
683     psiconv_warn(lev+1,off,"Reading of Font failed");
684     if (length)
685     *length = 0;
686     if (!res)
687     return -PSICONV_E_NOMEM;
688     else
689     return res;
690 frodo 43 }

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26