Mercurial > hg > xemacs-beta
comparison src/glyphs-eimage.c @ 373:6240c7796c7a r21-2b2
Import from CVS: tag r21-2b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:04:06 +0200 |
parents | cc15677e0335 |
children | 8626e4521993 |
comparison
equal
deleted
inserted
replaced
372:49e1ed2d7ed8 | 373:6240c7796c7a |
---|---|
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" |
514 #ifdef HAVE_GIF | 515 #ifdef HAVE_GIF |
515 /********************************************************************** | 516 /********************************************************************** |
516 * GIF * | 517 * GIF * |
517 **********************************************************************/ | 518 **********************************************************************/ |
518 | 519 |
519 #include <gifrlib.h> | 520 #include "gifrlib.h" |
520 | 521 |
521 static void | 522 static void |
522 gif_validate (Lisp_Object instantiator) | 523 gif_validate (Lisp_Object instantiator) |
523 { | 524 { |
524 file_or_data_must_be_present (instantiator); | 525 file_or_data_must_be_present (instantiator); |
695 pass = 0; | 696 pass = 0; |
696 row = interlace ? InterlacedOffset[pass] : 0; | 697 row = interlace ? InterlacedOffset[pass] : 0; |
697 eip = unwind.eimage; | 698 eip = unwind.eimage; |
698 for (i = 0; i < height; i++) | 699 for (i = 0; i < height; i++) |
699 { | 700 { |
700 if (interlace && row >= height) | 701 if (interlace) |
701 row = InterlacedOffset[++pass]; | 702 if (row >= height) { |
703 row = InterlacedOffset[++pass]; | |
704 while (row > height) | |
705 row = InterlacedOffset[++pass]; | |
706 } | |
702 eip = unwind.eimage + (row * width * 3); | 707 eip = unwind.eimage + (row * width * 3); |
703 for (j = 0; j < width; j++) | 708 for (j = 0; j < width; j++) |
704 { | 709 { |
705 unsigned char pixel = unwind.giffile->SavedImages[0].RasterBits[(i * width) + j]; | 710 unsigned char pixel = unwind.giffile->SavedImages[0].RasterBits[(i * width) + j]; |
706 *eip++ = cmo->Colors[pixel].Red; | 711 *eip++ = cmo->Colors[pixel].Red; |
810 if (data->png_ptr) | 815 if (data->png_ptr) |
811 png_destroy_read_struct (&(data->png_ptr), &(data->info_ptr), (png_infopp)NULL); | 816 png_destroy_read_struct (&(data->png_ptr), &(data->info_ptr), (png_infopp)NULL); |
812 if (data->instream) | 817 if (data->instream) |
813 fclose (data->instream); | 818 fclose (data->instream); |
814 | 819 |
820 if (data->eimage) xfree(data->eimage); | |
821 | |
815 return Qnil; | 822 return Qnil; |
816 } | 823 } |
817 | 824 |
818 static void | 825 static void |
819 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, | 826 png_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, |
900 row_pointers = xnew_array (png_byte *, height); | 907 row_pointers = xnew_array (png_byte *, height); |
901 | 908 |
902 for (y = 0; y < height; y++) | 909 for (y = 0; y < height; y++) |
903 row_pointers[y] = unwind.eimage + (width * 3 * y); | 910 row_pointers[y] = unwind.eimage + (width * 3 * y); |
904 | 911 |
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 | |
905 /* Now that we're using EImage, ask for 8bit RGB triples for any type | 948 /* Now that we're using EImage, ask for 8bit RGB triples for any type |
906 of image*/ | 949 of image*/ |
907 /* convert palatte images to full RGB */ | 950 /* convert palatte images to full RGB */ |
908 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 951 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
909 png_set_expand (png_ptr); | 952 png_set_expand (png_ptr); |
912 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | 955 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
913 png_set_gray_to_rgb (png_ptr); | 956 png_set_gray_to_rgb (png_ptr); |
914 /* we can't handle alpha values */ | 957 /* we can't handle alpha values */ |
915 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) | 958 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
916 png_set_strip_alpha (png_ptr); | 959 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 */ | 960 /* tell libpng to strip 16 bit depth files down to 8 bits */ |
924 if (info_ptr->bit_depth == 16) | 961 if (info_ptr->bit_depth == 16) |
925 png_set_strip_16 (png_ptr); | 962 png_set_strip_16 (png_ptr); |
926 /* if the image is < 8 bits, pad it out */ | 963 /* if the image is < 8 bits, pad it out */ |
927 if (info_ptr->bit_depth < 8) | 964 if (info_ptr->bit_depth < 8) |
930 png_set_expand (png_ptr); | 967 png_set_expand (png_ptr); |
931 else | 968 else |
932 png_set_packing (png_ptr); | 969 png_set_packing (png_ptr); |
933 } | 970 } |
934 | 971 |
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); | 972 png_read_image (png_ptr, row_pointers); |
955 png_read_end (png_ptr, info_ptr); | 973 png_read_end (png_ptr, info_ptr); |
956 | 974 |
957 #ifdef PNG_SHOW_COMMENTS | 975 #ifdef PNG_SHOW_COMMENTS |
958 /* #### | 976 /* #### |