From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jason Rumney Newsgroups: gmane.emacs.devel Subject: W32 image patch (was Re: XPM via Lisp in the toolbar) Date: 15 Nov 2002 17:47:47 +0000 Sender: emacs-devel-admin@gnu.org Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1037663982 11370 80.91.224.249 (18 Nov 2002 23:59:42 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 18 Nov 2002 23:59:42 +0000 (UTC) Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18Dvnn-0002x5-00 for ; Tue, 19 Nov 2002 00:59:39 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18DvqE-0001mJ-00 for ; Tue, 19 Nov 2002 01:02:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18DvDQ-0006Pz-00; Mon, 18 Nov 2002 18:22:05 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18Ckn5-0001s7-00 for emacs-devel@gnu.org; Fri, 15 Nov 2002 13:02:03 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18Ckn0-0001qA-00 for emacs-devel@gnu.org; Fri, 15 Nov 2002 13:02:02 -0500 Original-Received: from rhenium.btinternet.com ([194.73.73.93] helo=rhenium) by monty-python.gnu.org with esmtp (Exim 4.10) id 18Ckmz-0001q1-00 for emacs-devel@gnu.org; Fri, 15 Nov 2002 13:01:57 -0500 Original-Received: from host213-1-162-38.in-addr.btopenworld.com ([213.1.162.38] helo=nyaumo.btinternet.com) by rhenium with esmtp (Exim 3.22 #15) id 18Ckmr-0000Yn-00 for emacs-devel@gnu.org; Fri, 15 Nov 2002 18:01:50 +0000 Original-Received: from nyaumo.btinternet.com (nyaumo.btinternet.com [127.0.0.1]) by nyaumo.btinternet.com (Postfix) with ESMTP id C00C84AE26 for ; Fri, 15 Nov 2002 17:47:48 +0000 (GMT) Original-To: emacs-devel@gnu.org In-Reply-To: Original-Lines: 30 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:9534 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:9534 --=-=-= Below is a patch to improve image support on MS-Windows. Hopefully it is enough to make images with masks work in the toolbar. I currently am unable to check this in, so if someone else with write access to CVS and access to MS-Windows to ensure the patch applies cleanly, compiles and works can check this in, it would be greatly appreciated. If this patch works as well for others as it does for me, then I'll take back what I said last week about needing to disable image support on Windows if we start pretesting from HEAD in the near future. 2002-11-15 Jason Rumney * w32term.c (x_draw_image_foreground, x_draw_image_glyph_string) (w32_draw_image_foreground_1): Handle image masks. (x_draw_image_glyph_string): Don't BitBlt transparently. * w32fns.c (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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=w32img.patch Content-Description: W32 image patch *** src/w32term.c.~1.170.~ Thu Nov 14 16:02:54 2002 --- src/w32term.c Fri Nov 15 15:42:01 2002 *************** x_draw_image_foreground (s) *** 3888,3945 **** if (s->img->pixmap) { ! #if 0 /* TODO: image mask */ if (s->img->mask) { ! /* We can't set both a clip mask and use XSetClipRectangles ! because the latter also sets a clip mask. We also can't ! trust on the shape extension to be available ! (XShapeCombineRegion). So, compute the rectangle to draw ! manually. */ ! unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin ! | GCFunction); ! XGCValues xgcv; ! XRectangle clip_rect, image_rect, r; ! ! xgcv.clip_mask = s->img->mask; ! xgcv.clip_x_origin = x; ! xgcv.clip_y_origin = y; ! xgcv.function = GXcopy; ! XChangeGC (s->display, s->gc, mask, &xgcv); ! ! w32_get_glyph_string_clip_rect (s, &clip_rect); ! image_rect.x = x; ! image_rect.y = y; ! image_rect.width = s->img->width; ! image_rect.height = s->img->height; ! if (IntersectRect (&r, &clip_rect, &image_rect)) ! XCopyArea (s->display, s->img->pixmap, s->window, s->gc, ! r.x - x, r.y - y, r.width, r.height, r.x, r.y); } else - #endif { ! HDC compat_hdc = CreateCompatibleDC (s->hdc); ! HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); ! HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); ! HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); ! x_set_glyph_string_clipping (s); ! ! SetTextColor (s->hdc, s->gc->foreground); ! SetBkColor (s->hdc, s->gc->background); ! #if 0 /* From w32bdf.c (which is from Meadow). */ ! BitBlt (s->hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, SRCCOPY); ! BitBlt (s->hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, 0xB8074A); ! #else BitBlt (s->hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, 0xE20746); ! #endif ! SelectObject (s->hdc, orig_brush); ! DeleteObject (fg_brush); ! SelectObject (compat_hdc, orig_obj); ! DeleteDC (compat_hdc); /* When the image has a mask, we can expect that at least part of a mouse highlight or a block cursor will --- 3888,3927 ---- if (s->img->pixmap) { ! HDC compat_hdc = CreateCompatibleDC (s->hdc); ! HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); ! HBRUSH orig_brush = SelectObject (s->hdc, fg_brush); ! HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); ! SetBkColor (compat_hdc, RGB (255, 255, 255)); ! SetTextColor (s->hdc, RGB (0, 0, 0)); ! x_set_glyph_string_clipping (s); ! if (s->img->mask) { ! HDC mask_dc = CreateCompatibleDC (s->hdc); ! HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask); ! ! SetTextColor (s->hdc, RGB (255, 255, 255)); ! SetBkColor (s->hdc, RGB (0, 0, 0)); ! ! BitBlt (s->hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, 0x990066); ! BitBlt (s->hdc, x, y, s->img->width, s->img->height, ! mask_dc, 0, 0, SRCAND); ! BitBlt (s->hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, 0x990066); ! ! SelectObject (mask_dc, mask_orig_obj); ! DeleteDC (mask_dc); } else { ! SetTextColor (s->hdc, s->gc->foreground); ! SetBkColor (s->hdc, s->gc->background); ! BitBlt (s->hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, NOTSRCCOPY); ! /* Meadow uses 0xE20746, previously SRCCOPY and 0xB8074A. */ /* When the image has a mask, we can expect that at least part of a mouse highlight or a block cursor will *************** x_draw_image_foreground (s) *** 3954,3961 **** w32_draw_rectangle (s->hdc, s->gc, x - r, y - r , s->img->width + r*2 - 1, s->img->height + r*2 - 1); } - w32_set_clip_rectangle (s->hdc, NULL); } } else w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width -1, --- 3936,3948 ---- w32_draw_rectangle (s->hdc, s->gc, x - r, y - r , s->img->width + r*2 - 1, s->img->height + r*2 - 1); } } + + w32_set_clip_rectangle (s->hdc, NULL); + SelectObject (s->hdc, orig_brush); + DeleteObject (fg_brush); + SelectObject (compat_hdc, orig_obj); + DeleteDC (compat_hdc); } else w32_draw_rectangle (s->hdc, s->gc, x, y, s->img->width -1, *************** w32_draw_image_foreground_1 (s, pixmap) *** 4040,4090 **** if (s->img->pixmap) { ! #if 0 /* TODO: image mask */ if (s->img->mask) { ! /* We can't set both a clip mask and use XSetClipRectangles ! because the latter also sets a clip mask. We also can't ! trust on the shape extension to be available ! (XShapeCombineRegion). So, compute the rectangle to draw ! manually. */ ! unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin ! | GCFunction); ! XGCValues xgcv; ! ! xgcv.clip_mask = s->img->mask; ! xgcv.clip_x_origin = x; ! xgcv.clip_y_origin = y; ! xgcv.function = GXcopy; ! XChangeGC (s->display, s->gc, mask, &xgcv); ! XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, ! 0, 0, s->img->width, s->img->height, x, y); ! XSetClipMask (s->display, s->gc, None); } else - #endif { ! HDC compat_hdc = CreateCompatibleDC (hdc); ! HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); ! HBRUSH orig_brush = SelectObject (hdc, fg_brush); ! HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); ! ! SetTextColor (hdc, s->gc->foreground); ! SetBkColor (hdc, s->gc->background); ! #if 0 /* From w32bdf.c (which is from Meadow). */ ! BitBlt (hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, SRCCOPY); ! BitBlt (hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, 0xB8074A); ! #else BitBlt (hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, 0xE20746); ! #endif ! SelectObject (hdc, orig_brush); ! DeleteObject (fg_brush); ! SelectObject (compat_hdc, orig_obj); ! DeleteDC (compat_hdc); /* When the image has a mask, we can expect that at least part of a mouse highlight or a block cursor will --- 4027,4061 ---- if (s->img->pixmap) { ! HDC compat_hdc = CreateCompatibleDC (hdc); ! HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground); ! HBRUSH orig_brush = SelectObject (hdc, fg_brush); ! HGDIOBJ orig_obj = SelectObject (compat_hdc, s->img->pixmap); ! if (s->img->mask) { ! HDC mask_dc = CreateCompatibleDC (hdc); ! HGDIOBJ mask_orig_obj = SelectObject (mask_dc, s->img->mask); ! SetTextColor (hdc, RGB (0, 0, 0)); ! SetBkColor (hdc, RGB (255, 255, 255)); ! BitBlt (hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, SRCINVERT); ! BitBlt (hdc, x, y, s->img->width, s->img->height, ! mask_dc, 0, 0, SRCAND); ! BitBlt (hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, SRCINVERT); ! ! SelectObject (mask_dc, mask_orig_obj); ! DeleteDC (mask_dc); } else { ! SetTextColor (hdc, s->gc->foreground); ! SetBkColor (hdc, s->gc->background); ! BitBlt (hdc, x, y, s->img->width, s->img->height, ! compat_hdc, 0, 0, NOTSRCCOPY); /* When the image has a mask, we can expect that at least part of a mouse highlight or a block cursor will *************** w32_draw_image_foreground_1 (s, pixmap) *** 4096,4105 **** { int r = s->img->relief; if (r < 0) r = -r; ! w32_draw_rectangle (s->hdc, s->gc, x - r, y - r , s->img->width + r*2 - 1, s->img->height + r*2 - 1); } } } else w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, --- 4067,4081 ---- { int r = s->img->relief; if (r < 0) r = -r; ! w32_draw_rectangle (hdc, s->gc, x - r, y - r , s->img->width + r*2 - 1, s->img->height + r*2 - 1); } } + + SelectObject (hdc, orig_brush); + DeleteObject (fg_brush); + SelectObject (compat_hdc, orig_obj); + DeleteDC (compat_hdc); } else w32_draw_rectangle (hdc, s->gc, x, y, s->img->width - 1, *************** x_draw_image_glyph_string (s) *** 4165,4173 **** if (height > s->img->height || s->img->hmargin || s->img->vmargin - #if 0 /* TODO: image mask */ || s->img->mask - #endif || s->img->pixmap == 0 || s->width != s->background_width) { --- 4141,4147 ---- *************** x_draw_image_glyph_string (s) *** 4177,4183 **** x = s->x; y = s->y + box_line_vwidth; ! #if 0 /* TODO: image mask */ if (s->img->mask) { /* Create a pixmap as large as the glyph string. Fill it --- 4151,4157 ---- x = s->x; y = s->y + box_line_vwidth; ! #if 0 /* TODO: figure out if we need to do this on Windows. */ if (s->img->mask) { /* Create a pixmap as large as the glyph string. Fill it *************** x_draw_image_glyph_string (s) *** 4235,4249 **** SetTextColor (s->hdc, s->gc->foreground); SetBkColor (s->hdc, s->gc->background); - #if 0 /* From w32bdf.c (which is from Meadow). */ BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, compat_hdc, 0, 0, SRCCOPY); ! BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, ! compat_hdc, 0, 0, 0xB8074A); ! #else ! BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, ! compat_hdc, 0, 0, 0xE20746); ! #endif SelectObject (s->hdc, orig_brush); DeleteObject (fg_brush); SelectObject (compat_hdc, orig_obj); --- 4209,4217 ---- SetTextColor (s->hdc, s->gc->foreground); SetBkColor (s->hdc, s->gc->background); BitBlt (s->hdc, s->x, s->y, s->background_width, s->height, compat_hdc, 0, 0, SRCCOPY); ! SelectObject (s->hdc, orig_brush); DeleteObject (fg_brush); SelectObject (compat_hdc, orig_obj); *** src/w32fns.c.~1.186.~ Thu Nov 14 16:02:51 2002 --- src/w32fns.c Fri Nov 15 15:39:34 2002 *************** w32_defined_color (f, color, color_def, *** 1948,1956 **** w32_color_ref = XUINT (tem) | 0x2000000; color_def->pixel = w32_color_ref; ! color_def->red = GetRValue (w32_color_ref); ! color_def->green = GetGValue (w32_color_ref); ! color_def->blue = GetBValue (w32_color_ref); return 1; } --- 1948,1956 ---- w32_color_ref = XUINT (tem) | 0x2000000; color_def->pixel = w32_color_ref; ! color_def->red = GetRValue (w32_color_ref) * 256; ! color_def->green = GetGValue (w32_color_ref) * 256; ! color_def->blue = GetBValue (w32_color_ref) * 256; return 1; } *************** DEFUN ("image-mask-p", Fimage_mask_p, Si *** 8540,8545 **** --- 8540,8546 ---- static struct image *make_image P_ ((Lisp_Object spec, unsigned hash)); static void free_image P_ ((struct frame *f, struct image *img)); + static void x_destroy_x_image P_ ((XImage *)); /* Allocate and return a new image structure for image specification *************** image_ascent (img, face) *** 8646,8663 **** /* Find the "best" corner color of a bitmap. XIMG is assumed to a device context with the bitmap selected. */ static COLORREF ! four_corners_best (ximg, width, height) ! HDC ximg; unsigned long width, height; { COLORREF corners[4], best; int i, best_count; ! /* Get the colors at the corners of ximg. */ ! corners[0] = GetPixel (ximg, 0, 0); ! corners[1] = GetPixel (ximg, width - 1, 0); ! corners[2] = GetPixel (ximg, width - 1, height - 1); ! corners[3] = GetPixel (ximg, 0, height - 1); /* Choose the most frequently found color as background. */ for (i = best_count = 0; i < 4; ++i) --- 8647,8664 ---- /* Find the "best" corner color of a bitmap. XIMG is assumed to a device context with the bitmap selected. */ static COLORREF ! four_corners_best (img_dc, width, height) ! HDC img_dc; unsigned long width, height; { COLORREF corners[4], best; int i, best_count; ! /* Get the colors at the corners of img_dc. */ ! corners[0] = GetPixel (img_dc, 0, 0); ! corners[1] = GetPixel (img_dc, width - 1, 0); ! corners[2] = GetPixel (img_dc, width - 1, height - 1); ! corners[3] = GetPixel (img_dc, 0, height - 1); /* Choose the most frequently found color as background. */ for (i = best_count = 0; i < 4; ++i) *************** four_corners_best (ximg, width, height) *** 8676,8707 **** } /* Return the `background' field of IMG. If IMG doesn't have one yet, ! it is guessed heuristically. If non-zero, XIMG is an existing XImage ! object to use for the heuristic. */ unsigned long ! image_background (img, f, ximg) struct image *img; struct frame *f; ! XImage *ximg; { if (! img->background_valid) /* IMG doesn't have a background yet, try to guess a reasonable value. */ { ! #if 0 /* TODO: Image support. */ ! int free_ximg = !ximg; ! if (! ximg) ! ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, ! 0, 0, img->width, img->height, ~0, ZPixmap); ! img->background = four_corners_best (ximg, img->width, img->height); if (free_ximg) ! XDestroyImage (ximg); img->background_valid = 1; - #endif } return img->background; --- 8677,8715 ---- } /* Return the `background' field of IMG. If IMG doesn't have one yet, ! it is guessed heuristically. If non-zero, IMG_DC is an existing ! device context with the image selected to use for the heuristic. */ unsigned long ! image_background (img, f, img_dc) struct image *img; struct frame *f; ! HDC img_dc; { if (! img->background_valid) /* IMG doesn't have a background yet, try to guess a reasonable value. */ { ! int free_ximg = !img_dc; ! HGDIOBJ prev; ! ! if (free_ximg) ! { ! HDC frame_dc = get_frame_dc (f); ! img_dc = CreateCompatibleDC (frame_dc); ! release_frame_dc (f, frame_dc); ! prev = SelectObject (img_dc, img->pixmap); ! } ! img->background = four_corners_best (img_dc, img->width, img->height); if (free_ximg) ! { ! SelectObject (img_dc, prev); ! DeleteDC (img_dc); ! } img->background_valid = 1; } return img->background; *************** image_background (img, f, ximg) *** 8715,8742 **** image_background_transparent (img, f, mask) struct image *img; struct frame *f; ! XImage *mask; { if (! img->background_transparent_valid) /* IMG doesn't have a background yet, try to guess a reasonable value. */ { - #if 0 /* TODO: Image support. */ if (img->mask) { int free_mask = !mask; ! if (! mask) ! mask = XGetImage (FRAME_X_DISPLAY (f), img->mask, ! 0, 0, img->width, img->height, ~0, ZPixmap); img->background_transparent = !four_corners_best (mask, img->width, img->height); if (free_mask) ! XDestroyImage (mask); } else - #endif img->background_transparent = 0; img->background_transparent_valid = 1; --- 8723,8757 ---- image_background_transparent (img, f, mask) struct image *img; struct frame *f; ! HDC mask; { if (! img->background_transparent_valid) /* IMG doesn't have a background yet, try to guess a reasonable value. */ { if (img->mask) { int free_mask = !mask; + HGDIOBJ prev; ! if (free_mask) ! { ! HDC frame_dc = get_frame_dc (f); ! mask = CreateCompatibleDC (frame_dc); ! release_frame_dc (f, frame_dc); ! ! prev = SelectObject (mask, img->mask); ! } img->background_transparent = !four_corners_best (mask, img->width, img->height); if (free_mask) ! { ! SelectObject (mask, prev); ! DeleteDC (mask); ! } } else img->background_transparent = 0; img->background_transparent_valid = 1; *************** x_alloc_image_color (f, img, color_name, *** 8879,8884 **** --- 8894,8900 ---- static void cache_image P_ ((struct frame *f, struct image *img)); static void postprocess_image P_ ((struct frame *, struct image *)); + static void x_disable_image P_ ((struct frame *, struct image *)); /* Return a new, initialized image cache that is allocated from the *************** postprocess_image (f, img) *** 9018,9024 **** struct frame *f; struct image *img; { - #if 0 /* TODO: image support. */ /* Manipulation of the image's mask. */ if (img->pixmap) { --- 9034,9039 ---- *************** postprocess_image (f, img) *** 9083,9089 **** Fplist_get (tem, QCcolor_adjustment)); } } - #endif } --- 9098,9103 ---- *************** forall_images_in_image_cache (f, fn) *** 9275,9281 **** static int x_create_x_image_and_pixmap P_ ((struct frame *, int, int, int, XImage **, Pixmap *)); - static void x_destroy_x_image P_ ((XImage *)); static void x_put_x_image P_ ((struct frame *, XImage *, Pixmap, int, int)); --- 9289,9294 ---- *************** x_create_x_image_and_pixmap (f, width, h *** 9338,9348 **** header->biCompression = BI_RGB; header->biClrUsed = palette_colors; hdc = get_frame_dc (f); /* Create a DIBSection and raster array for the bitmap, and store its handle in *pixmap. */ ! *pixmap = CreateDIBSection (hdc, &((*ximg)->info), DIB_RGB_COLORS, &((*ximg)->data), NULL, 0); /* Realize display palette and garbage all frames. */ --- 9351,9364 ---- header->biCompression = BI_RGB; header->biClrUsed = palette_colors; + /* TODO: fill in palette. */ + hdc = get_frame_dc (f); /* Create a DIBSection and raster array for the bitmap, and store its handle in *pixmap. */ ! *pixmap = CreateDIBSection (hdc, &((*ximg)->info), ! (depth < 16) ? DIB_PAL_COLORS : DIB_RGB_COLORS, &((*ximg)->data), NULL, 0); /* Realize display palette and garbage all frames. */ *************** x_put_x_image (f, ximg, pixmap, width, h *** 9388,9401 **** XImage *ximg; Pixmap pixmap; { ! ! #if TODO /* W32 specific image code. */ ! GC gc; ! ! xassert (interrupt_input_blocked); ! gc = XCreateGC (NULL, pixmap, 0, NULL); ! XPutImage (NULL, pixmap, gc, ximg, 0, 0, 0, 0, width, height); ! XFreeGC (NULL, gc); #endif } --- 9404,9413 ---- XImage *ximg; Pixmap pixmap; { ! #if 0 /* I don't think this is necessary looking at where it is used. */ ! HDC hdc = get_frame_dc (f); ! SetDIBits (hdc, pixmap, 0, height, ximg->data, &(ximg->info), DIB_RGB_COLORS); ! release_frame_dc (f, hdc); #endif } *************** xbm_load (f, img) *** 10065,10071 **** { struct image_keyword fmt[XBM_LAST]; Lisp_Object data; - int depth; unsigned long foreground = FRAME_FOREGROUND_PIXEL (f); unsigned long background = FRAME_BACKGROUND_PIXEL (f); char *bits; --- 10077,10082 ---- *************** xbm_load (f, img) *** 10127,10133 **** bits = XBOOL_VECTOR (data)->data; /* Create the pixmap. */ - depth = one_w32_display_info.n_cbits; img->pixmap = w32_create_pixmap_from_bitmap_data (img->width, img->height, bits); --- 10138,10143 ---- *************** xbm_load (f, img) *** 10200,10206 **** {":background", IMAGE_STRING_OR_NIL_VALUE, 0} }; ! /* Structure describing the image type XBM. */ static struct image_type xpm_type = { --- 10210,10216 ---- {":background", IMAGE_STRING_OR_NIL_VALUE, 0} }; ! /* Structure describing the image type XPM. */ static struct image_type xpm_type = { *************** x_to_xcolors (f, img, rgb_p) *** 10641,10653 **** { int x, y; XColor *colors, *p; ! XImage *ximg; colors = (XColor *) xmalloc (img->width * img->height * sizeof *colors); ! #if 0 /* TODO: implement image colors. */ ! /* Get the X image IMG->pixmap. */ ! ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, ! 0, 0, img->width, img->height, ~0, ZPixmap); /* Fill the `pixel' members of the XColor array. I wished there were an easy and portable way to circumvent XGetPixel. */ --- 10651,10666 ---- { int x, y; XColor *colors, *p; ! HDC hdc, bmpdc; ! HGDIOBJ prev; colors = (XColor *) xmalloc (img->width * img->height * sizeof *colors); ! ! /* Load the image into a memory device context. */ ! hdc = get_frame_dc (f); ! bmpdc = CreateCompatibleDC (hdc); ! release_frame_dc (f, hdc); ! prev = SelectObject (bmpdc, img->pixmap); /* Fill the `pixel' members of the XColor array. I wished there were an easy and portable way to circumvent XGetPixel. */ *************** x_to_xcolors (f, img, rgb_p) *** 10657,10670 **** XColor *row = p; for (x = 0; x < img->width; ++x, ++p) ! p->pixel = XGetPixel (ximg, x, y); ! if (rgb_p) ! x_query_colors (f, row, img->width); } ! XDestroyImage (ximg); ! #endif return colors; } --- 10670,10691 ---- XColor *row = p; for (x = 0; x < img->width; ++x, ++p) ! { ! /* TODO: palette support needed here? */ ! p->pixel = GetPixel (bmpdc, x, y); ! if (rgb_p) ! { ! p->red = 256 * GetRValue (p->pixel); ! p->green = 256 * GetGValue (p->pixel); ! p->blue = 256 * GetBValue (p->pixel); ! } ! } } ! SelectObject (bmpdc, prev); ! DeleteDC (bmpdc); ! return colors; } *************** x_from_xcolors (f, img, colors) *** 10723,10729 **** #if 0 /* TODO: color tables. */ pixel = lookup_rgb_color (f, p->red, p->green, p->blue); #else ! pixel = PALETTERGB (p->red, p->green, p->blue); #endif XPutPixel (oimg, x, y, pixel); } --- 10744,10750 ---- #if 0 /* TODO: color tables. */ pixel = lookup_rgb_color (f, p->red, p->green, p->blue); #else ! pixel = PALETTERGB (p->red / 256, p->green / 256, p->blue / 256); #endif XPutPixel (oimg, x, y, pixel); } *************** x_disable_image (f, img) *** 10916,10944 **** should. */ if (dpyinfo->n_planes * dpyinfo->n_cbits < 2 || cross_disabled_images) { ! #if 0 /* TODO: full image support */ ! Display *dpy = FRAME_X_DISPLAY (f); ! GC gc; ! ! gc = XCreateGC (dpy, img->pixmap, 0, NULL); ! XSetForeground (dpy, gc, BLACK_PIX_DEFAULT (f)); ! XDrawLine (dpy, img->pixmap, gc, 0, 0, ! img->width - 1, img->height - 1); ! XDrawLine (dpy, img->pixmap, gc, 0, img->height - 1, ! img->width - 1, 0); ! XFreeGC (dpy, gc); if (img->mask) { ! gc = XCreateGC (dpy, img->mask, 0, NULL); ! XSetForeground (dpy, gc, WHITE_PIX_DEFAULT (f)); ! XDrawLine (dpy, img->mask, gc, 0, 0, ! img->width - 1, img->height - 1); ! XDrawLine (dpy, img->mask, gc, 0, img->height - 1, ! img->width - 1, 0); ! XFreeGC (dpy, gc); } ! #endif } } --- 10937,10968 ---- should. */ if (dpyinfo->n_planes * dpyinfo->n_cbits < 2 || cross_disabled_images) { ! HDC hdc, bmpdc; ! HGDIOBJ prev; ! ! hdc = get_frame_dc (f); ! bmpdc = CreateCompatibleDC (hdc); ! release_frame_dc (f, hdc); ! ! prev = SelectObject (bmpdc, img->pixmap); ! ! SetTextColor (bmpdc, BLACK_PIX_DEFAULT (f)); ! MoveToEx (bmpdc, 0, 0, NULL); ! LineTo (bmpdc, img->width - 1, img->height - 1); ! MoveToEx (bmpdc, 0, img->height - 1, NULL); ! LineTo (bmpdc, img->width - 1, 0); if (img->mask) { ! SelectObject (bmpdc, img->mask); ! SetTextColor (bmpdc, WHITE_PIX_DEFAULT (f)); ! MoveToEx (bmpdc, 0, 0, NULL); ! LineTo (bmpdc, img->width - 1, img->height - 1); ! MoveToEx (bmpdc, 0, img->height - 1, NULL); ! LineTo (bmpdc, img->width - 1, 0); } ! SelectObject (bmpdc, prev); ! DeleteDC (bmpdc); } } *************** x_build_heuristic_mask (f, img, how) *** 10956,10985 **** struct image *img; Lisp_Object how; { ! #if 0 /* TODO: full image support. */ ! Display *dpy = FRAME_W32_DISPLAY (f); ! XImage *ximg, *mask_img; int x, y, rc, use_img_background; unsigned long bg = 0; if (img->mask) { ! XFreePixmap (FRAME_X_DISPLAY (f), img->mask); ! img->mask = None; img->background_transparent_valid = 0; } ! /* Create an image and pixmap serving as mask. */ ! rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1, ! &mask_img, &img->mask); ! if (!rc) ! return 0; ! ! /* Get the X image of IMG->pixmap. */ ! ximg = XGetImage (dpy, img->pixmap, 0, 0, img->width, img->height, ! ~0, ZPixmap); ! /* Determine the background color of ximg. If HOW is `(R G B)' take that as color. Otherwise, use the image's background color. */ use_img_background = 1; --- 10980,11011 ---- struct image *img; Lisp_Object how; { ! HDC img_dc, frame_dc; ! HGDIOBJ prev; ! char *mask_img; int x, y, rc, use_img_background; unsigned long bg = 0; + int row_width; if (img->mask) { ! DeleteObject (img->mask); ! img->mask = NULL; img->background_transparent_valid = 0; } ! /* Create the bit array serving as mask. */ ! row_width = (img->width + 7) / 8; ! mask_img = xmalloc (row_width * img->height); ! bzero (mask_img, row_width * img->height); ! ! /* Create a memory device context for IMG->pixmap. */ ! frame_dc = get_frame_dc (f); ! img_dc = CreateCompatibleDC (frame_dc); ! release_frame_dc (f, frame_dc); ! prev = SelectObject (img_dc, img->pixmap); ! /* Determine the background color of img_dc. If HOW is `(R G B)' take that as color. Otherwise, use the image's background color. */ use_img_background = 1; *************** x_build_heuristic_mask (f, img, how) *** 11003,11028 **** } if (use_img_background) ! bg = four_corners_best (ximg, img->width, img->height); /* Set all bits in mask_img to 1 whose color in ximg is different from the background color bg. */ for (y = 0; y < img->height; ++y) for (x = 0; x < img->width; ++x) ! XPutPixel (mask_img, x, y, XGetPixel (ximg, x, y) != bg); /* Fill in the background_transparent field while we have the mask handy. */ ! image_background_transparent (img, f, mask_img); /* Put mask_img into img->mask. */ - x_put_x_image (f, mask_img, img->mask, img->width, img->height); x_destroy_x_image (mask_img); ! XDestroyImage (ximg); return 1; - #else - return 0; - #endif } --- 11029,11061 ---- } if (use_img_background) ! bg = four_corners_best (img_dc, img->width, img->height); /* Set all bits in mask_img to 1 whose color in ximg is different from the background color bg. */ for (y = 0; y < img->height; ++y) for (x = 0; x < img->width; ++x) ! { ! COLORREF p = GetPixel (img_dc, x, y); ! if (p != bg) ! mask_img[y * row_width + x / 8] |= 1 << (x % 8); ! } ! ! /* Create the mask image. */ ! img->mask = w32_create_pixmap_from_bitmap_data (img->width, img->height, ! mask_img); /* Fill in the background_transparent field while we have the mask handy. */ ! SelectObject (img_dc, img->mask); ! ! image_background_transparent (img, f, img_dc); /* Put mask_img into img->mask. */ x_destroy_x_image (mask_img); ! SelectObject (img_dc, prev); ! DeleteDC (img_dc); return 1; } --=-=-=--