comparison src/glyphs-eimage.c @ 5372:6c3a695f54f5

Update png_instantiate () to work with more recent versions of libpng. 2011-03-14 Aidan Kehoe <kehoea@parhasard.net> * glyphs-eimage.c (png_instantiate): Update the PNG handling code to work with versions of the library where the png_info structure is no longer visible. Thank you for the report, Robert Delius Royar.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 14 Mar 2011 21:04:45 +0000
parents db84c9d41437
children ac37a5f7e5be
comparison
equal deleted inserted replaced
5371:6f10ac29bf40 5372:6c3a695f54f5
980 980
981 { 981 {
982 int y, padding; 982 int y, padding;
983 Binbyte **row_pointers; 983 Binbyte **row_pointers;
984 UINT_64_BIT pixels_sq; 984 UINT_64_BIT pixels_sq;
985 height = info_ptr->height; 985 height = png_get_image_height (png_ptr, info_ptr);
986 width = info_ptr->width; 986 width = png_get_image_width (png_ptr, info_ptr);
987 pixels_sq = (UINT_64_BIT) width * (UINT_64_BIT) height; 987 pixels_sq = (UINT_64_BIT) width * (UINT_64_BIT) height;
988 if (pixels_sq > ((size_t) -1) / 3) 988 if (pixels_sq > ((size_t) -1) / 3)
989 signal_image_error ("PNG image too large to instantiate", instantiator); 989 signal_image_error ("PNG image too large to instantiate", instantiator);
990 990
991 /* Wow, allocate all the memory. Truly, exciting. 991 /* Wow, allocate all the memory. Truly, exciting.
1042 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); 1042 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
1043 } 1043 }
1044 1044
1045 /* Now that we're using EImage, ask for 8bit RGB triples for any type 1045 /* Now that we're using EImage, ask for 8bit RGB triples for any type
1046 of image*/ 1046 of image*/
1047 /* convert palette images to RGB */ 1047 switch (png_get_color_type (png_ptr, info_ptr))
1048 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1049 png_set_palette_to_rgb (png_ptr);
1050 /* convert grayscale images to RGB */
1051 else if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
1052 info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1053 png_set_gray_to_rgb (png_ptr);
1054 /* pad images with depth < 8 bits */
1055 else if (info_ptr->bit_depth < 8)
1056 { 1048 {
1057 if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) 1049 case PNG_COLOR_TYPE_PALETTE:
1058 png_set_expand (png_ptr); 1050 /* convert palette images to RGB */
1059 else 1051 png_set_palette_to_rgb (png_ptr);
1060 png_set_packing (png_ptr); 1052 break;
1053
1054 case PNG_COLOR_TYPE_GRAY:
1055 case PNG_COLOR_TYPE_GRAY_ALPHA:
1056 /* convert grayscale images to RGB */
1057 png_set_gray_to_rgb (png_ptr);
1058 break;
1059
1060 default:
1061 /* pad images with depth < 8 bits */
1062 if (png_get_bit_depth (png_ptr, info_ptr) < 8)
1063 {
1064 png_set_packing (png_ptr);
1065 }
1066 break;
1061 } 1067 }
1068
1062 /* strip 16-bit depth files down to 8 bits */ 1069 /* strip 16-bit depth files down to 8 bits */
1063 if (info_ptr->bit_depth == 16) 1070 if (png_get_bit_depth (png_ptr, info_ptr) == 16)
1064 png_set_strip_16 (png_ptr); 1071 png_set_strip_16 (png_ptr);
1065 /* strip alpha channel 1072 /* strip alpha channel
1066 #### shouldn't we handle this? 1073 #### shouldn't we handle this?
1067 first call png_read_update_info in case above transformations 1074 first call png_read_update_info in case above transformations
1068 have generated an alpha channel */ 1075 have generated an alpha channel */
1069 png_read_update_info(png_ptr, info_ptr); 1076 png_read_update_info(png_ptr, info_ptr);
1070 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) 1077 if (png_get_color_type (png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA)
1071 png_set_strip_alpha (png_ptr); 1078 png_set_strip_alpha (png_ptr);
1072 1079
1073 png_read_image (png_ptr, row_pointers); 1080 png_read_image (png_ptr, row_pointers);
1074 png_read_end (png_ptr, info_ptr); 1081 png_read_end (png_ptr, info_ptr);
1075 1082
1076 /* #### There should be some way to pass this type of data down 1083 /* #### There should be some way to pass this type of data down
1077 * into the glyph code, where you can get to it from lisp 1084 * into the glyph code, where you can get to it from lisp
1078 * anyway. - WMP */ 1085 * anyway. - WMP */
1079 { 1086 {
1080 int i; 1087 int ii, num_text = 0;
1088 png_textp text_ptr = NULL;
1081 DECLARE_EISTRING (key); 1089 DECLARE_EISTRING (key);
1082 DECLARE_EISTRING (text); 1090 DECLARE_EISTRING (text);
1083 1091
1084 for (i = 0 ; i < info_ptr->num_text ; i++) 1092 if (png_get_text (png_ptr, info_ptr, &text_ptr, &num_text) > 0)
1085 { 1093 {
1086 /* How paranoid do I have to be about no trailing NULLs, and 1094 for (ii = 0 ; ii < num_text; ii++)
1087 using (int)info_ptr->text[i].text_length, and strncpy and a temp 1095 {
1088 string somewhere? */ 1096 eireset (key);
1089 eireset(key); 1097 eireset (text);
1090 eireset(text); 1098
1091 eicpy_ext(key, info_ptr->text[i].key, Qbinary); 1099 eicpy_ext (key, text_ptr[ii].key, Qbinary);
1092 eicpy_ext(text, info_ptr->text[i].text, Qbinary); 1100 eicpy_ext (text, text_ptr[ii].text, Qbinary);
1093 1101
1094 warn_when_safe (Qpng, Qinfo, "%s - %s", 1102 warn_when_safe (Qpng, Qinfo, "%s - %s", eidata (key),
1095 eidata(key), eidata(text)); 1103 eidata (text));
1096 } 1104 }
1105 }
1097 } 1106 }
1098 1107
1099 xfree (row_pointers); 1108 xfree (row_pointers);
1100 } 1109 }
1101 1110