/[public]/psiconv/tags/rel-0-9-9/lib/psiconv/generate_image.c
ViewVC logotype

Diff of /psiconv/tags/rel-0-9-9/lib/psiconv/generate_image.c

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

Revision 178 Revision 244
1/* 1/*
2
3 generate_image.c - Part of psiconv, a PSION 5 file formats converter 2 generate_image.c - Part of psiconv, a PSION 5 file formats converter
4 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl>
5 4
6 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
7 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
8 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 8 (at your option) any later version.
35 int xsize,int ysize, 34 int xsize,int ysize,
36 const psiconv_pixel_floats_t data, 35 const psiconv_pixel_floats_t data,
37 int colordepth,int color, 36 int colordepth,int color,
38 int redbits,int greenbits,int bluebits, 37 int redbits,int greenbits,int bluebits,
39 const psiconv_pixel_floats_t palet); 38 const psiconv_pixel_floats_t palet);
40static int psiconv_pixel_data_to_bytes(const psiconv_config config, 39static int psiconv_pixel_data_to_bytes(const psiconv_config config,int lev,
41 psiconv_pixel_bytes *bytes, int xsize, 40 psiconv_pixel_bytes *bytes, int xsize,
42 int ysize, const psiconv_pixel_ints pixels, 41 int ysize, const psiconv_pixel_ints pixels,
43 int colordepth); 42 int colordepth);
44static int psiconv_encode_rle8(const psiconv_config config, 43static int psiconv_encode_rle8(const psiconv_config config,
45 const psiconv_pixel_bytes plain_bytes, 44 const psiconv_pixel_bytes plain_bytes,
53static int psiconv_encode_rle24(const psiconv_config config, 52static int psiconv_encode_rle24(const psiconv_config config,
54 const psiconv_pixel_bytes plain_bytes, 53 const psiconv_pixel_bytes plain_bytes,
55 psiconv_pixel_bytes *encoded_bytes); 54 psiconv_pixel_bytes *encoded_bytes);
56 55
57int psiconv_write_paint_data_section(const psiconv_config config, 56int psiconv_write_paint_data_section(const psiconv_config config,
58 psiconv_buffer buf, 57 psiconv_buffer buf, int lev,
59 const psiconv_paint_data_section value, 58 const psiconv_paint_data_section value,
60 int is_clipart) 59 int is_clipart)
61{ 60{
62 int res,colordepth,i; 61 int res,colordepth,i;
63 psiconv_pixel_ints ints; 62 psiconv_pixel_ints ints;
64 psiconv_pixel_floats_t floats,palet; 63 psiconv_pixel_floats_t floats,palet;
65 psiconv_list bytes,bytes_rle; 64 psiconv_list bytes,bytes_rle;
66 psiconv_u8 *byteptr,encoding; 65 psiconv_u8 *byteptr,encoding;
67 66
67 psiconv_progress(config,lev,0,"Writing paint data section");
68
68 /* First, we check whether we can cope with the current configuration. 69 /* First, we check whether we can cope with the current configuration.
69 If not, we stop at once */ 70 If not, we stop at once */
70 if ((config->colordepth != 2) && (config->colordepth != 4) && 71 if ((config->colordepth != 2) && (config->colordepth != 4) &&
71 (config->colordepth != 8) && (config->colordepth != 12) && 72 (config->colordepth != 8) && (config->colordepth != 12) &&
72 (config->colordepth != 16) && (config->colordepth != 24)) { 73 (config->colordepth != 16) && (config->colordepth != 24)) {
73 psiconv_warn(config,0,psiconv_buffer_length(buf), 74 psiconv_error(config,lev,0,
74 "Unsupported color depth (%d); try 2, 4, 8, 16 or 24", 75 "Unsupported color depth (%d); try 2, 4, 8, 16 or 24",
75 config->colordepth); 76 config->colordepth);
76 res = -PSICONV_E_GENERATE; 77 res = -PSICONV_E_GENERATE;
77 goto ERROR1; 78 goto ERROR1;
78 } 79 }
79 80
80 if ((config->color) && 81 if ((config->color) &&
81 (config->bluebits || config->redbits || config->greenbits) && 82 (config->bluebits || config->redbits || config->greenbits) &&
82 (config->bluebits+config->redbits+config->greenbits!=config->colordepth)) { 83 (config->bluebits+config->redbits+config->greenbits!=config->colordepth)) {
83 psiconv_warn(config,0,psiconv_buffer_length(buf), 84 psiconv_error(config,lev,0,
84 "Sum of red (%d), green (%d) and blue (%d) bits should be " 85 "Sum of red (%d), green (%d) and blue (%d) bits should be "
85 "equal to the color depth (%d)", 86 "equal to the color depth (%d)",
86 config->redbits,config->greenbits,config->bluebits, 87 config->redbits,config->greenbits,config->bluebits,
87 config->colordepth); 88 config->colordepth);
88 res = -PSICONV_E_GENERATE; 89 res = -PSICONV_E_GENERATE;
90 } 91 }
91 92
92 if (config->color && 93 if (config->color &&
93 !(config->redbits || config->greenbits || config->bluebits) && 94 !(config->redbits || config->greenbits || config->bluebits) &&
94 (config->colordepth != 4) && (config->colordepth != 8)) { 95 (config->colordepth != 4) && (config->colordepth != 8)) {
95 psiconv_warn(config,0,psiconv_buffer_length(buf), 96 psiconv_error(config,lev,0,
96 "Current color depth (%d) has no palet associated with it", 97 "Current color depth (%d) has no palet associated with it",
97 config->colordepth); 98 config->colordepth);
98 res = -PSICONV_E_GENERATE; 99 res = -PSICONV_E_GENERATE;
99 goto ERROR1; 100 goto ERROR1;
100 } 101 }
101 102
102 if (config->color || (config->colordepth != 2)) 103 if (config->color || (config->colordepth != 2))
103 psiconv_warn(config,0,psiconv_buffer_length(buf), 104 psiconv_warn(config,lev,0,
104 "All image types except 2-bit greyscale are experimental!"); 105 "All image types except 2-bit greyscale are experimental!");
105 106
106 107
107 if (!value) { 108 if (!value) {
108 psiconv_warn(config,0,psiconv_buffer_length(buf),"Null paint data section"); 109 psiconv_error(config,lev,0,"Null paint data section");
109 res = -PSICONV_E_GENERATE; 110 res = -PSICONV_E_GENERATE;
110 goto ERROR1; 111 goto ERROR1;
111 } 112 }
112 113
113 floats.red = value->red; 114 floats.red = value->red;
114 floats.green = value->green; 115 floats.green = value->green;
115 floats.blue = value->blue; 116 floats.blue = value->blue;
116 floats.length = value->xsize * value->ysize; 117 floats.length = value->xsize * value->ysize;
117 118
118 palet = psiconv_palet_none; 119 palet = psiconv_palet_none;
119 if ((config->color) && (config->redbits == 0) && (config->greenbits == 0) &&\ 120 if ((config->color) && (config->redbits == 0) && (config->greenbits == 0) &&
120 (config->bluebits == 0)) 121 (config->bluebits == 0))
121 switch (config->colordepth) { 122 switch (config->colordepth) {
122 case 4: palet = psiconv_palet_color_4; break; 123 case 4: palet = psiconv_palet_color_4; break;
123 case 8: palet = psiconv_palet_color_8; break; 124 case 8: palet = psiconv_palet_color_8; break;
124 default: palet = psiconv_palet_none; break; 125 default: palet = psiconv_palet_none; break;
126 127
127 if ((res = psiconv_collect_pixel_data(&ints,value->xsize, 128 if ((res = psiconv_collect_pixel_data(&ints,value->xsize,
128 value->ysize,floats, 129 value->ysize,floats,
129 config->colordepth,config->color, 130 config->colordepth,config->color,
130 config->redbits,config->greenbits, 131 config->redbits,config->greenbits,
131 config->bluebits,palet))) 132 config->bluebits,palet))) {
133 psiconv_error(config,lev,0,"Error collecting pixel data");
132 goto ERROR1; 134 goto ERROR1;
135 }
133 136
134 if ((res = psiconv_pixel_data_to_bytes(config,&bytes,value->xsize,value->ysize, 137 if ((res = psiconv_pixel_data_to_bytes(config,lev+1,&bytes,value->xsize,
135 ints,config->colordepth))) 138 value->ysize,ints,
139 config->colordepth))) {
140 psiconv_error(config,lev,0,"Error translating pixel data to bytes");
136 goto ERROR2; 141 goto ERROR2;
142 }
137 143
138 144
139 switch (config->colordepth) { 145 switch (config->colordepth) {
140 case 2: 146 case 2:
141 case 4: 147 case 4:
142 case 8: 148 case 8:
143 encoding = 0x01; 149 encoding = 0x01;
144 if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle))) 150 if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle))) {
151 psiconv_error(config,lev,0,"Error encoding RLE8");
145 goto ERROR3; 152 goto ERROR3;
153 }
146 break; 154 break;
147 case 12: 155 case 12:
148 encoding = 0x02; 156 encoding = 0x02;
149 if ((res = psiconv_encode_rle12(config,bytes,&bytes_rle))) 157 if ((res = psiconv_encode_rle12(config,bytes,&bytes_rle))) {
158 psiconv_error(config,lev,0,"Error encoding RLE12");
150 goto ERROR3; 159 goto ERROR3;
160 }
151 break; 161 break;
152 case 16: 162 case 16:
153 encoding = 0x03; 163 encoding = 0x03;
154 if ((res = psiconv_encode_rle16(config,bytes,&bytes_rle))) 164 if ((res = psiconv_encode_rle16(config,bytes,&bytes_rle))) {
165 psiconv_error(config,lev,0,"Error encoding RLE16");
155 goto ERROR3; 166 goto ERROR3;
167 }
156 break; 168 break;
157 case 24: 169 case 24:
158 encoding = 0x04; 170 encoding = 0x04;
159 if ((res = psiconv_encode_rle24(config,bytes,&bytes_rle))) 171 if ((res = psiconv_encode_rle24(config,bytes,&bytes_rle))) {
172 psiconv_error(config,lev,0,"Error encoding RLE24");
160 goto ERROR3; 173 goto ERROR3;
174 }
161 break; 175 break;
162 default: 176 default:
163 encoding = 0x00; 177 encoding = 0x00;
164 } 178 }
165 if (encoding) { 179 if (encoding) {
170 psiconv_list_free(bytes_rle); 184 psiconv_list_free(bytes_rle);
171 encoding = 0x00; 185 encoding = 0x00;
172 } 186 }
173 } 187 }
174 188
175 if ((res = psiconv_write_u32(config,buf, 189 if ((res = psiconv_write_u32(config,buf,lev+1,
176 0x28+psiconv_list_length(bytes)))) 190 0x28+psiconv_list_length(bytes))))
177 goto ERROR3; 191 goto ERROR3;
178 if ((res = psiconv_write_u32(config,buf,0x28))) 192 if ((res = psiconv_write_u32(config,buf,lev+1,0x28)))
179 goto ERROR3; 193 goto ERROR3;
180 if ((res = psiconv_write_u32(config,buf,value->xsize))) 194 if ((res = psiconv_write_u32(config,buf,lev+1,value->xsize)))
181 goto ERROR3; 195 goto ERROR3;
182 if ((res = psiconv_write_u32(config,buf,value->ysize))) 196 if ((res = psiconv_write_u32(config,buf,lev+1,value->ysize)))
183 goto ERROR3; 197 goto ERROR3;
184 if ((res = psiconv_write_length(config,buf,value->pic_xsize))) 198 if ((res = psiconv_write_length(config,buf,lev+1,value->pic_xsize)))
185 goto ERROR3; 199 goto ERROR3;
186 if ((res = psiconv_write_length(config,buf,value->pic_ysize))) 200 if ((res = psiconv_write_length(config,buf,lev+1,value->pic_ysize)))
187 goto ERROR3; 201 goto ERROR3;
188 colordepth = config->colordepth; 202 colordepth = config->colordepth;
189 if ((res = psiconv_write_u32(config,buf,colordepth))) 203 if ((res = psiconv_write_u32(config,buf,lev+1,colordepth)))
190 goto ERROR3; 204 goto ERROR3;
191 if ((res = psiconv_write_u32(config,buf,(config->color?1:0)))) 205 if ((res = psiconv_write_u32(config,buf,lev+1,(config->color?1:0))))
192 goto ERROR3; 206 goto ERROR3;
193 if ((res = psiconv_write_u32(config,buf,0))) 207 if ((res = psiconv_write_u32(config,buf,lev+1,0)))
194 goto ERROR3; 208 goto ERROR3;
195 if ((res = psiconv_write_u32(config,buf,encoding))) 209 if ((res = psiconv_write_u32(config,buf,lev+1,encoding)))
196 goto ERROR3; 210 goto ERROR3;
197 if (is_clipart) { 211 if (is_clipart) {
198 if ((res = psiconv_write_u32(config,buf,0xffffffff))) 212 if ((res = psiconv_write_u32(config,buf,lev+1,0xffffffff)))
199 goto ERROR3; 213 goto ERROR3;
200 if ((res = psiconv_write_u32(config,buf,0x00000044))) 214 if ((res = psiconv_write_u32(config,buf,lev+1,0x00000044)))
201 goto ERROR3; 215 goto ERROR3;
202 } 216 }
203 for (i = 0; i < psiconv_list_length(bytes); i++) { 217 for (i = 0; i < psiconv_list_length(bytes); i++) {
204 if (!(byteptr = psiconv_list_get(bytes,i))) 218 if (!(byteptr = psiconv_list_get(bytes,i)))
205 goto ERROR3; 219 goto ERROR3;
206 if ((res = psiconv_write_u8(config,buf,*byteptr))) 220 if ((res = psiconv_write_u8(config,buf,lev+1,*byteptr)))
207 goto ERROR3; 221 goto ERROR3;
208 } 222 }
209 223
210ERROR3: 224ERROR3:
211 psiconv_list_free(bytes); 225 psiconv_list_free(bytes);
212ERROR2: 226ERROR2:
213 psiconv_list_free(ints); 227 psiconv_list_free(ints);
214ERROR1: 228ERROR1:
229 if (res)
230 psiconv_error(config,lev,0,"Writing of paint data section failed");
231 else
232 psiconv_progress(config,lev,0,"End of paint data section");
215 return res; 233 return res;
216} 234}
217 235
218/* Translate the floating point RGB information into pixel values. 236/* Translate the floating point RGB information into pixel values.
219 The palet is optional; without it, we just use the 237 The palet is optional; without it, we just use the
246 << (greenbits+bluebits)) + 264 << (greenbits+bluebits)) +
247 (((psiconv_u32) (p_green * (1 << greenbits) + 0.5)) 265 (((psiconv_u32) (p_green * (1 << greenbits) + 0.5))
248 << bluebits) + 266 << bluebits) +
249 ((psiconv_u32) (p_blue * (1 << bluebits) + 0.5)); 267 ((psiconv_u32) (p_blue * (1 << bluebits) + 0.5));
250 else 268 else
251 pixel = (p_red + p_green + p_blue)/3.0 * (1 << colordepth); 269 pixel = (0.212671 * p_red + 0.715160 * p_green + 0.072169 * p_blue) * ((1 << colordepth) * 0.999);
252 } else { 270 } else {
253 dist = 4; /* Max distance is 3, so this is safe */ 271 dist = 4; /* Max distance is 3, so this is safe */
254 pixel = -1; 272 pixel = -1;
255 for (i = 0; i < palet.length; i++) { 273 for (i = 0; i < palet.length; i++) {
256 new_dist = (p_red - palet.red[i]) * (p_red - palet.red[i]) + 274 new_dist = (p_red - palet.red[i]) * (p_red - palet.red[i]) +
272 psiconv_list_free(*pixels); 290 psiconv_list_free(*pixels);
273ERROR1: 291ERROR1:
274 return res; 292 return res;
275} 293}
276 294
277int psiconv_pixel_data_to_bytes(const psiconv_config config, 295int psiconv_pixel_data_to_bytes(const psiconv_config config,int lev,
278 psiconv_pixel_bytes *bytes, int xsize, 296 psiconv_pixel_bytes *bytes, int xsize,
279 int ysize, const psiconv_pixel_ints pixels, 297 int ysize, const psiconv_pixel_ints pixels,
280 int colordepth) 298 int colordepth)
281{ 299{
282 int res; 300 int res;
287 psiconv_u32 *pixelptr; 305 psiconv_u32 *pixelptr;
288 int inputbitsleft,outputbitnr,bitsfit,outputbytenr; 306 int inputbitsleft,outputbitnr,bitsfit,outputbytenr;
289 307
290 308
291 if (!bytes) { 309 if (!bytes) {
292 psiconv_warn(config,0,0,"NULL pixel data"); 310 psiconv_error(config,lev,0,"NULL pixel data");
293 res = -PSICONV_E_GENERATE; 311 res = -PSICONV_E_GENERATE;
294 goto ERROR1; 312 goto ERROR1;
295 } 313 }
296 if (!pixels) { 314 if (!pixels) {
297 psiconv_warn(config,0,0,"NULL pixel data"); 315 psiconv_error(config,lev,0,"NULL pixel data");
298 res = -PSICONV_E_GENERATE; 316 res = -PSICONV_E_GENERATE;
299 goto ERROR1; 317 goto ERROR1;
300 } 318 }
301 if (psiconv_list_length(pixels) != xsize * ysize) { 319 if (psiconv_list_length(pixels) != xsize * ysize) {
302 psiconv_warn(config,0,0,"Pixel number is not correct"); 320 psiconv_error(config,lev,0,"Pixel number is not correct");
303 res = -PSICONV_E_GENERATE; 321 res = -PSICONV_E_GENERATE;
304 goto ERROR1; 322 goto ERROR1;
305 } 323 }
306 324
307 if (!(*bytes = psiconv_list_new(sizeof(psiconv_u8)))) { 325 if (!(*bytes = psiconv_list_new(sizeof(psiconv_u8)))) {
314 outputbyte = 0; 332 outputbyte = 0;
315 for (y = 0; y < ysize; y++) { 333 for (y = 0; y < ysize; y++) {
316 outputbytenr = 0; 334 outputbytenr = 0;
317 for (x = 0; x < xsize; x++) { 335 for (x = 0; x < xsize; x++) {
318 if (!(pixelptr = psiconv_list_get(pixels,y*xsize+x))) { 336 if (!(pixelptr = psiconv_list_get(pixels,y*xsize+x))) {
319 psiconv_warn(config,0,0,"Massive internal corruption"); 337 psiconv_error(config,lev,0,"Data structure corruption");
320 res = -PSICONV_E_NOMEM; 338 res = -PSICONV_E_NOMEM;
321 goto ERROR2; 339 goto ERROR2;
322 } 340 }
323 inputbitsleft = colordepth; 341 inputbitsleft = colordepth;
324 inputdata = *pixelptr; 342 inputdata = *pixelptr;
395 goto ERROR2; 413 goto ERROR2;
396 if ((res = psiconv_list_add(*encoded_bytes,next))) 414 if ((res = psiconv_list_add(*encoded_bytes,next)))
397 goto ERROR2; 415 goto ERROR2;
398 i +=2; 416 i +=2;
399 } else if (*next == *entry) { 417 } else if (*next == *entry) {
400 len = 0; 418 len = 1;
401 while ((*next == *entry) && 419 while ((*next == *entry) &&
402 (i+len + 1 < psiconv_list_length(plain_bytes)) && 420 (i+len + 2 < psiconv_list_length(plain_bytes)) &&
403 len < 0x80) { 421 len < 0x80) {
404 len ++; 422 len ++;
405 if (!(next = psiconv_list_get(plain_bytes,i+len))) { 423 if (!(next = psiconv_list_get(plain_bytes,i+len))) {
406 res = -PSICONV_E_NOMEM; 424 res = -PSICONV_E_NOMEM;
407 goto ERROR2; 425 goto ERROR2;
817 return res; 835 return res;
818} 836}
819 837
820 838
821int psiconv_write_sketch_section(const psiconv_config config, 839int psiconv_write_sketch_section(const psiconv_config config,
822 psiconv_buffer buf, 840 psiconv_buffer buf, int lev,
823 const psiconv_sketch_section value) 841 const psiconv_sketch_section value)
824{ 842{
825 int res; 843 int res;
826 844
845 psiconv_progress(config,lev,0,"Writing sketch section");
827 if (!value) { 846 if (!value) {
828 psiconv_warn(config,0,0,"NULL sketch section"); 847 psiconv_error(config,lev,0,"NULL sketch section");
829 res = -PSICONV_E_GENERATE; 848 res = -PSICONV_E_GENERATE;
830 goto ERROR1; 849 goto ERROR1;
831 } 850 }
832 851
833 if ((res = psiconv_write_u16(config,buf,value->displayed_xsize))) 852 if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_xsize)))
834 goto ERROR1; 853 goto ERROR1;
835 if ((res = psiconv_write_u16(config,buf,value->displayed_ysize))) 854 if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_ysize)))
836 goto ERROR1; 855 goto ERROR1;
837 if ((res = psiconv_write_u16(config,buf,value->picture_data_x_offset))) 856 if ((res = psiconv_write_u16(config,buf,lev+1,value->picture_data_x_offset)))
838 goto ERROR1; 857 goto ERROR1;
839 if ((res = psiconv_write_u16(config,buf,value->picture_data_y_offset))) 858 if ((res = psiconv_write_u16(config,buf,lev+1,value->picture_data_y_offset)))
840 goto ERROR1; 859 goto ERROR1;
841 if ((res = psiconv_write_u16(config,buf,value->displayed_size_x_offset))) 860 if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_size_x_offset)))
842 goto ERROR1; 861 goto ERROR1;
843 if ((res = psiconv_write_u16(config,buf,value->displayed_size_y_offset))) 862 if ((res = psiconv_write_u16(config,buf,lev+1,value->displayed_size_y_offset)))
844 goto ERROR1; 863 goto ERROR1;
845 if ((res = psiconv_write_u16(config,buf,value->form_xsize))) 864 if ((res = psiconv_write_u16(config,buf,lev+1,value->form_xsize)))
846 goto ERROR1; 865 goto ERROR1;
847 if ((res = psiconv_write_u16(config,buf,value->form_ysize))) 866 if ((res = psiconv_write_u16(config,buf,lev+1,value->form_ysize)))
848 goto ERROR1; 867 goto ERROR1;
849 if ((res = psiconv_write_u16(config,buf,0x0000))) 868 if ((res = psiconv_write_u16(config,buf,lev+1,0x0000)))
850 goto ERROR1; 869 goto ERROR1;
851 if ((res = psiconv_write_paint_data_section(config,buf,value->picture,0))) 870 if ((res = psiconv_write_paint_data_section(config,buf,lev+1,value->picture,0)))
852 goto ERROR1; 871 goto ERROR1;
853 if ((res = psiconv_write_u16(config,buf,value->magnification_x * 0x03e8))) 872 if ((res = psiconv_write_u16(config,buf,lev+1,value->magnification_x * 0x03e8)))
854 goto ERROR1; 873 goto ERROR1;
855 if ((res = psiconv_write_u16(config,buf,value->magnification_y * 0x03e8))) 874 if ((res = psiconv_write_u16(config,buf,lev+1,value->magnification_y * 0x03e8)))
856 goto ERROR1; 875 goto ERROR1;
857 if ((res = psiconv_write_u32(config,buf,value->cut_left * 0x0c * 876 if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_left * 0x0c *
858 value->displayed_xsize))) 877 value->displayed_xsize)))
859 goto ERROR1; 878 goto ERROR1;
860 if ((res = psiconv_write_u32(config,buf,value->cut_right * 0x0c * 879 if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_right * 0x0c *
861 value->displayed_xsize))) 880 value->displayed_xsize)))
862 goto ERROR1; 881 goto ERROR1;
863 if ((res = psiconv_write_u32(config,buf,value->cut_top * 0x0c * 882 if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_top * 0x0c *
864 value->displayed_ysize))) 883 value->displayed_ysize)))
865 goto ERROR1; 884 goto ERROR1;
866 if ((res = psiconv_write_u32(config,buf,value->cut_bottom * 0x0c * 885 if ((res = psiconv_write_u32(config,buf,lev+1,value->cut_bottom * 0x0c *
867 value->displayed_ysize))) 886 value->displayed_ysize)))
868 goto ERROR1; 887 goto ERROR1;
869 888
870ERROR1: 889ERROR1:
890 if (res)
891 psiconv_error(config,lev,0,"Writing of sketch section failed");
892 else
893 psiconv_progress(config,lev,0,"End of sketch section");
871 return res; 894 return res;
872} 895}
873 896
874int psiconv_write_clipart_section(const psiconv_config config, 897int psiconv_write_clipart_section(const psiconv_config config,
875 psiconv_buffer buf, 898 psiconv_buffer buf, int lev,
876 const psiconv_clipart_section value) 899 const psiconv_clipart_section value)
877{ 900{
878 int res; 901 int res;
879 902
880 903 psiconv_progress(config,lev,0,"Writing clipart section");
881 if (!value) { 904 if (!value) {
882 psiconv_warn(config,0,psiconv_buffer_length(buf), 905 psiconv_error(config,lev,0, "NULL Clipart Section");
883 "NULL Clipart Section");
884 res = -PSICONV_E_GENERATE; 906 res = -PSICONV_E_GENERATE;
885 goto ERROR; 907 goto ERROR;
886 } 908 }
887 if ((res = psiconv_write_u32(config,buf,PSICONV_ID_CLIPART_ITEM))) 909 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_CLIPART_ITEM)))
888 goto ERROR; 910 goto ERROR;
889 if ((res = psiconv_write_u32(config,buf,0x00000002))) 911 if ((res = psiconv_write_u32(config,buf,lev+1,0x00000002)))
890 goto ERROR; 912 goto ERROR;
891 if ((res = psiconv_write_u32(config,buf,0x00000000))) 913 if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000)))
892 goto ERROR; 914 goto ERROR;
893 if ((res = psiconv_write_u32(config,buf,0x00000000))) 915 if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000)))
894 goto ERROR; 916 goto ERROR;
895 if ((res = psiconv_write_u32(config,buf,0x0000000C))) 917 if ((res = psiconv_write_u32(config,buf,lev+1,0x0000000C)))
896 goto ERROR; 918 goto ERROR;
897 if ((res = psiconv_write_paint_data_section(config,buf,value->picture,1))) 919 if ((res = psiconv_write_paint_data_section(config,buf,lev+1,value->picture,1)))
898 goto ERROR; 920 goto ERROR;
899 921
900ERROR: 922ERROR:
923 if (res)
924 psiconv_error(config,lev,0,"Writing of clipart section failed");
925 else
926 psiconv_progress(config,lev,0,"End of clipart section");
901 return res; 927 return res;
902} 928}
903 929
904int psiconv_write_jumptable_section(const psiconv_config config, 930int psiconv_write_jumptable_section(const psiconv_config config,
905 psiconv_buffer buf, 931 psiconv_buffer buf, int lev,
906 const psiconv_jumptable_section value) 932 const psiconv_jumptable_section value)
907{ 933{
908 int res,i; 934 int res,i;
909 psiconv_u32 *offset_ptr; 935 psiconv_u32 *offset_ptr;
910 936
937 psiconv_progress(config,lev,0,"Writing jumptable section");
911 938
912 if (!value) { 939 if (!value) {
913 psiconv_warn(config,0,psiconv_buffer_length(buf), 940 psiconv_error(config,lev,0,"NULL Jumptable Section");
914 "NULL Jumptable Section");
915 res = -PSICONV_E_GENERATE; 941 res = -PSICONV_E_GENERATE;
916 goto ERROR; 942 goto ERROR;
917 } 943 }
918 if ((res = psiconv_write_u32(config,buf,psiconv_list_length(value)))) 944 if ((res = psiconv_write_u32(config,buf,lev+1,psiconv_list_length(value))))
919 goto ERROR; 945 goto ERROR;
920 for (i = 0; i < psiconv_list_length(value); i++) { 946 for (i = 0; i < psiconv_list_length(value); i++) {
921 if (!(offset_ptr = psiconv_list_get(value,i))) { 947 if (!(offset_ptr = psiconv_list_get(value,i))) {
922 psiconv_warn(config,0,psiconv_buffer_length(buf), 948 psiconv_error(config,lev,0,"Massive memory corruption");
923 "Massive memory corruption");
924 res = -PSICONV_E_NOMEM; 949 res = -PSICONV_E_NOMEM;
925 goto ERROR; 950 goto ERROR;
926 } 951 }
927 if ((res = psiconv_write_offset(config,buf,*offset_ptr))) 952 if ((res = psiconv_write_offset(config,buf,lev+1,*offset_ptr)))
928 goto ERROR; 953 goto ERROR;
929 } 954 }
930 955
931ERROR: 956ERROR:
957 if (res)
958 psiconv_error(config,lev,0,"Writing of jumptable section failed");
959 else
960 psiconv_progress(config,lev,0,"End of jumptable section");
932 return res; 961 return res;
933} 962}
934

Legend:
Removed from v.178  
changed lines
  Added in v.244

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