Skip to main content
Inspiring
February 25, 2024
Answered

Writing a Plugin that scales the layer applied to

  • February 25, 2024
  • 2 replies
  • 2296 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 25, 2024

yes, the process you described is correct. take a peek at the sample projects in the SDK, they all (the effects at least) show a similar concept for handling the render.

 

now i'll go a bit deeper.

the only thing that really matters in regards to rendering, is that the ouptut buffer is returned filled within the scope of the render call. that is, you can't tell AE "i'll return now, bu t pass the result later". once your plug-in returns from a render call, AE will use the ouput buffer for downstream processes.

 

the rendering code itself doesn't have to reside entirely in the render function. you can write classes to handle that, you can send the innputs to a remote server for processing (don't do that. i'm just being rehtorical), AE doesn't know or care as long as the output buffer is filled by the time your plug-in returns from the render call.

 

some stuff to consider:

to use AE's suites, you would (probably) want to use the suite handler (otherwise it's a hassle to aquire and release the suites). to use that handler you need to pass it the basic_picaP pointer from in the in_data structure.

now we're getting to the point. that in_data structure is only valid within the scope of a single AE call to the plugin. if you try to store the in_data and use it after the call in which that data was sent has returned, that data is now garbage and using it will cause your plug-in to crash.

that being said, the basic_picaP pointer itself is consistent throughout the AE session, and is safe to store.