/* Functions for image support on window system.
Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include "blockinput.h"
#include "systime.h"
#include <epaths.h>
+#include "charset.h"
+#include "coding.h"
#ifdef HAVE_X_WINDOWS
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] = pixel;
+ ((unsigned long *) (base_addr + y * row_bytes))[x] = 0xff000000 | pixel;
}
- else if (depth == 1)
+ else
+#endif
+ if (depth == 1)
{
char *base_addr = GetPixBaseAddr (pixmap);
short row_bytes = GetPixRowBytes (pixmap);
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];
+ return ((unsigned long *) (base_addr + y * row_bytes))[x] & 0x00ffffff;
}
- else if (depth == 1)
+ else
+#endif
+ if (depth == 1)
{
char *base_addr = GetPixBaseAddr (pixmap);
short row_bytes = GetPixRowBytes (pixmap);
{
UnlockPixels (GetGWorldPixMap (ximg));
}
+
+#if USE_CG_DRAWING
+static CGImageRef
+mac_create_cg_image_from_image (f, img)
+ struct frame *f;
+ struct image *img;
+{
+ 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 /* USE_CG_DRAWING */
#endif /* MAC_OS */
type dependent loader function. */
if (img->pixmap == NO_PIXMAP && !img->load_failed_p)
img->load_failed_p = img->type->load (f, img) == 0;
+
+#if defined (MAC_OS) && USE_CG_DRAWING
+ if (!img->load_failed_p && img->data.ptr_val == NULL)
+ {
+ img->data.ptr_val = mac_create_cg_image_from_image (f, img);
+ if (img->data.ptr_val == NULL)
+ {
+ img->load_failed_p = 1;
+ img->type->free (f, img);
+ }
+ }
+#endif
}
img->colors = NULL;
img->ncolors = 0;
}
+
+#if defined (MAC_OS) && USE_CG_DRAWING
+ if (img->data.ptr_val)
+ {
+ CGImageRelease (img->data.ptr_val);
+ img->data.ptr_val = NULL;
+ }
+#endif
}
/* Free X resources of image IMG which is used on frame F. */
/* Find image file FILE. Look in data-directory, then
- x-bitmap-file-path. Value is the full name of the file found, or
- nil if not found. */
+ x-bitmap-file-path. Value is the encoded full name of the file
+ found, or nil if not found. */
Lisp_Object
x_find_image_file (file)
if (fd == -1)
file_found = Qnil;
else
- close (fd);
+ {
+ file_found = ENCODE_FILE (file_found);
+ close (fd);
+ }
UNGCPRO;
return file_found;
Lisp_Object specified_file, *file;
FSSpec *fss;
{
-#if MAC_OSX
- FSRef fsr;
-#endif
OSErr err;
+ AEDesc desc;
*file = x_find_image_file (specified_file);
if (!STRINGP (*file))
return fnfErr; /* file or directory not found;
incomplete pathname */
/* Try to open the image file. */
-#if MAC_OSX
- err = FSPathMakeRef (SDATA (*file), &fsr, NULL);
+ err = AECoercePtr (TYPE_FILE_NAME, SDATA (*file),
+ SBYTES (*file), typeFSS, &desc);
if (err == noErr)
- err = FSGetCatalogInfo (&fsr, kFSCatInfoNone, NULL, NULL, fss, NULL);
+ {
+#if TARGET_API_MAC_CARBON
+ err = AEGetDescData (&desc, fss, sizeof (FSSpec));
#else
- err = posix_pathname_to_fsspec (SDATA (*file), fss);
+ *fss = *(FSSpec *)(*(desc.dataHandle));
#endif
+ AEDisposeDesc (&desc);
+ }
return err;
}
if (!check_image_size (f, width, height))
{
+ CGImageRelease (image);
UNGCPRO;
image_error ("Invalid image size", Qnil, Qnil);
return 0;
#endif /* HAVE_XPM || MAC_OS */
+#if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
+int
+x_create_bitmap_from_xpm_data (f, bits)
+ struct frame *f;
+ char **bits;
+{
+ Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+ int id, rc;
+ XpmAttributes attrs;
+ Pixmap bitmap, mask;
+
+ bzero (&attrs, sizeof attrs);
+
+ attrs.visual = FRAME_X_VISUAL (f);
+ attrs.colormap = FRAME_X_COLORMAP (f);
+ attrs.valuemask |= XpmVisual;
+ attrs.valuemask |= XpmColormap;
+
+ rc = XpmCreatePixmapFromData (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+ bits, &bitmap, &mask, &attrs);
+ if (rc != XpmSuccess)
+ {
+ XpmFreeAttributes (&attrs);
+ return -1;
+ }
+
+ id = x_allocate_bitmap_record (f);
+ dpyinfo->bitmaps[id - 1].pixmap = bitmap;
+ dpyinfo->bitmaps[id - 1].have_mask = 1;
+ dpyinfo->bitmaps[id - 1].mask = mask;
+ dpyinfo->bitmaps[id - 1].file = NULL;
+ dpyinfo->bitmaps[id - 1].height = attrs.height;
+ dpyinfo->bitmaps[id - 1].width = attrs.width;
+ dpyinfo->bitmaps[id - 1].depth = attrs.depth;
+ dpyinfo->bitmaps[id - 1].refcount = 1;
+
+ XpmFreeAttributes (&attrs);
+ return id;
+}
+#endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
+
/* Load image IMG which will be displayed on frame F. Value is
non-zero if successful. */
attrs.valuemask |= XpmCloseness;
#endif /* not XpmAllocCloseColors */
#endif /* ALLOC_XPM_COLORS */
+#ifdef ALLOC_XPM_COLORS
+ xpm_init_color_cache (f, &attrs);
+#endif
/* If image specification contains symbolic color definitions, add
these to `attrs'. */
if (color == NULL)
goto failure;
- while (str = strtok (NULL, " \t"))
+ while ((str = strtok (NULL, " \t")) != NULL)
{
next_key = xpm_str_to_color_key (str);
if (next_key >= 0)
Lisp_Object specified_color = Fassoc (symbol_color, color_symbols);
if (CONSP (specified_color) && STRINGP (XCDR (specified_color)))
- if (xstricmp (SDATA (XCDR (specified_color)), "None") == 0)
- color_val = Qt;
- else if (x_defined_color (f, SDATA (XCDR (specified_color)),
- &cdef, 0))
- color_val = make_number (cdef.pixel);
+ {
+ if (xstricmp (SDATA (XCDR (specified_color)), "None") == 0)
+ color_val = Qt;
+ else if (x_defined_color (f, SDATA (XCDR (specified_color)),
+ &cdef, 0))
+ color_val = make_number (cdef.pixel);
+ }
}
if (NILP (color_val) && max_key > 0)
- if (xstricmp (max_color, "None") == 0)
- color_val = Qt;
- else if (x_defined_color (f, max_color, &cdef, 0))
- color_val = make_number (cdef.pixel);
+ {
+ if (xstricmp (max_color, "None") == 0)
+ color_val = Qt;
+ else if (x_defined_color (f, max_color, &cdef, 0))
+ color_val = make_number (cdef.pixel);
+ }
if (!NILP (color_val))
(*put_color_table) (color_table, beg, chars_per_pixel, color_val);
int width, height;
XImagePtr ximg;
TimeValue time;
- struct gcpro gcpro1;
int ino;
CGrafPtr old_port;
GDHandle old_gdh;
specified_file = image_spec_value (img->spec, QCfile, NULL);
specified_data = image_spec_value (img->spec, QCdata, NULL);
+ /* Animated gifs use QuickTime Movie Toolbox. So initialize it here. */
+ EnterMovies ();
+
if (NILP (specified_data))
{
/* Read from a file */
void
init_image ()
{
-#ifdef MAC_OS
- /* Animated gifs use QuickTime Movie Toolbox. So initialize it here. */
- EnterMovies ();
-#ifdef MAC_OSX
+#if defined (MAC_OSX) && TARGET_API_MAC_CARBON
init_image_func_pointer ();
#endif
-#endif
}
/* arch-tag: 123c2a5e-14a8-4c53-ab95-af47d7db49b9