comparison src/glyphs-eimage.c @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents 4711e16a8e49
children 6240c7796c7a
comparison
equal deleted inserted replaced
370:bd866891f083 371:cc15677e0335
47 #include <config.h> 47 #include <config.h>
48 #include "lisp.h" 48 #include "lisp.h"
49 #include "lstream.h" 49 #include "lstream.h"
50 #include "console.h" 50 #include "console.h"
51 #include "device.h" 51 #include "device.h"
52 #include "faces.h"
53 #include "glyphs.h" 52 #include "glyphs.h"
54 #include "objects.h" 53 #include "objects.h"
55 54
56 #include "buffer.h" 55 #include "buffer.h"
57 #include "frame.h" 56 #include "frame.h"
515 #ifdef HAVE_GIF 514 #ifdef HAVE_GIF
516 /********************************************************************** 515 /**********************************************************************
517 * GIF * 516 * GIF *
518 **********************************************************************/ 517 **********************************************************************/
519 518
520 #include "gifrlib.h" 519 #include <gifrlib.h>
521 520
522 static void 521 static void
523 gif_validate (Lisp_Object instantiator) 522 gif_validate (Lisp_Object instantiator)
524 { 523 {
525 file_or_data_must_be_present (instantiator); 524 file_or_data_must_be_present (instantiator);
696 pass = 0; 695 pass = 0;
697 row = interlace ? InterlacedOffset[pass] : 0; 696 row = interlace ? InterlacedOffset[pass] : 0;
698 eip = unwind.eimage; 697 eip = unwind.eimage;
699 for (i = 0; i < height; i++) 698 for (i = 0; i < height; i++)
700 { 699 {
701 if (interlace) 700 if (interlace && row >= height)
702 if (row >= height) { 701 row = InterlacedOffset[++pass];
703 row = InterlacedOffset[++pass];
704 while (row >= height)
705 row = InterlacedOffset[++pass];
706 }
707 eip = unwind.eimage + (row * width * 3); 702 eip = unwind.eimage + (row * width * 3);
708 for (j = 0; j < width; j++) 703 for (j = 0; j < width; j++)
709 { 704 {
710 unsigned char pixel = unwind.giffile->SavedImages[0].RasterBits[(i * width) + j]; 705 unsigned char pixel = unwind.giffile->SavedImages[0].RasterBits[(i * width) + j];
711 *eip++ = cmo->Colors[pixel].Red; 706 *eip++ = cmo->Colors[pixel].Red;
815 if (data->png_ptr) 810 if (data->png_ptr)
816 png_destroy_read_struct (&(data->png_ptr), &(data->info_ptr), (png_infopp)NULL); 811 png_destroy_read_struct (&(data->png_ptr), &(data->info_ptr), (png_infopp)NULL);
817 if (data->instream) 812 if (data->instream)
818 fclose (data->instream); 813 fclose (data->instream);
819 814
820 if (data->eimage) xfree(data->eimage);
821
822 return Qnil; 815 return Qnil;
823 } 816 }
824 817
825 static void 818 static void
826 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 819 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
907 row_pointers = xnew_array (png_byte *, height); 900 row_pointers = xnew_array (png_byte *, height);
908 901
909 for (y = 0; y < height; y++) 902 for (y = 0; y < height; y++)
910 row_pointers[y] = unwind.eimage + (width * 3 * y); 903 row_pointers[y] = unwind.eimage + (width * 3 * y);
911 904
912 {
913 /* if the png specifies a background chunk, go ahead and
914 use it, else use what we can get from the default face. */
915 png_color_16 my_background, *image_background;
916 Lisp_Object bkgd = Qnil;
917
918 my_background.red = 0x7fff;
919 my_background.green = 0x7fff;
920 my_background.blue = 0x7fff;
921 bkgd = FACE_BACKGROUND (Vdefault_face, domain);
922 if (!COLOR_INSTANCEP (bkgd))
923 {
924 warn_when_safe (Qpng, Qinfo, "Couldn't get background color!");
925 }
926 else
927 {
928 struct Lisp_Color_Instance *c;
929 Lisp_Object rgblist;
930
931 c = XCOLOR_INSTANCE (bkgd);
932 rgblist = MAYBE_LISP_DEVMETH (XDEVICE (c->device),
933 color_instance_rgb_components,
934 (c));
935 my_background.red = XINT (XCAR (rgblist));
936 my_background.green = XINT (XCAR (XCDR (rgblist)));
937 my_background.blue = XINT (XCAR (XCDR (XCDR (rgblist))));
938 }
939
940 if (png_get_bKGD (png_ptr, info_ptr, &image_background))
941 png_set_background (png_ptr, image_background,
942 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
943 else
944 png_set_background (png_ptr, &my_background,
945 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
946 }
947
948 /* Now that we're using EImage, ask for 8bit RGB triples for any type 905 /* Now that we're using EImage, ask for 8bit RGB triples for any type
949 of image*/ 906 of image*/
950 /* convert palatte images to full RGB */ 907 /* convert palatte images to full RGB */
951 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 908 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
952 png_set_expand (png_ptr); 909 png_set_expand (png_ptr);
955 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 912 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
956 png_set_gray_to_rgb (png_ptr); 913 png_set_gray_to_rgb (png_ptr);
957 /* we can't handle alpha values */ 914 /* we can't handle alpha values */
958 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) 915 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
959 png_set_strip_alpha (png_ptr); 916 png_set_strip_alpha (png_ptr);
917 /* rip out any transparancy layers/colors */
918 if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
919 {
920 png_set_expand (png_ptr);
921 png_set_strip_alpha (png_ptr);
922 }
960 /* tell libpng to strip 16 bit depth files down to 8 bits */ 923 /* tell libpng to strip 16 bit depth files down to 8 bits */
961 if (info_ptr->bit_depth == 16) 924 if (info_ptr->bit_depth == 16)
962 png_set_strip_16 (png_ptr); 925 png_set_strip_16 (png_ptr);
963 /* if the image is < 8 bits, pad it out */ 926 /* if the image is < 8 bits, pad it out */
964 if (info_ptr->bit_depth < 8) 927 if (info_ptr->bit_depth < 8)
967 png_set_expand (png_ptr); 930 png_set_expand (png_ptr);
968 else 931 else
969 png_set_packing (png_ptr); 932 png_set_packing (png_ptr);
970 } 933 }
971 934
935 #if 1 /* tests? or permanent? */
936 {
937 /* if the png specifies a background chunk, go ahead and
938 use it */
939 png_color_16 my_background, *image_background;
940
941 /* ### how do I get the background of the current frame? */
942 my_background.red = 0x7fff;
943 my_background.green = 0x7fff;
944 my_background.blue = 0x7fff;
945
946 if (png_get_bKGD (png_ptr, info_ptr, &image_background))
947 png_set_background (png_ptr, image_background,
948 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
949 else
950 png_set_background (png_ptr, &my_background,
951 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
952 }
953 #endif
972 png_read_image (png_ptr, row_pointers); 954 png_read_image (png_ptr, row_pointers);
973 png_read_end (png_ptr, info_ptr); 955 png_read_end (png_ptr, info_ptr);
974 956
975 #ifdef PNG_SHOW_COMMENTS 957 #ifdef PNG_SHOW_COMMENTS
976 /* #### 958 /* ####