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