#endif
#endif
+#include <setjmp.h>
+
/* This makes the fields of a Display accessible, in Xlib header files. */
#define XLIB_ILLEGAL_ACCESS
the bitmaps yourself. That is, creating a bitmap from the same
data more than once will not be caught. */
-#ifdef MAC_OS
-
-static XImagePtr
-XGetImage (display, pixmap, x, y, width, height, plane_mask, format)
- Display *display; /* not used */
- Pixmap pixmap;
- int x, y; /* not used */
- unsigned int width, height; /* not used */
- unsigned long plane_mask; /* not used */
- int format; /* not used */
-{
-#if !USE_MAC_IMAGE_IO
-#if GLYPH_DEBUG
- xassert (x == 0 && y == 0);
- {
- Rect ri, rp;
- SetRect (&ri, 0, 0, width, height);
- xassert (EqualRect (&ri, GetPixBounds (GetGWorldPixMap (pixmap), &rp)));
- }
- xassert (! (pixelsLocked & GetPixelsState (GetGWorldPixMap (pixmap))));
-#endif
-
- LockPixels (GetGWorldPixMap (pixmap));
-#endif
-
- return pixmap;
-}
-
-static void
-XPutPixel (ximage, x, y, pixel)
- XImagePtr ximage;
- int x, y;
- unsigned long pixel;
-{
-#if USE_MAC_IMAGE_IO
- if (ximage->bits_per_pixel == 32)
- ((unsigned int *)(ximage->data + y * ximage->bytes_per_line))[x] = pixel;
- else
- ((unsigned char *)(ximage->data + y * ximage->bytes_per_line))[x] = pixel;
-#else
- PixMapHandle pixmap = GetGWorldPixMap (ximage);
- short depth = GetPixDepth (pixmap);
-
-#if defined (WORDS_BIG_ENDIAN) || !USE_CG_DRAWING
- if (depth == 32)
- {
- char *base_addr = GetPixBaseAddr (pixmap);
- short row_bytes = GetPixRowBytes (pixmap);
-
- ((unsigned long *) (base_addr + y * row_bytes))[x] = 0xff000000 | pixel;
- }
- else
-#endif
- if (depth == 1)
- {
- char *base_addr = GetPixBaseAddr (pixmap);
- short row_bytes = GetPixRowBytes (pixmap);
-
- if (pixel == PIX_MASK_DRAW)
- base_addr[y * row_bytes + x / 8] |= (1 << 7) >> (x & 7);
- else
- base_addr[y * row_bytes + x / 8] &= ~((1 << 7) >> (x & 7));
- }
- else
- {
- CGrafPtr old_port;
- GDHandle old_gdh;
- RGBColor color;
-
- GetGWorld (&old_port, &old_gdh);
- SetGWorld (ximage, NULL);
-
- color.red = RED16_FROM_ULONG (pixel);
- color.green = GREEN16_FROM_ULONG (pixel);
- color.blue = BLUE16_FROM_ULONG (pixel);
-
- SetCPixel (x, y, &color);
-
- SetGWorld (old_port, old_gdh);
- }
-#endif
-}
-
-static unsigned long
-XGetPixel (ximage, x, y)
- XImagePtr ximage;
- int x, y;
-{
-#if USE_MAC_IMAGE_IO
- if (ximage->bits_per_pixel == 32)
- return ((unsigned int *)(ximage->data + y * ximage->bytes_per_line))[x];
- else
- return ((unsigned char *)(ximage->data + y * ximage->bytes_per_line))[x];
-#else
- PixMapHandle pixmap = GetGWorldPixMap (ximage);
- short depth = GetPixDepth (pixmap);
-
-#if defined (WORDS_BIG_ENDIAN) || !USE_CG_DRAWING
- if (depth == 32)
- {
- char *base_addr = GetPixBaseAddr (pixmap);
- short row_bytes = GetPixRowBytes (pixmap);
-
- return ((unsigned long *) (base_addr + y * row_bytes))[x] & 0x00ffffff;
- }
- else
-#endif
- if (depth == 1)
- {
- char *base_addr = GetPixBaseAddr (pixmap);
- short row_bytes = GetPixRowBytes (pixmap);
-
- if (base_addr[y * row_bytes + x / 8] & (1 << (~x & 7)))
- return PIX_MASK_DRAW;
- else
- return PIX_MASK_RETAIN;
- }
- else
- {
- CGrafPtr old_port;
- GDHandle old_gdh;
- RGBColor color;
-
- GetGWorld (&old_port, &old_gdh);
- SetGWorld (ximage, NULL);
-
- GetCPixel (x, y, &color);
-
- SetGWorld (old_port, old_gdh);
- return RGB_TO_ULONG (color.red >> 8, color.green >> 8, color.blue >> 8);
- }
-#endif
-}
-
-static void
-XDestroyImage (ximg)
- XImagePtr ximg;
-{
-#if !USE_MAC_IMAGE_IO
- UnlockPixels (GetGWorldPixMap (ximg));
-#endif
-}
-
-#if USE_CG_DRAWING
-#if USE_MAC_IMAGE_IO
-void
-mac_data_provider_release_data (info, data, size)
- void *info;
- const void *data;
- size_t size;
-{
- xfree ((void *)data);
-}
-#endif
-
-static CGImageRef
-mac_create_cg_image_from_image (f, img)
- struct frame *f;
- struct image *img;
-{
-#if USE_MAC_IMAGE_IO
- XImagePtr ximg = img->pixmap;
- CGDataProviderRef provider;
- CGImageRef result;
-
- if (img->mask)
- {
- int x, y;
- unsigned long color, alpha;
-
- for (y = 0; y < ximg->height; y++)
- for (x = 0; x < ximg->width; x++)
- {
- color = XGetPixel (ximg, x, y);
- alpha = XGetPixel (img->mask, x, y);
- XPutPixel (ximg, x, y,
- ARGB_TO_ULONG (alpha,
- RED_FROM_ULONG (color)
- * alpha / PIX_MASK_DRAW,
- GREEN_FROM_ULONG (color)
- * alpha / PIX_MASK_DRAW,
- BLUE_FROM_ULONG (color)
- * alpha / PIX_MASK_DRAW));
- }
- xfree (img->mask->data);
- img->mask->data = NULL;
- }
- BLOCK_INPUT;
- provider = CGDataProviderCreateWithData (NULL, ximg->data,
- ximg->bytes_per_line * ximg->height,
- mac_data_provider_release_data);
- ximg->data = NULL;
- result = CGImageCreate (ximg->width, ximg->height, 8, 32,
- ximg->bytes_per_line, mac_cg_color_space_rgb,
- ((img->mask ? kCGImageAlphaPremultipliedFirst
- : kCGImageAlphaNoneSkipFirst)
- | kCGBitmapByteOrder32Host),
- provider, NULL, 0, kCGRenderingIntentDefault);
- CGDataProviderRelease (provider);
- UNBLOCK_INPUT;
-
- return result;
-#else
- Pixmap mask;
- CGImageRef result = NULL;
-
- BLOCK_INPUT;
- if (img->mask)
- mask = img->mask;
- else
- {
- mask = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
- img->width, img->height, 1);
- if (mask)
- {
- CGrafPtr old_port;
- GDHandle old_gdh;
- Rect r;
-
- GetGWorld (&old_port, &old_gdh);
- SetGWorld (mask, NULL);
- BackColor (blackColor); /* Don't mask. */
- SetRect (&r, 0, 0, img->width, img->height);
- EraseRect (&r);
- SetGWorld (old_port, old_gdh);
- }
- }
- if (mask)
- {
- CreateCGImageFromPixMaps (GetGWorldPixMap (img->pixmap),
- GetGWorldPixMap (mask), &result);
- if (mask != img->mask)
- XFreePixmap (FRAME_X_DISPLAY (f), mask);
- }
- UNBLOCK_INPUT;
-
- return result;
-#endif
-}
-#endif /* USE_CG_DRAWING */
-#endif /* MAC_OS */
-
#ifdef HAVE_NS
XImagePtr
XGetImage (Display *display, Pixmap pixmap, int x, int y,
#include <jpeglib.h>
#include <jerror.h>
-#include <setjmp.h>
#ifdef HAVE_STLIB_H_1
#define HAVE_STDLIB_H 1