aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorAlexander Gramiak2019-05-10 17:12:39 -0600
committerAlexander Gramiak2019-05-19 19:50:33 -0600
commitb2b1ccb86df85705fe88360da27f237b1197575b (patch)
tree12a5fccf501e640fbafa92f15be39a5d63efbf18 /src/image.c
parenta4fe9c70af7a60117480d3361541550341da801a (diff)
downloademacs-b2b1ccb86df85705fe88360da27f237b1197575b.tar.gz
emacs-b2b1ccb86df85705fe88360da27f237b1197575b.zip
Introduce Emacs_Pix_Container and Emacs_Pix_Context typedefs
Emacs_Pix_Container is a pointer to a struct representing pixmap data on the backend. Emacs_Pix_Context is the context for the bitmap/pixmap on the backend. Only w32 currently makes this distinction; they are otherwise the same type. * src/dispextern.h: Remove XImagePtr in favor of using XImage* directly. Rename XImagePtr_or_DC to Emacs_Pix_Context. [HAVE_X_WINDOWS] Alias Emacs_Pix_Container and Emacs_Pix_Context to XImage*. [HAVE_NS] Alias Emacs_Pix_Container and Emacs_Pix_Context to trivial Emacs_Pixmap definition. [HAVE_NTGUI]: Alias Emacs_Pix_Container to XImage* and Emacs_Pix_Context to HDC. * src/dispextern.h: * src/image.c: Use Emacs_Pix_Container over XImagePtr and Emacs_Pix_Context over XImagePtr_or_DC.
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c253
1 files changed, 129 insertions, 124 deletions
diff --git a/src/image.c b/src/image.c
index 8e57444bb04..35ca3e2d66d 100644
--- a/src/image.c
+++ b/src/image.c
@@ -132,17 +132,17 @@ static unsigned long *colors_in_color_table (int *n);
132#ifdef HAVE_NS 132#ifdef HAVE_NS
133/* Use with images created by ns_image_for_XPM. */ 133/* Use with images created by ns_image_for_XPM. */
134static unsigned long 134static unsigned long
135XGetPixel (XImagePtr ximage, int x, int y) 135XGetPixel (Emacs_Pix_Container image, int x, int y)
136{ 136{
137 return ns_get_pixel (ximage, x, y); 137 return ns_get_pixel (image, x, y);
138} 138}
139 139
140/* Use with images created by ns_image_for_XPM; alpha set to 1; 140/* Use with images created by ns_image_for_XPM; alpha set to 1;
141 pixel is assumed to be in RGB form. */ 141 pixel is assumed to be in RGB form. */
142static void 142static void
143XPutPixel (XImagePtr ximage, int x, int y, unsigned long pixel) 143XPutPixel (Emacs_Pix_Container image, int x, int y, unsigned long pixel)
144{ 144{
145 ns_put_pixel (ximage, x, y, pixel); 145 ns_put_pixel (image, x, y, pixel);
146} 146}
147#endif /* HAVE_NS */ 147#endif /* HAVE_NS */
148 148
@@ -412,18 +412,19 @@ typedef void Picture;
412#endif 412#endif
413 413
414static bool image_create_x_image_and_pixmap_1 (struct frame *, int, int, int, 414static bool image_create_x_image_and_pixmap_1 (struct frame *, int, int, int,
415 XImagePtr *, Emacs_Pixmap *, 415 Emacs_Pix_Container *,
416 Picture *); 416 Emacs_Pixmap *, Picture *);
417static void image_destroy_x_image (XImagePtr ximg); 417static void image_destroy_x_image (Emacs_Pix_Container);
418 418
419#ifdef HAVE_NTGUI 419#ifdef HAVE_NTGUI
420static XImagePtr_or_DC image_get_x_image_or_dc (struct frame *, struct image *, 420static HDC image_get_x_image_or_dc (struct frame *, struct image *,
421 bool, HGDIOBJ *); 421 bool, HGDIOBJ *);
422static void image_unget_x_image_or_dc (struct image *, bool, XImagePtr_or_DC, 422static void image_unget_x_image_or_dc (struct image *, bool,
423 HGDIOBJ); 423 HDC, HGDIOBJ);
424#else 424#else
425static XImagePtr image_get_x_image (struct frame *, struct image *, bool); 425static Emacs_Pix_Container image_get_x_image (struct frame *, struct image *,
426static void image_unget_x_image (struct image *, bool, XImagePtr); 426 bool);
427static void image_unget_x_image (struct image *, bool, Emacs_Pix_Container);
427#define image_get_x_image_or_dc(f, img, mask_p, dummy) \ 428#define image_get_x_image_or_dc(f, img, mask_p, dummy) \
428 image_get_x_image (f, img, mask_p) 429 image_get_x_image (f, img, mask_p)
429#define image_unget_x_image_or_dc(img, mask_p, ximg, dummy) \ 430#define image_unget_x_image_or_dc(img, mask_p, ximg, dummy) \
@@ -437,7 +438,7 @@ static void image_sync_to_pixmaps (struct frame *, struct image *);
437/* Useful functions defined in the section 438/* Useful functions defined in the section
438 `Image type independent image structures' below. */ 439 `Image type independent image structures' below. */
439 440
440static unsigned long four_corners_best (XImagePtr ximg, 441static unsigned long four_corners_best (XImage *ximg,
441 int *corners, 442 int *corners,
442 unsigned long width, 443 unsigned long width,
443 unsigned long height); 444 unsigned long height);
@@ -450,7 +451,7 @@ void
450x_create_bitmap_mask (struct frame *f, ptrdiff_t id) 451x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
451{ 452{
452 Pixmap pixmap, mask; 453 Pixmap pixmap, mask;
453 XImagePtr ximg, mask_img; 454 XImage *ximg, *mask_img;
454 unsigned long width, height; 455 unsigned long width, height;
455 bool result; 456 bool result;
456 unsigned long bg; 457 unsigned long bg;
@@ -1122,10 +1123,10 @@ set_cairo_image_surface (struct image *img, cairo_surface_t *surface)
1122/* Image background colors. */ 1123/* Image background colors. */
1123 1124
1124/* Find the "best" corner color of a bitmap. 1125/* Find the "best" corner color of a bitmap.
1125 On W32, XIMG is assumed to a device context with the bitmap selected. */ 1126 On W32, PIMG is assumed to a device context with the bitmap selected. */
1126 1127
1127static RGB_PIXEL_COLOR 1128static RGB_PIXEL_COLOR
1128four_corners_best (XImagePtr_or_DC ximg, int *corners, 1129four_corners_best (Emacs_Pix_Context pimg, int *corners,
1129 unsigned long width, unsigned long height) 1130 unsigned long width, unsigned long height)
1130{ 1131{
1131 RGB_PIXEL_COLOR corner_pixels[4]; 1132 RGB_PIXEL_COLOR corner_pixels[4];
@@ -1134,19 +1135,19 @@ four_corners_best (XImagePtr_or_DC ximg, int *corners,
1134 1135
1135 if (corners && corners[BOT_CORNER] >= 0) 1136 if (corners && corners[BOT_CORNER] >= 0)
1136 { 1137 {
1137 /* Get the colors at the corner_pixels of ximg. */ 1138 /* Get the colors at the corner_pixels of pimg. */
1138 corner_pixels[0] = GET_PIXEL (ximg, corners[LEFT_CORNER], corners[TOP_CORNER]); 1139 corner_pixels[0] = GET_PIXEL (pimg, corners[LEFT_CORNER], corners[TOP_CORNER]);
1139 corner_pixels[1] = GET_PIXEL (ximg, corners[RIGHT_CORNER] - 1, corners[TOP_CORNER]); 1140 corner_pixels[1] = GET_PIXEL (pimg, corners[RIGHT_CORNER] - 1, corners[TOP_CORNER]);
1140 corner_pixels[2] = GET_PIXEL (ximg, corners[RIGHT_CORNER] - 1, corners[BOT_CORNER] - 1); 1141 corner_pixels[2] = GET_PIXEL (pimg, corners[RIGHT_CORNER] - 1, corners[BOT_CORNER] - 1);
1141 corner_pixels[3] = GET_PIXEL (ximg, corners[LEFT_CORNER], corners[BOT_CORNER] - 1); 1142 corner_pixels[3] = GET_PIXEL (pimg, corners[LEFT_CORNER], corners[BOT_CORNER] - 1);
1142 } 1143 }
1143 else 1144 else
1144 { 1145 {
1145 /* Get the colors at the corner_pixels of ximg. */ 1146 /* Get the colors at the corner_pixels of pimg. */
1146 corner_pixels[0] = GET_PIXEL (ximg, 0, 0); 1147 corner_pixels[0] = GET_PIXEL (pimg, 0, 0);
1147 corner_pixels[1] = GET_PIXEL (ximg, width - 1, 0); 1148 corner_pixels[1] = GET_PIXEL (pimg, width - 1, 0);
1148 corner_pixels[2] = GET_PIXEL (ximg, width - 1, height - 1); 1149 corner_pixels[2] = GET_PIXEL (pimg, width - 1, height - 1);
1149 corner_pixels[3] = GET_PIXEL (ximg, 0, height - 1); 1150 corner_pixels[3] = GET_PIXEL (pimg, 0, height - 1);
1150 } 1151 }
1151 /* Choose the most frequently found color as background. */ 1152 /* Choose the most frequently found color as background. */
1152 for (i = best_count = 0; i < 4; ++i) 1153 for (i = best_count = 0; i < 4; ++i)
@@ -1166,27 +1167,27 @@ four_corners_best (XImagePtr_or_DC ximg, int *corners,
1166 1167
1167/* Return the `background' field of IMG. If IMG doesn't have one yet, 1168/* Return the `background' field of IMG. If IMG doesn't have one yet,
1168 it is guessed heuristically. If non-zero, XIMG is an existing 1169 it is guessed heuristically. If non-zero, XIMG is an existing
1169 XImage object (or device context with the image selected on W32) to 1170 Emacs_Pix_Context object (device context with the image selected on
1170 use for the heuristic. */ 1171 W32) to use for the heuristic. */
1171 1172
1172RGB_PIXEL_COLOR 1173RGB_PIXEL_COLOR
1173image_background (struct image *img, struct frame *f, XImagePtr_or_DC ximg) 1174image_background (struct image *img, struct frame *f, Emacs_Pix_Context pimg)
1174{ 1175{
1175 if (! img->background_valid) 1176 if (! img->background_valid)
1176 /* IMG doesn't have a background yet, try to guess a reasonable value. */ 1177 /* IMG doesn't have a background yet, try to guess a reasonable value. */
1177 { 1178 {
1178 bool free_ximg = !ximg; 1179 bool free_pimg = !pimg;
1179#ifdef HAVE_NTGUI 1180#ifdef HAVE_NTGUI
1180 HGDIOBJ prev; 1181 HGDIOBJ prev;
1181#endif /* HAVE_NTGUI */ 1182#endif /* HAVE_NTGUI */
1182 1183
1183 if (free_ximg) 1184 if (free_pimg)
1184 ximg = image_get_x_image_or_dc (f, img, 0, &prev); 1185 pimg = image_get_x_image_or_dc (f, img, 0, &prev);
1185 1186
1186 img->background = four_corners_best (ximg, img->corners, img->width, img->height); 1187 img->background = four_corners_best (pimg, img->corners, img->width, img->height);
1187 1188
1188 if (free_ximg) 1189 if (free_pimg)
1189 image_unget_x_image_or_dc (img, 0, ximg, prev); 1190 image_unget_x_image_or_dc (img, 0, pimg, prev);
1190 1191
1191 img->background_valid = 1; 1192 img->background_valid = 1;
1192 } 1193 }
@@ -1196,10 +1197,12 @@ image_background (struct image *img, struct frame *f, XImagePtr_or_DC ximg)
1196 1197
1197/* Return the `background_transparent' field of IMG. If IMG doesn't 1198/* Return the `background_transparent' field of IMG. If IMG doesn't
1198 have one yet, it is guessed heuristically. If non-zero, MASK is an 1199 have one yet, it is guessed heuristically. If non-zero, MASK is an
1199 existing XImage object to use for the heuristic. */ 1200 existing Emacs_Pix_Context (XImage* on X) object to use for the
1201 heuristic. */
1200 1202
1201int 1203int
1202image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_DC mask) 1204image_background_transparent (struct image *img, struct frame *f,
1205 Emacs_Pix_Context mask)
1203{ 1206{
1204 if (! img->background_transparent_valid) 1207 if (! img->background_transparent_valid)
1205 /* IMG doesn't have a background yet, try to guess a reasonable value. */ 1208 /* IMG doesn't have a background yet, try to guess a reasonable value. */
@@ -2002,7 +2005,7 @@ mark_image_cache (struct image_cache *c)
2002 WIDTH and HEIGHT must both be positive. 2005 WIDTH and HEIGHT must both be positive.
2003 If XIMG is null, assume it is a bitmap. */ 2006 If XIMG is null, assume it is a bitmap. */
2004static bool 2007static bool
2005image_check_image_size (XImagePtr ximg, int width, int height) 2008image_check_image_size (Emacs_Pix_Container ximg, int width, int height)
2006{ 2009{
2007#ifdef HAVE_X_WINDOWS 2010#ifdef HAVE_X_WINDOWS
2008 /* Respect Xlib's limits: it cannot deal with images that have more 2011 /* Respect Xlib's limits: it cannot deal with images that have more
@@ -2036,19 +2039,20 @@ image_check_image_size (XImagePtr ximg, int width, int height)
2036#endif 2039#endif
2037} 2040}
2038 2041
2039/* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on 2042/* Create an Emacs_Pix_Container and a pixmap of size WIDTH x
2040 frame F. Set *XIMG and *PIXMAP to the XImage and Emacs_Pixmap 2043 HEIGHT for use on frame F. Set *PIMG and *PIXMAP to the
2041 created. Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels 2044 Emacs_Pix_Container and Emacs_Pixmap created. Set (*PIMG)->data
2042 allocated via xmalloc. Print error messages via image_error if an 2045 to a raster of WIDTH x HEIGHT pixels allocated via xmalloc. Print
2043 error occurs. Value is true if successful. 2046 error messages via image_error if an error occurs. Value is true
2047 if successful.
2044 2048
2045 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH 2049 On W32, a DEPTH of zero signifies a 24 bit image, otherwise DEPTH
2046 should indicate the bit depth of the image. */ 2050 should indicate the bit depth of the image. */
2047 2051
2048static bool 2052static bool
2049image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int depth, 2053image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int depth,
2050 XImagePtr *ximg, Emacs_Pixmap *pixmap, 2054 Emacs_Pix_Container *pimg,
2051 Picture *picture) 2055 Emacs_Pixmap *pixmap, Picture *picture)
2052{ 2056{
2053#ifdef HAVE_X_WINDOWS 2057#ifdef HAVE_X_WINDOWS
2054 Display *display = FRAME_X_DISPLAY (f); 2058 Display *display = FRAME_X_DISPLAY (f);
@@ -2059,33 +2063,33 @@ image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int d
2059 2063
2060 if (depth <= 0) 2064 if (depth <= 0)
2061 depth = DefaultDepthOfScreen (screen); 2065 depth = DefaultDepthOfScreen (screen);
2062 *ximg = XCreateImage (display, DefaultVisualOfScreen (screen), 2066 *pimg = XCreateImage (display, DefaultVisualOfScreen (screen),
2063 depth, ZPixmap, 0, NULL, width, height, 2067 depth, ZPixmap, 0, NULL, width, height,
2064 depth > 16 ? 32 : depth > 8 ? 16 : 8, 0); 2068 depth > 16 ? 32 : depth > 8 ? 16 : 8, 0);
2065 if (*ximg == NULL) 2069 if (*pimg == NULL)
2066 { 2070 {
2067 image_error ("Unable to allocate X image"); 2071 image_error ("Unable to allocate X image");
2068 return 0; 2072 return 0;
2069 } 2073 }
2070 2074
2071 if (! image_check_image_size (*ximg, width, height)) 2075 if (! image_check_image_size (*pimg, width, height))
2072 { 2076 {
2073 image_destroy_x_image (*ximg); 2077 image_destroy_x_image (*pimg);
2074 *ximg = NULL; 2078 *pimg = NULL;
2075 image_error ("Image too large (%dx%d)", 2079 image_error ("Image too large (%dx%d)",
2076 make_fixnum (width), make_fixnum (height)); 2080 make_fixnum (width), make_fixnum (height));
2077 return 0; 2081 return 0;
2078 } 2082 }
2079 2083
2080 /* Allocate image raster. */ 2084 /* Allocate image raster. */
2081 (*ximg)->data = xmalloc ((*ximg)->bytes_per_line * height); 2085 (*pimg)->data = xmalloc ((*pimg)->bytes_per_line * height);
2082 2086
2083 /* Allocate a pixmap of the same size. */ 2087 /* Allocate a pixmap of the same size. */
2084 *pixmap = XCreatePixmap (display, drawable, width, height, depth); 2088 *pixmap = XCreatePixmap (display, drawable, width, height, depth);
2085 if (*pixmap == NO_PIXMAP) 2089 if (*pixmap == NO_PIXMAP)
2086 { 2090 {
2087 image_destroy_x_image (*ximg); 2091 image_destroy_x_image (*pimg);
2088 *ximg = NULL; 2092 *pimg = NULL;
2089 image_error ("Unable to create X pixmap"); 2093 image_error ("Unable to create X pixmap");
2090 return 0; 2094 return 0;
2091 } 2095 }
@@ -2152,10 +2156,10 @@ image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int d
2152 if (depth < 16) 2156 if (depth < 16)
2153 palette_colors = 1 << (depth - 1); 2157 palette_colors = 1 << (depth - 1);
2154 2158
2155 *ximg = xmalloc (sizeof (XImage) + palette_colors * sizeof (RGBQUAD)); 2159 *pimg = xmalloc (sizeof (XImage) + palette_colors * sizeof (RGBQUAD));
2156 2160
2157 header = &(*ximg)->info.bmiHeader; 2161 header = &(*pimg)->info.bmiHeader;
2158 memset (&(*ximg)->info, 0, sizeof (BITMAPINFO)); 2162 memset (&(*pimg)->info, 0, sizeof (BITMAPINFO));
2159 header->biSize = sizeof (*header); 2163 header->biSize = sizeof (*header);
2160 header->biWidth = width; 2164 header->biWidth = width;
2161 header->biHeight = -height; /* negative indicates a top-down bitmap. */ 2165 header->biHeight = -height; /* negative indicates a top-down bitmap. */
@@ -2167,10 +2171,10 @@ image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int d
2167 /* TODO: fill in palette. */ 2171 /* TODO: fill in palette. */
2168 if (depth == 1) 2172 if (depth == 1)
2169 { 2173 {
2170 (*ximg)->info.bmiColors[0].rgbBlue = 0; 2174 (*pimg)->info.bmiColors[0].rgbBlue = 0;
2171 (*ximg)->info.bmiColors[0].rgbGreen = 0; 2175 (*pimg)->info.bmiColors[0].rgbGreen = 0;
2172 (*ximg)->info.bmiColors[0].rgbRed = 0; 2176 (*pimg)->info.bmiColors[0].rgbRed = 0;
2173 (*ximg)->info.bmiColors[0].rgbReserved = 0; 2177 (*pimg)->info.bmiColors[0].rgbReserved = 0;
2174 /* bmiColors is a variable-length array declared by w32api 2178 /* bmiColors is a variable-length array declared by w32api
2175 headers as bmiColors[1], which triggers a warning under 2179 headers as bmiColors[1], which triggers a warning under
2176 -Warray-bounds; shut that up. */ 2180 -Warray-bounds; shut that up. */
@@ -2178,10 +2182,10 @@ image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int d
2178# pragma GCC push_options 2182# pragma GCC push_options
2179# pragma GCC diagnostic ignored "-Warray-bounds" 2183# pragma GCC diagnostic ignored "-Warray-bounds"
2180# endif 2184# endif
2181 (*ximg)->info.bmiColors[1].rgbBlue = 255; 2185 (*pimg)->info.bmiColors[1].rgbBlue = 255;
2182 (*ximg)->info.bmiColors[1].rgbGreen = 255; 2186 (*pimg)->info.bmiColors[1].rgbGreen = 255;
2183 (*ximg)->info.bmiColors[1].rgbRed = 255; 2187 (*pimg)->info.bmiColors[1].rgbRed = 255;
2184 (*ximg)->info.bmiColors[1].rgbReserved = 0; 2188 (*pimg)->info.bmiColors[1].rgbReserved = 0;
2185# if GNUC_PREREQ (4, 4, 0) 2189# if GNUC_PREREQ (4, 4, 0)
2186# pragma GCC pop_options 2190# pragma GCC pop_options
2187# endif 2191# endif
@@ -2191,10 +2195,10 @@ image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int d
2191 2195
2192 /* Create a DIBSection and raster array for the bitmap, 2196 /* Create a DIBSection and raster array for the bitmap,
2193 and store its handle in *pixmap. */ 2197 and store its handle in *pixmap. */
2194 *pixmap = CreateDIBSection (hdc, &((*ximg)->info), 2198 *pixmap = CreateDIBSection (hdc, &((*pimg)->info),
2195 (depth < 16) ? DIB_PAL_COLORS : DIB_RGB_COLORS, 2199 (depth < 16) ? DIB_PAL_COLORS : DIB_RGB_COLORS,
2196 /* casting avoids a GCC warning */ 2200 /* casting avoids a GCC warning */
2197 (void **)&((*ximg)->data), NULL, 0); 2201 (void **)&((*pimg)->data), NULL, 0);
2198 2202
2199 /* Realize display palette and garbage all frames. */ 2203 /* Realize display palette and garbage all frames. */
2200 release_frame_dc (f, hdc); 2204 release_frame_dc (f, hdc);
@@ -2206,8 +2210,8 @@ image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int d
2206 /* All system errors are < 10000, so the following is safe. */ 2210 /* All system errors are < 10000, so the following is safe. */
2207 XSETINT (errcode, err); 2211 XSETINT (errcode, err);
2208 image_error ("Unable to create bitmap, error code %d", errcode); 2212 image_error ("Unable to create bitmap, error code %d", errcode);
2209 image_destroy_x_image (*ximg); 2213 image_destroy_x_image (*pimg);
2210 *ximg = NULL; 2214 *pimg = NULL;
2211 return 0; 2215 return 0;
2212 } 2216 }
2213 2217
@@ -2219,69 +2223,70 @@ image_create_x_image_and_pixmap_1 (struct frame *f, int width, int height, int d
2219 *pixmap = ns_image_for_XPM (width, height, depth); 2223 *pixmap = ns_image_for_XPM (width, height, depth);
2220 if (*pixmap == 0) 2224 if (*pixmap == 0)
2221 { 2225 {
2222 *ximg = NULL; 2226 *pimg = NULL;
2223 image_error ("Unable to allocate NSImage for XPM pixmap"); 2227 image_error ("Unable to allocate NSImage for XPM pixmap");
2224 return 0; 2228 return 0;
2225 } 2229 }
2226 *ximg = *pixmap; 2230 *pimg = *pixmap;
2227 return 1; 2231 return 1;
2228#endif 2232#endif
2229} 2233}
2230 2234
2231 2235
2232/* Destroy XImage XIMG. Free XIMG->data. */ 2236/* Destroy Emacs_Pix_Container PIMG. Free data associated with PIMG. */
2233 2237
2234static void 2238static void
2235image_destroy_x_image (XImagePtr ximg) 2239image_destroy_x_image (Emacs_Pix_Container pimg)
2236{ 2240{
2237 eassert (input_blocked_p ()); 2241 eassert (input_blocked_p ());
2238 if (ximg) 2242 if (pimg)
2239 { 2243 {
2240#ifdef HAVE_X_WINDOWS 2244#ifdef HAVE_X_WINDOWS
2241 xfree (ximg->data); 2245 xfree (pimg->data);
2242 ximg->data = NULL; 2246 pimg->data = NULL;
2243 XDestroyImage (ximg); 2247 XDestroyImage (pimg);
2244#endif /* HAVE_X_WINDOWS */ 2248#endif /* HAVE_X_WINDOWS */
2245#ifdef HAVE_NTGUI 2249#ifdef HAVE_NTGUI
2246 /* Data will be freed by DestroyObject. */ 2250 /* Data will be freed by DestroyObject. */
2247 ximg->data = NULL; 2251 pimg->data = NULL;
2248 xfree (ximg); 2252 xfree (pimg);
2249#endif /* HAVE_NTGUI */ 2253#endif /* HAVE_NTGUI */
2250#ifdef HAVE_NS 2254#ifdef HAVE_NS
2251 ns_release_object (ximg); 2255 ns_release_object (pimg);
2252#endif /* HAVE_NS */ 2256#endif /* HAVE_NS */
2253 } 2257 }
2254} 2258}
2255 2259
2256 2260
2257/* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT 2261/* Put Emacs_Pix_Container PIMG into pixmap PIXMAP on frame F.
2258 are width and height of both the image and pixmap. */ 2262 WIDTH and HEIGHT are width and height of both the image and
2263 pixmap. */
2259 2264
2260static void 2265static void
2261gui_put_x_image (struct frame *f, XImagePtr ximg, Emacs_Pixmap pixmap, 2266gui_put_x_image (struct frame *f, Emacs_Pix_Container pimg,
2262 int width, int height) 2267 Emacs_Pixmap pixmap, int width, int height)
2263{ 2268{
2264#ifdef HAVE_X_WINDOWS 2269#ifdef HAVE_X_WINDOWS
2265 GC gc; 2270 GC gc;
2266 2271
2267 eassert (input_blocked_p ()); 2272 eassert (input_blocked_p ());
2268 gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL); 2273 gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL);
2269 XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, 2274 XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, pimg, 0, 0, 0, 0,
2270 ximg->width, ximg->height); 2275 pimg->width, pimg->height);
2271 XFreeGC (FRAME_X_DISPLAY (f), gc); 2276 XFreeGC (FRAME_X_DISPLAY (f), gc);
2272#endif /* HAVE_X_WINDOWS */ 2277#endif /* HAVE_X_WINDOWS */
2273 2278
2274#ifdef HAVE_NTGUI 2279#ifdef HAVE_NTGUI
2275#if 0 /* I don't think this is necessary looking at where it is used. */ 2280#if 0 /* I don't think this is necessary looking at where it is used. */
2276 HDC hdc = get_frame_dc (f); 2281 HDC hdc = get_frame_dc (f);
2277 SetDIBits (hdc, pixmap, 0, height, ximg->data, &(ximg->info), DIB_RGB_COLORS); 2282 SetDIBits (hdc, pixmap, 0, height, pimg->data, &(pimg->info), DIB_RGB_COLORS);
2278 release_frame_dc (f, hdc); 2283 release_frame_dc (f, hdc);
2279#endif 2284#endif
2280#endif /* HAVE_NTGUI */ 2285#endif /* HAVE_NTGUI */
2281 2286
2282#ifdef HAVE_NS 2287#ifdef HAVE_NS
2283 eassert (ximg == pixmap); 2288 eassert (pimg == pixmap);
2284 ns_retain_object (ximg); 2289 ns_retain_object (pimg);
2285#endif 2290#endif
2286} 2291}
2287 2292
@@ -2291,7 +2296,7 @@ gui_put_x_image (struct frame *f, XImagePtr ximg, Emacs_Pixmap pixmap,
2291static bool 2296static bool
2292image_create_x_image_and_pixmap (struct frame *f, struct image *img, 2297image_create_x_image_and_pixmap (struct frame *f, struct image *img,
2293 int width, int height, int depth, 2298 int width, int height, int depth,
2294 XImagePtr *ximg, bool mask_p) 2299 Emacs_Pix_Container *ximg, bool mask_p)
2295{ 2300{
2296 eassert ((!mask_p ? img->pixmap : img->mask) == NO_PIXMAP); 2301 eassert ((!mask_p ? img->pixmap : img->mask) == NO_PIXMAP);
2297 2302
@@ -2304,14 +2309,14 @@ image_create_x_image_and_pixmap (struct frame *f, struct image *img,
2304 picture); 2309 picture);
2305} 2310}
2306 2311
2307/* Put X image XIMG into image IMG on frame F, as a mask if and only 2312/* Put pixel image PIMG into image IMG on frame F, as a mask if and only
2308 if MASK_P. On X, this simply records XIMG on a member of IMG, so 2313 if MASK_P. On X, this simply records PIMG on a member of IMG, so
2309 it can be put into the pixmap afterwards via image_sync_to_pixmaps. 2314 it can be put into the pixmap afterwards via image_sync_to_pixmaps.
2310 On the other platforms, it puts XIMG into the pixmap, then frees 2315 On the other platforms, it puts PIMG into the pixmap, then frees
2311 the X image and its buffer. */ 2316 the pixel image and its buffer. */
2312 2317
2313static void 2318static void
2314image_put_x_image (struct frame *f, struct image *img, XImagePtr ximg, 2319image_put_x_image (struct frame *f, struct image *img, Emacs_Pix_Container ximg,
2315 bool mask_p) 2320 bool mask_p)
2316{ 2321{
2317#ifdef HAVE_X_WINDOWS 2322#ifdef HAVE_X_WINDOWS
@@ -2359,12 +2364,12 @@ image_sync_to_pixmaps (struct frame *f, struct image *img)
2359 currently selected GDI object into *PREV for future restoration by 2364 currently selected GDI object into *PREV for future restoration by
2360 image_unget_x_image_or_dc. */ 2365 image_unget_x_image_or_dc. */
2361 2366
2362static XImagePtr_or_DC 2367static HDC
2363image_get_x_image_or_dc (struct frame *f, struct image *img, bool mask_p, 2368image_get_x_image_or_dc (struct frame *f, struct image *img, bool mask_p,
2364 HGDIOBJ *prev) 2369 HGDIOBJ *prev)
2365{ 2370{
2366 HDC frame_dc = get_frame_dc (f); 2371 HDC frame_dc = get_frame_dc (f);
2367 XImagePtr_or_DC ximg = CreateCompatibleDC (frame_dc); 2372 HDC ximg = CreateCompatibleDC (frame_dc);
2368 2373
2369 release_frame_dc (f, frame_dc); 2374 release_frame_dc (f, frame_dc);
2370 *prev = SelectObject (ximg, !mask_p ? img->pixmap : img->mask); 2375 *prev = SelectObject (ximg, !mask_p ? img->pixmap : img->mask);
@@ -2374,7 +2379,7 @@ image_get_x_image_or_dc (struct frame *f, struct image *img, bool mask_p,
2374 2379
2375static void 2380static void
2376image_unget_x_image_or_dc (struct image *img, bool mask_p, 2381image_unget_x_image_or_dc (struct image *img, bool mask_p,
2377 XImagePtr_or_DC ximg, HGDIOBJ prev) 2382 HDC ximg, HGDIOBJ prev)
2378{ 2383{
2379 SelectObject (ximg, prev); 2384 SelectObject (ximg, prev);
2380 DeleteDC (ximg); 2385 DeleteDC (ximg);
@@ -2383,11 +2388,11 @@ image_unget_x_image_or_dc (struct image *img, bool mask_p,
2383/* Get the X image for IMG on frame F. The resulting X image data 2388/* Get the X image for IMG on frame F. The resulting X image data
2384 should be treated as read-only at least on X. */ 2389 should be treated as read-only at least on X. */
2385 2390
2386static XImagePtr 2391static Emacs_Pix_Container
2387image_get_x_image (struct frame *f, struct image *img, bool mask_p) 2392image_get_x_image (struct frame *f, struct image *img, bool mask_p)
2388{ 2393{
2389#ifdef HAVE_X_WINDOWS 2394#ifdef HAVE_X_WINDOWS
2390 XImagePtr ximg_in_img = !mask_p ? img->ximg : img->mask_img; 2395 XImage *ximg_in_img = !mask_p ? img->ximg : img->mask_img;
2391 2396
2392 if (ximg_in_img) 2397 if (ximg_in_img)
2393 return ximg_in_img; 2398 return ximg_in_img;
@@ -2395,7 +2400,7 @@ image_get_x_image (struct frame *f, struct image *img, bool mask_p)
2395 return XGetImage (FRAME_X_DISPLAY (f), !mask_p ? img->pixmap : img->mask, 2400 return XGetImage (FRAME_X_DISPLAY (f), !mask_p ? img->pixmap : img->mask,
2396 0, 0, img->width, img->height, ~0, ZPixmap); 2401 0, 0, img->width, img->height, ~0, ZPixmap);
2397#elif defined (HAVE_NS) 2402#elif defined (HAVE_NS)
2398 XImagePtr pixmap = !mask_p ? img->pixmap : img->mask; 2403 Emacs_Pix_Container pixmap = !mask_p ? img->pixmap : img->mask;
2399 2404
2400 ns_retain_object (pixmap); 2405 ns_retain_object (pixmap);
2401 return pixmap; 2406 return pixmap;
@@ -2403,10 +2408,10 @@ image_get_x_image (struct frame *f, struct image *img, bool mask_p)
2403} 2408}
2404 2409
2405static void 2410static void
2406image_unget_x_image (struct image *img, bool mask_p, XImagePtr ximg) 2411image_unget_x_image (struct image *img, bool mask_p, Emacs_Pix_Container ximg)
2407{ 2412{
2408#ifdef HAVE_X_WINDOWS 2413#ifdef HAVE_X_WINDOWS
2409 XImagePtr ximg_in_img = !mask_p ? img->ximg : img->mask_img; 2414 XImage *ximg_in_img = !mask_p ? img->ximg : img->mask_img;
2410 2415
2411 if (ximg_in_img) 2416 if (ximg_in_img)
2412 eassert (ximg == ximg_in_img); 2417 eassert (ximg == ximg_in_img);
@@ -4203,7 +4208,7 @@ xpm_load_image (struct frame *f,
4203#ifndef HAVE_NS 4208#ifndef HAVE_NS
4204 bool have_mask = false; 4209 bool have_mask = false;
4205#endif 4210#endif
4206 XImagePtr ximg = NULL, mask_img = NULL; 4211 Emacs_Pix_Container ximg = NULL, mask_img = NULL;
4207 4212
4208#define match() \ 4213#define match() \
4209 LA1 = xpm_scan (&s, end, &beg, &len) 4214 LA1 = xpm_scan (&s, end, &beg, &len)
@@ -4785,7 +4790,7 @@ image_to_emacs_colors (struct frame *f, struct image *img, bool rgb_p)
4785{ 4790{
4786 int x, y; 4791 int x, y;
4787 Emacs_Color *colors, *p; 4792 Emacs_Color *colors, *p;
4788 XImagePtr_or_DC ximg; 4793 Emacs_Pix_Context ximg;
4789 ptrdiff_t nbytes; 4794 ptrdiff_t nbytes;
4790#ifdef HAVE_NTGUI 4795#ifdef HAVE_NTGUI
4791 HGDIOBJ prev; 4796 HGDIOBJ prev;
@@ -4841,7 +4846,7 @@ image_to_emacs_colors (struct frame *f, struct image *img, bool rgb_p)
4841 stored in ximg->data. */ 4846 stored in ximg->data. */
4842 4847
4843static void 4848static void
4844XPutPixel (XImagePtr ximg, int x, int y, COLORREF color) 4849XPutPixel (XImage *ximg, int x, int y, COLORREF color)
4845{ 4850{
4846 int width = ximg->info.bmiHeader.biWidth; 4851 int width = ximg->info.bmiHeader.biWidth;
4847 unsigned char * pixel; 4852 unsigned char * pixel;
@@ -4888,7 +4893,7 @@ static void
4888image_from_emacs_colors (struct frame *f, struct image *img, Emacs_Color *colors) 4893image_from_emacs_colors (struct frame *f, struct image *img, Emacs_Color *colors)
4889{ 4894{
4890 int x, y; 4895 int x, y;
4891 XImagePtr oimg = NULL; 4896 Emacs_Pix_Container oimg = NULL;
4892 Emacs_Color *p; 4897 Emacs_Color *p;
4893 4898
4894 init_color_table (); 4899 init_color_table ();
@@ -5160,13 +5165,13 @@ static void
5160image_build_heuristic_mask (struct frame *f, struct image *img, 5165image_build_heuristic_mask (struct frame *f, struct image *img,
5161 Lisp_Object how) 5166 Lisp_Object how)
5162{ 5167{
5163 XImagePtr_or_DC ximg; 5168 Emacs_Pix_Context ximg;
5164#ifdef HAVE_NTGUI 5169#ifdef HAVE_NTGUI
5165 HGDIOBJ prev; 5170 HGDIOBJ prev;
5166 char *mask_img; 5171 char *mask_img;
5167 int row_width; 5172 int row_width;
5168#elif !defined HAVE_NS 5173#elif !defined HAVE_NS
5169 XImagePtr mask_img; 5174 Emacs_Pix_Container mask_img;
5170#endif 5175#endif
5171 int x, y; 5176 int x, y;
5172 bool use_img_background; 5177 bool use_img_background;
@@ -5402,7 +5407,7 @@ pbm_load (struct frame *f, struct image *img)
5402 char *contents = NULL; 5407 char *contents = NULL;
5403 char *end, *p; 5408 char *end, *p;
5404#ifndef USE_CAIRO 5409#ifndef USE_CAIRO
5405 XImagePtr ximg; 5410 Emacs_Pix_Container ximg;
5406#endif 5411#endif
5407 5412
5408 specified_file = image_spec_value (img->spec, QCfile, NULL); 5413 specified_file = image_spec_value (img->spec, QCfile, NULL);
@@ -5702,7 +5707,7 @@ pbm_load (struct frame *f, struct image *img)
5702#else 5707#else
5703 if (NILP (image_spec_value (img->spec, QCbackground, NULL))) 5708 if (NILP (image_spec_value (img->spec, QCbackground, NULL)))
5704 /* Casting avoids a GCC warning. */ 5709 /* Casting avoids a GCC warning. */
5705 IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); 5710 IMAGE_BACKGROUND (img, f, (Emacs_Pix_Context)ximg);
5706 5711
5707 /* Put ximg into the image. */ 5712 /* Put ximg into the image. */
5708 image_put_x_image (f, img, ximg, 0); 5713 image_put_x_image (f, img, ximg, 0);
@@ -6024,7 +6029,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
6024 cairo_surface_t *surface; 6029 cairo_surface_t *surface;
6025 uint32_t *dataptr; 6030 uint32_t *dataptr;
6026#else 6031#else
6027 XImagePtr ximg, mask_img = NULL; 6032 Emacs_Pix_Container ximg, mask_img = NULL;
6028#endif 6033#endif
6029 6034
6030 /* Find out what file to load. */ 6035 /* Find out what file to load. */
@@ -6337,7 +6342,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
6337#else 6342#else
6338 /* Maybe fill in the background field while we have ximg handy. 6343 /* Maybe fill in the background field while we have ximg handy.
6339 Casting avoids a GCC warning. */ 6344 Casting avoids a GCC warning. */
6340 IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); 6345 IMAGE_BACKGROUND (img, f, (Emacs_Pix_Context)ximg);
6341 6346
6342 /* Put ximg into the image. */ 6347 /* Put ximg into the image. */
6343 image_put_x_image (f, img, ximg, 0); 6348 image_put_x_image (f, img, ximg, 0);
@@ -6347,7 +6352,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
6347 { 6352 {
6348 /* Fill in the background_transparent field while we have the 6353 /* Fill in the background_transparent field while we have the
6349 mask handy. Casting avoids a GCC warning. */ 6354 mask handy. Casting avoids a GCC warning. */
6350 image_background_transparent (img, f, (XImagePtr_or_DC)mask_img); 6355 image_background_transparent (img, f, (Emacs_Pix_Context)mask_img);
6351 6356
6352 image_put_x_image (f, img, mask_img, 1); 6357 image_put_x_image (f, img, mask_img, 1);
6353 } 6358 }
@@ -6767,7 +6772,7 @@ jpeg_load_body (struct frame *f, struct image *img,
6767 int i, ir, ig, ib; 6772 int i, ir, ig, ib;
6768#ifndef USE_CAIRO 6773#ifndef USE_CAIRO
6769 unsigned long *colors; 6774 unsigned long *colors;
6770 XImagePtr ximg = NULL; 6775 Emacs_Pix_Container ximg = NULL;
6771#endif 6776#endif
6772 6777
6773 /* Open the JPEG file. */ 6778 /* Open the JPEG file. */
@@ -6957,7 +6962,7 @@ jpeg_load_body (struct frame *f, struct image *img,
6957 /* Maybe fill in the background field while we have ximg handy. */ 6962 /* Maybe fill in the background field while we have ximg handy. */
6958 if (NILP (image_spec_value (img->spec, QCbackground, NULL))) 6963 if (NILP (image_spec_value (img->spec, QCbackground, NULL)))
6959 /* Casting avoids a GCC warning. */ 6964 /* Casting avoids a GCC warning. */
6960 IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); 6965 IMAGE_BACKGROUND (img, f, (Emacs_Pix_Context)ximg);
6961 6966
6962 /* Put ximg into the image. */ 6967 /* Put ximg into the image. */
6963 image_put_x_image (f, img, ximg, 0); 6968 image_put_x_image (f, img, ximg, 0);
@@ -7257,7 +7262,7 @@ tiff_load (struct frame *f, struct image *img)
7257 int width, height, x, y, count; 7262 int width, height, x, y, count;
7258 uint32 *buf; 7263 uint32 *buf;
7259 int rc; 7264 int rc;
7260 XImagePtr ximg; 7265 Emacs_Pix_Container ximg;
7261 tiff_memory_source memsrc; 7266 tiff_memory_source memsrc;
7262 Lisp_Object image; 7267 Lisp_Object image;
7263 7268
@@ -7427,7 +7432,7 @@ tiff_load (struct frame *f, struct image *img)
7427 /* Maybe fill in the background field while we have ximg handy. */ 7432 /* Maybe fill in the background field while we have ximg handy. */
7428 if (NILP (image_spec_value (img->spec, QCbackground, NULL))) 7433 if (NILP (image_spec_value (img->spec, QCbackground, NULL)))
7429 /* Casting avoids a GCC warning on W32. */ 7434 /* Casting avoids a GCC warning on W32. */
7430 IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); 7435 IMAGE_BACKGROUND (img, f, (Emacs_Pix_Context)ximg);
7431 7436
7432 /* Put ximg into the image. */ 7437 /* Put ximg into the image. */
7433 image_put_x_image (f, img, ximg, 0); 7438 image_put_x_image (f, img, ximg, 0);
@@ -7831,7 +7836,7 @@ gif_load (struct frame *f, struct image *img)
7831 } 7836 }
7832#else 7837#else
7833 /* Create the X image and pixmap. */ 7838 /* Create the X image and pixmap. */
7834 XImagePtr ximg; 7839 Emacs_Pix_Container ximg;
7835 if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) 7840 if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0))
7836 { 7841 {
7837 gif_close (gif, NULL); 7842 gif_close (gif, NULL);
@@ -8061,7 +8066,7 @@ gif_load (struct frame *f, struct image *img)
8061 /* Maybe fill in the background field while we have ximg handy. */ 8066 /* Maybe fill in the background field while we have ximg handy. */
8062 if (NILP (image_spec_value (img->spec, QCbackground, NULL))) 8067 if (NILP (image_spec_value (img->spec, QCbackground, NULL)))
8063 /* Casting avoids a GCC warning. */ 8068 /* Casting avoids a GCC warning. */
8064 IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); 8069 IMAGE_BACKGROUND (img, f, (Emacs_Pix_Context)ximg);
8065 8070
8066 /* Put ximg into the image. */ 8071 /* Put ximg into the image. */
8067 image_put_x_image (f, img, ximg, 0); 8072 image_put_x_image (f, img, ximg, 0);
@@ -8445,7 +8450,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
8445 size_t image_width, image_height; 8450 size_t image_width, image_height;
8446 MagickBooleanType status; 8451 MagickBooleanType status;
8447#ifndef USE_CAIRO 8452#ifndef USE_CAIRO
8448 XImagePtr ximg; 8453 Emacs_Pix_Container ximg;
8449#endif 8454#endif
8450 int x, y; 8455 int x, y;
8451 MagickWand *image_wand; 8456 MagickWand *image_wand;
@@ -9276,7 +9281,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
9276 g_object_unref (pixbuf); 9281 g_object_unref (pixbuf);
9277#else 9282#else
9278 /* Try to create a x pixmap to hold the svg pixmap. */ 9283 /* Try to create a x pixmap to hold the svg pixmap. */
9279 XImagePtr ximg; 9284 Emacs_Pix_Container ximg;
9280 if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) 9285 if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0))
9281 { 9286 {
9282 g_object_unref (pixbuf); 9287 g_object_unref (pixbuf);
@@ -9343,7 +9348,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
9343 9348
9344 /* Maybe fill in the background field while we have ximg handy. 9349 /* Maybe fill in the background field while we have ximg handy.
9345 Casting avoids a GCC warning. */ 9350 Casting avoids a GCC warning. */
9346 IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); 9351 IMAGE_BACKGROUND (img, f, (Emacs_Pix_Context)ximg);
9347 9352
9348 /* Put ximg into the image. */ 9353 /* Put ximg into the image. */
9349 image_put_x_image (f, img, ximg, 0); 9354 image_put_x_image (f, img, ximg, 0);
@@ -9571,7 +9576,7 @@ x_kill_gs_process (Emacs_Pixmap pixmap, struct frame *f)
9571 img->pixmap. */ 9576 img->pixmap. */
9572 if (x_mutable_colormap (FRAME_X_VISUAL (f))) 9577 if (x_mutable_colormap (FRAME_X_VISUAL (f)))
9573 { 9578 {
9574 XImagePtr ximg; 9579 XImage *ximg;
9575 9580
9576 block_input (); 9581 block_input ();
9577 9582