emacs-devel
[Top][All Lists]

## Re: Image transformations

 From: Alan Third Subject: Re: Image transformations Date: Thu, 13 Jun 2019 17:12:15 +0100 User-agent: Mutt/1.12.0 (2019-05-25)

```On Thu, Jun 13, 2019 at 08:41:02AM +0300, Eli Zaretskii wrote:
> > From: Alp Aker <address@hidden>
> > Date: Thu, 13 Jun 2019 00:16:36 -0400
> >
> > > matrix:
> > > 0.000000 1.000000 0.000000
> > > -1.000000 0.000000 232.000000
> > > 0.000000 0.000000 1.000000
> > >
> > > I don’t know exactly what that means.  The 1 and -1 are shearing the
> > > image in the x and y dimensions. The 232 is moving the image in the y
> > > dimension
> >
> > This is a transformation matrix using so-called homogenous coordinates:
> >
> > https://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations
>
> Right, I got that far, it's the details that somewhat confuse me, see
> below.
>
> > It's a clockwise 90 degree rotation followed by a translation along the y
> > axis.
>
> This already goes contrary to my geometric intuition, please bear with
> me.  The rotation is around the (0,0) origin, i.e. around the top-left
> corner of the original image, right?  If so, the rotation should have
> been followed by a translation along the X axis, not Y, because
> rotating a 333-pixel wide, 233-pixel high image 90 deg clockwise
> produces a 233-pixel wide, 333-pixel high image that is entirely to
> the LEFT of the Y axis.  Here's ASCII-art representation of that:
>
>     +------------------+> X        +----------+-------------------> X
>     |                  |           |          |
>     |                  |           |          |
>     |                  |           |          |
>     |                  |   ===>    |          |
>     +------------------+           |          |
>     |                              |          |
>     |                              |          |
>     |                              |          |
>     |                              +----------+
>     |                                         |
>     V                                         V
>     Y                                         Y
>
> The above is just after the rotation around (0,0).  Is that correct,
> or am I missing something?

I think I confused things by saying ‘followed by’, as I think they
probably happen simultaneously.

It works if you consider it as moving the origin from the top left
corner, 232 pixels down the Y axis to the bottom left corner, then
especially since this matrix is the result of two translations and a
rotation multiplied together.

One thing that may also be confusing is that there are two different
approaches to this. XRender applies the transforms to the image,
whereas NS applies the tranforms to the surface the image is to be
drawn to. I have a suspicion, having read some Windows API
documentation (but not much) that Windows works the same way as NS.
This is unfortunate as it’s harder to understand what’s going on.

A way to visualise the difference is that XRender is like taking a
photo and rotating and moving it around before putting it on a bit of
paper. The NS method is like holding a photo still and moving the bit
of paper under it.

The key difference is that for NS I have to invert the transformation
matrix. I also have to take more care with where I place the origin
before applying the transformation matrix.

I could be wrong, but it may explain why things aren’t doing what
you’re expecting. Or it could simply be down to the fact I transposed
the rows and columns. I think it’s probably a good idea for us to deal
with the transposition first before making any definite statements on
this.
--
Alan Third

```