diff options
| author | Jason Rumney | 2002-11-15 18:59:29 +0000 |
|---|---|---|
| committer | Jason Rumney | 2002-11-15 18:59:29 +0000 |
| commit | 197edd3510a58777ef5ea3f4945e3e6176820631 (patch) | |
| tree | abff637443d765f053e9f93c00fb6132870e23f9 /src | |
| parent | d30591dcceac5cd7cf1c9cc7fa55abd7c847b7da (diff) | |
| download | emacs-197edd3510a58777ef5ea3f4945e3e6176820631.tar.gz emacs-197edd3510a58777ef5ea3f4945e3e6176820631.zip | |
(w32_defined_color): Adjust RGB values for Emacs.
(x_from_xcolors): Adjust RGB values for W32.
(image_background, image_background_transparent)
(postprocess_image, x_to_xcolors, x_disable_image)
(x_build_heuristic_mask): Adapt for W32 and enable.
(x_create_x_image_and_pixmap): Mark images with palettes as such.
(xbm_load): Remove unused variable.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32fns.c | 223 |
1 files changed, 128 insertions, 95 deletions
diff --git a/src/w32fns.c b/src/w32fns.c index bfdf34b15ce..19b4d90a79e 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -1948,9 +1948,9 @@ w32_defined_color (f, color, color_def, alloc) | |||
| 1948 | w32_color_ref = XUINT (tem) | 0x2000000; | 1948 | w32_color_ref = XUINT (tem) | 0x2000000; |
| 1949 | 1949 | ||
| 1950 | color_def->pixel = w32_color_ref; | 1950 | color_def->pixel = w32_color_ref; |
| 1951 | color_def->red = GetRValue (w32_color_ref); | 1951 | color_def->red = GetRValue (w32_color_ref) * 256; |
| 1952 | color_def->green = GetGValue (w32_color_ref); | 1952 | color_def->green = GetGValue (w32_color_ref) * 256; |
| 1953 | color_def->blue = GetBValue (w32_color_ref); | 1953 | color_def->blue = GetBValue (w32_color_ref) * 256; |
| 1954 | 1954 | ||
| 1955 | return 1; | 1955 | return 1; |
| 1956 | } | 1956 | } |
| @@ -8540,6 +8540,7 @@ or omitted means use the selected frame. */) | |||
| 8540 | 8540 | ||
| 8541 | static struct image *make_image P_ ((Lisp_Object spec, unsigned hash)); | 8541 | static struct image *make_image P_ ((Lisp_Object spec, unsigned hash)); |
| 8542 | static void free_image P_ ((struct frame *f, struct image *img)); | 8542 | static void free_image P_ ((struct frame *f, struct image *img)); |
| 8543 | static void x_destroy_x_image P_ ((XImage *)); | ||
| 8543 | 8544 | ||
| 8544 | 8545 | ||
| 8545 | /* Allocate and return a new image structure for image specification | 8546 | /* Allocate and return a new image structure for image specification |
| @@ -8646,18 +8647,18 @@ image_ascent (img, face) | |||
| 8646 | /* Find the "best" corner color of a bitmap. XIMG is assumed to a device | 8647 | /* Find the "best" corner color of a bitmap. XIMG is assumed to a device |
| 8647 | context with the bitmap selected. */ | 8648 | context with the bitmap selected. */ |
| 8648 | static COLORREF | 8649 | static COLORREF |
| 8649 | four_corners_best (ximg, width, height) | 8650 | four_corners_best (img_dc, width, height) |
| 8650 | HDC ximg; | 8651 | HDC img_dc; |
| 8651 | unsigned long width, height; | 8652 | unsigned long width, height; |
| 8652 | { | 8653 | { |
| 8653 | COLORREF corners[4], best; | 8654 | COLORREF corners[4], best; |
| 8654 | int i, best_count; | 8655 | int i, best_count; |
| 8655 | 8656 | ||
| 8656 | /* Get the colors at the corners of ximg. */ | 8657 | /* Get the colors at the corners of img_dc. */ |
| 8657 | corners[0] = GetPixel (ximg, 0, 0); | 8658 | corners[0] = GetPixel (img_dc, 0, 0); |
| 8658 | corners[1] = GetPixel (ximg, width - 1, 0); | 8659 | corners[1] = GetPixel (img_dc, width - 1, 0); |
| 8659 | corners[2] = GetPixel (ximg, width - 1, height - 1); | 8660 | corners[2] = GetPixel (img_dc, width - 1, height - 1); |
| 8660 | corners[3] = GetPixel (ximg, 0, height - 1); | 8661 | corners[3] = GetPixel (img_dc, 0, height - 1); |
| 8661 | 8662 | ||
| 8662 | /* Choose the most frequently found color as background. */ | 8663 | /* Choose the most frequently found color as background. */ |
| 8663 | for (i = best_count = 0; i < 4; ++i) | 8664 | for (i = best_count = 0; i < 4; ++i) |
| @@ -8676,32 +8677,39 @@ four_corners_best (ximg, width, height) | |||
| 8676 | } | 8677 | } |
| 8677 | 8678 | ||
| 8678 | /* Return the `background' field of IMG. If IMG doesn't have one yet, | 8679 | /* Return the `background' field of IMG. If IMG doesn't have one yet, |
| 8679 | it is guessed heuristically. If non-zero, XIMG is an existing XImage | 8680 | it is guessed heuristically. If non-zero, IMG_DC is an existing |
| 8680 | object to use for the heuristic. */ | 8681 | device context with the image selected to use for the heuristic. */ |
| 8681 | 8682 | ||
| 8682 | unsigned long | 8683 | unsigned long |
| 8683 | image_background (img, f, ximg) | 8684 | image_background (img, f, img_dc) |
| 8684 | struct image *img; | 8685 | struct image *img; |
| 8685 | struct frame *f; | 8686 | struct frame *f; |
| 8686 | XImage *ximg; | 8687 | HDC img_dc; |
| 8687 | { | 8688 | { |
| 8688 | if (! img->background_valid) | 8689 | if (! img->background_valid) |
| 8689 | /* IMG doesn't have a background yet, try to guess a reasonable value. */ | 8690 | /* IMG doesn't have a background yet, try to guess a reasonable value. */ |
| 8690 | { | 8691 | { |
| 8691 | #if 0 /* TODO: Image support. */ | 8692 | int free_ximg = !img_dc; |
| 8692 | int free_ximg = !ximg; | 8693 | HGDIOBJ prev; |
| 8694 | |||
| 8695 | if (free_ximg) | ||
| 8696 | { | ||
| 8697 | HDC frame_dc = get_frame_dc (f); | ||
| 8698 | img_dc = CreateCompatibleDC (frame_dc); | ||
| 8699 | release_frame_dc (f, frame_dc); | ||
| 8693 | 8700 | ||
| 8694 | if (! ximg) | 8701 | prev = SelectObject (img_dc, img->pixmap); |
| 8695 | ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, | 8702 | } |
| 8696 | 0, 0, img->width, img->height, ~0, ZPixmap); | ||
| 8697 | 8703 | ||
| 8698 | img->background = four_corners_best (ximg, img->width, img->height); | 8704 | img->background = four_corners_best (img_dc, img->width, img->height); |
| 8699 | 8705 | ||
| 8700 | if (free_ximg) | 8706 | if (free_ximg) |
| 8701 | XDestroyImage (ximg); | 8707 | { |
| 8708 | SelectObject (img_dc, prev); | ||
| 8709 | DeleteDC (img_dc); | ||
| 8710 | } | ||
| 8702 | 8711 | ||
| 8703 | img->background_valid = 1; | 8712 | img->background_valid = 1; |
| 8704 | #endif | ||
| 8705 | } | 8713 | } |
| 8706 | 8714 | ||
| 8707 | return img->background; | 8715 | return img->background; |
| @@ -8715,28 +8723,35 @@ int | |||
| 8715 | image_background_transparent (img, f, mask) | 8723 | image_background_transparent (img, f, mask) |
| 8716 | struct image *img; | 8724 | struct image *img; |
| 8717 | struct frame *f; | 8725 | struct frame *f; |
| 8718 | XImage *mask; | 8726 | HDC mask; |
| 8719 | { | 8727 | { |
| 8720 | if (! img->background_transparent_valid) | 8728 | if (! img->background_transparent_valid) |
| 8721 | /* IMG doesn't have a background yet, try to guess a reasonable value. */ | 8729 | /* IMG doesn't have a background yet, try to guess a reasonable value. */ |
| 8722 | { | 8730 | { |
| 8723 | #if 0 /* TODO: Image support. */ | ||
| 8724 | if (img->mask) | 8731 | if (img->mask) |
| 8725 | { | 8732 | { |
| 8726 | int free_mask = !mask; | 8733 | int free_mask = !mask; |
| 8734 | HGDIOBJ prev; | ||
| 8735 | |||
| 8736 | if (free_mask) | ||
| 8737 | { | ||
| 8738 | HDC frame_dc = get_frame_dc (f); | ||
| 8739 | mask = CreateCompatibleDC (frame_dc); | ||
| 8740 | release_frame_dc (f, frame_dc); | ||
| 8727 | 8741 | ||
| 8728 | if (! mask) | 8742 | prev = SelectObject (mask, img->mask); |
| 8729 | mask = XGetImage (FRAME_X_DISPLAY (f), img->mask, | 8743 | } |
| 8730 | 0, 0, img->width, img->height, ~0, ZPixmap); | ||
| 8731 | 8744 | ||
| 8732 | img->background_transparent | 8745 | img->background_transparent |
| 8733 | = !four_corners_best (mask, img->width, img->height); | 8746 | = !four_corners_best (mask, img->width, img->height); |
| 8734 | 8747 | ||
| 8735 | if (free_mask) | 8748 | if (free_mask) |
| 8736 | XDestroyImage (mask); | 8749 | { |
| 8750 | SelectObject (mask, prev); | ||
| 8751 | DeleteDC (mask); | ||
| 8752 | } | ||
| 8737 | } | 8753 | } |
| 8738 | else | 8754 | else |
| 8739 | #endif | ||
| 8740 | img->background_transparent = 0; | 8755 | img->background_transparent = 0; |
| 8741 | 8756 | ||
| 8742 | img->background_transparent_valid = 1; | 8757 | img->background_transparent_valid = 1; |
| @@ -8879,6 +8894,7 @@ x_alloc_image_color (f, img, color_name, dflt) | |||
| 8879 | 8894 | ||
| 8880 | static void cache_image P_ ((struct frame *f, struct image *img)); | 8895 | static void cache_image P_ ((struct frame *f, struct image *img)); |
| 8881 | static void postprocess_image P_ ((struct frame *, struct image *)); | 8896 | static void postprocess_image P_ ((struct frame *, struct image *)); |
| 8897 | static void x_disable_image P_ ((struct frame *, struct image *)); | ||
| 8882 | 8898 | ||
| 8883 | 8899 | ||
| 8884 | /* Return a new, initialized image cache that is allocated from the | 8900 | /* Return a new, initialized image cache that is allocated from the |
| @@ -9018,7 +9034,6 @@ postprocess_image (f, img) | |||
| 9018 | struct frame *f; | 9034 | struct frame *f; |
| 9019 | struct image *img; | 9035 | struct image *img; |
| 9020 | { | 9036 | { |
| 9021 | #if 0 /* TODO: image support. */ | ||
| 9022 | /* Manipulation of the image's mask. */ | 9037 | /* Manipulation of the image's mask. */ |
| 9023 | if (img->pixmap) | 9038 | if (img->pixmap) |
| 9024 | { | 9039 | { |
| @@ -9083,7 +9098,6 @@ postprocess_image (f, img) | |||
| 9083 | Fplist_get (tem, QCcolor_adjustment)); | 9098 | Fplist_get (tem, QCcolor_adjustment)); |
| 9084 | } | 9099 | } |
| 9085 | } | 9100 | } |
| 9086 | #endif | ||
| 9087 | } | 9101 | } |
| 9088 | 9102 | ||
| 9089 | 9103 | ||
| @@ -9275,7 +9289,6 @@ forall_images_in_image_cache (f, fn) | |||
| 9275 | 9289 | ||
| 9276 | static int x_create_x_image_and_pixmap P_ ((struct frame *, int, int, int, | 9290 | static int x_create_x_image_and_pixmap P_ ((struct frame *, int, int, int, |
| 9277 | XImage **, Pixmap *)); | 9291 | XImage **, Pixmap *)); |
| 9278 | static void x_destroy_x_image P_ ((XImage *)); | ||
| 9279 | static void x_put_x_image P_ ((struct frame *, XImage *, Pixmap, int, int)); | 9292 | static void x_put_x_image P_ ((struct frame *, XImage *, Pixmap, int, int)); |
| 9280 | 9293 | ||
| 9281 | 9294 | ||
| @@ -9338,11 +9351,14 @@ x_create_x_image_and_pixmap (f, width, height, depth, ximg, pixmap) | |||
| 9338 | header->biCompression = BI_RGB; | 9351 | header->biCompression = BI_RGB; |
| 9339 | header->biClrUsed = palette_colors; | 9352 | header->biClrUsed = palette_colors; |
| 9340 | 9353 | ||
| 9354 | /* TODO: fill in palette. */ | ||
| 9355 | |||
| 9341 | hdc = get_frame_dc (f); | 9356 | hdc = get_frame_dc (f); |
| 9342 | 9357 | ||
| 9343 | /* Create a DIBSection and raster array for the bitmap, | 9358 | /* Create a DIBSection and raster array for the bitmap, |
| 9344 | and store its handle in *pixmap. */ | 9359 | and store its handle in *pixmap. */ |
| 9345 | *pixmap = CreateDIBSection (hdc, &((*ximg)->info), DIB_RGB_COLORS, | 9360 | *pixmap = CreateDIBSection (hdc, &((*ximg)->info), |
| 9361 | (depth < 16) ? DIB_PAL_COLORS : DIB_RGB_COLORS, | ||
| 9346 | &((*ximg)->data), NULL, 0); | 9362 | &((*ximg)->data), NULL, 0); |
| 9347 | 9363 | ||
| 9348 | /* Realize display palette and garbage all frames. */ | 9364 | /* Realize display palette and garbage all frames. */ |
| @@ -9388,14 +9404,10 @@ x_put_x_image (f, ximg, pixmap, width, height) | |||
| 9388 | XImage *ximg; | 9404 | XImage *ximg; |
| 9389 | Pixmap pixmap; | 9405 | Pixmap pixmap; |
| 9390 | { | 9406 | { |
| 9391 | 9407 | #if 0 /* I don't think this is necessary looking at where it is used. */ | |
| 9392 | #if TODO /* W32 specific image code. */ | 9408 | HDC hdc = get_frame_dc (f); |
| 9393 | GC gc; | 9409 | SetDIBits (hdc, pixmap, 0, height, ximg->data, &(ximg->info), DIB_RGB_COLORS); |
| 9394 | 9410 | release_frame_dc (f, hdc); | |
| 9395 | xassert (interrupt_input_blocked); | ||
| 9396 | gc = XCreateGC (NULL, pixmap, 0, NULL); | ||
| 9397 | XPutImage (NULL, pixmap, gc, ximg, 0, 0, 0, 0, width, height); | ||
| 9398 | XFreeGC (NULL, gc); | ||
| 9399 | #endif | 9411 | #endif |
| 9400 | } | 9412 | } |
| 9401 | 9413 | ||
| @@ -10065,7 +10077,6 @@ xbm_load (f, img) | |||
| 10065 | { | 10077 | { |
| 10066 | struct image_keyword fmt[XBM_LAST]; | 10078 | struct image_keyword fmt[XBM_LAST]; |
| 10067 | Lisp_Object data; | 10079 | Lisp_Object data; |
| 10068 | int depth; | ||
| 10069 | unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); | 10080 | unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); |
| 10070 | unsigned long background = FRAME_BACKGROUND_PIXEL (f); | 10081 | unsigned long background = FRAME_BACKGROUND_PIXEL (f); |
| 10071 | char *bits; | 10082 | char *bits; |
| @@ -10127,7 +10138,6 @@ xbm_load (f, img) | |||
| 10127 | bits = XBOOL_VECTOR (data)->data; | 10138 | bits = XBOOL_VECTOR (data)->data; |
| 10128 | 10139 | ||
| 10129 | /* Create the pixmap. */ | 10140 | /* Create the pixmap. */ |
| 10130 | depth = one_w32_display_info.n_cbits; | ||
| 10131 | img->pixmap | 10141 | img->pixmap |
| 10132 | = w32_create_pixmap_from_bitmap_data (img->width, img->height, | 10142 | = w32_create_pixmap_from_bitmap_data (img->width, img->height, |
| 10133 | bits); | 10143 | bits); |
| @@ -10200,7 +10210,7 @@ static struct image_keyword xpm_format[XPM_LAST] = | |||
| 10200 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} | 10210 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} |
| 10201 | }; | 10211 | }; |
| 10202 | 10212 | ||
| 10203 | /* Structure describing the image type XBM. */ | 10213 | /* Structure describing the image type XPM. */ |
| 10204 | 10214 | ||
| 10205 | static struct image_type xpm_type = | 10215 | static struct image_type xpm_type = |
| 10206 | { | 10216 | { |
| @@ -10641,13 +10651,16 @@ x_to_xcolors (f, img, rgb_p) | |||
| 10641 | { | 10651 | { |
| 10642 | int x, y; | 10652 | int x, y; |
| 10643 | XColor *colors, *p; | 10653 | XColor *colors, *p; |
| 10644 | XImage *ximg; | 10654 | HDC hdc, bmpdc; |
| 10655 | HGDIOBJ prev; | ||
| 10645 | 10656 | ||
| 10646 | colors = (XColor *) xmalloc (img->width * img->height * sizeof *colors); | 10657 | colors = (XColor *) xmalloc (img->width * img->height * sizeof *colors); |
| 10647 | #if 0 /* TODO: implement image colors. */ | 10658 | |
| 10648 | /* Get the X image IMG->pixmap. */ | 10659 | /* Load the image into a memory device context. */ |
| 10649 | ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, | 10660 | hdc = get_frame_dc (f); |
| 10650 | 0, 0, img->width, img->height, ~0, ZPixmap); | 10661 | bmpdc = CreateCompatibleDC (hdc); |
| 10662 | release_frame_dc (f, hdc); | ||
| 10663 | prev = SelectObject (bmpdc, img->pixmap); | ||
| 10651 | 10664 | ||
| 10652 | /* Fill the `pixel' members of the XColor array. I wished there | 10665 | /* Fill the `pixel' members of the XColor array. I wished there |
| 10653 | were an easy and portable way to circumvent XGetPixel. */ | 10666 | were an easy and portable way to circumvent XGetPixel. */ |
| @@ -10657,14 +10670,22 @@ x_to_xcolors (f, img, rgb_p) | |||
| 10657 | XColor *row = p; | 10670 | XColor *row = p; |
| 10658 | 10671 | ||
| 10659 | for (x = 0; x < img->width; ++x, ++p) | 10672 | for (x = 0; x < img->width; ++x, ++p) |
| 10660 | p->pixel = XGetPixel (ximg, x, y); | 10673 | { |
| 10674 | /* TODO: palette support needed here? */ | ||
| 10675 | p->pixel = GetPixel (bmpdc, x, y); | ||
| 10661 | 10676 | ||
| 10662 | if (rgb_p) | 10677 | if (rgb_p) |
| 10663 | x_query_colors (f, row, img->width); | 10678 | { |
| 10679 | p->red = 256 * GetRValue (p->pixel); | ||
| 10680 | p->green = 256 * GetGValue (p->pixel); | ||
| 10681 | p->blue = 256 * GetBValue (p->pixel); | ||
| 10682 | } | ||
| 10683 | } | ||
| 10664 | } | 10684 | } |
| 10665 | 10685 | ||
| 10666 | XDestroyImage (ximg); | 10686 | SelectObject (bmpdc, prev); |
| 10667 | #endif | 10687 | DeleteDC (bmpdc); |
| 10688 | |||
| 10668 | return colors; | 10689 | return colors; |
| 10669 | } | 10690 | } |
| 10670 | 10691 | ||
| @@ -10723,7 +10744,7 @@ x_from_xcolors (f, img, colors) | |||
| 10723 | #if 0 /* TODO: color tables. */ | 10744 | #if 0 /* TODO: color tables. */ |
| 10724 | pixel = lookup_rgb_color (f, p->red, p->green, p->blue); | 10745 | pixel = lookup_rgb_color (f, p->red, p->green, p->blue); |
| 10725 | #else | 10746 | #else |
| 10726 | pixel = PALETTERGB (p->red, p->green, p->blue); | 10747 | pixel = PALETTERGB (p->red / 256, p->green / 256, p->blue / 256); |
| 10727 | #endif | 10748 | #endif |
| 10728 | XPutPixel (oimg, x, y, pixel); | 10749 | XPutPixel (oimg, x, y, pixel); |
| 10729 | } | 10750 | } |
| @@ -10916,29 +10937,32 @@ x_disable_image (f, img) | |||
| 10916 | should. */ | 10937 | should. */ |
| 10917 | if (dpyinfo->n_planes * dpyinfo->n_cbits < 2 || cross_disabled_images) | 10938 | if (dpyinfo->n_planes * dpyinfo->n_cbits < 2 || cross_disabled_images) |
| 10918 | { | 10939 | { |
| 10919 | #if 0 /* TODO: full image support */ | 10940 | HDC hdc, bmpdc; |
| 10920 | Display *dpy = FRAME_X_DISPLAY (f); | 10941 | HGDIOBJ prev; |
| 10921 | GC gc; | 10942 | |
| 10943 | hdc = get_frame_dc (f); | ||
| 10944 | bmpdc = CreateCompatibleDC (hdc); | ||
| 10945 | release_frame_dc (f, hdc); | ||
| 10946 | |||
| 10947 | prev = SelectObject (bmpdc, img->pixmap); | ||
| 10922 | 10948 | ||
| 10923 | gc = XCreateGC (dpy, img->pixmap, 0, NULL); | 10949 | SetTextColor (bmpdc, BLACK_PIX_DEFAULT (f)); |
| 10924 | XSetForeground (dpy, gc, BLACK_PIX_DEFAULT (f)); | 10950 | MoveToEx (bmpdc, 0, 0, NULL); |
| 10925 | XDrawLine (dpy, img->pixmap, gc, 0, 0, | 10951 | LineTo (bmpdc, img->width - 1, img->height - 1); |
| 10926 | img->width - 1, img->height - 1); | 10952 | MoveToEx (bmpdc, 0, img->height - 1, NULL); |
| 10927 | XDrawLine (dpy, img->pixmap, gc, 0, img->height - 1, | 10953 | LineTo (bmpdc, img->width - 1, 0); |
| 10928 | img->width - 1, 0); | ||
| 10929 | XFreeGC (dpy, gc); | ||
| 10930 | 10954 | ||
| 10931 | if (img->mask) | 10955 | if (img->mask) |
| 10932 | { | 10956 | { |
| 10933 | gc = XCreateGC (dpy, img->mask, 0, NULL); | 10957 | SelectObject (bmpdc, img->mask); |
| 10934 | XSetForeground (dpy, gc, WHITE_PIX_DEFAULT (f)); | 10958 | SetTextColor (bmpdc, WHITE_PIX_DEFAULT (f)); |
| 10935 | XDrawLine (dpy, img->mask, gc, 0, 0, | 10959 | MoveToEx (bmpdc, 0, 0, NULL); |
| 10936 | img->width - 1, img->height - 1); | 10960 | LineTo (bmpdc, img->width - 1, img->height - 1); |
| 10937 | XDrawLine (dpy, img->mask, gc, 0, img->height - 1, | 10961 | MoveToEx (bmpdc, 0, img->height - 1, NULL); |
| 10938 | img->width - 1, 0); | 10962 | LineTo (bmpdc, img->width - 1, 0); |
| 10939 | XFreeGC (dpy, gc); | ||
| 10940 | } | 10963 | } |
| 10941 | #endif | 10964 | SelectObject (bmpdc, prev); |
| 10965 | DeleteDC (bmpdc); | ||
| 10942 | } | 10966 | } |
| 10943 | } | 10967 | } |
| 10944 | 10968 | ||
| @@ -10956,30 +10980,32 @@ x_build_heuristic_mask (f, img, how) | |||
| 10956 | struct image *img; | 10980 | struct image *img; |
| 10957 | Lisp_Object how; | 10981 | Lisp_Object how; |
| 10958 | { | 10982 | { |
| 10959 | #if 0 /* TODO: full image support. */ | 10983 | HDC img_dc, frame_dc; |
| 10960 | Display *dpy = FRAME_W32_DISPLAY (f); | 10984 | HGDIOBJ prev; |
| 10961 | XImage *ximg, *mask_img; | 10985 | char *mask_img; |
| 10962 | int x, y, rc, use_img_background; | 10986 | int x, y, rc, use_img_background; |
| 10963 | unsigned long bg = 0; | 10987 | unsigned long bg = 0; |
| 10988 | int row_width; | ||
| 10964 | 10989 | ||
| 10965 | if (img->mask) | 10990 | if (img->mask) |
| 10966 | { | 10991 | { |
| 10967 | XFreePixmap (FRAME_X_DISPLAY (f), img->mask); | 10992 | DeleteObject (img->mask); |
| 10968 | img->mask = None; | 10993 | img->mask = NULL; |
| 10969 | img->background_transparent_valid = 0; | 10994 | img->background_transparent_valid = 0; |
| 10970 | } | 10995 | } |
| 10971 | 10996 | ||
| 10972 | /* Create an image and pixmap serving as mask. */ | 10997 | /* Create the bit array serving as mask. */ |
| 10973 | rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1, | 10998 | row_width = (img->width + 7) / 8; |
| 10974 | &mask_img, &img->mask); | 10999 | mask_img = xmalloc (row_width * img->height); |
| 10975 | if (!rc) | 11000 | bzero (mask_img, row_width * img->height); |
| 10976 | return 0; | ||
| 10977 | 11001 | ||
| 10978 | /* Get the X image of IMG->pixmap. */ | 11002 | /* Create a memory device context for IMG->pixmap. */ |
| 10979 | ximg = XGetImage (dpy, img->pixmap, 0, 0, img->width, img->height, | 11003 | frame_dc = get_frame_dc (f); |
| 10980 | ~0, ZPixmap); | 11004 | img_dc = CreateCompatibleDC (frame_dc); |
| 11005 | release_frame_dc (f, frame_dc); | ||
| 11006 | prev = SelectObject (img_dc, img->pixmap); | ||
| 10981 | 11007 | ||
| 10982 | /* Determine the background color of ximg. If HOW is `(R G B)' | 11008 | /* Determine the background color of img_dc. If HOW is `(R G B)' |
| 10983 | take that as color. Otherwise, use the image's background color. */ | 11009 | take that as color. Otherwise, use the image's background color. */ |
| 10984 | use_img_background = 1; | 11010 | use_img_background = 1; |
| 10985 | 11011 | ||
| @@ -11003,26 +11029,33 @@ x_build_heuristic_mask (f, img, how) | |||
| 11003 | } | 11029 | } |
| 11004 | 11030 | ||
| 11005 | if (use_img_background) | 11031 | if (use_img_background) |
| 11006 | bg = four_corners_best (ximg, img->width, img->height); | 11032 | bg = four_corners_best (img_dc, img->width, img->height); |
| 11007 | 11033 | ||
| 11008 | /* Set all bits in mask_img to 1 whose color in ximg is different | 11034 | /* Set all bits in mask_img to 1 whose color in ximg is different |
| 11009 | from the background color bg. */ | 11035 | from the background color bg. */ |
| 11010 | for (y = 0; y < img->height; ++y) | 11036 | for (y = 0; y < img->height; ++y) |
| 11011 | for (x = 0; x < img->width; ++x) | 11037 | for (x = 0; x < img->width; ++x) |
| 11012 | XPutPixel (mask_img, x, y, XGetPixel (ximg, x, y) != bg); | 11038 | { |
| 11039 | COLORREF p = GetPixel (img_dc, x, y); | ||
| 11040 | if (p != bg) | ||
| 11041 | mask_img[y * row_width + x / 8] |= 1 << (x % 8); | ||
| 11042 | } | ||
| 11043 | |||
| 11044 | /* Create the mask image. */ | ||
| 11045 | img->mask = w32_create_pixmap_from_bitmap_data (img->width, img->height, | ||
| 11046 | mask_img); | ||
| 11013 | 11047 | ||
| 11014 | /* Fill in the background_transparent field while we have the mask handy. */ | 11048 | /* Fill in the background_transparent field while we have the mask handy. */ |
| 11015 | image_background_transparent (img, f, mask_img); | 11049 | SelectObject (img_dc, img->mask); |
| 11050 | |||
| 11051 | image_background_transparent (img, f, img_dc); | ||
| 11016 | 11052 | ||
| 11017 | /* Put mask_img into img->mask. */ | 11053 | /* Put mask_img into img->mask. */ |
| 11018 | x_put_x_image (f, mask_img, img->mask, img->width, img->height); | ||
| 11019 | x_destroy_x_image (mask_img); | 11054 | x_destroy_x_image (mask_img); |
| 11020 | XDestroyImage (ximg); | 11055 | SelectObject (img_dc, prev); |
| 11056 | DeleteDC (img_dc); | ||
| 11021 | 11057 | ||
| 11022 | return 1; | 11058 | return 1; |
| 11023 | #else | ||
| 11024 | return 0; | ||
| 11025 | #endif | ||
| 11026 | } | 11059 | } |
| 11027 | 11060 | ||
| 11028 | 11061 | ||