all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Image transformations
Date: Tue, 11 Jun 2019 21:02:33 +0100	[thread overview]
Message-ID: <20190611200233.GA80199@breton.holly.idiocy.org> (raw)
In-Reply-To: <9A21DE14-BB5F-426E-BBB2-19C87930E733@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2254 bytes --]

On Tue, Jun 11, 2019 at 08:10:41AM +0300, Eli Zaretskii wrote:
>   . The :crop parameter of image specs doesn't seem to be documented anywhere.  We previously supported it without documenting only for ImageMagick, which was already a problem; now it's a much bigger problem.
>   . The ELisp manual doesn't mention that :rotation is generally supported only for multiples of 90 deg, except if ImageMagick is available.
>   . The transformation matrix used by the implementation is not described; one needs to guess what its components mean, or search the Internet for docs of XRender and/or Cairo, which are generally not helpful enough, especially the XRender one.

I hope the attached patch goes some way to solving these issues.

>   . There are no tests, AFAICT.  We should have a simple manual test
>   which could be used to exercise all of the transformations,
>   separately and in combinations.  I wonder how did the people who
>   worked on the implementations for different platforns verify that
>   the results are consistent, especially given the lack of
>   documentation (e.g., is rotation of 90 deg clockwise or
>   counter-clockwise?).

Is there some example of how to write a manual test like this?

>  . I question the wisdom of the current definition of
>  image-transforms-p. First, it returns a simple yes/no value, under
>  the assumption that either all of the transformations are supported
>  or none of them; IMO, it is better to return a list of supported
>  capabilities instead. Second, it doesn't distinguish between
>  capability to rotate by arbitrary angles and by 90 deg multiples
>  only, which will require Lisp programs to test for ImageMagick,
>  something that undermines the very raison d'etre of this function

My hope was that MS Windows support for affine transform matrices
would be forthcoming quite quickly in which case there would be no
need to differentiate between the different types of transform (if one
is supported, they all are), but perhaps that’s hoping for too much. :)

I’ve been thinking a bit about the idea of returning some sort of
capabilities list and it seems quite neat. We could perhaps roll some
of the imagemagick-types stuff into it.

I’ll look into it further.

-- 
Alan Third

[-- Attachment #2: 0001-Document-image-transforms.patch --]
[-- Type: text/plain, Size: 3127 bytes --]

From bb51fbf18d8e9fcb7f65afef49d802b9fc768149 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Tue, 11 Jun 2019 20:31:24 +0100
Subject: [PATCH] Document image transforms

* doc/lispref/display.texi (Image Descriptors): Document :crop and
update :rotation.
* src/image.c: Describe the image transform matrix layout.
---
 doc/lispref/display.texi | 23 ++++++++++++++++++++++-
 src/image.c              | 16 ++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 93c5217c36..d29e98a8fd 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -5181,8 +5181,29 @@ Image Descriptors
 specified, the height/width will be adjusted by the specified scaling
 factor.
 
+@item :crop @var{geometry}
+This should be a list of the form @code{(@var{width} @var{height}
+@var{x} @var{y})}.  If @var{width} and @var{height} are positive
+numbers they specify the width and height of the cropped image.  If
+@var{x} is a positive number it specifies the offset of the cropped
+area from the left of the original image, and if negative the offset
+from the right. If @var{y} is a positive number it specifies the
+offset from the top of the original image, and if negative from the
+bottom. If @var{x} or @var{y} are @code{nil} or unspecified the crop
+area will be centred on the original image.
+
+If the crop area is outside or overlaps the edge of the image it will
+be reduced to exclude any areas outside of the image.  This means it
+is not possible to use @code{:crop} to increase the size of the image
+by entering large @var{width} or @var{height} values.
+
+Cropping is performed after scaling but before rotation.
+
 @item :rotation @var{angle}
-Specifies a rotation angle in degrees.
+Specifies a rotation angle in degrees.  Only multiples of 90 degrees
+are supported, unless the image type is @code{imagemagick}.  Positive
+values rotate clockwise, negative values anti-clockwise.  Rotation is
+performed after scaling and cropping.
 
 @item :index @var{frame}
 @xref{Multi-Frame Images}.
diff --git a/src/image.c b/src/image.c
index 86f8e8f4bb..12e35e4527 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1967,6 +1967,22 @@ compute_image_size (size_t width, size_t 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:
+
+   m[0][0] = m11 | m[0][1] = m12 | m[0][2] = tx
+   --------------+---------------+-------------
+   m[1][0] = m21 | m[1][1] = m22 | m[1][2] = ty
+   --------------+---------------+-------------
+   m[2][0] = 0   | m[2][1] = 0   | m[2][2] = 1
+
+   tx and ty represent translations, m11 and m22 represent scaling
+   transforms and m21 and m12 represent shear transforms. Some
+   graphics toolkits don't require the third row, however it is
+   necessary for multiplication.  */
+
 typedef double matrix3x3[3][3];
 
 static void
-- 
2.21.0


  reply	other threads:[~2019-06-11 20:02 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11  5:10 Image transformations Eli Zaretskii
2019-06-11 20:02 ` Alan Third [this message]
2019-06-12 15:30   ` Eli Zaretskii
2019-06-12 22:07     ` Alan Third
2019-06-12 22:15       ` Alan Third
2019-06-13  4:16       ` Alp Aker
2019-06-13  5:41         ` Eli Zaretskii
2019-06-13  9:19           ` Alp Aker
2019-06-13 13:05             ` Eli Zaretskii
2019-06-13 15:57               ` Alp Aker
2019-06-13 16:20                 ` Eli Zaretskii
2019-06-13 19:00                   ` Richard Copley
2019-06-13 19:29                     ` Eli Zaretskii
2019-06-14 10:45                     ` Alp Aker
2019-06-14 10:55                       ` Richard Copley
2019-06-14 11:45                         ` YAMAMOTO Mitsuharu
2019-06-14 11:59                         ` Alp Aker
2019-06-13 16:12           ` Alan Third
2019-06-13 17:05             ` Eli Zaretskii
2019-06-13 19:35               ` Richard Copley
2019-06-13  5:48       ` Eli Zaretskii
2019-06-13 16:58         ` Alan Third
2019-06-13 17:11           ` Eli Zaretskii
2019-06-13 19:27             ` Alan Third
2019-06-13 19:39               ` Alan Third
2019-06-13 19:47               ` Eli Zaretskii
2019-06-13 22:26                 ` Alan Third
2019-06-14  7:05                   ` Eli Zaretskii
2019-06-14  9:57                     ` Stefan Monnier
2019-06-14 10:57                       ` Eli Zaretskii
2019-06-14 11:21                         ` Richard Copley
2019-06-14 12:06                           ` Eli Zaretskii
2019-06-14 12:49                             ` Richard Copley
2019-06-14 14:16                               ` Yuri Khan
2019-06-14 14:43                               ` Eli Zaretskii
2019-06-14 15:55                                 ` Richard Copley
2019-06-15 11:00                                   ` Alan Third
2019-06-15 11:34                                     ` Eli Zaretskii
2019-06-15 10:42                     ` Alan Third
2019-06-15 11:31                       ` Eli Zaretskii
2019-06-16 15:22                         ` Alan Third
2019-06-16 16:34                           ` Eli Zaretskii
2019-06-17 21:13                             ` Alan Third
2019-06-19 17:56                               ` Eli Zaretskii
2019-06-24 17:54                               ` Eli Zaretskii
2019-06-24 19:50                                 ` Stefan Monnier
2019-06-25  2:33                                   ` Eli Zaretskii
2019-06-25  3:28                                     ` Stefan Monnier
2019-06-25  4:34                                       ` Eli Zaretskii
2019-06-25 14:43                                         ` Stefan Monnier
2019-06-25 15:35                                           ` Eli Zaretskii
2019-06-26  0:28                                             ` YAMAMOTO Mitsuharu
2019-06-26 15:34                                               ` Eli Zaretskii
2019-06-27  3:37                                                 ` YAMAMOTO Mitsuharu
2019-06-27 13:13                                                   ` Eli Zaretskii
2019-06-25 18:33                                 ` Alan Third
2019-06-25 18:57                                   ` Eli Zaretskii
2019-06-27 13:59                                     ` Eli Zaretskii
2019-06-28 18:36                                       ` Alan Third
2019-06-28 19:50                                         ` Eli Zaretskii
2019-06-29 11:55                                           ` Eli Zaretskii
2019-06-29 19:51                                             ` Alan Third
2019-06-29 19:49                                           ` Alan Third
2019-06-29 19:53                                             ` Lars Ingebrigtsen
2019-06-30 14:38                                               ` Alan Third
2019-06-30 15:24                                                 ` Lars Ingebrigtsen
2019-07-25 19:40                                                   ` Lars Ingebrigtsen
2019-07-26  6:10                                                     ` Eli Zaretskii
2019-07-26  6:46                                                       ` Lars Ingebrigtsen
2019-07-26  8:06                                                         ` Eli Zaretskii
2019-07-26  8:23                                                           ` Lars Ingebrigtsen
2019-07-26  8:24                                                             ` Lars Ingebrigtsen
2019-07-26  8:33                                                               ` Eli Zaretskii
2019-07-26  8:58                                                                 ` Lars Ingebrigtsen
2019-07-26  9:13                                                                   ` Eli Zaretskii
2019-07-26 10:23                                                                     ` Lars Ingebrigtsen
2019-07-26 14:08                                                                   ` Stefan Monnier
2019-07-26  8:32                                                             ` Eli Zaretskii
2019-06-29 21:05                                             ` Stefan Monnier
2019-06-30 15:12                                             ` Eli Zaretskii
2019-06-30 19:10                                               ` Alan Third
2019-07-01 14:55                                                 ` Eli Zaretskii
2019-06-18 11:01                       ` Tak Kunihiro
2019-06-13 17:41           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190611200233.GA80199@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.