Skip to main content
Inspiring
February 25, 2024
Answered

Writing a Plugin that scales the layer applied to

  • February 25, 2024
  • 2 replies
  • 2248 views

Hi, im new to writing ae plugins and wanted to try figure out how to write a simple plugin that can scale the footage,layer etc... of what its applied to. 

 

i understand in logic of how to do it:

 

find out layer w&h in pixels

CurrentscaleX = 100;

CurrentScaleY = 100;

 

scaleP.ScaleMultipler = params[EXAMPLE_SCALE]->u.fs_d.value / 100;     ie 101/100= 1.01 scale increase  

 

if (ScaleP ) {

 NewscaleX = CurrentScaleX * Scale Multiplier; 

 NewscaleY = CurrentScaleY * Scale Multiplier; 

 

CurrentScaleX = NewScaleX;

CurrentScaleY = NewScaleY;

}

 

but as to writing that logic into a format the sdk can understand i have no idea. would be great if i could get a bit of help.

Correct answer Mallowed

oh gawd no! construct one matrix and do the transormation only once. both for performance sake and for not re-sampling the image 3 times which will blur your image in a nasty way.

 

you're putting the correct stuff in the correct places in the matrix, but these operations need to be multiplied as whole matrices for each of the transformation operations, and not multiplying the separate components in the matrix.

lookup matrix multiplication. you'll find a function in no time.

 

but here's some shortcuts before going on this adventure:

the default matirx which does nothing is rederred to as "identity mtrix". it's filled as follows:

1, 0, 0,

0, 1, 0,

0, 0, 1,

use that as the base for each of your separate transform, scale and rotate matrices, and then multiply them.

 

2. matrix operations happen relative to the top left corner of the image. if you want it relative to the center you need to first create an transpose matrix for half the width and height.

so what you'd actually want to do to construct a proper transformation matrix is:

1. create a transpose matrix for negative the anchor point value. that moves the image's pivot point to the matrix's 0,0 coordinate.

2. multiply that matrix by the scale matrix, which will now happen around the anchor point.

3. multiply the previous result by the rotation marix (again, will happen aroung the expected point)

4. multiply the previous result by another transform matrix with the x/y position values.

that's it. your matrix is ready to use.

when going more advanced, you'll want to factor in pixel aspext ration as well. it would just mean doing a scaling matrix on x and the begining and end steps.


I cannot thank you enough for all the help through this. i have the image scaling through the slider now without issue, i need to make it scale from the center of the layer but im sure i can figure out the rest myself, i cannot thank you enough through all of this. you are a legend,

 

Mal

2 replies

Community Expert
February 25, 2024

generally speaking, a plug-in receives an input buffer with pixels to mnipulate, and an output buffer to put the results into. *how* the output buffer is filled is entirely up to you. AE doesn't care.

so to scale your image you could use your won algorithm to shuffle pixels around, use 3rd party libraries, OR use some of the tools supplied by AE's API.

for example, you could use transform_world() from PF_WorldTransformSuite1 to transpose, scale to rotate an image.

here's a thread talking aobut it:
https://community.adobe.com/t5/after-effects-discussions/help-with-transform-world/m-p/1840909

search the forum for more info, this function has been talked about here on numerous occasions.

MallowedAuthor
Inspiring
February 25, 2024

thank you for this, i saw in the sdk documentation about transform_world() but didnt know how to execute it. do just code it directly into the render section of the cpp file or do i use a err(suites.pf_worldtransfomsuite1 )-> and pass it through to a func8?

 

sorry if this seems like a silly question but still very new to this 

Community Expert
February 27, 2024

I cannot thank you enough for all the help through this. i have the image scaling through the slider now without issue, i need to make it scale from the center of the layer but im sure i can figure out the rest myself, i cannot thank you enough through all of this. you are a legend,

 

Mal


i'm marking your answer as correct because it contains only true statements.