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