From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.devel Subject: Re: image-size Date: Wed, 26 Jun 2013 17:25:06 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: <837ghopy8a.fsf@gnu.org> <83zjukog7h.fsf@gnu.org> <83txksodgv.fsf@gnu.org> <83r4fwocqd.fsf@gnu.org> <83ppvgoaw9.fsf@gnu.org> <83mwqko9ge.fsf@gnu.org> <83k3loo66g.fsf@gnu.org> <2D9A8A78-829E-4AEC-BA3E-9409A1457053@swipnet.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1372235131 7605 80.91.229.3 (26 Jun 2013 08:25:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Jun 2013 08:25:31 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 26 10:25:32 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Url2h-00063K-6s for ged-emacs-devel@m.gmane.org; Wed, 26 Jun 2013 10:25:31 +0200 Original-Received: from localhost ([::1]:44117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Url2g-00018M-LJ for ged-emacs-devel@m.gmane.org; Wed, 26 Jun 2013 04:25:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Url2Y-00014j-8c for emacs-devel@gnu.org; Wed, 26 Jun 2013 04:25:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Url2R-0002mj-9C for emacs-devel@gnu.org; Wed, 26 Jun 2013 04:25:22 -0400 Original-Received: from mathmail.math.s.chiba-u.ac.jp ([133.82.132.2]:54343) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Url2Q-0002gM-04 for emacs-devel@gnu.org; Wed, 26 Jun 2013 04:25:15 -0400 Original-Received: from church.math.s.chiba-u.ac.jp (church [133.82.132.36]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id D5B36C055D for ; Wed, 26 Jun 2013 17:25:06 +0900 (JST) In-Reply-To: User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (=?ISO-8859-4?Q?Shij=F2?=) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 133.82.132.2 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:161078 Archived-At: >>>>> On Fri, 21 Jun 2013 08:27:58 +0200, Lars Magne Ingebrigtsen said: >> Right. And as I mentioned in (*), a possible way to solve this >> problem is to defer the creation of Pixmap (server side resource) >> from XImage (client side resource) until the actual display happens >> (i.e., at prepare_image_for_display rather than lookup_image), so >> as to avoid unnecessary round trip of image data between the X11 >> server and client. > I think that sounds like a brilliant idea. You wouldn't have a > patch that does that, by any chance? :-) Could you try this? It doesn't defer the allocation of Pixmap actually, but defers image data transfer by XPutImage (and also by XGetImage in the case of postprocessing) until the actual display happens. YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp === modified file 'src/image.c' *** src/image.c 2013-06-23 19:24:27 +0000 --- src/image.c 2013-06-26 08:17:12 +0000 *************** *** 106,113 **** #define GET_PIXEL(ximg, x, y) XGetPixel (ximg, x, y) #define NO_PIXMAP 0 - #define ZPixmap 0 - #define PIX_MASK_RETAIN 0 #define PIX_MASK_DRAW 1 --- 106,111 ---- *************** *** 146,161 **** data more than once will not be caught. */ #ifdef HAVE_NS - XImagePtr - XGetImage (Display *display, Pixmap pixmap, int x, int y, - unsigned int width, unsigned int height, - unsigned long plane_mask, int format) - { - /* TODO: not sure what this function is supposed to do.. */ - ns_retain_object (pixmap); - return pixmap; - } - /* Use with images created by ns_image_for_XPM. */ unsigned long XGetPixel (XImagePtr ximage, int x, int y) --- 144,149 ---- *************** *** 435,442 **** --- 423,445 ---- XImagePtr *, Pixmap *); static void x_destroy_x_image (XImagePtr ximg); + #ifdef HAVE_NTGUI + static XImagePtr_or_DC image_get_x_image_or_dc (struct frame *, struct image *, + bool, HGDIOBJ *); + static void image_unget_x_image_or_dc (XImagePtr_or_DC, HGDIOBJ); + #else + static XImagePtr image_get_x_image (struct frame *, struct image *, bool); + static void image_unget_x_image (XImagePtr); + #define image_get_x_image_or_dc(f, img, mask_p, dummy) \ + image_get_x_image (f, img, mask_p) + #define image_unget_x_image_or_dc(ximg, dummy) \ + image_unget_x_image (ximg) + #endif + #ifdef HAVE_X_WINDOWS + static void image_sync_to_pixmaps (struct frame *, struct image *); + /* Useful functions defined in the section `Image type independent image structures' below. */ *************** *** 1050,1055 **** --- 1053,1066 ---- if (img->pixmap == NO_PIXMAP && !img->load_failed_p) img->load_failed_p = ! img->type->load (f, img); + #ifdef HAVE_X_WINDOWS + if (!img->load_failed_p) + { + block_input (); + image_sync_to_pixmaps (f, img); + unblock_input (); + } + #endif } *************** *** 1145,1169 **** #ifdef HAVE_NTGUI - #define Destroy_Image(img_dc, prev) \ - do { SelectObject (img_dc, prev); DeleteDC (img_dc); } while (0) - #define Free_Pixmap(display, pixmap) \ DeleteObject (pixmap) #elif defined (HAVE_NS) - #define Destroy_Image(ximg, dummy) \ - ns_release_object (ximg) - #define Free_Pixmap(display, pixmap) \ ns_release_object (pixmap) #else - #define Destroy_Image(ximg, dummy) \ - XDestroyImage (ximg) - #define Free_Pixmap(display, pixmap) \ XFreePixmap (display, pixmap) --- 1156,1171 ---- *************** *** 1187,1208 **** #endif /* HAVE_NTGUI */ if (free_ximg) ! { ! #ifndef HAVE_NTGUI ! ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, ! 0, 0, img->width, img->height, ~0, ZPixmap); ! #else ! HDC frame_dc = get_frame_dc (f); ! ximg = CreateCompatibleDC (frame_dc); ! release_frame_dc (f, frame_dc); ! prev = SelectObject (ximg, img->pixmap); ! #endif /* !HAVE_NTGUI */ ! } img->background = four_corners_best (ximg, img->corners, img->width, img->height); if (free_ximg) ! Destroy_Image (ximg, prev); img->background_valid = 1; } --- 1189,1200 ---- #endif /* HAVE_NTGUI */ if (free_ximg) ! ximg = image_get_x_image_or_dc (f, img, 0, &prev); img->background = four_corners_best (ximg, img->corners, img->width, img->height); if (free_ximg) ! image_unget_x_image_or_dc (ximg, prev); img->background_valid = 1; } *************** *** 1228,1250 **** #endif /* HAVE_NTGUI */ if (free_mask) ! { ! #ifndef HAVE_NTGUI ! mask = XGetImage (FRAME_X_DISPLAY (f), img->mask, ! 0, 0, img->width, img->height, ~0, ZPixmap); ! #else ! HDC frame_dc = get_frame_dc (f); ! mask = CreateCompatibleDC (frame_dc); ! release_frame_dc (f, frame_dc); ! prev = SelectObject (mask, img->mask); ! #endif /* HAVE_NTGUI */ ! } img->background_transparent = (four_corners_best (mask, img->corners, img->width, img->height) == PIX_MASK_RETAIN); if (free_mask) ! Destroy_Image (mask, prev); } else img->background_transparent = 0; --- 1220,1232 ---- #endif /* HAVE_NTGUI */ if (free_mask) ! mask = image_get_x_image_or_dc (f, img, 1, &prev); img->background_transparent = (four_corners_best (mask, img->corners, img->width, img->height) == PIX_MASK_RETAIN); if (free_mask) ! image_unget_x_image_or_dc (mask, prev); } else img->background_transparent = 0; *************** *** 1260,1289 **** Helper functions for X image types ***********************************************************************/ ! /* Clear X resources of image IMG on frame F. PIXMAP_P means free the ! pixmap if any. MASK_P means clear the mask pixmap if any. ! COLORS_P means free colors allocated for the image, if any. */ static void ! x_clear_image_1 (struct frame *f, struct image *img, bool pixmap_p, ! bool mask_p, bool colors_p) { ! if (pixmap_p && img->pixmap) { ! Free_Pixmap (FRAME_X_DISPLAY (f), img->pixmap); ! img->pixmap = NO_PIXMAP; ! /* NOTE (HAVE_NS): background color is NOT an indexed color! */ ! img->background_valid = 0; } ! if (mask_p && img->mask) { ! Free_Pixmap (FRAME_X_DISPLAY (f), img->mask); ! img->mask = NO_PIXMAP; ! img->background_transparent_valid = 0; } ! if (colors_p && img->ncolors) { /* W32_TODO: color table support. */ #ifdef HAVE_X_WINDOWS --- 1242,1299 ---- Helper functions for X image types ***********************************************************************/ ! /* Clear X resources of image IMG on frame F according to FLAGS. ! FLAGS is bitwise-or of the following masks: ! CLEAR_IMAGE_PIXMAP free the pixmap if any. ! CLEAR_IMAGE_MASK means clear the mask pixmap if any. ! CLEAR_IMAGE_COLORS means free colors allocated for the image, if ! any. */ ! ! #define CLEAR_IMAGE_PIXMAP (1 << 0) ! #define CLEAR_IMAGE_MASK (1 << 1) ! #define CLEAR_IMAGE_COLORS (1 << 2) static void ! x_clear_image_1 (struct frame *f, struct image *img, int flags) { ! if (flags & CLEAR_IMAGE_PIXMAP) { ! if (img->pixmap) ! { ! Free_Pixmap (FRAME_X_DISPLAY (f), img->pixmap); ! img->pixmap = NO_PIXMAP; ! /* NOTE (HAVE_NS): background color is NOT an indexed color! */ ! img->background_valid = 0; ! } ! #ifdef HAVE_X_WINDOWS ! if (img->ximg) ! { ! x_destroy_x_image (img->ximg); ! img->ximg = NULL; ! img->background_valid = 0; ! } ! #endif } ! if (flags & CLEAR_IMAGE_MASK) { ! if (img->mask) ! { ! Free_Pixmap (FRAME_X_DISPLAY (f), img->mask); ! img->mask = NO_PIXMAP; ! img->background_transparent_valid = 0; ! } ! #ifdef HAVE_X_WINDOWS ! if (img->mask_img) ! { ! x_destroy_x_image (img->mask_img); ! img->mask_img = NULL; ! img->background_transparent_valid = 0; ! } ! #endif } ! if ((flags & CLEAR_IMAGE_COLORS) && img->ncolors) { /* W32_TODO: color table support. */ #ifdef HAVE_X_WINDOWS *************** *** 1302,1308 **** x_clear_image (struct frame *f, struct image *img) { block_input (); ! x_clear_image_1 (f, img, 1, 1, 1); unblock_input (); } --- 1312,1319 ---- x_clear_image (struct frame *f, struct image *img) { block_input (); ! x_clear_image_1 (f, img, ! CLEAR_IMAGE_PIXMAP | CLEAR_IMAGE_MASK | CLEAR_IMAGE_COLORS); unblock_input (); } *************** *** 1633,1642 **** x_build_heuristic_mask (f, img, XCDR (mask)); } else if (NILP (mask) && found_p && img->mask) ! { ! Free_Pixmap (FRAME_X_DISPLAY (f), img->mask); ! img->mask = NO_PIXMAP; ! } } --- 1644,1650 ---- x_build_heuristic_mask (f, img, XCDR (mask)); } else if (NILP (mask) && found_p && img->mask) ! x_clear_image_1 (f, img, CLEAR_IMAGE_MASK); } *************** *** 2094,2099 **** --- 2102,2222 ---- #endif } + /* Thin wrapper for x_create_x_image_and_pixmap, so that it matches + with image_put_x_image. */ + + static bool + image_create_x_image_and_pixmap (struct frame *f, struct image *img, + int width, int height, int depth, + XImagePtr *ximg, bool mask_p) + { + return x_create_x_image_and_pixmap (f, width, height, depth, ximg, + !mask_p ? &img->pixmap : &img->mask); + } + + /* Put X image XIMG into image IMG on frame F, as a mask if and only + if MASK_P. On X, this simply records XIMG on a member of IMG, so + it can be put into the pixmap afterwards via image_sync_to_pixmaps. + On the other platforms, it puts XIMG into the pixmap, then frees + the X image and its buffer. */ + + static void + image_put_x_image (struct frame *f, struct image *img, XImagePtr ximg, + bool mask_p) + { + #ifdef HAVE_X_WINDOWS + if (!mask_p) + img->ximg = ximg; + else + img->mask_img = ximg; + #else + x_put_x_image (f, ximg, !mask_p ? img->pixmap : img->mask, + img->width, img->height); + x_destroy_x_image (ximg); + #endif + } + + #ifdef HAVE_X_WINDOWS + /* Put the X images recorded in IMG on frame F into pixmaps, then free + the X images and their buffer. */ + + static void + image_sync_to_pixmaps (struct frame *f, struct image *img) + { + if (img->ximg) + { + x_put_x_image (f, img->ximg, img->pixmap, img->width, img->height); + x_destroy_x_image (img->ximg); + img->ximg = NULL; + } + if (img->mask_img) + { + x_put_x_image (f, img->mask_img, img->mask, img->width, img->height); + x_destroy_x_image (img->mask_img); + img->mask_img = NULL; + } + } + #endif + + #ifdef HAVE_NTGUI + /* Create a memory device context for IMG on frame F. It stores the + currently selected GDI object into *PREV for future restoration by + image_unget_x_image_or_dc. */ + + static XImagePtr_or_DC + image_get_x_image_or_dc (struct frame *f, struct image *img, bool mask_p, + HGDIOBJ *prev) + { + HDC frame_dc = get_frame_dc (f); + XImagePtr_or_DC ximg = CreateCompatibleDC (frame_dc); + + release_frame_dc (f, frame_dc); + *prev = SelectObject (ximg, !mask_p ? img->pixmap : img->mask); + } + + static void image_unget_x_image_or_dc (XImagePtr_or_DC ximg, HGDIOBJ prev) + { + SelectObject (ximg, prev); + DeleteDC (ximg); + } + #else /* !HAVE_NTGUI */ + /* Get the X image for IMG on frame F. */ + + static XImagePtr + image_get_x_image (struct frame *f, struct image *img, bool mask_p) + { + #ifdef HAVE_X_WINDOWS + if (!mask_p) + { + if (img->ximg == NULL) + img->ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, + 0, 0, img->width, img->height, ~0, ZPixmap); + return img->ximg; + } + else + { + if (img->mask_img == NULL) + img->mask_img = XGetImage (FRAME_X_DISPLAY (f), img->mask, + 0, 0, img->width, img->height, ~0, ZPixmap); + return img->mask_img; + } + #elif defined (HAVE_NS) + XImagePtr pixmap = !mask_p ? img->pixmap : img->mask; + + ns_retain_object (pixmap); + return pixmap; + #endif + } + + static void image_unget_x_image (XImagePtr ximg) + { + #ifdef HAVE_X_WINDOWS + #elif defined (HAVE_NS) + ns_release_object (ximg); + #endif + } + #endif /* !HAVE_NTGUI */ + /*********************************************************************** File Handling *************** *** 3461,3469 **** &xpm_image, &xpm_mask, &attrs); #else ! rc = XpmReadFileToPixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), ! SSDATA (file), &img->pixmap, &img->mask, ! &attrs); #endif /* HAVE_NTGUI */ } else --- 3584,3592 ---- &xpm_image, &xpm_mask, &attrs); #else ! rc = XpmReadFileToImage (FRAME_X_DISPLAY (f), SSDATA (file), ! &img->ximg, &img->mask_img, ! &attrs); #endif /* HAVE_NTGUI */ } else *************** *** 3484,3496 **** &xpm_image, &xpm_mask, &attrs); #else ! rc = XpmCreatePixmapFromBuffer (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), ! SSDATA (buffer), ! &img->pixmap, &img->mask, ! &attrs); #endif /* HAVE_NTGUI */ } if (rc == XpmSuccess) { #if defined (COLOR_TABLE_SUPPORT) && defined (ALLOC_XPM_COLORS) --- 3607,3644 ---- &xpm_image, &xpm_mask, &attrs); #else ! rc = XpmCreateImageFromBuffer (FRAME_X_DISPLAY (f), SSDATA (buffer), ! &img->ximg, &img->mask_img, ! &attrs); #endif /* HAVE_NTGUI */ } + #ifdef HAVE_X_WINDOWS + if (rc == XpmSuccess) + { + img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), + img->ximg->width, img->ximg->height, + img->ximg->depth); + if (img->pixmap == NO_PIXMAP) + { + x_clear_image (f, img); + rc = XpmNoMemory; + } + else if (img->mask_img) + { + img->mask = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), + img->mask_img->width, + img->mask_img->height, + img->mask_img->depth); + if (img->mask == NO_PIXMAP) + { + x_clear_image (f, img); + rc = XpmNoMemory; + } + } + } + #endif + if (rc == XpmSuccess) { #if defined (COLOR_TABLE_SUPPORT) && defined (ALLOC_XPM_COLORS) *************** *** 3847,3857 **** goto failure; } ! if (!x_create_x_image_and_pixmap (f, width, height, 0, ! &ximg, &img->pixmap) #ifndef HAVE_NS ! || !x_create_x_image_and_pixmap (f, width, height, 1, ! &mask_img, &img->mask) #endif ) { --- 3995,4004 ---- goto failure; } ! if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0) #ifndef HAVE_NS ! || !image_create_x_image_and_pixmap (f, img, width, height, 1, ! &mask_img, 1) #endif ) { *************** *** 3986,3993 **** if (NILP (image_spec_value (img->spec, QCbackground, NULL))) IMAGE_BACKGROUND (img, f, ximg); ! x_put_x_image (f, ximg, img->pixmap, width, height); ! x_destroy_x_image (ximg); #ifndef HAVE_NS if (have_mask) { --- 4133,4139 ---- if (NILP (image_spec_value (img->spec, QCbackground, NULL))) IMAGE_BACKGROUND (img, f, ximg); ! image_put_x_image (f, img, ximg, 0); #ifndef HAVE_NS if (have_mask) { *************** *** 3995,4008 **** mask handy. */ image_background_transparent (img, f, mask_img); ! x_put_x_image (f, mask_img, img->mask, width, height); ! x_destroy_x_image (mask_img); } else { x_destroy_x_image (mask_img); ! Free_Pixmap (FRAME_X_DISPLAY (f), img->mask); ! img->mask = NO_PIXMAP; } #endif return 1; --- 4141,4152 ---- mask handy. */ image_background_transparent (img, f, mask_img); ! image_put_x_image (f, img, mask_img, 1); } else { x_destroy_x_image (mask_img); ! x_clear_image_1 (f, img, CLEAR_IMAGE_MASK); } #endif return 1; *************** *** 4400,4416 **** memory_full (SIZE_MAX); colors = xmalloc (sizeof *colors * img->width * img->height); ! #ifndef HAVE_NTGUI ! /* Get the X image IMG->pixmap. */ ! ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, ! 0, 0, img->width, img->height, ~0, ZPixmap); ! #else ! /* Load the image into a memory device context. */ ! hdc = get_frame_dc (f); ! ximg = CreateCompatibleDC (hdc); ! release_frame_dc (f, hdc); ! prev = SelectObject (ximg, img->pixmap); ! #endif /* HAVE_NTGUI */ /* Fill the `pixel' members of the XColor array. I wished there were an easy and portable way to circumvent XGetPixel. */ --- 4544,4551 ---- memory_full (SIZE_MAX); colors = xmalloc (sizeof *colors * img->width * img->height); ! /* Get the X image or create a memory device context for IMG. */ ! ximg = image_get_x_image_or_dc (f, img, 0, &prev); /* Fill the `pixel' members of the XColor array. I wished there were an easy and portable way to circumvent XGetPixel. */ *************** *** 4440,4446 **** #endif /* HAVE_X_WINDOWS */ } ! Destroy_Image (ximg, prev); return colors; } --- 4575,4581 ---- #endif /* HAVE_X_WINDOWS */ } ! image_unget_x_image_or_dc (ximg, prev); return colors; } *************** *** 4505,4512 **** init_color_table (); ! x_create_x_image_and_pixmap (f, img->width, img->height, 0, ! &oimg, &pixmap); p = colors; for (y = 0; y < img->height; ++y) for (x = 0; x < img->width; ++x, ++p) --- 4640,4648 ---- init_color_table (); ! x_clear_image_1 (f, img, CLEAR_IMAGE_PIXMAP | CLEAR_IMAGE_COLORS); ! image_create_x_image_and_pixmap (f, img, img->width, img->height, 0, ! &oimg, 0); p = colors; for (y = 0; y < img->height; ++y) for (x = 0; x < img->width; ++x, ++p) *************** *** 4517,4527 **** } xfree (colors); - x_clear_image_1 (f, img, 1, 0, 1); ! x_put_x_image (f, oimg, pixmap, img->width, img->height); ! x_destroy_x_image (oimg); ! img->pixmap = pixmap; #ifdef COLOR_TABLE_SUPPORT img->colors = colors_in_color_table (&img->ncolors); free_color_table (); --- 4653,4660 ---- } xfree (colors); ! image_put_x_image (f, img, oimg, 0); #ifdef COLOR_TABLE_SUPPORT img->colors = colors_in_color_table (&img->ncolors); free_color_table (); *************** *** 4706,4712 **** #define MaskForeground(f) WHITE_PIX_DEFAULT (f) Display *dpy = FRAME_X_DISPLAY (f); ! 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); --- 4839,4848 ---- #define MaskForeground(f) WHITE_PIX_DEFAULT (f) Display *dpy = FRAME_X_DISPLAY (f); ! GC gc; ! ! image_sync_to_pixmaps (f, img); ! 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); *************** *** 4781,4817 **** unsigned long bg = 0; if (img->mask) ! { ! Free_Pixmap (FRAME_X_DISPLAY (f), img->mask); ! img->mask = NO_PIXMAP; ! img->background_transparent_valid = 0; ! } #ifndef HAVE_NTGUI #ifndef HAVE_NS /* 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; #endif /* !HAVE_NS */ - - /* Get the X image of IMG->pixmap. */ - ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, 0, 0, - img->width, img->height, - ~0, ZPixmap); #else /* Create the bit array serving as mask. */ row_width = (img->width + 7) / 8; mask_img = xzalloc (row_width * img->height); - - /* Create a memory device context for IMG->pixmap. */ - frame_dc = get_frame_dc (f); - ximg = CreateCompatibleDC (frame_dc); - release_frame_dc (f, frame_dc); - prev = SelectObject (ximg, img->pixmap); #endif /* HAVE_NTGUI */ /* 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; --- 4917,4941 ---- unsigned long bg = 0; if (img->mask) ! x_clear_image_1 (f, img, CLEAR_IMAGE_MASK); #ifndef HAVE_NTGUI #ifndef HAVE_NS /* Create an image and pixmap serving as mask. */ ! rc = image_create_x_image_and_pixmap (f, img, img->width, img->height, 1, ! &mask_img, 1); if (!rc) return; #endif /* !HAVE_NS */ #else /* Create the bit array serving as mask. */ row_width = (img->width + 7) / 8; mask_img = xzalloc (row_width * img->height); #endif /* HAVE_NTGUI */ + /* Get the X image or create a memory device context for IMG. */ + ximg = image_get_x_image_or_dc (f, img, 0, &prev); + /* 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; *************** *** 4858,4866 **** /* 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); #endif /* !HAVE_NS */ #else for (y = 0; y < img->height; ++y) --- 4982,4989 ---- /* Fill in the background_transparent field while we have the mask handy. */ image_background_transparent (img, f, mask_img); ! /* Put mask_img into the image. */ ! image_put_x_image (f, img, mask_img, 1); #endif /* !HAVE_NS */ #else for (y = 0; y < img->height; ++y) *************** *** 4882,4888 **** xfree (mask_img); #endif /* HAVE_NTGUI */ ! Destroy_Image (ximg, prev); } --- 5005,5011 ---- xfree (mask_img); #endif /* HAVE_NTGUI */ ! image_unget_x_image_or_dc (ximg, prev); } *************** *** 5110,5117 **** goto error; } ! if (!x_create_x_image_and_pixmap (f, width, height, 0, ! &ximg, &img->pixmap)) goto error; /* Initialize the color hash table. */ --- 5233,5239 ---- goto error; } ! if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) goto error; /* Initialize the color hash table. */ *************** *** 5248,5256 **** /* Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put the image into a pixmap. */ ! x_put_x_image (f, ximg, img->pixmap, width, height); ! x_destroy_x_image (ximg); /* X and W32 versions did it here, MAC version above. ++kfs img->width = width; --- 5370,5377 ---- /* Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put ximg into the image. */ ! image_put_x_image (f, img, ximg, 0); /* X and W32 versions did it here, MAC version above. ++kfs img->width = width; *************** *** 5688,5695 **** /* Create the X image and pixmap now, so that the work below can be omitted if the image is too large for X. */ ! if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, ! &img->pixmap)) goto error; /* If image contains simply transparency data, we prefer to --- 5809,5815 ---- /* Create the X image and pixmap now, so that the work below can be omitted if the image is too large for X. */ ! if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) goto error; /* If image contains simply transparency data, we prefer to *************** *** 5801,5812 **** contains an alpha channel. */ if (channels == 4 && !transparent_p ! && !x_create_x_image_and_pixmap (f, width, height, 1, ! &mask_img, &img->mask)) { x_destroy_x_image (ximg); ! Free_Pixmap (FRAME_X_DISPLAY (f), img->pixmap); ! img->pixmap = NO_PIXMAP; goto error; } --- 5921,5931 ---- contains an alpha channel. */ if (channels == 4 && !transparent_p ! && !image_create_x_image_and_pixmap (f, img, width, height, 1, ! &mask_img, 1)) { x_destroy_x_image (ximg); ! x_clear_image_1 (f, img, CLEAR_IMAGE_PIXMAP); goto error; } *************** *** 5880,5888 **** Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put the image into the pixmap, then free the X image and its buffer. */ ! x_put_x_image (f, ximg, img->pixmap, width, height); ! x_destroy_x_image (ximg); /* Same for the mask. */ if (mask_img) --- 5999,6006 ---- Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put ximg into the image. */ ! image_put_x_image (f, img, ximg, 0); /* Same for the mask. */ if (mask_img) *************** *** 5891,5898 **** mask handy. Casting avoids a GCC warning. */ image_background_transparent (img, f, (XImagePtr_or_DC)mask_img); ! x_put_x_image (f, mask_img, img->mask, img->width, img->height); ! x_destroy_x_image (mask_img); } return 1; --- 6009,6015 ---- mask handy. Casting avoids a GCC warning. */ image_background_transparent (img, f, (XImagePtr_or_DC)mask_img); ! image_put_x_image (f, img, mask_img, 1); } return 1; *************** *** 6429,6435 **** } /* Create X image and pixmap. */ ! if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) { mgr->failure_code = MY_JPEG_CANNOT_CREATE_X; sys_longjmp (mgr->setjmp_buffer, 1); --- 6546,6552 ---- } /* Create X image and pixmap. */ ! if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) { mgr->failure_code = MY_JPEG_CANNOT_CREATE_X; sys_longjmp (mgr->setjmp_buffer, 1); *************** *** 6496,6504 **** /* Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put the image into the pixmap. */ ! x_put_x_image (f, ximg, img->pixmap, width, height); ! x_destroy_x_image (ximg); return 1; } --- 6613,6620 ---- /* Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put ximg into the image. */ ! image_put_x_image (f, img, ximg, 0); return 1; } *************** *** 6895,6902 **** /* Create the X image and pixmap. */ if (! (height <= min (PTRDIFF_MAX, SIZE_MAX) / sizeof *buf / width ! && x_create_x_image_and_pixmap (f, width, height, 0, ! &ximg, &img->pixmap))) { fn_TIFFClose (tiff); return 0; --- 7011,7018 ---- /* Create the X image and pixmap. */ if (! (height <= min (PTRDIFF_MAX, SIZE_MAX) / sizeof *buf / width ! && image_create_x_image_and_pixmap (f, img, width, height, 0, ! &ximg, 0))) { fn_TIFFClose (tiff); return 0; *************** *** 6955,6963 **** /* Casting avoids a GCC warning on W32. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put the image into the pixmap, then free the X image and its buffer. */ ! x_put_x_image (f, ximg, img->pixmap, width, height); ! x_destroy_x_image (ximg); xfree (buf); return 1; --- 7071,7078 ---- /* Casting avoids a GCC warning on W32. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put ximg into the image. */ ! image_put_x_image (f, img, ximg, 0); xfree (buf); return 1; *************** *** 7285,7291 **** } /* Create the X image and pixmap. */ ! if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) { fn_DGifCloseFile (gif); return 0; --- 7400,7406 ---- } /* Create the X image and pixmap. */ ! if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) { fn_DGifCloseFile (gif); return 0; *************** *** 7469,7477 **** /* Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put the image into the pixmap, then free the X image and its buffer. */ ! x_put_x_image (f, ximg, img->pixmap, width, height); ! x_destroy_x_image (ximg); return 1; } --- 7584,7591 ---- /* Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put ximg into the image. */ ! image_put_x_image (f, img, ximg, 0); return 1; } *************** *** 7909,7916 **** int imagedepth = 24; /*MagickGetImageDepth(image_wand);*/ const char *exportdepth = imagedepth <= 8 ? "I" : "BGRP"; /*"RGBP";*/ /* Try to create a x pixmap to hold the imagemagick pixmap. */ ! if (!x_create_x_image_and_pixmap (f, width, height, imagedepth, ! &ximg, &img->pixmap)) { #ifdef COLOR_TABLE_SUPPORT free_color_table (); --- 8023,8030 ---- int imagedepth = 24; /*MagickGetImageDepth(image_wand);*/ const char *exportdepth = imagedepth <= 8 ? "I" : "BGRP"; /*"RGBP";*/ /* Try to create a x pixmap to hold the imagemagick pixmap. */ ! if (!image_create_x_image_and_pixmap (f, img, width, height, imagedepth, ! &ximg, 0)) { #ifdef COLOR_TABLE_SUPPORT free_color_table (); *************** *** 7948,7955 **** size_t image_height; /* Try to create a x pixmap to hold the imagemagick pixmap. */ ! if (!x_create_x_image_and_pixmap (f, width, height, 0, ! &ximg, &img->pixmap)) { #ifdef COLOR_TABLE_SUPPORT free_color_table (); --- 8062,8069 ---- size_t image_height; /* Try to create a x pixmap to hold the imagemagick pixmap. */ ! if (!image_create_x_image_and_pixmap (f, img, width, height, 0, ! &ximg, 0)) { #ifdef COLOR_TABLE_SUPPORT free_color_table (); *************** *** 8003,8012 **** img->width = width; img->height = height; ! /* Put the image into the pixmap, then free the X image and its ! buffer. */ ! x_put_x_image (f, ximg, img->pixmap, width, height); ! x_destroy_x_image (ximg); /* Final cleanup. image_wand should be the only resource left. */ DestroyMagickWand (image_wand); --- 8117,8124 ---- img->width = width; img->height = height; ! /* Put ximg into the image. */ ! image_put_x_image (f, img, ximg, 0); /* Final cleanup. image_wand should be the only resource left. */ DestroyMagickWand (image_wand); *************** *** 8400,8406 **** eassert (fn_gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); /* Try to create a x pixmap to hold the svg pixmap. */ ! if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) { fn_g_object_unref (pixbuf); return 0; --- 8512,8518 ---- eassert (fn_gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); /* Try to create a x pixmap to hold the svg pixmap. */ ! if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) { fn_g_object_unref (pixbuf); return 0; *************** *** 8475,8484 **** Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put the image into the pixmap, then free the X image and its ! buffer. */ ! x_put_x_image (f, ximg, img->pixmap, width, height); ! x_destroy_x_image (ximg); return 1; --- 8587,8594 ---- Casting avoids a GCC warning. */ IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); ! /* Put ximg into the image. */ ! image_put_x_image (f, img, ximg, 0); return 1;