aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/src/image.c b/src/image.c
index ba78a835ef3..8e3a0afe91a 100644
--- a/src/image.c
+++ b/src/image.c
@@ -189,6 +189,7 @@ XPutPixel (ximage, x, y, pixel)
189 PixMapHandle pixmap = GetGWorldPixMap (ximage); 189 PixMapHandle pixmap = GetGWorldPixMap (ximage);
190 short depth = GetPixDepth (pixmap); 190 short depth = GetPixDepth (pixmap);
191 191
192#if defined (WORDS_BIG_ENDIAN) || !USE_CG_DRAWING
192 if (depth == 32) 193 if (depth == 32)
193 { 194 {
194 char *base_addr = GetPixBaseAddr (pixmap); 195 char *base_addr = GetPixBaseAddr (pixmap);
@@ -196,7 +197,9 @@ XPutPixel (ximage, x, y, pixel)
196 197
197 ((unsigned long *) (base_addr + y * row_bytes))[x] = 0xff000000 | pixel; 198 ((unsigned long *) (base_addr + y * row_bytes))[x] = 0xff000000 | pixel;
198 } 199 }
199 else if (depth == 1) 200 else
201#endif
202 if (depth == 1)
200 { 203 {
201 char *base_addr = GetPixBaseAddr (pixmap); 204 char *base_addr = GetPixBaseAddr (pixmap);
202 short row_bytes = GetPixRowBytes (pixmap); 205 short row_bytes = GetPixRowBytes (pixmap);
@@ -233,6 +236,7 @@ XGetPixel (ximage, x, y)
233 PixMapHandle pixmap = GetGWorldPixMap (ximage); 236 PixMapHandle pixmap = GetGWorldPixMap (ximage);
234 short depth = GetPixDepth (pixmap); 237 short depth = GetPixDepth (pixmap);
235 238
239#if defined (WORDS_BIG_ENDIAN) || !USE_CG_DRAWING
236 if (depth == 32) 240 if (depth == 32)
237 { 241 {
238 char *base_addr = GetPixBaseAddr (pixmap); 242 char *base_addr = GetPixBaseAddr (pixmap);
@@ -240,7 +244,9 @@ XGetPixel (ximage, x, y)
240 244
241 return ((unsigned long *) (base_addr + y * row_bytes))[x] & 0x00ffffff; 245 return ((unsigned long *) (base_addr + y * row_bytes))[x] & 0x00ffffff;
242 } 246 }
243 else if (depth == 1) 247 else
248#endif
249 if (depth == 1)
244 { 250 {
245 char *base_addr = GetPixBaseAddr (pixmap); 251 char *base_addr = GetPixBaseAddr (pixmap);
246 short row_bytes = GetPixRowBytes (pixmap); 252 short row_bytes = GetPixRowBytes (pixmap);
@@ -272,6 +278,49 @@ XDestroyImage (ximg)
272{ 278{
273 UnlockPixels (GetGWorldPixMap (ximg)); 279 UnlockPixels (GetGWorldPixMap (ximg));
274} 280}
281
282#if USE_CG_DRAWING
283static CGImageRef
284mac_create_cg_image_from_image (f, img)
285 struct frame *f;
286 struct image *img;
287{
288 Pixmap mask;
289 CGImageRef result = NULL;
290
291 BLOCK_INPUT;
292 if (img->mask)
293 mask = img->mask;
294 else
295 {
296 mask = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
297 img->width, img->height, 1);
298 if (mask)
299 {
300 CGrafPtr old_port;
301 GDHandle old_gdh;
302 Rect r;
303
304 GetGWorld (&old_port, &old_gdh);
305 SetGWorld (mask, NULL);
306 BackColor (blackColor); /* Don't mask. */
307 SetRect (&r, 0, 0, img->width, img->height);
308 EraseRect (&r);
309 SetGWorld (old_port, old_gdh);
310 }
311 }
312 if (mask)
313 {
314 CreateCGImageFromPixMaps (GetGWorldPixMap (img->pixmap),
315 GetGWorldPixMap (mask), &result);
316 if (mask != img->mask)
317 XFreePixmap (FRAME_X_DISPLAY (f), mask);
318 }
319 UNBLOCK_INPUT;
320
321 return result;
322}
323#endif /* USE_CG_DRAWING */
275#endif /* MAC_OS */ 324#endif /* MAC_OS */
276 325
277 326
@@ -1206,6 +1255,18 @@ prepare_image_for_display (f, img)
1206 type dependent loader function. */ 1255 type dependent loader function. */
1207 if (img->pixmap == NO_PIXMAP && !img->load_failed_p) 1256 if (img->pixmap == NO_PIXMAP && !img->load_failed_p)
1208 img->load_failed_p = img->type->load (f, img) == 0; 1257 img->load_failed_p = img->type->load (f, img) == 0;
1258
1259#if defined (MAC_OS) && USE_CG_DRAWING
1260 if (!img->load_failed_p && img->data.ptr_val == NULL)
1261 {
1262 img->data.ptr_val = mac_create_cg_image_from_image (f, img);
1263 if (img->data.ptr_val == NULL)
1264 {
1265 img->load_failed_p = 1;
1266 img->type->free (f, img);
1267 }
1268 }
1269#endif
1209} 1270}
1210 1271
1211 1272
@@ -1452,6 +1513,14 @@ x_clear_image_1 (f, img, pixmap_p, mask_p, colors_p)
1452 img->colors = NULL; 1513 img->colors = NULL;
1453 img->ncolors = 0; 1514 img->ncolors = 0;
1454 } 1515 }
1516
1517#if defined (MAC_OS) && USE_CG_DRAWING
1518 if (img->data.ptr_val)
1519 {
1520 CGImageRelease (img->data.ptr_val);
1521 img->data.ptr_val = NULL;
1522 }
1523#endif
1455} 1524}
1456 1525
1457/* Free X resources of image IMG which is used on frame F. */ 1526/* Free X resources of image IMG which is used on frame F. */