comparison src/xfns.c @ 40264:04766dd416bb

(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.
author Miles Bader <miles@gnu.org>
date Wed, 24 Oct 2001 17:57:28 +0000
parents 2ee3c7f9fb40
children 1adbc1480e83
comparison
equal deleted inserted replaced
40263:3657a6c97b2f 40264:04766dd416bb
5766 ascent = height * img->ascent / 100.0; 5766 ascent = height * img->ascent / 100.0;
5767 5767
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 /***********************************************************************
5774 Helper functions for X image types 5872 Helper functions for X image types
5775 ***********************************************************************/ 5873 ***********************************************************************/
5796 { 5894 {
5797 if (pixmap_p && img->pixmap) 5895 if (pixmap_p && img->pixmap)
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)
5810 { 5910 {
5811 x_free_colors (f, img->colors, img->ncolors); 5911 x_free_colors (f, img->colors, img->ncolors);
6131 ? XFASTINT (value) : DEFAULT_IMAGE_HEIGHT); 6231 ? XFASTINT (value) : DEFAULT_IMAGE_HEIGHT);
6132 } 6232 }
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))
6141 img->ascent = XFASTINT (ascent); 6242 img->ascent = XFASTINT (ascent);
6142 else if (EQ (ascent, Qcenter)) 6243 else if (EQ (ascent, Qcenter))
6158 if (INTEGERP (relief)) 6259 if (INTEGERP (relief))
6159 { 6260 {
6160 img->relief = XINT (relief); 6261 img->relief = XINT (relief);
6161 img->hmargin += abs (img->relief); 6262 img->hmargin += abs (img->relief);
6162 img->vmargin += abs (img->relief); 6263 img->vmargin += abs (img->relief);
6264 }
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 }
6163 } 6276 }
6164 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))
6873 6986
6874 /* Get foreground and background colors, maybe allocate colors. */ 6987 /* Get foreground and background colors, maybe allocate colors. */
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),
6885 FRAME_X_WINDOW (f), 7001 FRAME_X_WINDOW (f),
6886 data, 7002 data,
7079 XPM_RELIEF, 7195 XPM_RELIEF,
7080 XPM_ALGORITHM, 7196 XPM_ALGORITHM,
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
7087 /* Vector of image_keyword structures describing the format 7204 /* Vector of image_keyword structures describing the format
7088 of valid XPM image specifications. */ 7205 of valid XPM image specifications. */
7096 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 7213 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0},
7097 {":relief", IMAGE_INTEGER_VALUE, 0}, 7214 {":relief", IMAGE_INTEGER_VALUE, 0},
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. */
7105 7223
7106 static struct image_type xpm_type = 7224 static struct image_type xpm_type =
8039 struct image *img; 8157 struct image *img;
8040 Lisp_Object how; 8158 Lisp_Object 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. */
8054 rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1, 8173 rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1,
8055 &mask_img, &img->mask); 8174 &mask_img, &img->mask);
8059 /* Get the X image of IMG->pixmap. */ 8178 /* Get the X image of IMG->pixmap. */
8060 ximg = XGetImage (dpy, img->pixmap, 0, 0, img->width, img->height, 8179 ximg = XGetImage (dpy, img->pixmap, 0, 0, img->width, img->height,
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 {
8070 int rgb[3], i = 0; 8188 int rgb[3], i = 0;
8071 8189
8087 8205
8088 cmap = FRAME_X_COLORMAP (f); 8206 cmap = FRAME_X_COLORMAP (f);
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. */
8124 for (y = 0; y < img->height; ++y) 8220 for (y = 0; y < img->height; ++y)
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);
8223
8224 /* Fill in the background_transparent field while we have the mask handy. */
8225 image_background_transparent (img, f, mask_img);
8127 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);
8131 XDestroyImage (ximg); 8230 XDestroyImage (ximg);
8381 if (fmt[PBM_FOREGROUND].count 8480 if (fmt[PBM_FOREGROUND].count
8382 && STRINGP (fmt[PBM_FOREGROUND].value)) 8481 && STRINGP (fmt[PBM_FOREGROUND].value))
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)
8390 { 8493 {
8391 if (raw_p) 8494 if (raw_p)
8444 8547
8445 /* Store in IMG->colors the colors allocated for the image, and 8548 /* Store in IMG->colors the colors allocated for the image, and
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);
8452 x_destroy_x_image (ximg); 8559 x_destroy_x_image (ximg);
8453 8560
8489 PNG_MARGIN, 8596 PNG_MARGIN,
8490 PNG_RELIEF, 8597 PNG_RELIEF,
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
8497 /* Vector of image_keyword structures describing the format 8605 /* Vector of image_keyword structures describing the format
8498 of valid user-defined image specifications. */ 8606 of valid user-defined image specifications. */
8506 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 8614 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0},
8507 {":relief", IMAGE_INTEGER_VALUE, 0}, 8615 {":relief", IMAGE_INTEGER_VALUE, 0},
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'. */
8514 8623
8515 static struct image_type png_type = 8624 static struct image_type png_type =
8776 /* Handle alpha channel by combining the image with a background 8885 /* Handle alpha channel by combining the image with a background
8777 color. Do this only if a real alpha channel is supplied. For 8886 color. Do this only if a real alpha channel is supplied. For
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;
8782 8891 Lisp_Object specified_bg
8783 if (png_get_bKGD (png_ptr, info_ptr, &image_background)) 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;
8906
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 {
8790 /* Image does not contain a background color with which 8918 /* Image does not contain a background color with which
8791 to combine the image data via an alpha channel. Use 8919 to combine the image data via an alpha channel. Use
8894 ++p; 9022 ++p;
8895 } 9023 }
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 ();
8902 9042
8903 /* Clean up. */ 9043 /* Clean up. */
8906 xfree (pixels); 9046 xfree (pixels);
8907 9047
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);
8914 9057
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 }
8921 9068
8922 UNGCPRO; 9069 UNGCPRO;
8966 JPEG_MARGIN, 9113 JPEG_MARGIN,
8967 JPEG_RELIEF, 9114 JPEG_RELIEF,
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
8974 /* Vector of image_keyword structures describing the format 9122 /* Vector of image_keyword structures describing the format
8975 of valid user-defined image specifications. */ 9123 of valid user-defined image specifications. */
8982 {":ascent", IMAGE_ASCENT_VALUE, 0}, 9130 {":ascent", IMAGE_ASCENT_VALUE, 0},
8983 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 9131 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0},
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'. */
8991 9140
8992 static struct image_type jpeg_type = 9141 static struct image_type jpeg_type =
9281 /* Clean up. */ 9430 /* Clean up. */
9282 jpeg_finish_decompress (&cinfo); 9431 jpeg_finish_decompress (&cinfo);
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);
9289 x_destroy_x_image (ximg); 9442 x_destroy_x_image (ximg);
9290 UNGCPRO; 9443 UNGCPRO;
9321 TIFF_MARGIN, 9474 TIFF_MARGIN,
9322 TIFF_RELIEF, 9475 TIFF_RELIEF,
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
9329 /* Vector of image_keyword structures describing the format 9483 /* Vector of image_keyword structures describing the format
9330 of valid user-defined image specifications. */ 9484 of valid user-defined image specifications. */
9337 {":ascent", IMAGE_ASCENT_VALUE, 0}, 9491 {":ascent", IMAGE_ASCENT_VALUE, 0},
9338 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 9492 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0},
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'. */
9346 9501
9347 static struct image_type tiff_type = 9502 static struct image_type tiff_type =
9629 } 9784 }
9630 9785
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;
9645 } 9804 }
9646 9805
9675 GIF_RELIEF, 9834 GIF_RELIEF,
9676 GIF_ALGORITHM, 9835 GIF_ALGORITHM,
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
9683 /* Vector of image_keyword structures describing the format 9843 /* Vector of image_keyword structures describing the format
9684 of valid user-defined image specifications. */ 9844 of valid user-defined image specifications. */
9693 {":relief", IMAGE_INTEGER_VALUE, 0}, 9853 {":relief", IMAGE_INTEGER_VALUE, 0},
9694 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 9854 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
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'. */
9701 9862
9702 static struct image_type gif_type = 9863 static struct image_type gif_type =
9940 XPutPixel (ximg, x + image_left, y + image_top, pixel_colors[i]); 10101 XPutPixel (ximg, x + image_left, y + image_top, pixel_colors[i]);
9941 } 10102 }
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);
9948 x_destroy_x_image (ximg); 10113 x_destroy_x_image (ximg);
9949 10114
9985 GS_MARGIN, 10150 GS_MARGIN,
9986 GS_RELIEF, 10151 GS_RELIEF,
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
9993 /* Vector of image_keyword structures describing the format 10159 /* Vector of image_keyword structures describing the format
9994 of valid user-defined image specifications. */ 10160 of valid user-defined image specifications. */
10004 {":ascent", IMAGE_ASCENT_VALUE, 0}, 10170 {":ascent", IMAGE_ASCENT_VALUE, 0},
10005 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 10171 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0},
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'. */
10013 10180
10014 static struct image_type gs_type = 10181 static struct image_type gs_type =