From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Image transformations Date: Thu, 27 Jun 2019 16:59:06 +0300 Message-ID: <83v9wri0yd.fsf@gnu.org> References: <20190613192724.GA11945@breton.holly.idiocy.org> <83zhmlxo6d.fsf@gnu.org> <20190613222626.GA12971@breton.holly.idiocy.org> <83o930y7cl.fsf@gnu.org> <20190615104242.GA13368@breton.holly.idiocy.org> <838su3w0de.fsf@gnu.org> <20190616152259.GA22789@breton.holly.idiocy.org> <83d0jdv68i.fsf@gnu.org> <20190617211332.GA55597@breton.holly.idiocy.org> <83a7e6na26.fsf@gnu.org> <20190625183352.GA18019@breton.holly.idiocy.org> <838stplcgb.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="104287"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: alan@idiocy.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 27 16:00:38 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hgUx4-000Qug-0d for ged-emacs-devel@m.gmane.org; Thu, 27 Jun 2019 16:00:38 +0200 Original-Received: from localhost ([::1]:50962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgUx2-00024F-Ib for ged-emacs-devel@m.gmane.org; Thu, 27 Jun 2019 10:00:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41690) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgUvs-00020e-TD for emacs-devel@gnu.org; Thu, 27 Jun 2019 09:59:32 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:50753) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hgUvs-0002IY-H7; Thu, 27 Jun 2019 09:59:24 -0400 Original-Received: from [176.228.60.248] (port=2376 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hgUvq-0007IH-DF; Thu, 27 Jun 2019 09:59:23 -0400 In-reply-to: <838stplcgb.fsf@gnu.org> (message from Eli Zaretskii on Tue, 25 Jun 2019 21:57:56 +0300) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.org gmane.emacs.devel:238197 Archived-At: > Date: Tue, 25 Jun 2019 21:57:56 +0300 > From: Eli Zaretskii > Cc: emacs-devel@gnu.org > > > > Given these findings, what would you prefer to do in image.c? We > > > could either (a) make the individual functions (image_set_rotation > > > etc.) return the transformation parameters, and leave the matrix > > > calculation to image_set_transform, or we could have the individual > > > functions accept a flag to tell them whether to generate XRender/Cairo > > > style matrices or NS/Windows style. Or maybe you ave yet another > > > idea? > > > > The image size calculation is already a separate function, shared with > > ImageMagick, so I feel we’re halfway towards (a) as it is. I’m happy > > to put all the matrix code into image_set_transform: once we remove > > cropping the resulting function shouldn’t be obscenely large. > > OK, I will work on these changes. > > > '((:rotation imagemagick) > > (:width png gif svg imagemagick) > > (:height png gif svg imagemagick) > > ...) > > > > where png, svg, imagemagick, etc. are types (image backends) that you > > can pass to create-image. > > > > Or it might be better to spin it round a bit: > > > > '((png :width :height ...) > > (imagemagick :rotation :width ...)) > > > > Whenever I think about this I get a bit carried away and wonder if we > > could do it by image type rather than backend so that we could provide > > a function, that you pass an image type and spec to, which finds the > > first image backend that can handle it: > > > > (image-get-type "tiff" > > '(:rotation 90 :max-width 20)) > > => 'imagemagick > > > > (image-get-type "jpeg" > > '(:rotation 90 :max-width 20)) > > => 'jpeg > > > > I can’t decide if that’s getting a bit silly, though. > > Let me think about this and propose something. What I have now is below. This doesn't yet include documentation changes. I could only test this on MS-Windows, but I hope I didn't goof on other platforms. I left the NS code to use the same matrix as XRender/Cairo, as I couldn't test the result of letting it use the inverted matrix like MS-Windows does. If using that matrix works for NS, the inversion in nsimage.m could be removed. There's a FIXME in image_set_rotation, please tell what you think about it. Please also comment on image-transforms-p. Maybe we should return both 'rotate' and 'rotate90' in the list when ImageMagick is available? Any other comments are welcome, of course. TIA. diff --git a/src/dispextern.h b/src/dispextern.h index cc2d963..5d66fd8 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3020,6 +3020,9 @@ reset_mouse_highlight (Mouse_HLInfo *hlinfo) /* Picture versions of pixmap and mask for compositing. */ Picture picture, mask_picture; # endif +#endif /* HAVE_X_WINDOWS */ +#ifdef HAVE_NTGUI + XFORM xform; #endif /* Colors allocated for this image, if any. Allocated via xmalloc. */ diff --git a/src/image.c b/src/image.c index 7b648c4..6c240c3 100644 --- a/src/image.c +++ b/src/image.c @@ -57,6 +57,10 @@ Copyright (C) 1989, 1992-2019 Free Software Foundation, Inc. #include #endif /* HAVE_SYS_TYPES_H */ +#ifdef HAVE_NATIVE_TRANSFORMS +#include /* for FLT_MIN */ +#endif + #ifdef HAVE_WINDOW_SYSTEM #include TERM_HEADER #endif /* HAVE_WINDOW_SYSTEM */ @@ -1965,12 +1969,10 @@ compute_image_size (size_t width, size_t height, *d_width = desired_width; *d_height = desired_height; } -#endif /* HAVE_IMAGEMAGICK || HAVE_NATIVE_TRANSFORMS */ -/* image_set_rotation, image_set_crop, image_set_size and - image_set_transform use affine transformation matrices to perform - various transforms on the image. The matrix is a 2D array of - doubles. It is laid out like this: +/* image_set_rotation and image_set_transform use affine + transformation matrices to perform various transforms on the image. + The matrix is a 2D array of doubles. It is laid out like this: m[0][0] = m11 | m[1][0] = m12 | m[2][0] = tx --------------+---------------+------------- @@ -2039,14 +2041,15 @@ compute_image_size (size_t width, size_t height, finally move the origin back to the top left of the image, which may now be a different corner. - Cropping is easier as we just move the origin to the top left of - where we want to crop and set the width and height accordingly. - The matrices don't know anything about width and height. + Note that different GUI backends (X, Cairo, w32, NS) want the + transform matrix defined as transform from the original image to + the transformed image, while others want the matrix to describe the + transform of the space, which boils down to inverting the matrix. It's possible to pre-calculate the matrix multiplications and just generate one transform matrix that will do everything we need in a single step, but the maths for each element is much more complex - and I thought it was better to perform the steps separately. */ + and performing the steps separately makes for more readable code. */ typedef double matrix3x3[3][3]; @@ -2070,102 +2073,25 @@ matrix3x3_mult (matrix3x3 a, matrix3x3 b, matrix3x3 result) } static void -image_set_rotation (struct image *img, matrix3x3 tm) +image_set_rotation (struct image *img, double *rotation) { -#ifdef HAVE_NATIVE_TRANSFORMS -# ifdef HAVE_IMAGEMAGICK - /* ImageMagick images are already rotated. */ - if (EQ (image_spec_value (img->spec, QCtype, NULL), Qimagemagick)) - return; -# endif - -# if !defined USE_CAIRO && defined HAVE_XRENDER - if (!img->picture) - return; -# endif - - int rotation, cos_r, sin_r, width, height; - Lisp_Object value = image_spec_value (img->spec, QCrotation, NULL); + /* FIXME: should we signal an error here? */ if (! NUMBERP (value)) return; Lisp_Object reduced_angle = Fmod (value, make_fixnum (360)); - if (! FLOATP (reduced_angle)) - rotation = XFIXNUM (reduced_angle); - else - { - rotation = XFLOAT_DATA (reduced_angle); - if (rotation != XFLOAT_DATA (reduced_angle)) - goto not_a_multiple_of_90; - } - - if (rotation == 0) - return; - - if (rotation == 90) - { - width = img->height; - height = img->width; - - cos_r = 0; - sin_r = 1; - } - else if (rotation == 180) - { - width = img->width; - height = img->height; - - cos_r = -1; - sin_r = 0; - } - else if (rotation == 270) - { - width = img->height; - height = img->width; - - cos_r = 0; - sin_r = -1; - } + if (FLOATP (reduced_angle)) + *rotation = XFLOAT_DATA (reduced_angle); else - { - not_a_multiple_of_90: - image_error ("Native image rotation supports " - "only multiples of 90 degrees"); - return; - } - - /* Translate so (0, 0) is in the center of the image. */ - matrix3x3 t - = { [0][0] = 1, - [1][1] = 1, - [2][0] = img->width * .5, [2][1] = img->height * .5, [2][2] = 1 }; - matrix3x3 tmp; - matrix3x3_mult (t, tm, tmp); - - /* Rotate. */ - matrix3x3 rot = { [0][0] = cos_r, [0][1] = -sin_r, - [1][0] = sin_r, [1][1] = cos_r, - [2][2] = 1 }; - matrix3x3 tmp2; - matrix3x3_mult (rot, tmp, tmp2); - - /* Translate back. */ - t[2][0] = width * -.5; - t[2][1] = height * -.5; - matrix3x3_mult (t, tmp2, tm); - - img->width = width; - img->height = height; -#endif + *rotation = XFIXNUM (reduced_angle); } static void -image_set_crop (struct image *img, matrix3x3 tm) +image_set_transform (struct frame *f, struct image *img, matrix3x3 matrix) { -#ifdef HAVE_NATIVE_TRANSFORMS # ifdef HAVE_IMAGEMAGICK - /* ImageMagick images are already cropped. */ + /* ImageMagick images already have the correct transform. */ if (EQ (image_spec_value (img->spec, QCtype, NULL), Qimagemagick)) return; # endif @@ -2175,119 +2101,110 @@ image_set_crop (struct image *img, matrix3x3 tm) return; # endif - Lisp_Object crop = image_spec_value (img->spec, QCcrop, NULL); - - if (!CONSP (crop)) - return; - - Lisp_Object w = XCAR (crop), h = Qnil, x = Qnil, y = Qnil; - crop = XCDR (crop); - if (CONSP (crop)) - { - h = XCAR (crop); - crop = XCDR (crop); - if (CONSP (crop)) - { - x = XCAR (crop); - crop = XCDR (crop); - if (CONSP (crop)) - y = XCAR (crop); - } - } - - int width = img->width; - if (FIXNATP (w) && XFIXNAT (w) < img->width) - width = XFIXNAT (w); - int left; - if (TYPE_RANGED_FIXNUMP (int, x)) - { - left = XFIXNUM (x); - if (left < 0) - left = img->width - width + left; - } - else - left = (img->width - width) >> 1; - - int height = img->height; - if (FIXNATP (h) && XFIXNAT (h) < img->height) - height = XFIXNAT (h); - int top; - if (TYPE_RANGED_FIXNUMP (int, y)) - { - top = XFIXNUM (y); - if (top < 0) - top = img->height - height + top; - } - else - top = (img->height - height) >> 1; - - /* Negative values operate from the right and bottom of the image - instead of the left and top. */ - if (left < 0) - { - width = img->width + left; - left = 0; - } - - if (width + left > img->width) - width = img->width - left; + /* Determine size. */ + int width, height; + compute_image_size (img->width, img->height, img->spec, &width, &height); - if (top < 0) - { - height = img->height + top; - top = 0; - } + /* Determine rotation. */ + double rotation = 0.0; + image_set_rotation (img, &rotation); - if (height + top > img->height) - height = img->height - top; + /* Perform scale transformation. */ - matrix3x3 tmp, m = { [0][0] = 1, - [1][1] = 1, - [2][0] = left, [2][1] = top, [2][2] = 1 }; - matrix3x3_mult (m, tm, tmp); - matrix3x3_copy (tmp, tm); + double xscale = (double) width / img->width; + double yscale = (double) height / img->height; +# if defined USE_CAIRO || defined HAVE_XRENDER || defined HAVE_NS + /* Avoid division by zero. */ + xscale = max (xscale, FLT_MIN); + matrix3x3 tmp, rm = + { [0][0] = 1.0 / xscale, [1][1] = 1.0 / yscale, [2][2] = 1 }; + matrix3x3_mult (rm, matrix, tmp); +# elif defined HAVE_NTGUI + matrix3x3 tmp, rm = { [0][0] = xscale, [1][1] = yscale, [2][2] = 1 }; + matrix3x3_mult (matrix, rm, tmp); +# endif img->width = width; img->height = height; -#endif -} -static void -image_set_size (struct image *img, matrix3x3 tm) -{ -#ifdef HAVE_NATIVE_TRANSFORMS -# ifdef HAVE_IMAGEMAGICK - /* ImageMagick images are already the correct size. */ - if (EQ (image_spec_value (img->spec, QCtype, NULL), Qimagemagick)) - return; -# endif - -# if !defined USE_CAIRO && defined HAVE_XRENDER - if (!img->picture) - return; -# endif + /* Perform rotation transformation. */ - int width, height; - - compute_image_size (img->width, img->height, img->spec, &width, &height); + int cos_r, sin_r; + if (rotation == 0) + matrix3x3_copy (tmp, matrix); + else if (rotation == 90 || rotation == 180 || rotation == 270) + { + if (rotation == 90) + { + width = img->height; + height = img->width; - double xscale = img->width / (double) width; - double yscale = img->height / (double) height; + cos_r = 0; + sin_r = 1; + } + else if (rotation == 180) + { + width = img->width; + height = img->height; - matrix3x3 tmp, rm = { [0][0] = xscale, [1][1] = yscale, [2][2] = 1 }; - matrix3x3_mult (rm, tm, tmp); - matrix3x3_copy (tmp, tm); + cos_r = -1; + sin_r = 0; + } + else if (rotation == 270) + { + width = img->height; + height = img->width; - img->width = width; - img->height = height; -#endif -} + cos_r = 0; + sin_r = -1; + } +# if defined USE_CAIRO || defined HAVE_XRENDER || defined HAVE_NS + /* 1. Translate so (0, 0) is in the center of the image. */ + matrix3x3 t + = { [0][0] = 1, + [1][1] = 1, + [2][0] = img->width * .5, [2][1] = img->height * .5, [2][2] = 1 }; + matrix3x3 tmp2; + matrix3x3_mult (t, tmp, tmp2); + + /* 2. Rotate. */ + matrix3x3 rot = { [0][0] = cos_r, [0][1] = -sin_r, + [1][0] = sin_r, [1][1] = cos_r, + [2][2] = 1 }; + matrix3x3 tmp3; + matrix3x3_mult (rot, tmp2, tmp3); + + /* 3. Translate back. */ + t[2][0] = width * -.5; + t[2][1] = height * -.5; + matrix3x3_mult (t, tmp3, matrix); +# elif defined HAVE_NTGUI + /* 1. Translate so (0, 0) is in the center of the image. */ + matrix3x3 t + = { [0][0] = 1, + [1][1] = 1, + [2][0] = -img->width * .5, [2][1] = -img->height * .5, [2][2] = 1 }; + matrix3x3 tmp2; + matrix3x3_mult (tmp, t, tmp2); + + /* 2. Rotate. */ + matrix3x3 rot = { [0][0] = cos_r, [0][1] = sin_r, + [1][0] = -sin_r, [1][1] = cos_r, + [2][2] = 1 }; + matrix3x3 tmp3; + matrix3x3_mult (tmp2, rot, tmp3); + + /* 3. Translate back. */ + t[2][0] = width * .5; + t[2][1] = height * .5; + matrix3x3_mult (tmp3, t, matrix); +# endif + img->width = width; + img->height = height; + } + else + image_error ("Native image rotation supports only multiples of 90 degrees"); -static void -image_set_transform (struct frame *f, struct image *img, matrix3x3 matrix) -{ - /* TODO: Add MS Windows support. */ -#ifdef HAVE_NATIVE_TRANSFORMS # if defined (HAVE_NS) /* Under NS the transform is applied to the drawing surface at drawing time, so store it for later. */ @@ -2317,10 +2234,19 @@ image_set_transform (struct frame *f, struct image *img, matrix3x3 matrix) 0, 0); XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->picture, &tmat); } +# elif defined HAVE_NTGUI + /* Store the transform matrix for application at draw time. */ + img->xform.eM11 = matrix[0][0]; + img->xform.eM12 = matrix[0][1]; + img->xform.eM21 = matrix[1][0]; + img->xform.eM22 = matrix[1][1]; + img->xform.eDx = matrix[2][0]; + img->xform.eDy = matrix[2][1]; # endif -#endif } +#endif /* HAVE_IMAGEMAGICK || HAVE_NATIVE_TRANSFORMS */ + /* Return the id of image with Lisp specification SPEC on frame F. SPEC must be a valid Lisp image specification (see valid_image_p). */ @@ -2378,9 +2304,6 @@ lookup_image (struct frame *f, Lisp_Object spec) #ifdef HAVE_NATIVE_TRANSFORMS matrix3x3 transform_matrix = { [0][0] = 1, [1][1] = 1, [2][2] = 1 }; - image_set_size (img, transform_matrix); - image_set_crop (img, transform_matrix); - image_set_rotation (img, transform_matrix); image_set_transform (f, img, transform_matrix); #endif @@ -10010,19 +9933,38 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, DEFUN ("image-transforms-p", Fimage_transforms_p, Simage_transforms_p, 0, 1, 0, doc: /* Test whether FRAME supports image transformation. -Return t if FRAME supports native transforms, nil otherwise. */) +Return list of capabilities if FRAME supports native transforms, nil otherwise. +FRAME defaults to the selected frame. +The list of capabilities can include one or more of the following: + + - the symbol `scale' if FRAME supports image scaling + - the symbol `rotate' if FRAME supports image rotation by arbitrary angles + - the symbol `rotate90' if FRAME supports image rotation only by angles + that are integral multiples of 90 degrees + - the symbol `crop' if FRAME supports image cropping. */) (Lisp_Object frame) { -#if defined (USE_CAIRO) || defined (HAVE_NS) || defined (HAVE_NTGUI) - return Qt; -#elif defined (HAVE_X_WINDOWS) && defined (HAVE_XRENDER) - int event_basep, error_basep; - - if (XRenderQueryExtension - (FRAME_X_DISPLAY (decode_window_system_frame (frame)), - &event_basep, &error_basep)) - return Qt; + struct frame *f = decode_live_frame (frame); + if (FRAME_WINDOW_P (f)) + { +#ifdef HAVE_NATIVE_TRANSFORMS +# if defined HAVE_IMAGEMAGICK + return list3 (Qscale, Qrotate, Qcrop); +# elif defined (USE_CAIRO) || defined (HAVE_NS) + return list2 (Qscale, Qrotate90); +# elif defined (HAVE_NTGUI) + return (w32_image_rotations_p () + ? list2 (Qscale, Qrotate90) + : list1 (Qscale)); +# elif defined (HAVE_X_WINDOWS) && defined (HAVE_XRENDER) + int event_basep, error_basep; + + if (XRenderQueryExtension (FRAME_X_DISPLAY (f), + &event_basep, &error_basep)) + return list2 (Qscale, Qrotate90); +# endif #endif + } return Qnil; } @@ -10168,6 +10110,14 @@ syms_of_image (void) DEFSYM (Qpostscript, "postscript"); DEFSYM (QCmax_width, ":max-width"); DEFSYM (QCmax_height, ":max-height"); + +#ifdef HAVE_NATIVE_TRANSFORMS + DEFSYM (Qscale, "scale"); + DEFSYM (Qrotate, "rotate"); + DEFSYM (Qrotate90, "rotate90"); + DEFSYM (Qcrop, "crop"); +#endif + #ifdef HAVE_GHOSTSCRIPT add_image_type (Qpostscript); DEFSYM (QCloader, ":loader"); diff --git a/src/w32term.c b/src/w32term.c index 5726124..f392d31 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -117,6 +117,10 @@ #define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD (wparam)) /* Dynamic linking to SetLayeredWindowAttribute (only since 2000). */ BOOL (WINAPI *pfnSetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD); +/* PlgBlt is available since Windows 2000. */ +BOOL (WINAPI *pfnPlgBlt) (HDC, const POINT *, HDC, int, int, int, int, HBITMAP, int, int); + + #ifndef LWA_ALPHA #define LWA_ALPHA 0x02 #endif @@ -1753,6 +1757,26 @@ w32_draw_glyph_string_box (struct glyph_string *s) } } +bool +w32_image_rotations_p (void) +{ + return pfnPlgBlt != NULL; +} + +static POINT +transform (int x0, int y0, int x, int y, XFORM *xform) +{ + POINT pt; + + /* See https://docs.microsoft.com/en-us/windows/desktop/api/Wingdi/nf-wingdi-setworldtransform */ + pt.x = + x0 + (x - x0) * xform->eM11 + (y - y0) * xform->eM21 + xform->eDx + 0.5f; + pt.y = + y0 + (x - x0) * xform->eM12 + (y - y0) * xform->eM22 + xform->eDy + 0.5f; + + return pt; +} + /* Draw foreground of image glyph string S. */ @@ -1798,20 +1822,31 @@ w32_draw_image_foreground (struct glyph_string *s) } else { - DebPrint (("w32_draw_image_foreground: GetObject failed!\n")); + DebPrint (("w32_draw_image_foreground: GetObject(pixmap) failed!\n")); orig_width = s->slice.width; orig_height = s->slice.height; } double w_factor = 1.0, h_factor = 1.0; - bool scaled = false; + bool scaled = false, need_xform = false; int orig_slice_width = s->slice.width, orig_slice_height = s->slice.height; int orig_slice_x = s->slice.x, orig_slice_y = s->slice.y; - /* For scaled images we need to restore the original slice's - dimensions and origin coordinates, from before the scaling. */ - if (s->img->width != orig_width || s->img->height != orig_height) + POINT corner[3]; + if ((s->img->xform.eM12 != 0 || s->img->xform.eM21 != 0 + || s->img->xform.eDx != 0 || s->img->xform.eDy != 0) + /* PlgBlt is not available on Windows 9X. */ + && pfnPlgBlt) { + need_xform = true; + corner[0] = transform (x, y, x, y, &s->img->xform); + corner[1] = transform (x, y, x + orig_width, y, &s->img->xform); + corner[2] = transform (x, y, x, y + orig_height, &s->img->xform); + } + else if (s->img->width != orig_width || s->img->height != orig_height) + { + /* For scaled images we need to restore the original slice's + dimensions and origin coordinates, from before the scaling. */ scaled = true; w_factor = (double) orig_width / (double) s->img->width; h_factor = (double) orig_height / (double) s->img->height; @@ -1828,7 +1863,15 @@ w32_draw_image_foreground (struct glyph_string *s) SetTextColor (s->hdc, RGB (255, 255, 255)); SetBkColor (s->hdc, RGB (0, 0, 0)); - if (!scaled) + if (need_xform) + { + if (!pfnPlgBlt (s->hdc, corner, compat_hdc, + s->slice.x, s->slice.y, + orig_width, orig_height, + s->img->mask, s->slice.x, s->slice.y)) + DebPrint (("PlgBlt failed!")); + } + else if (!scaled) { BitBlt (s->hdc, x, y, s->slice.width, s->slice.height, compat_hdc, s->slice.x, s->slice.y, SRCINVERT); @@ -1865,7 +1908,14 @@ w32_draw_image_foreground (struct glyph_string *s) { SetTextColor (s->hdc, s->gc->foreground); SetBkColor (s->hdc, s->gc->background); - if (!scaled) + if (need_xform) + { + if (!pfnPlgBlt (s->hdc, corner, compat_hdc, + s->slice.x, s->slice.y, + orig_width, orig_height, NULL, 0, 0)) + DebPrint (("PlgBlt failed!")); + } + else if (!scaled) BitBlt (s->hdc, x, y, s->slice.width, s->slice.height, compat_hdc, s->slice.x, s->slice.y, SRCCOPY); else @@ -7354,6 +7404,11 @@ #define LOAD_PROC(lib, fn) pfn##fn = (void *) GetProcAddress (lib, #fn) LOAD_PROC (user_lib, SetLayeredWindowAttributes); + /* PlgBlt is not available on Windows 9X. */ + HMODULE hgdi = LoadLibrary ("gdi32.dll"); + if (hgdi) + LOAD_PROC (hgdi, PlgBlt); + #undef LOAD_PROC /* Ensure scrollbar handles are at least 5 pixels. */ diff --git a/src/w32term.h b/src/w32term.h index 729e8d0..6133e10 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -743,6 +743,8 @@ #define FILE_NOTIFICATIONS_SIZE 16384 extern void w32_initialize_display_info (Lisp_Object); extern void initialize_w32_display (struct terminal *, int *, int *); +extern bool w32_image_rotations_p (void); + #ifdef WINDOWSNT /* Keyboard hooks. */ extern void setup_w32_kbdhook (void); diff --git a/test/manual/image-transforms-tests.el b/test/manual/image-transforms-tests.el index d601b93..e8b301e 100644 --- a/test/manual/image-transforms-tests.el +++ b/test/manual/image-transforms-tests.el @@ -67,7 +67,7 @@ test-cropping ")) - (insert-header "Test Crop: cropping an image") + (insert-header "Test Crop: cropping an image (only works with ImageMagick)") (insert-test "all params" top-left image '(:crop (10 10 0 0))) (insert-test "width/height only" middle image '(:crop (10 10))) (insert-test "negative x y" middle image '(:crop (10 10 -10 -10)))