comparison src/glyphs-eimage.c @ 290:c9fe270a4101 r21-0b43

Import from CVS: tag r21-0b43
author cvs
date Mon, 13 Aug 2007 10:36:47 +0200
parents 7df0dd720c89
children 9ea74add5d37
comparison
equal deleted inserted replaced
289:6e6992ccc4b6 290:c9fe270a4101
33 GIF/JPEG support added by Ben Wing for 19.14 33 GIF/JPEG support added by Ben Wing for 19.14
34 PNG support added by Bill Perry for 19.14 34 PNG support added by Bill Perry for 19.14
35 Improved GIF/JPEG support added by Bill Perry for 19.14 35 Improved GIF/JPEG support added by Bill Perry for 19.14
36 Cleanup/simplification of error handling by Ben Wing for 19.14 36 Cleanup/simplification of error handling by Ben Wing for 19.14
37 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14 37 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14
38 GIF support changed to external GIFlib 3.1 by Jareth Hein for 21.0 38 GIF support changed to external Gifreader lib by Jareth Hein for 21.0
39 Many changes for color work and optimizations by Jareth Hein for 21.0 39 Many changes for color work and optimizations by Jareth Hein for 21.0
40 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0 40 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0
41 TIFF code by Jareth Hein for 21.0 41 TIFF code by Jareth Hein for 21.0
42 Generalization for ms-windows by Andy Piper for 21.0 42 Generalization for ms-windows by Andy Piper for 21.0
43 TODO: 43 TODO:
401 * (b) we passed TRUE to reject a tables-only JPEG file as an error. 401 * (b) we passed TRUE to reject a tables-only JPEG file as an error.
402 * See libjpeg.doc for more info. 402 * See libjpeg.doc for more info.
403 */ 403 */
404 404
405 { 405 {
406 int jpeg_gray = 0; /* if we're dealing with a grayscale */
406 /* Step 4: set parameters for decompression. */ 407 /* Step 4: set parameters for decompression. */
407 408
408 /* Now that we're using EImages, use the default of all data in 24bit color. 409 /* Now that we're using EImages, send all data as 24bit color.
409 The backend routine will take care of any necessary reductions. */ 410 The backend routine will take care of any necessary reductions.
411 We do have to handle the grayscale case ourselves, however. */
412 if (cinfo.jpeg_color_space == JCS_GRAYSCALE)
413 {
414 cinfo.out_color_space = JCS_GRAYSCALE;
415 jpeg_gray = 1;
416 }
417 else
418 {
419 /* we're relying on the jpeg driver to do any other conversions,
420 or signal an error if the conversion isn't supported. */
421 cinfo.out_color_space = JCS_RGB;
422 }
410 423
411 /* Step 5: Start decompressor */ 424 /* Step 5: Start decompressor */
412 jpeg_start_decompress (&cinfo); 425 jpeg_start_decompress (&cinfo);
413 426
414 /* Step 6: Read in the data and put into EImage format (8bit RGB triples)*/ 427 /* Step 6: Read in the data and put into EImage format (8bit RGB triples)*/
449 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1); 462 (void) jpeg_read_scanlines (&cinfo, row_buffer, 1);
450 jp = row_buffer[0]; 463 jp = row_buffer[0];
451 for (i = 0; i < cinfo.output_width; i++) 464 for (i = 0; i < cinfo.output_width; i++)
452 { 465 {
453 int clr; 466 int clr;
467 if (jpeg_gray)
468 {
469 unsigned char val;
454 #if (BITS_IN_JSAMPLE == 8) 470 #if (BITS_IN_JSAMPLE == 8)
455 for (clr = 0; clr < 3; clr++) 471 val = (unsigned char)*jp++;
456 *op++ = (unsigned char)*jp++;
457 #else /* other option is 12 */ 472 #else /* other option is 12 */
458 for (clr = 0; clr < 3; clr++) 473 val = (unsigned char)(*jp++ >> 4);
459 *op++ = (unsigned char)(*jp++ >> 4); 474 #endif
460 #endif 475 for (clr = 0; clr < 3; clr++) /* copy the same value into RGB */
476 *op++ = val;
477 }
478 else
479 {
480 for (clr = 0; clr < 3; clr++)
481 #if (BITS_IN_JSAMPLE == 8)
482 *op++ = (unsigned char)*jp++;
483 #else /* other option is 12 */
484 *op++ = (unsigned char)(*jp++ >> 4);
485 #endif
486 }
461 } 487 }
462 } 488 }
463 } 489 }
464 } 490 }
465 491
488 #ifdef HAVE_GIF 514 #ifdef HAVE_GIF
489 /********************************************************************** 515 /**********************************************************************
490 * GIF * 516 * GIF *
491 **********************************************************************/ 517 **********************************************************************/
492 518
493 #include <gif_lib.h> 519 #include <gifrlib.h>
494 520
495 static void 521 static void
496 gif_validate (Lisp_Object instantiator) 522 gif_validate (Lisp_Object instantiator)
497 { 523 {
498 file_or_data_must_be_present (instantiator); 524 file_or_data_must_be_present (instantiator);
796 { 822 {
797 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 823 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
798 struct png_unwind_data unwind; 824 struct png_unwind_data unwind;
799 int speccount = specpdl_depth (); 825 int speccount = specpdl_depth ();
800 int height, width; 826 int height, width;
827 struct png_memory_storage tbr; /* Data to be read */
801 828
802 /* PNG variables */ 829 /* PNG variables */
803 png_structp png_ptr; 830 png_structp png_ptr;
804 png_infop info_ptr; 831 png_infop info_ptr;
805 832
842 /* Initialize the IO layer and read in header information */ 869 /* Initialize the IO layer and read in header information */
843 { 870 {
844 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 871 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
845 CONST Extbyte *bytes; 872 CONST Extbyte *bytes;
846 Extcount len; 873 Extcount len;
847 struct png_memory_storage tbr; /* Data to be read */
848 874
849 assert (!NILP (data)); 875 assert (!NILP (data));
850 876
851 /* #### This is a definite problem under Mule due to the amount of 877 /* #### This is a definite problem under Mule due to the amount of
852 stack data it might allocate. Need to think about using Lstreams */ 878 stack data it might allocate. Need to think about using Lstreams */