use crate::*;
use crate::aegp::*;
use pr::RenderContextHandle;
define_suite!(
ColorSettingsSuite,
AEGP_ColorSettingsSuite6,
kAEGPColorSettingsSuite,
kAEGPColorSettingsSuiteVersion6
);
impl ColorSettingsSuite {
pub fn new() -> Result<Self, Error> {
crate::Suite::new()
}
pub fn blending_tables(&self, render_context: RenderContextHandle) -> Result<ae_sys::PF_EffectBlendingTables, Error> {
call_suite_fn_single!(self, AEGP_GetBlendingTables -> ae_sys::PF_EffectBlendingTables, render_context.as_ptr())
}
pub fn does_view_have_color_space_xform(&self, view: ItemViewHandle) -> Result<bool, Error> {
Ok(call_suite_fn_single!(self, AEGP_DoesViewHaveColorSpaceXform -> ae_sys::A_Boolean, view.as_ptr())? != 0)
}
pub fn xform_working_to_view_color_space(&self, view: ItemViewHandle, src: WorldHandle, dst: &mut WorldHandle) -> Result<(), Error> {
call_suite_fn!(self, AEGP_XformWorkingToViewColorSpace, view.as_ptr(), src.as_ptr(), dst.as_ptr())
}
pub fn new_working_space_color_profile(&self, plugin_id: PluginId, comp: CompHandle) -> Result<ColorProfileHandle, Error> {
Ok(ColorProfileHandle::from_raw_owned(
call_suite_fn_single!(self, AEGP_GetNewWorkingSpaceColorProfile -> ae_sys::AEGP_ColorProfileP, plugin_id, comp.as_ptr())?
))
}
pub fn new_color_profile_from_icc_profile(&self, plugin_id: PluginId, icc_size: i32, icc_data: *const std::ffi::c_void) -> Result<ColorProfileHandle, Error> {
Ok(ColorProfileHandle::from_raw_owned(
call_suite_fn_single!(self, AEGP_GetNewColorProfileFromICCProfile -> ae_sys::AEGP_ColorProfileP, plugin_id, icc_size, icc_data)?
))
}
pub fn new_icc_profile_from_color_profile(&self, plugin_id: PluginId, color_profile: ConstColorProfileHandle) -> Result<MemHandle<'_, u8>, Error> {
let handle = call_suite_fn_single!(self, AEGP_GetNewICCProfileFromColorProfile -> ae_sys::AEGP_MemHandle, plugin_id, color_profile.as_ptr())?;
Ok(MemHandle::from_raw(handle)?)
}
pub fn new_color_profile_description(&self, plugin_id: PluginId, color_profile: ConstColorProfileHandle) -> Result<String, Error> {
let mem_handle = call_suite_fn_single!(self, AEGP_GetNewColorProfileDescription -> ae_sys::AEGP_MemHandle, plugin_id, color_profile.as_ptr())?;
Ok(unsafe {
U16CString::from_ptr_str(
MemHandle::<u16>::from_raw(mem_handle)?.lock()?.as_ptr(),
).to_string_lossy()
})
}
pub fn dispose_color_profile(&self, color_profile: ae_sys::AEGP_ColorProfileP) -> Result<(), Error> {
call_suite_fn!(self, AEGP_DisposeColorProfile, color_profile)
}
pub fn color_profile_approximate_gamma(&self, color_profile: ConstColorProfileHandle) -> Result<f32, Error> {
Ok(call_suite_fn_single!(self, AEGP_GetColorProfileApproximateGamma -> ae_sys::A_FpShort, color_profile.as_ptr())?)
}
pub fn is_rgb_color_profile(&self, color_profile: ConstColorProfileHandle) -> Result<bool, Error> {
Ok(call_suite_fn_single!(self, AEGP_IsRGBColorProfile -> ae_sys::A_Boolean, color_profile.as_ptr())? != 0)
}
pub fn set_working_color_space(&self, plugin_id: PluginId, comp: CompHandle, color_profile: ConstColorProfileHandle) -> Result<(), Error> {
call_suite_fn!(self, AEGP_SetWorkingColorSpace, plugin_id, comp.as_ptr(), color_profile.as_ptr())
}
pub fn is_ocio_color_management_used(&self, plugin_id: PluginId) -> Result<bool, Error> {
Ok(call_suite_fn_single!(self, AEGP_IsOCIOColorManagementUsed -> ae_sys::A_Boolean, plugin_id)? != 0)
}
pub fn ocio_configuration_file(&self, plugin_id: PluginId) -> Result<String, Error> {
let mem_handle = call_suite_fn_single!(self, AEGP_GetOCIOConfigurationFile -> ae_sys::AEGP_MemHandle, plugin_id)?;
Ok(unsafe {
U16CString::from_ptr_str(
MemHandle::<u16>::from_raw(mem_handle)?.lock()?.as_ptr(),
).to_string_lossy()
})
}
pub fn ocio_configuration_file_path(&self, plugin_id: PluginId) -> Result<String, Error> {
let mem_handle = call_suite_fn_single!(self, AEGP_GetOCIOConfigurationFilePath -> ae_sys::AEGP_MemHandle, plugin_id)?;
Ok(unsafe {
U16CString::from_ptr_str(
MemHandle::<u16>::from_raw(mem_handle)?.lock()?.as_ptr(),
).to_string_lossy()
})
}
pub fn ocio_working_color_space(&self, plugin_id: PluginId) -> Result<String, Error> {
let mem_handle = call_suite_fn_single!(self, AEGPD_GetOCIOWorkingColorSpace -> ae_sys::AEGP_MemHandle, plugin_id)?;
Ok(unsafe {
U16CString::from_ptr_str(
MemHandle::<u16>::from_raw(mem_handle)?.lock()?.as_ptr(),
).to_string_lossy()
})
}
pub fn ocio_display_color_space(&self, plugin_id: PluginId) -> Result<(String, String), Error> {
let (display, view) = call_suite_fn_double!(self, AEGPD_GetOCIODisplayColorSpace -> ae_sys::AEGP_MemHandle, ae_sys::AEGP_MemHandle, plugin_id)?;
Ok(unsafe {(
U16CString::from_ptr_str(MemHandle::<u16>::from_raw(display)?.lock()?.as_ptr()).to_string_lossy(),
U16CString::from_ptr_str(MemHandle::<u16>::from_raw(view) ?.lock()?.as_ptr()).to_string_lossy()
)})
}
pub fn is_color_space_aware_effects_enabled(&self, plugin_id: PluginId) -> Result<bool, Error> {
Ok(call_suite_fn_single!(self, AEGPD_IsColorSpaceAwareEffectsEnabled -> ae_sys::A_Boolean, plugin_id)? != 0)
}
pub fn lut_interpolation_method(&self, plugin_id: PluginId) -> Result<u16, Error> {
Ok(call_suite_fn_single!(self, AEGPD_GetLUTInterpolationMethod -> ae_sys::A_u_short, plugin_id)?)
}
pub fn graphics_white_luminance(&self, plugin_id: PluginId) -> Result<u16, Error> {
Ok(call_suite_fn_single!(self, AEGPD_GetGraphicsWhiteLuminance -> ae_sys::A_u_short, plugin_id)?)
}
pub fn working_color_space_id(&self, plugin_id: PluginId) -> Result<ae_sys::AEGP_GuidP, Error> {
let val: ae_sys::AEGP_GuidP = unsafe { std::mem::zeroed() };
let err = unsafe { ae_get_suite_fn!(self.suite_ptr, AEGPD_GetWorkingColorSpaceId)(plugin_id, val) };
match err {
0 => Ok(val),
_ => Err(Error::from(err))
}
}
}
define_handle_wrapper!(ItemViewHandle, AEGP_ItemViewP);
define_handle_wrapper!(ConstColorProfileHandle, AEGP_ConstColorProfileP);
define_owned_handle_wrapper!(ColorProfileHandle, AEGP_ColorProfileP);
impl Drop for ColorProfileHandle {
fn drop(&mut self) {
if let Ok(suite) = ColorSettingsSuite::new() {
if suite.dispose_color_profile(self.as_ptr()).is_ok() {
self.0 = std::ptr::null_mut();
}
}
}
}