Mercurial > hg > xemacs-beta
comparison src/glyphs-x.c @ 269:b2472a1930f2 r20-5b33
Import from CVS: tag r20-5b33
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:27:19 +0200 |
parents | 966663fcf606 |
children | c5d627a313b1 |
comparison
equal
deleted
inserted
replaced
268:6ced69ccd85f | 269:b2472a1930f2 |
---|---|
147 | 147 |
148 | 148 |
149 /************************************************************************/ | 149 /************************************************************************/ |
150 /* image instance methods */ | 150 /* image instance methods */ |
151 /************************************************************************/ | 151 /************************************************************************/ |
152 DOESNT_RETURN | |
153 signal_image_error(CONST char *reason, Lisp_Object frob) | |
154 { | |
155 signal_error (Qimage_conversion_error, list2 (build_translated_string (reason), frob)); | |
156 } | |
157 | |
158 DOESNT_RETURN | |
159 signal_image_error_2 (CONST char *reason, | |
160 Lisp_Object frob0, Lisp_Object frob1) | |
161 { | |
162 signal_error (Qimage_conversion_error, list3 (build_translated_string (reason), frob0, | |
163 frob1)); | |
164 } | |
152 | 165 |
153 /************************************************************************/ | 166 /************************************************************************/ |
154 /* convert from a series of RGB triples to an XImage formated for the */ | 167 /* convert from a series of RGB triples to an XImage formated for the */ |
155 /* proper display */ | 168 /* proper display */ |
156 /************************************************************************/ | 169 /************************************************************************/ |
157 XImage *EImage2XImage(Lisp_Object device, int width, int height, unsigned char *pic, | 170 XImage * |
158 unsigned long **pixtbl, int *pixcount, int *npixels) | 171 convert_EImage_to_XImage(Lisp_Object device, int width, int height, unsigned char *pic, |
172 unsigned long **pixtbl, int *pixcount, int *npixels) | |
159 { | 173 { |
160 Display *dpy; | 174 Display *dpy; |
161 Colormap cmap; | 175 Colormap cmap; |
162 Visual *vis; | 176 Visual *vis; |
163 XImage *outimg; | 177 XImage *outimg; |
173 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); | 187 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); |
174 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); | 188 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); |
175 vis = DEVICE_X_VISUAL (XDEVICE(device)); | 189 vis = DEVICE_X_VISUAL (XDEVICE(device)); |
176 depth = DEVICE_X_DEPTH(XDEVICE(device)); | 190 depth = DEVICE_X_DEPTH(XDEVICE(device)); |
177 | 191 |
178 if (vis->class == PseudoColor) { | 192 if (vis->class == PseudoColor) |
179 /* Quantize the image and get a histogram while we're at it. | 193 { |
180 Do this first to save memory */ | 194 /* Quantize the image and get a histogram while we're at it. |
181 qtable = EImage_build_quantable(pic, width, height, 256); | 195 Do this first to save memory */ |
182 if (qtable == NULL) return NULL; | 196 qtable = build_EImage_quantable(pic, width, height, 256); |
183 } | 197 if (qtable == NULL) return NULL; |
198 } | |
184 | 199 |
185 bitmap_pad = ((depth > 16) ? 32 : | 200 bitmap_pad = ((depth > 16) ? 32 : |
186 (depth > 8) ? 16 : | 201 (depth > 8) ? 16 : |
187 8); | 202 8); |
188 byte_cnt = bitmap_pad >> 3; | 203 byte_cnt = bitmap_pad >> 3; |
191 depth, ZPixmap, 0, 0, width, height, | 206 depth, ZPixmap, 0, 0, width, height, |
192 bitmap_pad, 0); | 207 bitmap_pad, 0); |
193 if (!outimg) return NULL; | 208 if (!outimg) return NULL; |
194 | 209 |
195 data = (unsigned char *) xmalloc (outimg->bytes_per_line * height); | 210 data = (unsigned char *) xmalloc (outimg->bytes_per_line * height); |
196 if (!data) { | 211 if (!data) |
197 XDestroyImage(outimg); | 212 { |
198 return NULL; | 213 XDestroyImage(outimg); |
199 } | 214 return NULL; |
215 } | |
200 outimg->data = data; | 216 outimg->data = data; |
201 | 217 |
202 if (vis->class == PseudoColor) { | 218 if (vis->class == PseudoColor) |
203 unsigned long pixarray[256]; | 219 { |
204 int n; | 220 unsigned long pixarray[256]; |
205 /* use our quantize table to allocate the colors */ | 221 int n; |
206 *pixcount = 32; | 222 /* use our quantize table to allocate the colors */ |
207 *pixtbl = xnew_array (unsigned long, *pixcount); | 223 *pixcount = 32; |
208 *npixels = 0; | 224 *pixtbl = xnew_array (unsigned long, *pixcount); |
209 | 225 *npixels = 0; |
210 /* ### should implement a sort by popularity to assure proper allocation */ | 226 |
211 n = *npixels; | 227 /* ### should implement a sort by popularity to assure proper allocation */ |
212 for (i = 0; i < qtable->num_active_colors; i++) { | 228 n = *npixels; |
213 XColor color; | 229 for (i = 0; i < qtable->num_active_colors; i++) |
214 int res; | 230 { |
231 XColor color; | |
232 int res; | |
215 | 233 |
216 color.red = qtable->rm[i] ? qtable->rm[i] << 8 : 0; | 234 color.red = qtable->rm[i] ? qtable->rm[i] << 8 : 0; |
217 color.green = qtable->gm[i] ? qtable->gm[i] << 8 : 0; | 235 color.green = qtable->gm[i] ? qtable->gm[i] << 8 : 0; |
218 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0; | 236 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0; |
219 color.flags = DoRed | DoGreen | DoBlue; | 237 color.flags = DoRed | DoGreen | DoBlue; |
220 res = allocate_nearest_color (dpy, cmap, vis, &color); | 238 res = allocate_nearest_color (dpy, cmap, vis, &color); |
221 if (res > 0 && res < 3) | 239 if (res > 0 && res < 3) |
222 { | 240 { |
223 DO_REALLOC(*pixtbl, *pixcount, n+1, unsigned long); | 241 DO_REALLOC(*pixtbl, *pixcount, n+1, unsigned long); |
224 (*pixtbl)[n] = color.pixel; | 242 (*pixtbl)[n] = color.pixel; |
225 n++; | 243 n++; |
226 } | 244 } |
227 pixarray[i] = color.pixel; | 245 pixarray[i] = color.pixel; |
228 } | 246 } |
229 *npixels = n; | 247 *npixels = n; |
230 ip = pic; | 248 ip = pic; |
231 for (i = 0; i < height; i++) { | 249 for (i = 0; i < height; i++) |
232 dp = data + (i * outimg->bytes_per_line); | 250 { |
233 for (j = 0; j < width; j++) { | 251 dp = data + (i * outimg->bytes_per_line); |
234 rd = *ip++; | 252 for (j = 0; j < width; j++) |
235 gr = *ip++; | 253 { |
236 bl = *ip++; | 254 rd = *ip++; |
237 conv.val = pixarray[QUANT_GET_COLOR(qtable,rd,gr,bl)]; | 255 gr = *ip++; |
256 bl = *ip++; | |
257 conv.val = pixarray[QUANT_GET_COLOR(qtable,rd,gr,bl)]; | |
238 #ifdef WORDS_BIGENDIAN | 258 #ifdef WORDS_BIGENDIAN |
239 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q]; | 259 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q]; |
240 #else | 260 #else |
241 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q]; | 261 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q]; |
242 #endif | 262 #endif |
243 } | 263 } |
244 } | 264 } |
245 xfree(qtable); | 265 xfree(qtable); |
246 } else { | 266 } else { |
247 unsigned long rshift,gshift,bshift,rbits,gbits,bbits,junk; | 267 unsigned long rshift,gshift,bshift,rbits,gbits,bbits,junk; |
248 junk = vis->red_mask; | 268 junk = vis->red_mask; |
249 rshift = 0; | 269 rshift = 0; |
250 while ((junk & 0x1) == 0) { | 270 while ((junk & 0x1) == 0) |
251 junk = junk >> 1; | 271 { |
252 rshift ++; | 272 junk = junk >> 1; |
253 } | 273 rshift ++; |
254 rbits = 0; | 274 } |
255 while (junk != 0) { | 275 rbits = 0; |
256 junk = junk >> 1; | 276 while (junk != 0) |
257 rbits++; | 277 { |
258 } | 278 junk = junk >> 1; |
259 junk = vis->green_mask; | 279 rbits++; |
260 gshift = 0; | 280 } |
261 while ((junk & 0x1) == 0) { | 281 junk = vis->green_mask; |
262 junk = junk >> 1; | 282 gshift = 0; |
263 gshift ++; | 283 while ((junk & 0x1) == 0) |
264 } | 284 { |
265 gbits = 0; | 285 junk = junk >> 1; |
266 while (junk != 0) { | 286 gshift ++; |
267 junk = junk >> 1; | 287 } |
268 gbits++; | 288 gbits = 0; |
269 } | 289 while (junk != 0) |
270 junk = vis->blue_mask; | 290 { |
271 bshift = 0; | 291 junk = junk >> 1; |
272 while ((junk & 0x1) == 0) { | 292 gbits++; |
273 junk = junk >> 1; | 293 } |
274 bshift ++; | 294 junk = vis->blue_mask; |
275 } | 295 bshift = 0; |
276 bbits = 0; | 296 while ((junk & 0x1) == 0) |
277 while (junk != 0) { | 297 { |
278 junk = junk >> 1; | 298 junk = junk >> 1; |
279 bbits++; | 299 bshift ++; |
280 } | 300 } |
281 ip = pic; | 301 bbits = 0; |
282 for (i = 0; i < height; i++) { | 302 while (junk != 0) |
283 dp = data + (i * outimg->bytes_per_line); | 303 { |
284 for (j = 0; j < width; j++) { | 304 junk = junk >> 1; |
285 if (rbits > 8) | 305 bbits++; |
286 rd = *ip++ << (rbits - 8); | 306 } |
287 else | 307 ip = pic; |
288 rd = *ip++ >> (8 - rbits); | 308 for (i = 0; i < height; i++) |
289 if (gbits > 8) | 309 { |
290 gr = *ip++ << (gbits - 8); | 310 dp = data + (i * outimg->bytes_per_line); |
291 else | 311 for (j = 0; j < width; j++) |
292 gr = *ip++ >> (8 - gbits); | 312 { |
293 if (bbits > 8) | 313 if (rbits > 8) |
294 bl = *ip++ << (bbits - 8); | 314 rd = *ip++ << (rbits - 8); |
295 else | 315 else |
296 bl = *ip++ >> (8 - bbits); | 316 rd = *ip++ >> (8 - rbits); |
297 | 317 if (gbits > 8) |
298 conv.val = (rd << rshift) | (gr << gshift) | (bl << bshift); | 318 gr = *ip++ << (gbits - 8); |
319 else | |
320 gr = *ip++ >> (8 - gbits); | |
321 if (bbits > 8) | |
322 bl = *ip++ << (bbits - 8); | |
323 else | |
324 bl = *ip++ >> (8 - bbits); | |
325 | |
326 conv.val = (rd << rshift) | (gr << gshift) | (bl << bshift); | |
299 #ifdef WORDS_BIGENDIAN | 327 #ifdef WORDS_BIGENDIAN |
300 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q]; | 328 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q]; |
301 #else | 329 #else |
302 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q]; | 330 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q]; |
303 #endif | 331 #endif |
304 } | 332 } |
305 } | 333 } |
306 } | 334 } |
307 return outimg; | 335 return outimg; |
308 } | 336 } |
309 | 337 |
310 | 338 |
311 | 339 |
364 } | 392 } |
365 | 393 |
366 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0) | 394 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0) |
367 { | 395 { |
368 XFreeColors (dpy, | 396 XFreeColors (dpy, |
369 DEVICE_X_COLORMAP (XDEVICE(p->device)), | 397 IMAGE_INSTANCE_X_COLORMAP (p), |
370 IMAGE_INSTANCE_X_PIXELS (p), | 398 IMAGE_INSTANCE_X_PIXELS (p), |
371 IMAGE_INSTANCE_X_NPIXELS (p), 0); | 399 IMAGE_INSTANCE_X_NPIXELS (p), 0); |
372 IMAGE_INSTANCE_X_NPIXELS (p) = 0; | 400 IMAGE_INSTANCE_X_NPIXELS (p) = 0; |
373 } | 401 } |
374 } | 402 } |
389 switch (IMAGE_INSTANCE_TYPE (p1)) | 417 switch (IMAGE_INSTANCE_TYPE (p1)) |
390 { | 418 { |
391 case IMAGE_MONO_PIXMAP: | 419 case IMAGE_MONO_PIXMAP: |
392 case IMAGE_COLOR_PIXMAP: | 420 case IMAGE_COLOR_PIXMAP: |
393 case IMAGE_POINTER: | 421 case IMAGE_POINTER: |
394 if (IMAGE_INSTANCE_X_NPIXELS (p1) != IMAGE_INSTANCE_X_NPIXELS (p2)) | 422 if (IMAGE_INSTANCE_X_COLORMAP (p1) != IMAGE_INSTANCE_X_COLORMAP (p2) || |
423 IMAGE_INSTANCE_X_NPIXELS (p1) != IMAGE_INSTANCE_X_NPIXELS (p2)) | |
395 return 0; | 424 return 0; |
396 #if HAVE_SUBWINDOWS | 425 #if HAVE_SUBWINDOWS |
397 case IMAGE_SUBWINDOW: | 426 case IMAGE_SUBWINDOW: |
398 /* #### implement me */ | 427 /* #### implement me */ |
399 #endif | 428 #endif |
675 #else | 704 #else |
676 GCPRO2 (instream, outstream); | 705 GCPRO2 (instream, outstream); |
677 #endif | 706 #endif |
678 | 707 |
679 /* Get the data while doing the conversion */ | 708 /* Get the data while doing the conversion */ |
680 while (1) { | 709 while (1) |
681 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); | 710 { |
682 if (!size_in_bytes) | 711 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); |
683 break; | 712 if (!size_in_bytes) |
684 /* It does seem the flushes are necessary... */ | 713 break; |
714 /* It does seem the flushes are necessary... */ | |
685 #ifdef FILE_CODING | 715 #ifdef FILE_CODING |
686 Lstream_write (costr, tempbuf, size_in_bytes); | 716 Lstream_write (costr, tempbuf, size_in_bytes); |
687 Lstream_flush (costr); | 717 Lstream_flush (costr); |
688 #else | 718 #else |
689 Lstream_write (ostr, tempbuf, size_in_bytes); | 719 Lstream_write (ostr, tempbuf, size_in_bytes); |
690 #endif | 720 #endif |
691 Lstream_flush (ostr); | 721 Lstream_flush (ostr); |
692 if (fwrite ((unsigned char *)Dynarr_atp(conversion_out_dynarr, 0), | 722 if (fwrite ((unsigned char *)Dynarr_atp(conversion_out_dynarr, 0), |
693 Dynarr_length(conversion_out_dynarr), 1, tmpfil) != 1) | 723 Dynarr_length(conversion_out_dynarr), 1, tmpfil) != 1) |
694 { | 724 { |
695 fubar = 1; | 725 fubar = 1; |
696 break; | 726 break; |
697 } | 727 } |
698 /* reset the dynarr */ | 728 /* reset the dynarr */ |
699 Lstream_rewind(ostr); | 729 Lstream_rewind(ostr); |
700 } | 730 } |
701 | 731 |
702 if (fclose (tmpfil) != 0) | 732 if (fclose (tmpfil) != 0) |
703 fubar = 1; | 733 fubar = 1; |
704 Lstream_close (istr); | 734 Lstream_close (istr); |
705 #ifdef FILE_CODING | 735 #ifdef FILE_CODING |
822 | 852 |
823 static void | 853 static void |
824 init_image_instance_from_x_image (struct Lisp_Image_Instance *ii, | 854 init_image_instance_from_x_image (struct Lisp_Image_Instance *ii, |
825 XImage *ximage, | 855 XImage *ximage, |
826 int dest_mask, | 856 int dest_mask, |
857 Colormap cmap, | |
827 unsigned long *pixels, | 858 unsigned long *pixels, |
828 int npixels, | 859 int npixels, |
829 Lisp_Object instantiator) | 860 Lisp_Object instantiator) |
830 { | 861 { |
831 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | 862 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
869 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap; | 900 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap; |
870 IMAGE_INSTANCE_X_MASK (ii) = 0; | 901 IMAGE_INSTANCE_X_MASK (ii) = 0; |
871 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = ximage->width; | 902 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = ximage->width; |
872 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = ximage->height; | 903 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = ximage->height; |
873 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = ximage->depth; | 904 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = ximage->depth; |
905 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap; | |
874 IMAGE_INSTANCE_X_PIXELS (ii) = pixels; | 906 IMAGE_INSTANCE_X_PIXELS (ii) = pixels; |
875 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels; | 907 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels; |
876 } | 908 } |
877 | 909 |
878 | 910 |
1259 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); | 1291 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
1260 Pixmap mask = 0; | 1292 Pixmap mask = 0; |
1261 CONST char *gcc_may_you_rot_in_hell; | 1293 CONST char *gcc_may_you_rot_in_hell; |
1262 | 1294 |
1263 if (!NILP (mask_data)) | 1295 if (!NILP (mask_data)) |
1264 { | 1296 { |
1265 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))), | 1297 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))), |
1266 gcc_may_you_rot_in_hell); | 1298 gcc_may_you_rot_in_hell); |
1267 mask = | 1299 mask = |
1268 pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii), | 1300 pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii), |
1269 XINT (XCAR (mask_data)), | 1301 XINT (XCAR (mask_data)), |
1379 { | 1411 { |
1380 case XpmFileInvalid: | 1412 case XpmFileInvalid: |
1381 { | 1413 { |
1382 if (ok_if_data_invalid) | 1414 if (ok_if_data_invalid) |
1383 return Qt; | 1415 return Qt; |
1384 signal_simple_error ("invalid XPM data in file", name); | 1416 signal_image_error ("invalid XPM data in file", name); |
1385 } | 1417 } |
1386 case XpmNoMemory: | 1418 case XpmNoMemory: |
1387 { | 1419 { |
1388 signal_double_file_error ("Reading pixmap file", | 1420 signal_double_file_error ("Reading pixmap file", |
1389 "out of memory", name); | 1421 "out of memory", name); |
1645 incompatible_image_types (instantiator, dest_mask, | 1677 incompatible_image_types (instantiator, dest_mask, |
1646 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK | 1678 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK |
1647 | IMAGE_POINTER_MASK); | 1679 | IMAGE_POINTER_MASK); |
1648 force_mono = (type != IMAGE_COLOR_PIXMAP); | 1680 force_mono = (type != IMAGE_COLOR_PIXMAP); |
1649 | 1681 |
1650 #if 0 | 1682 #if 1 |
1651 /* Although I haven't found it documented yet, it appears that pointers are | 1683 /* Although I haven't found it documented yet, it appears that pointers are |
1652 always colored via the default window colormap... Sigh. However, with | 1684 always colored via the default window colormap... Sigh. However, with |
1653 the current color structure, this will blow the doors off as things aren't set up | 1685 the current color structure, this will blow the doors off as things aren't set up |
1654 to differenciate between two colormaps per console. AARGH! */ | 1686 to differenciate between two colormaps per console. AARGH! */ |
1655 if (type == IMAGE_POINTER) | 1687 if (type == IMAGE_POINTER) |
1717 case XpmSuccess: | 1749 case XpmSuccess: |
1718 break; | 1750 break; |
1719 case XpmFileInvalid: | 1751 case XpmFileInvalid: |
1720 { | 1752 { |
1721 xpm_free (&xpmattrs); | 1753 xpm_free (&xpmattrs); |
1722 signal_simple_error ("invalid XPM data", data); | 1754 signal_image_error ("invalid XPM data", data); |
1723 } | 1755 } |
1724 case XpmColorFailed: | 1756 case XpmColorFailed: |
1725 case XpmColorError: | 1757 case XpmColorError: |
1726 { | 1758 { |
1727 xpm_free (&xpmattrs); | 1759 xpm_free (&xpmattrs); |
1776 else | 1808 else |
1777 pixels = NULL; | 1809 pixels = NULL; |
1778 | 1810 |
1779 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap; | 1811 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap; |
1780 IMAGE_INSTANCE_X_MASK (ii) = mask; | 1812 IMAGE_INSTANCE_X_MASK (ii) = mask; |
1813 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap; | |
1781 IMAGE_INSTANCE_X_PIXELS (ii) = pixels; | 1814 IMAGE_INSTANCE_X_PIXELS (ii) = pixels; |
1782 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels; | 1815 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels; |
1783 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w; | 1816 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w; |
1784 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h; | 1817 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h; |
1785 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = | 1818 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = |
2072 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | 2105 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) |
2073 METHODDEF(void) | 2106 METHODDEF(void) |
2074 #else | 2107 #else |
2075 METHODDEF void | 2108 METHODDEF void |
2076 #endif | 2109 #endif |
2077 our_init_source (j_decompress_ptr cinfo) { | 2110 our_init_source (j_decompress_ptr cinfo) |
2111 { | |
2078 } | 2112 } |
2079 | 2113 |
2080 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | 2114 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) |
2081 METHODDEF(boolean) | 2115 METHODDEF(boolean) |
2082 #else | 2116 #else |
2083 METHODDEF boolean | 2117 METHODDEF boolean |
2084 #endif | 2118 #endif |
2085 our_fill_input_buffer (j_decompress_ptr cinfo) { | 2119 our_fill_input_buffer (j_decompress_ptr cinfo) |
2120 { | |
2086 /* Insert a fake EOI marker */ | 2121 /* Insert a fake EOI marker */ |
2087 struct jpeg_source_mgr *src = (struct jpeg_source_mgr *) cinfo->src; | 2122 struct jpeg_source_mgr *src = (struct jpeg_source_mgr *) cinfo->src; |
2088 static JOCTET buffer[2]; | 2123 static JOCTET buffer[2]; |
2089 | 2124 |
2090 buffer[0] = (JOCTET) 0xFF; | 2125 buffer[0] = (JOCTET) 0xFF; |
2098 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | 2133 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) |
2099 METHODDEF(void) | 2134 METHODDEF(void) |
2100 #else | 2135 #else |
2101 METHODDEF void | 2136 METHODDEF void |
2102 #endif | 2137 #endif |
2103 our_skip_input_data (j_decompress_ptr cinfo, long num_bytes) { | 2138 our_skip_input_data (j_decompress_ptr cinfo, long num_bytes) |
2139 { | |
2104 struct jpeg_source_mgr *src = NULL; | 2140 struct jpeg_source_mgr *src = NULL; |
2105 | 2141 |
2106 src = (struct jpeg_source_mgr *) cinfo->src; | 2142 src = (struct jpeg_source_mgr *) cinfo->src; |
2107 | 2143 |
2108 if (!src) { | 2144 if (!src) |
2109 return; | 2145 { |
2110 } else if (num_bytes > src->bytes_in_buffer) { | 2146 return; |
2111 ERREXIT(cinfo, JERR_INPUT_EOF); | 2147 } else if (num_bytes > src->bytes_in_buffer) |
2112 /*NOTREACHED*/ | 2148 { |
2113 } | 2149 ERREXIT(cinfo, JERR_INPUT_EOF); |
2150 /*NOTREACHED*/ | |
2151 } | |
2114 | 2152 |
2115 src->bytes_in_buffer -= num_bytes; | 2153 src->bytes_in_buffer -= num_bytes; |
2116 src->next_input_byte += num_bytes; | 2154 src->next_input_byte += num_bytes; |
2117 } | 2155 } |
2118 | 2156 |
2119 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) | 2157 #if defined(JPEG_LIB_VERSION) && (JPEG_LIB_VERSION >= 61) |
2120 METHODDEF(void) | 2158 METHODDEF(void) |
2121 #else | 2159 #else |
2122 METHODDEF void | 2160 METHODDEF void |
2123 #endif | 2161 #endif |
2124 our_term_source (j_decompress_ptr cinfo) { | 2162 our_term_source (j_decompress_ptr cinfo) |
2163 { | |
2125 } | 2164 } |
2126 | 2165 |
2127 typedef struct { | 2166 typedef struct { |
2128 struct jpeg_source_mgr pub; | 2167 struct jpeg_source_mgr pub; |
2129 } our_jpeg_source_mgr; | 2168 } our_jpeg_source_mgr; |
2131 static void | 2170 static void |
2132 jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, unsigned int len) | 2171 jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, unsigned int len) |
2133 { | 2172 { |
2134 struct jpeg_source_mgr *src = NULL; | 2173 struct jpeg_source_mgr *src = NULL; |
2135 | 2174 |
2136 if (cinfo->src == NULL) { /* first time for this JPEG object? */ | 2175 if (cinfo->src == NULL) |
2137 cinfo->src = (struct jpeg_source_mgr *) | 2176 { /* first time for this JPEG object? */ |
2138 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, | 2177 cinfo->src = (struct jpeg_source_mgr *) |
2139 sizeof(our_jpeg_source_mgr)); | 2178 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, |
2140 src = (struct jpeg_source_mgr *) cinfo->src; | 2179 sizeof(our_jpeg_source_mgr)); |
2141 src->next_input_byte = data; | 2180 src = (struct jpeg_source_mgr *) cinfo->src; |
2142 } | 2181 src->next_input_byte = data; |
2182 } | |
2143 src = (struct jpeg_source_mgr *) cinfo->src; | 2183 src = (struct jpeg_source_mgr *) cinfo->src; |
2144 src->init_source = our_init_source; | 2184 src->init_source = our_init_source; |
2145 src->fill_input_buffer = our_fill_input_buffer; | 2185 src->fill_input_buffer = our_fill_input_buffer; |
2146 src->skip_input_data = our_skip_input_data; | 2186 src->skip_input_data = our_skip_input_data; |
2147 src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ | 2187 src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ |
2265 | 2305 |
2266 /* Create the message */ | 2306 /* Create the message */ |
2267 (*cinfo.err->format_message) ((j_common_ptr) &cinfo, buffer); | 2307 (*cinfo.err->format_message) ((j_common_ptr) &cinfo, buffer); |
2268 errstring = build_string (buffer); | 2308 errstring = build_string (buffer); |
2269 | 2309 |
2270 signal_simple_error_2 ("JPEG decoding error", | 2310 signal_image_error_2 ("JPEG decoding error", |
2271 errstring, instantiator); | 2311 errstring, instantiator); |
2272 } | 2312 } |
2273 } | 2313 } |
2274 | 2314 |
2275 /* Now we can initialize the JPEG decompression object. */ | 2315 /* Now we can initialize the JPEG decompression object. */ |
2276 jpeg_create_decompress (&cinfo); | 2316 jpeg_create_decompress (&cinfo); |
2342 */ | 2382 */ |
2343 | 2383 |
2344 /* At this point we know the size of the image and the colormap. */ | 2384 /* At this point we know the size of the image and the colormap. */ |
2345 | 2385 |
2346 /* Step 5.33: Allocate the colors */ | 2386 /* Step 5.33: Allocate the colors */ |
2347 if (vis->class == PseudoColor) { | 2387 if (vis->class == PseudoColor) |
2348 int i; | 2388 { |
2349 unwind.pixcount = 32; | 2389 int i; |
2350 unwind.pixels = xnew_array (unsigned long, unwind.pixcount); | 2390 unwind.pixcount = 32; |
2351 unwind.npixels = 0; | 2391 unwind.pixels = xnew_array (unsigned long, unwind.pixcount); |
2352 | 2392 unwind.npixels = 0; |
2353 /* Allocate pixels for the various colors. */ | 2393 |
2354 for (i = 0; i < cinfo.actual_number_of_colors; i++) | 2394 /* Allocate pixels for the various colors. */ |
2355 { | 2395 for (i = 0; i < cinfo.actual_number_of_colors; i++) |
2356 XColor color; | 2396 { |
2357 int ri, gi, bi, res; | 2397 XColor color; |
2358 | 2398 int ri, gi, bi, res; |
2359 ri = 0; | 2399 |
2360 gi = cinfo.out_color_components > 1 ? 1 : 0; | 2400 ri = 0; |
2361 bi = cinfo.out_color_components > 2 ? 2 : 0; | 2401 gi = cinfo.out_color_components > 1 ? 1 : 0; |
2362 | 2402 bi = cinfo.out_color_components > 2 ? 2 : 0; |
2363 /* Ok... apparently, an entry of cinfo.colormap can be NULL if | 2403 |
2364 there are no bits of that color in the image. How incredibly | 2404 /* Ok... apparently, an entry of cinfo.colormap can be NULL if |
2365 gross. Wouldn't it be nice to have exceptions!? */ | 2405 there are no bits of that color in the image. How incredibly |
2366 color.red = cinfo.colormap[ri] ? cinfo.colormap[ri][i] << 8 : 0; | 2406 gross. Wouldn't it be nice to have exceptions!? */ |
2367 color.green = cinfo.colormap[gi] ? cinfo.colormap[gi][i] << 8 : 0; | 2407 color.red = cinfo.colormap[ri] ? cinfo.colormap[ri][i] << 8 : 0; |
2368 color.blue = cinfo.colormap[bi] ? cinfo.colormap[bi][i] << 8 : 0; | 2408 color.green = cinfo.colormap[gi] ? cinfo.colormap[gi][i] << 8 : 0; |
2369 color.flags = DoRed | DoGreen | DoBlue; | 2409 color.blue = cinfo.colormap[bi] ? cinfo.colormap[bi][i] << 8 : 0; |
2370 | 2410 color.flags = DoRed | DoGreen | DoBlue; |
2371 res = allocate_nearest_color (dpy, cmap, vis, &color); | 2411 |
2372 if (res > 0 && res < 3) | 2412 res = allocate_nearest_color (dpy, cmap, vis, &color); |
2373 { | 2413 if (res > 0 && res < 3) |
2374 DO_REALLOC(unwind.pixels, unwind.pixcount, unwind.npixels+1, unsigned long); | 2414 { |
2375 unwind.pixels[unwind.npixels] = color.pixel; | 2415 DO_REALLOC(unwind.pixels, unwind.pixcount, unwind.npixels+1, unsigned long); |
2376 unwind.npixels++; | 2416 unwind.pixels[unwind.npixels] = color.pixel; |
2377 } | 2417 unwind.npixels++; |
2378 } | 2418 } |
2379 } | 2419 } |
2420 } | |
2380 | 2421 |
2381 /* Step 5.66: Create the image */ | 2422 /* Step 5.66: Create the image */ |
2382 { | 2423 { |
2383 int height = cinfo.output_height; | 2424 int height = cinfo.output_height; |
2384 int width = cinfo.output_width; | 2425 int width = cinfo.output_width; |
2394 | 2435 |
2395 unwind.ximage = XCreateImage (dpy, vis, depth, ZPixmap, 0, 0, width, height, | 2436 unwind.ximage = XCreateImage (dpy, vis, depth, ZPixmap, 0, 0, width, height, |
2396 bitmap_pad, 0); | 2437 bitmap_pad, 0); |
2397 | 2438 |
2398 if (!unwind.ximage) | 2439 if (!unwind.ximage) |
2399 signal_simple_error ("Unable to create X image struct", instantiator); | 2440 signal_image_error ("Unable to create X image struct", instantiator); |
2400 | 2441 |
2401 /* now that bytes_per_line must have been set properly alloc data */ | 2442 /* now that bytes_per_line must have been set properly alloc data */ |
2402 unwind.ximage->data = | 2443 unwind.ximage->data = |
2403 (char *) xmalloc (unwind.ximage->bytes_per_line * height); | 2444 (char *) xmalloc (unwind.ximage->bytes_per_line * height); |
2404 } | 2445 } |
2462 | 2503 |
2463 /* Step 6: Read in the data and put into EImage format (8bit RGB triples)*/ | 2504 /* Step 6: Read in the data and put into EImage format (8bit RGB triples)*/ |
2464 | 2505 |
2465 unwind.eimage = (unsigned char*) xmalloc (cinfo.output_width * cinfo.output_height * 3); | 2506 unwind.eimage = (unsigned char*) xmalloc (cinfo.output_width * cinfo.output_height * 3); |
2466 if (!unwind.eimage) | 2507 if (!unwind.eimage) |
2467 signal_simple_error("Unable to allocate enough memory for image", instantiator); | 2508 signal_image_error("Unable to allocate enough memory for image", instantiator); |
2468 | 2509 |
2469 { | 2510 { |
2470 JSAMPARRAY row_buffer; /* Output row buffer */ | 2511 JSAMPARRAY row_buffer; /* Output row buffer */ |
2471 JSAMPLE *jp; | 2512 JSAMPLE *jp; |
2472 int row_stride; /* physical row width in output buffer */ | 2513 int row_stride; /* physical row width in output buffer */ |
2495 * Here the array is only one element long, but you could ask for | 2536 * Here the array is only one element long, but you could ask for |
2496 * more than one scanline at a time if that's more convenient. | 2537 * more than one scanline at a time if that's more convenient. |
2497 */ | 2538 */ |
2498 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1); | 2539 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1); |
2499 jp = row_buffer[0]; | 2540 jp = row_buffer[0]; |
2500 for (i = 0; i < cinfo.output_width; i++) { | 2541 for (i = 0; i < cinfo.output_width; i++) |
2501 int clr; | 2542 { |
2543 int clr; | |
2502 #if (BITS_IN_JSAMPLE == 8) | 2544 #if (BITS_IN_JSAMPLE == 8) |
2503 for (clr = 0; clr < 3; clr++) | 2545 for (clr = 0; clr < 3; clr++) |
2504 *op++ = (unsigned char)*jp++; | 2546 *op++ = (unsigned char)*jp++; |
2505 #else /* other option is 12 */ | 2547 #else /* other option is 12 */ |
2506 for (clr = 0; clr < 3; clr++) | 2548 for (clr = 0; clr < 3; clr++) |
2507 *op++ = (unsigned char)(*jp++ >> 4); | 2549 *op++ = (unsigned char)(*jp++ >> 4); |
2508 #endif | 2550 #endif |
2509 } | 2551 } |
2510 } | 2552 } |
2511 unwind.ximage = EImage2XImage (device, cinfo.output_width, cinfo.output_height, unwind.eimage, | 2553 unwind.ximage = convert_EImage_to_XImage (device, cinfo.output_width, cinfo.output_height, unwind.eimage, |
2512 &unwind.pixels, &unwind.pixcount, &unwind.npixels); | 2554 &unwind.pixels, &unwind.pixcount, &unwind.npixels); |
2513 if (!unwind.ximage) | 2555 if (!unwind.ximage) |
2514 signal_simple_error("JPEG conversion failed", instantiator); | 2556 signal_image_error("JPEG conversion failed", instantiator); |
2515 } | 2557 } |
2516 } | 2558 } |
2517 | 2559 |
2518 #endif | 2560 #endif |
2519 /* Step 6.5: Create the pixmap and set up the image instance */ | 2561 /* Step 6.5: Create the pixmap and set up the image instance */ |
2520 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, | 2562 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, |
2521 unwind.pixels, unwind.npixels, | 2563 cmap, unwind.pixels, unwind.npixels, |
2522 instantiator); | 2564 instantiator); |
2523 | 2565 |
2524 /* Step 7: Finish decompression */ | 2566 /* Step 7: Finish decompression */ |
2525 | 2567 |
2526 jpeg_finish_decompress (&cinfo); | 2568 jpeg_finish_decompress (&cinfo); |
2631 Extbyte *bytes; /* The data */ | 2673 Extbyte *bytes; /* The data */ |
2632 Extcount len; /* How big is it? */ | 2674 Extcount len; /* How big is it? */ |
2633 int index; /* Where are we? */ | 2675 int index; /* Where are we? */ |
2634 } gif_memory_storage; | 2676 } gif_memory_storage; |
2635 | 2677 |
2636 static size_t gif_read_from_memory(GifByteType *buf, size_t size, VoidPtr data) | 2678 static size_t |
2679 gif_read_from_memory(GifByteType *buf, size_t size, VoidPtr data) | |
2637 { | 2680 { |
2638 gif_memory_storage *mem = (gif_memory_storage*)data; | 2681 gif_memory_storage *mem = (gif_memory_storage*)data; |
2639 | 2682 |
2640 if (size > (mem->len - mem->index)) | 2683 if (size > (mem->len - mem->index)) |
2641 return -1; | 2684 return -1; |
2642 memcpy(buf, mem->bytes + mem->index, size); | 2685 memcpy(buf, mem->bytes + mem->index, size); |
2643 mem->index = mem->index + size; | 2686 mem->index = mem->index + size; |
2644 return size; | 2687 return size; |
2645 } | 2688 } |
2646 | 2689 |
2647 static int gif_memory_close(VoidPtr data) | 2690 static int |
2691 gif_memory_close(VoidPtr data) | |
2648 { | 2692 { |
2649 return 0; | 2693 return 0; |
2650 } | 2694 } |
2651 | 2695 |
2652 #endif | 2696 #endif |
2654 { | 2698 { |
2655 char *err_str; /* return the error string */ | 2699 char *err_str; /* return the error string */ |
2656 jmp_buf setjmp_buffer; /* for return to caller */ | 2700 jmp_buf setjmp_buffer; /* for return to caller */ |
2657 }; | 2701 }; |
2658 | 2702 |
2659 static void gif_error_func(CONST char *err_str, VoidPtr error_ptr) | 2703 static void |
2704 gif_error_func(CONST char *err_str, VoidPtr error_ptr) | |
2660 { | 2705 { |
2661 struct gif_error_struct *error_data = (struct gif_error_struct*)error_ptr; | 2706 struct gif_error_struct *error_data = (struct gif_error_struct*)error_ptr; |
2662 | 2707 |
2663 /* return to setjmp point */ | 2708 /* return to setjmp point */ |
2664 error_data->err_str = err_str; | 2709 error_data->err_str = err_str; |
2704 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | 2749 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); |
2705 | 2750 |
2706 assert (!NILP (data)); | 2751 assert (!NILP (data)); |
2707 | 2752 |
2708 if (!(unwind.giffile = GifSetup())) | 2753 if (!(unwind.giffile = GifSetup())) |
2709 signal_simple_error ("Insufficent memory to instantiate GIF image", instantiator); | 2754 signal_image_error ("Insufficent memory to instantiate GIF image", instantiator); |
2710 | 2755 |
2711 /* set up error facilities */ | 2756 /* set up error facilities */ |
2712 if (setjmp(gif_err.setjmp_buffer)) { | 2757 if (setjmp(gif_err.setjmp_buffer)) |
2713 /* An error was signaled. No clean up is needed, as unwind handles that | 2758 { |
2714 for us. Just pass the error along. */ | 2759 /* An error was signaled. No clean up is needed, as unwind handles that |
2715 Lisp_Object errstring; | 2760 for us. Just pass the error along. */ |
2716 errstring = build_string (gif_err.err_str); | 2761 Lisp_Object errstring; |
2717 signal_simple_error_2 ("GIF decoding error", errstring, instantiator); | 2762 errstring = build_string (gif_err.err_str); |
2718 } | 2763 signal_image_error_2 ("GIF decoding error", errstring, instantiator); |
2764 } | |
2719 GifSetErrorFunc(unwind.giffile, (Gif_error_func)gif_error_func, (VoidPtr)&gif_err); | 2765 GifSetErrorFunc(unwind.giffile, (Gif_error_func)gif_error_func, (VoidPtr)&gif_err); |
2720 | 2766 |
2721 #ifdef USE_TEMP_FILES_FOR_GIF_IMAGES | 2767 #ifdef USE_TEMP_FILES_FOR_GIF_IMAGES |
2722 write_lisp_string_to_temp_file (data, unwind.tempfile); | 2768 write_lisp_string_to_temp_file (data, unwind.tempfile); |
2723 unwind.tempfile_needs_to_be_removed = 1; | 2769 unwind.tempfile_needs_to_be_removed = 1; |
2793 unwind.ximage = XCreateImage (dpy, vis, | 2839 unwind.ximage = XCreateImage (dpy, vis, |
2794 depth, ZPixmap, 0, 0, width, height, | 2840 depth, ZPixmap, 0, 0, width, height, |
2795 bitmap_pad, 0); | 2841 bitmap_pad, 0); |
2796 | 2842 |
2797 if (!unwind.ximage) | 2843 if (!unwind.ximage) |
2798 signal_simple_error ("Unable to create X image struct", instantiator); | 2844 signal_image_error ("Unable to create X image struct", instantiator); |
2799 | 2845 |
2800 /* now that bytes_per_line must have been set properly alloc data */ | 2846 /* now that bytes_per_line must have been set properly alloc data */ |
2801 unwind.ximage->data = | 2847 unwind.ximage->data = |
2802 (char *) xmalloc (unwind.ximage->bytes_per_line * height); | 2848 (char *) xmalloc (unwind.ximage->bytes_per_line * height); |
2803 | 2849 |
2817 -dkindred@cs.cmu.edu */ | 2863 -dkindred@cs.cmu.edu */ |
2818 if (unwind.giffile->SavedImages[0].ImageDesc.Height != height | 2864 if (unwind.giffile->SavedImages[0].ImageDesc.Height != height |
2819 || unwind.giffile->SavedImages[0].ImageDesc.Width != width | 2865 || unwind.giffile->SavedImages[0].ImageDesc.Width != width |
2820 || unwind.giffile->SavedImages[0].ImageDesc.Left != 0 | 2866 || unwind.giffile->SavedImages[0].ImageDesc.Left != 0 |
2821 || unwind.giffile->SavedImages[0].ImageDesc.Top != 0) | 2867 || unwind.giffile->SavedImages[0].ImageDesc.Top != 0) |
2822 signal_simple_error ("First image in GIF file is not full size", | 2868 signal_image_error ("First image in GIF file is not full size", |
2823 instantiator); | 2869 instantiator); |
2824 | 2870 |
2825 interlace = unwind.giffile->SavedImages[0].ImageDesc.Interlace; | 2871 interlace = unwind.giffile->SavedImages[0].ImageDesc.Interlace; |
2826 pass = 0; | 2872 pass = 0; |
2827 row = interlace ? InterlacedOffset[pass] : 0; | 2873 row = interlace ? InterlacedOffset[pass] : 0; |
2854 static int InterlacedOffset[] = { 0, 4, 2, 1 }; | 2900 static int InterlacedOffset[] = { 0, 4, 2, 1 }; |
2855 static int InterlacedJumps[] = { 8, 8, 4, 2 }; | 2901 static int InterlacedJumps[] = { 8, 8, 4, 2 }; |
2856 | 2902 |
2857 unwind.eimage = (unsigned char*) xmalloc (width * height * 3); | 2903 unwind.eimage = (unsigned char*) xmalloc (width * height * 3); |
2858 if (!unwind.eimage) | 2904 if (!unwind.eimage) |
2859 signal_simple_error("Unable to allocate enough memory for image", instantiator); | 2905 signal_image_error("Unable to allocate enough memory for image", instantiator); |
2860 | 2906 |
2861 /* write the data in EImage format (8bit RGB triples) */ | 2907 /* write the data in EImage format (8bit RGB triples) */ |
2862 | 2908 |
2863 /* Note: We just use the first image in the file and ignore the rest. | 2909 /* Note: We just use the first image in the file and ignore the rest. |
2864 We check here that that image covers the full "screen" size. | 2910 We check here that that image covers the full "screen" size. |
2866 -dkindred@cs.cmu.edu */ | 2912 -dkindred@cs.cmu.edu */ |
2867 if (unwind.giffile->SavedImages[0].ImageDesc.Height != height | 2913 if (unwind.giffile->SavedImages[0].ImageDesc.Height != height |
2868 || unwind.giffile->SavedImages[0].ImageDesc.Width != width | 2914 || unwind.giffile->SavedImages[0].ImageDesc.Width != width |
2869 || unwind.giffile->SavedImages[0].ImageDesc.Left != 0 | 2915 || unwind.giffile->SavedImages[0].ImageDesc.Left != 0 |
2870 || unwind.giffile->SavedImages[0].ImageDesc.Top != 0) | 2916 || unwind.giffile->SavedImages[0].ImageDesc.Top != 0) |
2871 signal_simple_error ("First image in GIF file is not full size", | 2917 signal_image_error ("First image in GIF file is not full size", |
2872 instantiator); | 2918 instantiator); |
2873 | 2919 |
2874 interlace = unwind.giffile->SavedImages[0].ImageDesc.Interlace; | 2920 interlace = unwind.giffile->SavedImages[0].ImageDesc.Interlace; |
2875 pass = 0; | 2921 pass = 0; |
2876 row = interlace ? InterlacedOffset[pass] : 0; | 2922 row = interlace ? InterlacedOffset[pass] : 0; |
2878 for (i = 0; i < height; i++) | 2924 for (i = 0; i < height; i++) |
2879 { | 2925 { |
2880 if (interlace && row >= height) | 2926 if (interlace && row >= height) |
2881 row = InterlacedOffset[++pass]; | 2927 row = InterlacedOffset[++pass]; |
2882 eip = unwind.eimage + (row * width * 3); | 2928 eip = unwind.eimage + (row * width * 3); |
2883 for (j = 0; j < width; j++) { | 2929 for (j = 0; j < width; j++) |
2884 unsigned char pixel = unwind.giffile->SavedImages[0].RasterBits[(i * width) + j]; | 2930 { |
2885 *eip++ = cmo->Colors[pixel].Red; | 2931 unsigned char pixel = unwind.giffile->SavedImages[0].RasterBits[(i * width) + j]; |
2886 *eip++ = cmo->Colors[pixel].Green; | 2932 *eip++ = cmo->Colors[pixel].Red; |
2887 *eip++ = cmo->Colors[pixel].Blue; | 2933 *eip++ = cmo->Colors[pixel].Green; |
2888 } | 2934 *eip++ = cmo->Colors[pixel].Blue; |
2935 } | |
2889 row += interlace ? InterlacedJumps[pass] : 1; | 2936 row += interlace ? InterlacedJumps[pass] : 1; |
2890 } | 2937 } |
2891 unwind.ximage = EImage2XImage (device, width, height, unwind.eimage, | 2938 unwind.ximage = convert_EImage_to_XImage (device, width, height, unwind.eimage, |
2892 &unwind.pixels, &unwind.pixcount, &unwind.npixels); | 2939 &unwind.pixels, &unwind.pixcount, &unwind.npixels); |
2893 if (!unwind.ximage) | 2940 if (!unwind.ximage) |
2894 signal_simple_error("GIF conversion failed", instantiator); | 2941 signal_image_error("GIF conversion failed", instantiator); |
2895 } | 2942 } |
2896 #endif | 2943 #endif |
2897 /* 4. Now create the pixmap and set up the image instance */ | 2944 /* 4. Now create the pixmap and set up the image instance */ |
2898 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, | 2945 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, |
2899 unwind.pixels, unwind.npixels, | 2946 cmap, unwind.pixels, unwind.npixels, |
2900 instantiator); | 2947 instantiator); |
2901 /* Now that we've succeeded, we don't want the pixels | 2948 /* Now that we've succeeded, we don't want the pixels |
2902 freed right now. They're kept around in the image instance | 2949 freed right now. They're kept around in the image instance |
2903 structure until it's destroyed. */ | 2950 structure until it's destroyed. */ |
2904 unwind.npixels = 0; | 2951 unwind.npixels = 0; |
2939 Extbyte *bytes; /* The data */ | 2986 Extbyte *bytes; /* The data */ |
2940 Extcount len; /* How big is it? */ | 2987 Extcount len; /* How big is it? */ |
2941 int index; /* Where are we? */ | 2988 int index; /* Where are we? */ |
2942 }; | 2989 }; |
2943 | 2990 |
2944 static void png_read_from_memory(png_structp png_ptr, png_bytep data, | 2991 static void |
2945 png_size_t length) | 2992 png_read_from_memory(png_structp png_ptr, png_bytep data, |
2993 png_size_t length) | |
2946 { | 2994 { |
2947 struct png_memory_storage *tbr = | 2995 struct png_memory_storage *tbr = |
2948 (struct png_memory_storage *) png_get_io_ptr (png_ptr); | 2996 (struct png_memory_storage *) png_get_io_ptr (png_ptr); |
2949 | 2997 |
2950 if (length > (tbr->len - tbr->index)) | 2998 if (length > (tbr->len - tbr->index)) |
2951 png_error (png_ptr, (png_const_charp) "Read Error"); | 2999 png_error (png_ptr, (png_const_charp) "Read Error"); |
2952 memcpy(data,tbr->bytes + tbr->index,length); | 3000 memcpy (data,tbr->bytes + tbr->index,length); |
2953 tbr->index = tbr->index + length; | 3001 tbr->index = tbr->index + length; |
2954 } | 3002 } |
2955 #endif /* !USE_TEMP_FILES_FOR_PNG_IMAGES */ | 3003 #endif /* !USE_TEMP_FILES_FOR_PNG_IMAGES */ |
2956 | 3004 |
2957 struct png_error_struct | 3005 struct png_error_struct |
2966 around this, use our own error functions, and don't rely on things | 3014 around this, use our own error functions, and don't rely on things |
2967 passed in the png_ptr to them. This is an ugly hack and must | 3015 passed in the png_ptr to them. This is an ugly hack and must |
2968 go away when the lisp engine is threaded! */ | 3016 go away when the lisp engine is threaded! */ |
2969 static struct png_error_struct png_err_stct; | 3017 static struct png_error_struct png_err_stct; |
2970 | 3018 |
2971 static void png_error_func(png_structp png_ptr, png_const_charp message) | 3019 static void |
3020 png_error_func(png_structp png_ptr, png_const_charp message) | |
2972 { | 3021 { |
2973 png_err_stct.err_str = message; | 3022 png_err_stct.err_str = message; |
2974 longjmp (png_err_stct.setjmp_buffer, 1); | 3023 longjmp (png_err_stct.setjmp_buffer, 1); |
2975 } | 3024 } |
2976 | 3025 |
2977 static void png_warning_func(png_structp png_ptr, png_const_charp message) | 3026 static void |
3027 png_warning_func(png_structp png_ptr, png_const_charp message) | |
2978 { | 3028 { |
2979 warn_when_safe (Qpng, Qinfo, "%s", message); | 3029 warn_when_safe (Qpng, Qinfo, "%s", message); |
2980 } | 3030 } |
2981 | 3031 |
2982 struct png_unwind_data | 3032 struct png_unwind_data |
3053 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); | 3103 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); |
3054 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); | 3104 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); |
3055 vis = DEVICE_X_VISUAL (XDEVICE(device)); | 3105 vis = DEVICE_X_VISUAL (XDEVICE(device)); |
3056 | 3106 |
3057 /* Initialize all PNG structures */ | 3107 /* Initialize all PNG structures */ |
3058 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (void*)&png_err_stct, | 3108 png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (void*)&png_err_stct, |
3059 png_error_func, png_warning_func); | 3109 png_error_func, png_warning_func); |
3060 if (!png_ptr) | 3110 if (!png_ptr) |
3061 signal_simple_error("Error obtaining memory for png_read", instantiator); | 3111 signal_image_error ("Error obtaining memory for png_read", instantiator); |
3062 info_ptr = png_create_info_struct(png_ptr); | 3112 info_ptr = png_create_info_struct (png_ptr); |
3063 if (!info_ptr) | 3113 if (!info_ptr) |
3064 { | 3114 { |
3065 png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); | 3115 png_destroy_read_struct (&png_ptr, (png_infopp)NULL, (png_infopp)NULL); |
3066 signal_simple_error("Error obtaining memory for png_read", instantiator); | 3116 signal_image_error ("Error obtaining memory for png_read", instantiator); |
3067 } | 3117 } |
3068 | 3118 |
3069 memset (&unwind, 0, sizeof (unwind)); | 3119 memset (&unwind, 0, sizeof (unwind)); |
3070 unwind.png_ptr = png_ptr; | 3120 unwind.png_ptr = png_ptr; |
3071 unwind.info_ptr = info_ptr; | 3121 unwind.info_ptr = info_ptr; |
3085 /* Set the jmp_buf reurn context for png_error ... if this returns !0, then | 3135 /* Set the jmp_buf reurn context for png_error ... if this returns !0, then |
3086 we ran into a problem somewhere, and need to clean up after ourselves. */ | 3136 we ran into a problem somewhere, and need to clean up after ourselves. */ |
3087 if (setjmp (png_err_stct.setjmp_buffer)) | 3137 if (setjmp (png_err_stct.setjmp_buffer)) |
3088 { | 3138 { |
3089 /* Something blew up: just display the error (cleanup happens in the unwind) */ | 3139 /* Something blew up: just display the error (cleanup happens in the unwind) */ |
3090 signal_simple_error_2 ("Error decoding PNG", | 3140 signal_image_error_2 ("Error decoding PNG", |
3091 build_string(png_err_stct.err_str), | 3141 build_string(png_err_stct.err_str), |
3092 instantiator); | 3142 instantiator); |
3093 } | 3143 } |
3094 | 3144 |
3095 /* Initialize the IO layer and read in header information */ | 3145 /* Initialize the IO layer and read in header information */ |
3105 stack data it might allocate. Need to think about using Lstreams */ | 3155 stack data it might allocate. Need to think about using Lstreams */ |
3106 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); | 3156 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); |
3107 tbr.bytes = bytes; | 3157 tbr.bytes = bytes; |
3108 tbr.len = len; | 3158 tbr.len = len; |
3109 tbr.index = 0; | 3159 tbr.index = 0; |
3110 png_set_read_fn(png_ptr,(void *) &tbr, png_read_from_memory); | 3160 png_set_read_fn (png_ptr,(void *) &tbr, png_read_from_memory); |
3111 } | 3161 } |
3112 | 3162 |
3113 png_read_info (png_ptr, info_ptr); | 3163 png_read_info (png_ptr, info_ptr); |
3114 | 3164 |
3115 #if 0 | 3165 #if 0 |
3260 unwind.ximage = XCreateImage (dpy, vis, | 3310 unwind.ximage = XCreateImage (dpy, vis, |
3261 depth, ZPixmap, 0, 0, width, height, | 3311 depth, ZPixmap, 0, 0, width, height, |
3262 bitmap_pad, 0); | 3312 bitmap_pad, 0); |
3263 | 3313 |
3264 if (!unwind.ximage) | 3314 if (!unwind.ximage) |
3265 signal_simple_error ("Unable to create X image struct", | 3315 signal_image_error ("Unable to create X image struct", |
3266 instantiator); | 3316 instantiator); |
3267 | 3317 |
3268 /* now that bytes_per_line must have been set properly alloc data */ | 3318 /* now that bytes_per_line must have been set properly alloc data */ |
3269 unwind.ximage->data = (char *) xmalloc (unwind.ximage->bytes_per_line * | 3319 unwind.ximage->data = (char *) xmalloc (unwind.ximage->bytes_per_line * |
3270 height); | 3320 height); |
3300 | 3350 |
3301 /* Now that we're using EImage, ask for 8bit RGB triples for any type | 3351 /* Now that we're using EImage, ask for 8bit RGB triples for any type |
3302 of image*/ | 3352 of image*/ |
3303 /* convert palatte images to full RGB */ | 3353 /* convert palatte images to full RGB */ |
3304 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 3354 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
3305 png_set_expand(png_ptr); | 3355 png_set_expand (png_ptr); |
3306 /* send grayscale images to RGB too */ | 3356 /* send grayscale images to RGB too */ |
3307 if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || | 3357 if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || |
3308 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | 3358 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
3309 png_set_gray_to_rgb(png_ptr); | 3359 png_set_gray_to_rgb (png_ptr); |
3310 /* we can't handle alpha values */ | 3360 /* we can't handle alpha values */ |
3311 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) | 3361 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
3312 png_set_strip_alpha(png_ptr); | 3362 png_set_strip_alpha (png_ptr); |
3313 /* rip out any transparancy layers/colors */ | 3363 /* rip out any transparancy layers/colors */ |
3314 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { | 3364 if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) |
3315 png_set_expand(png_ptr); | 3365 { |
3316 png_set_strip_alpha(png_ptr); | 3366 png_set_expand (png_ptr); |
3317 } | 3367 png_set_strip_alpha (png_ptr); |
3368 } | |
3318 /* tell libpng to strip 16 bit depth files down to 8 bits */ | 3369 /* tell libpng to strip 16 bit depth files down to 8 bits */ |
3319 if (info_ptr->bit_depth == 16) | 3370 if (info_ptr->bit_depth == 16) |
3320 png_set_strip_16 (png_ptr); | 3371 png_set_strip_16 (png_ptr); |
3321 /* if the image is < 8 bits, pad it out */ | 3372 /* if the image is < 8 bits, pad it out */ |
3322 if (info_ptr->bit_depth < 8) { | 3373 if (info_ptr->bit_depth < 8) |
3323 if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) | 3374 { |
3324 png_set_expand(png_ptr); | 3375 if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) |
3325 else | 3376 png_set_expand (png_ptr); |
3326 png_set_packing (png_ptr); | 3377 else |
3327 } | 3378 png_set_packing (png_ptr); |
3379 } | |
3328 | 3380 |
3329 #if 1 /* tests? or permanent? */ | 3381 #if 1 /* tests? or permanent? */ |
3330 { | 3382 { |
3331 /* if the png specifies a background chunk, go ahead and | 3383 /* if the png specifies a background chunk, go ahead and |
3332 use it */ | 3384 use it */ |
3335 /* ### how do I get the background of the current frame? */ | 3387 /* ### how do I get the background of the current frame? */ |
3336 my_background.red = 0x7fff; | 3388 my_background.red = 0x7fff; |
3337 my_background.green = 0x7fff; | 3389 my_background.green = 0x7fff; |
3338 my_background.blue = 0x7fff; | 3390 my_background.blue = 0x7fff; |
3339 | 3391 |
3340 if (png_get_bKGD(png_ptr, info_ptr, &image_background)) | 3392 if (png_get_bKGD (png_ptr, info_ptr, &image_background)) |
3341 png_set_background(png_ptr, image_background, | 3393 png_set_background (png_ptr, image_background, |
3342 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); | 3394 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); |
3343 else | 3395 else |
3344 png_set_background(png_ptr, &my_background, | 3396 png_set_background (png_ptr, &my_background, |
3345 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); | 3397 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); |
3346 } | 3398 } |
3347 #endif | 3399 #endif |
3348 png_read_image (png_ptr, row_pointers); | 3400 png_read_image (png_ptr, row_pointers); |
3349 png_read_end (png_ptr, info_ptr); | 3401 png_read_end (png_ptr, info_ptr); |
3350 | 3402 |
3371 } | 3423 } |
3372 } | 3424 } |
3373 #endif | 3425 #endif |
3374 | 3426 |
3375 xfree (row_pointers); | 3427 xfree (row_pointers); |
3376 unwind.ximage = EImage2XImage (device, width, height, unwind.eimage, | 3428 unwind.ximage = convert_EImage_to_XImage (device, width, height, unwind.eimage, |
3377 &unwind.pixels, &unwind.pixcount, &unwind.npixels); | 3429 &unwind.pixels, &unwind.pixcount, &unwind.npixels); |
3378 if (!unwind.ximage) | 3430 if (!unwind.ximage) |
3379 signal_simple_error("PNG conversion failed", instantiator); | 3431 signal_image_error ("PNG conversion failed", instantiator); |
3380 } | 3432 } |
3381 #endif | 3433 #endif |
3382 | 3434 |
3383 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, | 3435 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, |
3384 unwind.pixels, unwind.npixels, | 3436 cmap, unwind.pixels, unwind.npixels, |
3385 instantiator); | 3437 instantiator); |
3386 | 3438 |
3387 /* This will clean up everything else. */ | 3439 /* This will clean up everything else. */ |
3388 unwind.npixels = 0; | 3440 unwind.npixels = 0; |
3389 unwind.pixcount = 0; | 3441 unwind.pixcount = 0; |
3441 if (data->tiff) | 3493 if (data->tiff) |
3442 { | 3494 { |
3443 TIFFClose(data->tiff); | 3495 TIFFClose(data->tiff); |
3444 } | 3496 } |
3445 if (data->eimage) | 3497 if (data->eimage) |
3446 xfree(data->eimage); | 3498 xfree (data->eimage); |
3447 if (data->npixels > 0) | 3499 if (data->npixels > 0) |
3448 XFreeColors (data->dpy, data->cmap, data->pixels, data->npixels, 0L); | 3500 XFreeColors (data->dpy, data->cmap, data->pixels, data->npixels, 0L); |
3449 if (data->pixcount) | 3501 if (data->pixcount) |
3450 xfree (data->pixels); | 3502 xfree (data->pixels); |
3451 if (data->ximage) | 3503 if (data->ximage) |
3466 Extbyte *bytes; /* The data */ | 3518 Extbyte *bytes; /* The data */ |
3467 Extcount len; /* How big is it? */ | 3519 Extcount len; /* How big is it? */ |
3468 int index; /* Where are we? */ | 3520 int index; /* Where are we? */ |
3469 } tiff_memory_storage; | 3521 } tiff_memory_storage; |
3470 | 3522 |
3471 static size_t tiff_memory_read(thandle_t data, tdata_t buf, tsize_t size) | 3523 static size_t |
3524 tiff_memory_read(thandle_t data, tdata_t buf, tsize_t size) | |
3472 { | 3525 { |
3473 tiff_memory_storage *mem = (tiff_memory_storage*)data; | 3526 tiff_memory_storage *mem = (tiff_memory_storage*)data; |
3474 | 3527 |
3475 if (size > (mem->len - mem->index)) | 3528 if (size > (mem->len - mem->index)) |
3476 return -1; | 3529 return -1; |
3508 | 3561 |
3509 mem->index = newidx; | 3562 mem->index = newidx; |
3510 return newidx; | 3563 return newidx; |
3511 } | 3564 } |
3512 | 3565 |
3513 static int tiff_memory_close(thandle_t data) | 3566 static int |
3567 tiff_memory_close(thandle_t data) | |
3514 { | 3568 { |
3515 return 0; | 3569 return 0; |
3516 } | 3570 } |
3517 | 3571 |
3518 static int tiff_map_noop(thandle_t data, tdata_t* pbase, toff_t* psize) | 3572 static int |
3573 tiff_map_noop(thandle_t data, tdata_t* pbase, toff_t* psize) | |
3519 { | 3574 { |
3520 return 0; | 3575 return 0; |
3521 } | 3576 } |
3522 | 3577 |
3523 static void tiff_unmap_noop(thandle_t data, tdata_t pbase, toff_t psize) | 3578 static void |
3579 tiff_unmap_noop(thandle_t data, tdata_t pbase, toff_t psize) | |
3524 { | 3580 { |
3525 return; | 3581 return; |
3526 } | 3582 } |
3527 | 3583 |
3528 static toff_t tiff_memory_size(thandle_t data) | 3584 static toff_t |
3585 tiff_memory_size(thandle_t data) | |
3529 { | 3586 { |
3530 tiff_memory_storage *mem = (tiff_memory_storage*)data; | 3587 tiff_memory_storage *mem = (tiff_memory_storage*)data; |
3531 return mem->len; | 3588 return mem->len; |
3532 } | 3589 } |
3533 | 3590 |
3545 is an ugly hack caused by the fact that libtiff (as of v3.4) doesn't | 3602 is an ugly hack caused by the fact that libtiff (as of v3.4) doesn't |
3546 have any place to store error func data. This should be rectified | 3603 have any place to store error func data. This should be rectified |
3547 before XEmacs gets threads! */ | 3604 before XEmacs gets threads! */ |
3548 static struct tiff_error_struct tiff_err_data; | 3605 static struct tiff_error_struct tiff_err_data; |
3549 | 3606 |
3550 static void tiff_error_func(CONST char *module, CONST char *fmt, ...) | 3607 static void |
3608 tiff_error_func(CONST char *module, CONST char *fmt, ...) | |
3551 { | 3609 { |
3552 va_list vargs; | 3610 va_list vargs; |
3553 | 3611 |
3554 va_start (vargs, fmt); | 3612 va_start (vargs, fmt); |
3555 #if HAVE_VSNPRINTF | 3613 #if HAVE_VSNPRINTF |
3556 vsnprintf(tiff_err_data.err_str, 255, fmt, vargs); | 3614 vsnprintf (tiff_err_data.err_str, 255, fmt, vargs); |
3557 #else | 3615 #else |
3558 /* pray this doesn't overflow... */ | 3616 /* pray this doesn't overflow... */ |
3559 vsprintf(tiff_err_data.err_str, fmt, vargs); | 3617 vsprintf (tiff_err_data.err_str, fmt, vargs); |
3560 #endif | 3618 #endif |
3561 va_end(vargs); | 3619 va_end (vargs); |
3562 /* return to setjmp point */ | 3620 /* return to setjmp point */ |
3563 longjmp (tiff_err_data.setjmp_buffer, 1); | 3621 longjmp (tiff_err_data.setjmp_buffer, 1); |
3564 } | 3622 } |
3565 | 3623 |
3566 static void tiff_warning_func(CONST char *module, CONST char *fmt, ...) | 3624 static void |
3625 tiff_warning_func(CONST char *module, CONST char *fmt, ...) | |
3567 { | 3626 { |
3568 va_list vargs; | 3627 va_list vargs; |
3569 #if HAVE_VSNPRINTF | 3628 #if HAVE_VSNPRINTF |
3570 char warn_str[256]; | 3629 char warn_str[256]; |
3571 #else | 3630 #else |
3572 char warn_str[1024]; | 3631 char warn_str[1024]; |
3573 #endif | 3632 #endif |
3574 | 3633 |
3575 va_start (vargs, fmt); | 3634 va_start (vargs, fmt); |
3576 #if HAVE_VSNPRINTF | 3635 #if HAVE_VSNPRINTF |
3577 vsnprintf(warn_str, 255, fmt, vargs); | 3636 vsnprintf (warn_str, 255, fmt, vargs); |
3578 #else | 3637 #else |
3579 vsprintf(warn_str, fmt, vargs); | 3638 vsprintf (warn_str, fmt, vargs); |
3580 #endif | 3639 #endif |
3581 va_end(vargs); | 3640 va_end (vargs); |
3582 warn_when_safe (Qtiff, Qinfo, "%s - %s", | 3641 warn_when_safe (Qtiff, Qinfo, "%s - %s", |
3583 module, warn_str); | 3642 module, warn_str); |
3584 } | 3643 } |
3585 | 3644 |
3586 static void | 3645 static void |
3609 unwind.dpy = dpy; | 3668 unwind.dpy = dpy; |
3610 unwind.cmap = cmap; | 3669 unwind.cmap = cmap; |
3611 record_unwind_protect (tiff_instantiate_unwind, make_opaque_ptr (&unwind)); | 3670 record_unwind_protect (tiff_instantiate_unwind, make_opaque_ptr (&unwind)); |
3612 | 3671 |
3613 /* set up error facilities */ | 3672 /* set up error facilities */ |
3614 if (setjmp(tiff_err_data.setjmp_buffer)) { | 3673 if (setjmp (tiff_err_data.setjmp_buffer)) |
3615 /* An error was signaled. No clean up is needed, as unwind handles that | 3674 { |
3616 for us. Just pass the error along. */ | 3675 /* An error was signaled. No clean up is needed, as unwind handles that |
3617 signal_simple_error_2 ("TIFF decoding error", | 3676 for us. Just pass the error along. */ |
3618 build_string(tiff_err_data.err_str), | 3677 signal_image_error_2 ("TIFF decoding error", |
3619 instantiator); | 3678 build_string(tiff_err_data.err_str), |
3620 } | 3679 instantiator); |
3621 TIFFSetErrorHandler((TIFFErrorHandler)tiff_error_func); | 3680 } |
3622 TIFFSetWarningHandler((TIFFErrorHandler)tiff_warning_func); | 3681 TIFFSetErrorHandler ((TIFFErrorHandler)tiff_error_func); |
3682 TIFFSetWarningHandler ((TIFFErrorHandler)tiff_warning_func); | |
3623 { | 3683 { |
3624 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); | 3684 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); |
3625 Extbyte *bytes; | 3685 Extbyte *bytes; |
3626 Extcount len; | 3686 Extcount len; |
3627 | 3687 |
3636 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); | 3696 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); |
3637 mem_struct.bytes = bytes; | 3697 mem_struct.bytes = bytes; |
3638 mem_struct.len = len; | 3698 mem_struct.len = len; |
3639 mem_struct.index = 0; | 3699 mem_struct.index = 0; |
3640 | 3700 |
3641 unwind.tiff = TIFFClientOpen("memfile", "r", &mem_struct, | 3701 unwind.tiff = TIFFClientOpen ("memfile", "r", &mem_struct, |
3642 (TIFFReadWriteProc)tiff_memory_read, | 3702 (TIFFReadWriteProc)tiff_memory_read, |
3643 (TIFFReadWriteProc)tiff_memory_write, | 3703 (TIFFReadWriteProc)tiff_memory_write, |
3644 tiff_memory_seek, tiff_memory_close, tiff_memory_size, | 3704 tiff_memory_seek, tiff_memory_close, tiff_memory_size, |
3645 tiff_map_noop, tiff_unmap_noop); | 3705 tiff_map_noop, tiff_unmap_noop); |
3646 if (!unwind.tiff) | 3706 if (!unwind.tiff) |
3647 signal_simple_error ("Insufficent memory to instantiate TIFF image", instantiator); | 3707 signal_image_error ("Insufficent memory to instantiate TIFF image", instantiator); |
3648 | 3708 |
3649 TIFFGetField(unwind.tiff, TIFFTAG_IMAGEWIDTH, &width); | 3709 TIFFGetField (unwind.tiff, TIFFTAG_IMAGEWIDTH, &width); |
3650 TIFFGetField(unwind.tiff, TIFFTAG_IMAGELENGTH, &height); | 3710 TIFFGetField (unwind.tiff, TIFFTAG_IMAGELENGTH, &height); |
3651 unwind.eimage = xmalloc(width * height * 3); | 3711 unwind.eimage = xmalloc (width * height * 3); |
3652 | 3712 |
3653 /* ### This is little more than proof-of-concept/function testing. | 3713 /* ### This is little more than proof-of-concept/function testing. |
3654 It needs to be reimplimented via scanline reads for both memory | 3714 It needs to be reimplimented via scanline reads for both memory |
3655 compactness. */ | 3715 compactness. */ |
3656 raster = (uint32*) _TIFFmalloc(width * height * sizeof (uint32)); | 3716 raster = (uint32*) _TIFFmalloc (width * height * sizeof (uint32)); |
3657 if (raster != NULL) { | 3717 if (raster != NULL) |
3658 int i,j; | 3718 { |
3659 uint32 *rp; | 3719 int i,j; |
3660 ep = unwind.eimage; | 3720 uint32 *rp; |
3661 rp = raster; | 3721 ep = unwind.eimage; |
3662 if (TIFFReadRGBAImage(unwind.tiff, width, height, raster, 0)) { | 3722 rp = raster; |
3663 for (i = height - 1; i >= 0; i--) { | 3723 if (TIFFReadRGBAImage (unwind.tiff, width, height, raster, 0)) |
3664 /* This is to get around weirdness in the libtiff library where properly | 3724 { |
3665 made TIFFs will come out upside down. libtiff bug or jhod-brainlock? */ | 3725 for (i = height - 1; i >= 0; i--) |
3666 rp = raster + (i * width); | 3726 { |
3667 for (j = 0; j < width; j++) { | 3727 /* This is to get around weirdness in the libtiff library where properly |
3668 *ep++ = (unsigned char)TIFFGetR(*rp); | 3728 made TIFFs will come out upside down. libtiff bug or jhod-brainlock? */ |
3669 *ep++ = (unsigned char)TIFFGetG(*rp); | 3729 rp = raster + (i * width); |
3670 *ep++ = (unsigned char)TIFFGetB(*rp); | 3730 for (j = 0; j < width; j++) |
3671 rp++; | 3731 { |
3732 *ep++ = (unsigned char)TIFFGetR(*rp); | |
3733 *ep++ = (unsigned char)TIFFGetG(*rp); | |
3734 *ep++ = (unsigned char)TIFFGetB(*rp); | |
3735 rp++; | |
3736 } | |
3737 } | |
3672 } | 3738 } |
3673 } | 3739 _TIFFfree (raster); |
3674 } | 3740 } else |
3675 _TIFFfree(raster); | 3741 signal_image_error ("Unable to allocate memory for TIFFReadRGBA", instantiator); |
3676 } else | 3742 |
3677 signal_simple_error ("Unable to allocate memory for TIFFReadRGBA", instantiator); | 3743 unwind.ximage = convert_EImage_to_XImage (device, width, height, unwind.eimage, |
3678 | |
3679 unwind.ximage = EImage2XImage (device, width, height, unwind.eimage, | |
3680 &unwind.pixels, &unwind.pixcount, &unwind.npixels); | 3744 &unwind.pixels, &unwind.pixcount, &unwind.npixels); |
3681 if (!unwind.ximage) | 3745 if (!unwind.ximage) |
3682 signal_simple_error("TIFF conversion failed", instantiator); | 3746 signal_image_error ("TIFF conversion failed", instantiator); |
3683 } | 3747 } |
3684 /* Now create the pixmap and set up the image instance */ | 3748 /* Now create the pixmap and set up the image instance */ |
3685 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, | 3749 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask, |
3686 unwind.pixels, unwind.npixels, | 3750 cmap, unwind.pixels, unwind.npixels, |
3687 instantiator); | 3751 instantiator); |
3688 /* Now that we've succeeded, we don't want the pixels | 3752 /* Now that we've succeeded, we don't want the pixels |
3689 freed right now. They're kept around in the image instance | 3753 freed right now. They're kept around in the image instance |
3690 structure until it's destroyed. */ | 3754 structure until it's destroyed. */ |
3691 unwind.npixels = 0; | 3755 unwind.npixels = 0; |