diff options
| author | Jason Rumney | 2003-02-01 23:54:34 +0000 |
|---|---|---|
| committer | Jason Rumney | 2003-02-01 23:54:34 +0000 |
| commit | c736ffda58fbde8474b8aef829ff12466620b442 (patch) | |
| tree | 11f228aa8d0857f5b4357f830d60b32f56c82e75 | |
| parent | 51c397779d714cc9905eed359145abc01e9b89ef (diff) | |
| download | emacs-c736ffda58fbde8474b8aef829ff12466620b442.tar.gz emacs-c736ffda58fbde8474b8aef829ff12466620b442.zip | |
(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.
| -rw-r--r-- | src/w32fns.c | 111 |
1 files changed, 94 insertions, 17 deletions
diff --git a/src/w32fns.c b/src/w32fns.c index d23c658b6b2..feed88096f7 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -9867,7 +9867,7 @@ w32_create_pixmap_from_bitmap_data (int width, int height, char *data) | |||
| 9867 | 9867 | ||
| 9868 | w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */ | 9868 | w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */ |
| 9869 | w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */ | 9869 | w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */ |
| 9870 | bits = (char *) xmalloc (height * w2); | 9870 | bits = (char *) alloca (height * w2); |
| 9871 | bzero (bits, height * w2); | 9871 | bzero (bits, height * w2); |
| 9872 | for (i = 0; i < height; i++) | 9872 | for (i = 0; i < height; i++) |
| 9873 | { | 9873 | { |
| @@ -9876,7 +9876,6 @@ w32_create_pixmap_from_bitmap_data (int width, int height, char *data) | |||
| 9876 | *p++ = reflect_byte(*data++); | 9876 | *p++ = reflect_byte(*data++); |
| 9877 | } | 9877 | } |
| 9878 | bmp = CreateBitmap (width, height, 1, 1, bits); | 9878 | bmp = CreateBitmap (width, height, 1, 1, bits); |
| 9879 | xfree (bits); | ||
| 9880 | 9879 | ||
| 9881 | return bmp; | 9880 | return bmp; |
| 9882 | } | 9881 | } |
| @@ -10292,7 +10291,17 @@ static int xpm_image_p P_ ((Lisp_Object object)); | |||
| 10292 | static int xpm_load P_ ((struct frame *f, struct image *img)); | 10291 | static int xpm_load P_ ((struct frame *f, struct image *img)); |
| 10293 | static int xpm_valid_color_symbols_p P_ ((Lisp_Object)); | 10292 | static int xpm_valid_color_symbols_p P_ ((Lisp_Object)); |
| 10294 | 10293 | ||
| 10294 | /* Indicate to xpm.h that we don't have Xlib. */ | ||
| 10295 | #define FOR_MSW | ||
| 10296 | /* simx.h in xpm defines XColor and XImage differently than Emacs. */ | ||
| 10297 | #define XColor xpm_XColor | ||
| 10298 | #define XImage xpm_XImage | ||
| 10299 | #define PIXEL_ALREADY_TYPEDEFED | ||
| 10295 | #include "X11/xpm.h" | 10300 | #include "X11/xpm.h" |
| 10301 | #undef FOR_MSW | ||
| 10302 | #undef XColor | ||
| 10303 | #undef XImage | ||
| 10304 | #undef PIXEL_ALREADY_TYPEDEFED | ||
| 10296 | 10305 | ||
| 10297 | /* The symbol `xpm' identifying XPM-format images. */ | 10306 | /* The symbol `xpm' identifying XPM-format images. */ |
| 10298 | 10307 | ||
| @@ -10346,6 +10355,26 @@ static struct image_type xpm_type = | |||
| 10346 | }; | 10355 | }; |
| 10347 | 10356 | ||
| 10348 | 10357 | ||
| 10358 | /* XPM library details. */ | ||
| 10359 | |||
| 10360 | DEF_IMGLIB_FN (XpmFreeAttributes); | ||
| 10361 | DEF_IMGLIB_FN (XpmCreateImageFromBuffer); | ||
| 10362 | DEF_IMGLIB_FN (XpmReadFileToImage); | ||
| 10363 | DEF_IMGLIB_FN (XImageFree); | ||
| 10364 | |||
| 10365 | |||
| 10366 | static int | ||
| 10367 | init_xpm_functions (library) | ||
| 10368 | HMODULE library; | ||
| 10369 | { | ||
| 10370 | LOAD_IMGLIB_FN (library, XpmFreeAttributes); | ||
| 10371 | LOAD_IMGLIB_FN (library, XpmCreateImageFromBuffer); | ||
| 10372 | LOAD_IMGLIB_FN (library, XpmReadFileToImage); | ||
| 10373 | LOAD_IMGLIB_FN (library, XImageFree); | ||
| 10374 | |||
| 10375 | return 1; | ||
| 10376 | } | ||
| 10377 | |||
| 10349 | /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list | 10378 | /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list |
| 10350 | for XPM images. Such a list must consist of conses whose car and | 10379 | for XPM images. Such a list must consist of conses whose car and |
| 10351 | cdr are strings. */ | 10380 | cdr are strings. */ |
| @@ -10394,17 +10423,23 @@ xpm_load (f, img) | |||
| 10394 | struct frame *f; | 10423 | struct frame *f; |
| 10395 | struct image *img; | 10424 | struct image *img; |
| 10396 | { | 10425 | { |
| 10397 | int rc, i; | 10426 | HDC hdc; |
| 10427 | int rc; | ||
| 10398 | XpmAttributes attrs; | 10428 | XpmAttributes attrs; |
| 10399 | Lisp_Object specified_file, color_symbols; | 10429 | Lisp_Object specified_file, color_symbols; |
| 10430 | xpm_XImage * xpm_image, * xpm_mask; | ||
| 10400 | 10431 | ||
| 10401 | /* Configure the XPM lib. Use the visual of frame F. Allocate | 10432 | /* Configure the XPM lib. Use the visual of frame F. Allocate |
| 10402 | close colors. Return colors allocated. */ | 10433 | close colors. Return colors allocated. */ |
| 10403 | bzero (&attrs, sizeof attrs); | 10434 | bzero (&attrs, sizeof attrs); |
| 10435 | xpm_image = xpm_mask = NULL; | ||
| 10436 | |||
| 10437 | #if 0 | ||
| 10404 | attrs.visual = FRAME_X_VISUAL (f); | 10438 | attrs.visual = FRAME_X_VISUAL (f); |
| 10405 | attrs.colormap = FRAME_X_COLORMAP (f); | 10439 | attrs.colormap = FRAME_X_COLORMAP (f); |
| 10406 | attrs.valuemask |= XpmVisual; | 10440 | attrs.valuemask |= XpmVisual; |
| 10407 | attrs.valuemask |= XpmColormap; | 10441 | attrs.valuemask |= XpmColormap; |
| 10442 | #endif | ||
| 10408 | attrs.valuemask |= XpmReturnAllocPixels; | 10443 | attrs.valuemask |= XpmReturnAllocPixels; |
| 10409 | #ifdef XpmAllocCloseColors | 10444 | #ifdef XpmAllocCloseColors |
| 10410 | attrs.alloc_close_colors = 1; | 10445 | attrs.alloc_close_colors = 1; |
| @@ -10452,34 +10487,71 @@ xpm_load (f, img) | |||
| 10452 | 10487 | ||
| 10453 | /* Create a pixmap for the image, either from a file, or from a | 10488 | /* Create a pixmap for the image, either from a file, or from a |
| 10454 | string buffer containing data in the same format as an XPM file. */ | 10489 | string buffer containing data in the same format as an XPM file. */ |
| 10455 | BLOCK_INPUT; | 10490 | |
| 10456 | specified_file = image_spec_value (img->spec, QCfile, NULL); | 10491 | specified_file = image_spec_value (img->spec, QCfile, NULL); |
| 10492 | |||
| 10493 | { | ||
| 10494 | HDC frame_dc = get_frame_dc (f); | ||
| 10495 | hdc = CreateCompatibleDC (frame_dc); | ||
| 10496 | release_frame_dc (f, frame_dc); | ||
| 10497 | } | ||
| 10498 | |||
| 10457 | if (STRINGP (specified_file)) | 10499 | if (STRINGP (specified_file)) |
| 10458 | { | 10500 | { |
| 10459 | Lisp_Object file = x_find_image_file (specified_file); | 10501 | Lisp_Object file = x_find_image_file (specified_file); |
| 10460 | if (!STRINGP (file)) | 10502 | if (!STRINGP (file)) |
| 10461 | { | 10503 | { |
| 10462 | image_error ("Cannot find image file `%s'", specified_file, Qnil); | 10504 | image_error ("Cannot find image file `%s'", specified_file, Qnil); |
| 10463 | UNBLOCK_INPUT; | ||
| 10464 | return 0; | 10505 | return 0; |
| 10465 | } | 10506 | } |
| 10466 | 10507 | ||
| 10467 | rc = XpmReadFileToPixmap (NULL, FRAME_W32_WINDOW (f), | 10508 | /* XpmReadFileToPixmap is not available in the Windows port of |
| 10468 | SDATA (file), &img->pixmap, &img->mask, | 10509 | libxpm. But XpmReadFileToImage almost does what we want. */ |
| 10469 | &attrs); | 10510 | rc = fn_XpmReadFileToImage (&hdc, SDATA (file), |
| 10511 | &xpm_image, &xpm_mask, | ||
| 10512 | &attrs); | ||
| 10470 | } | 10513 | } |
| 10471 | else | 10514 | else |
| 10472 | { | 10515 | { |
| 10473 | Lisp_Object buffer = image_spec_value (img->spec, QCdata, NULL); | 10516 | Lisp_Object buffer = image_spec_value (img->spec, QCdata, NULL); |
| 10474 | rc = XpmCreatePixmapFromBuffer (NULL, FRAME_W32_WINDOW (f), | 10517 | /* XpmCreatePixmapFromBuffer is not available in the Windows port |
| 10475 | SDATA (buffer), | 10518 | of libxpm. But XpmCreateImageFromBuffer almost does what we want. */ |
| 10476 | &img->pixmap, &img->mask, | 10519 | rc = fn_XpmCreateImageFromBuffer (&hdc, SDATA (buffer), |
| 10477 | &attrs); | 10520 | &xpm_image, &xpm_mask, |
| 10521 | &attrs); | ||
| 10478 | } | 10522 | } |
| 10479 | UNBLOCK_INPUT; | ||
| 10480 | 10523 | ||
| 10481 | if (rc == XpmSuccess) | 10524 | if (rc == XpmSuccess) |
| 10482 | { | 10525 | { |
| 10526 | int i; | ||
| 10527 | |||
| 10528 | /* W32 XPM uses XImage to wrap what W32 Emacs calls a Pixmap, | ||
| 10529 | plus some duplicate attributes. */ | ||
| 10530 | if (xpm_image && xpm_image->bitmap) | ||
| 10531 | { | ||
| 10532 | img->pixmap = xpm_image->bitmap; | ||
| 10533 | /* XImageFree in libXpm frees XImage struct without destroying | ||
| 10534 | the bitmap, which is what we want. */ | ||
| 10535 | fn_XImageFree (xpm_image); | ||
| 10536 | } | ||
| 10537 | if (xpm_mask && xpm_mask->bitmap) | ||
| 10538 | { | ||
| 10539 | /* The mask appears to be inverted compared with what we expect. | ||
| 10540 | TODO: invert our expectations. See other places where we | ||
| 10541 | have to invert bits because our idea of masks is backwards. */ | ||
| 10542 | HGDIOBJ old_obj; | ||
| 10543 | old_obj = SelectObject (hdc, xpm_mask->bitmap); | ||
| 10544 | |||
| 10545 | PatBlt (hdc, 0, 0, xpm_mask->width, xpm_mask->height, DSTINVERT); | ||
| 10546 | SelectObject (hdc, old_obj); | ||
| 10547 | |||
| 10548 | img->mask = xpm_mask->bitmap; | ||
| 10549 | fn_XImageFree (xpm_mask); | ||
| 10550 | DeleteDC (hdc); | ||
| 10551 | } | ||
| 10552 | |||
| 10553 | DeleteDC (hdc); | ||
| 10554 | |||
| 10483 | /* Remember allocated colors. */ | 10555 | /* Remember allocated colors. */ |
| 10484 | img->ncolors = attrs.nalloc_pixels; | 10556 | img->ncolors = attrs.nalloc_pixels; |
| 10485 | img->colors = (unsigned long *) xmalloc (img->ncolors | 10557 | img->colors = (unsigned long *) xmalloc (img->ncolors |
| @@ -10492,12 +10564,12 @@ xpm_load (f, img) | |||
| 10492 | xassert (img->width > 0 && img->height > 0); | 10564 | xassert (img->width > 0 && img->height > 0); |
| 10493 | 10565 | ||
| 10494 | /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */ | 10566 | /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */ |
| 10495 | BLOCK_INPUT; | 10567 | fn_XpmFreeAttributes (&attrs); |
| 10496 | XpmFreeAttributes (&attrs); | ||
| 10497 | UNBLOCK_INPUT; | ||
| 10498 | } | 10568 | } |
| 10499 | else | 10569 | else |
| 10500 | { | 10570 | { |
| 10571 | DeleteDC (hdc); | ||
| 10572 | |||
| 10501 | switch (rc) | 10573 | switch (rc) |
| 10502 | { | 10574 | { |
| 10503 | case XpmOpenFailed: | 10575 | case XpmOpenFailed: |
| @@ -15734,7 +15806,12 @@ init_external_image_libraries () | |||
| 15734 | HINSTANCE library; | 15806 | HINSTANCE library; |
| 15735 | 15807 | ||
| 15736 | #if HAVE_XPM | 15808 | #if HAVE_XPM |
| 15737 | define_image_type (&xpm_type); | 15809 | if ((library = LoadLibrary ("libXpm.dll"))) |
| 15810 | { | ||
| 15811 | if (init_xpm_functions (library)) | ||
| 15812 | define_image_type (&xpm_type); | ||
| 15813 | } | ||
| 15814 | |||
| 15738 | #endif | 15815 | #endif |
| 15739 | 15816 | ||
| 15740 | #if HAVE_JPEG | 15817 | #if HAVE_JPEG |