Skip to main content

ocio_rs/
config.rs

1use std::ffi::{c_void, CStr};
2use std::ptr::NonNull;
3
4use crate::transform::TransformHandle;
5use crate::{
6    cstr_from_mut, cstr_to_opt_string, cstring, ColorSpace, ColorSpaceSet, ColorSpaceVisibility,
7    ConfigIOProxy, Context, FileRules, Look, NamedTransform, NamedTransformVisibility, OcioError,
8    Processor, ReferenceSpaceType, Result, SearchReferenceSpaceType, TransformDirection,
9    ViewTransform, ViewType, ViewingRules,
10};
11use ocio_sys;
12
13fn legacy_view_type(
14    reference_space: SearchReferenceSpaceType,
15    display: Option<&str>,
16) -> Result<ViewType> {
17    match reference_space {
18        SearchReferenceSpaceType::Scene => Ok(ViewType::Shared),
19        SearchReferenceSpaceType::Display => Ok(ViewType::DisplayDefined),
20        // With an empty display, OCIO enumerates global shared views regardless
21        // of type. Pass a valid enum rather than the old invalid discriminant.
22        SearchReferenceSpaceType::All if display == Some("") => Ok(ViewType::Shared),
23        SearchReferenceSpaceType::All => Err(OcioError::InvalidInput(
24            "view queries distinguish shared and display-defined views, not reference spaces"
25                .into(),
26        )),
27    }
28}
29
30/// An OpenColorIO configuration.
31///
32/// `Config` is the central entry point for the crate. It holds color-space
33/// definitions, display/view mappings, file rules, looks, roles, and the
34/// metadata needed to build [`Processor`] pipelines.
35///
36/// A config can be loaded from a file, an environment variable, in-memory text,
37/// or one of OCIO's built-in presets:
38///
39/// ```rust,no_run
40/// # use ocio_rs::Config;
41/// # fn example() -> ocio_rs::Result<()> {
42/// // From a .ocio file
43/// let config = Config::from_file("config.ocio")?;
44///
45/// // From the OCIO environment variable
46/// let config = Config::from_env()?;
47///
48/// // From in-memory YAML text
49/// let config = Config::from_stream("ociofile_version: 2")?;
50///
51/// // From a built-in preset
52/// let config = Config::create_from_builtin_config("default")?;
53/// # Ok(())
54/// # }
55/// ```
56///
57/// Once loaded, use the config to query color-space metadata, enumerate
58/// displays and views, and create [`Processor`] instances for color-space
59/// conversions or display-view pipelines.
60///
61/// Config handles are thread-confined. Some native const operations also
62/// update internal caches, so a Rust handle must not be moved or shared
63/// between threads without explicit native interop and synchronization.
64///
65/// ```compile_fail
66/// fn require_send<T: Send>() {}
67/// require_send::<ocio_rs::Config>();
68/// ```
69/// ```compile_fail
70/// fn require_sync<T: Sync>() {}
71/// require_sync::<ocio_rs::Config>();
72/// ```
73///
74/// [`Processor`]: crate::Processor
75pub struct Config {
76    pub(crate) handle: NonNull<c_void>,
77}
78
79/// Shared immutable native configuration, independent of later global replacement.
80///
81/// The handle is thread-confined: native const access can update lazy caches.
82///
83/// ```compile_fail
84/// fn require_send<T: Send>() {}
85/// require_send::<ocio_rs::ConstConfig>();
86/// ```
87/// ```compile_fail
88/// fn require_sync<T: Sync>() {}
89/// require_sync::<ocio_rs::ConstConfig>();
90/// ```
91pub struct ConstConfig {
92    pub(crate) handle: NonNull<c_void>,
93}
94
95/// Borrow an editable or shared read-only configuration for native queries.
96#[derive(Clone, Copy)]
97pub enum ConfigRef<'a> {
98    /// A configuration with editable Rust access.
99    Editable(&'a Config),
100    /// A retained read-only native configuration.
101    ReadOnly(&'a ConstConfig),
102}
103impl<'a> From<&'a Config> for ConfigRef<'a> {
104    fn from(value: &'a Config) -> Self {
105        Self::Editable(value)
106    }
107}
108impl<'a> From<&'a ConstConfig> for ConfigRef<'a> {
109    fn from(value: &'a ConstConfig) -> Self {
110        Self::ReadOnly(value)
111    }
112}
113impl ConfigRef<'_> {
114    // Some native algorithms temporarily change cache flags even through a
115    // const config. A retained config may also be used by another thread.
116    pub(crate) fn isolated_copy(self) -> Result<Option<Config>> {
117        match self {
118            Self::Editable(_) => Ok(None),
119            Self::ReadOnly(value) => value.create_editable_copy().map(Some),
120        }
121    }
122    pub(crate) fn raw(self) -> (*mut c_void, bool) {
123        match self {
124            Self::Editable(value) => (value.handle.as_ptr(), false),
125            Self::ReadOnly(value) => (value.handle.as_ptr(), true),
126        }
127    }
128
129    /// Borrow the binding's native handle and its read-only representation flag.
130    ///
131    /// This pair is accepted by `ocio-sys` functions that document a config
132    /// handle followed by its const flag. It is not an `OCIO::Config*`; the
133    /// handle must not be destroyed, retained past this borrow, or passed to a
134    /// function expecting the other handle representation. Calling native FFI
135    /// is unsafe: some OCIO const operations change mutable caches, so callers
136    /// must also obey the target function's aliasing and concurrency contract.
137    /// No configuration is copied or reference count incremented.
138    pub fn as_raw_parts(self) -> (*mut c_void, bool) {
139        self.raw()
140    }
141}
142
143impl<'a> ConfigRef<'a> {
144    fn with_isolated_copy<'b>(self, copy: &'b Option<Config>) -> &'b Config
145    where
146        'a: 'b,
147    {
148        match (self, copy) {
149            (_, Some(value)) | (Self::Editable(value), None) => value,
150            (Self::ReadOnly(_), None) => unreachable!("read-only config must be isolated"),
151        }
152    }
153}
154
155/// Destination of a processor connecting two read-only configurations.
156#[derive(Debug, Clone, Copy)]
157pub enum ConfigProcessorTarget<'a> {
158    /// Destination color-space or role name.
159    ColorSpace(&'a CStr),
160    /// Destination display and view in the other configuration.
161    DisplayView {
162        display: &'a CStr,
163        view: &'a CStr,
164        direction: TransformDirection,
165    },
166}
167
168fn explicit_config_cache_id(
169    handle: NonNull<c_void>,
170    read_only: bool,
171    context: Option<&crate::ConstContext>,
172) -> Result<Option<String>> {
173    crate::clear_last_error();
174    let raw = unsafe {
175        ocio_sys::ocio_config_get_cache_id_explicit(
176            handle.as_ptr(),
177            read_only,
178            context.map_or(std::ptr::null(), |ctx| ctx.handle.as_ptr()),
179        )
180    };
181    crate::ocio_call_status()?;
182    Ok(unsafe { cstr_to_opt_string(raw.cast()) })
183}
184
185impl ConstConfig {
186    /// Return the native environment mode without creating a config or context copy.
187    pub fn environment_mode(&self) -> Result<crate::EnvironmentMode> {
188        crate::clear_last_error();
189        let mode = unsafe { ocio_sys::ocio_const_config_environment_mode(self.handle.as_ptr()) };
190        crate::ocio_call_status()?;
191        crate::context::environment_mode_from_raw(mode)
192    }
193    fn text(&self, field: i32) -> Result<Option<String>> {
194        crate::clear_last_error();
195        let ptr = unsafe { ocio_sys::ocio_const_config_text(self.handle.as_ptr(), field) };
196        let text = unsafe { cstr_to_opt_string(ptr) };
197        crate::ocio_call_status()?;
198        Ok(text)
199    }
200    /// Config name as owned text.
201    pub fn name(&self) -> Result<Option<String>> {
202        self.text(0)
203    }
204    /// Native cache identifier as owned text.
205    pub fn cache_id(&self) -> Result<Option<String>> {
206        self.text(1)
207    }
208    /// Cache identifier including file references resolved with this context.
209    pub fn cache_id_for_context(&self, context: &crate::ConstContext) -> Result<Option<String>> {
210        explicit_config_cache_id(self.handle, true, Some(context))
211    }
212    /// Cache identifier for the serialized config alone, without file references.
213    ///
214    /// This passes a null context to OCIO, unlike [Self::cache_id], which
215    /// uses the current context.
216    pub fn cache_id_without_file_references(&self) -> Result<Option<String>> {
217        explicit_config_cache_id(self.handle, true, None)
218    }
219    /// Observe the native processor cache policy on this snapshot.
220    pub fn processor_cache_flags(&self) -> Result<crate::ProcessorCacheFlags> {
221        crate::clear_last_error();
222        let raw =
223            unsafe { ocio_sys::ocio_const_config_get_processor_cache_flags(self.handle.as_ptr()) };
224        crate::ocio_call_status()?;
225        Ok(crate::ProcessorCacheFlags(raw as u32))
226    }
227    /// Change the native processor cache policy on this shared object.
228    /// This does not evict existing cached processors.
229    ///
230    /// # Safety
231    /// Do not run this concurrently with any operation on this native config
232    /// or cached processors, including through other handles or external OCIO
233    /// code. OCIO's const-qualified setter is not a synchronized update.
234    /// Use [crate::try_set_processor_cache_flags] to replace the global policy
235    /// without mutating an existing snapshot.
236    pub unsafe fn try_set_processor_cache_flags(
237        &self,
238        flags: crate::ProcessorCacheFlags,
239    ) -> Result<()> {
240        crate::clear_last_error();
241        unsafe {
242            ocio_sys::ocio_const_config_set_processor_cache_flags(
243                self.handle.as_ptr(),
244                flags.0 as i32,
245            );
246        }
247        crate::ocio_call_status()
248    }
249    /// Config description as owned text.
250    pub fn description(&self) -> Result<Option<String>> {
251        self.text(2)
252    }
253    /// Default display name as owned text.
254    pub fn default_display(&self) -> Result<Option<String>> {
255        Ok(self.text(3)?.filter(|display| !display.is_empty()))
256    }
257    /// Create an editable config copy using OCIO's native semantics.
258    /// Group transforms within it may still share children with the source;
259    /// see [`Config::create_editable_copy`].
260    pub fn create_editable_copy(&self) -> Result<Config> {
261        crate::clear_last_error();
262        let handle = unsafe { ocio_sys::ocio_const_config_editable_copy(self.handle.as_ptr()) };
263        crate::handle_result(handle).map(|handle| Config { handle })
264    }
265    /// Share an immutable color space without copying the native object.
266    pub fn try_const_color_space(
267        &self,
268        name: &std::ffi::CStr,
269    ) -> Result<Option<crate::ConstColorSpace>> {
270        crate::clear_last_error();
271        let handle = unsafe {
272            ocio_sys::ocio_const_config_get_color_space(self.handle.as_ptr(), name.as_ptr())
273        };
274        crate::ocio_call_status()?;
275        Ok(NonNull::new(handle).map(|handle| crate::ConstColorSpace { handle }))
276    }
277    /// Share the native current context without copying it.
278    pub fn try_const_current_context(&self) -> Result<Option<crate::ConstContext>> {
279        crate::clear_last_error();
280        let handle = unsafe { ocio_sys::ocio_const_config_get_context(self.handle.as_ptr()) };
281        crate::ocio_call_status()?;
282        Ok(NonNull::new(handle).map(|handle| crate::ConstContext { handle }))
283    }
284    /// Create a processor from native C-string color-space names.
285    ///
286    /// Static pipelines use this snapshot's native cache. Dynamic pipelines are
287    /// built from an independent configuration copy so separate processors do
288    /// not concurrently mutate shared dynamic properties.
289    pub fn processor(&self, src: &std::ffi::CStr, dst: &std::ffi::CStr) -> Result<Processor> {
290        crate::clear_last_error();
291        let handle = unsafe {
292            ocio_sys::ocio_const_config_get_processor(
293                self.handle.as_ptr(),
294                src.as_ptr(),
295                dst.as_ptr(),
296            )
297        };
298        Config::processor_handle_result(handle)
299    }
300
301    /// Create a processor using a shared context and native color-space names.
302    /// Static processors retain native caching; dynamic processors are isolated
303    /// as described by [`Self::processor`].
304    pub fn processor_with_const_context(
305        &self,
306        src: &std::ffi::CStr,
307        dst: &std::ffi::CStr,
308        context: &crate::ConstContext,
309    ) -> Result<Processor> {
310        crate::clear_last_error();
311        let handle = unsafe {
312            ocio_sys::ocio_const_config_get_processor_with_context(
313                self.handle.as_ptr(),
314                context.handle.as_ptr(),
315                src.as_ptr(),
316                dst.as_ptr(),
317            )
318        };
319        Config::processor_handle_result(handle)
320    }
321
322    /// Create a processor from a shared native transform and optional context.
323    /// Dynamic processors are isolated as described by [`Self::processor`].
324    pub fn processor_from_const_transform(
325        &self,
326        transform: &crate::transform::ConstTransform,
327        direction: TransformDirection,
328        context: Option<&crate::ConstContext>,
329    ) -> Result<Processor> {
330        crate::clear_last_error();
331        let handle = unsafe {
332            ocio_sys::ocio_const_config_get_processor_from_transform(
333                self.handle.as_ptr(),
334                context.map_or(std::ptr::null_mut(), |c| c.handle.as_ptr()),
335                transform.handle.as_ptr(),
336                direction as i32,
337            )
338        };
339        Config::processor_handle_result(handle)
340    }
341
342    /// Build a processor in the native default direction (forward).
343    pub fn processor_from_const_transform_default_direction(
344        &self,
345        transform: &crate::transform::ConstTransform,
346    ) -> Result<Processor> {
347        self.processor_from_const_transform(transform, TransformDirection::Forward, None)
348    }
349
350    /// Build a processor between two read-only configs without making editable
351    /// copies for a static pipeline.
352    ///
353    /// With no explicit contexts, each config uses its current context. Without
354    /// an interchange pair, OCIO selects the required interchange roles.
355    /// Explicit pairs are ordered source, then destination. Dynamic pipelines
356    /// are rebuilt in isolated config copies as with [Self::processor].
357    pub fn processor_to_config(
358        &self,
359        source: &CStr,
360        destination: &ConstConfig,
361        target: ConfigProcessorTarget<'_>,
362        contexts: Option<(&crate::ConstContext, &crate::ConstContext)>,
363        interchange: Option<(&CStr, &CStr)>,
364    ) -> Result<Processor> {
365        let (target, view, direction) = match target {
366            ConfigProcessorTarget::ColorSpace(name) => {
367                (name, std::ptr::null(), TransformDirection::Forward)
368            }
369            ConfigProcessorTarget::DisplayView {
370                display,
371                view,
372                direction,
373            } => (display, view.as_ptr(), direction),
374        };
375        let (src_ctx, dst_ctx) = contexts.map_or(
376            (std::ptr::null_mut(), std::ptr::null_mut()),
377            |(src, dst)| (src.handle.as_ptr(), dst.handle.as_ptr()),
378        );
379        let (src_space, dst_space) = interchange
380            .map_or((std::ptr::null(), std::ptr::null()), |(src, dst)| {
381                (src.as_ptr(), dst.as_ptr())
382            });
383        crate::clear_last_error();
384        let handle = unsafe {
385            ocio_sys::ocio_const_configs_get_processor(
386                self.handle.as_ptr(),
387                source.as_ptr(),
388                destination.handle.as_ptr(),
389                target.as_ptr(),
390                view,
391                direction as i32,
392                src_ctx,
393                dst_ctx,
394                src_space,
395                dst_space,
396            )
397        };
398        Config::processor_handle_result(handle)
399    }
400
401    /// Build a processor from this config's color space to a space in OCIO's
402    /// default built-in config. OCIO resolves the interchange space using an
403    /// isolated config copy because its heuristic changes native cache flags.
404    pub fn processor_to_builtin_color_space(
405        &self,
406        source: &CStr,
407        builtin_destination: &CStr,
408    ) -> Result<Processor> {
409        self.builtin_color_space_processor(source, builtin_destination, false)
410    }
411
412    /// Build a processor from a space in OCIO's default built-in config to
413    /// this config's color space. OCIO resolves the interchange space using an
414    /// isolated config copy because its heuristic changes native cache flags.
415    pub fn processor_from_builtin_color_space(
416        &self,
417        builtin_source: &CStr,
418        destination: &CStr,
419    ) -> Result<Processor> {
420        self.builtin_color_space_processor(destination, builtin_source, true)
421    }
422
423    fn builtin_color_space_processor(
424        &self,
425        local: &CStr,
426        builtin: &CStr,
427        from_builtin: bool,
428    ) -> Result<Processor> {
429        crate::clear_last_error();
430        let handle = unsafe {
431            ocio_sys::ocio_const_config_get_builtin_processor(
432                self.handle.as_ptr(),
433                local.as_ptr(),
434                builtin.as_ptr(),
435                from_builtin,
436            )
437        };
438        Config::processor_handle_result(handle)
439    }
440
441    /// Create a display/view processor with an optional read-only context.
442    /// Dynamic processors are isolated as described by [`Self::processor`].
443    pub fn processor_display(
444        &self,
445        src: &std::ffi::CStr,
446        display: &std::ffi::CStr,
447        view: &std::ffi::CStr,
448        direction: TransformDirection,
449        context: Option<&crate::ConstContext>,
450    ) -> Result<Processor> {
451        crate::clear_last_error();
452        let handle = unsafe {
453            ocio_sys::ocio_const_config_get_processor_display(
454                self.handle.as_ptr(),
455                context.map_or(std::ptr::null_mut(), |c| c.handle.as_ptr()),
456                src.as_ptr(),
457                display.as_ptr(),
458                view.as_ptr(),
459                direction as i32,
460            )
461        };
462        Config::processor_handle_result(handle)
463    }
464
465    /// Create a named-transform processor with an optional read-only context.
466    /// Dynamic processors are isolated as described by [`Self::processor`].
467    pub fn processor_named_transform(
468        &self,
469        name: &std::ffi::CStr,
470        direction: TransformDirection,
471        context: Option<&crate::ConstContext>,
472    ) -> Result<Processor> {
473        crate::clear_last_error();
474        let handle = unsafe {
475            ocio_sys::ocio_const_config_get_processor_named(
476                self.handle.as_ptr(),
477                context.map_or(std::ptr::null_mut(), |c| c.handle.as_ptr()),
478                name.as_ptr(),
479                direction as i32,
480            )
481        };
482        Config::processor_handle_result(handle)
483    }
484
485    /// Create a processor directly from shared color-space objects.
486    /// Static processors retain native caching; dynamic processors are isolated.
487    pub fn processor_from_const_color_spaces(
488        &self,
489        source: &crate::ConstColorSpace,
490        destination: &crate::ConstColorSpace,
491        context: Option<&crate::ConstContext>,
492    ) -> Result<Processor> {
493        crate::clear_last_error();
494        let handle = unsafe {
495            ocio_sys::ocio_const_config_get_processor_spaces(
496                self.handle.as_ptr(),
497                context.map_or(std::ptr::null_mut(), |c| c.handle.as_ptr()),
498                source.handle.as_ptr(),
499                destination.handle.as_ptr(),
500            )
501        };
502        Config::processor_handle_result(handle)
503    }
504
505    /// Create a processor directly from a shared named-transform object.
506    /// Dynamic processors are isolated as described by [`Self::processor`].
507    pub fn processor_from_const_named_transform(
508        &self,
509        named: &crate::ConstNamedTransform,
510        direction: TransformDirection,
511        context: Option<&crate::ConstContext>,
512    ) -> Result<Processor> {
513        crate::clear_last_error();
514        let handle = unsafe {
515            ocio_sys::ocio_const_config_get_processor_named_object(
516                self.handle.as_ptr(),
517                context.map_or(std::ptr::null_mut(), |c| c.handle.as_ptr()),
518                named.raw(),
519                direction as i32,
520            )
521        };
522        Config::processor_handle_result(handle)
523    }
524}
525impl Drop for ConstConfig {
526    fn drop(&mut self) {
527        unsafe { ocio_sys::ocio_const_config_destroy(self.handle.as_ptr()) }
528    }
529}
530
531impl Config {
532    fn processor_handle_result(handle: *mut c_void) -> Result<Processor> {
533        crate::handle_result(handle).map(|handle| Processor { handle })
534    }
535
536    /// Create a config from one of OCIO's built-in configuration presets.
537    ///
538    /// Use `BuiltinConfigRegistry` to enumerate the preset names exposed by the
539    /// linked OCIO build.
540    pub fn create_from_builtin_config(config_name: impl AsRef<str>) -> Result<Self> {
541        let config_name = cstring(config_name)?;
542        crate::clear_last_error();
543        let handle = unsafe {
544            ocio_sys::ocio_config_create_from_builtin_config(config_name.as_ptr().cast())
545        };
546        crate::handle_result(handle).map(|handle| Self { handle })
547    }
548
549    /// Create an empty editable configuration using OCIO defaults.
550    /// Unlike [`Self::raw`], this does not install the built-in raw color space.
551    pub fn create() -> Result<Self> {
552        crate::clear_last_error();
553        let handle = unsafe { ocio_sys::ocio_config_create_empty() };
554        crate::handle_result(handle).map(|handle| Self { handle })
555    }
556
557    /// Create OCIO's fallback raw configuration with a raw color space.
558    pub fn raw() -> Result<Self> {
559        crate::clear_last_error();
560        let handle = unsafe { ocio_sys::ocio_config_create_raw() };
561        crate::handle_result(handle).map(|handle| Self { handle })
562    }
563
564    /// Load a config from an `.ocio` file on disk.
565    pub fn from_file(path: impl AsRef<str>) -> Result<Self> {
566        let path = cstring(path)?;
567        crate::clear_last_error();
568        let handle = unsafe { ocio_sys::ocio_config_create_from_file(path.as_ptr().cast()) };
569        crate::handle_result(handle).map(|handle| Self { handle })
570    }
571
572    /// Load a config from the `OCIO` environment variable.
573    ///
574    /// In real OCIO mode this mirrors `OCIO::Config::CreateFromEnv`.
575    pub fn from_env() -> Result<Self> {
576        crate::clear_last_error();
577        let handle = unsafe { ocio_sys::ocio_config_create_from_env() };
578        crate::handle_result(handle).map(|handle| Self { handle })
579    }
580
581    /// Parse a config from in-memory OCIO text.
582    ///
583    /// This is useful for tests, generated configs, or editor tooling that
584    /// wants to validate config text before writing it to disk.
585    pub fn from_stream(text: impl AsRef<str>) -> Result<Self> {
586        let text = cstring(text)?;
587        crate::clear_last_error();
588        let handle = unsafe { ocio_sys::ocio_config_create_from_stream(text.as_ptr().cast()) };
589        crate::handle_result(handle).map(|handle| Self { handle })
590    }
591
592    /// Create a config from an in-memory `ConfigIOProxy`.
593    pub fn from_config_io_proxy(proxy: &ConfigIOProxy) -> Result<Self> {
594        crate::clear_last_error();
595        let handle =
596            unsafe { ocio_sys::ocio_config_create_from_config_io_proxy(proxy.handle.as_ptr()) };
597        crate::handle_result(handle).map(|handle| Self { handle })
598    }
599
600    // --- Name & metadata ---
601
602    /// Return the config name, if one has been authored.
603    pub fn name(&self) -> Option<String> {
604        self.try_name().ok().flatten()
605    }
606
607    /// Return the config name while preserving bridge failures.
608    pub fn try_name(&self) -> Result<Option<String>> {
609        crate::clear_last_error();
610        let name = unsafe {
611            cstr_from_mut(ocio_sys::ocio_config_get_name(
612                self.handle.as_ptr() as *mut c_void
613            ))
614        };
615        crate::ocio_call_status()?;
616        Ok(name)
617    }
618
619    /// Set the config name used in serialized metadata.
620    pub fn set_name(&self, name: impl AsRef<str>) -> Result<()> {
621        let name = cstring(name)?;
622        crate::clear_last_error();
623        unsafe { ocio_sys::ocio_config_set_name(self.handle.as_ptr(), name.as_ptr().cast()) };
624        crate::ocio_call_status()
625    }
626
627    /// Return the config description, if present.
628    pub fn description(&self) -> Option<String> {
629        self.try_description().ok().flatten()
630    }
631
632    /// Return the config description while preserving bridge failures.
633    pub fn try_description(&self) -> Result<Option<String>> {
634        crate::clear_last_error();
635        let description = unsafe {
636            cstr_from_mut(ocio_sys::ocio_config_get_description(
637                self.handle.as_ptr() as *mut c_void
638            ))
639        };
640        crate::ocio_call_status()?;
641        Ok(description)
642    }
643
644    /// Set the config description stored in serialized metadata.
645    pub fn set_description(&self, desc: impl AsRef<str>) -> Result<()> {
646        let desc = cstring(desc)?;
647        crate::clear_last_error();
648        unsafe {
649            ocio_sys::ocio_config_set_description(self.handle.as_ptr(), desc.as_ptr().cast())
650        };
651        crate::ocio_call_status()
652    }
653
654    /// Return OCIO's cache identifier for the config's current authored state.
655    pub fn cache_id(&self) -> Option<String> {
656        self.try_cache_id().ok().flatten()
657    }
658
659    /// Return OCIO's cache identifier while preserving bridge failures.
660    pub fn try_cache_id(&self) -> Result<Option<String>> {
661        crate::clear_last_error();
662        let cache_id = unsafe {
663            cstr_from_mut(ocio_sys::ocio_config_get_cache_id(
664                self.handle.as_ptr() as *mut c_void
665            ))
666        };
667        crate::ocio_call_status()?;
668        Ok(cache_id)
669    }
670
671    /// Return a cache identifier specialized for a concrete OCIO context.
672    pub fn cache_id_for_context(&self, context: &Context) -> Option<String> {
673        self.try_cache_id_for_context(context).ok().flatten()
674    }
675
676    /// Return a context-specialized cache identifier while preserving bridge failures.
677    pub fn try_cache_id_for_context(&self, context: &Context) -> Result<Option<String>> {
678        crate::clear_last_error();
679        let cache_id = unsafe {
680            cstr_from_mut(ocio_sys::ocio_config_get_cache_id_n(
681                self.handle.as_ptr(),
682                context.handle.as_ptr(),
683            ))
684        };
685        crate::ocio_call_status()?;
686        Ok(cache_id)
687    }
688
689    /// Use a shared read-only context, without making an editable copy of it.
690    pub fn try_cache_id_for_const_context(
691        &self,
692        context: &crate::ConstContext,
693    ) -> Result<Option<String>> {
694        explicit_config_cache_id(self.handle, false, Some(context))
695    }
696
697    /// Hash the serialized config alone by passing a null context to OCIO.
698    pub fn try_cache_id_without_file_references(&self) -> Result<Option<String>> {
699        explicit_config_cache_id(self.handle, false, None)
700    }
701
702    #[deprecated(since = "0.2.0", note = "compat alias; prefer cache_id_for_context()")]
703    pub fn cache_id_with_context(&self, context: &Context) -> Option<String> {
704        self.cache_id_for_context(context)
705    }
706
707    // --- Version ---
708
709    /// Return the major version of this config profile.
710    pub fn major_version(&self) -> u32 {
711        unsafe { ocio_sys::ocio_config_get_major_version(self.handle.as_ptr()) as u32 }
712    }
713
714    /// Return the minor version of this config profile.
715    pub fn minor_version(&self) -> u32 {
716        unsafe { ocio_sys::ocio_config_get_minor_version(self.handle.as_ptr()) as u32 }
717    }
718
719    /// Set the authored config version.
720    ///
721    /// OCIO rejects unsupported major/minor combinations. For example, asking
722    /// for a minor version that does not exist for the current major returns an
723    /// error instead of silently clamping.
724    pub fn set_version(&self, major: u32, minor: u32) -> Result<()> {
725        crate::clear_last_error();
726        unsafe { ocio_sys::ocio_config_set_version(self.handle.as_ptr(), major, minor) };
727        crate::ocio_call_status()
728    }
729
730    /// Upgrade this config to the newest OCIO profile version it supports.
731    pub fn upgrade_to_latest_version(&self) -> Result<()> {
732        crate::clear_last_error();
733        unsafe { ocio_sys::ocio_config_upgrade_to_latest_version(self.handle.as_ptr()) };
734        crate::ocio_call_status()
735    }
736
737    /// Return the character used to separate family hierarchy levels in color-space names.
738    pub fn family_separator(&self) -> char {
739        let sep = unsafe {
740            ocio_sys::ocio_config_get_family_separator(self.handle.as_ptr() as *mut c_void)
741        };
742        sep as u8 as char
743    }
744
745    // --- Color spaces ---
746
747    /// Return the number of active color spaces in this config.
748    pub fn num_color_spaces(&self) -> i32 {
749        unsafe {
750            ocio_sys::ocio_config_get_num_color_spaces_v1(self.handle.as_ptr() as *mut c_void)
751        }
752    }
753
754    /// Count color spaces matching OCIO's reference-space and visibility filters.
755    pub fn try_num_color_spaces_filtered(
756        &self,
757        reference: SearchReferenceSpaceType,
758        visibility: ColorSpaceVisibility,
759    ) -> Result<i32> {
760        crate::clear_last_error();
761        let count = unsafe {
762            ocio_sys::ocio_config_get_num_color_spaces(
763                self.handle.as_ptr(),
764                reference as i32,
765                visibility as i32,
766            )
767        };
768        crate::ocio_call_status()?;
769        Ok(count)
770    }
771
772    /// Return a filtered color-space name, or `None` for an invalid index.
773    pub fn try_color_space_name_by_index_filtered(
774        &self,
775        reference: SearchReferenceSpaceType,
776        visibility: ColorSpaceVisibility,
777        index: i32,
778    ) -> Result<Option<String>> {
779        crate::clear_last_error();
780        let name = unsafe {
781            cstr_from_mut(ocio_sys::ocio_config_get_color_space_name_by_index(
782                self.handle.as_ptr(),
783                reference as i32,
784                visibility as i32,
785                index,
786            ))
787        };
788        crate::ocio_call_status()?;
789        Ok(name.filter(|name| !name.is_empty()))
790    }
791
792    #[doc(hidden)]
793    #[deprecated(since = "0.2.0", note = "compat alias; prefer num_color_spaces()")]
794    pub fn get_num_color_spaces_v1(&self) -> i32 {
795        self.num_color_spaces()
796    }
797
798    /// Return the name of the color space at the given index, or `None` if out of range.
799    pub fn color_space_name_by_index(&self, index: i32) -> Option<String> {
800        self.try_color_space_name_by_index(index).ok().flatten()
801    }
802
803    /// Return a color-space name by index, preserving bridge failures.
804    pub fn try_color_space_name_by_index(&self, index: i32) -> Result<Option<String>> {
805        crate::clear_last_error();
806        let name = unsafe {
807            cstr_from_mut(ocio_sys::ocio_config_get_color_space_name_by_index_v1(
808                self.handle.as_ptr(),
809                index,
810            ))
811        };
812        crate::ocio_call_status()?;
813        Ok(name.filter(|name| !name.is_empty()))
814    }
815
816    #[doc(hidden)]
817    #[deprecated(
818        since = "0.2.0",
819        note = "compat alias; prefer color_space_name_by_index()"
820    )]
821    pub fn get_color_space_name_by_index_v1(&self, index: i32) -> Option<String> {
822        self.color_space_name_by_index(index)
823    }
824
825    /// Return active color-space names as a comma-separated list in config order.
826    pub fn color_spaces(&self) -> Option<String> {
827        self.try_color_spaces().ok()
828    }
829
830    /// Return active color-space names, preserving failures and releasing the set.
831    pub fn try_color_spaces(&self) -> Result<String> {
832        // getColorSpaces returns an owned ColorSpaceSet handle, not a C string.
833        // Let the typed wrapper release it on both success and early errors.
834        let set = self.color_space_set(None::<&str>)?;
835        let names = (0..set.num_color_spaces())
836            .map(|index| {
837                set.try_color_space_name_by_index(index)?.ok_or_else(|| {
838                    OcioError::ValidationFailed(format!(
839                        "missing color-space name at index {index}"
840                    ))
841                })
842            })
843            .collect::<Result<Vec<_>>>()?;
844        Ok(names.join(","))
845    }
846
847    /// Resolve a color-space name, role, alias, or named-transform name to its
848    /// canonical name, or return `None` if it is not found.
849    pub fn canonical_name(&self, name: impl AsRef<str>) -> Option<String> {
850        self.try_canonical_name(name).ok().flatten()
851    }
852
853    /// Resolve a color-space or named-transform name, preserving bridge failures.
854    pub fn try_canonical_name(&self, name: impl AsRef<str>) -> Result<Option<String>> {
855        let name = cstring(name)?;
856        crate::clear_last_error();
857        let canonical_name = unsafe {
858            cstr_from_mut(ocio_sys::ocio_config_get_canonical_name(
859                self.handle.as_ptr(),
860                name.as_ptr().cast(),
861            ))
862        };
863        crate::ocio_call_status()?;
864        Ok(canonical_name.filter(|name| !name.is_empty()))
865    }
866
867    /// Test whether a named color space is linear with respect to a reference space type.
868    /// Returns `false` on error; use [`Self::try_is_color_space_linear`] to distinguish errors.
869    pub fn is_color_space_linear(
870        &self,
871        color_space: impl AsRef<str>,
872        reference: ReferenceSpaceType,
873    ) -> bool {
874        self.try_is_color_space_linear(color_space, reference)
875            .unwrap_or(false)
876    }
877
878    /// Test color-space linearity, preserving missing-space and native errors.
879    pub fn try_is_color_space_linear(
880        &self,
881        color_space: impl AsRef<str>,
882        reference: ReferenceSpaceType,
883    ) -> Result<bool> {
884        let cs = cstring(color_space)?;
885        self.try_is_color_space_linear_cstr(&cs, reference)
886    }
887
888    /// Test color-space linearity with an existing native name and no name allocation.
889    pub fn try_is_color_space_linear_cstr(
890        &self,
891        color_space: &std::ffi::CStr,
892        reference: ReferenceSpaceType,
893    ) -> Result<bool> {
894        crate::clear_last_error();
895        let result = unsafe {
896            ocio_sys::ocio_config_is_color_space_linear(
897                self.handle.as_ptr(),
898                color_space.as_ptr(),
899                reference as i32,
900            )
901        };
902        crate::ocio_call_status()?;
903        Ok(result)
904    }
905
906    /// Identify the color-space name in `src_config` equivalent to a color space from a built-in
907    /// config.
908    ///
909    /// This is the safe counterpart to OCIO's `Config::IdentifyBuiltinColorSpace`. It preserves
910    /// an OCIO lookup failure as [`OcioError`] and returns `None` only when OCIO reports no match.
911    pub fn try_identify_builtin_color_space(
912        src_config: &Self,
913        builtin_config: &Self,
914        builtin_color_space_name: impl AsRef<str>,
915    ) -> Result<Option<String>> {
916        let builtin_color_space_name = cstring(builtin_color_space_name)?;
917        crate::clear_last_error();
918        let name = unsafe {
919            cstr_from_mut(ocio_sys::ocio_config_identify_builtin_color_space(
920                src_config.handle.as_ptr(),
921                src_config.handle.as_ptr(),
922                builtin_config.handle.as_ptr(),
923                builtin_color_space_name.as_ptr().cast(),
924            ))
925        };
926        crate::ocio_call_status()?;
927        Ok(name)
928    }
929
930    /// Identify a built-in space using editable or retained configurations.
931    /// Read-only inputs are copied to isolate OCIO's cache-flag changes.
932    pub fn try_identify_builtin_color_space_ref<'a, 'b>(
933        src_config: impl Into<ConfigRef<'a>>,
934        builtin_config: impl Into<ConfigRef<'b>>,
935        name: impl AsRef<str>,
936    ) -> Result<Option<String>> {
937        let src = src_config.into();
938        let builtin = builtin_config.into();
939        let src_copy = src.isolated_copy()?;
940        let builtin_copy = builtin.isolated_copy()?;
941        let src = src.with_isolated_copy(&src_copy);
942        let builtin = builtin.with_isolated_copy(&builtin_copy);
943        Self::try_identify_builtin_color_space(src, builtin, name)
944    }
945
946    /// Identify the interchange color spaces used to convert a color space between two configs.
947    ///
948    /// The returned names are owned Rust strings. An OCIO failure to identify either interchange
949    /// space is returned as [`OcioError`].
950    pub fn try_identify_interchange_space(
951        src_config: &Self,
952        src_color_space_name: impl AsRef<str>,
953        builtin_config: &Self,
954        builtin_color_space_name: impl AsRef<str>,
955    ) -> Result<(Option<String>, Option<String>)> {
956        let src_color_space_name = cstring(src_color_space_name)?;
957        let builtin_color_space_name = cstring(builtin_color_space_name)?;
958        let mut src_interchange_name = std::ptr::null_mut();
959        let mut builtin_interchange_name = std::ptr::null_mut();
960
961        crate::clear_last_error();
962        unsafe {
963            ocio_sys::ocio_config_identify_interchange_space(
964                src_config.handle.as_ptr(),
965                (&mut src_interchange_name as *mut *mut c_void).cast(),
966                (&mut builtin_interchange_name as *mut *mut c_void).cast(),
967                src_config.handle.as_ptr(),
968                src_color_space_name.as_ptr().cast(),
969                builtin_config.handle.as_ptr(),
970                builtin_color_space_name.as_ptr().cast(),
971            );
972        }
973        crate::ocio_call_status()?;
974        Ok(unsafe {
975            (
976                cstr_from_mut(src_interchange_name),
977                cstr_from_mut(builtin_interchange_name),
978            )
979        })
980    }
981
982    /// Identify interchange spaces using editable or retained configurations.
983    /// Read-only inputs are copied to isolate OCIO's cache-flag changes.
984    pub fn try_identify_interchange_space_ref<'a, 'b>(
985        src_config: impl Into<ConfigRef<'a>>,
986        src_name: impl AsRef<str>,
987        builtin_config: impl Into<ConfigRef<'b>>,
988        builtin_name: impl AsRef<str>,
989    ) -> Result<(Option<String>, Option<String>)> {
990        let src = src_config.into();
991        let builtin = builtin_config.into();
992        let src_copy = src.isolated_copy()?;
993        let builtin_copy = builtin.isolated_copy()?;
994        let src = src.with_isolated_copy(&src_copy);
995        let builtin = builtin.with_isolated_copy(&builtin_copy);
996        Self::try_identify_interchange_space(src, src_name, builtin, builtin_name)
997    }
998
999    /// # Safety
1000    /// `src_config` and `builtin_config` must be valid pointers to live `ConfigHandle` values
1001    /// from this ABI. They are borrowed for the duration of this call and must not be freed here.
1002    #[doc(hidden)]
1003    #[deprecated(
1004        since = "0.2.0",
1005        note = "raw OCIO config-pointer entry point; prefer built-in config and color-space APIs unless you must interoperate with external OCIO ABI objects"
1006    )]
1007    pub unsafe fn identify_builtin_color_space(
1008        &self,
1009        src_config: *mut c_void,
1010        builtin_config: *mut c_void,
1011        builtin_color_space_name: impl AsRef<str>,
1012    ) -> Option<String> {
1013        let builtin_color_space_name = cstring(builtin_color_space_name).ok()?;
1014        unsafe {
1015            cstr_from_mut(ocio_sys::ocio_config_identify_builtin_color_space(
1016                self.handle.as_ptr(),
1017                src_config,
1018                builtin_config,
1019                builtin_color_space_name.as_ptr().cast(),
1020            ))
1021        }
1022    }
1023
1024    /// # Safety
1025    /// `src_interchange_name` and `builtin_interchange_name` must point to writable storage for
1026    /// a `const char *` output. The output pointers are borrowed from OCIO and must not be freed.
1027    /// `src_config` and `builtin_config` must be valid pointers to live `ConfigHandle` values
1028    /// from this ABI and are borrowed for the duration of this call.
1029    #[doc(hidden)]
1030    #[deprecated(
1031        since = "0.2.0",
1032        note = "raw OCIO interchange/config pointer entry point; prefer higher-level config APIs unless you must interoperate with external OCIO ABI objects"
1033    )]
1034    pub unsafe fn identify_interchange_space(
1035        &self,
1036        src_interchange_name: *mut c_void,
1037        builtin_interchange_name: *mut c_void,
1038        src_config: *mut c_void,
1039        src_color_space_name: impl AsRef<str>,
1040        builtin_config: *mut c_void,
1041        builtin_color_space_name: impl AsRef<str>,
1042    ) {
1043        let src_color_space_name = match cstring(src_color_space_name) {
1044            Ok(v) => v,
1045            Err(_) => return,
1046        };
1047        let builtin_color_space_name = match cstring(builtin_color_space_name) {
1048            Ok(v) => v,
1049            Err(_) => return,
1050        };
1051        unsafe {
1052            ocio_sys::ocio_config_identify_interchange_space(
1053                self.handle.as_ptr(),
1054                src_interchange_name,
1055                builtin_interchange_name,
1056                src_config,
1057                src_color_space_name.as_ptr().cast(),
1058                builtin_config,
1059                builtin_color_space_name.as_ptr().cast(),
1060            );
1061        }
1062    }
1063
1064    /// Guess the color space for a file path using the config's file-rule patterns.
1065    pub fn color_space_from_filepath(&self, file_path: impl AsRef<str>) -> Option<String> {
1066        self.try_color_space_from_filepath(file_path).ok().flatten()
1067    }
1068
1069    /// Guess a color space for a file path while preserving bridge failures.
1070    pub fn try_color_space_from_filepath(
1071        &self,
1072        file_path: impl AsRef<str>,
1073    ) -> Result<Option<String>> {
1074        let file_path = cstring(file_path)?;
1075        crate::clear_last_error();
1076        let color_space = unsafe {
1077            cstr_from_mut(ocio_sys::ocio_config_get_color_space_from_filepath(
1078                self.handle.as_ptr(),
1079                file_path.as_ptr().cast(),
1080            ))
1081        };
1082        crate::ocio_call_status()?;
1083        Ok(color_space)
1084    }
1085
1086    #[doc(hidden)]
1087    #[deprecated(
1088        since = "0.2.0",
1089        note = "compat alias; prefer color_space_from_filepath_with_rule_index() or color_space_from_filepath()"
1090    )]
1091    pub fn get_color_space_from_filepath_by_ref_type(
1092        &self,
1093        file_path: impl AsRef<str>,
1094    ) -> Option<String> {
1095        self.color_space_from_filepath_with_rule_index(file_path)
1096            .map(|(color_space, _rule_index)| color_space)
1097    }
1098
1099    /// Parse a color-space name from a free-form text string (e.g. a file path or description).
1100    pub fn parse_color_space_from_string(&self, text: impl AsRef<str>) -> Option<String> {
1101        let text = cstring(text).ok()?;
1102        unsafe {
1103            cstr_from_mut(ocio_sys::ocio_config_parse_color_space_from_string(
1104                self.handle.as_ptr(),
1105                text.as_ptr().cast(),
1106            ))
1107        }
1108    }
1109
1110    // --- Displays ---
1111
1112    /// Return the default display name, or `None` if no displays are configured.
1113    pub fn default_display(&self) -> Option<String> {
1114        self.try_default_display().ok().flatten()
1115    }
1116
1117    /// Return the default display name while preserving bridge failures.
1118    pub fn try_default_display(&self) -> Result<Option<String>> {
1119        crate::clear_last_error();
1120        let display = unsafe {
1121            cstr_from_mut(ocio_sys::ocio_config_get_default_display(
1122                self.handle.as_ptr() as *mut c_void,
1123            ))
1124        };
1125        crate::ocio_call_status()?;
1126        Ok(display.filter(|display| !display.is_empty()))
1127    }
1128
1129    #[doc(hidden)]
1130    #[deprecated(
1131        since = "0.2.0",
1132        note = "compat alias; OpenColorIO does not expose a setDefaultDisplay() mutator, prefer set_active_displays()"
1133    )]
1134    pub fn set_default_display(&self, display: impl AsRef<str>) -> Result<()> {
1135        self.set_active_displays(display)
1136    }
1137
1138    /// Return the number of active displays in this config.
1139    pub fn num_displays(&self) -> i32 {
1140        unsafe { ocio_sys::ocio_config_get_num_displays(self.handle.as_ptr() as *mut c_void) }
1141    }
1142
1143    /// Return the display name at the given index, or `None` if out of range.
1144    pub fn display(&self, index: i32) -> Option<String> {
1145        self.try_display(index).ok().flatten()
1146    }
1147
1148    /// Return a display name by index, preserving bridge failures.
1149    pub fn try_display(&self, index: i32) -> Result<Option<String>> {
1150        crate::clear_last_error();
1151        let display = unsafe {
1152            cstr_from_mut(ocio_sys::ocio_config_get_display(
1153                self.handle.as_ptr(),
1154                index,
1155            ))
1156        };
1157        crate::ocio_call_status()?;
1158        Ok(display.filter(|display| !display.is_empty()))
1159    }
1160
1161    // --- Views ---
1162
1163    /// Return the default view name for the given display, or `None` if not found.
1164    pub fn default_view(&self, display: impl AsRef<str>) -> Option<String> {
1165        self.try_default_view(display).ok().flatten()
1166    }
1167
1168    /// Return the default view for a display while preserving bridge failures.
1169    pub fn try_default_view(&self, display: impl AsRef<str>) -> Result<Option<String>> {
1170        let display = cstring(display)?;
1171        crate::clear_last_error();
1172        let view = unsafe {
1173            cstr_from_mut(ocio_sys::ocio_config_get_default_view(
1174                self.handle.as_ptr(),
1175                display.as_ptr().cast(),
1176            ))
1177        };
1178        crate::ocio_call_status()?;
1179        Ok(view.filter(|view| !view.is_empty()))
1180    }
1181
1182    /// Return the default view for a display, filtered by color-space name.
1183    pub fn default_view_with_color_space(
1184        &self,
1185        display: impl AsRef<str>,
1186        color_space_name: impl AsRef<str>,
1187    ) -> Option<String> {
1188        self.try_default_view_with_color_space(display, color_space_name)
1189            .ok()
1190            .flatten()
1191    }
1192
1193    /// Return the default view filtered by color space while preserving bridge failures.
1194    pub fn try_default_view_with_color_space(
1195        &self,
1196        display: impl AsRef<str>,
1197        color_space_name: impl AsRef<str>,
1198    ) -> Result<Option<String>> {
1199        let display = cstring(display)?;
1200        let color_space_name = cstring(color_space_name)?;
1201        crate::clear_last_error();
1202        let view = unsafe {
1203            cstr_from_mut(ocio_sys::ocio_config_get_default_view_v1(
1204                self.handle.as_ptr(),
1205                display.as_ptr().cast(),
1206                color_space_name.as_ptr().cast(),
1207            ))
1208        };
1209        crate::ocio_call_status()?;
1210        Ok(view.filter(|view| !view.is_empty()))
1211    }
1212
1213    #[doc(hidden)]
1214    #[deprecated(
1215        since = "0.2.0",
1216        note = "compat overload; prefer default_view_with_color_space()"
1217    )]
1218    pub fn get_default_view_v1(
1219        &self,
1220        display: impl AsRef<str>,
1221        color_space_name: impl AsRef<str>,
1222    ) -> Option<String> {
1223        self.default_view_with_color_space(display, color_space_name)
1224    }
1225
1226    #[doc(hidden)]
1227    #[deprecated(
1228        since = "0.2.0",
1229        note = "compat alias; OpenColorIO does not expose a setDefaultView() mutator, prefer set_active_views()"
1230    )]
1231    pub fn set_default_view(&self, view: impl AsRef<str>) -> Result<()> {
1232        self.set_active_views(view)
1233    }
1234
1235    /// Return the number of views registered for the given display.
1236    pub fn num_views(&self, display: impl AsRef<str>) -> i32 {
1237        self.try_num_views(display).unwrap_or(0)
1238    }
1239
1240    /// Return the number of views registered for the given display.
1241    ///
1242    /// Unlike [`Self::num_views`], this preserves invalid input and OCIO query
1243    /// failures as [`OcioError`]. A missing display is reported by OCIO as zero.
1244    pub fn try_num_views(&self, display: impl AsRef<str>) -> Result<i32> {
1245        let display = cstring(display)?;
1246        crate::clear_last_error();
1247        let count = unsafe {
1248            ocio_sys::ocio_config_get_num_views(self.handle.as_ptr(), display.as_ptr().cast())
1249        };
1250        crate::ocio_call_status()?;
1251        Ok(count)
1252    }
1253
1254    /// Return the number of views for a display, filtered by color-space name.
1255    pub fn num_views_with_color_space(
1256        &self,
1257        display: impl AsRef<str>,
1258        color_space_name: impl AsRef<str>,
1259    ) -> i32 {
1260        self.try_num_views_with_color_space(display, color_space_name)
1261            .unwrap_or(0)
1262    }
1263
1264    /// Return the number of views for a display, filtered by color-space name.
1265    ///
1266    /// Unlike [`Self::num_views_with_color_space`], this preserves invalid
1267    /// input and OCIO query failures as [`OcioError`].
1268    pub fn try_num_views_with_color_space(
1269        &self,
1270        display: impl AsRef<str>,
1271        color_space_name: impl AsRef<str>,
1272    ) -> Result<i32> {
1273        let display = cstring(display)?;
1274        let color_space_name = cstring(color_space_name)?;
1275        crate::clear_last_error();
1276        let count = unsafe {
1277            ocio_sys::ocio_config_get_num_views_v1(
1278                self.handle.as_ptr(),
1279                display.as_ptr().cast(),
1280                color_space_name.as_ptr().cast(),
1281            )
1282        };
1283        crate::ocio_call_status()?;
1284        Ok(count)
1285    }
1286
1287    #[doc(hidden)]
1288    #[deprecated(
1289        since = "0.2.0",
1290        note = "compat overload; prefer num_views_with_color_space()"
1291    )]
1292    pub fn get_num_views_v1(
1293        &self,
1294        display: impl AsRef<str>,
1295        color_space_name: impl AsRef<str>,
1296    ) -> i32 {
1297        self.num_views_with_color_space(display, color_space_name)
1298    }
1299
1300    /// Return the view name at the given index for the specified display.
1301    pub fn view(&self, display: impl AsRef<str>, index: i32) -> Option<String> {
1302        self.try_view(display, index).ok().flatten()
1303    }
1304
1305    /// Return a view name by display and index, preserving bridge failures.
1306    /// An empty native result is returned as `None`.
1307    pub fn try_view(&self, display: impl AsRef<str>, index: i32) -> Result<Option<String>> {
1308        let display = cstring(display)?;
1309        crate::clear_last_error();
1310        let view = unsafe {
1311            cstr_from_mut(ocio_sys::ocio_config_get_view(
1312                self.handle.as_ptr(),
1313                display.as_ptr().cast(),
1314                index,
1315            ))
1316        };
1317        crate::ocio_call_status()?;
1318        Ok(view.filter(|view| !view.is_empty()))
1319    }
1320
1321    /// Return the view name at a given index for a display, filtered by color-space name.
1322    pub fn view_with_color_space(
1323        &self,
1324        display: impl AsRef<str>,
1325        color_space_name: impl AsRef<str>,
1326        index: i32,
1327    ) -> Option<String> {
1328        self.try_view_with_color_space(display, color_space_name, index)
1329            .ok()
1330            .flatten()
1331    }
1332
1333    /// Return the view name at a given index for a display and color-space name.
1334    ///
1335    /// Unlike [`Self::view_with_color_space`], this preserves invalid input and
1336    /// OCIO query failures as [`OcioError`]. An empty native result becomes
1337    /// `None`; OCIO may instead return a fallback view for some filters.
1338    pub fn try_view_with_color_space(
1339        &self,
1340        display: impl AsRef<str>,
1341        color_space_name: impl AsRef<str>,
1342        index: i32,
1343    ) -> Result<Option<String>> {
1344        let display = cstring(display)?;
1345        let color_space_name = cstring(color_space_name)?;
1346        crate::clear_last_error();
1347        let view = unsafe {
1348            cstr_from_mut(ocio_sys::ocio_config_get_view_v1(
1349                self.handle.as_ptr(),
1350                display.as_ptr().cast(),
1351                color_space_name.as_ptr().cast(),
1352                index,
1353            ))
1354        };
1355        crate::ocio_call_status()?;
1356        Ok(view.filter(|view| !view.is_empty()))
1357    }
1358
1359    #[doc(hidden)]
1360    #[deprecated(
1361        since = "0.2.0",
1362        note = "compat overload; prefer view_with_color_space()"
1363    )]
1364    pub fn get_view_v1(
1365        &self,
1366        display: impl AsRef<str>,
1367        color_space_name: impl AsRef<str>,
1368        index: i32,
1369    ) -> Option<String> {
1370        self.view_with_color_space(display, color_space_name, index)
1371    }
1372
1373    /// Return whether a given view is a shared view for a specific display.
1374    #[cfg(feature = "v2_5")]
1375    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
1376    pub fn is_view_shared(&self, display: impl AsRef<str>, view: impl AsRef<str>) -> bool {
1377        let display = match cstring(display) {
1378            Ok(v) => v,
1379            Err(_) => return false,
1380        };
1381        let view = match cstring(view) {
1382            Ok(v) => v,
1383            Err(_) => return false,
1384        };
1385        unsafe {
1386            ocio_sys::ocio_config_is_view_shared(
1387                self.handle.as_ptr(),
1388                display.as_ptr().cast(),
1389                view.as_ptr().cast(),
1390            )
1391        }
1392    }
1393
1394    /// # Safety
1395    /// `first` and `second` must be valid pointers to live `ConfigHandle` values from this ABI.
1396    /// Both are borrowed for the duration of this call and must not be freed here.
1397    #[doc(hidden)]
1398    #[deprecated(
1399        since = "0.2.0",
1400        note = "raw OCIO view-descriptor entry point; prefer higher-level display/view APIs unless you must interoperate with external OCIO ABI objects"
1401    )]
1402    #[cfg(feature = "v2_5")]
1403    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
1404    pub unsafe fn are_views_equal(
1405        &self,
1406        first: *mut c_void,
1407        second: *mut c_void,
1408        display: impl AsRef<str>,
1409        view: impl AsRef<str>,
1410    ) -> bool {
1411        let display = match cstring(display) {
1412            Ok(v) => v,
1413            Err(_) => return false,
1414        };
1415        let view = match cstring(view) {
1416            Ok(v) => v,
1417            Err(_) => return false,
1418        };
1419        unsafe {
1420            ocio_sys::ocio_config_are_views_equal(
1421                self.handle.as_ptr(),
1422                first,
1423                second,
1424                display.as_ptr().cast(),
1425                view.as_ptr().cast(),
1426            )
1427        }
1428    }
1429
1430    /// Compare a display/view definition in two configs.
1431    ///
1432    /// This is the safe counterpart to OCIO's `Config::AreViewsEqual`. It compares the strings
1433    /// in the definitions; it does not compare the identities of referenced color spaces or view
1434    /// transforms.
1435    #[cfg(feature = "v2_5")]
1436    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
1437    pub fn try_are_views_equal(
1438        first: &Self,
1439        second: &Self,
1440        display: impl AsRef<str>,
1441        view: impl AsRef<str>,
1442    ) -> Result<bool> {
1443        let display = cstring(display)?;
1444        let view = cstring(view)?;
1445        crate::clear_last_error();
1446        let equal = unsafe {
1447            ocio_sys::ocio_config_are_views_equal(
1448                first.handle.as_ptr(),
1449                first.handle.as_ptr(),
1450                second.handle.as_ptr(),
1451                display.as_ptr().cast(),
1452                view.as_ptr().cast(),
1453            )
1454        };
1455        crate::ocio_call_status()?;
1456        Ok(equal)
1457    }
1458
1459    // --- Looks ---
1460
1461    /// Return the total number of looks registered in the config.
1462    pub fn num_looks(&self) -> i32 {
1463        unsafe { ocio_sys::ocio_config_get_num_looks(self.handle.as_ptr() as *mut c_void) }
1464    }
1465
1466    /// Return the look name at a given index, or `None` if out of range.
1467    pub fn look_name_by_index(&self, index: i32) -> Option<String> {
1468        self.try_look_name_by_index(index).ok().flatten()
1469    }
1470
1471    /// Return a look name by index, preserving bridge failures.
1472    pub fn try_look_name_by_index(&self, index: i32) -> Result<Option<String>> {
1473        crate::clear_last_error();
1474        let name = unsafe {
1475            cstr_from_mut(ocio_sys::ocio_config_get_look_name_by_index(
1476                self.handle.as_ptr(),
1477                index,
1478            ))
1479        };
1480        crate::ocio_call_status()?;
1481        Ok(name.filter(|name| !name.is_empty()))
1482    }
1483
1484    /// Return a comma-separated string of all look names.
1485    pub fn looks(&self) -> Option<String> {
1486        self.try_looks().ok()
1487    }
1488
1489    /// Return all look names as a comma-separated list, preserving query errors.
1490    pub fn try_looks(&self) -> Result<String> {
1491        let names = (0..self.num_looks())
1492            .map(|index| {
1493                self.try_look_name_by_index(index)?.ok_or_else(|| {
1494                    OcioError::ValidationFailed(format!("missing look name at index {index}"))
1495                })
1496            })
1497            .collect::<Result<Vec<_>>>()?;
1498        Ok(names.join(","))
1499    }
1500
1501    // --- Luma coefficients ---
1502
1503    /// Return the default luminance coefficients used by display transforms.
1504    pub fn default_luma_coefs(&self) -> Result<[f64; 3]> {
1505        let mut coefs = [0.0f64; 3];
1506        crate::clear_last_error();
1507        unsafe {
1508            ocio_sys::ocio_config_get_default_luma_coefs(
1509                self.handle.as_ptr(),
1510                coefs.as_mut_ptr() as *mut c_void,
1511            );
1512        }
1513        crate::ocio_call_status()?;
1514        Ok(coefs)
1515    }
1516
1517    /// Set the default luminance coefficients used by display transforms.
1518    pub fn set_default_luma_coefs(&self, coefs: &[f64; 3]) -> Result<()> {
1519        crate::clear_last_error();
1520        unsafe {
1521            ocio_sys::ocio_config_set_default_luma_coefs(
1522                self.handle.as_ptr(),
1523                coefs.as_ptr() as *mut c_void,
1524            )
1525        };
1526        crate::ocio_call_status()
1527    }
1528
1529    // --- Roles ---
1530
1531    /// Return the total number of roles defined in the config.
1532    pub fn num_roles(&self) -> i32 {
1533        unsafe { ocio_sys::ocio_config_get_num_roles(self.handle.as_ptr() as *mut c_void) }
1534    }
1535
1536    /// Return whether a role with the given name exists.
1537    pub fn has_role(&self, role: impl AsRef<str>) -> bool {
1538        let role = match cstring(role) {
1539            Ok(r) => r,
1540            Err(_) => return false,
1541        };
1542        unsafe { ocio_sys::ocio_config_has_role(self.handle.as_ptr(), role.as_ptr().cast()) }
1543    }
1544
1545    /// Return the role name at a given index.
1546    pub fn role_name(&self, index: i32) -> Option<String> {
1547        self.try_role_name(index).ok().flatten()
1548    }
1549
1550    /// Return the role name at a given index.
1551    ///
1552    /// Unlike [`Self::role_name`], this preserves OCIO query failures as
1553    /// [`OcioError`].
1554    pub fn try_role_name(&self, index: i32) -> Result<Option<String>> {
1555        crate::clear_last_error();
1556        let name = unsafe {
1557            cstr_from_mut(ocio_sys::ocio_config_get_role_name(
1558                self.handle.as_ptr(),
1559                index,
1560            ))
1561        };
1562        crate::ocio_call_status()?;
1563        Ok(name.filter(|name| !name.is_empty()))
1564    }
1565
1566    /// Return the color-space name bound to the role at a given index.
1567    pub fn role_color_space_by_index(&self, index: i32) -> Option<String> {
1568        self.try_role_color_space_by_index(index).ok().flatten()
1569    }
1570
1571    /// Return the color-space name bound to the role at a given index.
1572    ///
1573    /// Unlike [`Self::role_color_space_by_index`], this preserves OCIO query
1574    /// failures as [`OcioError`].
1575    pub fn try_role_color_space_by_index(&self, index: i32) -> Result<Option<String>> {
1576        crate::clear_last_error();
1577        let color_space = unsafe {
1578            cstr_from_mut(ocio_sys::ocio_config_get_role_color_space_by_index(
1579                self.handle.as_ptr(),
1580                index,
1581            ))
1582        };
1583        crate::ocio_call_status()?;
1584        Ok(color_space)
1585    }
1586
1587    /// Look up the color space currently bound to a role name.
1588    pub fn role_color_space(&self, role_name: impl AsRef<str>) -> Option<String> {
1589        self.try_role_color_space(role_name).ok().flatten()
1590    }
1591
1592    /// Look up the color space currently bound to a role name.
1593    ///
1594    /// Unlike [`Self::role_color_space`], this preserves invalid input and
1595    /// OCIO query failures as [`OcioError`].
1596    pub fn try_role_color_space(&self, role_name: impl AsRef<str>) -> Result<Option<String>> {
1597        let role = cstring(role_name)?;
1598        crate::clear_last_error();
1599        let color_space = unsafe {
1600            cstr_from_mut(ocio_sys::ocio_config_get_role_color_space_by_name(
1601                self.handle.as_ptr(),
1602                role.as_ptr().cast(),
1603            ))
1604        };
1605        crate::ocio_call_status()?;
1606        Ok(color_space)
1607    }
1608
1609    // --- Active displays / views ---
1610
1611    /// Return the comma-separated string of active display names.
1612    pub fn active_displays(&self) -> Option<String> {
1613        self.try_active_displays().ok().flatten()
1614    }
1615
1616    /// Return the active display list, preserving OCIO query failures.
1617    pub fn try_active_displays(&self) -> Result<Option<String>> {
1618        crate::clear_last_error();
1619        let displays = unsafe {
1620            cstr_from_mut(ocio_sys::ocio_config_get_active_displays(
1621                self.handle.as_ptr() as *mut c_void,
1622            ))
1623        };
1624        crate::ocio_call_status()?;
1625        Ok(displays)
1626    }
1627
1628    /// Return the comma-separated string of active view names.
1629    pub fn active_views(&self) -> Option<String> {
1630        self.try_active_views().ok().flatten()
1631    }
1632
1633    /// Return the active view list, preserving OCIO query failures.
1634    pub fn try_active_views(&self) -> Result<Option<String>> {
1635        crate::clear_last_error();
1636        let views = unsafe {
1637            cstr_from_mut(ocio_sys::ocio_config_get_active_views(
1638                self.handle.as_ptr() as *mut c_void
1639            ))
1640        };
1641        crate::ocio_call_status()?;
1642        Ok(views)
1643    }
1644
1645    /// Replace the active displays list from a comma-separated string.
1646    pub fn set_active_displays(&self, displays: impl AsRef<str>) -> Result<()> {
1647        let d = cstring(displays)?;
1648        crate::clear_last_error();
1649        unsafe {
1650            ocio_sys::ocio_config_set_active_displays(self.handle.as_ptr(), d.as_ptr().cast())
1651        };
1652        crate::ocio_call_status()
1653    }
1654
1655    /// Replace the active views list from a comma-separated string.
1656    pub fn set_active_views(&self, views: impl AsRef<str>) -> Result<()> {
1657        let v = cstring(views)?;
1658        crate::clear_last_error();
1659        unsafe { ocio_sys::ocio_config_set_active_views(self.handle.as_ptr(), v.as_ptr().cast()) };
1660        crate::ocio_call_status()
1661    }
1662
1663    // --- Display/view transform name queries ---
1664
1665    /// Return the display-view transform name for the given display/view pair.
1666    pub fn display_view_transform_name(
1667        &self,
1668        display: impl AsRef<str>,
1669        view: impl AsRef<str>,
1670    ) -> Option<String> {
1671        let display = cstring(display).ok()?;
1672        let view = cstring(view).ok()?;
1673        unsafe {
1674            cstr_from_mut(ocio_sys::ocio_config_get_display_view_transform_name(
1675                self.handle.as_ptr(),
1676                display.as_ptr().cast(),
1677                view.as_ptr().cast(),
1678            ))
1679        }
1680    }
1681
1682    /// Return the color-space name associated with the given display/view pair.
1683    pub fn display_view_color_space_name(
1684        &self,
1685        display: impl AsRef<str>,
1686        view: impl AsRef<str>,
1687    ) -> Option<String> {
1688        let display = cstring(display).ok()?;
1689        let view = cstring(view).ok()?;
1690        unsafe {
1691            cstr_from_mut(ocio_sys::ocio_config_get_display_view_color_space_name(
1692                self.handle.as_ptr(),
1693                display.as_ptr().cast(),
1694                view.as_ptr().cast(),
1695            ))
1696        }
1697    }
1698
1699    /// Return the looks string associated with a display/view pair.
1700    pub fn display_view_looks(
1701        &self,
1702        display: impl AsRef<str>,
1703        view: impl AsRef<str>,
1704    ) -> Option<String> {
1705        let d = cstring(display).ok()?;
1706        let v = cstring(view).ok()?;
1707        unsafe {
1708            cstr_from_mut(ocio_sys::ocio_config_get_display_view_looks(
1709                self.handle.as_ptr(),
1710                d.as_ptr().cast(),
1711                v.as_ptr().cast(),
1712            ))
1713        }
1714    }
1715
1716    /// Return the rule name associated with a display/view pair.
1717    pub fn display_view_rule(
1718        &self,
1719        display: impl AsRef<str>,
1720        view: impl AsRef<str>,
1721    ) -> Option<String> {
1722        let display = cstring(display).ok()?;
1723        let view = cstring(view).ok()?;
1724        unsafe {
1725            cstr_from_mut(ocio_sys::ocio_config_get_display_view_rule(
1726                self.handle.as_ptr(),
1727                display.as_ptr().cast(),
1728                view.as_ptr().cast(),
1729            ))
1730        }
1731    }
1732
1733    #[doc(hidden)]
1734    #[deprecated(since = "0.2.0", note = "compat alias; prefer display_view_rule()")]
1735    pub fn get_display_view_rule(
1736        &self,
1737        display: impl AsRef<str>,
1738        view: impl AsRef<str>,
1739    ) -> Option<String> {
1740        self.display_view_rule(display, view)
1741    }
1742
1743    /// Return the description string for a display/view pair.
1744    pub fn display_view_description(
1745        &self,
1746        display: impl AsRef<str>,
1747        view: impl AsRef<str>,
1748    ) -> Option<String> {
1749        let display = cstring(display).ok()?;
1750        let view = cstring(view).ok()?;
1751        unsafe {
1752            cstr_from_mut(ocio_sys::ocio_config_get_display_view_description(
1753                self.handle.as_ptr(),
1754                display.as_ptr().cast(),
1755                view.as_ptr().cast(),
1756            ))
1757        }
1758    }
1759
1760    #[doc(hidden)]
1761    #[deprecated(
1762        since = "0.2.0",
1763        note = "compat alias; prefer display_view_description()"
1764    )]
1765    pub fn get_display_view_description(
1766        &self,
1767        display: impl AsRef<str>,
1768        view: impl AsRef<str>,
1769    ) -> Option<String> {
1770        self.display_view_description(display, view)
1771    }
1772
1773    /// Return whether the given view exists for the specified display.
1774    #[cfg(feature = "v2_5")]
1775    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
1776    pub fn has_view(&self, display: impl AsRef<str>, view: impl AsRef<str>) -> bool {
1777        let display = match cstring(display) {
1778            Ok(v) => v,
1779            Err(_) => return false,
1780        };
1781        let view = match cstring(view) {
1782            Ok(v) => v,
1783            Err(_) => return false,
1784        };
1785        unsafe {
1786            ocio_sys::ocio_config_has_view(
1787                self.handle.as_ptr(),
1788                display.as_ptr().cast(),
1789                view.as_ptr().cast(),
1790            )
1791        }
1792    }
1793
1794    /// Check a config-level shared view using OCIO's null-display query.
1795    ///
1796    /// This does not require the shared view to be attached to a display.
1797    /// Invalid input and bridge failures are returned as errors.
1798    #[cfg(feature = "v2_5")]
1799    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
1800    pub fn try_has_shared_view(&self, view: impl AsRef<str>) -> Result<bool> {
1801        let view = cstring(view)?;
1802        crate::clear_last_error();
1803        let exists = unsafe {
1804            ocio_sys::ocio_config_has_view(self.handle.as_ptr(), std::ptr::null(), view.as_ptr())
1805        };
1806        crate::ocio_call_status()?;
1807        Ok(exists)
1808    }
1809
1810    /// Return an editable copy of the default scene-to-display view transform.
1811    pub fn default_scene_to_display_view_transform(&self) -> Option<crate::ViewTransform> {
1812        self.try_default_scene_to_display_view_transform()
1813            .ok()
1814            .flatten()
1815    }
1816
1817    /// Copy the default view transform while preserving native errors.
1818    pub fn try_default_scene_to_display_view_transform(
1819        &self,
1820    ) -> Result<Option<crate::ViewTransform>> {
1821        crate::clear_last_error();
1822        let handle = unsafe {
1823            ocio_sys::ocio_config_get_default_scene_to_display_view_transform(
1824                self.handle.as_ptr() as *mut c_void
1825            )
1826        };
1827        crate::ocio_call_status()?;
1828        Ok(NonNull::new(handle).map(|h| crate::ViewTransform { handle: h }))
1829    }
1830
1831    /// Return the name of the default view transform.
1832    pub fn default_view_transform_name(&self) -> Option<String> {
1833        unsafe {
1834            cstr_from_mut(ocio_sys::ocio_config_get_default_view_transform_name(
1835                self.handle.as_ptr(),
1836            ))
1837        }
1838    }
1839
1840    #[doc(hidden)]
1841    #[deprecated(
1842        since = "0.2.0",
1843        note = "compat alias; prefer default_view_transform_name()"
1844    )]
1845    pub fn get_default_view_transform_name(&self) -> Option<String> {
1846        self.default_view_transform_name()
1847    }
1848
1849    /// Set the name of the default view transform.
1850    pub fn set_default_view_transform_name(&self, default_name: impl AsRef<str>) -> Result<()> {
1851        let default_name = cstring(default_name)?;
1852        crate::clear_last_error();
1853        unsafe {
1854            ocio_sys::ocio_config_set_default_view_transform_name(
1855                self.handle.as_ptr(),
1856                default_name.as_ptr().cast(),
1857            );
1858        }
1859        crate::ocio_call_status()
1860    }
1861
1862    // --- Processors ---
1863
1864    /// Create a processor between two authored color-space names.
1865    pub fn processor(&self, src: impl AsRef<str>, dst: impl AsRef<str>) -> Result<Processor> {
1866        let src = cstring(src)?;
1867        let dst = cstring(dst)?;
1868        crate::clear_last_error();
1869        let handle = unsafe {
1870            ocio_sys::ocio_config_get_processor_v2(
1871                self.handle.as_ptr(),
1872                src.as_ptr().cast(),
1873                dst.as_ptr().cast(),
1874            )
1875        };
1876        Self::processor_handle_result(handle)
1877    }
1878
1879    /// Create a processor between two `ColorSpace` object handles.
1880    pub fn processor_from_color_spaces(
1881        &self,
1882        src_color_space: &ColorSpace,
1883        dst_color_space: &ColorSpace,
1884    ) -> Result<Processor> {
1885        crate::clear_last_error();
1886        let handle = unsafe {
1887            ocio_sys::ocio_config_get_processor_v1(
1888                self.handle.as_ptr(),
1889                src_color_space.handle.as_ptr(),
1890                dst_color_space.handle.as_ptr(),
1891            )
1892        };
1893        Self::processor_handle_result(handle)
1894    }
1895
1896    /// Create a processor using editable or read-only color-space objects.
1897    pub fn processor_from_color_space_refs<'a, 'b>(
1898        &self,
1899        src: impl Into<crate::ColorSpaceRef<'a>>,
1900        dst: impl Into<crate::ColorSpaceRef<'b>>,
1901    ) -> Result<Processor> {
1902        self.processor_from_color_space_refs_inner(None, src.into(), dst.into())
1903    }
1904
1905    /// Create a processor using object references and an explicit OCIO context.
1906    pub fn processor_from_color_space_refs_with_context<'a, 'b>(
1907        &self,
1908        context: &Context,
1909        src: impl Into<crate::ColorSpaceRef<'a>>,
1910        dst: impl Into<crate::ColorSpaceRef<'b>>,
1911    ) -> Result<Processor> {
1912        self.processor_from_color_space_refs_inner(Some(context), src.into(), dst.into())
1913    }
1914
1915    fn processor_from_color_space_refs_inner(
1916        &self,
1917        context: Option<&Context>,
1918        src: crate::ColorSpaceRef<'_>,
1919        dst: crate::ColorSpaceRef<'_>,
1920    ) -> Result<Processor> {
1921        let (src, src_const) = src.raw();
1922        let (dst, dst_const) = dst.raw();
1923        crate::clear_last_error();
1924        let handle = unsafe {
1925            ocio_sys::ocio_config_get_processor_from_color_space_refs(
1926                self.handle.as_ptr(),
1927                context.map_or(std::ptr::null_mut(), |value| value.handle.as_ptr()),
1928                src,
1929                src_const,
1930                dst,
1931                dst_const,
1932            )
1933        };
1934        Self::processor_handle_result(handle)
1935    }
1936
1937    #[doc(hidden)]
1938    #[deprecated(
1939        since = "0.2.0",
1940        note = "compat alias; prefer processor_from_color_spaces()"
1941    )]
1942    pub fn get_processor_v1(
1943        &self,
1944        src_color_space: &ColorSpace,
1945        dst_color_space: &ColorSpace,
1946    ) -> Result<Processor> {
1947        self.processor_from_color_spaces(src_color_space, dst_color_space)
1948    }
1949
1950    #[doc(hidden)]
1951    #[deprecated(since = "0.2.0", note = "compat alias; prefer processor()")]
1952    pub fn get_processor_v2(
1953        &self,
1954        src: impl AsRef<str>,
1955        dst: impl AsRef<str>,
1956    ) -> Result<Processor> {
1957        self.processor(src, dst)
1958    }
1959
1960    /// Create a processor that resolves through a display/view pair.
1961    pub fn processor_display(
1962        &self,
1963        src: impl AsRef<str>,
1964        display: impl AsRef<str>,
1965        view: impl AsRef<str>,
1966        direction: TransformDirection,
1967    ) -> Result<Processor> {
1968        let src = cstring(src)?;
1969        let display = cstring(display)?;
1970        let view = cstring(view)?;
1971        crate::clear_last_error();
1972        let handle = unsafe {
1973            ocio_sys::ocio_config_get_processor_v4(
1974                self.handle.as_ptr(),
1975                src.as_ptr().cast(),
1976                display.as_ptr().cast(),
1977                view.as_ptr().cast(),
1978                direction as i32,
1979            )
1980        };
1981        Self::processor_handle_result(handle)
1982    }
1983
1984    #[doc(hidden)]
1985    #[deprecated(since = "0.2.0", note = "compat alias; prefer processor_display()")]
1986    pub fn get_processor_v4(
1987        &self,
1988        src: impl AsRef<str>,
1989        display: impl AsRef<str>,
1990        view: impl AsRef<str>,
1991        direction: TransformDirection,
1992    ) -> Result<Processor> {
1993        self.processor_display(src, display, view, direction)
1994    }
1995
1996    /// Create a processor from names using a shared read-only context.
1997    pub fn processor_with_const_context(
1998        &self,
1999        src: &std::ffi::CStr,
2000        dst: &std::ffi::CStr,
2001        context: &crate::ConstContext,
2002    ) -> Result<Processor> {
2003        crate::clear_last_error();
2004        let handle = unsafe {
2005            ocio_sys::ocio_config_get_processor_with_const_context(
2006                self.handle.as_ptr(),
2007                context.handle.as_ptr(),
2008                src.as_ptr(),
2009                dst.as_ptr(),
2010            )
2011        };
2012        Self::processor_handle_result(handle)
2013    }
2014    /// Create a processor directly from shared read-only context and transform objects.
2015    pub fn processor_from_const_transform_with_const_context(
2016        &self,
2017        transform: &crate::transform::ConstTransform,
2018        direction: TransformDirection,
2019        context: &crate::ConstContext,
2020    ) -> Result<Processor> {
2021        crate::clear_last_error();
2022        let handle = unsafe {
2023            ocio_sys::ocio_config_get_processor_const_transform_with_const_context(
2024                self.handle.as_ptr(),
2025                context.handle.as_ptr(),
2026                transform.handle.as_ptr(),
2027                direction as i32,
2028            )
2029        };
2030        Self::processor_handle_result(handle)
2031    }
2032
2033    /// Create a processor directly from a shared named transform and optional context.
2034    pub fn processor_from_const_named_transform(
2035        &self,
2036        named: &crate::ConstNamedTransform,
2037        direction: TransformDirection,
2038        context: Option<&Context>,
2039    ) -> Result<Processor> {
2040        crate::clear_last_error();
2041        let handle = unsafe {
2042            ocio_sys::ocio_config_get_processor_from_const_named_transform(
2043                self.handle.as_ptr(),
2044                context.map_or(std::ptr::null_mut(), |c| c.handle.as_ptr()),
2045                named.raw(),
2046                direction as i32,
2047            )
2048        };
2049        Self::processor_handle_result(handle)
2050    }
2051
2052    /// Create a processor from a shared read-only transform and optional context.
2053    pub fn processor_from_const_transform(
2054        &self,
2055        transform: &crate::transform::ConstTransform,
2056        direction: TransformDirection,
2057        context: Option<&Context>,
2058    ) -> Result<Processor> {
2059        crate::clear_last_error();
2060        let handle = unsafe {
2061            ocio_sys::ocio_config_get_processor_from_const_transform(
2062                self.handle.as_ptr(),
2063                context.map_or(std::ptr::null_mut(), |c| c.handle.as_ptr()),
2064                transform.handle.as_ptr(),
2065                direction as i32,
2066            )
2067        };
2068        Self::processor_handle_result(handle)
2069    }
2070
2071    /// Create a processor from a transform with an explicit direction.
2072    pub fn processor_from_transform(
2073        &self,
2074        transform: &impl TransformHandle,
2075        direction: TransformDirection,
2076    ) -> Result<Processor> {
2077        crate::clear_last_error();
2078        let handle = unsafe {
2079            ocio_sys::ocio_config_get_processor_v11(
2080                self.handle.as_ptr(),
2081                transform.as_ptr(),
2082                direction as i32,
2083            )
2084        };
2085        Self::processor_handle_result(handle)
2086    }
2087
2088    /// Create a processor from a transform using OCIO's default transform direction.
2089    pub fn processor_from_transform_default_direction(
2090        &self,
2091        transform: &impl TransformHandle,
2092    ) -> Result<Processor> {
2093        crate::clear_last_error();
2094        let handle = unsafe {
2095            ocio_sys::ocio_config_get_processor_v10(self.handle.as_ptr(), transform.as_ptr())
2096        };
2097        Self::processor_handle_result(handle)
2098    }
2099
2100    #[doc(hidden)]
2101    #[deprecated(
2102        since = "0.2.0",
2103        note = "compat alias; prefer processor_from_transform_default_direction()"
2104    )]
2105    pub fn get_processor_v10(&self, transform: &impl TransformHandle) -> Result<Processor> {
2106        self.processor_from_transform_default_direction(transform)
2107    }
2108
2109    #[doc(hidden)]
2110    #[deprecated(
2111        since = "0.2.0",
2112        note = "compat alias; prefer processor_from_transform()"
2113    )]
2114    pub fn get_processor_v11(
2115        &self,
2116        transform: &impl TransformHandle,
2117        direction: TransformDirection,
2118    ) -> Result<Processor> {
2119        self.processor_from_transform(transform, direction)
2120    }
2121
2122    /// Create a processor between two color spaces using an explicit context for lookups.
2123    pub fn processor_with_context(
2124        &self,
2125        src: impl AsRef<str>,
2126        dst: impl AsRef<str>,
2127        context: &crate::Context,
2128    ) -> Result<Processor> {
2129        let src = cstring(src)?;
2130        let dst = cstring(dst)?;
2131        crate::clear_last_error();
2132        let handle = unsafe {
2133            ocio_sys::ocio_config_get_processor_v3(
2134                self.handle.as_ptr(),
2135                context.handle.as_ptr(),
2136                src.as_ptr().cast(),
2137                dst.as_ptr().cast(),
2138            )
2139        };
2140        Self::processor_handle_result(handle)
2141    }
2142
2143    #[doc(hidden)]
2144    #[deprecated(
2145        since = "0.2.0",
2146        note = "compat alias; prefer processor_with_context()"
2147    )]
2148    pub fn get_processor_v3(
2149        &self,
2150        src: impl AsRef<str>,
2151        dst: impl AsRef<str>,
2152        context: &crate::Context,
2153    ) -> Result<Processor> {
2154        self.processor_with_context(src, dst, context)
2155    }
2156
2157    /// Create a processor that resolves through a display/view pair with an explicit context.
2158    pub fn processor_display_with_context(
2159        &self,
2160        src: impl AsRef<str>,
2161        display: impl AsRef<str>,
2162        view: impl AsRef<str>,
2163        direction: TransformDirection,
2164        context: &crate::Context,
2165    ) -> Result<Processor> {
2166        let src = cstring(src)?;
2167        let display = cstring(display)?;
2168        let view = cstring(view)?;
2169        crate::clear_last_error();
2170        let handle = unsafe {
2171            ocio_sys::ocio_config_get_processor_v5(
2172                self.handle.as_ptr(),
2173                context.handle.as_ptr(),
2174                src.as_ptr().cast(),
2175                display.as_ptr().cast(),
2176                view.as_ptr().cast(),
2177                direction as i32,
2178            )
2179        };
2180        Self::processor_handle_result(handle)
2181    }
2182
2183    #[doc(hidden)]
2184    #[deprecated(
2185        since = "0.2.0",
2186        note = "compat alias; prefer processor_display_with_context()"
2187    )]
2188    pub fn get_processor_v5(
2189        &self,
2190        src: impl AsRef<str>,
2191        display: impl AsRef<str>,
2192        view: impl AsRef<str>,
2193        direction: TransformDirection,
2194        context: &crate::Context,
2195    ) -> Result<Processor> {
2196        self.processor_display_with_context(src, display, view, direction, context)
2197    }
2198
2199    /// Create a processor from a transform and an explicit context.
2200    pub fn processor_from_transform_with_context(
2201        &self,
2202        context: &crate::Context,
2203        transform: &impl TransformHandle,
2204        direction: TransformDirection,
2205    ) -> Result<Processor> {
2206        crate::clear_last_error();
2207        let handle = unsafe {
2208            ocio_sys::ocio_config_get_processor_v12(
2209                self.handle.as_ptr(),
2210                context.handle.as_ptr(),
2211                transform.as_ptr(),
2212                direction as i32,
2213            )
2214        };
2215        Self::processor_handle_result(handle)
2216    }
2217
2218    #[doc(hidden)]
2219    #[deprecated(
2220        since = "0.2.0",
2221        note = "compat alias; prefer processor_from_transform_with_context()"
2222    )]
2223    pub fn get_processor_v12(
2224        &self,
2225        context: &crate::Context,
2226        transform: &impl TransformHandle,
2227        direction: TransformDirection,
2228    ) -> Result<Processor> {
2229        self.processor_from_transform_with_context(context, transform, direction)
2230    }
2231
2232    /// Create a processor from a named-transform object.
2233    pub fn processor_named_transform(
2234        &self,
2235        named_transform: &NamedTransform,
2236        direction: TransformDirection,
2237    ) -> Result<Processor> {
2238        crate::clear_last_error();
2239        let handle = unsafe {
2240            ocio_sys::ocio_config_get_processor_v6(
2241                self.handle.as_ptr(),
2242                named_transform.handle.as_ptr(),
2243                direction as i32,
2244            )
2245        };
2246        Self::processor_handle_result(handle)
2247    }
2248
2249    #[doc(hidden)]
2250    #[deprecated(
2251        since = "0.2.0",
2252        note = "compat alias; prefer processor_named_transform()"
2253    )]
2254    pub fn get_processor_v6(
2255        &self,
2256        named_transform: &NamedTransform,
2257        direction: TransformDirection,
2258    ) -> Result<Processor> {
2259        self.processor_named_transform(named_transform, direction)
2260    }
2261
2262    /// Create a processor from a named-transform object with an explicit context.
2263    pub fn processor_named_transform_with_context(
2264        &self,
2265        context: &crate::Context,
2266        named_transform: &NamedTransform,
2267        direction: TransformDirection,
2268    ) -> Result<Processor> {
2269        crate::clear_last_error();
2270        let handle = unsafe {
2271            ocio_sys::ocio_config_get_processor_v7(
2272                self.handle.as_ptr(),
2273                context.handle.as_ptr(),
2274                named_transform.handle.as_ptr(),
2275                direction as i32,
2276            )
2277        };
2278        Self::processor_handle_result(handle)
2279    }
2280
2281    #[doc(hidden)]
2282    #[deprecated(
2283        since = "0.2.0",
2284        note = "compat alias; prefer processor_named_transform_with_context()"
2285    )]
2286    pub fn get_processor_v7(
2287        &self,
2288        context: &crate::Context,
2289        named_transform: &NamedTransform,
2290        direction: TransformDirection,
2291    ) -> Result<Processor> {
2292        self.processor_named_transform_with_context(context, named_transform, direction)
2293    }
2294
2295    /// Create a processor from a named-transform name.
2296    pub fn processor_named_transform_name(
2297        &self,
2298        named_transform_name: impl AsRef<str>,
2299        direction: TransformDirection,
2300    ) -> Result<Processor> {
2301        let named_transform_name = cstring(named_transform_name)?;
2302        crate::clear_last_error();
2303        let handle = unsafe {
2304            ocio_sys::ocio_config_get_processor_v8(
2305                self.handle.as_ptr(),
2306                named_transform_name.as_ptr().cast(),
2307                direction as i32,
2308            )
2309        };
2310        Self::processor_handle_result(handle)
2311    }
2312
2313    #[doc(hidden)]
2314    #[deprecated(
2315        since = "0.2.0",
2316        note = "compat alias; prefer processor_named_transform_name()"
2317    )]
2318    pub fn get_processor_v8(
2319        &self,
2320        named_transform_name: impl AsRef<str>,
2321        direction: TransformDirection,
2322    ) -> Result<Processor> {
2323        self.processor_named_transform_name(named_transform_name, direction)
2324    }
2325
2326    /// Create a processor from a named-transform name with an explicit context.
2327    pub fn processor_named_transform_name_with_context(
2328        &self,
2329        context: &crate::Context,
2330        named_transform_name: impl AsRef<str>,
2331        direction: TransformDirection,
2332    ) -> Result<Processor> {
2333        let named_transform_name = cstring(named_transform_name)?;
2334        crate::clear_last_error();
2335        let handle = unsafe {
2336            ocio_sys::ocio_config_get_processor_v9(
2337                self.handle.as_ptr(),
2338                context.handle.as_ptr(),
2339                named_transform_name.as_ptr().cast(),
2340                direction as i32,
2341            )
2342        };
2343        Self::processor_handle_result(handle)
2344    }
2345
2346    #[doc(hidden)]
2347    #[deprecated(
2348        since = "0.2.0",
2349        note = "compat alias; prefer processor_named_transform_name_with_context()"
2350    )]
2351    pub fn get_processor_v9(
2352        &self,
2353        context: &crate::Context,
2354        named_transform_name: impl AsRef<str>,
2355        direction: TransformDirection,
2356    ) -> Result<Processor> {
2357        self.processor_named_transform_name_with_context(context, named_transform_name, direction)
2358    }
2359
2360    /// Create a processor from a source config color space to a built-in color space.
2361    pub fn processor_to_builtin_color_space(
2362        &self,
2363        src_config: &Config,
2364        src_color_space_name: impl AsRef<str>,
2365        builtin_color_space_name: impl AsRef<str>,
2366    ) -> Result<Processor> {
2367        let src_color_space_name = cstring(src_color_space_name)?;
2368        let builtin_color_space_name = cstring(builtin_color_space_name)?;
2369        crate::clear_last_error();
2370        let handle = unsafe {
2371            ocio_sys::ocio_config_get_processor_to_builtin_color_space(
2372                self.handle.as_ptr(),
2373                src_config.handle.as_ptr(),
2374                src_color_space_name.as_ptr().cast(),
2375                builtin_color_space_name.as_ptr().cast(),
2376            )
2377        };
2378        Self::processor_handle_result(handle)
2379    }
2380
2381    #[doc(hidden)]
2382    #[deprecated(
2383        since = "0.2.0",
2384        note = "compat alias; prefer processor_to_builtin_color_space()"
2385    )]
2386    pub fn get_processor_to_builtin_color_space(
2387        &self,
2388        src_config: &Config,
2389        src_color_space_name: impl AsRef<str>,
2390        builtin_color_space_name: impl AsRef<str>,
2391    ) -> Result<Processor> {
2392        self.processor_to_builtin_color_space(
2393            src_config,
2394            src_color_space_name,
2395            builtin_color_space_name,
2396        )
2397    }
2398
2399    /// Create a processor from a built-in color space to a source config color space.
2400    pub fn processor_from_builtin_color_space(
2401        &self,
2402        builtin_color_space_name: impl AsRef<str>,
2403        src_config: &Config,
2404        src_color_space_name: impl AsRef<str>,
2405    ) -> Result<Processor> {
2406        let builtin_color_space_name = cstring(builtin_color_space_name)?;
2407        let src_color_space_name = cstring(src_color_space_name)?;
2408        crate::clear_last_error();
2409        let handle = unsafe {
2410            ocio_sys::ocio_config_get_processor_from_builtin_color_space(
2411                self.handle.as_ptr(),
2412                builtin_color_space_name.as_ptr().cast(),
2413                src_config.handle.as_ptr(),
2414                src_color_space_name.as_ptr().cast(),
2415            )
2416        };
2417        Self::processor_handle_result(handle)
2418    }
2419
2420    #[doc(hidden)]
2421    #[deprecated(
2422        since = "0.2.0",
2423        note = "compat alias; prefer processor_from_builtin_color_space()"
2424    )]
2425    pub fn get_processor_from_builtin_color_space(
2426        &self,
2427        builtin_color_space_name: impl AsRef<str>,
2428        src_config: &Config,
2429        src_color_space_name: impl AsRef<str>,
2430    ) -> Result<Processor> {
2431        self.processor_from_builtin_color_space(
2432            builtin_color_space_name,
2433            src_config,
2434            src_color_space_name,
2435        )
2436    }
2437
2438    /// Create a processor between two color spaces in two different configs.
2439    pub fn processor_from_configs(
2440        src_config: &Config,
2441        src_name: impl AsRef<str>,
2442        dst_config: &Config,
2443        dst_name: impl AsRef<str>,
2444    ) -> Result<Processor> {
2445        let src_name = cstring(src_name)?;
2446        let dst_name = cstring(dst_name)?;
2447        crate::clear_last_error();
2448        let handle = unsafe {
2449            ocio_sys::ocio_config_get_processor_from_configs(
2450                src_config.handle.as_ptr(),
2451                src_config.handle.as_ptr(),
2452                src_name.as_ptr().cast(),
2453                dst_config.handle.as_ptr(),
2454                dst_name.as_ptr().cast(),
2455            )
2456        };
2457        Self::processor_handle_result(handle)
2458    }
2459
2460    /// Create a processor between two configs with explicit context objects.
2461    pub fn processor_from_configs_with_contexts(
2462        &self,
2463        src_context: &Context,
2464        src_config: &Config,
2465        src_color_space_name: impl AsRef<str>,
2466        dst_context: &Context,
2467        dst_config: &Config,
2468        dst_color_space_name: impl AsRef<str>,
2469    ) -> Result<Processor> {
2470        let src_color_space_name = cstring(src_color_space_name)?;
2471        let dst_color_space_name = cstring(dst_color_space_name)?;
2472        crate::clear_last_error();
2473        let handle = unsafe {
2474            ocio_sys::ocio_config_get_processor_from_configs_v1(
2475                self.handle.as_ptr(),
2476                src_context.handle.as_ptr(),
2477                src_config.handle.as_ptr(),
2478                src_color_space_name.as_ptr().cast(),
2479                dst_context.handle.as_ptr(),
2480                dst_config.handle.as_ptr(),
2481                dst_color_space_name.as_ptr().cast(),
2482            )
2483        };
2484        Self::processor_handle_result(handle)
2485    }
2486
2487    #[doc(hidden)]
2488    #[deprecated(
2489        since = "0.2.0",
2490        note = "compat alias; prefer processor_from_configs_with_contexts()"
2491    )]
2492    pub fn get_processor_from_configs_v1(
2493        &self,
2494        src_context: &Context,
2495        src_config: &Config,
2496        src_color_space_name: impl AsRef<str>,
2497        dst_context: &Context,
2498        dst_config: &Config,
2499        dst_color_space_name: impl AsRef<str>,
2500    ) -> Result<Processor> {
2501        self.processor_from_configs_with_contexts(
2502            src_context,
2503            src_config,
2504            src_color_space_name,
2505            dst_context,
2506            dst_config,
2507            dst_color_space_name,
2508        )
2509    }
2510
2511    /// Create a processor between two configs using interchange color spaces for matching.
2512    pub fn processor_from_configs_with_interchange(
2513        &self,
2514        src_config: &Config,
2515        src_color_space_name: impl AsRef<str>,
2516        src_interchange_name: impl AsRef<str>,
2517        dst_config: &Config,
2518        dst_color_space_name: impl AsRef<str>,
2519        dst_interchange_name: impl AsRef<str>,
2520    ) -> Result<Processor> {
2521        let src_color_space_name = cstring(src_color_space_name)?;
2522        let src_interchange_name = cstring(src_interchange_name)?;
2523        let dst_color_space_name = cstring(dst_color_space_name)?;
2524        let dst_interchange_name = cstring(dst_interchange_name)?;
2525        crate::clear_last_error();
2526        let handle = unsafe {
2527            ocio_sys::ocio_config_get_processor_from_configs_v2(
2528                self.handle.as_ptr(),
2529                src_config.handle.as_ptr(),
2530                src_color_space_name.as_ptr().cast(),
2531                src_interchange_name.as_ptr().cast(),
2532                dst_config.handle.as_ptr(),
2533                dst_color_space_name.as_ptr().cast(),
2534                dst_interchange_name.as_ptr().cast(),
2535            )
2536        };
2537        Self::processor_handle_result(handle)
2538    }
2539
2540    #[doc(hidden)]
2541    #[deprecated(
2542        since = "0.2.0",
2543        note = "compat alias; prefer processor_from_configs_with_interchange()"
2544    )]
2545    pub fn get_processor_from_configs_v2(
2546        &self,
2547        src_config: &Config,
2548        src_color_space_name: impl AsRef<str>,
2549        src_interchange_name: impl AsRef<str>,
2550        dst_config: &Config,
2551        dst_color_space_name: impl AsRef<str>,
2552        dst_interchange_name: impl AsRef<str>,
2553    ) -> Result<Processor> {
2554        self.processor_from_configs_with_interchange(
2555            src_config,
2556            src_color_space_name,
2557            src_interchange_name,
2558            dst_config,
2559            dst_color_space_name,
2560            dst_interchange_name,
2561        )
2562    }
2563
2564    /// Create a processor between two configs with explicit contexts and interchange spaces.
2565    #[allow(clippy::too_many_arguments)]
2566    pub fn processor_from_configs_with_contexts_and_interchange(
2567        &self,
2568        src_context: &Context,
2569        src_config: &Config,
2570        src_color_space_name: impl AsRef<str>,
2571        src_interchange_name: impl AsRef<str>,
2572        dst_context: &Context,
2573        dst_config: &Config,
2574        dst_color_space_name: impl AsRef<str>,
2575        dst_interchange_name: impl AsRef<str>,
2576    ) -> Result<Processor> {
2577        let src_color_space_name = cstring(src_color_space_name)?;
2578        let src_interchange_name = cstring(src_interchange_name)?;
2579        let dst_color_space_name = cstring(dst_color_space_name)?;
2580        let dst_interchange_name = cstring(dst_interchange_name)?;
2581        crate::clear_last_error();
2582        let handle = unsafe {
2583            ocio_sys::ocio_config_get_processor_from_configs_v3(
2584                self.handle.as_ptr(),
2585                src_context.handle.as_ptr(),
2586                src_config.handle.as_ptr(),
2587                src_color_space_name.as_ptr().cast(),
2588                src_interchange_name.as_ptr().cast(),
2589                dst_context.handle.as_ptr(),
2590                dst_config.handle.as_ptr(),
2591                dst_color_space_name.as_ptr().cast(),
2592                dst_interchange_name.as_ptr().cast(),
2593            )
2594        };
2595        Self::processor_handle_result(handle)
2596    }
2597
2598    #[allow(clippy::too_many_arguments)]
2599    #[doc(hidden)]
2600    #[deprecated(
2601        since = "0.2.0",
2602        note = "compat alias; prefer processor_from_configs_with_contexts_and_interchange()"
2603    )]
2604    pub fn get_processor_from_configs_v3(
2605        &self,
2606        src_context: &Context,
2607        src_config: &Config,
2608        src_color_space_name: impl AsRef<str>,
2609        src_interchange_name: impl AsRef<str>,
2610        dst_context: &Context,
2611        dst_config: &Config,
2612        dst_color_space_name: impl AsRef<str>,
2613        dst_interchange_name: impl AsRef<str>,
2614    ) -> Result<Processor> {
2615        self.processor_from_configs_with_contexts_and_interchange(
2616            src_context,
2617            src_config,
2618            src_color_space_name,
2619            src_interchange_name,
2620            dst_context,
2621            dst_config,
2622            dst_color_space_name,
2623            dst_interchange_name,
2624        )
2625    }
2626
2627    /// Create a processor from a source color space to a destination display/view pair across configs.
2628    pub fn processor_from_configs_to_display(
2629        &self,
2630        src_config: &Config,
2631        src_color_space_name: impl AsRef<str>,
2632        dst_config: &Config,
2633        dst_display: impl AsRef<str>,
2634        dst_view: impl AsRef<str>,
2635        direction: TransformDirection,
2636    ) -> Result<Processor> {
2637        let src_color_space_name = cstring(src_color_space_name)?;
2638        let dst_display = cstring(dst_display)?;
2639        let dst_view = cstring(dst_view)?;
2640        crate::clear_last_error();
2641        let handle = unsafe {
2642            ocio_sys::ocio_config_get_processor_from_configs_v4(
2643                self.handle.as_ptr(),
2644                src_config.handle.as_ptr(),
2645                src_color_space_name.as_ptr().cast(),
2646                dst_config.handle.as_ptr(),
2647                dst_display.as_ptr().cast(),
2648                dst_view.as_ptr().cast(),
2649                direction as i32,
2650            )
2651        };
2652        Self::processor_handle_result(handle)
2653    }
2654
2655    #[doc(hidden)]
2656    #[deprecated(
2657        since = "0.2.0",
2658        note = "compat alias; prefer processor_from_configs_to_display()"
2659    )]
2660    pub fn get_processor_from_configs_v4(
2661        &self,
2662        src_config: &Config,
2663        src_color_space_name: impl AsRef<str>,
2664        dst_config: &Config,
2665        dst_display: impl AsRef<str>,
2666        dst_view: impl AsRef<str>,
2667        direction: TransformDirection,
2668    ) -> Result<Processor> {
2669        self.processor_from_configs_to_display(
2670            src_config,
2671            src_color_space_name,
2672            dst_config,
2673            dst_display,
2674            dst_view,
2675            direction,
2676        )
2677    }
2678
2679    /// Create a processor to a display/view pair with explicit context objects for both configs.
2680    #[allow(clippy::too_many_arguments)]
2681    pub fn processor_from_configs_to_display_with_contexts(
2682        &self,
2683        src_context: &Context,
2684        src_config: &Config,
2685        src_color_space_name: impl AsRef<str>,
2686        dst_context: &Context,
2687        dst_config: &Config,
2688        dst_display: impl AsRef<str>,
2689        dst_view: impl AsRef<str>,
2690        direction: TransformDirection,
2691    ) -> Result<Processor> {
2692        let src_color_space_name = cstring(src_color_space_name)?;
2693        let dst_display = cstring(dst_display)?;
2694        let dst_view = cstring(dst_view)?;
2695        crate::clear_last_error();
2696        let handle = unsafe {
2697            ocio_sys::ocio_config_get_processor_from_configs_v5(
2698                self.handle.as_ptr(),
2699                src_context.handle.as_ptr(),
2700                src_config.handle.as_ptr(),
2701                src_color_space_name.as_ptr().cast(),
2702                dst_context.handle.as_ptr(),
2703                dst_config.handle.as_ptr(),
2704                dst_display.as_ptr().cast(),
2705                dst_view.as_ptr().cast(),
2706                direction as i32,
2707            )
2708        };
2709        Self::processor_handle_result(handle)
2710    }
2711
2712    #[allow(clippy::too_many_arguments)]
2713    #[doc(hidden)]
2714    #[deprecated(
2715        since = "0.2.0",
2716        note = "compat alias; prefer processor_from_configs_to_display_with_contexts()"
2717    )]
2718    pub fn get_processor_from_configs_v5(
2719        &self,
2720        src_context: &Context,
2721        src_config: &Config,
2722        src_color_space_name: impl AsRef<str>,
2723        dst_context: &Context,
2724        dst_config: &Config,
2725        dst_display: impl AsRef<str>,
2726        dst_view: impl AsRef<str>,
2727        direction: TransformDirection,
2728    ) -> Result<Processor> {
2729        self.processor_from_configs_to_display_with_contexts(
2730            src_context,
2731            src_config,
2732            src_color_space_name,
2733            dst_context,
2734            dst_config,
2735            dst_display,
2736            dst_view,
2737            direction,
2738        )
2739    }
2740
2741    /// Create a processor to a display/view pair with interchange spaces for matching.
2742    #[allow(clippy::too_many_arguments)]
2743    pub fn processor_from_configs_to_display_with_interchange(
2744        &self,
2745        src_config: &Config,
2746        src_color_space_name: impl AsRef<str>,
2747        src_interchange_name: impl AsRef<str>,
2748        dst_config: &Config,
2749        dst_display: impl AsRef<str>,
2750        dst_view: impl AsRef<str>,
2751        dst_interchange_name: impl AsRef<str>,
2752        direction: TransformDirection,
2753    ) -> Result<Processor> {
2754        let src_color_space_name = cstring(src_color_space_name)?;
2755        let src_interchange_name = cstring(src_interchange_name)?;
2756        let dst_display = cstring(dst_display)?;
2757        let dst_view = cstring(dst_view)?;
2758        let dst_interchange_name = cstring(dst_interchange_name)?;
2759        crate::clear_last_error();
2760        let handle = unsafe {
2761            ocio_sys::ocio_config_get_processor_from_configs_v6(
2762                self.handle.as_ptr(),
2763                src_config.handle.as_ptr(),
2764                src_color_space_name.as_ptr().cast(),
2765                src_interchange_name.as_ptr().cast(),
2766                dst_config.handle.as_ptr(),
2767                dst_display.as_ptr().cast(),
2768                dst_view.as_ptr().cast(),
2769                dst_interchange_name.as_ptr().cast(),
2770                direction as i32,
2771            )
2772        };
2773        Self::processor_handle_result(handle)
2774    }
2775
2776    #[allow(clippy::too_many_arguments)]
2777    #[doc(hidden)]
2778    #[deprecated(
2779        since = "0.2.0",
2780        note = "compat alias; prefer processor_from_configs_to_display_with_interchange()"
2781    )]
2782    pub fn get_processor_from_configs_v6(
2783        &self,
2784        src_config: &Config,
2785        src_color_space_name: impl AsRef<str>,
2786        src_interchange_name: impl AsRef<str>,
2787        dst_config: &Config,
2788        dst_display: impl AsRef<str>,
2789        dst_view: impl AsRef<str>,
2790        dst_interchange_name: impl AsRef<str>,
2791        direction: TransformDirection,
2792    ) -> Result<Processor> {
2793        self.processor_from_configs_to_display_with_interchange(
2794            src_config,
2795            src_color_space_name,
2796            src_interchange_name,
2797            dst_config,
2798            dst_display,
2799            dst_view,
2800            dst_interchange_name,
2801            direction,
2802        )
2803    }
2804
2805    /// Create a processor to a display/view pair with contexts and interchange spaces.
2806    #[allow(clippy::too_many_arguments)]
2807    pub fn processor_from_configs_to_display_with_contexts_and_interchange(
2808        &self,
2809        src_context: &Context,
2810        src_config: &Config,
2811        src_color_space_name: impl AsRef<str>,
2812        src_interchange_name: impl AsRef<str>,
2813        dst_context: &Context,
2814        dst_config: &Config,
2815        dst_display: impl AsRef<str>,
2816        dst_view: impl AsRef<str>,
2817        dst_interchange_name: impl AsRef<str>,
2818        direction: TransformDirection,
2819    ) -> Result<Processor> {
2820        let src_color_space_name = cstring(src_color_space_name)?;
2821        let src_interchange_name = cstring(src_interchange_name)?;
2822        let dst_display = cstring(dst_display)?;
2823        let dst_view = cstring(dst_view)?;
2824        let dst_interchange_name = cstring(dst_interchange_name)?;
2825        crate::clear_last_error();
2826        let handle = unsafe {
2827            ocio_sys::ocio_config_get_processor_from_configs_v7(
2828                self.handle.as_ptr(),
2829                src_context.handle.as_ptr(),
2830                src_config.handle.as_ptr(),
2831                src_color_space_name.as_ptr().cast(),
2832                src_interchange_name.as_ptr().cast(),
2833                dst_context.handle.as_ptr(),
2834                dst_config.handle.as_ptr(),
2835                dst_display.as_ptr().cast(),
2836                dst_view.as_ptr().cast(),
2837                dst_interchange_name.as_ptr().cast(),
2838                direction as i32,
2839            )
2840        };
2841        Self::processor_handle_result(handle)
2842    }
2843
2844    #[allow(clippy::too_many_arguments)]
2845    #[doc(hidden)]
2846    #[deprecated(
2847        since = "0.2.0",
2848        note = "compat alias; prefer processor_from_configs_to_display_with_contexts_and_interchange()"
2849    )]
2850    pub fn get_processor_from_configs_v7(
2851        &self,
2852        src_context: &Context,
2853        src_config: &Config,
2854        src_color_space_name: impl AsRef<str>,
2855        src_interchange_name: impl AsRef<str>,
2856        dst_context: &Context,
2857        dst_config: &Config,
2858        dst_display: impl AsRef<str>,
2859        dst_view: impl AsRef<str>,
2860        dst_interchange_name: impl AsRef<str>,
2861        direction: TransformDirection,
2862    ) -> Result<Processor> {
2863        self.processor_from_configs_to_display_with_contexts_and_interchange(
2864            src_context,
2865            src_config,
2866            src_color_space_name,
2867            src_interchange_name,
2868            dst_context,
2869            dst_config,
2870            dst_display,
2871            dst_view,
2872            dst_interchange_name,
2873            direction,
2874        )
2875    }
2876
2877    /// Look up an editable copy by name, role, or alias.
2878    ///
2879    /// Register changes to the color-space object with [`Self::try_add_color_space`].
2880    /// Native group-transform copies still share their children, so changes to
2881    /// those shared nodes can affect the config without re-registering it.
2882    pub fn color_space(&self, name: impl AsRef<str>) -> Option<ColorSpace> {
2883        self.try_color_space(name).ok().flatten()
2884    }
2885
2886    /// Look up a shared read-only color space without copying the native object.
2887    pub fn try_const_color_space(
2888        &self,
2889        name: impl AsRef<str>,
2890    ) -> Result<Option<crate::ConstColorSpace>> {
2891        let name = cstring(name)?;
2892        crate::clear_last_error();
2893        let handle = unsafe {
2894            ocio_sys::ocio_config_get_const_color_space(self.handle.as_ptr(), name.as_ptr())
2895        };
2896        crate::ocio_call_status()?;
2897        Ok(NonNull::new(handle).map(|handle| crate::ConstColorSpace { handle }))
2898    }
2899
2900    /// Look up an editable color-space copy, preserving failures. Group
2901    /// transform children may remain shared with the config.
2902    pub fn try_color_space(&self, name: impl AsRef<str>) -> Result<Option<ColorSpace>> {
2903        let n = cstring(name)?;
2904        crate::clear_last_error();
2905        let handle = unsafe {
2906            ocio_sys::ocio_config_get_color_space(self.handle.as_ptr(), n.as_ptr().cast())
2907        };
2908        crate::ocio_call_status()?;
2909        Ok(NonNull::new(handle).map(|h| ColorSpace { handle: h }))
2910    }
2911
2912    #[doc(hidden)]
2913    #[deprecated(since = "0.2.0", note = "compat alias; prefer color_space()")]
2914    pub fn get_color_space(&self, name: impl AsRef<str>) -> Option<ColorSpace> {
2915        self.color_space(name)
2916    }
2917
2918    /// Look up a color space by name, filtered by reference space type (scene, display, or all).
2919    pub fn color_space_by_ref_type(
2920        &self,
2921        name: impl AsRef<str>,
2922        ref_type: SearchReferenceSpaceType,
2923    ) -> Option<ColorSpace> {
2924        let color_space = self.color_space(name)?;
2925        match ref_type {
2926            SearchReferenceSpaceType::All => Some(color_space),
2927            SearchReferenceSpaceType::Scene
2928                if color_space.reference_space_type() == crate::ReferenceSpaceType::Scene =>
2929            {
2930                Some(color_space)
2931            }
2932            SearchReferenceSpaceType::Display
2933                if color_space.reference_space_type() == crate::ReferenceSpaceType::Display =>
2934            {
2935                Some(color_space)
2936            }
2937            _ => None,
2938        }
2939    }
2940
2941    /// Infer a color space from a file path and also return the matched rule index.
2942    pub fn color_space_from_filepath_with_rule_index(
2943        &self,
2944        path: impl AsRef<str>,
2945    ) -> Option<(String, usize)> {
2946        self.try_color_space_from_filepath_with_rule_index(path)
2947            .ok()
2948            .flatten()
2949    }
2950
2951    /// Infer a color space and matching file-rule index while preserving bridge failures.
2952    pub fn try_color_space_from_filepath_with_rule_index(
2953        &self,
2954        path: impl AsRef<str>,
2955    ) -> Result<Option<(String, usize)>> {
2956        let path = cstring(path)?;
2957        let mut rule_index = 0usize;
2958        crate::clear_last_error();
2959        let color_space = unsafe {
2960            cstr_from_mut(
2961                ocio_sys::ocio_config_get_color_space_from_filepath_with_rule_index(
2962                    self.handle.as_ptr(),
2963                    path.as_ptr().cast(),
2964                    &mut rule_index,
2965                ),
2966            )
2967        };
2968        crate::ocio_call_status()?;
2969        Ok(color_space.map(|color_space| (color_space, rule_index)))
2970    }
2971
2972    /// Return the index of the named color space, or -1 if not found or on error.
2973    pub fn color_space_index(&self, name: impl AsRef<str>) -> i32 {
2974        self.try_color_space_index(name).unwrap_or(-1)
2975    }
2976
2977    /// Return a native index, preserving lookup errors separately from -1.
2978    pub fn try_color_space_index(&self, name: impl AsRef<str>) -> Result<i32> {
2979        self.try_color_space_index_cstr(&cstring(name)?)
2980    }
2981
2982    /// Look up an index using an existing native name without allocating it.
2983    pub fn try_color_space_index_cstr(&self, name: &std::ffi::CStr) -> Result<i32> {
2984        crate::clear_last_error();
2985        let index = unsafe {
2986            ocio_sys::ocio_config_get_index_for_color_space(self.handle.as_ptr(), name.as_ptr())
2987        };
2988        crate::ocio_call_status()?;
2989        Ok(index)
2990    }
2991
2992    #[doc(hidden)]
2993    #[deprecated(since = "0.2.0", note = "compat alias; prefer color_space_index()")]
2994    pub fn get_index_for_color_space(&self, name: impl AsRef<str>) -> i32 {
2995        self.color_space_index(name)
2996    }
2997
2998    /// Add a color space to the config; panics on failure.
2999    pub fn add_color_space(&self, cs: &ColorSpace) {
3000        self.try_add_color_space(cs)
3001            .expect("failed to add color space");
3002    }
3003
3004    /// Add a color space to the config, returning an error on failure.
3005    pub fn try_add_color_space(&self, cs: &ColorSpace) -> Result<()> {
3006        crate::clear_last_error();
3007        unsafe {
3008            ocio_sys::ocio_config_add_color_space(
3009                self.handle.as_ptr(),
3010                cs.handle.as_ptr() as *mut c_void,
3011            );
3012        }
3013        crate::ocio_call_status()
3014    }
3015
3016    /// Remove a named color space from the config.
3017    pub fn remove_color_space(&self, name: impl AsRef<str>) -> Result<()> {
3018        let n = cstring(name)?;
3019        crate::clear_last_error();
3020        unsafe {
3021            ocio_sys::ocio_config_remove_color_space(self.handle.as_ptr(), n.as_ptr().cast());
3022        }
3023        crate::ocio_call_status()
3024    }
3025
3026    /// Return whether a named color space is referenced by any other part of the config.
3027    pub fn is_color_space_used(&self, name: impl AsRef<str>) -> bool {
3028        let n = cstring(name);
3029        match n {
3030            Ok(n) => unsafe {
3031                ocio_sys::ocio_config_is_color_space_used(self.handle.as_ptr(), n.as_ptr().cast())
3032            },
3033            Err(_) => false,
3034        }
3035    }
3036
3037    /// Look up an editable `Look` copy by authored name. Group transform
3038    /// children may remain shared with the config.
3039    pub fn look(&self, name: impl AsRef<str>) -> Option<Look> {
3040        self.try_look(name).ok().flatten()
3041    }
3042
3043    /// Copy a `Look` by authored name while preserving bridge failures.
3044    pub fn try_look(&self, name: impl AsRef<str>) -> Result<Option<Look>> {
3045        let n = cstring(name)?;
3046        crate::clear_last_error();
3047        let handle =
3048            unsafe { ocio_sys::ocio_config_get_look(self.handle.as_ptr(), n.as_ptr().cast()) };
3049        crate::ocio_call_status()?;
3050        Ok(NonNull::new(handle).map(|h| Look { handle: h }))
3051    }
3052
3053    #[doc(hidden)]
3054    #[deprecated(since = "0.2.0", note = "compat alias; prefer look()")]
3055    pub fn get_look(&self, name: impl AsRef<str>) -> Option<Look> {
3056        self.look(name)
3057    }
3058
3059    pub fn add_look(&self, look: &Look) {
3060        self.try_add_look(look).expect("failed to add look");
3061    }
3062
3063    pub fn try_add_look(&self, look: &Look) -> Result<()> {
3064        crate::clear_last_error();
3065        unsafe {
3066            ocio_sys::ocio_config_add_look(
3067                self.handle.as_ptr(),
3068                look.handle.as_ptr() as *mut c_void,
3069            );
3070        }
3071        crate::ocio_call_status()
3072    }
3073
3074    // --- Clear collections ---
3075
3076    pub fn clear_color_spaces(&self) {
3077        self.try_clear_color_spaces()
3078            .expect("failed to clear color spaces");
3079    }
3080
3081    /// Clear all color spaces and surface any OCIO validation error.
3082    pub fn try_clear_color_spaces(&self) -> Result<()> {
3083        crate::clear_last_error();
3084        unsafe { ocio_sys::ocio_config_clear_color_spaces(self.handle.as_ptr() as *mut c_void) };
3085        crate::ocio_call_status()
3086    }
3087
3088    pub fn clear_looks(&self) {
3089        self.try_clear_looks().expect("failed to clear looks");
3090    }
3091
3092    /// Clear all looks and surface any OCIO validation error.
3093    pub fn try_clear_looks(&self) -> Result<()> {
3094        crate::clear_last_error();
3095        unsafe { ocio_sys::ocio_config_clear_looks(self.handle.as_ptr() as *mut c_void) };
3096        crate::ocio_call_status()
3097    }
3098
3099    pub fn clear_named_transforms(&self) {
3100        self.try_clear_named_transforms()
3101            .expect("failed to clear named transforms");
3102    }
3103
3104    /// Clear all named transforms and surface any OCIO validation error.
3105    pub fn try_clear_named_transforms(&self) -> Result<()> {
3106        crate::clear_last_error();
3107        unsafe {
3108            ocio_sys::ocio_config_clear_named_transforms(self.handle.as_ptr() as *mut c_void)
3109        };
3110        crate::ocio_call_status()
3111    }
3112
3113    pub fn clear_view_transforms(&self) {
3114        self.try_clear_view_transforms()
3115            .expect("failed to clear view transforms");
3116    }
3117
3118    /// Clear all view transforms and surface any OCIO validation error.
3119    pub fn try_clear_view_transforms(&self) -> Result<()> {
3120        crate::clear_last_error();
3121        unsafe { ocio_sys::ocio_config_clear_view_transforms(self.handle.as_ptr() as *mut c_void) };
3122        crate::ocio_call_status()
3123    }
3124
3125    // --- Display/view management ---
3126
3127    /// Add or replace a display view using a color-space name and looks.
3128    ///
3129    /// `looks` is the OCIO look expression and may be empty. It is not a
3130    /// viewing-rule name; use [`Self::add_display_view_detailed`] when a
3131    /// view transform, viewing rule, or description is needed.
3132    pub fn add_display(
3133        &self,
3134        display: impl AsRef<str>,
3135        view: impl AsRef<str>,
3136        color_space_name: impl AsRef<str>,
3137        looks: impl AsRef<str>,
3138    ) -> Result<()> {
3139        let display = cstring(display)?;
3140        let view = cstring(view)?;
3141        let color_space_name = cstring(color_space_name)?;
3142        let looks = cstring(looks)?;
3143        crate::clear_last_error();
3144        unsafe {
3145            ocio_sys::ocio_config_add_display_view_v1(
3146                self.handle.as_ptr(),
3147                display.as_ptr().cast(),
3148                view.as_ptr().cast(),
3149                color_space_name.as_ptr().cast(),
3150                looks.as_ptr().cast(),
3151            );
3152        }
3153        crate::ocio_call_status()
3154    }
3155
3156    #[doc(hidden)]
3157    #[deprecated(
3158        since = "0.2.0",
3159        note = "compat alias; prefer add_display() for basic display/view wiring"
3160    )]
3161    pub fn add_display_view_v1(
3162        &self,
3163        display: impl AsRef<str>,
3164        view: impl AsRef<str>,
3165        color_space_name: impl AsRef<str>,
3166        looks: impl AsRef<str>,
3167    ) -> Result<()> {
3168        let display = cstring(display)?;
3169        let view = cstring(view)?;
3170        let color_space_name = cstring(color_space_name)?;
3171        let looks = cstring(looks)?;
3172        crate::clear_last_error();
3173        unsafe {
3174            ocio_sys::ocio_config_add_display_view_v1(
3175                self.handle.as_ptr(),
3176                display.as_ptr().cast(),
3177                view.as_ptr().cast(),
3178                color_space_name.as_ptr().cast(),
3179                looks.as_ptr().cast(),
3180            );
3181        }
3182        crate::ocio_call_status()
3183    }
3184
3185    #[allow(clippy::too_many_arguments)]
3186    pub fn add_display_view_detailed(
3187        &self,
3188        display: impl AsRef<str>,
3189        view: impl AsRef<str>,
3190        view_transform_name: impl AsRef<str>,
3191        color_space_name: impl AsRef<str>,
3192        looks: impl AsRef<str>,
3193        rule_name: impl AsRef<str>,
3194        description: impl AsRef<str>,
3195    ) -> Result<()> {
3196        let display = cstring(display)?;
3197        let view = cstring(view)?;
3198        let view_transform_name = cstring(view_transform_name)?;
3199        let color_space_name = cstring(color_space_name)?;
3200        let looks = cstring(looks)?;
3201        let rule_name = cstring(rule_name)?;
3202        let description = cstring(description)?;
3203        crate::clear_last_error();
3204        unsafe {
3205            ocio_sys::ocio_config_add_display_view_v2(
3206                self.handle.as_ptr(),
3207                display.as_ptr().cast(),
3208                view.as_ptr().cast(),
3209                view_transform_name.as_ptr().cast(),
3210                color_space_name.as_ptr().cast(),
3211                looks.as_ptr().cast(),
3212                rule_name.as_ptr().cast(),
3213                description.as_ptr().cast(),
3214            );
3215        }
3216        crate::ocio_call_status()
3217    }
3218
3219    #[allow(clippy::too_many_arguments)]
3220    #[doc(hidden)]
3221    #[deprecated(
3222        since = "0.2.0",
3223        note = "compat alias; prefer add_display_view_detailed()"
3224    )]
3225    pub fn add_display_view_v2(
3226        &self,
3227        display: impl AsRef<str>,
3228        view: impl AsRef<str>,
3229        view_transform_name: impl AsRef<str>,
3230        color_space_name: impl AsRef<str>,
3231        looks: impl AsRef<str>,
3232        rule_name: impl AsRef<str>,
3233        description: impl AsRef<str>,
3234    ) -> Result<()> {
3235        self.add_display_view_detailed(
3236            display,
3237            view,
3238            view_transform_name,
3239            color_space_name,
3240            looks,
3241            rule_name,
3242            description,
3243        )
3244    }
3245
3246    pub fn add_shared_view(
3247        &self,
3248        view: impl AsRef<str>,
3249        view_transform_name: impl AsRef<str>,
3250        color_space_name: impl AsRef<str>,
3251        looks: impl AsRef<str>,
3252        rule_name: impl AsRef<str>,
3253        description: impl AsRef<str>,
3254    ) -> Result<()> {
3255        let view = cstring(view)?;
3256        let view_transform_name = cstring(view_transform_name)?;
3257        let color_space_name = cstring(color_space_name)?;
3258        let looks = cstring(looks)?;
3259        let rule_name = cstring(rule_name)?;
3260        let description = cstring(description)?;
3261        crate::clear_last_error();
3262        unsafe {
3263            ocio_sys::ocio_config_add_shared_view(
3264                self.handle.as_ptr(),
3265                view.as_ptr().cast(),
3266                view_transform_name.as_ptr().cast(),
3267                color_space_name.as_ptr().cast(),
3268                looks.as_ptr().cast(),
3269                rule_name.as_ptr().cast(),
3270                description.as_ptr().cast(),
3271            );
3272        }
3273        crate::ocio_call_status()
3274    }
3275
3276    pub fn remove_shared_view(&self, view: impl AsRef<str>) -> Result<()> {
3277        let view = cstring(view)?;
3278        crate::clear_last_error();
3279        unsafe {
3280            ocio_sys::ocio_config_remove_shared_view(self.handle.as_ptr(), view.as_ptr().cast())
3281        };
3282        crate::ocio_call_status()
3283    }
3284
3285    pub fn clear_shared_views(&self) {
3286        self.try_clear_shared_views()
3287            .expect("failed to clear shared views");
3288    }
3289
3290    /// Clear every shared view and surface any OCIO validation error.
3291    pub fn try_clear_shared_views(&self) -> Result<()> {
3292        crate::clear_last_error();
3293        unsafe { ocio_sys::ocio_config_clear_shared_views(self.handle.as_ptr()) };
3294        crate::ocio_call_status()
3295    }
3296
3297    pub fn remove_view(&self, display: impl AsRef<str>, view: impl AsRef<str>) -> Result<()> {
3298        let display = cstring(display)?;
3299        let view = cstring(view)?;
3300        crate::clear_last_error();
3301        unsafe {
3302            ocio_sys::ocio_config_remove_display_view(
3303                self.handle.as_ptr(),
3304                display.as_ptr().cast(),
3305                view.as_ptr().cast(),
3306            );
3307        }
3308        crate::ocio_call_status()
3309    }
3310
3311    pub fn remove_display_view(
3312        &self,
3313        display: impl AsRef<str>,
3314        view: impl AsRef<str>,
3315    ) -> Result<()> {
3316        self.remove_view(display, view)
3317    }
3318
3319    pub fn add_display_shared_view(
3320        &self,
3321        display: impl AsRef<str>,
3322        shared_view: impl AsRef<str>,
3323    ) -> Result<()> {
3324        let display = cstring(display)?;
3325        let shared_view = cstring(shared_view)?;
3326        crate::clear_last_error();
3327        unsafe {
3328            ocio_sys::ocio_config_add_display_shared_view(
3329                self.handle.as_ptr(),
3330                display.as_ptr().cast(),
3331                shared_view.as_ptr().cast(),
3332            );
3333        }
3334        crate::ocio_call_status()
3335    }
3336
3337    pub fn clear_displays(&self) {
3338        self.try_clear_displays().expect("failed to clear displays");
3339    }
3340
3341    /// Clear every display and surface any OCIO validation error.
3342    pub fn try_clear_displays(&self) -> Result<()> {
3343        crate::clear_last_error();
3344        unsafe { ocio_sys::ocio_config_clear_displays(self.handle.as_ptr()) };
3345        crate::ocio_call_status()
3346    }
3347
3348    #[cfg(feature = "v2_5")]
3349    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
3350    pub fn has_virtual_view(&self, view_name: impl AsRef<str>) -> bool {
3351        let view_name = match cstring(view_name) {
3352            Ok(v) => v,
3353            Err(_) => return false,
3354        };
3355        unsafe {
3356            ocio_sys::ocio_config_has_virtual_view(self.handle.as_ptr(), view_name.as_ptr().cast())
3357        }
3358    }
3359
3360    #[cfg(feature = "v2_5")]
3361    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
3362    pub fn is_virtual_view_shared(&self, view_name: impl AsRef<str>) -> bool {
3363        let view_name = match cstring(view_name) {
3364            Ok(v) => v,
3365            Err(_) => return false,
3366        };
3367        unsafe {
3368            ocio_sys::ocio_config_is_virtual_view_shared(
3369                self.handle.as_ptr(),
3370                view_name.as_ptr().cast(),
3371            )
3372        }
3373    }
3374
3375    pub fn add_virtual_display_view(
3376        &self,
3377        view: impl AsRef<str>,
3378        view_transform_name: impl AsRef<str>,
3379        color_space_name: impl AsRef<str>,
3380        looks: impl AsRef<str>,
3381        rule_name: impl AsRef<str>,
3382        description: impl AsRef<str>,
3383    ) -> Result<()> {
3384        let view = cstring(view)?;
3385        let view_transform_name = cstring(view_transform_name)?;
3386        let color_space_name = cstring(color_space_name)?;
3387        let looks = cstring(looks)?;
3388        let rule_name = cstring(rule_name)?;
3389        let description = cstring(description)?;
3390        crate::clear_last_error();
3391        unsafe {
3392            ocio_sys::ocio_config_add_virtual_display_view(
3393                self.handle.as_ptr(),
3394                view.as_ptr().cast(),
3395                view_transform_name.as_ptr().cast(),
3396                color_space_name.as_ptr().cast(),
3397                looks.as_ptr().cast(),
3398                rule_name.as_ptr().cast(),
3399                description.as_ptr().cast(),
3400            );
3401        }
3402        crate::ocio_call_status()
3403    }
3404
3405    pub fn add_virtual_display_shared_view(&self, shared_view: impl AsRef<str>) -> Result<()> {
3406        let shared_view = cstring(shared_view)?;
3407        crate::clear_last_error();
3408        unsafe {
3409            ocio_sys::ocio_config_add_virtual_display_shared_view(
3410                self.handle.as_ptr(),
3411                shared_view.as_ptr().cast(),
3412            );
3413        }
3414        crate::ocio_call_status()
3415    }
3416
3417    pub fn virtual_display_num_views(&self, reference_space: SearchReferenceSpaceType) -> i32 {
3418        self.try_virtual_display_num_views(reference_space)
3419            .unwrap_or(0)
3420    }
3421
3422    /// Compatibility query: `Scene` means shared and `Display` means display-defined.
3423    /// Prefer [`Self::try_virtual_display_num_views_by_type`].
3424    pub fn try_virtual_display_num_views(
3425        &self,
3426        reference_space: SearchReferenceSpaceType,
3427    ) -> Result<i32> {
3428        self.try_virtual_display_num_views_by_type(legacy_view_type(reference_space, None)?)
3429    }
3430
3431    /// Return the count of shared or display-defined virtual views.
3432    pub fn try_virtual_display_num_views_by_type(&self, view_type: ViewType) -> Result<i32> {
3433        crate::clear_last_error();
3434        let count = unsafe {
3435            ocio_sys::ocio_config_get_virtual_display_num_views(
3436                self.handle.as_ptr(),
3437                view_type as i32,
3438            )
3439        };
3440        crate::ocio_call_status()?;
3441        Ok(count)
3442    }
3443
3444    #[doc(hidden)]
3445    #[deprecated(
3446        since = "0.2.0",
3447        note = "compat alias; prefer virtual_display_num_views()"
3448    )]
3449    pub fn get_virtual_display_num_views(&self, reference_space: SearchReferenceSpaceType) -> i32 {
3450        self.virtual_display_num_views(reference_space)
3451    }
3452
3453    pub fn virtual_display_view(
3454        &self,
3455        reference_space: SearchReferenceSpaceType,
3456        index: i32,
3457    ) -> Option<String> {
3458        self.try_virtual_display_view(reference_space, index)
3459            .ok()
3460            .flatten()
3461    }
3462
3463    /// Compatibility query: `Scene` means shared and `Display` means display-defined.
3464    /// Prefer [`Self::try_virtual_display_view_by_type`].
3465    pub fn try_virtual_display_view(
3466        &self,
3467        reference_space: SearchReferenceSpaceType,
3468        index: i32,
3469    ) -> Result<Option<String>> {
3470        self.try_virtual_display_view_by_type(legacy_view_type(reference_space, None)?, index)
3471    }
3472
3473    /// Return a virtual-display view by its origin and index, or `None` for
3474    /// an empty native result.
3475    pub fn try_virtual_display_view_by_type(
3476        &self,
3477        view_type: ViewType,
3478        index: i32,
3479    ) -> Result<Option<String>> {
3480        crate::clear_last_error();
3481        let view = unsafe {
3482            cstr_from_mut(ocio_sys::ocio_config_get_virtual_display_view(
3483                self.handle.as_ptr(),
3484                view_type as i32,
3485                index,
3486            ))
3487        };
3488        crate::ocio_call_status()?;
3489        Ok(view.filter(|view| !view.is_empty()))
3490    }
3491
3492    #[doc(hidden)]
3493    #[deprecated(since = "0.2.0", note = "compat alias; prefer virtual_display_view()")]
3494    #[cfg(feature = "v2_5")]
3495    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
3496    pub fn get_virtual_display_view(
3497        &self,
3498        reference_space: SearchReferenceSpaceType,
3499        index: i32,
3500    ) -> Option<String> {
3501        self.virtual_display_view(reference_space, index)
3502    }
3503
3504    /// # Safety
3505    /// `first` and `second` must be valid pointers to live `ConfigHandle` values from this ABI.
3506    /// Both are borrowed for the duration of this call and must not be freed here.
3507    #[doc(hidden)]
3508    #[deprecated(
3509        since = "0.2.0",
3510        note = "raw OCIO virtual-view entry point; prefer higher-level virtual display APIs unless you must interoperate with external OCIO ABI objects"
3511    )]
3512    #[cfg(feature = "v2_5")]
3513    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
3514    pub unsafe fn are_virtual_views_equal(
3515        &self,
3516        first: *mut c_void,
3517        second: *mut c_void,
3518        view_name: impl AsRef<str>,
3519    ) -> bool {
3520        let view_name = match cstring(view_name) {
3521            Ok(v) => v,
3522            Err(_) => return false,
3523        };
3524        unsafe {
3525            ocio_sys::ocio_config_are_virtual_views_equal(
3526                self.handle.as_ptr(),
3527                first,
3528                second,
3529                view_name.as_ptr().cast(),
3530            )
3531        }
3532    }
3533
3534    /// Compare a virtual display-view definition in two configs.
3535    ///
3536    /// This is the safe counterpart to OCIO's `Config::AreVirtualViewsEqual`. It compares the
3537    /// strings in the definitions, not the identities of referenced color spaces or transforms.
3538    #[cfg(feature = "v2_5")]
3539    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
3540    pub fn try_are_virtual_views_equal(
3541        first: &Self,
3542        second: &Self,
3543        view_name: impl AsRef<str>,
3544    ) -> Result<bool> {
3545        let view_name = cstring(view_name)?;
3546        crate::clear_last_error();
3547        let equal = unsafe {
3548            ocio_sys::ocio_config_are_virtual_views_equal(
3549                first.handle.as_ptr(),
3550                first.handle.as_ptr(),
3551                second.handle.as_ptr(),
3552                view_name.as_ptr().cast(),
3553            )
3554        };
3555        crate::ocio_call_status()?;
3556        Ok(equal)
3557    }
3558
3559    pub fn virtual_display_view_transform_name(&self, view: impl AsRef<str>) -> Option<String> {
3560        self.try_virtual_display_view_transform_name(view)
3561            .ok()
3562            .flatten()
3563    }
3564
3565    /// Return a virtual display view's transform name, preserving query failures.
3566    pub fn try_virtual_display_view_transform_name(
3567        &self,
3568        view: impl AsRef<str>,
3569    ) -> Result<Option<String>> {
3570        let view = cstring(view)?;
3571        crate::clear_last_error();
3572        let name = unsafe {
3573            cstr_from_mut(
3574                ocio_sys::ocio_config_get_virtual_display_view_transform_name(
3575                    self.handle.as_ptr(),
3576                    view.as_ptr().cast(),
3577                ),
3578            )
3579        };
3580        crate::ocio_call_status()?;
3581        Ok(name)
3582    }
3583
3584    #[doc(hidden)]
3585    #[deprecated(
3586        since = "0.2.0",
3587        note = "compat alias; prefer virtual_display_view_transform_name()"
3588    )]
3589    pub fn get_virtual_display_view_transform_name(&self, view: impl AsRef<str>) -> Option<String> {
3590        self.virtual_display_view_transform_name(view)
3591    }
3592
3593    pub fn virtual_display_view_color_space_name(&self, view: impl AsRef<str>) -> Option<String> {
3594        self.try_virtual_display_view_color_space_name(view)
3595            .ok()
3596            .flatten()
3597    }
3598
3599    /// Return a virtual display view's color-space name, preserving query failures.
3600    pub fn try_virtual_display_view_color_space_name(
3601        &self,
3602        view: impl AsRef<str>,
3603    ) -> Result<Option<String>> {
3604        let view = cstring(view)?;
3605        crate::clear_last_error();
3606        let name = unsafe {
3607            cstr_from_mut(
3608                ocio_sys::ocio_config_get_virtual_display_view_color_space_name(
3609                    self.handle.as_ptr(),
3610                    view.as_ptr().cast(),
3611                ),
3612            )
3613        };
3614        crate::ocio_call_status()?;
3615        Ok(name)
3616    }
3617
3618    #[doc(hidden)]
3619    #[deprecated(
3620        since = "0.2.0",
3621        note = "compat alias; prefer virtual_display_view_color_space_name()"
3622    )]
3623    pub fn get_virtual_display_view_color_space_name(
3624        &self,
3625        view: impl AsRef<str>,
3626    ) -> Option<String> {
3627        self.virtual_display_view_color_space_name(view)
3628    }
3629
3630    pub fn virtual_display_view_looks(&self, view: impl AsRef<str>) -> Option<String> {
3631        self.try_virtual_display_view_looks(view).ok().flatten()
3632    }
3633
3634    /// Return a virtual display view's looks string, preserving query failures.
3635    pub fn try_virtual_display_view_looks(&self, view: impl AsRef<str>) -> Result<Option<String>> {
3636        let view = cstring(view)?;
3637        crate::clear_last_error();
3638        let looks = unsafe {
3639            cstr_from_mut(ocio_sys::ocio_config_get_virtual_display_view_looks(
3640                self.handle.as_ptr(),
3641                view.as_ptr().cast(),
3642            ))
3643        };
3644        crate::ocio_call_status()?;
3645        Ok(looks)
3646    }
3647
3648    #[doc(hidden)]
3649    #[deprecated(
3650        since = "0.2.0",
3651        note = "compat alias; prefer virtual_display_view_looks()"
3652    )]
3653    pub fn get_virtual_display_view_looks(&self, view: impl AsRef<str>) -> Option<String> {
3654        self.virtual_display_view_looks(view)
3655    }
3656
3657    pub fn virtual_display_view_rule(&self, view: impl AsRef<str>) -> Option<String> {
3658        self.try_virtual_display_view_rule(view).ok().flatten()
3659    }
3660
3661    /// Return a virtual display view's viewing rule, preserving query failures.
3662    pub fn try_virtual_display_view_rule(&self, view: impl AsRef<str>) -> Result<Option<String>> {
3663        let view = cstring(view)?;
3664        crate::clear_last_error();
3665        let rule = unsafe {
3666            cstr_from_mut(ocio_sys::ocio_config_get_virtual_display_view_rule(
3667                self.handle.as_ptr(),
3668                view.as_ptr().cast(),
3669            ))
3670        };
3671        crate::ocio_call_status()?;
3672        Ok(rule)
3673    }
3674
3675    #[doc(hidden)]
3676    #[deprecated(
3677        since = "0.2.0",
3678        note = "compat alias; prefer virtual_display_view_rule()"
3679    )]
3680    pub fn get_virtual_display_view_rule(&self, view: impl AsRef<str>) -> Option<String> {
3681        self.virtual_display_view_rule(view)
3682    }
3683
3684    pub fn virtual_display_view_description(&self, view: impl AsRef<str>) -> Option<String> {
3685        self.try_virtual_display_view_description(view)
3686            .ok()
3687            .flatten()
3688    }
3689
3690    /// Return a virtual display view's description, preserving query failures.
3691    pub fn try_virtual_display_view_description(
3692        &self,
3693        view: impl AsRef<str>,
3694    ) -> Result<Option<String>> {
3695        let view = cstring(view)?;
3696        crate::clear_last_error();
3697        let description = unsafe {
3698            cstr_from_mut(ocio_sys::ocio_config_get_virtual_display_view_description(
3699                self.handle.as_ptr(),
3700                view.as_ptr().cast(),
3701            ))
3702        };
3703        crate::ocio_call_status()?;
3704        Ok(description)
3705    }
3706
3707    #[doc(hidden)]
3708    #[deprecated(
3709        since = "0.2.0",
3710        note = "compat alias; prefer virtual_display_view_description()"
3711    )]
3712    pub fn get_virtual_display_view_description(&self, view: impl AsRef<str>) -> Option<String> {
3713        self.virtual_display_view_description(view)
3714    }
3715
3716    pub fn remove_virtual_display_view(&self, view: impl AsRef<str>) -> Result<()> {
3717        let view = cstring(view)?;
3718        crate::clear_last_error();
3719        unsafe {
3720            ocio_sys::ocio_config_remove_virtual_display_view(
3721                self.handle.as_ptr(),
3722                view.as_ptr().cast(),
3723            );
3724        }
3725        crate::ocio_call_status()
3726    }
3727
3728    pub fn clear_virtual_display(&self) {
3729        self.try_clear_virtual_display()
3730            .expect("failed to clear virtual display");
3731    }
3732
3733    /// Clear all virtual-display views and surface any OCIO validation error.
3734    pub fn try_clear_virtual_display(&self) -> Result<()> {
3735        crate::clear_last_error();
3736        unsafe { ocio_sys::ocio_config_clear_virtual_display(self.handle.as_ptr()) };
3737        crate::ocio_call_status()
3738    }
3739
3740    pub fn instantiate_display_from_monitor_name(&self, monitor_name: impl AsRef<str>) -> i32 {
3741        self.try_instantiate_display_from_monitor_name(monitor_name)
3742            .unwrap_or(-1)
3743    }
3744
3745    /// Instantiate a display using a system monitor name, preserving OCIO failures.
3746    pub fn try_instantiate_display_from_monitor_name(
3747        &self,
3748        monitor_name: impl AsRef<str>,
3749    ) -> Result<i32> {
3750        let monitor_name = cstring(monitor_name)?;
3751        crate::clear_last_error();
3752        let index = unsafe {
3753            ocio_sys::ocio_config_instantiate_display_from_monitor_name(
3754                self.handle.as_ptr(),
3755                monitor_name.as_ptr().cast(),
3756            )
3757        };
3758        crate::ocio_call_status()?;
3759        Ok(index)
3760    }
3761
3762    pub fn instantiate_display_from_icc_profile(
3763        &self,
3764        icc_profile_filepath: impl AsRef<str>,
3765    ) -> i32 {
3766        self.try_instantiate_display_from_icc_profile(icc_profile_filepath)
3767            .unwrap_or(-1)
3768    }
3769
3770    /// Instantiate a display using an ICC profile, preserving OCIO failures.
3771    ///
3772    /// OCIO requires a virtual-display definition in the config for this
3773    /// operation. Missing or invalid definitions are returned as an error.
3774    pub fn try_instantiate_display_from_icc_profile(
3775        &self,
3776        icc_profile_filepath: impl AsRef<str>,
3777    ) -> Result<i32> {
3778        let icc_profile_filepath = cstring(icc_profile_filepath)?;
3779        crate::clear_last_error();
3780        let index = unsafe {
3781            ocio_sys::ocio_config_instantiate_display_from_icc_profile(
3782                self.handle.as_ptr(),
3783                icc_profile_filepath.as_ptr().cast(),
3784            )
3785        };
3786        crate::ocio_call_status()?;
3787        Ok(index)
3788    }
3789
3790    // --- Named transforms ---
3791
3792    /// Return the number of active named transforms in the config.
3793    pub fn num_named_transforms(&self) -> i32 {
3794        unsafe {
3795            ocio_sys::ocio_config_get_num_named_transforms_v1(self.handle.as_ptr() as *mut c_void)
3796        }
3797    }
3798
3799    /// Count named transforms matching OCIO's visibility filter.
3800    pub fn try_num_named_transforms_filtered(
3801        &self,
3802        visibility: NamedTransformVisibility,
3803    ) -> Result<i32> {
3804        crate::clear_last_error();
3805        let count = unsafe {
3806            ocio_sys::ocio_config_get_num_named_transforms(self.handle.as_ptr(), visibility as i32)
3807        };
3808        crate::ocio_call_status()?;
3809        Ok(count)
3810    }
3811
3812    /// Return a filtered named-transform name, or `None` for an invalid index.
3813    pub fn try_named_transform_name_by_index_filtered(
3814        &self,
3815        visibility: NamedTransformVisibility,
3816        index: i32,
3817    ) -> Result<Option<String>> {
3818        crate::clear_last_error();
3819        let name = unsafe {
3820            cstr_from_mut(ocio_sys::ocio_config_get_named_transform_name_by_index(
3821                self.handle.as_ptr(),
3822                visibility as i32,
3823                index,
3824            ))
3825        };
3826        crate::ocio_call_status()?;
3827        Ok(name.filter(|name| !name.is_empty()))
3828    }
3829
3830    #[doc(hidden)]
3831    #[deprecated(since = "0.2.0", note = "compat alias; prefer num_named_transforms()")]
3832    pub fn get_num_named_transforms_v1(&self) -> i32 {
3833        self.num_named_transforms()
3834    }
3835
3836    /// Return the active named-transform name at `index`, or `None` if absent.
3837    pub fn named_transform_name_by_index(&self, index: i32) -> Option<String> {
3838        unsafe {
3839            cstr_from_mut(ocio_sys::ocio_config_get_named_transform_name_by_index_v1(
3840                self.handle.as_ptr(),
3841                index,
3842            ))
3843        }
3844        .filter(|name| !name.is_empty())
3845    }
3846
3847    #[doc(hidden)]
3848    #[deprecated(
3849        since = "0.2.0",
3850        note = "compat alias; prefer named_transform_name_by_index()"
3851    )]
3852    pub fn get_named_transform_name_by_index_v1(&self, index: i32) -> Option<String> {
3853        self.named_transform_name_by_index(index)
3854    }
3855
3856    /// Look up an editable `NamedTransform` copy by name. Group transform
3857    /// children may remain shared with the config.
3858    pub fn named_transform(&self, name: impl AsRef<str>) -> Option<NamedTransform> {
3859        self.try_named_transform(name).ok().flatten()
3860    }
3861
3862    /// Copy a `NamedTransform` by name while preserving bridge failures.
3863    pub fn try_named_transform(&self, name: impl AsRef<str>) -> Result<Option<NamedTransform>> {
3864        let n = cstring(name)?;
3865        crate::clear_last_error();
3866        let handle = unsafe {
3867            ocio_sys::ocio_config_get_named_transform(self.handle.as_ptr(), n.as_ptr().cast())
3868        };
3869        crate::ocio_call_status()?;
3870        Ok(NonNull::new(handle).map(|h| NamedTransform { handle: h }))
3871    }
3872
3873    #[doc(hidden)]
3874    #[deprecated(since = "0.2.0", note = "compat alias; prefer named_transform()")]
3875    pub fn get_named_transform(&self, name: impl AsRef<str>) -> Option<NamedTransform> {
3876        self.named_transform(name)
3877    }
3878
3879    /// Return the index of a named transform, or -1 if not found or on error.
3880    pub fn named_transform_index(&self, name: impl AsRef<str>) -> i32 {
3881        self.try_named_transform_index(name).unwrap_or(-1)
3882    }
3883
3884    /// Return a native index, preserving invalid input and bridge errors separately from -1.
3885    pub fn try_named_transform_index(&self, name: impl AsRef<str>) -> Result<i32> {
3886        self.try_named_transform_index_cstr(&cstring(name)?)
3887    }
3888
3889    /// Look up a named-transform index using an existing native name.
3890    pub fn try_named_transform_index_cstr(&self, name: &std::ffi::CStr) -> Result<i32> {
3891        crate::clear_last_error();
3892        let index = unsafe {
3893            ocio_sys::ocio_config_get_index_for_named_transform(self.handle.as_ptr(), name.as_ptr())
3894        };
3895        crate::ocio_call_status()?;
3896        Ok(index)
3897    }
3898
3899    #[doc(hidden)]
3900    #[deprecated(since = "0.2.0", note = "compat alias; prefer named_transform_index()")]
3901    pub fn get_index_for_named_transform(&self, name: impl AsRef<str>) -> i32 {
3902        self.named_transform_index(name)
3903    }
3904
3905    /// Add a named transform to the config; panics on failure.
3906    pub fn add_named_transform(&self, named_transform: &NamedTransform) {
3907        self.try_add_named_transform(named_transform)
3908            .expect("failed to add named transform");
3909    }
3910
3911    /// Add a named transform to the config, returning an error on failure.
3912    pub fn try_add_named_transform(&self, named_transform: &NamedTransform) -> Result<()> {
3913        crate::clear_last_error();
3914        unsafe {
3915            ocio_sys::ocio_config_add_named_transform(
3916                self.handle.as_ptr(),
3917                named_transform.handle.as_ptr() as *mut c_void,
3918            );
3919        }
3920        crate::ocio_call_status()
3921    }
3922
3923    /// Remove a named transform by name.
3924    #[cfg(feature = "v2_5")]
3925    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
3926    pub fn remove_named_transform(&self, name: impl AsRef<str>) -> Result<()> {
3927        let n = cstring(name)?;
3928        crate::clear_last_error();
3929        unsafe {
3930            ocio_sys::ocio_config_remove_named_transform(self.handle.as_ptr(), n.as_ptr().cast());
3931        }
3932        crate::ocio_call_status()
3933    }
3934
3935    // --- View transforms ---
3936
3937    /// Return the total number of view transforms in the config.
3938    pub fn num_view_transforms(&self) -> i32 {
3939        unsafe {
3940            ocio_sys::ocio_config_get_num_view_transforms(self.handle.as_ptr() as *mut c_void)
3941        }
3942    }
3943
3944    /// Return the view-transform name at `index`, or `None` if absent.
3945    pub fn view_transform_name_by_index(&self, index: i32) -> Option<String> {
3946        unsafe {
3947            cstr_from_mut(ocio_sys::ocio_config_get_view_transform_name_by_index(
3948                self.handle.as_ptr(),
3949                index,
3950            ))
3951        }
3952        .filter(|name| !name.is_empty())
3953    }
3954
3955    /// Look up an editable `ViewTransform` copy by name. Group transform
3956    /// children may remain shared with the config.
3957    pub fn view_transform(&self, name: impl AsRef<str>) -> Option<ViewTransform> {
3958        self.try_view_transform(name).ok().flatten()
3959    }
3960
3961    /// Copy a `ViewTransform` by name while preserving bridge failures.
3962    pub fn try_view_transform(&self, name: impl AsRef<str>) -> Result<Option<ViewTransform>> {
3963        let n = cstring(name)?;
3964        crate::clear_last_error();
3965        let handle = unsafe {
3966            ocio_sys::ocio_config_get_view_transform(self.handle.as_ptr(), n.as_ptr().cast())
3967        };
3968        crate::ocio_call_status()?;
3969        Ok(NonNull::new(handle).map(|h| ViewTransform { handle: h }))
3970    }
3971
3972    #[doc(hidden)]
3973    #[deprecated(since = "0.2.0", note = "compat alias; prefer view_transform()")]
3974    pub fn get_view_transform(&self, name: impl AsRef<str>) -> Option<ViewTransform> {
3975        self.view_transform(name)
3976    }
3977
3978    /// Add a view transform to the config; panics on failure.
3979    pub fn add_view_transform(&self, view_transform: &ViewTransform) {
3980        self.try_add_view_transform(view_transform)
3981            .expect("failed to add view transform");
3982    }
3983
3984    /// Add a view transform to the config, returning an error on failure.
3985    pub fn try_add_view_transform(&self, view_transform: &ViewTransform) -> Result<()> {
3986        crate::clear_last_error();
3987        unsafe {
3988            ocio_sys::ocio_config_add_view_transform(
3989                self.handle.as_ptr(),
3990                view_transform.handle.as_ptr() as *mut c_void,
3991            );
3992        }
3993        crate::ocio_call_status()
3994    }
3995
3996    // --- Search paths ---
3997
3998    /// Return the serialized search-path string used for file resolution.
3999    pub fn search_path(&self) -> Option<String> {
4000        unsafe {
4001            cstr_from_mut(ocio_sys::ocio_config_get_search_path(
4002                self.handle.as_ptr() as *mut c_void
4003            ))
4004        }
4005    }
4006
4007    /// Replace the config search-path list from a serialized search-path string.
4008    pub fn set_search_path(&self, path: impl AsRef<str>) -> Result<()> {
4009        let p = cstring(path)?;
4010        crate::clear_last_error();
4011        unsafe { ocio_sys::ocio_config_set_search_path(self.handle.as_ptr(), p.as_ptr().cast()) };
4012        crate::ocio_call_status()
4013    }
4014
4015    /// Return the number of individual search-path entries.
4016    pub fn num_search_paths(&self) -> i32 {
4017        unsafe { ocio_sys::ocio_config_get_num_search_paths(self.handle.as_ptr() as *mut c_void) }
4018    }
4019
4020    /// Return the search-path string at a given index.
4021    pub fn search_path_by_index(&self, index: i32) -> Option<String> {
4022        unsafe {
4023            cstr_from_mut(ocio_sys::ocio_config_get_search_path_by_index(
4024                self.handle.as_ptr(),
4025                index,
4026            ))
4027        }
4028    }
4029
4030    /// Remove all configured search-path entries.
4031    #[deprecated(
4032        since = "0.2.0",
4033        note = "discarded OCIO errors; prefer try_clear_search_paths()"
4034    )]
4035    pub fn clear_search_paths(&self) {
4036        let _ = self.try_clear_search_paths();
4037    }
4038
4039    /// Try to remove all configured search-path entries.
4040    pub fn try_clear_search_paths(&self) -> Result<()> {
4041        crate::clear_last_error();
4042        unsafe { ocio_sys::ocio_config_clear_search_paths(self.handle.as_ptr() as *mut c_void) };
4043        crate::ocio_call_status()
4044    }
4045
4046    /// Append one search-path entry to the config.
4047    pub fn add_search_path(&self, path: impl AsRef<str>) -> Result<()> {
4048        let p = cstring(path)?;
4049        crate::clear_last_error();
4050        unsafe { ocio_sys::ocio_config_add_search_path(self.handle.as_ptr(), p.as_ptr().cast()) };
4051        crate::ocio_call_status()
4052    }
4053
4054    // --- Strict parsing ---
4055
4056    pub fn is_strict_parsing_enabled(&self) -> bool {
4057        unsafe {
4058            ocio_sys::ocio_config_is_strict_parsing_enabled(self.handle.as_ptr() as *mut c_void)
4059        }
4060    }
4061
4062    pub fn set_strict_parsing_enabled(&self, enabled: bool) {
4063        self.try_set_strict_parsing_enabled(enabled)
4064            .expect("failed to set strict parsing enabled");
4065    }
4066
4067    /// Enable or disable strict parsing and surface any OCIO validation error.
4068    pub fn try_set_strict_parsing_enabled(&self, enabled: bool) -> Result<()> {
4069        crate::clear_last_error();
4070        unsafe { ocio_sys::ocio_config_set_strict_parsing_enabled(self.handle.as_ptr(), enabled) };
4071        crate::ocio_call_status()
4072    }
4073
4074    // --- Roles (mutable) ---
4075
4076    pub fn set_role(&self, role: impl AsRef<str>, color_space: impl AsRef<str>) -> Result<()> {
4077        let r = cstring(role)?;
4078        let cs = cstring(color_space)?;
4079        self.set_role_cstr(&r, Some(&cs))
4080    }
4081
4082    /// Remove an authored role using OCIO's null color-space argument.
4083    pub fn remove_role(&self, role: impl AsRef<str>) -> Result<()> {
4084        self.set_role_cstr(&cstring(role)?, None)
4085    }
4086
4087    fn set_role_cstr(&self, role: &CStr, color_space: Option<&CStr>) -> Result<()> {
4088        crate::clear_last_error();
4089        unsafe {
4090            ocio_sys::ocio_config_set_role(
4091                self.handle.as_ptr(),
4092                role.as_ptr().cast(),
4093                color_space.map_or(std::ptr::null(), |value| value.as_ptr().cast()),
4094            );
4095        }
4096        crate::ocio_call_status()
4097    }
4098
4099    // --- Family separator ---
4100
4101    pub fn set_family_separator(&self, separator: char) {
4102        self.try_set_family_separator(separator)
4103            .expect("failed to set family separator");
4104    }
4105
4106    /// Set the family separator character and surface any OCIO validation error.
4107    pub fn try_set_family_separator(&self, separator: char) -> Result<()> {
4108        if separator != '\0' && !(' '..='~').contains(&separator) {
4109            return Err(OcioError::InvalidInput(
4110                "family separator must be printable ASCII or NUL".into(),
4111            ));
4112        }
4113        crate::clear_last_error();
4114        unsafe {
4115            ocio_sys::ocio_config_set_family_separator(self.handle.as_ptr(), separator as i8);
4116        }
4117        crate::ocio_call_status()
4118    }
4119
4120    // --- Validate ---
4121
4122    /// Ask OCIO to validate the config in its current authored state.
4123    pub fn validate(&self) -> Result<()> {
4124        crate::clear_last_error();
4125        unsafe { ocio_sys::ocio_config_validate(self.handle.as_ptr()) };
4126        crate::validation_status()
4127    }
4128
4129    // --- Serialize ---
4130
4131    /// Serialize the config to OCIO YAML text.
4132    ///
4133    /// Returns `Ok(None)` in stub builds where no real OCIO serializer is linked.
4134    pub fn serialize(&self) -> Result<Option<String>> {
4135        self.serialize_to_string()
4136    }
4137
4138    /// Serialize the config to OCIO YAML text.
4139    ///
4140    /// Returns `Ok(None)` in stub builds where no real OCIO serializer is linked.
4141    ///
4142    /// Returns an error when OCIO cannot serialize this config.
4143    pub fn serialize_to_string(&self) -> Result<Option<String>> {
4144        crate::clear_last_error();
4145        let text = unsafe {
4146            cstr_from_mut(ocio_sys::ocio_config_serialize_to_string(
4147                self.handle.as_ptr(),
4148            ))
4149        };
4150        crate::ocio_call_status()?;
4151        Ok(text)
4152    }
4153
4154    // --- Editable copy ---
4155
4156    /// Create an editable config copy using OCIO's native semantics.
4157    ///
4158    /// Config fields are copied, but group transforms inside color spaces,
4159    /// looks, named transforms and view transforms may retain shared children.
4160    /// Mutating shared transforms can affect both configs. Coordinate such
4161    /// mutations and clear affected processor caches before rebuilding processors;
4162    /// already-created processors do not automatically adopt the changes.
4163    pub fn create_editable_copy(&self) -> Result<Self> {
4164        crate::clear_last_error();
4165        let handle = unsafe {
4166            ocio_sys::ocio_config_create_editable_copy(self.handle.as_ptr() as *mut c_void)
4167        };
4168        crate::handle_result(handle).map(|handle| Self { handle })
4169    }
4170
4171    // --- Context ---
4172
4173    /// Return the current context associated with this config, if available.
4174    ///
4175    /// This compatibility helper returns `None` both when no context is
4176    /// available and when OCIO reports an error. Use [`Self::try_current_context`]
4177    /// when those cases must be distinguished.
4178    pub fn current_context(&self) -> Option<Context> {
4179        self.try_current_context().ok().flatten()
4180    }
4181
4182    /// Try to get the current context associated with this config.
4183    ///
4184    /// Returns an independent editable copy; edits do not change the config.
4185    pub fn try_current_context(&self) -> Result<Option<Context>> {
4186        crate::clear_last_error();
4187        let handle = unsafe {
4188            ocio_sys::ocio_config_get_current_context(self.handle.as_ptr() as *mut c_void)
4189        };
4190        crate::ocio_call_status()?;
4191        Ok(NonNull::new(handle).map(|handle| Context { handle }))
4192    }
4193
4194    /// Share the config's current native context without an editable copy.
4195    pub fn try_const_current_context(&self) -> Result<Option<crate::ConstContext>> {
4196        crate::clear_last_error();
4197        let handle =
4198            unsafe { ocio_sys::ocio_config_get_const_current_context(self.handle.as_ptr()) };
4199        crate::ocio_call_status()?;
4200        Ok(NonNull::new(handle).map(|handle| crate::ConstContext { handle }))
4201    }
4202
4203    // --- Clear all ---
4204
4205    pub fn clear_all(&self) {
4206        self.try_clear_all()
4207            .expect("failed to clear all config collections");
4208    }
4209
4210    /// Clear all config collections and surface any OCIO validation error.
4211    ///
4212    pub fn try_clear_all(&self) -> Result<()> {
4213        self.try_clear_color_spaces()?;
4214        self.try_clear_looks()?;
4215        self.try_clear_named_transforms()?;
4216        self.try_clear_view_transforms()?;
4217        self.try_clear_shared_views()?;
4218        self.try_clear_displays()?;
4219        self.set_active_displays("")?;
4220        self.set_active_views("")?;
4221        Ok(())
4222    }
4223
4224    // --- Version setters ---
4225
4226    /// Set the authored config major version.
4227    ///
4228    /// OCIO validates that the requested major version is supported and will
4229    /// update the minor version to the newest supported value for that major.
4230    pub fn set_major_version(&self, version: u32) -> Result<()> {
4231        crate::clear_last_error();
4232        unsafe { ocio_sys::ocio_config_set_major_version(self.handle.as_ptr(), version) };
4233        crate::ocio_call_status()
4234    }
4235
4236    /// Set the authored config minor version for the current major version.
4237    ///
4238    /// OCIO rejects minor versions that are unsupported for the current major.
4239    pub fn set_minor_version(&self, version: u32) -> Result<()> {
4240        crate::clear_last_error();
4241        unsafe { ocio_sys::ocio_config_set_minor_version(self.handle.as_ptr(), version) };
4242        crate::ocio_call_status()
4243    }
4244
4245    // --- Working directory ---
4246
4247    /// Return the config's working directory.
4248    pub fn working_dir(&self) -> Option<String> {
4249        unsafe {
4250            cstr_from_mut(ocio_sys::ocio_config_get_working_dir(
4251                self.handle.as_ptr() as *mut c_void
4252            ))
4253        }
4254    }
4255
4256    /// Set the config's working directory.
4257    pub fn set_working_dir(&self, dir_name: impl AsRef<str>) -> Result<()> {
4258        let d = cstring(dir_name)?;
4259        crate::clear_last_error();
4260        unsafe { ocio_sys::ocio_config_set_working_dir(self.handle.as_ptr(), d.as_ptr().cast()) };
4261        crate::ocio_call_status()
4262    }
4263
4264    // --- ColorSpaceSet ---
4265
4266    /// Return active color spaces filtered by an optional category.
4267    pub fn color_space_set<S: AsRef<str>>(&self, search: Option<S>) -> Result<ColorSpaceSet> {
4268        crate::clear_last_error();
4269        let handle = match search {
4270            Some(ref s) => {
4271                let s = cstring(s.as_ref())?;
4272                unsafe {
4273                    ocio_sys::ocio_config_get_color_spaces(self.handle.as_ptr(), s.as_ptr().cast())
4274                }
4275            }
4276            None => unsafe {
4277                ocio_sys::ocio_config_get_color_spaces(self.handle.as_ptr(), std::ptr::null())
4278            },
4279        };
4280        crate::handle_result(handle).map(|handle| ColorSpaceSet { handle })
4281    }
4282
4283    // --- FileRules ---
4284
4285    /// Return an independent editable copy of the config's file rules.
4286    pub fn file_rules(&self) -> Result<FileRules> {
4287        crate::clear_last_error();
4288        let handle =
4289            unsafe { ocio_sys::ocio_config_get_file_rules(self.handle.as_ptr() as *mut c_void) };
4290        crate::handle_result(handle).map(|handle| FileRules { handle })
4291    }
4292
4293    /// Attach a file-rules object to this config.
4294    pub fn set_file_rules(&self, file_rules: &FileRules) -> Result<()> {
4295        crate::clear_last_error();
4296        unsafe {
4297            ocio_sys::ocio_config_set_file_rules(
4298                self.handle.as_ptr(),
4299                file_rules.handle.as_ptr() as *mut c_void,
4300            );
4301        }
4302        crate::ocio_call_status()
4303    }
4304
4305    // --- Environment mode ---
4306
4307    /// Select whether OCIO imports only declared variables or the full process environment.
4308    pub fn set_environment_mode(&self, mode: crate::EnvironmentMode) -> Result<()> {
4309        crate::clear_last_error();
4310        unsafe {
4311            ocio_sys::ocio_config_set_environment_mode(self.handle.as_ptr(), mode as i32);
4312        }
4313        crate::ocio_call_status()
4314    }
4315
4316    /// Return the current environment mode, or `Unknown` if the query fails.
4317    pub fn environment_mode(&self) -> crate::EnvironmentMode {
4318        self.try_environment_mode()
4319            .unwrap_or(crate::EnvironmentMode::Unknown)
4320    }
4321
4322    /// Return the native mode, preserving errors and unrecognized values.
4323    pub fn try_environment_mode(&self) -> Result<crate::EnvironmentMode> {
4324        crate::clear_last_error();
4325        let mode = unsafe { ocio_sys::ocio_config_get_environment_mode(self.handle.as_ptr()) };
4326        crate::ocio_call_status()?;
4327        crate::context::environment_mode_from_raw(mode)
4328    }
4329
4330    /// Refresh this config's context variables from the process environment.
4331    pub fn load_environment(&self) -> Result<()> {
4332        crate::clear_last_error();
4333        unsafe { ocio_sys::ocio_config_load_environment(self.handle.as_ptr() as *mut c_void) };
4334        crate::ocio_call_status()
4335    }
4336
4337    // --- Inactive color spaces ---
4338
4339    /// Return the comma-separated list of inactive color-space names.
4340    pub fn inactive_color_spaces(&self) -> Option<String> {
4341        unsafe {
4342            cstr_from_mut(ocio_sys::ocio_config_get_inactive_color_spaces(
4343                self.handle.as_ptr() as *mut c_void,
4344            ))
4345        }
4346    }
4347
4348    /// Set the comma-separated list of inactive color-space names.
4349    pub fn set_inactive_color_spaces(&self, inactive: impl AsRef<str>) -> Result<()> {
4350        let s = cstring(inactive)?;
4351        crate::clear_last_error();
4352        unsafe {
4353            ocio_sys::ocio_config_set_inactive_color_spaces(
4354                self.handle.as_ptr(),
4355                s.as_ptr().cast(),
4356            );
4357        }
4358        crate::ocio_call_status()
4359    }
4360
4361    /// Test whether a given color space name is in the inactive set.
4362    pub fn is_inactive_color_space(&self, color_space: impl AsRef<str>) -> bool {
4363        let color_space = match cstring(color_space) {
4364            Ok(v) => v,
4365            Err(_) => return false,
4366        };
4367        unsafe {
4368            ocio_sys::ocio_config_is_inactive_color_space(
4369                self.handle.as_ptr(),
4370                color_space.as_ptr().cast(),
4371            )
4372        }
4373    }
4374
4375    // --- Archivable ---
4376
4377    /// Return whether the config can be serialized as an OCIO archive.
4378    pub fn is_archivable(&self) -> bool {
4379        unsafe { ocio_sys::ocio_config_is_archivable(self.handle.as_ptr() as *mut c_void) }
4380    }
4381
4382    // --- Processor cache ---
4383
4384    #[deprecated(
4385        since = "0.2.0",
4386        note = "discarded OCIO errors; prefer try_clear_processor_cache()"
4387    )]
4388    pub fn clear_processor_cache(&self) {
4389        let _ = self.try_clear_processor_cache();
4390    }
4391
4392    /// Try to invalidate this config's processor cache.
4393    pub fn try_clear_processor_cache(&self) -> Result<()> {
4394        crate::clear_last_error();
4395        unsafe { ocio_sys::ocio_config_clear_processor_cache(self.handle.as_ptr() as *mut c_void) };
4396        crate::ocio_call_status()
4397    }
4398
4399    // --- v2.5.1: Environment variables ---
4400
4401    /// Add an environment-variable declaration with a name and default value.
4402    pub fn add_environment_var(
4403        &self,
4404        name: impl AsRef<str>,
4405        default_val: impl AsRef<str>,
4406    ) -> Result<()> {
4407        let n = cstring(name)?;
4408        let v = cstring(default_val)?;
4409        crate::clear_last_error();
4410        unsafe {
4411            ocio_sys::ocio_config_add_environment_var(
4412                self.handle.as_ptr(),
4413                n.as_ptr().cast(),
4414                v.as_ptr().cast(),
4415            )
4416        };
4417        crate::ocio_call_status()
4418    }
4419
4420    /// Return the number of environment-variable declarations.
4421    pub fn num_environment_vars(&self) -> i32 {
4422        unsafe {
4423            ocio_sys::ocio_config_get_num_environment_vars(self.handle.as_ptr() as *mut c_void)
4424        }
4425    }
4426
4427    /// Return the environment-variable name at a given index.
4428    pub fn environment_var_name_by_index(&self, index: i32) -> Option<String> {
4429        unsafe {
4430            cstr_from_mut(ocio_sys::ocio_config_get_environment_var_name_by_index(
4431                self.handle.as_ptr(),
4432                index,
4433            ))
4434        }
4435    }
4436
4437    /// Return the default value for a named environment variable.
4438    pub fn environment_var_default(&self, name: impl AsRef<str>) -> Option<String> {
4439        let n = cstring(name).ok()?;
4440        unsafe {
4441            cstr_from_mut(ocio_sys::ocio_config_get_environment_var_default(
4442                self.handle.as_ptr(),
4443                n.as_ptr().cast(),
4444            ))
4445        }
4446    }
4447
4448    /// Remove every environment-variable declaration authored on this config.
4449    pub fn clear_environment_vars(&self) -> Result<()> {
4450        crate::clear_last_error();
4451        unsafe {
4452            ocio_sys::ocio_config_clear_environment_vars(self.handle.as_ptr() as *mut c_void)
4453        };
4454        crate::ocio_call_status()
4455    }
4456
4457    // --- v2.5.1: Active display/view management ---
4458
4459    /// Append a single display name to the active displays list.
4460    #[cfg(feature = "v2_5")]
4461    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4462    pub fn add_active_display(&self, display: impl AsRef<str>) -> Result<()> {
4463        let d = cstring(display)?;
4464        crate::clear_last_error();
4465        unsafe {
4466            ocio_sys::ocio_config_add_active_display(self.handle.as_ptr(), d.as_ptr().cast())
4467        };
4468        crate::ocio_call_status()
4469    }
4470
4471    /// Return the active display name at a given index.
4472    #[cfg(feature = "v2_5")]
4473    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4474    pub fn active_display(&self, index: i32) -> Option<String> {
4475        self.try_active_display(index).ok().flatten()
4476    }
4477
4478    /// Return an active display name at a given index, preserving query failures.
4479    #[cfg(feature = "v2_5")]
4480    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4481    pub fn try_active_display(&self, index: i32) -> Result<Option<String>> {
4482        crate::clear_last_error();
4483        let display = unsafe {
4484            cstr_from_mut(ocio_sys::ocio_config_get_active_display(
4485                self.handle.as_ptr(),
4486                index,
4487            ))
4488        };
4489        crate::ocio_call_status()?;
4490        Ok(display)
4491    }
4492
4493    #[doc(hidden)]
4494    #[deprecated(since = "0.2.0", note = "compat alias; prefer active_display()")]
4495    #[cfg(feature = "v2_5")]
4496    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4497    pub fn get_active_display(&self, index: i32) -> Option<String> {
4498        self.active_display(index)
4499    }
4500
4501    /// Remove a single display name from the active displays list.
4502    #[cfg(feature = "v2_5")]
4503    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4504    pub fn remove_active_display(&self, display: impl AsRef<str>) -> Result<()> {
4505        let display = cstring(display)?;
4506        crate::clear_last_error();
4507        unsafe {
4508            ocio_sys::ocio_config_remove_active_display(
4509                self.handle.as_ptr(),
4510                display.as_ptr().cast(),
4511            )
4512        };
4513        crate::ocio_call_status()
4514    }
4515
4516    /// Append a single view name to the active views list.
4517    #[cfg(feature = "v2_5")]
4518    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4519    pub fn add_active_view(&self, view: impl AsRef<str>) -> Result<()> {
4520        let v = cstring(view)?;
4521        crate::clear_last_error();
4522        unsafe { ocio_sys::ocio_config_add_active_view(self.handle.as_ptr(), v.as_ptr().cast()) };
4523        crate::ocio_call_status()
4524    }
4525
4526    /// Return the active view name at a given index.
4527    #[cfg(feature = "v2_5")]
4528    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4529    pub fn active_view(&self, index: i32) -> Option<String> {
4530        self.try_active_view(index).ok().flatten()
4531    }
4532
4533    /// Return an active view name at a given index, preserving query failures.
4534    #[cfg(feature = "v2_5")]
4535    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4536    pub fn try_active_view(&self, index: i32) -> Result<Option<String>> {
4537        crate::clear_last_error();
4538        let view = unsafe {
4539            cstr_from_mut(ocio_sys::ocio_config_get_active_view(
4540                self.handle.as_ptr(),
4541                index,
4542            ))
4543        };
4544        crate::ocio_call_status()?;
4545        Ok(view)
4546    }
4547
4548    #[doc(hidden)]
4549    #[deprecated(since = "0.2.0", note = "compat alias; prefer active_view()")]
4550    #[cfg(feature = "v2_5")]
4551    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4552    pub fn get_active_view(&self, index: i32) -> Option<String> {
4553        self.active_view(index)
4554    }
4555
4556    /// Remove a single view name from the active views list.
4557    #[cfg(feature = "v2_5")]
4558    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4559    pub fn remove_active_view(&self, view: impl AsRef<str>) -> Result<()> {
4560        let view = cstring(view)?;
4561        crate::clear_last_error();
4562        unsafe {
4563            ocio_sys::ocio_config_remove_active_view(self.handle.as_ptr(), view.as_ptr().cast())
4564        };
4565        crate::ocio_call_status()
4566    }
4567
4568    #[deprecated(
4569        since = "0.2.0",
4570        note = "discarded OCIO errors; prefer try_clear_active_displays()"
4571    )]
4572    #[cfg(feature = "v2_5")]
4573    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4574    pub fn clear_active_displays(&self) {
4575        let _ = self.try_clear_active_displays();
4576    }
4577
4578    /// Try to clear all active display overrides.
4579    #[cfg(feature = "v2_5")]
4580    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4581    pub fn try_clear_active_displays(&self) -> Result<()> {
4582        crate::clear_last_error();
4583        unsafe { ocio_sys::ocio_config_clear_active_displays(self.handle.as_ptr() as *mut c_void) };
4584        crate::ocio_call_status()
4585    }
4586
4587    #[deprecated(
4588        since = "0.2.0",
4589        note = "discarded OCIO errors; prefer try_clear_active_views()"
4590    )]
4591    #[cfg(feature = "v2_5")]
4592    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4593    pub fn clear_active_views(&self) {
4594        let _ = self.try_clear_active_views();
4595    }
4596
4597    /// Try to clear all active view overrides.
4598    #[cfg(feature = "v2_5")]
4599    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4600    pub fn try_clear_active_views(&self) -> Result<()> {
4601        crate::clear_last_error();
4602        unsafe { ocio_sys::ocio_config_clear_active_views(self.handle.as_ptr() as *mut c_void) };
4603        crate::ocio_call_status()
4604    }
4605
4606    /// Return the count of active displays.
4607    #[cfg(feature = "v2_5")]
4608    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4609    pub fn num_active_displays(&self) -> i32 {
4610        self.try_num_active_displays().unwrap_or(0)
4611    }
4612
4613    /// Return the count of active displays, preserving OCIO query failures.
4614    #[cfg(feature = "v2_5")]
4615    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4616    pub fn try_num_active_displays(&self) -> Result<i32> {
4617        crate::clear_last_error();
4618        let count = unsafe {
4619            ocio_sys::ocio_config_get_num_active_displays(self.handle.as_ptr() as *mut c_void)
4620        };
4621        crate::ocio_call_status()?;
4622        Ok(count)
4623    }
4624
4625    #[cfg(feature = "v2_5")]
4626    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4627    pub fn num_active_views(&self) -> i32 {
4628        self.try_num_active_views().unwrap_or(0)
4629    }
4630
4631    /// Return the count of active views, preserving OCIO query failures.
4632    #[cfg(feature = "v2_5")]
4633    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4634    pub fn try_num_active_views(&self) -> Result<i32> {
4635        crate::clear_last_error();
4636        let count = unsafe {
4637            ocio_sys::ocio_config_get_num_active_views(self.handle.as_ptr() as *mut c_void)
4638        };
4639        crate::ocio_call_status()?;
4640        Ok(count)
4641    }
4642
4643    /// Return the total number of all displays (including inactive).
4644    pub fn num_displays_all(&self) -> i32 {
4645        self.try_num_displays_all().unwrap_or(0)
4646    }
4647
4648    /// Return the total number of all displays, preserving OCIO query failures.
4649    pub fn try_num_displays_all(&self) -> Result<i32> {
4650        crate::clear_last_error();
4651        let count = unsafe { ocio_sys::ocio_config_get_num_displays_all(self.handle.as_ptr()) };
4652        crate::ocio_call_status()?;
4653        Ok(count)
4654    }
4655
4656    #[doc(hidden)]
4657    #[deprecated(since = "0.2.0", note = "compat alias; prefer num_displays_all()")]
4658    pub fn get_num_displays_all(&self) -> i32 {
4659        self.num_displays_all()
4660    }
4661
4662    /// Return the display name at a given index from all displays (including inactive).
4663    pub fn display_all(&self, index: i32) -> Option<String> {
4664        self.try_display_all(index).ok().flatten()
4665    }
4666
4667    /// Return a display name at a given all-display index, preserving query failures.
4668    pub fn try_display_all(&self, index: i32) -> Result<Option<String>> {
4669        crate::clear_last_error();
4670        let display = unsafe {
4671            cstr_from_mut(ocio_sys::ocio_config_get_display_all(
4672                self.handle.as_ptr(),
4673                index,
4674            ))
4675        };
4676        crate::ocio_call_status()?;
4677        Ok(display.filter(|display| !display.is_empty()))
4678    }
4679
4680    #[doc(hidden)]
4681    #[deprecated(since = "0.2.0", note = "compat alias; prefer display_all()")]
4682    pub fn get_display_all(&self, index: i32) -> Option<String> {
4683        self.display_all(index)
4684    }
4685
4686    pub fn display_all_index(&self, display: impl AsRef<str>) -> i32 {
4687        self.try_display_all_index(display).unwrap_or(-1)
4688    }
4689
4690    /// Return an all-display index by name, preserving invalid input and OCIO failures.
4691    ///
4692    /// A negative result means OCIO did not find the display.
4693    pub fn try_display_all_index(&self, display: impl AsRef<str>) -> Result<i32> {
4694        let display = cstring(display)?;
4695        crate::clear_last_error();
4696        let index = unsafe {
4697            ocio_sys::ocio_config_get_display_all_by_name(
4698                self.handle.as_ptr(),
4699                display.as_ptr() as *mut c_void,
4700            )
4701        };
4702        crate::ocio_call_status()?;
4703        Ok(index)
4704    }
4705
4706    #[doc(hidden)]
4707    #[deprecated(since = "0.2.0", note = "compat alias; prefer display_all_index()")]
4708    pub fn get_display_all_by_name(&self, display: impl AsRef<str>) -> i32 {
4709        self.display_all_index(display)
4710    }
4711
4712    /// Return whether the display at a given index is marked as temporary.
4713    pub fn is_display_temporary(&self, index: i32) -> bool {
4714        unsafe { ocio_sys::ocio_config_is_display_temporary(self.handle.as_ptr(), index) }
4715    }
4716
4717    /// Mark the display at `index` as temporary or persistent.
4718    ///
4719    /// Returns an error when `index` does not identify an existing display.
4720    #[cfg(feature = "v2_5")]
4721    #[cfg_attr(docsrs, doc(cfg(feature = "v2_5")))]
4722    pub fn set_display_temporary(&self, index: i32, temporary: bool) -> Result<()> {
4723        crate::clear_last_error();
4724        unsafe {
4725            ocio_sys::ocio_config_set_display_temporary(self.handle.as_ptr(), index, temporary)
4726        };
4727        crate::ocio_call_status()
4728    }
4729
4730    /// Compatibility query. The argument selects the view origin, not a reference space.
4731    pub fn num_views_by_reference_space(
4732        &self,
4733        reference_space: SearchReferenceSpaceType,
4734        display: impl AsRef<str>,
4735    ) -> i32 {
4736        self.try_num_views_by_reference_space(reference_space, display)
4737            .unwrap_or(0)
4738    }
4739
4740    /// Compatibility query: `Scene` means shared and `Display` means display-defined.
4741    /// Prefer [`Self::try_num_views_by_type`].
4742    pub fn try_num_views_by_reference_space(
4743        &self,
4744        reference_space: SearchReferenceSpaceType,
4745        display: impl AsRef<str>,
4746    ) -> Result<i32> {
4747        let display = display.as_ref();
4748        self.try_num_views_by_type(legacy_view_type(reference_space, Some(display))?, display)
4749    }
4750
4751    /// Return the count of shared or display-defined views. An empty display
4752    /// queries all global shared views, regardless of the type.
4753    pub fn try_num_views_by_type(
4754        &self,
4755        view_type: ViewType,
4756        display: impl AsRef<str>,
4757    ) -> Result<i32> {
4758        let display = cstring(display)?;
4759        crate::clear_last_error();
4760        let count = unsafe {
4761            ocio_sys::ocio_config_get_num_views_v2(
4762                self.handle.as_ptr(),
4763                view_type as i32,
4764                display.as_ptr().cast(),
4765            )
4766        };
4767        crate::ocio_call_status()?;
4768        Ok(count)
4769    }
4770
4771    #[doc(hidden)]
4772    #[deprecated(
4773        since = "0.2.0",
4774        note = "compat overload; prefer try_num_views_by_type()"
4775    )]
4776    pub fn get_num_views_v2(
4777        &self,
4778        reference_space: SearchReferenceSpaceType,
4779        display: impl AsRef<str>,
4780    ) -> i32 {
4781        self.num_views_by_reference_space(reference_space, display)
4782    }
4783
4784    /// Compatibility query. The argument selects the view origin, not a reference space.
4785    pub fn view_by_reference_space(
4786        &self,
4787        reference_space: SearchReferenceSpaceType,
4788        display: impl AsRef<str>,
4789        index: i32,
4790    ) -> Option<String> {
4791        self.try_view_by_reference_space(reference_space, display, index)
4792            .ok()
4793            .flatten()
4794    }
4795
4796    /// Compatibility query: `Scene` means shared and `Display` means display-defined.
4797    /// Prefer [`Self::try_view_by_type`].
4798    pub fn try_view_by_reference_space(
4799        &self,
4800        reference_space: SearchReferenceSpaceType,
4801        display: impl AsRef<str>,
4802        index: i32,
4803    ) -> Result<Option<String>> {
4804        let display = display.as_ref();
4805        self.try_view_by_type(
4806            legacy_view_type(reference_space, Some(display))?,
4807            display,
4808            index,
4809        )
4810    }
4811
4812    /// Return a view by origin and index. An empty display queries global shared views;
4813    /// an empty native result is returned as `None`.
4814    pub fn try_view_by_type(
4815        &self,
4816        view_type: ViewType,
4817        display: impl AsRef<str>,
4818        index: i32,
4819    ) -> Result<Option<String>> {
4820        let display = cstring(display)?;
4821        crate::clear_last_error();
4822        let view = unsafe {
4823            cstr_from_mut(ocio_sys::ocio_config_get_view_v2(
4824                self.handle.as_ptr(),
4825                view_type as i32,
4826                display.as_ptr().cast(),
4827                index,
4828            ))
4829        };
4830        crate::ocio_call_status()?;
4831        Ok(view.filter(|view| !view.is_empty()))
4832    }
4833
4834    #[doc(hidden)]
4835    #[deprecated(since = "0.2.0", note = "compat overload; prefer try_view_by_type()")]
4836    pub fn get_view_v2(
4837        &self,
4838        reference_space: SearchReferenceSpaceType,
4839        display: impl AsRef<str>,
4840        index: i32,
4841    ) -> Option<String> {
4842        self.view_by_reference_space(reference_space, display, index)
4843    }
4844
4845    /// Return an independent editable copy of the config's viewing rules, if any.
4846    pub fn viewing_rules(&self) -> Option<ViewingRules> {
4847        self.try_viewing_rules().ok().flatten()
4848    }
4849
4850    /// Return the editable viewing-rules object attached to this config.
4851    ///
4852    /// `Ok(None)` means the config has no viewing-rules object. OCIO bridge
4853    /// failures are returned separately.
4854    pub fn try_viewing_rules(&self) -> Result<Option<ViewingRules>> {
4855        crate::clear_last_error();
4856        let handle = unsafe { ocio_sys::ocio_config_get_viewing_rules(self.handle.as_ptr()) };
4857        crate::ocio_call_status()?;
4858        Ok(NonNull::new(handle).map(|handle| ViewingRules { handle }))
4859    }
4860
4861    /// Attach a viewing-rules object to this config.
4862    pub fn set_viewing_rules_object(&self, viewing_rules: &ViewingRules) -> Result<()> {
4863        crate::clear_last_error();
4864        unsafe {
4865            ocio_sys::ocio_config_set_viewing_rules(
4866                self.handle.as_ptr(),
4867                viewing_rules.handle.as_ptr(),
4868            )
4869        };
4870        crate::ocio_call_status()
4871    }
4872
4873    /// Return an owned raw OCIO viewing-rules handle.
4874    ///
4875    /// # Safety
4876    /// The caller must release a non-null handle with
4877    /// [`ocio_sys::ocio_viewing_rules_destroy`]. It wraps an independent
4878    /// shared OCIO viewing-rules reference and remains valid after this config
4879    /// drops. Prefer [`Self::viewing_rules`] for a typed wrapper.
4880    #[doc(hidden)]
4881    #[deprecated(
4882        since = "0.2.0",
4883        note = "raw OCIO viewing-rules handle; prefer higher-level Config APIs where possible"
4884    )]
4885    pub unsafe fn get_viewing_rules(&self) -> *mut c_void {
4886        unsafe { ocio_sys::ocio_config_get_viewing_rules(self.handle.as_ptr()) }
4887    }
4888
4889    /// # Safety
4890    /// `viewing_rules` must be a valid OCIO viewing-rules pointer for the
4891    /// active ABI and must remain valid for as long as OCIO retains it. Prefer
4892    /// [`Self::set_viewing_rules_object`] for a typed wrapper.
4893    #[doc(hidden)]
4894    #[deprecated(
4895        since = "0.2.0",
4896        note = "raw OCIO viewing-rules handle; prefer higher-level Config APIs where possible"
4897    )]
4898    pub unsafe fn set_viewing_rules(&self, viewing_rules: *mut c_void) {
4899        crate::clear_last_error();
4900        unsafe { ocio_sys::ocio_config_set_viewing_rules(self.handle.as_ptr(), viewing_rules) };
4901        let _ = crate::ocio_call_status();
4902    }
4903
4904    // --- v2.5.1: Misc utilities ---
4905
4906    /// Deprecated text conversion: OCIOZ is binary. Use [`Self::archive_to_bytes`].
4907    #[deprecated(note = "OCIOZ is binary; use archive_to_bytes or archive_to_writer")]
4908    pub fn archive(&self) -> Result<Option<String>> {
4909        #[allow(deprecated)]
4910        self.archive_to_string()
4911    }
4912
4913    /// Deprecated text conversion; rejects non-UTF-8 or NUL-containing archives.
4914    #[deprecated(note = "OCIOZ is binary; use archive_to_bytes or archive_to_writer")]
4915    pub fn archive_to_string(&self) -> Result<Option<String>> {
4916        self.archive_to_bytes()?
4917            .map(|bytes| {
4918                if bytes.contains(&0) {
4919                    return Err(OcioError::InvalidInput(
4920                        "OCIOZ is binary; use archive_to_bytes or archive_to_writer".into(),
4921                    ));
4922                }
4923                String::from_utf8(bytes).map_err(|_| {
4924                    OcioError::InvalidInput(
4925                        "OCIOZ is binary; use archive_to_bytes or archive_to_writer".into(),
4926                    )
4927                })
4928            })
4929            .transpose()
4930    }
4931
4932    /// Write the binary OCIOZ archive to a writer without an extra archive-sized
4933    /// bridge buffer. OCIO itself constructs the archive in memory. The writer
4934    /// is not flushed; partial output remains on error. Do not reenter this
4935    /// config from the callback. Stub builds write nothing.
4936    pub fn archive_to_writer<W: std::io::Write + ?Sized>(&self, writer: &mut W) -> Result<()> {
4937        // The native bridge uses the callback synchronously and does not retain it.
4938        unsafe {
4939            crate::output_writer::write_to(writer, "Archive", |context, callback| {
4940                ocio_sys::ocio_config_archive_to_writer(self.handle.as_ptr(), context, callback)
4941            })
4942        }
4943    }
4944
4945    /// Archive to owned binary OCIOZ bytes, or `None` in stub builds.
4946    pub fn archive_to_bytes(&self) -> Result<Option<Vec<u8>>> {
4947        if crate::is_stub_build() {
4948            crate::clear_last_error();
4949            return Ok(None);
4950        }
4951        let mut bytes = Vec::new();
4952        self.archive_to_writer(&mut bytes)?;
4953        Ok(Some(bytes))
4954    }
4955
4956    /// Return the attached typed config IO proxy when it originated from a Rust-managed proxy.
4957    pub fn config_io_proxy_object(&self) -> Option<ConfigIOProxy> {
4958        self.try_config_io_proxy_object().ok().flatten()
4959    }
4960
4961    /// Return the attached typed config IO proxy, preserving bridge errors.
4962    ///
4963    /// `Ok(None)` means this config has no proxy attached.
4964    pub fn try_config_io_proxy_object(&self) -> Result<Option<ConfigIOProxy>> {
4965        crate::clear_last_error();
4966        let handle = unsafe {
4967            ocio_sys::ocio_config_get_config_io_proxy(self.handle.as_ptr() as *mut c_void)
4968        };
4969        crate::ocio_call_status()?;
4970        Ok(NonNull::new(handle).map(|handle| ConfigIOProxy { handle }))
4971    }
4972
4973    /// Attach a typed config IO proxy used to serve the config and LUT assets.
4974    /// Attach a proxy and invalidate this config's context path resolutions.
4975    /// OCIO separately caches file hashes process-wide by path, not by proxy.
4976    /// When an existing path changes meaning, coordinate with other OCIO users
4977    /// and call [`crate::try_clear_all_caches`]; this is never done implicitly.
4978    pub fn set_config_io_proxy_object(&self, proxy: &ConfigIOProxy) -> Result<()> {
4979        crate::clear_last_error();
4980        unsafe {
4981            ocio_sys::ocio_config_set_config_io_proxy(self.handle.as_ptr(), proxy.handle.as_ptr())
4982        };
4983        crate::ocio_call_status()
4984    }
4985
4986    /// Detach the IO proxy. Other retained proxy handles remain valid. The
4987    /// process-global file hash cache is not implicitly cleared.
4988    pub fn clear_config_io_proxy(&self) -> Result<()> {
4989        crate::clear_last_error();
4990        unsafe {
4991            ocio_sys::ocio_config_set_config_io_proxy(self.handle.as_ptr(), std::ptr::null_mut())
4992        };
4993        crate::ocio_call_status()
4994    }
4995
4996    /// Return the default family separator character for this OCIO version.
4997    pub fn default_family_separator(&self) -> char {
4998        unsafe {
4999            ocio_sys::ocio_config_get_default_family_separator(self.handle.as_ptr() as *mut c_void)
5000                as u8 as char
5001        }
5002    }
5003
5004    #[doc(hidden)]
5005    #[deprecated(
5006        since = "0.2.0",
5007        note = "raw OCIO config-IO proxy handle; prefer file/path based Config APIs where possible"
5008    )]
5009    /// Returns an owned raw OCIO config-IO proxy handle.
5010    ///
5011    /// The caller must release a non-null handle with
5012    /// [`ocio_sys::ocio_config_io_proxy_destroy`]. It wraps an independent
5013    /// shared OCIO proxy reference and remains valid after this config drops.
5014    pub fn config_io_proxy(&self) -> *mut std::ffi::c_void {
5015        unsafe { ocio_sys::ocio_config_get_config_io_proxy(self.handle.as_ptr() as *mut c_void) }
5016    }
5017
5018    #[doc(hidden)]
5019    #[deprecated(since = "0.2.0", note = "compat alias; prefer config_io_proxy()")]
5020    pub fn get_config_io_proxy(&self) -> *mut std::ffi::c_void {
5021        unsafe { ocio_sys::ocio_config_get_config_io_proxy(self.handle.as_ptr() as *mut c_void) }
5022    }
5023
5024    /// # Safety
5025    /// The caller must pass a valid OCIO config-IO proxy pointer for the
5026    /// active ABI and keep it alive for as long as OCIO may use it. Prefer
5027    /// [`Self::set_config_io_proxy_object`] for a typed wrapper.
5028    #[doc(hidden)]
5029    #[deprecated(
5030        since = "0.2.0",
5031        note = "raw OCIO config-IO proxy handle; prefer file/path based Config APIs where possible"
5032    )]
5033    pub unsafe fn set_config_io_proxy(&self, proxy: *mut std::ffi::c_void) {
5034        crate::clear_last_error();
5035        unsafe { ocio_sys::ocio_config_set_config_io_proxy(self.handle.as_ptr(), proxy) };
5036        let _ = crate::ocio_call_status();
5037    }
5038
5039    /// Return whether a file path matches only the default rule, or false on error.
5040    pub fn filepath_only_matches_default_rule(&self, filepath: impl AsRef<str>) -> bool {
5041        self.try_filepath_only_matches_default_rule(filepath)
5042            .unwrap_or(false)
5043    }
5044
5045    /// Determine whether only the default rule matches, preserving native errors.
5046    pub fn try_filepath_only_matches_default_rule(
5047        &self,
5048        filepath: impl AsRef<str>,
5049    ) -> Result<bool> {
5050        self.try_filepath_only_matches_default_rule_cstr(&cstring(filepath)?)
5051    }
5052
5053    /// Determine whether only the default rule matches using a native path.
5054    pub fn try_filepath_only_matches_default_rule_cstr(
5055        &self,
5056        filepath: &std::ffi::CStr,
5057    ) -> Result<bool> {
5058        crate::clear_last_error();
5059        let result = unsafe {
5060            ocio_sys::ocio_config_filepath_only_matches_default_rule(
5061                self.handle.as_ptr(),
5062                filepath.as_ptr(),
5063            )
5064        };
5065        crate::ocio_call_status()?;
5066        Ok(result)
5067    }
5068
5069    // --- v2.5.1: Processor cache flags ---
5070
5071    /// Return the current processor-cache behavior flags.
5072    pub fn processor_cache_flags(&self) -> i32 {
5073        unsafe {
5074            ocio_sys::ocio_config_get_processor_cache_flags(self.handle.as_ptr() as *mut c_void)
5075        }
5076    }
5077
5078    #[deprecated(
5079        since = "0.2.0",
5080        note = "discarded OCIO errors; prefer try_set_processor_cache_flags()"
5081    )]
5082    pub fn set_processor_cache_flags(&self, flags: i32) {
5083        let _ = self.try_set_processor_cache_flags(flags);
5084    }
5085
5086    /// Try to set OCIO's processor-cache behavior flags for this config.
5087    pub fn try_set_processor_cache_flags(&self, flags: i32) -> Result<()> {
5088        crate::clear_last_error();
5089        unsafe {
5090            ocio_sys::ocio_config_set_processor_cache_flags(
5091                self.handle.as_ptr() as *mut c_void,
5092                flags,
5093            )
5094        };
5095        crate::ocio_call_status()
5096    }
5097}
5098
5099impl Drop for Config {
5100    fn drop(&mut self) {
5101        unsafe { ocio_sys::ocio_config_destroy(self.handle.as_ptr() as *mut c_void) };
5102    }
5103}
5104
5105#[cfg(test)]
5106mod tests {
5107    use super::*;
5108    use std::fs;
5109    use std::sync::{Mutex, OnceLock};
5110
5111    fn env_lock() -> std::sync::MutexGuard<'static, ()> {
5112        static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
5113        LOCK.get_or_init(|| Mutex::new(())).lock().unwrap()
5114    }
5115
5116    #[test]
5117    fn create_raw_config() {
5118        let cfg = Config::raw();
5119        assert!(cfg.is_ok());
5120    }
5121
5122    #[test]
5123    fn create_config_from_env_no_crash() {
5124        let _guard = env_lock();
5125        let path = "tests/data/configs/context_test1/config.ocio";
5126        let prev = std::env::var_os("OCIO");
5127        unsafe {
5128            std::env::set_var("OCIO", path);
5129        }
5130
5131        let cfg = Config::from_env();
5132
5133        match prev {
5134            Some(value) => unsafe { std::env::set_var("OCIO", value) },
5135            None => unsafe { std::env::remove_var("OCIO") },
5136        }
5137
5138        if crate::is_stub_build() {
5139            let _ = cfg;
5140        } else {
5141            assert!(cfg.is_ok());
5142        }
5143    }
5144
5145    #[test]
5146    fn create_config_from_stream_no_crash() {
5147        let text =
5148            fs::read_to_string("tests/data/configs/context_test1/config.ocio").expect("read ocio");
5149        let cfg = Config::from_stream(text);
5150        if crate::is_stub_build() {
5151            let _ = cfg;
5152        } else {
5153            assert!(cfg.is_ok());
5154        }
5155    }
5156
5157    #[test]
5158    fn config_metadata_no_crash() {
5159        let config = Config::raw().unwrap();
5160        let _ = config.name();
5161        let _ = config.description();
5162        let _ = config.cache_id();
5163    }
5164
5165    #[test]
5166    fn config_version() {
5167        let config = Config::raw().unwrap();
5168        let _ = config.major_version();
5169        let _ = config.minor_version();
5170        let _ = config.family_separator();
5171    }
5172
5173    #[test]
5174    fn config_color_spaces() {
5175        let config = Config::raw().unwrap();
5176        // In stub mode, num_color_spaces is 0
5177        assert!(config.num_color_spaces() >= 0);
5178    }
5179
5180    #[test]
5181    fn config_displays_views() {
5182        let config = Config::raw().unwrap();
5183        // In stub mode these return 0/None, but shouldn't crash
5184        let _ = config.num_displays();
5185        let _ = config.default_display();
5186        let _ = config.default_view("sRGB");
5187    }
5188
5189    #[test]
5190    fn config_looks() {
5191        let config = Config::raw().unwrap();
5192        assert!(config.num_looks() >= 0);
5193        let _ = config.look_name_by_index(0);
5194    }
5195
5196    #[test]
5197    fn config_luma_coefs() {
5198        let config = Config::raw().unwrap();
5199        let coefs = config.default_luma_coefs().unwrap();
5200        // Stub mode returns zeros
5201        assert_eq!(coefs.len(), 3);
5202    }
5203
5204    #[test]
5205    fn config_roles() {
5206        let config = Config::raw().unwrap();
5207        assert!(config.num_roles() >= 0);
5208        let _ = config.has_role("default");
5209    }
5210
5211    #[test]
5212    fn config_active() {
5213        let config = Config::raw().unwrap();
5214        let _ = config.active_displays();
5215        let _ = config.active_views();
5216    }
5217
5218    #[test]
5219    fn create_processor() {
5220        let config = Config::raw().unwrap();
5221        let proc = config.processor("raw", "raw");
5222        assert!(proc.is_ok());
5223    }
5224
5225    #[test]
5226    fn create_processor_display() {
5227        let config = Config::raw().unwrap();
5228        // In stub mode this returns error since stub config has no displays
5229        let proc = config.processor_display("raw", "sRGB", "Film", TransformDirection::Forward);
5230        // Just check it doesn't crash
5231        let _ = proc;
5232    }
5233
5234    #[test]
5235    fn config_view_named_wrappers_no_crash() {
5236        let config = Config::raw().unwrap();
5237        let _ = config.default_view("sRGB");
5238        let _ = config.num_views("sRGB");
5239        let _ = config.view("sRGB", 0);
5240        let _ = config.default_view_with_color_space("sRGB", "raw");
5241        let _ = config.num_views_with_color_space("sRGB", "raw");
5242        let _ = config.view_with_color_space("sRGB", "raw", 0);
5243        let _ = config.num_views_by_reference_space(SearchReferenceSpaceType::Scene, "sRGB");
5244        let _ = config.view_by_reference_space(SearchReferenceSpaceType::Scene, "sRGB", 0);
5245        let _ = config.virtual_display_num_views(SearchReferenceSpaceType::Scene);
5246        let _ = config.virtual_display_view(SearchReferenceSpaceType::Scene, 0);
5247    }
5248
5249    #[test]
5250    fn processor_from_transform_no_crash() {
5251        let config = Config::raw().unwrap();
5252        let ft = crate::transform::FileTransform::create().unwrap();
5253        let proc = config.processor_from_transform(&ft, TransformDirection::Forward);
5254        let _ = proc;
5255    }
5256
5257    #[test]
5258    fn config_lookup_named_wrappers_no_crash() {
5259        let config = Config::raw().unwrap();
5260        let _ = config.color_space("raw");
5261        let _ = config.color_space_index("raw");
5262        let _ = config.look("look_name");
5263        let _ = config.named_transform("Default");
5264        let _ = config.named_transform_index("Default");
5265        let _ = config.view_transform("Default");
5266    }
5267
5268    #[test]
5269    fn add_remove_color_space_no_crash() {
5270        let config = Config::raw().unwrap();
5271        let cs = ColorSpace::create().unwrap();
5272        cs.set_name("TestCS").unwrap();
5273        config.add_color_space(&cs);
5274        let _ = config.color_space_index("TestCS");
5275        let _ = config.is_color_space_used("TestCS");
5276        let _ = config.remove_color_space("TestCS");
5277    }
5278
5279    #[test]
5280    fn get_look_no_crash() {
5281        let config = Config::raw().unwrap();
5282        let _ = config.look("look_name");
5283    }
5284
5285    #[test]
5286    fn add_look_no_crash() {
5287        let config = Config::raw().unwrap();
5288        let look = Look::create().unwrap();
5289        look.set_name("MyLook").unwrap();
5290        config.add_look(&look);
5291    }
5292
5293    #[test]
5294    fn search_path_no_crash() {
5295        let config = Config::raw().unwrap();
5296        let _ = config.search_path();
5297        assert!(config.set_search_path("/path/to/ocio").is_ok());
5298    }
5299
5300    #[test]
5301    fn strict_parsing_no_crash() {
5302        let config = Config::raw().unwrap();
5303        let _ = config.is_strict_parsing_enabled();
5304        config.set_strict_parsing_enabled(true);
5305        config.set_strict_parsing_enabled(false);
5306    }
5307
5308    #[test]
5309    fn set_role_no_crash() {
5310        let config = Config::raw().unwrap();
5311        assert!(config.set_role("default", "raw").is_ok());
5312    }
5313
5314    #[test]
5315    fn set_family_separator_no_crash() {
5316        let config = Config::raw().unwrap();
5317        config.set_family_separator('|');
5318    }
5319
5320    #[test]
5321    fn validate_no_crash() {
5322        let config = Config::raw().unwrap();
5323        let _ = config.validate();
5324    }
5325
5326    #[test]
5327    fn serialize_no_crash() {
5328        let config = Config::raw().unwrap();
5329        let serialized = config.serialize().unwrap();
5330        if crate::is_stub_build() {
5331            assert!(serialized.is_none());
5332        } else {
5333            let serialized = serialized.expect("real OCIO config should serialize");
5334            assert!(
5335                !serialized.trim().is_empty(),
5336                "real OCIO config serialization should not be empty"
5337            );
5338            assert!(
5339                serialized.contains("ocio_profile_version"),
5340                "serialized config should look like OCIO YAML"
5341            );
5342        }
5343    }
5344
5345    #[test]
5346    fn archive_no_crash() {
5347        let config = Config::raw().unwrap();
5348        if crate::is_stub_build() {
5349            assert!(config.archive_to_bytes().unwrap().is_none());
5350        } else if config.is_archivable() {
5351            let archived = config
5352                .archive_to_bytes()
5353                .unwrap()
5354                .expect("real archivable config should archive");
5355            assert!(
5356                !archived.is_empty(),
5357                "real OCIO config archive should not be empty"
5358            );
5359        } else {
5360            assert!(matches!(config.archive_to_bytes(), Err(OcioError::Ocio(_))));
5361        }
5362    }
5363
5364    #[test]
5365    fn create_editable_copy_no_crash() {
5366        let config = Config::raw().unwrap();
5367        let _ = config.create_editable_copy();
5368    }
5369
5370    #[test]
5371    fn fail_on_missing_file() {
5372        if crate::is_stub_build() {
5373            let cfg = Config::from_file("tests/missing_config.ocio");
5374            assert!(cfg.is_err());
5375        }
5376    }
5377
5378    #[test]
5379    fn set_active_displays_views_no_crash() {
5380        let config = Config::raw().unwrap();
5381        assert!(config.set_active_displays("sRGB").is_ok());
5382        assert!(config.set_active_views("Film,Log").is_ok());
5383    }
5384
5385    #[test]
5386    fn display_view_transform_name_no_crash() {
5387        let config = Config::raw().unwrap();
5388        let _ = config.display_view_transform_name("sRGB", "Film");
5389        let _ = config.display_view_color_space_name("sRGB", "Film");
5390        let _ = config.display_view_rule("sRGB", "Film");
5391        let _ = config.display_view_description("sRGB", "Film");
5392    }
5393
5394    #[test]
5395    fn set_default_luma_coefs_no_crash() {
5396        let config = Config::raw().unwrap();
5397        config
5398            .set_default_luma_coefs(&[0.2126, 0.7152, 0.0722])
5399            .unwrap();
5400    }
5401
5402    #[test]
5403    fn clear_color_spaces_looks_no_crash() {
5404        let config = Config::raw().unwrap();
5405        config.try_clear_color_spaces().unwrap();
5406        config.try_clear_looks().unwrap();
5407    }
5408
5409    #[test]
5410    fn display_management_no_crash() {
5411        let config = Config::raw().unwrap();
5412        assert!(config
5413            .add_display("sRGB", "Film", "DisplayTransform", "srgb")
5414            .is_ok());
5415        assert!(config
5416            .add_shared_view("SharedView", "TransformName", "srgb", "", "", "")
5417            .is_ok());
5418        assert!(config.remove_view("sRGB", "Film").is_ok());
5419    }
5420
5421    #[test]
5422    fn named_transforms_no_crash() {
5423        let config = Config::raw().unwrap();
5424        let _ = config.num_named_transforms();
5425        let _ = config.named_transform_name_by_index(0);
5426        let _ = config.named_transform("Default");
5427        let _ = config.named_transform_index("Default");
5428    }
5429
5430    #[cfg(feature = "v2_5")]
5431    #[test]
5432    fn add_remove_named_transform_no_crash() {
5433        let config = Config::raw().unwrap();
5434        let nt = NamedTransform::create().unwrap();
5435        nt.set_name("MyNamedTransform").unwrap();
5436        let identity = crate::transform::MatrixTransform::identity().unwrap();
5437        nt.set_transform(&identity, crate::TransformDirection::Forward);
5438        config.add_named_transform(&nt);
5439        assert!(config.remove_named_transform("MyNamedTransform").is_ok());
5440    }
5441
5442    #[test]
5443    fn view_transforms_no_crash() {
5444        let config = Config::raw().unwrap();
5445        let _ = config.num_view_transforms();
5446        let _ = config.view_transform_name_by_index(0);
5447        let _ = config.view_transform("Default");
5448    }
5449
5450    #[test]
5451    fn clear_all_no_crash() {
5452        let config = Config::raw().unwrap();
5453        config.clear_all();
5454    }
5455
5456    #[test]
5457    fn version_setters_no_crash() {
5458        let config = Config::raw().unwrap();
5459        assert!(config.set_major_version(2).is_ok());
5460        assert!(config.set_minor_version(1).is_ok());
5461    }
5462
5463    #[test]
5464    fn color_space_set_no_crash() {
5465        let config = Config::raw().unwrap();
5466        let set = config.color_space_set(Some(""));
5467        assert!(set.is_ok());
5468        if let Ok(set) = set {
5469            let _ = set.num_color_spaces();
5470            let _ = set.has_color_space("raw");
5471        }
5472    }
5473
5474    #[test]
5475    fn working_dir_no_crash() {
5476        let config = Config::raw().unwrap();
5477        let _ = config.working_dir();
5478        assert!(config.set_working_dir("/path/to/working").is_ok());
5479    }
5480
5481    #[test]
5482    fn file_rules_set_no_crash() {
5483        let config = Config::raw().unwrap();
5484        // Stub mode creates a default FileRules, real mode gets from config
5485        if let Ok(rules) = config.file_rules() {
5486            config.set_file_rules(&rules).unwrap();
5487        }
5488    }
5489
5490    #[test]
5491    fn inactive_color_spaces_no_crash() {
5492        let config = Config::raw().unwrap();
5493        assert!(config.set_inactive_color_spaces("inactive_cs").is_ok());
5494    }
5495
5496    #[test]
5497    fn is_archivable_no_crash() {
5498        let config = Config::raw().unwrap();
5499        let _ = config.is_archivable();
5500    }
5501
5502    #[test]
5503    fn clear_processor_cache_no_crash() {
5504        let config = Config::raw().unwrap();
5505        assert!(config.try_clear_processor_cache().is_ok());
5506    }
5507
5508    #[test]
5509    fn config_num_search_paths_no_crash() {
5510        let config = Config::raw().unwrap();
5511        let n = config.num_search_paths();
5512        assert!(n >= 0);
5513        let _ = config.search_path_by_index(0);
5514    }
5515
5516    #[test]
5517    fn default_display_view_compat_aliases_no_crash() {
5518        let config = Config::raw().unwrap();
5519        #[allow(deprecated)]
5520        {
5521            assert!(config.set_default_display("sRGB").is_ok());
5522            assert!(config.set_default_view("Film").is_ok());
5523        }
5524        let _ = config.default_view_transform_name();
5525    }
5526
5527    #[test]
5528    fn get_inactive_color_spaces_no_crash() {
5529        let config = Config::raw().unwrap();
5530        let _ = config.inactive_color_spaces();
5531    }
5532
5533    #[test]
5534    fn color_space_by_ref_type_no_crash() {
5535        let config = Config::raw().unwrap();
5536        let _ = config.color_space_by_ref_type("raw", SearchReferenceSpaceType::Scene);
5537        let _ = config.color_space_by_ref_type("raw", SearchReferenceSpaceType::Display);
5538        let _ = config.color_space_by_ref_type("raw", SearchReferenceSpaceType::All);
5539    }
5540
5541    #[test]
5542    fn color_space_from_filepath_with_rule_index_no_crash() {
5543        let config = Config::raw().unwrap();
5544        let _ = config.color_space_from_filepath_with_rule_index("test.jpg");
5545    }
5546
5547    #[test]
5548    #[allow(deprecated)]
5549    fn color_space_from_filepath_compat_alias_no_crash() {
5550        let config = Config::raw().unwrap();
5551        let _ = config.get_color_space_from_filepath_by_ref_type("test.jpg");
5552    }
5553
5554    #[test]
5555    fn processor_from_configs_no_crash() {
5556        let src_config = Config::raw().unwrap();
5557        let dst_config = Config::raw().unwrap();
5558        let proc = Config::processor_from_configs(&src_config, "raw", &dst_config, "raw");
5559        let _ = proc;
5560    }
5561
5562    #[test]
5563    #[allow(deprecated)]
5564    fn processor_from_configs_overloads_no_crash() {
5565        let config = Config::raw().unwrap();
5566        let src_config = Config::raw().unwrap();
5567        let dst_config = Config::raw().unwrap();
5568        let src_ctx = src_config.current_context();
5569        let dst_ctx = dst_config.current_context();
5570
5571        let _ =
5572            config.get_processor_from_configs_v2(&src_config, "raw", "", &dst_config, "raw", "");
5573        let _ = config.get_processor_from_configs_v4(
5574            &src_config,
5575            "raw",
5576            &dst_config,
5577            "sRGB",
5578            "Film",
5579            TransformDirection::Forward,
5580        );
5581        let _ = config.get_processor_from_configs_v6(
5582            &src_config,
5583            "raw",
5584            "",
5585            &dst_config,
5586            "sRGB",
5587            "Film",
5588            "",
5589            TransformDirection::Forward,
5590        );
5591
5592        if let (Some(src_ctx), Some(dst_ctx)) = (src_ctx, dst_ctx) {
5593            let _ = config.get_processor_from_configs_v1(
5594                &src_ctx,
5595                &src_config,
5596                "raw",
5597                &dst_ctx,
5598                &dst_config,
5599                "raw",
5600            );
5601            let _ = config.get_processor_from_configs_v3(
5602                &src_ctx,
5603                &src_config,
5604                "raw",
5605                "",
5606                &dst_ctx,
5607                &dst_config,
5608                "raw",
5609                "",
5610            );
5611            let _ = config.get_processor_from_configs_v5(
5612                &src_ctx,
5613                &src_config,
5614                "raw",
5615                &dst_ctx,
5616                &dst_config,
5617                "sRGB",
5618                "Film",
5619                TransformDirection::Forward,
5620            );
5621            let _ = config.get_processor_from_configs_v7(
5622                &src_ctx,
5623                &src_config,
5624                "raw",
5625                "",
5626                &dst_ctx,
5627                &dst_config,
5628                "sRGB",
5629                "Film",
5630                "",
5631                TransformDirection::Forward,
5632            );
5633        }
5634    }
5635
5636    #[test]
5637    fn processor_from_configs_named_wrappers_no_crash() {
5638        let config = Config::raw().unwrap();
5639        let src_config = Config::raw().unwrap();
5640        let dst_config = Config::raw().unwrap();
5641        let src_ctx = src_config.current_context();
5642        let dst_ctx = dst_config.current_context();
5643
5644        let _ = config.processor_from_configs_with_interchange(
5645            &src_config,
5646            "raw",
5647            "",
5648            &dst_config,
5649            "raw",
5650            "",
5651        );
5652        let _ = config.processor_from_configs_to_display(
5653            &src_config,
5654            "raw",
5655            &dst_config,
5656            "sRGB",
5657            "Film",
5658            TransformDirection::Forward,
5659        );
5660        let _ = config.processor_from_configs_to_display_with_interchange(
5661            &src_config,
5662            "raw",
5663            "",
5664            &dst_config,
5665            "sRGB",
5666            "Film",
5667            "",
5668            TransformDirection::Forward,
5669        );
5670
5671        if let (Some(src_ctx), Some(dst_ctx)) = (src_ctx, dst_ctx) {
5672            let _ = config.processor_from_configs_with_contexts(
5673                &src_ctx,
5674                &src_config,
5675                "raw",
5676                &dst_ctx,
5677                &dst_config,
5678                "raw",
5679            );
5680            let _ = config.processor_from_configs_with_contexts_and_interchange(
5681                &src_ctx,
5682                &src_config,
5683                "raw",
5684                "",
5685                &dst_ctx,
5686                &dst_config,
5687                "raw",
5688                "",
5689            );
5690            let _ = config.processor_from_configs_to_display_with_contexts(
5691                &src_ctx,
5692                &src_config,
5693                "raw",
5694                &dst_ctx,
5695                &dst_config,
5696                "sRGB",
5697                "Film",
5698                TransformDirection::Forward,
5699            );
5700            let _ = config.processor_from_configs_to_display_with_contexts_and_interchange(
5701                &src_ctx,
5702                &src_config,
5703                "raw",
5704                "",
5705                &dst_ctx,
5706                &dst_config,
5707                "sRGB",
5708                "Film",
5709                "",
5710                TransformDirection::Forward,
5711            );
5712        }
5713    }
5714
5715    #[cfg(feature = "v2_5")]
5716    #[test]
5717    fn active_and_all_display_named_wrappers_no_crash() {
5718        let config = Config::raw().unwrap();
5719        let _ = config.num_active_displays();
5720        let _ = config.num_active_views();
5721        let _ = config.active_display(0);
5722        let _ = config.active_view(0);
5723        let _ = config.num_displays_all();
5724        let _ = config.display_all(0);
5725        let _ = config.display_all_index("sRGB");
5726    }
5727
5728    #[test]
5729    fn processor_with_context_no_crash() {
5730        let config = Config::raw().unwrap();
5731        if let Some(ctx) = config.current_context() {
5732            let proc = config.processor_with_context("raw", "raw", &ctx);
5733            let _ = proc;
5734        }
5735    }
5736
5737    #[test]
5738    fn processor_overload_named_wrappers_no_crash() {
5739        let config = Config::raw().unwrap();
5740        let ft = crate::transform::FileTransform::create().unwrap();
5741        let src_cs = crate::ColorSpace::create().unwrap();
5742        let dst_cs = crate::ColorSpace::create().unwrap();
5743        let nt = configured_named_transform_for_processor_tests();
5744        config.add_named_transform(&nt);
5745
5746        let _ = config.processor("raw", "raw");
5747        let _ = config.processor_from_color_spaces(&src_cs, &dst_cs);
5748        let _ = config.processor_display("raw", "sRGB", "Film", TransformDirection::Forward);
5749        let _ = config.processor_from_transform_default_direction(&ft);
5750        let _ = config.processor_from_transform(&ft, TransformDirection::Forward);
5751        let _ = config.processor_named_transform(&nt, TransformDirection::Forward);
5752        let _ = config.processor_named_transform_name(
5753            "UnitCompatNamedTransform",
5754            TransformDirection::Forward,
5755        );
5756        let _ = config.processor_to_builtin_color_space(&config, "raw", "ACES2065-1");
5757        let _ = config.processor_from_builtin_color_space("ACES2065-1", &config, "raw");
5758
5759        if let Some(ctx) = config.current_context() {
5760            let _ = config.processor_with_context("raw", "raw", &ctx);
5761            let _ = config.processor_display_with_context(
5762                "raw",
5763                "sRGB",
5764                "Film",
5765                TransformDirection::Forward,
5766                &ctx,
5767            );
5768            let _ = config.processor_from_transform_with_context(
5769                &ctx,
5770                &ft,
5771                TransformDirection::Forward,
5772            );
5773            let _ = config.processor_named_transform_with_context(
5774                &ctx,
5775                &nt,
5776                TransformDirection::Forward,
5777            );
5778            let _ = config.processor_named_transform_name_with_context(
5779                &ctx,
5780                "UnitCompatNamedTransform",
5781                TransformDirection::Forward,
5782            );
5783        }
5784    }
5785
5786    #[test]
5787    #[allow(deprecated)]
5788    fn processor_basic_compat_aliases_no_crash() {
5789        let config = Config::raw().unwrap();
5790        let src_cs = crate::ColorSpace::create().unwrap();
5791        let dst_cs = crate::ColorSpace::create().unwrap();
5792
5793        let _ = config.get_processor_v1(&src_cs, &dst_cs);
5794        let _ = config.get_processor_v2("raw", "raw");
5795        let _ = config.get_processor_v4("raw", "sRGB", "Film", TransformDirection::Forward);
5796    }
5797
5798    #[test]
5799    #[allow(deprecated)]
5800    fn processor_context_compat_aliases_no_crash() {
5801        let config = Config::raw().unwrap();
5802        if let Some(ctx) = config.current_context() {
5803            let _ = config.get_processor_v3("raw", "raw", &ctx);
5804            let _ =
5805                config.get_processor_v5("raw", "sRGB", "Film", TransformDirection::Forward, &ctx);
5806        }
5807    }
5808
5809    #[test]
5810    #[allow(deprecated)]
5811    fn processor_transform_compat_aliases_no_crash() {
5812        let config = Config::raw().unwrap();
5813        let ft = crate::transform::FileTransform::create().unwrap();
5814
5815        let _ = config.get_processor_v10(&ft);
5816        let _ = config.get_processor_v11(&ft, TransformDirection::Forward);
5817
5818        if let Some(ctx) = config.current_context() {
5819            let _ = config.get_processor_v12(&ctx, &ft, TransformDirection::Forward);
5820        }
5821    }
5822
5823    #[test]
5824    #[allow(deprecated)]
5825    fn processor_named_transform_compat_aliases_no_crash() {
5826        let config = Config::raw().unwrap();
5827        let nt = configured_named_transform_for_processor_tests();
5828        config.add_named_transform(&nt);
5829
5830        let _ = config.get_processor_v6(&nt, TransformDirection::Forward);
5831        let _ = config.get_processor_v8("UnitCompatNamedTransform", TransformDirection::Forward);
5832
5833        if let Some(ctx) = config.current_context() {
5834            let _ = config.get_processor_v7(&ctx, &nt, TransformDirection::Forward);
5835            let _ = config.get_processor_v9(
5836                &ctx,
5837                "UnitCompatNamedTransform",
5838                TransformDirection::Forward,
5839            );
5840        }
5841    }
5842
5843    #[test]
5844    #[allow(deprecated)]
5845    fn processor_builtin_color_space_compat_aliases_no_crash() {
5846        let config = Config::raw().unwrap();
5847        let _ = config.get_processor_to_builtin_color_space(&config, "raw", "ACES2065-1");
5848        let _ = config.get_processor_from_builtin_color_space("ACES2065-1", &config, "raw");
5849    }
5850
5851    fn configured_named_transform_for_processor_tests() -> NamedTransform {
5852        let nt = NamedTransform::create().unwrap();
5853        nt.set_name("UnitCompatNamedTransform").unwrap();
5854
5855        let forward = crate::transform::MatrixTransform::scale(&[1.0, 1.0, 1.0, 1.0]).unwrap();
5856        let inverse = crate::transform::MatrixTransform::scale(&[1.0, 1.0, 1.0, 1.0]).unwrap();
5857        nt.set_transform(&forward, TransformDirection::Forward);
5858        nt.set_transform(&inverse, TransformDirection::Inverse);
5859        nt
5860    }
5861
5862    #[test]
5863    fn cache_id_with_context_no_crash() {
5864        let config = Config::raw().unwrap();
5865        if let Some(ctx) = config.current_context() {
5866            let _ = config.cache_id_for_context(&ctx);
5867            #[allow(deprecated)]
5868            let _ = config.cache_id_with_context(&ctx);
5869        }
5870    }
5871
5872    #[test]
5873    fn search_paths_no_crash() {
5874        let config = Config::raw().unwrap();
5875        assert!(config.try_clear_search_paths().is_ok());
5876        assert!(config.add_search_path("/some/path").is_ok());
5877    }
5878
5879    #[test]
5880    fn display_view_looks_no_crash() {
5881        let config = Config::raw().unwrap();
5882        let _ = config.display_view_looks("sRGB", "Film");
5883    }
5884
5885    #[test]
5886    fn default_scene_to_display_view_transform_no_crash() {
5887        let config = Config::raw().unwrap();
5888        let _ = config.default_scene_to_display_view_transform();
5889    }
5890
5891    #[test]
5892    fn color_spaces_looks_string_no_crash() {
5893        let config = Config::raw().unwrap();
5894        let spaces = config.try_color_spaces().unwrap();
5895        let looks = config.try_looks().unwrap();
5896        assert_eq!(config.color_spaces(), Some(spaces.clone()));
5897        assert_eq!(config.looks(), Some(looks.clone()));
5898        if crate::is_stub_build() {
5899            assert!(spaces.is_empty());
5900            assert!(looks.is_empty());
5901        }
5902    }
5903
5904    #[test]
5905    fn clear_named_view_transforms_no_crash() {
5906        let config = Config::raw().unwrap();
5907        config.try_clear_named_transforms().unwrap();
5908        config.try_clear_view_transforms().unwrap();
5909    }
5910
5911    #[test]
5912    fn environment_mode_no_crash() {
5913        let config = Config::raw().unwrap();
5914        let _ = config.environment_mode();
5915        config
5916            .set_environment_mode(crate::EnvironmentMode::LoadAll)
5917            .unwrap();
5918        config
5919            .set_environment_mode(crate::EnvironmentMode::LoadPredefined)
5920            .unwrap();
5921        config.load_environment().unwrap();
5922    }
5923
5924    #[test]
5925    #[allow(deprecated)]
5926    fn config_version_aliases_no_crash() {
5927        let config = Config::raw().unwrap();
5928        let _ = config.get_num_color_spaces_v1();
5929        let _ = config.get_color_space_name_by_index_v1(0);
5930        // A given OCIO release only accepts config versions up to its own.
5931        #[cfg(feature = "v2_5")]
5932        assert!(config.set_version(2, 5).is_ok());
5933        #[cfg(not(feature = "v2_5"))]
5934        assert!(config.set_version(2, 4).is_ok());
5935        config.upgrade_to_latest_version().unwrap();
5936    }
5937
5938    #[test]
5939    fn config_named_enumeration_wrappers_no_crash() {
5940        let config = Config::raw().unwrap();
5941        let _ = config.num_color_spaces();
5942        let _ = config.color_space_name_by_index(0);
5943        let _ = config.num_named_transforms();
5944        let _ = config.named_transform_name_by_index(0);
5945    }
5946
5947    #[test]
5948    #[allow(deprecated)]
5949    fn config_io_proxy_no_crash() {
5950        let config = Config::raw().unwrap();
5951        unsafe { config.set_config_io_proxy(std::ptr::null_mut()) };
5952        let _ = config.config_io_proxy();
5953    }
5954
5955    #[test]
5956    #[cfg_attr(ocio_stub, ignore = "requires a real OpenColorIO build")]
5957    fn config_io_proxy_object_no_crash() {
5958        if crate::is_stub_build() {
5959            return;
5960        }
5961
5962        let config = Config::raw().unwrap();
5963        let proxy = ConfigIOProxy::create().unwrap();
5964        proxy.set_config_data("ocio_profile_version: 2\nroles:\n  default: raw\ncolorspaces:\n  - !<ColorSpace> {name: raw, isdata: true}\n").unwrap();
5965        config.set_config_io_proxy_object(&proxy).unwrap();
5966        let _ = config.config_io_proxy_object();
5967    }
5968
5969    #[test]
5970    #[cfg_attr(ocio_stub, ignore = "requires a real OpenColorIO build")]
5971    fn create_from_config_io_proxy_real_behavior() {
5972        if crate::is_stub_build() {
5973            return;
5974        }
5975
5976        let proxy = ConfigIOProxy::create().expect("config io proxy");
5977        let config_text = std::fs::read_to_string("tests/data/configs/context_test1/config.ocio")
5978            .expect("config text");
5979        let lut = std::fs::read("tests/data/configs/context_test1/lut1.clf").expect("lut");
5980        proxy
5981            .set_config_data(&config_text)
5982            .expect("set config data");
5983        proxy
5984            .set_lut_data("E:/virtual/context/lut1.clf", &lut, "lut1-hash")
5985            .expect("set lut data");
5986
5987        let config = Config::from_config_io_proxy(&proxy).expect("config from proxy");
5988        config
5989            .set_working_dir("E:/virtual/context")
5990            .expect("working dir");
5991
5992        let processor = config
5993            .processor("plain_lut1_cs", "reference")
5994            .expect("processor");
5995        let cpu = processor.optimized_cpu_processor(0).expect("cpu processor");
5996        let mut pixel = [1.0f32, 1.0, 1.0, 1.0];
5997        cpu.apply_rgba(&mut pixel);
5998        assert!((pixel[0] - 5.0).abs() < 1e-5);
5999        assert!((pixel[1] - 5.0).abs() < 1e-5);
6000        assert!((pixel[2] - 5.0).abs() < 1e-5);
6001    }
6002
6003    #[test]
6004    #[allow(deprecated)]
6005    fn config_io_proxy_compat_alias_no_crash() {
6006        let config = Config::raw().unwrap();
6007        let _ = config.get_config_io_proxy();
6008    }
6009
6010    #[cfg(feature = "v2_5")]
6011    #[test]
6012    #[allow(deprecated)]
6013    fn active_display_view_management_v251_no_crash() {
6014        let config = Config::raw().unwrap();
6015        assert!(config.add_active_display("sRGB").is_ok());
6016        assert!(config.add_active_view("Film").is_ok());
6017        let _ = config.num_active_displays();
6018        let _ = config.num_active_views();
6019        let _ = config.get_active_display(0);
6020        let _ = config.get_active_view(0);
6021        assert!(config.remove_active_display("sRGB").is_ok());
6022        assert!(config.remove_active_view("Film").is_ok());
6023        config.clear_active_displays();
6024        config.clear_active_views();
6025    }
6026
6027    #[test]
6028    #[allow(deprecated)]
6029    fn display_view_v2_and_view_transform_aliases_no_crash() {
6030        let config = Config::raw().unwrap();
6031        let vt = crate::ViewTransform::create(crate::ReferenceSpaceType::Scene).unwrap();
6032        assert!(vt.set_name("MyViewTransform").is_ok());
6033        let identity = crate::transform::MatrixTransform::identity().unwrap();
6034        vt.set_transform(
6035            Some(&identity),
6036            crate::ViewTransformDirection::FromReference,
6037        );
6038        config.add_view_transform(&vt);
6039
6040        assert!(config
6041            .set_default_view_transform_name("MyViewTransform")
6042            .is_ok());
6043        let _ = config.get_default_view_transform_name();
6044        assert!(config
6045            .add_display_view_v2("sRGB", "Film", "MyViewTransform", "raw", "", "", "",)
6046            .is_ok());
6047        let _ = config.get_num_views_v2(crate::SearchReferenceSpaceType::Scene, "sRGB");
6048        let _ = config.get_view_v2(crate::SearchReferenceSpaceType::Scene, "sRGB", 0);
6049    }
6050
6051    #[test]
6052    fn view_transforms_named_wrappers_no_crash() {
6053        let config = Config::raw().unwrap();
6054        let vt = crate::ViewTransform::create(crate::ReferenceSpaceType::Scene).unwrap();
6055        assert!(vt.set_name("MyViewTransform").is_ok());
6056        let identity = crate::transform::MatrixTransform::identity().unwrap();
6057        vt.set_transform(
6058            Some(&identity),
6059            crate::ViewTransformDirection::FromReference,
6060        );
6061        config.add_view_transform(&vt);
6062
6063        assert!(config
6064            .add_display_view_detailed("sRGB", "Film", "MyViewTransform", "raw", "", "", "")
6065            .is_ok());
6066        let _ = config.virtual_display_num_views(crate::SearchReferenceSpaceType::Scene);
6067        let _ = config.virtual_display_view(crate::SearchReferenceSpaceType::Scene, 0);
6068    }
6069
6070    #[test]
6071    fn virtual_display_named_metadata_no_crash() {
6072        let config = Config::raw().unwrap();
6073        assert!(config
6074            .add_shared_view("SharedView", "MyViewTransform", "raw", "", "", "")
6075            .is_ok());
6076        assert!(config.add_display_shared_view("sRGB", "SharedView").is_ok());
6077        assert!(config.add_virtual_display_shared_view("SharedView").is_ok());
6078        assert!(config
6079            .add_virtual_display_view("VirtualFilm", "MyViewTransform", "raw", "", "", "")
6080            .is_ok());
6081        let _ = config.virtual_display_num_views(crate::SearchReferenceSpaceType::Scene);
6082        let _ = config.virtual_display_view(crate::SearchReferenceSpaceType::Scene, 0);
6083        let _ = config.virtual_display_view_transform_name("VirtualFilm");
6084        let _ = config.virtual_display_view_color_space_name("VirtualFilm");
6085        let _ = config.virtual_display_view_looks("VirtualFilm");
6086        let _ = config.virtual_display_view_rule("VirtualFilm");
6087        let _ = config.virtual_display_view_description("VirtualFilm");
6088        assert!(config.remove_virtual_display_view("VirtualFilm").is_ok());
6089        config.clear_virtual_display();
6090    }
6091
6092    #[cfg(feature = "v2_5")]
6093    #[test]
6094    #[allow(deprecated)]
6095    fn virtual_display_management_no_crash() {
6096        let config = Config::raw().unwrap();
6097        assert!(config
6098            .add_shared_view("SharedView", "MyViewTransform", "raw", "", "", "")
6099            .is_ok());
6100        assert!(config.add_display_shared_view("sRGB", "SharedView").is_ok());
6101        assert!(config.add_virtual_display_shared_view("SharedView").is_ok());
6102        assert!(config
6103            .add_virtual_display_view("VirtualFilm", "MyViewTransform", "raw", "", "", "")
6104            .is_ok());
6105        let _ = config.get_virtual_display_num_views(crate::SearchReferenceSpaceType::Scene);
6106        let _ = config.get_virtual_display_view(crate::SearchReferenceSpaceType::Scene, 0);
6107        let _ = config.get_virtual_display_view_transform_name("VirtualFilm");
6108        let _ = config.get_virtual_display_view_color_space_name("VirtualFilm");
6109        let _ = config.get_virtual_display_view_looks("VirtualFilm");
6110        let _ = config.get_virtual_display_view_rule("VirtualFilm");
6111        let _ = config.get_virtual_display_view_description("VirtualFilm");
6112        assert!(config.remove_virtual_display_view("VirtualFilm").is_ok());
6113        config.clear_virtual_display();
6114    }
6115
6116    #[test]
6117    #[allow(deprecated)]
6118    fn viewing_rules_pointer_round_trip_no_crash() {
6119        let config = Config::raw().unwrap();
6120        let ptr = unsafe { config.get_viewing_rules() };
6121        if !ptr.is_null() {
6122            unsafe { config.set_viewing_rules(ptr) };
6123        }
6124    }
6125
6126    #[test]
6127    #[allow(deprecated)]
6128    fn builtin_config_entry_points_no_crash() {
6129        if let Ok(registry) = crate::BuiltinConfigRegistry::get() {
6130            if registry.num_builtin_configs() > 0 {
6131                if let Some(name) = registry.config_name(0) {
6132                    let config = Config::create_from_builtin_config(&name).unwrap();
6133                    let _ = config.validate();
6134                    let _ = config.get_num_displays_all();
6135                    let _ = config.get_display_all(0);
6136                }
6137            }
6138        }
6139    }
6140}