comparison src/glyphs-eimage.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 84b14dcb0985
children abe6d1db359e
comparison
equal deleted inserted replaced
439:357dd071b03c 440:8de8e3f6228a
312 static void 312 static void
313 jpeg_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 313 jpeg_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
314 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 314 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
315 int dest_mask, Lisp_Object domain) 315 int dest_mask, Lisp_Object domain)
316 { 316 {
317 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 317 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
318 /* It is OK for the unwind data to be local to this function, 318 /* It is OK for the unwind data to be local to this function,
319 because the unwind-protect is always executed when this 319 because the unwind-protect is always executed when this
320 stack frame is still valid. */ 320 stack frame is still valid. */
321 struct jpeg_unwind_data unwind; 321 struct jpeg_unwind_data unwind;
322 int speccount = specpdl_depth (); 322 int speccount = specpdl_depth ();
376 Extcount len; 376 Extcount len;
377 377
378 /* #### This is a definite problem under Mule due to the amount of 378 /* #### This is a definite problem under Mule due to the amount of
379 stack data it might allocate. Need to be able to convert and 379 stack data it might allocate. Need to be able to convert and
380 write out to a file. */ 380 write out to a file. */
381 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); 381 TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
382 jpeg_memory_src (&cinfo, (JOCTET *) bytes, len); 382 jpeg_memory_src (&cinfo, (JOCTET *) bytes, len);
383 } 383 }
384 384
385 /* Step 3: read file parameters with jpeg_read_header() */ 385 /* Step 3: read file parameters with jpeg_read_header() */
386 386
597 static void 597 static void
598 gif_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 598 gif_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
599 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 599 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
600 int dest_mask, Lisp_Object domain) 600 int dest_mask, Lisp_Object domain)
601 { 601 {
602 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 602 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
603 /* It is OK for the unwind data to be local to this function, 603 /* It is OK for the unwind data to be local to this function,
604 because the unwind-protect is always executed when this 604 because the unwind-protect is always executed when this
605 stack frame is still valid. */ 605 stack frame is still valid. */
606 struct gif_unwind_data unwind; 606 struct gif_unwind_data unwind;
607 int speccount = specpdl_depth (); 607 int speccount = specpdl_depth ();
621 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 621 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
622 622
623 assert (!NILP (data)); 623 assert (!NILP (data));
624 624
625 if (!(unwind.giffile = GifSetup())) 625 if (!(unwind.giffile = GifSetup()))
626 signal_image_error ("Insufficent memory to instantiate GIF image", instantiator); 626 signal_image_error ("Insufficient memory to instantiate GIF image", instantiator);
627 627
628 /* set up error facilities */ 628 /* set up error facilities */
629 if (setjmp(gif_err.setjmp_buffer)) 629 if (setjmp(gif_err.setjmp_buffer))
630 { 630 {
631 /* An error was signaled. No clean up is needed, as unwind handles that 631 /* An error was signaled. No clean up is needed, as unwind handles that
634 errstring = build_string (gif_err.err_str); 634 errstring = build_string (gif_err.err_str);
635 signal_image_error_2 ("GIF decoding error", errstring, instantiator); 635 signal_image_error_2 ("GIF decoding error", errstring, instantiator);
636 } 636 }
637 GifSetErrorFunc(unwind.giffile, (Gif_error_func)gif_error_func, (VoidPtr)&gif_err); 637 GifSetErrorFunc(unwind.giffile, (Gif_error_func)gif_error_func, (VoidPtr)&gif_err);
638 638
639 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); 639 TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
640 mem_struct.bytes = bytes; 640 mem_struct.bytes = bytes;
641 mem_struct.len = len; 641 mem_struct.len = len;
642 mem_struct.index = 0; 642 mem_struct.index = 0;
643 GifSetReadFunc(unwind.giffile, gif_read_from_memory, (VoidPtr)&mem_struct); 643 GifSetReadFunc(unwind.giffile, gif_read_from_memory, (VoidPtr)&mem_struct);
644 GifSetCloseFunc(unwind.giffile, gif_memory_close, (VoidPtr)&mem_struct); 644 GifSetCloseFunc(unwind.giffile, gif_memory_close, (VoidPtr)&mem_struct);
842 static void 842 static void
843 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 843 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
844 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 844 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
845 int dest_mask, Lisp_Object domain) 845 int dest_mask, Lisp_Object domain)
846 { 846 {
847 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 847 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
848 struct png_unwind_data unwind; 848 struct png_unwind_data unwind;
849 int speccount = specpdl_depth (); 849 int speccount = specpdl_depth ();
850 int height, width; 850 int height, width;
851 struct png_memory_storage tbr; /* Data to be read */ 851 struct png_memory_storage tbr; /* Data to be read */
852 852
898 898
899 assert (!NILP (data)); 899 assert (!NILP (data));
900 900
901 /* #### This is a definite problem under Mule due to the amount of 901 /* #### This is a definite problem under Mule due to the amount of
902 stack data it might allocate. Need to think about using Lstreams */ 902 stack data it might allocate. Need to think about using Lstreams */
903 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); 903 TO_EXTERNAL_FORMAT (LISP_STRING, data, ALLOCA, (bytes, len), Qbinary);
904 tbr.bytes = bytes; 904 tbr.bytes = bytes;
905 tbr.len = len; 905 tbr.len = len;
906 tbr.index = 0; 906 tbr.index = 0;
907 png_set_read_fn (png_ptr,(void *) &tbr, png_read_from_memory); 907 png_set_read_fn (png_ptr,(void *) &tbr, png_read_from_memory);
908 } 908 }
940 { 940 {
941 warn_when_safe (Qpng, Qinfo, "Couldn't get background color!"); 941 warn_when_safe (Qpng, Qinfo, "Couldn't get background color!");
942 } 942 }
943 else 943 else
944 { 944 {
945 struct Lisp_Color_Instance *c; 945 Lisp_Color_Instance *c;
946 Lisp_Object rgblist; 946 Lisp_Object rgblist;
947 947
948 c = XCOLOR_INSTANCE (bkgd); 948 c = XCOLOR_INSTANCE (bkgd);
949 rgblist = MAYBE_LISP_DEVMETH (XDEVICE (c->device), 949 rgblist = MAYBE_LISP_DEVMETH (XDEVICE (c->device),
950 color_instance_rgb_components, 950 color_instance_rgb_components,
1210 static void 1210 static void
1211 tiff_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 1211 tiff_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1212 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 1212 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1213 int dest_mask, Lisp_Object domain) 1213 int dest_mask, Lisp_Object domain)
1214 { 1214 {
1215 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 1215 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1216 tiff_memory_storage mem_struct; 1216 tiff_memory_storage mem_struct;
1217 /* It is OK for the unwind data to be local to this function, 1217 /* It is OK for the unwind data to be local to this function,
1218 because the unwind-protect is always executed when this 1218 because the unwind-protect is always executed when this
1219 stack frame is still valid. */ 1219 stack frame is still valid. */
1220 struct tiff_unwind_data unwind; 1220 struct tiff_unwind_data unwind;
1245 1245
1246 assert (!NILP (data)); 1246 assert (!NILP (data));
1247 1247
1248 /* #### This is a definite problem under Mule due to the amount of 1248 /* #### This is a definite problem under Mule due to the amount of
1249 stack data it might allocate. Think about Lstreams... */ 1249 stack data it might allocate. Think about Lstreams... */
1250 GET_STRING_BINARY_DATA_ALLOCA (data, bytes, len); 1250 TO_EXTERNAL_FORMAT (LISP_STRING, data,
1251 ALLOCA, (bytes, len),
1252 Qbinary);
1251 mem_struct.bytes = bytes; 1253 mem_struct.bytes = bytes;
1252 mem_struct.len = len; 1254 mem_struct.len = len;
1253 mem_struct.index = 0; 1255 mem_struct.index = 0;
1254 1256
1255 unwind.tiff = TIFFClientOpen ("memfile", "r", &mem_struct, 1257 unwind.tiff = TIFFClientOpen ("memfile", "r", &mem_struct,
1256 (TIFFReadWriteProc)tiff_memory_read, 1258 (TIFFReadWriteProc)tiff_memory_read,
1257 (TIFFReadWriteProc)tiff_memory_write, 1259 (TIFFReadWriteProc)tiff_memory_write,
1258 tiff_memory_seek, tiff_memory_close, tiff_memory_size, 1260 tiff_memory_seek, tiff_memory_close, tiff_memory_size,
1259 tiff_map_noop, tiff_unmap_noop); 1261 tiff_map_noop, tiff_unmap_noop);
1260 if (!unwind.tiff) 1262 if (!unwind.tiff)
1261 signal_image_error ("Insufficent memory to instantiate TIFF image", instantiator); 1263 signal_image_error ("Insufficient memory to instantiate TIFF image", instantiator);
1262 1264
1263 TIFFGetField (unwind.tiff, TIFFTAG_IMAGEWIDTH, &width); 1265 TIFFGetField (unwind.tiff, TIFFTAG_IMAGEWIDTH, &width);
1264 TIFFGetField (unwind.tiff, TIFFTAG_IMAGELENGTH, &height); 1266 TIFFGetField (unwind.tiff, TIFFTAG_IMAGELENGTH, &height);
1265 unwind.eimage = (unsigned char *) xmalloc (width * height * 3); 1267 unwind.eimage = (unsigned char *) xmalloc (width * height * 3);
1266 1268
1267 /* ### This is little more than proof-of-concept/function testing. 1269 /* #### This is little more than proof-of-concept/function testing.
1268 It needs to be reimplemented via scanline reads for both memory 1270 It needs to be reimplemented via scanline reads for both memory
1269 compactness. */ 1271 compactness. */
1270 raster = (uint32*) _TIFFmalloc (width * height * sizeof (uint32)); 1272 raster = (uint32*) _TIFFmalloc (width * height * sizeof (uint32));
1271 if (raster != NULL) 1273 if (raster != NULL)
1272 { 1274 {