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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.45  
changed lines
  Added in v.168

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