Jump to content

Trouble with Equations filter : do ‘w’ and ‘h’ always stand for document width and height ?


Recommended Posts

I recently wrote formulas for the Equations filter that map the initial rectangle of a pixel layer into a truncated diamond inscribed in this rectangle

      x=x

      y= h/2+(y-h/2)/(1-(1-a)*abs(1-2*x/w))

where ‘a’ is a glider-controlled variable between 0 and 1 (perfect diamond for a=0 and no distortion for a=1)

 

To save time in experimentations, I made a macro of it, at

http://www.oitregor.com/numeric/affinity_photo/divers/losange.afmacro

(to be imported within Macro panel).  It generally works  as expected, as shown below:

image.thumb.jpeg.2c254fa136f7e7b0063d101eae104568.jpeg

However it sometimes fails. I specially met up against this issue after using the Move tool. In the following picture, I prepared a detailed, simple process to show what can happen —and a possible way to avoid it.   I would be happy to understand what occurs, whether it is a bug somewhere in Affinity Photo or a misunderstanding of mine.

image.thumb.jpeg.b42b15e7b62dc2d6ff8a1681e9c10b89.jpeg

 

 

Link to comment
Share on other sites

  • Moderators

Hi @ch22,

The Macro has worked here for myself and another member of the Tech Team, could you provide a screen recording of your actions?

Also instead of using the Selection Tools to select the red rectangle, you can just right click on the Rectangle in the Layers Panel and select Duplicate, does that give you better results?

Link to comment
Share on other sites

If you stretch a pixel layer, you will change the dpi, not the pixel size. This might explain the difference.

Maybe adding a rasterize (after move/stretch) step could solve the issue

Link to comment
Share on other sites

 The point is not to accommodate with the behaviour of my macro (I gave a way for that), it is that this behaviour is not acceptable. I built my process only to put  it in evidence. Maybe I misunderstood something —in this case, please explain!  I join the video record you asked for.

 

 

 

Link to comment
Share on other sites

It is exactly what i assumed before: you need to rasterize and trim the layer after enlarging it by move tool (about timecode 1:24)

the macro works correctly in every case. By enlarging the layer you effectively reduced the layer dpi. The equations filter delivers its result, and keeps the layer dpi. You can simply reduce the size of that layer again. When activating the move tool, and zoom out, you can see that the layer kept is original pixel size, but it has been stretched (not changing the number of pixels).

Dont take this as offending, i simply describe the technical facts.

The best advise is to use equations only on layers covering the canvas, having the same DPI and size as the canvas.

Otherwise surprising results like this may occur - not a bug in my view.

Ps: just tested (on iPad).

when you apply equations to transformed layer (position, dpi, rotation, skew) it will work on the layer x/y coordinate system ( not the canvas system), E.g. when the layer is rotated by 90 degree, a formula x=x+w/2 will move all pixels in the layer x axis to the left. As the transformation stays intact unchanged, all pixels will move upwards in y direction. 
 

layer and canvas are different animals. 

Link to comment
Share on other sites

To answer the original question 

Trouble with Equations filter : do ‘w’ and ‘h’ always stand for document width and height ?

no, it stays for layer w and h. If you want to access document size, use sw / sh instead - but this will not help in the example you gave.

 

https://affinity.help/photo/English.lproj/pages/Workspace/expressions.html

Link to comment
Share on other sites

@NotMyFault : thank you for your analysis.

For the title, I made it deliberately provocative to get attention. I had observed an illogical behavior and I was looking for a suspect: I offered a misinterpretation of w and h because these two variables are poorly documented in the available online help. For example, in the online manual (the link you provide), w and h are really presented as width and height of the document, not of the layer. Besides, there is no clear definition for the various terms proposed such as “document” or “spread”.

 Anyway, the issue does not come from a misunderstanding of document variables w and h. Similar anomalies can be observed with much simpler equations such as x=300+(x-300)/a  and y=200+(y-200)/a  (homothety with respect to point (300,200), of ratio ‘a’) as soon as the Move tool has been used on the layer, even for a simple move without deformation.  These anomalies can be avoided if the displaced part is set into a selection before moving it or, following your advice, by rasterizing the layer before applying to it the Equations filter.  Incidentally, where did you find this need for rasterizing so as not fooling the Equations filter? I never heard of that before.  A subsidiary question: what is different between a pixel layer and the same layer processed with the Move tool and which would disappear in the rasterizing operation?

Link to comment
Share on other sites

28 minutes ago, ch22 said:

A subsidiary question: what is different between a pixel layer and the same layer processed with the Move tool and which would disappear in the rasterizing operation?

Not sure if i understand this question fully.

the main difference is how out-of-canvas areas are treated by different tools (brushes, masks, rasterize, rasterize &trim., channels panel.

if you include DPI, rotation and sheer into the mix, it soon gets complicated (but always following some logic).

Rasterize itself (without trim) will not lead to “disappearing”.

Rasterize and trim will remove all out-of-canvas areas and fully transparent bounding box areas.

Link to comment
Share on other sites

Thanks

In my experiments, I'm careful not to drag any non-transparent pixels  from the source layer off the canvas with the Move Tool, and I find that Rasterize works just as well as Rasterize and Trim. I'm afraid that using the Move tool will create something else, in the very canvas.

Link to comment
Share on other sites

2 hours ago, ch22 said:

I'm afraid that using the Move tool will create something else, in the very canvas.

No, the move tool wont create anything on its own. 
 

it might help to create a complete and correct mental model of pixel layers and canvas, and how different operations interact with them.

Pixels are like 1x1 size lego blocks, having (one) color and transparency value. You can combine many of then (with invisible glue) on a rectangular grid.

To optimize storage and operation, Affinity uses a “bounding box”, the smallest possible rectangle which contains all non-transparent pixels.

You can stack as many of these layers as you want.

Then comes some magic: every layer can be transformed (individually)

  • Position x/y
  • rotation angle
  • Size in x direction
  • size in y direction
  • skew angle between x and y axis (lego can’t do the last 3)

you can create layers with unequal pixel length pixels, rhombus shapes pixels, and other strange shapes.

The canvas is simply a fixed size (but adjustable) window, always orthogonal, where you look through onto the stack of layers.

Rasterize (or merge down) will “press” layers pixels into the form of the target layer. In case of rasterize, it is a simple layer exactly like the canvas. In case of merge down, it uses any strange-hood of the lower layer. It is fun to play with these options.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

Please note there is currently a delay in replying to some post. See pinned thread in the Questions forum. These are the Terms of Use you will be asked to agree to if you join the forum. | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.