Commit c736ffda authored by Jason Rumney's avatar Jason Rumney

(w32_create_pixmap_from_bitmap_data): Use alloca for

local malloc.
[HAVE_XPM]: Avoid clashes with XColor, XImage and Pixel
definitions in xpm.h.
(init_xpm_functions): New function.
(xpm_load): Sync with xfns.c. Adapt for Windows version of libXpm.
(init_external_image_libraries): Try to load libXpm.dll.
parent 51c39777
...@@ -9867,7 +9867,7 @@ w32_create_pixmap_from_bitmap_data (int width, int height, char *data) ...@@ -9867,7 +9867,7 @@ w32_create_pixmap_from_bitmap_data (int width, int height, char *data)
w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */ w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */
w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */ w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */
bits = (char *) xmalloc (height * w2); bits = (char *) alloca (height * w2);
bzero (bits, height * w2); bzero (bits, height * w2);
for (i = 0; i < height; i++) for (i = 0; i < height; i++)
{ {
...@@ -9876,7 +9876,6 @@ w32_create_pixmap_from_bitmap_data (int width, int height, char *data) ...@@ -9876,7 +9876,6 @@ w32_create_pixmap_from_bitmap_data (int width, int height, char *data)
*p++ = reflect_byte(*data++); *p++ = reflect_byte(*data++);
} }
bmp = CreateBitmap (width, height, 1, 1, bits); bmp = CreateBitmap (width, height, 1, 1, bits);
xfree (bits);
return bmp; return bmp;
} }
...@@ -10292,7 +10291,17 @@ static int xpm_image_p P_ ((Lisp_Object object)); ...@@ -10292,7 +10291,17 @@ static int xpm_image_p P_ ((Lisp_Object object));
static int xpm_load P_ ((struct frame *f, struct image *img)); static int xpm_load P_ ((struct frame *f, struct image *img));
static int xpm_valid_color_symbols_p P_ ((Lisp_Object)); static int xpm_valid_color_symbols_p P_ ((Lisp_Object));
/* Indicate to xpm.h that we don't have Xlib. */
#define FOR_MSW
/* simx.h in xpm defines XColor and XImage differently than Emacs. */
#define XColor xpm_XColor
#define XImage xpm_XImage
#define PIXEL_ALREADY_TYPEDEFED
#include "X11/xpm.h" #include "X11/xpm.h"
#undef FOR_MSW
#undef XColor
#undef XImage
#undef PIXEL_ALREADY_TYPEDEFED
/* The symbol `xpm' identifying XPM-format images. */ /* The symbol `xpm' identifying XPM-format images. */
...@@ -10346,6 +10355,26 @@ static struct image_type xpm_type = ...@@ -10346,6 +10355,26 @@ static struct image_type xpm_type =
}; };
/* XPM library details. */
DEF_IMGLIB_FN (XpmFreeAttributes);
DEF_IMGLIB_FN (XpmCreateImageFromBuffer);
DEF_IMGLIB_FN (XpmReadFileToImage);
DEF_IMGLIB_FN (XImageFree);
static int
init_xpm_functions (library)
HMODULE library;
{
LOAD_IMGLIB_FN (library, XpmFreeAttributes);
LOAD_IMGLIB_FN (library, XpmCreateImageFromBuffer);
LOAD_IMGLIB_FN (library, XpmReadFileToImage);
LOAD_IMGLIB_FN (library, XImageFree);
return 1;
}
/* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
for XPM images. Such a list must consist of conses whose car and for XPM images. Such a list must consist of conses whose car and
cdr are strings. */ cdr are strings. */
...@@ -10394,17 +10423,23 @@ xpm_load (f, img) ...@@ -10394,17 +10423,23 @@ xpm_load (f, img)
struct frame *f; struct frame *f;
struct image *img; struct image *img;
{ {
int rc, i; HDC hdc;
int rc;
XpmAttributes attrs; XpmAttributes attrs;
Lisp_Object specified_file, color_symbols; Lisp_Object specified_file, color_symbols;
xpm_XImage * xpm_image, * xpm_mask;
/* Configure the XPM lib. Use the visual of frame F. Allocate /* Configure the XPM lib. Use the visual of frame F. Allocate
close colors. Return colors allocated. */ close colors. Return colors allocated. */
bzero (&attrs, sizeof attrs); bzero (&attrs, sizeof attrs);
xpm_image = xpm_mask = NULL;
#if 0
attrs.visual = FRAME_X_VISUAL (f); attrs.visual = FRAME_X_VISUAL (f);
attrs.colormap = FRAME_X_COLORMAP (f); attrs.colormap = FRAME_X_COLORMAP (f);
attrs.valuemask |= XpmVisual; attrs.valuemask |= XpmVisual;
attrs.valuemask |= XpmColormap; attrs.valuemask |= XpmColormap;
#endif
attrs.valuemask |= XpmReturnAllocPixels; attrs.valuemask |= XpmReturnAllocPixels;
#ifdef XpmAllocCloseColors #ifdef XpmAllocCloseColors
attrs.alloc_close_colors = 1; attrs.alloc_close_colors = 1;
...@@ -10452,34 +10487,71 @@ xpm_load (f, img) ...@@ -10452,34 +10487,71 @@ xpm_load (f, img)
/* Create a pixmap for the image, either from a file, or from a /* Create a pixmap for the image, either from a file, or from a
string buffer containing data in the same format as an XPM file. */ string buffer containing data in the same format as an XPM file. */
BLOCK_INPUT;
specified_file = image_spec_value (img->spec, QCfile, NULL); specified_file = image_spec_value (img->spec, QCfile, NULL);
{
HDC frame_dc = get_frame_dc (f);
hdc = CreateCompatibleDC (frame_dc);
release_frame_dc (f, frame_dc);
}
if (STRINGP (specified_file)) if (STRINGP (specified_file))
{ {
Lisp_Object file = x_find_image_file (specified_file); Lisp_Object file = x_find_image_file (specified_file);
if (!STRINGP (file)) if (!STRINGP (file))
{ {
image_error ("Cannot find image file `%s'", specified_file, Qnil); image_error ("Cannot find image file `%s'", specified_file, Qnil);
UNBLOCK_INPUT;
return 0; return 0;
} }
rc = XpmReadFileToPixmap (NULL, FRAME_W32_WINDOW (f), /* XpmReadFileToPixmap is not available in the Windows port of
SDATA (file), &img->pixmap, &img->mask, libxpm. But XpmReadFileToImage almost does what we want. */
&attrs); rc = fn_XpmReadFileToImage (&hdc, SDATA (file),
&xpm_image, &xpm_mask,
&attrs);
} }
else else
{ {
Lisp_Object buffer = image_spec_value (img->spec, QCdata, NULL); Lisp_Object buffer = image_spec_value (img->spec, QCdata, NULL);
rc = XpmCreatePixmapFromBuffer (NULL, FRAME_W32_WINDOW (f), /* XpmCreatePixmapFromBuffer is not available in the Windows port
SDATA (buffer), of libxpm. But XpmCreateImageFromBuffer almost does what we want. */
&img->pixmap, &img->mask, rc = fn_XpmCreateImageFromBuffer (&hdc, SDATA (buffer),
&attrs); &xpm_image, &xpm_mask,
&attrs);
} }
UNBLOCK_INPUT;
if (rc == XpmSuccess) if (rc == XpmSuccess)
{ {
int i;
/* W32 XPM uses XImage to wrap what W32 Emacs calls a Pixmap,
plus some duplicate attributes. */
if (xpm_image && xpm_image->bitmap)
{
img->pixmap = xpm_image->bitmap;
/* XImageFree in libXpm frees XImage struct without destroying
the bitmap, which is what we want. */
fn_XImageFree (xpm_image);
}
if (xpm_mask && xpm_mask->bitmap)
{
/* The mask appears to be inverted compared with what we expect.
TODO: invert our expectations. See other places where we
have to invert bits because our idea of masks is backwards. */
HGDIOBJ old_obj;
old_obj = SelectObject (hdc, xpm_mask->bitmap);
PatBlt (hdc, 0, 0, xpm_mask->width, xpm_mask->height, DSTINVERT);
SelectObject (hdc, old_obj);
img->mask = xpm_mask->bitmap;
fn_XImageFree (xpm_mask);
DeleteDC (hdc);
}
DeleteDC (hdc);
/* Remember allocated colors. */ /* Remember allocated colors. */
img->ncolors = attrs.nalloc_pixels; img->ncolors = attrs.nalloc_pixels;
img->colors = (unsigned long *) xmalloc (img->ncolors img->colors = (unsigned long *) xmalloc (img->ncolors
...@@ -10492,12 +10564,12 @@ xpm_load (f, img) ...@@ -10492,12 +10564,12 @@ xpm_load (f, img)
xassert (img->width > 0 && img->height > 0); xassert (img->width > 0 && img->height > 0);
/* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */ /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
BLOCK_INPUT; fn_XpmFreeAttributes (&attrs);
XpmFreeAttributes (&attrs);
UNBLOCK_INPUT;
} }
else else
{ {
DeleteDC (hdc);
switch (rc) switch (rc)
{ {
case XpmOpenFailed: case XpmOpenFailed:
...@@ -15734,7 +15806,12 @@ init_external_image_libraries () ...@@ -15734,7 +15806,12 @@ init_external_image_libraries ()
HINSTANCE library; HINSTANCE library;
#if HAVE_XPM #if HAVE_XPM
define_image_type (&xpm_type); if ((library = LoadLibrary ("libXpm.dll")))
{
if (init_xpm_functions (library))
define_image_type (&xpm_type);
}
#endif #endif
#if HAVE_JPEG #if HAVE_JPEG
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment