* bug#47095: 27.1; Feature request: mirror image display @ 2021-03-12 10:34 ynyaaa 2021-12-27 8:36 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Timo Taipalus 0 siblings, 1 reply; 13+ messages in thread From: ynyaaa @ 2021-03-12 10:34 UTC (permalink / raw) To: 47095 Emacs can not display mirror images. At least horizontal/vertical mirror images are required. It is ideal to support +45/-45 degrees axis mirroring. In GNU Emacs 27.1 (build 1, x86_64-w64-mingw32) of 2020-08-22 built on CIRROCUMULUS Repository revision: 86d8d76aa36037184db0b2897c434cdaab1a9ae8 Repository branch: HEAD Windowing system distributor 'Microsoft Corp.', version 10.0.18363 System Description: Microsoft Windows 10 Pro (v10.0.1909.18363.1379) Recent messages: Configured using: 'configure --without-dbus --host=x86_64-w64-mingw32 --without-compress-install 'CFLAGS=-O2 -static'' Configured features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY W32NOTIFY ACL GNUTLS LIBXML2 HARFBUZZ ZLIB TOOLKIT_SCROLL_BARS MODULES THREADS JSON PDUMPER LCMS2 GMP Important settings: value of $LANG: JPN locale-coding-system: cp932 Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (gnutls network-stream nsm mailalias smtpmail auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs json map jka-compr help-fns radix-tree cl-print debug backtrace find-func ispell misearch multi-isearch mailcap help-mode pp shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg epg-config gnus-util rmail rmail-loaddefs text-property-search time-date subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils term/bobcat japan-util tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite charscript charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote threads w32notify w32 lcms2 multi-tty make-network-process emacs) Memory information: ((conses 16 76064 16835) (symbols 48 8874 6) (strings 32 24646 2231) (string-bytes 1 792768) (vectors 16 14199) (vector-slots 8 275047 18288) (floats 8 28 292) (intervals 56 1942 0) (buffers 1000 18)) ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: [PATCH] Add support for image mirroring (Bug#47095) 2021-03-12 10:34 bug#47095: 27.1; Feature request: mirror image display ynyaaa @ 2021-12-27 8:36 ` Timo Taipalus 2021-12-28 1:01 ` bug#47095: 27.1; Feature request: mirror image display Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-12-28 11:22 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Alan Third 0 siblings, 2 replies; 13+ messages in thread From: Timo Taipalus @ 2021-12-27 8:36 UTC (permalink / raw) To: 47095 [-- Attachment #1: Type: text/plain, Size: 311 bytes --] It seems image-mode does not have capability for image mirroring, so here's a patch for it. Tested NS (macOS) and XRender/Cairo implementations. As it is, it has no effect if ImageMagick is enabled. I chose 'h' as the action key because 'm' and 'f' were reserved, and 'h' is easy to memorize ("horizontal"). [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-support-for-image-mirroring-Bug-47095.patch --] [-- Type: text/x-diff; name=0001-Add-support-for-image-mirroring-Bug-47095.patch, Size: 4255 bytes --] From 3e67734ceb1f710a6039824b8c224b97cdebcd44 Mon Sep 17 00:00:00 2001 From: Timo <timo@taipalus.cc> Date: Sat, 25 Dec 2021 15:38:20 +0200 Subject: [PATCH] Add support for image mirroring (Bug#47095) * lisp/image.el (image-map): Keybinding for mirroring function. (image-mirror): New function that toggles image mirroring property. * src/image.c (syms_of_image): Add property. (image_set_transform): Modify image rotation code to also horizontally mirror the image when the property is set. * etc/NEWS: Add description. --- etc/NEWS | 4 ++++ lisp/image.el | 9 +++++++++ src/image.c | 26 ++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index c9466d0fef..08cf624020 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -570,6 +570,10 @@ This controls whether or not to show a message when opening certain image formats saying how to edit it as text. The default is to show this message for SVG and XPM. ++++ +*** New command 'image-mirror'. +This command mirrors (horizontally flips) the image under point. + ** Image-Dired +++ diff --git a/lisp/image.el b/lisp/image.el index 702985f41f..c060c4c650 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -181,6 +181,7 @@ image-map (define-key map [C-wheel-up] 'image-mouse-increase-size) (define-key map [C-mouse-4] 'image-mouse-increase-size) (define-key map "r" 'image-rotate) + (define-key map "h" 'image-mirror) (define-key map "o" 'image-save) map)) @@ -1249,6 +1250,14 @@ image-save (write-region (point-min) (point-max) (read-file-name "Write image to file: "))))) +(defun image-mirror () + "Mirror (horizontally flip) the image under point." + (interactive) + (let ((image (image--get-image))) + (image-flush image) + (setf (image-property image :mirror) + (not (image-property image :mirror))))) + (provide 'image) ;;; image.el ends here diff --git a/src/image.c b/src/image.c index 1d83065cf7..5b324637ce 100644 --- a/src/image.c +++ b/src/image.c @@ -2406,6 +2406,11 @@ image_set_transform (struct frame *f, struct image *img) double rotation = 0.0; compute_image_rotation (img, &rotation); + /* Determine mirroring. */ + bool mirroring; + Lisp_Object m = image_spec_value (img->spec, QCmirror, NULL); + mirroring = !NILP (m); + #ifndef HAVE_HAIKU # if defined USE_CAIRO || defined HAVE_XRENDER || defined HAVE_NS /* We want scale up operations to use a nearest neighbor filter to @@ -2445,14 +2450,20 @@ image_set_transform (struct frame *f, struct image *img) /* Perform rotation transformation. */ int rotate_flag = -1; - if (rotation == 0) + if (rotation == 0 && !mirroring) rotate_flag = 0; else { # if (defined USE_CAIRO || defined HAVE_XRENDER \ || defined HAVE_NTGUI || defined HAVE_NS) int cos_r, sin_r; - if (rotation == 90) + if (rotation == 0) + { + cos_r = 1; + sin_r = 0; + rotate_flag = 1; + } + else if (rotation == 90) { width = img->height; height = img->width; @@ -2493,9 +2504,14 @@ image_set_transform (struct frame *f, struct image *img) matrix3x3 v; matrix3x3_mult (rot, u, v); - /* 3. Translate back. */ + /* 3. Translate back. Apply mirroring if requested. */ t[2][0] = width * -.5; t[2][1] = height * -.5; + if (mirroring) + { + t[0][0] = -t[0][0]; + t[2][0] = -t[2][0]; + } matrix3x3_mult (t, v, matrix); # else /* 1. Translate so (0, 0) is in the center of the image. */ @@ -2513,9 +2529,10 @@ image_set_transform (struct frame *f, struct image *img) matrix3x3 v; matrix3x3_mult (u, rot, v); - /* 3. Translate back. */ + /* 3. Translate back. Apply mirroring if requested. */ t[2][0] = width * .5; t[2][1] = height * .5; + if (mirroring) t[0][0] = -t[0][0]; matrix3x3_mult (v, t, matrix); # endif img->width = width; @@ -11363,6 +11380,7 @@ syms_of_image (void) DEFSYM (QCtransform_smoothing, ":transform-smoothing"); DEFSYM (QCcolor_adjustment, ":color-adjustment"); DEFSYM (QCmask, ":mask"); + DEFSYM (QCmirror, ":mirror"); /* Other symbols. */ DEFSYM (Qlaplace, "laplace"); -- 2.32.0 (Apple Git-132) ^ permalink raw reply related [flat|nested] 13+ messages in thread
* bug#47095: 27.1; Feature request: mirror image display 2021-12-27 8:36 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Timo Taipalus @ 2021-12-28 1:01 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-12-28 9:54 ` Timo Taipalus 2021-12-28 11:22 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Alan Third 1 sibling, 1 reply; 13+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-28 1:01 UTC (permalink / raw) To: Timo Taipalus; +Cc: 47095 Timo Taipalus <timo@taipalus.cc> writes: > It seems image-mode does not have capability for image mirroring, so > here's a patch for it. Tested NS (macOS) and XRender/Cairo > implementations. As it is, it has no effect if ImageMagick is > enabled. Can you try to make it work on Haiku? If you can't, no problems there (I will do that myself), but if you can it would make my life a little bit easier. Thanks. ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: 27.1; Feature request: mirror image display 2021-12-28 1:01 ` bug#47095: 27.1; Feature request: mirror image display Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-28 9:54 ` Timo Taipalus 2021-12-28 10:07 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 13+ messages in thread From: Timo Taipalus @ 2021-12-28 9:54 UTC (permalink / raw) To: Po Lu; +Cc: 47095 On 28.12.2021 3:01, Po Lu wrote: > Timo Taipalus <timo@taipalus.cc> writes: > >> It seems image-mode does not have capability for image mirroring, so >> here's a patch for it. Tested NS (macOS) and XRender/Cairo >> implementations. As it is, it has no effect if ImageMagick is >> enabled. > > Can you try to make it work on Haiku? If you can't, no problems there > (I will do that myself), but if you can it would make my life a little > bit easier. > > Thanks. Unfortunately I have no experience with Haiku. ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: 27.1; Feature request: mirror image display 2021-12-28 9:54 ` Timo Taipalus @ 2021-12-28 10:07 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 0 replies; 13+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-28 10:07 UTC (permalink / raw) To: Timo Taipalus; +Cc: 47095 Timo Taipalus <timo@taipalus.cc> writes: > On 28.12.2021 3:01, Po Lu wrote: >> Timo Taipalus <timo@taipalus.cc> writes: >> >>> It seems image-mode does not have capability for image mirroring, so >>> here's a patch for it. Tested NS (macOS) and XRender/Cairo >>> implementations. As it is, it has no effect if ImageMagick is >>> enabled. >> Can you try to make it work on Haiku? If you can't, no problems >> there >> (I will do that myself), but if you can it would make my life a little >> bit easier. >> Thanks. > > Unfortunately I have no experience with Haiku. Sure, when this is installed I'll implement it. Thanks anyway. ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: [PATCH] Add support for image mirroring (Bug#47095) 2021-12-27 8:36 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Timo Taipalus 2021-12-28 1:01 ` bug#47095: 27.1; Feature request: mirror image display Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-12-28 11:22 ` Alan Third 2021-12-28 18:09 ` bug#47095: [External] : " Drew Adams 2021-12-29 9:10 ` Timo Taipalus 1 sibling, 2 replies; 13+ messages in thread From: Alan Third @ 2021-12-28 11:22 UTC (permalink / raw) To: Timo Taipalus; +Cc: 47095 On Mon, Dec 27, 2021 at 10:36:43AM +0200, Timo Taipalus wrote: > It seems image-mode does not have capability for image mirroring, so > here's a patch for it. Tested NS (macOS) and XRender/Cairo > implementations. As it is, it has no effect if ImageMagick is > enabled. I suspect this won't work at all on windows due to the way the transform is implemented there, but someone should probably check. > I chose 'h' as the action key because 'm' and 'f' were reserved, and > 'h' is easy to memorize ("horizontal"). 'r' for reverse, maybe? Is it possible to do the mirroring before the rotation instead of as part of it? I feel like it would make the code a little clearer, although I suspect you're doing it in the rotation to reduce the number of calculations? Would it be possible to have both horizontal and vertical mirroring? -- Alan Third ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: [External] : bug#47095: [PATCH] Add support for image mirroring (Bug#47095) 2021-12-28 11:22 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Alan Third @ 2021-12-28 18:09 ` Drew Adams 2021-12-29 9:10 ` Timo Taipalus 1 sibling, 0 replies; 13+ messages in thread From: Drew Adams @ 2021-12-28 18:09 UTC (permalink / raw) To: Alan Third, Timo Taipalus; +Cc: 47095@debbugs.gnu.org > > I chose 'h' as the action key because 'm' and 'f' were reserved, and > > 'h' is easy to memorize ("horizontal"). > > 'r' for reverse, maybe? (Sorry, I'm not following this thread. Please ignore if my comment is OT or otherwise irrelevant.) But if this is about mirroring in the sense of flipping an image horizontally around its vertical midline, then `h' makes sense (and it is used in some image-display programs). Similarly, if we have vertical mirroring then it makes sense to use `v' for that. ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: [PATCH] Add support for image mirroring (Bug#47095) 2021-12-28 11:22 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Alan Third 2021-12-28 18:09 ` bug#47095: [External] : " Drew Adams @ 2021-12-29 9:10 ` Timo Taipalus 2022-01-02 14:54 ` Alan Third 1 sibling, 1 reply; 13+ messages in thread From: Timo Taipalus @ 2021-12-29 9:10 UTC (permalink / raw) To: Timo Taipalus; +Cc: 47095 [-- Attachment #1: Type: text/plain, Size: 1628 bytes --] On 28.12.2021 13:22, Alan Third wrote: > On Mon, Dec 27, 2021 at 10:36:43AM +0200, Timo Taipalus wrote: >> It seems image-mode does not have capability for image mirroring, so >> here's a patch for it. Tested NS (macOS) and XRender/Cairo >> implementations. As it is, it has no effect if ImageMagick is >> enabled. > > I suspect this won't work at all on windows due to the way the > transform is implemented there, but someone should probably check. > >> I chose 'h' as the action key because 'm' and 'f' were reserved, and >> 'h' is easy to memorize ("horizontal"). > > 'r' for reverse, maybe? > > Is it possible to do the mirroring before the rotation instead of as > part of it? I feel like it would make the code a little clearer, > although I suspect you're doing it in the rotation to reduce the > number of calculations? Would it be possible to have both horizontal > and vertical mirroring? As said elsewhere, "r" is reserved for rotation. :) I added an elisp function to do a vertical flip. Also I renamed the procedure flipping because that's what GIMP calls it. Attached is a revised patch to replace the previous one. As for the C code, I agree it adds some complexity to the transform function, but this is probably the fastest way to achieve it. Flipping before rotation would lead to strange results when the image has been rotated 90/270 degrees. Then the flip commands seem reversed – horizontal flip actually flips vertically and vice versa. This is because the transform function always rotates the initial image, which is what would be flipped. Hopefully someone can test this patch on Windows. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-support-for-image-flipping-Bug-47095.patch --] [-- Type: text/x-diff; name=0001-Add-support-for-image-flipping-Bug-47095.patch, Size: 4706 bytes --] From b58619431d6fa0f6b9f50a94aefc09be6121fa3e Mon Sep 17 00:00:00 2001 From: Timo <timo@taipalus.cc> Date: Wed, 29 Dec 2021 10:55:06 +0200 Subject: [PATCH] Add support for image flipping (Bug#47095) * lisp/image.el (image-map): Keybindings for flipping functions. (image-flip-horizontally): New function that toggles image flipping property. (image-flip-vertically): New function that toggles image flipping property and rotates image by 180 degrees. * src/image.c (syms_of_image): Add property. (image_set_transform): Modify image rotation code to also horizontally flip the image when the property is set. * etc/NEWS: Add description. --- etc/NEWS | 4 ++++ lisp/image.el | 18 ++++++++++++++++++ src/image.c | 26 ++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index c9466d0fef..ae894c5465 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -570,6 +570,10 @@ This controls whether or not to show a message when opening certain image formats saying how to edit it as text. The default is to show this message for SVG and XPM. ++++ +*** New commands: 'image-flip-horizontally' and 'image-flip-vertically'. +These commands horizontally and vertically flip the image under point. + ** Image-Dired +++ diff --git a/lisp/image.el b/lisp/image.el index 702985f41f..05e50cc4ae 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -181,6 +181,8 @@ image-map (define-key map [C-wheel-up] 'image-mouse-increase-size) (define-key map [C-mouse-4] 'image-mouse-increase-size) (define-key map "r" 'image-rotate) + (define-key map "h" 'image-flip-horizontally) + (define-key map "v" 'image-flip-vertically) (define-key map "o" 'image-save) map)) @@ -1249,6 +1251,22 @@ image-save (write-region (point-min) (point-max) (read-file-name "Write image to file: "))))) +(defun image-flip-horizontally () + "Horizontally flip the image under point." + (interactive) + (let ((image (image--get-image))) + (image-flush image) + (setf (image-property image :flip) + (not (image-property image :flip))))) + +(defun image-flip-vertically () + "Vertically flip the image under point." + (interactive) + (let ((image (image--get-image))) + (image-rotate 180) + (setf (image-property image :flip) + (not (image-property image :flip))))) + (provide 'image) ;;; image.el ends here diff --git a/src/image.c b/src/image.c index 1d83065cf7..5cbc85f357 100644 --- a/src/image.c +++ b/src/image.c @@ -2406,6 +2406,11 @@ image_set_transform (struct frame *f, struct image *img) double rotation = 0.0; compute_image_rotation (img, &rotation); + /* Determine flipping. */ + bool flip; + Lisp_Object m = image_spec_value (img->spec, QCflip, NULL); + flip = !NILP (m); + #ifndef HAVE_HAIKU # if defined USE_CAIRO || defined HAVE_XRENDER || defined HAVE_NS /* We want scale up operations to use a nearest neighbor filter to @@ -2445,14 +2450,20 @@ image_set_transform (struct frame *f, struct image *img) /* Perform rotation transformation. */ int rotate_flag = -1; - if (rotation == 0) + if (rotation == 0 && !flip) rotate_flag = 0; else { # if (defined USE_CAIRO || defined HAVE_XRENDER \ || defined HAVE_NTGUI || defined HAVE_NS) int cos_r, sin_r; - if (rotation == 90) + if (rotation == 0) + { + cos_r = 1; + sin_r = 0; + rotate_flag = 1; + } + else if (rotation == 90) { width = img->height; height = img->width; @@ -2493,9 +2504,14 @@ image_set_transform (struct frame *f, struct image *img) matrix3x3 v; matrix3x3_mult (rot, u, v); - /* 3. Translate back. */ + /* 3. Translate back. Flip horizontally if requested. */ t[2][0] = width * -.5; t[2][1] = height * -.5; + if (flip) + { + t[0][0] = -t[0][0]; + t[2][0] = -t[2][0]; + } matrix3x3_mult (t, v, matrix); # else /* 1. Translate so (0, 0) is in the center of the image. */ @@ -2513,9 +2529,10 @@ image_set_transform (struct frame *f, struct image *img) matrix3x3 v; matrix3x3_mult (u, rot, v); - /* 3. Translate back. */ + /* 3. Translate back. Flip horizontally if requested. */ t[2][0] = width * .5; t[2][1] = height * .5; + if (flip) t[0][0] = -t[0][0]; matrix3x3_mult (v, t, matrix); # endif img->width = width; @@ -11363,6 +11380,7 @@ syms_of_image (void) DEFSYM (QCtransform_smoothing, ":transform-smoothing"); DEFSYM (QCcolor_adjustment, ":color-adjustment"); DEFSYM (QCmask, ":mask"); + DEFSYM (QCflip, ":flip"); /* Other symbols. */ DEFSYM (Qlaplace, "laplace"); -- 2.32.0 (Apple Git-132) ^ permalink raw reply related [flat|nested] 13+ messages in thread
* bug#47095: [PATCH] Add support for image mirroring (Bug#47095) 2021-12-29 9:10 ` Timo Taipalus @ 2022-01-02 14:54 ` Alan Third 2022-01-04 10:25 ` Alan Third 2022-01-07 17:00 ` Timo Taipalus 0 siblings, 2 replies; 13+ messages in thread From: Alan Third @ 2022-01-02 14:54 UTC (permalink / raw) To: Timo Taipalus; +Cc: 47095 On Wed, Dec 29, 2021 at 11:10:03AM +0200, Timo Taipalus wrote: > On 28.12.2021 13:22, Alan Third wrote: > > Is it possible to do the mirroring before the rotation instead of as > > part of it? I feel like it would make the code a little clearer, > > although I suspect you're doing it in the rotation to reduce the > > number of calculations? Would it be possible to have both horizontal > > and vertical mirroring? > > As said elsewhere, "r" is reserved for rotation. :) > > I added an elisp function to do a vertical flip. Also I renamed the > procedure flipping because that's what GIMP calls it. Attached is a > revised patch to replace the previous one. > > As for the C code, I agree it adds some complexity to the transform > function, but this is probably the fastest way to achieve it. > > Flipping before rotation would lead to strange results when the image > has been rotated 90/270 degrees. Then the flip commands seem reversed > – horizontal flip actually flips vertically and vice versa. This is > because the transform function always rotates the initial image, > which is what would be flipped. That's actually what I'd expect to happen, tbh. :) There's a bit of a problem with Emacs image manipulation, IMO, in that the transform order is baked in, so we end up with strange situations like when you set max-width, then rotate 90 degrees so now max-width affects the height of the image instead of the width. So whatever, I don't feel very strongly about it. One more thing: do you feel up to adding a note in the manual about this new property? It should go in doc/lispref/display.texi. Look for rotation. > Hopefully someone can test this patch on Windows. Indeed. If nobody tests it in a week or so we can try just pushing it to master and hope someone reports a bug if it doesn't work. -- Alan Third ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: [PATCH] Add support for image mirroring (Bug#47095) 2022-01-02 14:54 ` Alan Third @ 2022-01-04 10:25 ` Alan Third 2022-01-05 16:14 ` Lars Ingebrigtsen 2022-01-07 17:00 ` Timo Taipalus 1 sibling, 1 reply; 13+ messages in thread From: Alan Third @ 2022-01-04 10:25 UTC (permalink / raw) To: Timo Taipalus, 47095 On Sun, Jan 02, 2022 at 02:54:52PM +0000, Alan Third wrote: > On Wed, Dec 29, 2021 at 11:10:03AM +0200, Timo Taipalus wrote: > > Hopefully someone can test this patch on Windows. > > Indeed. If nobody tests it in a week or so we can try just pushing it > to master and hope someone reports a bug if it doesn't work. Oh, I forgot to check, do you have the copyright paperwork on file with the FSF? -- Alan Third ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: [PATCH] Add support for image mirroring (Bug#47095) 2022-01-04 10:25 ` Alan Third @ 2022-01-05 16:14 ` Lars Ingebrigtsen 0 siblings, 0 replies; 13+ messages in thread From: Lars Ingebrigtsen @ 2022-01-05 16:14 UTC (permalink / raw) To: Alan Third; +Cc: Timo Taipalus, 47095 Alan Third <alan@idiocy.org> writes: >> Indeed. If nobody tests it in a week or so we can try just pushing it >> to master and hope someone reports a bug if it doesn't work. > > Oh, I forgot to check, do you have the copyright paperwork on file > with the FSF? I don't see the name in the copyright.list file. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#47095: [PATCH] Add support for image mirroring (Bug#47095) 2022-01-02 14:54 ` Alan Third 2022-01-04 10:25 ` Alan Third @ 2022-01-07 17:00 ` Timo Taipalus 2022-06-24 12:45 ` bug#47095: 27.1; Feature request: mirror image display Lars Ingebrigtsen 1 sibling, 1 reply; 13+ messages in thread From: Timo Taipalus @ 2022-01-07 17:00 UTC (permalink / raw) To: Alan Third; +Cc: 47095 [-- Attachment #1: Type: text/plain, Size: 955 bytes --] On 2.1.2022 16:54, Alan Third wrote: > That's actually what I'd expect to happen, tbh. :) > > There's a bit of a problem with Emacs image manipulation, IMO, in that > the transform order is baked in, so we end up with strange situations > like when you set max-width, then rotate 90 degrees so now max-width > affects the height of the image instead of the width. > > So whatever, I don't feel very strongly about it. In my experience the way flipping works now is how image viewers generally work. But I guess neither is the one true way, the way it works now is my preference. If many do feel strongly about it, then it can be changed I guess. > > One more thing: do you feel up to adding a note in the manual about > this new property? It should go in doc/lispref/display.texi. Look for > rotation. > I added documentation as requested plus code comments. The paperwork was sent on 26th Dec to assign@gnu.org, so admins please check there. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-support-for-image-flipping-Bug-47095_rev_3.patch --] [-- Type: text/x-diff; name=0001-Add-support-for-image-flipping-Bug-47095_rev_3.patch, Size: 5901 bytes --] From e25c6211a88d0b05aad035c481f3a7cee3d0eb16 Mon Sep 17 00:00:00 2001 From: Timo Taipalus <timo@taipalus.cc> Date: Thu, 6 Jan 2022 10:28:38 +0200 Subject: [PATCH] Add support for image flipping (Bug#47095) * lisp/image.el (image-map): Keybindings for flipping functions. (image-flip-horizontally): New function that toggles image flipping property. (image-flip-vertically): New function that toggles image flipping property and rotates image 180 degrees. * src/image.c (syms_of_image): Add property. (image_set_transform): Modify image rotation code to also horizontally flip the image when the property is set. * etc/NEWS: Add description. * doc/lispref/display.texi (Image Descriptors): Document :flip. --- doc/lispref/display.texi | 6 ++++++ etc/NEWS | 4 ++++ lisp/image.el | 18 ++++++++++++++++++ src/image.c | 31 +++++++++++++++++++++++++++---- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 1b08eda200..488af2a866 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -5596,6 +5596,12 @@ Image Descriptors values rotate clockwise, negative values counter-clockwise. Rotation is performed after scaling and cropping. +@item :flip @var{flip} +If this is @code{t}, the image will be horizontally flipped. +Currently it has no effect if the image type is @code{imagemagick}. +Vertical flipping can be achieved by rotating the image 180 degrees +and toggling this value. + @item :transform-smoothing @var{smooth} If this is @code{t}, any image transform will have smoothing applied; if @code{nil}, no smoothing will be applied. The exact algorithm used diff --git a/etc/NEWS b/etc/NEWS index 9c892b285d..231beae5d1 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -599,6 +599,10 @@ This controls whether or not to show a message when opening certain image formats saying how to edit it as text. The default is to show this message for SVG and XPM. ++++ +*** New commands: 'image-flip-horizontally' and 'image-flip-vertically'. +These commands horizontally and vertically flip the image under point. + ** Image-Dired +++ diff --git a/lisp/image.el b/lisp/image.el index c9165f7781..53358888c2 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -181,6 +181,8 @@ image-map (define-key map [C-wheel-up] 'image-mouse-increase-size) (define-key map [C-mouse-4] 'image-mouse-increase-size) (define-key map "r" 'image-rotate) + (define-key map "h" 'image-flip-horizontally) + (define-key map "v" 'image-flip-vertically) (define-key map "o" 'image-save) map)) @@ -1249,6 +1251,22 @@ image-save (write-region (point-min) (point-max) (read-file-name "Write image to file: "))))) +(defun image-flip-horizontally () + "Horizontally flip the image under point." + (interactive) + (let ((image (image--get-image))) + (image-flush image) + (setf (image-property image :flip) + (not (image-property image :flip))))) + +(defun image-flip-vertically () + "Vertically flip the image under point." + (interactive) + (let ((image (image--get-image))) + (image-rotate 180) + (setf (image-property image :flip) + (not (image-property image :flip))))) + (provide 'image) ;;; image.el ends here diff --git a/src/image.c b/src/image.c index e7d347b782..61771ee4cf 100644 --- a/src/image.c +++ b/src/image.c @@ -2408,6 +2408,11 @@ image_set_transform (struct frame *f, struct image *img) double rotation = 0.0; compute_image_rotation (img, &rotation); + /* Determine flipping. */ + bool flip; + Lisp_Object m = image_spec_value (img->spec, QCflip, NULL); + flip = !NILP (m); + #ifndef HAVE_HAIKU # if defined USE_CAIRO || defined HAVE_XRENDER || defined HAVE_NS /* We want scale up operations to use a nearest neighbor filter to @@ -2447,14 +2452,25 @@ image_set_transform (struct frame *f, struct image *img) /* Perform rotation transformation. */ int rotate_flag = -1; - if (rotation == 0) + if (rotation == 0 && !flip) rotate_flag = 0; else { # if (defined USE_CAIRO || defined HAVE_XRENDER \ || defined HAVE_NTGUI || defined HAVE_NS) int cos_r, sin_r; - if (rotation == 90) + if (rotation == 0) + { + /* FLIP is always true here. As this will rotate by 0 + degrees, it has no visible effect. Applying only + translation matrix to the image would be sufficient for + horizontal flipping, but writing special handling for + this case would increase code complexity somewhat. */ + cos_r = 1; + sin_r = 0; + rotate_flag = 1; + } + else if (rotation == 90) { width = img->height; height = img->width; @@ -2495,9 +2511,14 @@ image_set_transform (struct frame *f, struct image *img) matrix3x3 v; matrix3x3_mult (rot, u, v); - /* 3. Translate back. */ + /* 3. Translate back. Flip horizontally if requested. */ t[2][0] = width * -.5; t[2][1] = height * -.5; + if (flip) + { + t[0][0] = -t[0][0]; + t[2][0] = -t[2][0]; + } matrix3x3_mult (t, v, matrix); # else /* 1. Translate so (0, 0) is in the center of the image. */ @@ -2515,9 +2536,10 @@ image_set_transform (struct frame *f, struct image *img) matrix3x3 v; matrix3x3_mult (u, rot, v); - /* 3. Translate back. */ + /* 3. Translate back. Flip horizontally if requested. */ t[2][0] = width * .5; t[2][1] = height * .5; + if (flip) t[0][0] = -t[0][0]; matrix3x3_mult (v, t, matrix); # endif img->width = width; @@ -11365,6 +11387,7 @@ syms_of_image (void) DEFSYM (QCtransform_smoothing, ":transform-smoothing"); DEFSYM (QCcolor_adjustment, ":color-adjustment"); DEFSYM (QCmask, ":mask"); + DEFSYM (QCflip, ":flip"); /* Other symbols. */ DEFSYM (Qlaplace, "laplace"); -- 2.32.0 (Apple Git-132) ^ permalink raw reply related [flat|nested] 13+ messages in thread
* bug#47095: 27.1; Feature request: mirror image display 2022-01-07 17:00 ` Timo Taipalus @ 2022-06-24 12:45 ` Lars Ingebrigtsen 0 siblings, 0 replies; 13+ messages in thread From: Lars Ingebrigtsen @ 2022-06-24 12:45 UTC (permalink / raw) To: Timo Taipalus; +Cc: Alan Third, 47095 Timo Taipalus <timo@taipalus.cc> writes: > The paperwork was sent on 26th Dec to assign@gnu.org, so admins please > check there. The paperwork was finished in February, apparently, but then we forgot to apply the patch. So I've now tested the patch, and it seems to work great. Now pushed to Emacs 29. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-06-24 12:45 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-03-12 10:34 bug#47095: 27.1; Feature request: mirror image display ynyaaa 2021-12-27 8:36 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Timo Taipalus 2021-12-28 1:01 ` bug#47095: 27.1; Feature request: mirror image display Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-12-28 9:54 ` Timo Taipalus 2021-12-28 10:07 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-12-28 11:22 ` bug#47095: [PATCH] Add support for image mirroring (Bug#47095) Alan Third 2021-12-28 18:09 ` bug#47095: [External] : " Drew Adams 2021-12-29 9:10 ` Timo Taipalus 2022-01-02 14:54 ` Alan Third 2022-01-04 10:25 ` Alan Third 2022-01-05 16:14 ` Lars Ingebrigtsen 2022-01-07 17:00 ` Timo Taipalus 2022-06-24 12:45 ` bug#47095: 27.1; Feature request: mirror image display Lars Ingebrigtsen
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.