comparison src/glyphs-eimage.c @ 306:9ea74add5d37 r21-0b51

Import from CVS: tag r21-0b51
author cvs
date Mon, 13 Aug 2007 10:41:58 +0200
parents c9fe270a4101
children 33bdb3d4b97f
comparison
equal deleted inserted replaced
305:18920a7e9a86 306:9ea74add5d37
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"
52 #include "glyphs.h" 53 #include "glyphs.h"
53 #include "objects.h" 54 #include "objects.h"
54 55
55 #include "buffer.h" 56 #include "buffer.h"
56 #include "frame.h" 57 #include "frame.h"
900 row_pointers = xnew_array (png_byte *, height); 901 row_pointers = xnew_array (png_byte *, height);
901 902
902 for (y = 0; y < height; y++) 903 for (y = 0; y < height; y++)
903 row_pointers[y] = unwind.eimage + (width * 3 * y); 904 row_pointers[y] = unwind.eimage + (width * 3 * y);
904 905
906 {
907 /* if the png specifies a background chunk, go ahead and
908 use it, else use what we can get from the default face. */
909 png_color_16 my_background, *image_background;
910 Lisp_Object bkgd = Qnil;
911
912 my_background.red = 0x7fff;
913 my_background.green = 0x7fff;
914 my_background.blue = 0x7fff;
915 bkgd = FACE_BACKGROUND (Vdefault_face, domain);
916 if (!COLOR_INSTANCEP (bkgd))
917 {
918 warn_when_safe (Qpng, Qinfo, "Couldn't get background color!");
919 }
920 else
921 {
922 struct Lisp_Color_Instance *c;
923 Lisp_Object rgblist;
924
925 c = XCOLOR_INSTANCE (bkgd);
926 rgblist = MAYBE_LISP_DEVMETH (XDEVICE (c->device),
927 color_instance_rgb_components,
928 (c));
929 my_background.red = XINT (XCAR (rgblist));
930 my_background.green = XINT (XCAR (XCDR (rgblist)));
931 my_background.blue = XINT (XCAR (XCDR (XCDR (rgblist))));
932 }
933
934 if (png_get_bKGD (png_ptr, info_ptr, &image_background))
935 png_set_background (png_ptr, image_background,
936 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
937 else
938 png_set_background (png_ptr, &my_background,
939 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
940 }
941
905 /* Now that we're using EImage, ask for 8bit RGB triples for any type 942 /* Now that we're using EImage, ask for 8bit RGB triples for any type
906 of image*/ 943 of image*/
907 /* convert palatte images to full RGB */ 944 /* convert palatte images to full RGB */
908 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 945 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
909 png_set_expand (png_ptr); 946 png_set_expand (png_ptr);
912 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) 949 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
913 png_set_gray_to_rgb (png_ptr); 950 png_set_gray_to_rgb (png_ptr);
914 /* we can't handle alpha values */ 951 /* we can't handle alpha values */
915 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) 952 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
916 png_set_strip_alpha (png_ptr); 953 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 }
923 /* tell libpng to strip 16 bit depth files down to 8 bits */ 954 /* tell libpng to strip 16 bit depth files down to 8 bits */
924 if (info_ptr->bit_depth == 16) 955 if (info_ptr->bit_depth == 16)
925 png_set_strip_16 (png_ptr); 956 png_set_strip_16 (png_ptr);
926 /* if the image is < 8 bits, pad it out */ 957 /* if the image is < 8 bits, pad it out */
927 if (info_ptr->bit_depth < 8) 958 if (info_ptr->bit_depth < 8)
930 png_set_expand (png_ptr); 961 png_set_expand (png_ptr);
931 else 962 else
932 png_set_packing (png_ptr); 963 png_set_packing (png_ptr);
933 } 964 }
934 965
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
954 png_read_image (png_ptr, row_pointers); 966 png_read_image (png_ptr, row_pointers);
955 png_read_end (png_ptr, info_ptr); 967 png_read_end (png_ptr, info_ptr);
956 968
957 #ifdef PNG_SHOW_COMMENTS 969 #ifdef PNG_SHOW_COMMENTS
958 /* #### 970 /* ####