diff options
| author | Miles Bader | 2001-10-24 17:57:28 +0000 |
|---|---|---|
| committer | Miles Bader | 2001-10-24 17:57:28 +0000 |
| commit | f20a3b7a24410563b30a4e146ff74efe61a451c4 (patch) | |
| tree | a862fdf10644c999210f42bb3a4d306873727226 /src | |
| parent | 0ff7c0d413d922c3ae7db173ac1a658bde2a4252 (diff) | |
| download | emacs-f20a3b7a24410563b30a4e146ff74efe61a451c4.tar.gz emacs-f20a3b7a24410563b30a4e146ff74efe61a451c4.zip | |
(image_background, image_background_transparent)
(four_corners_best): New functions.
(xpm_format, png_format, jpeg_format, tiff_format, gif_format)
(gs_format): Add `:background' entry.
(lookup_image): Set IMG's background color if specified.
(pbm_load, xbm_load_image, png_load): Set IMG's background field
when appropriate.
(x_clear_image_1): Reset `background_valid' and
`background_transparent_valid' fields.
(x_build_heuristic_mask): Use IMAGE_BACKGROUND instead of
calculating it here. Set IMG's background_transparent field.
(enum xpm_keyword_index): Add XPM_BACKGROUND.
(enum png_keyword_index): Add PNG_BACKGROUND.
(enum jpeg_keyword_index): Add JPEG_BACKGROUND.
(enum tiff_keyword_index): Add TIFF_BACKGROUND.
(enum gif_keyword_index): Add GIF_BACKGROUND.
(enum gs_keyword_index): Add GS_BACKGROUND.
(pbm_load, png_load, jpeg_load, tiff_load, gif_load):
Pre-calculate image background color where necessary.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfns.c | 255 |
1 files changed, 211 insertions, 44 deletions
diff --git a/src/xfns.c b/src/xfns.c index e5256ec3497..ebe63d1edd9 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -5768,6 +5768,104 @@ image_ascent (img, face) | |||
| 5768 | return ascent; | 5768 | return ascent; |
| 5769 | } | 5769 | } |
| 5770 | 5770 | ||
| 5771 | |||
| 5772 | /* Image background colors. */ | ||
| 5773 | |||
| 5774 | static unsigned long | ||
| 5775 | four_corners_best (ximg, width, height) | ||
| 5776 | XImage *ximg; | ||
| 5777 | unsigned long width, height; | ||
| 5778 | { | ||
| 5779 | unsigned long corners[4], best; | ||
| 5780 | int i, best_count; | ||
| 5781 | |||
| 5782 | /* Get the colors at the corners of ximg. */ | ||
| 5783 | corners[0] = XGetPixel (ximg, 0, 0); | ||
| 5784 | corners[1] = XGetPixel (ximg, width - 1, 0); | ||
| 5785 | corners[2] = XGetPixel (ximg, width - 1, height - 1); | ||
| 5786 | corners[3] = XGetPixel (ximg, 0, height - 1); | ||
| 5787 | |||
| 5788 | /* Choose the most frequently found color as background. */ | ||
| 5789 | for (i = best_count = 0; i < 4; ++i) | ||
| 5790 | { | ||
| 5791 | int j, n; | ||
| 5792 | |||
| 5793 | for (j = n = 0; j < 4; ++j) | ||
| 5794 | if (corners[i] == corners[j]) | ||
| 5795 | ++n; | ||
| 5796 | |||
| 5797 | if (n > best_count) | ||
| 5798 | best = corners[i], best_count = n; | ||
| 5799 | } | ||
| 5800 | |||
| 5801 | return best; | ||
| 5802 | } | ||
| 5803 | |||
| 5804 | /* Return the `background' field of IMG. If IMG doesn't have one yet, | ||
| 5805 | it is guessed heuristically. If non-zero, XIMG is an existing XImage | ||
| 5806 | object to use for the heuristic. */ | ||
| 5807 | |||
| 5808 | unsigned long | ||
| 5809 | image_background (img, f, ximg) | ||
| 5810 | struct image *img; | ||
| 5811 | struct frame *f; | ||
| 5812 | XImage *ximg; | ||
| 5813 | { | ||
| 5814 | if (! img->background_valid) | ||
| 5815 | /* IMG doesn't have a background yet, try to guess a reasonable value. */ | ||
| 5816 | { | ||
| 5817 | int free_ximg = !ximg; | ||
| 5818 | |||
| 5819 | if (! ximg) | ||
| 5820 | ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, | ||
| 5821 | 0, 0, img->width, img->height, ~0, ZPixmap); | ||
| 5822 | |||
| 5823 | img->background = four_corners_best (ximg, img->width, img->height); | ||
| 5824 | |||
| 5825 | if (free_ximg) | ||
| 5826 | XDestroyImage (ximg); | ||
| 5827 | |||
| 5828 | img->background_valid = 1; | ||
| 5829 | } | ||
| 5830 | |||
| 5831 | return img->background; | ||
| 5832 | } | ||
| 5833 | |||
| 5834 | /* Return the `background_transparent' field of IMG. If IMG doesn't | ||
| 5835 | have one yet, it is guessed heuristically. If non-zero, MASK is an | ||
| 5836 | existing XImage object to use for the heuristic. */ | ||
| 5837 | |||
| 5838 | int | ||
| 5839 | image_background_transparent (img, f, mask) | ||
| 5840 | struct image *img; | ||
| 5841 | struct frame *f; | ||
| 5842 | XImage *mask; | ||
| 5843 | { | ||
| 5844 | if (! img->background_transparent_valid) | ||
| 5845 | /* IMG doesn't have a background yet, try to guess a reasonable value. */ | ||
| 5846 | { | ||
| 5847 | if (img->mask) | ||
| 5848 | { | ||
| 5849 | int free_mask = !mask; | ||
| 5850 | |||
| 5851 | if (! mask) | ||
| 5852 | mask = XGetImage (FRAME_X_DISPLAY (f), img->mask, | ||
| 5853 | 0, 0, img->width, img->height, ~0, ZPixmap); | ||
| 5854 | |||
| 5855 | img->background_transparent | ||
| 5856 | = !four_corners_best (mask, img->width, img->height); | ||
| 5857 | |||
| 5858 | if (free_mask) | ||
| 5859 | XDestroyImage (mask); | ||
| 5860 | } | ||
| 5861 | else | ||
| 5862 | img->background_transparent = 0; | ||
| 5863 | |||
| 5864 | img->background_transparent_valid = 1; | ||
| 5865 | } | ||
| 5866 | |||
| 5867 | return img->background_transparent; | ||
| 5868 | } | ||
| 5771 | 5869 | ||
| 5772 | 5870 | ||
| 5773 | /*********************************************************************** | 5871 | /*********************************************************************** |
| @@ -5798,12 +5896,14 @@ x_clear_image_1 (f, img, pixmap_p, mask_p, colors_p) | |||
| 5798 | { | 5896 | { |
| 5799 | XFreePixmap (FRAME_X_DISPLAY (f), img->pixmap); | 5897 | XFreePixmap (FRAME_X_DISPLAY (f), img->pixmap); |
| 5800 | img->pixmap = None; | 5898 | img->pixmap = None; |
| 5899 | img->background_valid = 0; | ||
| 5801 | } | 5900 | } |
| 5802 | 5901 | ||
| 5803 | if (mask_p && img->mask) | 5902 | if (mask_p && img->mask) |
| 5804 | { | 5903 | { |
| 5805 | XFreePixmap (FRAME_X_DISPLAY (f), img->mask); | 5904 | XFreePixmap (FRAME_X_DISPLAY (f), img->mask); |
| 5806 | img->mask = None; | 5905 | img->mask = None; |
| 5906 | img->background_transparent_valid = 0; | ||
| 5807 | } | 5907 | } |
| 5808 | 5908 | ||
| 5809 | if (colors_p && img->ncolors) | 5909 | if (colors_p && img->ncolors) |
| @@ -6133,8 +6233,9 @@ lookup_image (f, spec) | |||
| 6133 | else | 6233 | else |
| 6134 | { | 6234 | { |
| 6135 | /* Handle image type independent image attributes | 6235 | /* Handle image type independent image attributes |
| 6136 | `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF'. */ | 6236 | `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF', |
| 6137 | Lisp_Object ascent, margin, relief; | 6237 | `:background COLOR'. */ |
| 6238 | Lisp_Object ascent, margin, relief, bg; | ||
| 6138 | 6239 | ||
| 6139 | ascent = image_spec_value (spec, QCascent, NULL); | 6240 | ascent = image_spec_value (spec, QCascent, NULL); |
| 6140 | if (INTEGERP (ascent)) | 6241 | if (INTEGERP (ascent)) |
| @@ -6162,6 +6263,18 @@ lookup_image (f, spec) | |||
| 6162 | img->vmargin += abs (img->relief); | 6263 | img->vmargin += abs (img->relief); |
| 6163 | } | 6264 | } |
| 6164 | 6265 | ||
| 6266 | if (! img->background_valid) | ||
| 6267 | { | ||
| 6268 | bg = image_spec_value (img->spec, QCbackground, NULL); | ||
| 6269 | if (!NILP (bg)) | ||
| 6270 | { | ||
| 6271 | img->background | ||
| 6272 | = x_alloc_image_color (f, img, bg, | ||
| 6273 | FRAME_BACKGROUND_PIXEL (f)); | ||
| 6274 | img->background_valid = 1; | ||
| 6275 | } | ||
| 6276 | } | ||
| 6277 | |||
| 6165 | /* Do image transformations and compute masks, unless we | 6278 | /* Do image transformations and compute masks, unless we |
| 6166 | don't have the image yet. */ | 6279 | don't have the image yet. */ |
| 6167 | if (!EQ (*img->type->type, Qpostscript)) | 6280 | if (!EQ (*img->type->type, Qpostscript)) |
| @@ -6875,10 +6988,13 @@ xbm_load_image (f, img, contents, end) | |||
| 6875 | value = image_spec_value (img->spec, QCforeground, NULL); | 6988 | value = image_spec_value (img->spec, QCforeground, NULL); |
| 6876 | if (!NILP (value)) | 6989 | if (!NILP (value)) |
| 6877 | foreground = x_alloc_image_color (f, img, value, foreground); | 6990 | foreground = x_alloc_image_color (f, img, value, foreground); |
| 6878 | |||
| 6879 | value = image_spec_value (img->spec, QCbackground, NULL); | 6991 | value = image_spec_value (img->spec, QCbackground, NULL); |
| 6880 | if (!NILP (value)) | 6992 | if (!NILP (value)) |
| 6881 | background = x_alloc_image_color (f, img, value, background); | 6993 | { |
| 6994 | background = x_alloc_image_color (f, img, value, background); | ||
| 6995 | img->background = background; | ||
| 6996 | img->background_valid = 1; | ||
| 6997 | } | ||
| 6882 | 6998 | ||
| 6883 | img->pixmap | 6999 | img->pixmap |
| 6884 | = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), | 7000 | = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), |
| @@ -7081,6 +7197,7 @@ enum xpm_keyword_index | |||
| 7081 | XPM_HEURISTIC_MASK, | 7197 | XPM_HEURISTIC_MASK, |
| 7082 | XPM_MASK, | 7198 | XPM_MASK, |
| 7083 | XPM_COLOR_SYMBOLS, | 7199 | XPM_COLOR_SYMBOLS, |
| 7200 | XPM_BACKGROUND, | ||
| 7084 | XPM_LAST | 7201 | XPM_LAST |
| 7085 | }; | 7202 | }; |
| 7086 | 7203 | ||
| @@ -7098,7 +7215,8 @@ static struct image_keyword xpm_format[XPM_LAST] = | |||
| 7098 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 7215 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 7099 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 7216 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 7100 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 7217 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 7101 | {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE, 0} | 7218 | {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 7219 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} | ||
| 7102 | }; | 7220 | }; |
| 7103 | 7221 | ||
| 7104 | /* Structure describing the image type XBM. */ | 7222 | /* Structure describing the image type XBM. */ |
| @@ -8041,13 +8159,14 @@ x_build_heuristic_mask (f, img, how) | |||
| 8041 | { | 8159 | { |
| 8042 | Display *dpy = FRAME_X_DISPLAY (f); | 8160 | Display *dpy = FRAME_X_DISPLAY (f); |
| 8043 | XImage *ximg, *mask_img; | 8161 | XImage *ximg, *mask_img; |
| 8044 | int x, y, rc, look_at_corners_p; | 8162 | int x, y, rc, use_img_background; |
| 8045 | unsigned long bg = 0; | 8163 | unsigned long bg = 0; |
| 8046 | 8164 | ||
| 8047 | if (img->mask) | 8165 | if (img->mask) |
| 8048 | { | 8166 | { |
| 8049 | XFreePixmap (FRAME_X_DISPLAY (f), img->mask); | 8167 | XFreePixmap (FRAME_X_DISPLAY (f), img->mask); |
| 8050 | img->mask = None; | 8168 | img->mask = None; |
| 8169 | img->background_transparent_valid = 0; | ||
| 8051 | } | 8170 | } |
| 8052 | 8171 | ||
| 8053 | /* Create an image and pixmap serving as mask. */ | 8172 | /* Create an image and pixmap serving as mask. */ |
| @@ -8061,9 +8180,8 @@ x_build_heuristic_mask (f, img, how) | |||
| 8061 | ~0, ZPixmap); | 8180 | ~0, ZPixmap); |
| 8062 | 8181 | ||
| 8063 | /* Determine the background color of ximg. If HOW is `(R G B)' | 8182 | /* Determine the background color of ximg. If HOW is `(R G B)' |
| 8064 | take that as color. Otherwise, try to determine the color | 8183 | take that as color. Otherwise, use the image's background color. */ |
| 8065 | heuristically. */ | 8184 | use_img_background = 1; |
| 8066 | look_at_corners_p = 1; | ||
| 8067 | 8185 | ||
| 8068 | if (CONSP (how)) | 8186 | if (CONSP (how)) |
| 8069 | { | 8187 | { |
| @@ -8089,35 +8207,13 @@ x_build_heuristic_mask (f, img, how) | |||
| 8089 | if (XLookupColor (dpy, cmap, color_name, &exact, &color)) | 8207 | if (XLookupColor (dpy, cmap, color_name, &exact, &color)) |
| 8090 | { | 8208 | { |
| 8091 | bg = color.pixel; | 8209 | bg = color.pixel; |
| 8092 | look_at_corners_p = 0; | 8210 | use_img_background = 0; |
| 8093 | } | 8211 | } |
| 8094 | } | 8212 | } |
| 8095 | } | 8213 | } |
| 8096 | 8214 | ||
| 8097 | if (look_at_corners_p) | 8215 | if (use_img_background) |
| 8098 | { | 8216 | bg = IMAGE_BACKGROUND (img, f, ximg); |
| 8099 | unsigned long corners[4]; | ||
| 8100 | int i, best_count; | ||
| 8101 | |||
| 8102 | /* Get the colors at the corners of ximg. */ | ||
| 8103 | corners[0] = XGetPixel (ximg, 0, 0); | ||
| 8104 | corners[1] = XGetPixel (ximg, img->width - 1, 0); | ||
| 8105 | corners[2] = XGetPixel (ximg, img->width - 1, img->height - 1); | ||
| 8106 | corners[3] = XGetPixel (ximg, 0, img->height - 1); | ||
| 8107 | |||
| 8108 | /* Choose the most frequently found color as background. */ | ||
| 8109 | for (i = best_count = 0; i < 4; ++i) | ||
| 8110 | { | ||
| 8111 | int j, n; | ||
| 8112 | |||
| 8113 | for (j = n = 0; j < 4; ++j) | ||
| 8114 | if (corners[i] == corners[j]) | ||
| 8115 | ++n; | ||
| 8116 | |||
| 8117 | if (n > best_count) | ||
| 8118 | bg = corners[i], best_count = n; | ||
| 8119 | } | ||
| 8120 | } | ||
| 8121 | 8217 | ||
| 8122 | /* Set all bits in mask_img to 1 whose color in ximg is different | 8218 | /* Set all bits in mask_img to 1 whose color in ximg is different |
| 8123 | from the background color bg. */ | 8219 | from the background color bg. */ |
| @@ -8125,6 +8221,9 @@ x_build_heuristic_mask (f, img, how) | |||
| 8125 | for (x = 0; x < img->width; ++x) | 8221 | for (x = 0; x < img->width; ++x) |
| 8126 | XPutPixel (mask_img, x, y, XGetPixel (ximg, x, y) != bg); | 8222 | XPutPixel (mask_img, x, y, XGetPixel (ximg, x, y) != bg); |
| 8127 | 8223 | ||
| 8224 | /* Fill in the background_transparent field while we have the mask handy. */ | ||
| 8225 | image_background_transparent (img, f, mask_img); | ||
| 8226 | |||
| 8128 | /* Put mask_img into img->mask. */ | 8227 | /* Put mask_img into img->mask. */ |
| 8129 | x_put_x_image (f, mask_img, img->mask, img->width, img->height); | 8228 | x_put_x_image (f, mask_img, img->mask, img->width, img->height); |
| 8130 | x_destroy_x_image (mask_img); | 8229 | x_destroy_x_image (mask_img); |
| @@ -8383,7 +8482,11 @@ pbm_load (f, img) | |||
| 8383 | fg = x_alloc_image_color (f, img, fmt[PBM_FOREGROUND].value, fg); | 8482 | fg = x_alloc_image_color (f, img, fmt[PBM_FOREGROUND].value, fg); |
| 8384 | if (fmt[PBM_BACKGROUND].count | 8483 | if (fmt[PBM_BACKGROUND].count |
| 8385 | && STRINGP (fmt[PBM_BACKGROUND].value)) | 8484 | && STRINGP (fmt[PBM_BACKGROUND].value)) |
| 8386 | bg = x_alloc_image_color (f, img, fmt[PBM_BACKGROUND].value, bg); | 8485 | { |
| 8486 | bg = x_alloc_image_color (f, img, fmt[PBM_BACKGROUND].value, bg); | ||
| 8487 | img->background = bg; | ||
| 8488 | img->background_valid = 1; | ||
| 8489 | } | ||
| 8387 | 8490 | ||
| 8388 | for (y = 0; y < height; ++y) | 8491 | for (y = 0; y < height; ++y) |
| 8389 | for (x = 0; x < width; ++x) | 8492 | for (x = 0; x < width; ++x) |
| @@ -8446,6 +8549,10 @@ pbm_load (f, img) | |||
| 8446 | free the color table. */ | 8549 | free the color table. */ |
| 8447 | img->colors = colors_in_color_table (&img->ncolors); | 8550 | img->colors = colors_in_color_table (&img->ncolors); |
| 8448 | free_color_table (); | 8551 | free_color_table (); |
| 8552 | |||
| 8553 | /* Maybe fill in the background field while we have ximg handy. */ | ||
| 8554 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) | ||
| 8555 | IMAGE_BACKGROUND (img, f, ximg); | ||
| 8449 | 8556 | ||
| 8450 | /* Put the image into a pixmap. */ | 8557 | /* Put the image into a pixmap. */ |
| 8451 | x_put_x_image (f, ximg, img->pixmap, width, height); | 8558 | x_put_x_image (f, ximg, img->pixmap, width, height); |
| @@ -8491,6 +8598,7 @@ enum png_keyword_index | |||
| 8491 | PNG_ALGORITHM, | 8598 | PNG_ALGORITHM, |
| 8492 | PNG_HEURISTIC_MASK, | 8599 | PNG_HEURISTIC_MASK, |
| 8493 | PNG_MASK, | 8600 | PNG_MASK, |
| 8601 | PNG_BACKGROUND, | ||
| 8494 | PNG_LAST | 8602 | PNG_LAST |
| 8495 | }; | 8603 | }; |
| 8496 | 8604 | ||
| @@ -8508,6 +8616,7 @@ static struct image_keyword png_format[PNG_LAST] = | |||
| 8508 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 8616 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 8509 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 8617 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 8510 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0} | 8618 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0} |
| 8619 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} | ||
| 8511 | }; | 8620 | }; |
| 8512 | 8621 | ||
| 8513 | /* Structure describing the image type `png'. */ | 8622 | /* Structure describing the image type `png'. */ |
| @@ -8778,12 +8887,31 @@ png_load (f, img) | |||
| 8778 | simple transparency, we prefer a clipping mask. */ | 8887 | simple transparency, we prefer a clipping mask. */ |
| 8779 | if (!transparent_p) | 8888 | if (!transparent_p) |
| 8780 | { | 8889 | { |
| 8781 | png_color_16 *image_background; | 8890 | png_color_16 *image_bg; |
| 8891 | Lisp_Object specified_bg | ||
| 8892 | = image_spec_value (img->spec, QCbackground, NULL); | ||
| 8893 | |||
| 8894 | if (! NILP (specified_bg)) | ||
| 8895 | /* The user specified `:background', use that. */ | ||
| 8896 | { | ||
| 8897 | XColor color; | ||
| 8898 | if (x_defined_color (f, specified_bg, &color, 0)) | ||
| 8899 | { | ||
| 8900 | png_color_16 user_bg; | ||
| 8901 | |||
| 8902 | bzero (&user_bg, sizeof user_bg); | ||
| 8903 | user_bg.red = color.red; | ||
| 8904 | user_bg.green = color.green; | ||
| 8905 | user_bg.blue = color.blue; | ||
| 8782 | 8906 | ||
| 8783 | if (png_get_bKGD (png_ptr, info_ptr, &image_background)) | 8907 | png_set_background (png_ptr, &user_bg, |
| 8908 | PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0); | ||
| 8909 | } | ||
| 8910 | } | ||
| 8911 | else if (png_get_bKGD (png_ptr, info_ptr, &image_bg)) | ||
| 8784 | /* Image contains a background color with which to | 8912 | /* Image contains a background color with which to |
| 8785 | combine the image. */ | 8913 | combine the image. */ |
| 8786 | png_set_background (png_ptr, image_background, | 8914 | png_set_background (png_ptr, image_bg, |
| 8787 | PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); | 8915 | PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); |
| 8788 | else | 8916 | else |
| 8789 | { | 8917 | { |
| @@ -8896,6 +9024,18 @@ png_load (f, img) | |||
| 8896 | } | 9024 | } |
| 8897 | } | 9025 | } |
| 8898 | 9026 | ||
| 9027 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) | ||
| 9028 | /* Set IMG's background color from the PNG image, unless the user | ||
| 9029 | overrode it. */ | ||
| 9030 | { | ||
| 9031 | png_color_16 *bg; | ||
| 9032 | if (png_get_bKGD (png_ptr, info_ptr, &bg)) | ||
| 9033 | { | ||
| 9034 | img->background = lookup_rgb_color (f, bg.red, bg.green, bg.blue); | ||
| 9035 | img->background_valid = 1; | ||
| 9036 | } | ||
| 9037 | } | ||
| 9038 | |||
| 8899 | /* Remember colors allocated for this image. */ | 9039 | /* Remember colors allocated for this image. */ |
| 8900 | img->colors = colors_in_color_table (&img->ncolors); | 9040 | img->colors = colors_in_color_table (&img->ncolors); |
| 8901 | free_color_table (); | 9041 | free_color_table (); |
| @@ -8908,6 +9048,9 @@ png_load (f, img) | |||
| 8908 | img->width = width; | 9048 | img->width = width; |
| 8909 | img->height = height; | 9049 | img->height = height; |
| 8910 | 9050 | ||
| 9051 | /* Maybe fill in the background field while we have ximg handy. */ | ||
| 9052 | IMAGE_BACKGROUND (img, f, ximg); | ||
| 9053 | |||
| 8911 | /* Put the image into the pixmap, then free the X image and its buffer. */ | 9054 | /* Put the image into the pixmap, then free the X image and its buffer. */ |
| 8912 | x_put_x_image (f, ximg, img->pixmap, width, height); | 9055 | x_put_x_image (f, ximg, img->pixmap, width, height); |
| 8913 | x_destroy_x_image (ximg); | 9056 | x_destroy_x_image (ximg); |
| @@ -8915,6 +9058,10 @@ png_load (f, img) | |||
| 8915 | /* Same for the mask. */ | 9058 | /* Same for the mask. */ |
| 8916 | if (mask_img) | 9059 | if (mask_img) |
| 8917 | { | 9060 | { |
| 9061 | /* Fill in the background_transparent field while we have the mask | ||
| 9062 | handy. */ | ||
| 9063 | image_background_transparent (img, f, mask_img); | ||
| 9064 | |||
| 8918 | x_put_x_image (f, mask_img, img->mask, img->width, img->height); | 9065 | x_put_x_image (f, mask_img, img->mask, img->width, img->height); |
| 8919 | x_destroy_x_image (mask_img); | 9066 | x_destroy_x_image (mask_img); |
| 8920 | } | 9067 | } |
| @@ -8968,6 +9115,7 @@ enum jpeg_keyword_index | |||
| 8968 | JPEG_ALGORITHM, | 9115 | JPEG_ALGORITHM, |
| 8969 | JPEG_HEURISTIC_MASK, | 9116 | JPEG_HEURISTIC_MASK, |
| 8970 | JPEG_MASK, | 9117 | JPEG_MASK, |
| 9118 | JPEG_BACKGROUND, | ||
| 8971 | JPEG_LAST | 9119 | JPEG_LAST |
| 8972 | }; | 9120 | }; |
| 8973 | 9121 | ||
| @@ -8984,7 +9132,8 @@ static struct image_keyword jpeg_format[JPEG_LAST] = | |||
| 8984 | {":relief", IMAGE_INTEGER_VALUE, 0}, | 9132 | {":relief", IMAGE_INTEGER_VALUE, 0}, |
| 8985 | {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 9133 | {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 8986 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 9134 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 8987 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0} | 9135 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9136 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} | ||
| 8988 | }; | 9137 | }; |
| 8989 | 9138 | ||
| 8990 | /* Structure describing the image type `jpeg'. */ | 9139 | /* Structure describing the image type `jpeg'. */ |
| @@ -9283,6 +9432,10 @@ jpeg_load (f, img) | |||
| 9283 | jpeg_destroy_decompress (&cinfo); | 9432 | jpeg_destroy_decompress (&cinfo); |
| 9284 | if (fp) | 9433 | if (fp) |
| 9285 | fclose ((FILE *) fp); | 9434 | fclose ((FILE *) fp); |
| 9435 | |||
| 9436 | /* Maybe fill in the background field while we have ximg handy. */ | ||
| 9437 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) | ||
| 9438 | IMAGE_BACKGROUND (img, f, ximg); | ||
| 9286 | 9439 | ||
| 9287 | /* Put the image into the pixmap. */ | 9440 | /* Put the image into the pixmap. */ |
| 9288 | x_put_x_image (f, ximg, img->pixmap, width, height); | 9441 | x_put_x_image (f, ximg, img->pixmap, width, height); |
| @@ -9323,6 +9476,7 @@ enum tiff_keyword_index | |||
| 9323 | TIFF_ALGORITHM, | 9476 | TIFF_ALGORITHM, |
| 9324 | TIFF_HEURISTIC_MASK, | 9477 | TIFF_HEURISTIC_MASK, |
| 9325 | TIFF_MASK, | 9478 | TIFF_MASK, |
| 9479 | TIFF_BACKGROUND, | ||
| 9326 | TIFF_LAST | 9480 | TIFF_LAST |
| 9327 | }; | 9481 | }; |
| 9328 | 9482 | ||
| @@ -9339,7 +9493,8 @@ static struct image_keyword tiff_format[TIFF_LAST] = | |||
| 9339 | {":relief", IMAGE_INTEGER_VALUE, 0}, | 9493 | {":relief", IMAGE_INTEGER_VALUE, 0}, |
| 9340 | {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 9494 | {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9341 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 9495 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9342 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0} | 9496 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9497 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} | ||
| 9343 | }; | 9498 | }; |
| 9344 | 9499 | ||
| 9345 | /* Structure describing the image type `tiff'. */ | 9500 | /* Structure describing the image type `tiff'. */ |
| @@ -9631,14 +9786,18 @@ tiff_load (f, img) | |||
| 9631 | /* Remember the colors allocated for the image. Free the color table. */ | 9786 | /* Remember the colors allocated for the image. Free the color table. */ |
| 9632 | img->colors = colors_in_color_table (&img->ncolors); | 9787 | img->colors = colors_in_color_table (&img->ncolors); |
| 9633 | free_color_table (); | 9788 | free_color_table (); |
| 9789 | |||
| 9790 | img->width = width; | ||
| 9791 | img->height = height; | ||
| 9792 | |||
| 9793 | /* Maybe fill in the background field while we have ximg handy. */ | ||
| 9794 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) | ||
| 9795 | IMAGE_BACKGROUND (img, f, ximg); | ||
| 9634 | 9796 | ||
| 9635 | /* Put the image into the pixmap, then free the X image and its buffer. */ | 9797 | /* Put the image into the pixmap, then free the X image and its buffer. */ |
| 9636 | x_put_x_image (f, ximg, img->pixmap, width, height); | 9798 | x_put_x_image (f, ximg, img->pixmap, width, height); |
| 9637 | x_destroy_x_image (ximg); | 9799 | x_destroy_x_image (ximg); |
| 9638 | xfree (buf); | 9800 | xfree (buf); |
| 9639 | |||
| 9640 | img->width = width; | ||
| 9641 | img->height = height; | ||
| 9642 | 9801 | ||
| 9643 | UNGCPRO; | 9802 | UNGCPRO; |
| 9644 | return 1; | 9803 | return 1; |
| @@ -9677,6 +9836,7 @@ enum gif_keyword_index | |||
| 9677 | GIF_HEURISTIC_MASK, | 9836 | GIF_HEURISTIC_MASK, |
| 9678 | GIF_MASK, | 9837 | GIF_MASK, |
| 9679 | GIF_IMAGE, | 9838 | GIF_IMAGE, |
| 9839 | GIF_BACKGROUND, | ||
| 9680 | GIF_LAST | 9840 | GIF_LAST |
| 9681 | }; | 9841 | }; |
| 9682 | 9842 | ||
| @@ -9695,6 +9855,7 @@ static struct image_keyword gif_format[GIF_LAST] = | |||
| 9695 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 9855 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9696 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 9856 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 9697 | {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0} | 9857 | {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE, 0} |
| 9858 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} | ||
| 9698 | }; | 9859 | }; |
| 9699 | 9860 | ||
| 9700 | /* Structure describing the image type `gif'. */ | 9861 | /* Structure describing the image type `gif'. */ |
| @@ -9942,6 +10103,10 @@ gif_load (f, img) | |||
| 9942 | } | 10103 | } |
| 9943 | 10104 | ||
| 9944 | DGifCloseFile (gif); | 10105 | DGifCloseFile (gif); |
| 10106 | |||
| 10107 | /* Maybe fill in the background field while we have ximg handy. */ | ||
| 10108 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) | ||
| 10109 | IMAGE_BACKGROUND (img, f, ximg); | ||
| 9945 | 10110 | ||
| 9946 | /* Put the image into the pixmap, then free the X image and its buffer. */ | 10111 | /* Put the image into the pixmap, then free the X image and its buffer. */ |
| 9947 | x_put_x_image (f, ximg, img->pixmap, width, height); | 10112 | x_put_x_image (f, ximg, img->pixmap, width, height); |
| @@ -9987,6 +10152,7 @@ enum gs_keyword_index | |||
| 9987 | GS_ALGORITHM, | 10152 | GS_ALGORITHM, |
| 9988 | GS_HEURISTIC_MASK, | 10153 | GS_HEURISTIC_MASK, |
| 9989 | GS_MASK, | 10154 | GS_MASK, |
| 10155 | GS_BACKGROUND, | ||
| 9990 | GS_LAST | 10156 | GS_LAST |
| 9991 | }; | 10157 | }; |
| 9992 | 10158 | ||
| @@ -10006,7 +10172,8 @@ static struct image_keyword gs_format[GS_LAST] = | |||
| 10006 | {":relief", IMAGE_INTEGER_VALUE, 0}, | 10172 | {":relief", IMAGE_INTEGER_VALUE, 0}, |
| 10007 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 10173 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 10008 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 10174 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 10009 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0} | 10175 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 10176 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} | ||
| 10010 | }; | 10177 | }; |
| 10011 | 10178 | ||
| 10012 | /* Structure describing the image type `ghostscript'. */ | 10179 | /* Structure describing the image type `ghostscript'. */ |