after_effects/pf/
out_data.rs

1use super::*;
2use std::any::Any;
3
4// struct PF_OutData {
5//     pub start_sampL: A_long,             // Used only for Audio commands
6//     pub dur_sampL: A_long,               // --^
7//     pub dest_snd: PF_SoundWorld,         // --^
8//     ...
9// }
10
11#[derive(Clone, Copy, Debug)]
12pub struct OutData {
13    pub(crate) ptr: *mut ae_sys::PF_OutData,
14}
15
16impl AsRef<ae_sys::PF_OutData> for OutData {
17    fn as_ref(&self) -> &ae_sys::PF_OutData {
18        unsafe { &*self.ptr }
19    }
20}
21impl AsMut<ae_sys::PF_OutData> for OutData {
22    fn as_mut(&mut self) -> &mut ae_sys::PF_OutData {
23        unsafe { &mut *self.ptr }
24    }
25}
26
27impl OutData {
28    pub fn from_raw(ptr: *mut ae_sys::PF_OutData) -> Self {
29        assert!(!ptr.is_null());
30        Self { ptr }
31    }
32
33    pub fn as_ptr(&self) -> *const ae_sys::PF_OutData {
34        self.ptr
35    }
36
37    pub fn width(&self) -> u32 {
38        self.as_ref().width as u32
39    }
40
41    /// Set during [`Command::FrameSetup`] if the output image size differs from the input. width and height are the size of the output buffer, and origin is the point the input should map to in the output.
42    /// To create a 5-pixel drop shadow up and left, set origin to (5, 5).
43    pub fn set_width(&mut self, width: u32) {
44        self.as_mut().width = width as ae_sys::A_long;
45    }
46
47    pub fn height(&self) -> u32 {
48        self.as_ref().height as u32
49    }
50
51    /// Set during [`Command::FrameSetup`] if the output image size differs from the input. width and height are the size of the output buffer, and origin is the point the input should map to in the output.
52    /// To create a 5-pixel drop shadow up and left, set origin to (5, 5).
53    pub fn set_height(&mut self, height: u32) {
54        self.as_mut().height = height as ae_sys::A_long;
55    }
56
57    pub fn origin(&self) -> Point {
58        self.as_ref().origin.into()
59    }
60
61    /// Set during [`Command::FrameSetup`] if the output image size differs from the input. width and height are the size of the output buffer, and origin is the point the input should map to in the output.
62    /// To create a 5-pixel drop shadow up and left, set origin to (5, 5).
63    pub fn set_origin(&mut self, origin: Point) {
64        self.as_mut().origin = origin.into();
65    }
66
67    /// After Effects displays any string you put here (checked and cleared after every command selector).
68    pub fn set_return_msg(&mut self, msg: &str) {
69        //let buf = std::ffi::CString::new(s).unwrap().into_bytes_with_nul();
70        //self.return_msg[0..buf.len()].copy_from_slice(unsafe { std::mem::transmute(buf.as_slice()) });
71        let msg = msg.as_bytes();
72        assert!(msg.len() < 256);
73        self.as_mut().return_msg[..msg.len()].copy_from_slice(unsafe { std::mem::transmute(msg) });
74    }
75
76    /// After Effects displays any string you put here as an error (checked and cleared after every command selector).
77    pub fn set_error_msg(&mut self, msg: &str) {
78        self.set_return_msg(msg);
79        self.set_out_flag(OutFlags::DisplayErrorMessage, true);
80    }
81
82    /// Set this flag to the version of your plug-in code. After Effects uses this data to decide which of duplicate effects to load.
83    pub fn set_version(&mut self, v: u32) {
84        self.as_mut().my_version = v as ae_sys::A_u_long;
85    }
86
87    /// Send messages to After Effects. OR together multiple values.
88    pub fn set_out_flags(&mut self, v: OutFlags) {
89        self.as_mut().out_flags = v.into();
90    }
91
92    /// Send messages to After Effects. OR together multiple values.
93    pub fn set_out_flags2(&mut self, v: OutFlags2) {
94        self.as_mut().out_flags2 = v.into();
95    }
96
97    /// Send messages to After Effects. OR together multiple values.
98    pub fn set_out_flag(&mut self, flag: OutFlags, enabled: bool) {
99        if enabled {
100            self.as_mut().out_flags |= Into::<ae_sys::PF_OutFlags>::into(flag);
101        } else {
102            self.as_mut().out_flags &= !(Into::<ae_sys::PF_OutFlags>::into(flag));
103        }
104    }
105
106    /// Send messages to After Effects. OR together multiple values.
107    pub fn set_out_flag2(&mut self, flag: OutFlags2, enabled: bool) {
108        if enabled {
109            self.as_mut().out_flags2 |= Into::<ae_sys::PF_OutFlags2>::into(flag);
110        } else {
111            self.as_mut().out_flags2 &= !(Into::<ae_sys::PF_OutFlags2>::into(flag));
112        }
113    }
114
115    /// Set the [`OutFlags::ForceRerender`] flag
116    pub fn set_force_rerender(&mut self) {
117        self.set_out_flag(OutFlags::ForceRerender, true);
118    }
119
120    /// Data you (might have) allocated during [`Command::FrameSetup`].
121    /// This is never written to disk; it was used to pass information from your [`Command::FrameSetup`] response to your [`Command::Render`] or [`Command::FrameSetdown`]
122    /// (which you must do if you resize the output buffer). Otherwise, this memory is rarely used.
123    pub fn set_frame_data<T: Any>(&mut self, val: T) {
124        let boxed: Box<Box<dyn Any>> = Box::new(Box::new(val));
125        self.as_mut().frame_data = Box::<Box<dyn Any>>::into_raw(boxed) as *mut _;
126    }
127}
128
129define_enum! {
130    ae_sys::PF_OutFlags,
131    OutFlags {
132        None                         = ae_sys::PF_OutFlag_NONE,
133        KeepResourceOpen             = ae_sys::PF_OutFlag_KEEP_RESOURCE_OPEN,
134        WideTimeInput                = ae_sys::PF_OutFlag_WIDE_TIME_INPUT,
135        NonParamVary                 = ae_sys::PF_OutFlag_NON_PARAM_VARY,
136        SequenceDataNeedsFlattening  = ae_sys::PF_OutFlag_SEQUENCE_DATA_NEEDS_FLATTENING,
137        IDoDialog                    = ae_sys::PF_OutFlag_I_DO_DIALOG,
138        UseOutputExtent              = ae_sys::PF_OutFlag_USE_OUTPUT_EXTENT,
139        SendDoDialog                 = ae_sys::PF_OutFlag_SEND_DO_DIALOG,
140        DisplayErrorMessage          = ae_sys::PF_OutFlag_DISPLAY_ERROR_MESSAGE,
141        IExpandBuffer                = ae_sys::PF_OutFlag_I_EXPAND_BUFFER,
142        PixIndependent               = ae_sys::PF_OutFlag_PIX_INDEPENDENT,
143        IWriteInputBuffer            = ae_sys::PF_OutFlag_I_WRITE_INPUT_BUFFER,
144        IShrinkBuffer                = ae_sys::PF_OutFlag_I_SHRINK_BUFFER,
145        WorksInPlace                 = ae_sys::PF_OutFlag_WORKS_IN_PLACE,
146        CustomUi                     = ae_sys::PF_OutFlag_CUSTOM_UI,
147        RefreshUi                    = ae_sys::PF_OutFlag_REFRESH_UI,
148        NopRender                    = ae_sys::PF_OutFlag_NOP_RENDER,
149        IUseShutterAngle             = ae_sys::PF_OutFlag_I_USE_SHUTTER_ANGLE,
150        IUseAudio                    = ae_sys::PF_OutFlag_I_USE_AUDIO,
151        IAmObsolete                  = ae_sys::PF_OutFlag_I_AM_OBSOLETE,
152        ForceRerender                = ae_sys::PF_OutFlag_FORCE_RERENDER,
153        PiplOverridesOutdataOutflags = ae_sys::PF_OutFlag_PiPL_OVERRIDES_OUTDATA_OUTFLAGS,
154        IHaveExternalDependencies    = ae_sys::PF_OutFlag_I_HAVE_EXTERNAL_DEPENDENCIES,
155        DeepColorAware               = ae_sys::PF_OutFlag_DEEP_COLOR_AWARE,
156        SendUpdateParamsUi           = ae_sys::PF_OutFlag_SEND_UPDATE_PARAMS_UI,
157        AudioFloatOnly               = ae_sys::PF_OutFlag_AUDIO_FLOAT_ONLY,
158        AudioIir                     = ae_sys::PF_OutFlag_AUDIO_IIR,
159        ISynthesizeAudio             = ae_sys::PF_OutFlag_I_SYNTHESIZE_AUDIO,
160        AudioEffectToo               = ae_sys::PF_OutFlag_AUDIO_EFFECT_TOO,
161        AudioEffectOnly              = ae_sys::PF_OutFlag_AUDIO_EFFECT_ONLY,
162    }
163}
164
165
166define_enum! {
167    ae_sys::PF_OutFlags2,
168    OutFlags2 {
169        None                                = ae_sys::PF_OutFlag2_NONE,
170        SupportsQueryDynamicFlags           = ae_sys::PF_OutFlag2_SUPPORTS_QUERY_DYNAMIC_FLAGS,
171        IUse3DCamera                        = ae_sys::PF_OutFlag2_I_USE_3D_CAMERA,
172        IUse3DLights                        = ae_sys::PF_OutFlag2_I_USE_3D_LIGHTS,
173        ParamGroupStartCollapsedFlag        = ae_sys::PF_OutFlag2_PARAM_GROUP_START_COLLAPSED_FLAG,
174        IAmThreadsafe                       = ae_sys::PF_OutFlag2_I_AM_THREADSAFE,
175        CanCombineWithDestination           = ae_sys::PF_OutFlag2_CAN_COMBINE_WITH_DESTINATION,
176        DoesntNeedEmptyPixels               = ae_sys::PF_OutFlag2_DOESNT_NEED_EMPTY_PIXELS,
177        RevealsZeroAlpha                    = ae_sys::PF_OutFlag2_REVEALS_ZERO_ALPHA,
178        PreservesFullyOpaquePixels          = ae_sys::PF_OutFlag2_PRESERVES_FULLY_OPAQUE_PIXELS,
179        SupportsSmartRender                 = ae_sys::PF_OutFlag2_SUPPORTS_SMART_RENDER,
180        FloatColorAware                     = ae_sys::PF_OutFlag2_FLOAT_COLOR_AWARE,
181        IUseColorspaceEnumeration           = ae_sys::PF_OutFlag2_I_USE_COLORSPACE_ENUMERATION,
182        IAmDeprecated                       = ae_sys::PF_OutFlag2_I_AM_DEPRECATED,
183        PproDoNotCloneSequenceDataForRender = ae_sys::PF_OutFlag2_PPRO_DO_NOT_CLONE_SEQUENCE_DATA_FOR_RENDER,
184        AutomaticWideTimeInput              = ae_sys::PF_OutFlag2_AUTOMATIC_WIDE_TIME_INPUT,
185        IUseTimecode                        = ae_sys::PF_OutFlag2_I_USE_TIMECODE,
186        DependsOnUnreferencedMasks          = ae_sys::PF_OutFlag2_DEPENDS_ON_UNREFERENCED_MASKS,
187        OutputIsWatermarked                 = ae_sys::PF_OutFlag2_OUTPUT_IS_WATERMARKED,
188        IMixGuidDependencies                = ae_sys::PF_OutFlag2_I_MIX_GUID_DEPENDENCIES,
189        Ae135Threadsafe                     = ae_sys::PF_OutFlag2_AE13_5_THREADSAFE,
190        SupportsGetFlattenedSequenceData    = ae_sys::PF_OutFlag2_SUPPORTS_GET_FLATTENED_SEQUENCE_DATA,
191        CustomUiAsyncManager                = ae_sys::PF_OutFlag2_CUSTOM_UI_ASYNC_MANAGER,
192        SupportsGpuRenderF32                = ae_sys::PF_OutFlag2_SUPPORTS_GPU_RENDER_F32,
193        SupportsThreadedRendering           = ae_sys::PF_OutFlag2_SUPPORTS_THREADED_RENDERING,
194        MutableRenderSequenceDataSlower     = ae_sys::PF_OutFlag2_MUTABLE_RENDER_SEQUENCE_DATA_SLOWER,
195    }
196}