Skip to main content

ocio_rs/
config_merging.rs

1//! Native OCIO 2.5.1+ configuration merging.
2use crate::{ColorSpace, Config, ConstConfig, OcioError, Result};
3use std::{
4    ffi::{c_char, c_void, CStr, CString},
5    ptr::NonNull,
6};
7
8unsafe fn text<'a>(value: *const c_char) -> &'a CStr {
9    if value.is_null() {
10        c""
11    } else {
12        unsafe { CStr::from_ptr(value) }
13    }
14}
15
16/// Conflict policy used by OpenColorIO when merging a configuration section.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18#[repr(i32)]
19pub enum MergeStrategy {
20    PreferInput = 0,
21    PreferBase = 1,
22    InputOnly = 2,
23    BaseOnly = 3,
24    Remove = 4,
25    Unspecified = 5,
26}
27impl MergeStrategy {
28    fn from_native(value: i32) -> Result<Self> {
29        match value {
30            0 => Ok(Self::PreferInput),
31            1 => Ok(Self::PreferBase),
32            2 => Ok(Self::InputOnly),
33            3 => Ok(Self::BaseOnly),
34            4 => Ok(Self::Remove),
35            5 => Ok(Self::Unspecified),
36            _ => Err(OcioError::Ocio(format!("Unknown merge strategy: {value}"))),
37        }
38    }
39}
40
41/// Owned native configuration merge parameters.
42pub struct ConfigMergingParameters {
43    handle: NonNull<c_void>,
44}
45impl ConfigMergingParameters {
46    /// Serialize using OCIO's diagnostic stream operator.
47    pub fn serialize(&self) -> Result<String> {
48        crate::app_helpers::serialize_app_helper(self.handle, 5)
49    }
50    /// Create via the native merge API.
51    pub fn create() -> Result<Self> {
52        crate::clear_last_error();
53        let value = unsafe { ocio_sys::ocio_config_merging_parameters_create() };
54        Ok(Self {
55            handle: crate::handle_result(value)?,
56        })
57    }
58
59    /// Create an editable copy via the native merge API.
60    ///
61    /// OCIO copies the parameters but shares their internal override config;
62    /// changes to search paths, environment, displays, and views are visible
63    /// through both copies.
64    pub fn create_editable_copy(&self) -> Result<Self> {
65        crate::clear_last_error();
66        let value = unsafe {
67            ocio_sys::ocio_config_merging_parameters_create_editable_copy(self.handle.as_ptr())
68        };
69        Ok(Self {
70            handle: crate::handle_result(value)?,
71        })
72    }
73
74    /// Base config name via the native merge API.
75    pub fn base_config_name(&self) -> Result<&CStr> {
76        crate::clear_last_error();
77        let value = unsafe {
78            ocio_sys::ocio_config_merging_parameters_get_base_config_name(self.handle.as_ptr())
79        };
80        crate::ocio_call_status()?;
81        Ok(unsafe { text(value) })
82    }
83
84    /// Set base config name via the native merge API.
85    pub fn set_base_config_name(&mut self, value: &CStr) -> Result<()> {
86        crate::clear_last_error();
87        unsafe {
88            ocio_sys::ocio_config_merging_parameters_set_base_config_name(
89                self.handle.as_ptr(),
90                value.as_ptr(),
91            )
92        };
93        crate::ocio_call_status()
94    }
95
96    /// Input config name via the native merge API.
97    pub fn input_config_name(&self) -> Result<&CStr> {
98        crate::clear_last_error();
99        let value = unsafe {
100            ocio_sys::ocio_config_merging_parameters_get_input_config_name(self.handle.as_ptr())
101        };
102        crate::ocio_call_status()?;
103        Ok(unsafe { text(value) })
104    }
105
106    /// Set input config name via the native merge API.
107    pub fn set_input_config_name(&mut self, value: &CStr) -> Result<()> {
108        crate::clear_last_error();
109        unsafe {
110            ocio_sys::ocio_config_merging_parameters_set_input_config_name(
111                self.handle.as_ptr(),
112                value.as_ptr(),
113            )
114        };
115        crate::ocio_call_status()
116    }
117
118    /// Output name via the native merge API.
119    pub fn output_name(&self) -> Result<&CStr> {
120        crate::clear_last_error();
121        let value = unsafe {
122            ocio_sys::ocio_config_merging_parameters_get_output_name(self.handle.as_ptr())
123        };
124        crate::ocio_call_status()?;
125        Ok(unsafe { text(value) })
126    }
127
128    /// Set output name via the native merge API.
129    pub fn set_output_name(&mut self, value: &CStr) -> Result<()> {
130        crate::clear_last_error();
131        unsafe {
132            ocio_sys::ocio_config_merging_parameters_set_output_name(
133                self.handle.as_ptr(),
134                value.as_ptr(),
135            )
136        };
137        crate::ocio_call_status()
138    }
139
140    /// Input family prefix via the native merge API.
141    pub fn input_family_prefix(&self) -> Result<&CStr> {
142        crate::clear_last_error();
143        let value = unsafe {
144            ocio_sys::ocio_config_merging_parameters_get_input_family_prefix(self.handle.as_ptr())
145        };
146        crate::ocio_call_status()?;
147        Ok(unsafe { text(value) })
148    }
149
150    /// Set input family prefix via the native merge API.
151    pub fn set_input_family_prefix(&mut self, value: &CStr) -> Result<()> {
152        crate::clear_last_error();
153        unsafe {
154            ocio_sys::ocio_config_merging_parameters_set_input_family_prefix(
155                self.handle.as_ptr(),
156                value.as_ptr(),
157            )
158        };
159        crate::ocio_call_status()
160    }
161
162    /// Base family prefix via the native merge API.
163    pub fn base_family_prefix(&self) -> Result<&CStr> {
164        crate::clear_last_error();
165        let value = unsafe {
166            ocio_sys::ocio_config_merging_parameters_get_base_family_prefix(self.handle.as_ptr())
167        };
168        crate::ocio_call_status()?;
169        Ok(unsafe { text(value) })
170    }
171
172    /// Set base family prefix via the native merge API.
173    pub fn set_base_family_prefix(&mut self, value: &CStr) -> Result<()> {
174        crate::clear_last_error();
175        unsafe {
176            ocio_sys::ocio_config_merging_parameters_set_base_family_prefix(
177                self.handle.as_ptr(),
178                value.as_ptr(),
179            )
180        };
181        crate::ocio_call_status()
182    }
183
184    /// Name via the native merge API.
185    pub fn name(&self) -> Result<&CStr> {
186        crate::clear_last_error();
187        let value =
188            unsafe { ocio_sys::ocio_config_merging_parameters_get_name(self.handle.as_ptr()) };
189        crate::ocio_call_status()?;
190        Ok(unsafe { text(value) })
191    }
192
193    /// Set name via the native merge API.
194    pub fn set_name(&mut self, value: &CStr) -> Result<()> {
195        crate::clear_last_error();
196        unsafe {
197            ocio_sys::ocio_config_merging_parameters_set_name(self.handle.as_ptr(), value.as_ptr())
198        };
199        crate::ocio_call_status()
200    }
201
202    /// Description via the native merge API.
203    pub fn description(&self) -> Result<&CStr> {
204        crate::clear_last_error();
205        let value = unsafe {
206            ocio_sys::ocio_config_merging_parameters_get_description(self.handle.as_ptr())
207        };
208        crate::ocio_call_status()?;
209        Ok(unsafe { text(value) })
210    }
211
212    /// Set description via the native merge API.
213    pub fn set_description(&mut self, value: &CStr) -> Result<()> {
214        crate::clear_last_error();
215        unsafe {
216            ocio_sys::ocio_config_merging_parameters_set_description(
217                self.handle.as_ptr(),
218                value.as_ptr(),
219            )
220        };
221        crate::ocio_call_status()
222    }
223
224    /// Search path as an owned snapshot of the shared native override config.
225    pub fn search_path(&self) -> Result<CString> {
226        crate::clear_last_error();
227        let value = unsafe {
228            ocio_sys::ocio_config_merging_parameters_get_search_path(self.handle.as_ptr())
229        };
230        crate::ocio_call_status()?;
231        Ok(unsafe { text(value) }.to_owned())
232    }
233
234    /// Set search path via the native merge API.
235    pub fn set_search_path(&mut self, value: &CStr) -> Result<()> {
236        crate::clear_last_error();
237        unsafe {
238            ocio_sys::ocio_config_merging_parameters_set_search_path(
239                self.handle.as_ptr(),
240                value.as_ptr(),
241            )
242        };
243        crate::ocio_call_status()
244    }
245
246    /// Active displays as an owned snapshot of the shared native override config.
247    pub fn active_displays(&self) -> Result<CString> {
248        crate::clear_last_error();
249        let value = unsafe {
250            ocio_sys::ocio_config_merging_parameters_get_active_displays(self.handle.as_ptr())
251        };
252        crate::ocio_call_status()?;
253        Ok(unsafe { text(value) }.to_owned())
254    }
255
256    /// Set active displays via the native merge API.
257    pub fn set_active_displays(&mut self, value: &CStr) -> Result<()> {
258        crate::clear_last_error();
259        unsafe {
260            ocio_sys::ocio_config_merging_parameters_set_active_displays(
261                self.handle.as_ptr(),
262                value.as_ptr(),
263            )
264        };
265        crate::ocio_call_status()
266    }
267
268    /// Active views as an owned snapshot of the shared native override config.
269    pub fn active_views(&self) -> Result<CString> {
270        crate::clear_last_error();
271        let value = unsafe {
272            ocio_sys::ocio_config_merging_parameters_get_active_views(self.handle.as_ptr())
273        };
274        crate::ocio_call_status()?;
275        Ok(unsafe { text(value) }.to_owned())
276    }
277
278    /// Set active views via the native merge API.
279    pub fn set_active_views(&mut self, value: &CStr) -> Result<()> {
280        crate::clear_last_error();
281        unsafe {
282            ocio_sys::ocio_config_merging_parameters_set_active_views(
283                self.handle.as_ptr(),
284                value.as_ptr(),
285            )
286        };
287        crate::ocio_call_status()
288    }
289
290    /// Inactive color spaces as an owned snapshot of the shared native override config.
291    pub fn inactive_color_spaces(&self) -> Result<CString> {
292        crate::clear_last_error();
293        let value = unsafe {
294            ocio_sys::ocio_config_merging_parameters_get_inactive_color_spaces(self.handle.as_ptr())
295        };
296        crate::ocio_call_status()?;
297        Ok(unsafe { text(value) }.to_owned())
298    }
299
300    /// Set inactive color spaces via the native merge API.
301    pub fn set_inactive_color_spaces(&mut self, value: &CStr) -> Result<()> {
302        crate::clear_last_error();
303        unsafe {
304            ocio_sys::ocio_config_merging_parameters_set_inactive_color_spaces(
305                self.handle.as_ptr(),
306                value.as_ptr(),
307            )
308        };
309        crate::ocio_call_status()
310    }
311
312    /// Is input first via the native merge API.
313    pub fn is_input_first(&self) -> Result<bool> {
314        crate::clear_last_error();
315        let value = unsafe {
316            ocio_sys::ocio_config_merging_parameters_is_input_first(self.handle.as_ptr())
317        };
318        crate::ocio_call_status()?;
319        Ok(value)
320    }
321
322    /// Set input first via the native merge API.
323    pub fn set_input_first(&mut self, value: bool) -> Result<()> {
324        crate::clear_last_error();
325        unsafe {
326            ocio_sys::ocio_config_merging_parameters_set_input_first(self.handle.as_ptr(), value)
327        };
328        crate::ocio_call_status()
329    }
330
331    /// Is error on conflict via the native merge API.
332    pub fn is_error_on_conflict(&self) -> Result<bool> {
333        crate::clear_last_error();
334        let value = unsafe {
335            ocio_sys::ocio_config_merging_parameters_is_error_on_conflict(self.handle.as_ptr())
336        };
337        crate::ocio_call_status()?;
338        Ok(value)
339    }
340
341    /// Set error on conflict via the native merge API.
342    pub fn set_error_on_conflict(&mut self, value: bool) -> Result<()> {
343        crate::clear_last_error();
344        unsafe {
345            ocio_sys::ocio_config_merging_parameters_set_error_on_conflict(
346                self.handle.as_ptr(),
347                value,
348            )
349        };
350        crate::ocio_call_status()
351    }
352
353    /// Is avoid duplicates via the native merge API.
354    pub fn is_avoid_duplicates(&self) -> Result<bool> {
355        crate::clear_last_error();
356        let value = unsafe {
357            ocio_sys::ocio_config_merging_parameters_is_avoid_duplicates(self.handle.as_ptr())
358        };
359        crate::ocio_call_status()?;
360        Ok(value)
361    }
362
363    /// Set avoid duplicates via the native merge API.
364    pub fn set_avoid_duplicates(&mut self, value: bool) -> Result<()> {
365        crate::clear_last_error();
366        unsafe {
367            ocio_sys::ocio_config_merging_parameters_set_avoid_duplicates(
368                self.handle.as_ptr(),
369                value,
370            )
371        };
372        crate::ocio_call_status()
373    }
374
375    /// Is adjust input reference space via the native merge API.
376    pub fn is_adjust_input_reference_space(&self) -> Result<bool> {
377        crate::clear_last_error();
378        let value = unsafe {
379            ocio_sys::ocio_config_merging_parameters_is_adjust_input_reference_space(
380                self.handle.as_ptr(),
381            )
382        };
383        crate::ocio_call_status()?;
384        Ok(value)
385    }
386
387    /// Set adjust input reference space via the native merge API.
388    pub fn set_adjust_input_reference_space(&mut self, value: bool) -> Result<()> {
389        crate::clear_last_error();
390        unsafe {
391            ocio_sys::ocio_config_merging_parameters_set_adjust_input_reference_space(
392                self.handle.as_ptr(),
393                value,
394            )
395        };
396        crate::ocio_call_status()
397    }
398
399    /// Default strategy via the native merge API.
400    pub fn default_strategy(&self) -> Result<MergeStrategy> {
401        crate::clear_last_error();
402        let value = unsafe {
403            ocio_sys::ocio_config_merging_parameters_get_default_strategy(self.handle.as_ptr())
404        };
405        crate::ocio_call_status()?;
406        MergeStrategy::from_native(value)
407    }
408
409    /// Set default strategy via the native merge API.
410    pub fn set_default_strategy(&mut self, value: MergeStrategy) -> Result<()> {
411        crate::clear_last_error();
412        unsafe {
413            ocio_sys::ocio_config_merging_parameters_set_default_strategy(
414                self.handle.as_ptr(),
415                value as i32,
416            )
417        };
418        crate::ocio_call_status()
419    }
420
421    /// Roles via the native merge API.
422    pub fn roles(&self) -> Result<MergeStrategy> {
423        crate::clear_last_error();
424        let value =
425            unsafe { ocio_sys::ocio_config_merging_parameters_get_roles(self.handle.as_ptr()) };
426        crate::ocio_call_status()?;
427        MergeStrategy::from_native(value)
428    }
429
430    /// Set roles via the native merge API.
431    pub fn set_roles(&mut self, value: MergeStrategy) -> Result<()> {
432        crate::clear_last_error();
433        unsafe {
434            ocio_sys::ocio_config_merging_parameters_set_roles(self.handle.as_ptr(), value as i32)
435        };
436        crate::ocio_call_status()
437    }
438
439    /// File rules via the native merge API.
440    pub fn file_rules(&self) -> Result<MergeStrategy> {
441        crate::clear_last_error();
442        let value = unsafe {
443            ocio_sys::ocio_config_merging_parameters_get_file_rules(self.handle.as_ptr())
444        };
445        crate::ocio_call_status()?;
446        MergeStrategy::from_native(value)
447    }
448
449    /// Set file rules via the native merge API.
450    pub fn set_file_rules(&mut self, value: MergeStrategy) -> Result<()> {
451        crate::clear_last_error();
452        unsafe {
453            ocio_sys::ocio_config_merging_parameters_set_file_rules(
454                self.handle.as_ptr(),
455                value as i32,
456            )
457        };
458        crate::ocio_call_status()
459    }
460
461    /// Display views via the native merge API.
462    pub fn display_views(&self) -> Result<MergeStrategy> {
463        crate::clear_last_error();
464        let value = unsafe {
465            ocio_sys::ocio_config_merging_parameters_get_display_views(self.handle.as_ptr())
466        };
467        crate::ocio_call_status()?;
468        MergeStrategy::from_native(value)
469    }
470
471    /// Set display views via the native merge API.
472    pub fn set_display_views(&mut self, value: MergeStrategy) -> Result<()> {
473        crate::clear_last_error();
474        unsafe {
475            ocio_sys::ocio_config_merging_parameters_set_display_views(
476                self.handle.as_ptr(),
477                value as i32,
478            )
479        };
480        crate::ocio_call_status()
481    }
482
483    /// View transforms via the native merge API.
484    pub fn view_transforms(&self) -> Result<MergeStrategy> {
485        crate::clear_last_error();
486        let value = unsafe {
487            ocio_sys::ocio_config_merging_parameters_get_view_transforms(self.handle.as_ptr())
488        };
489        crate::ocio_call_status()?;
490        MergeStrategy::from_native(value)
491    }
492
493    /// Set view transforms via the native merge API.
494    pub fn set_view_transforms(&mut self, value: MergeStrategy) -> Result<()> {
495        crate::clear_last_error();
496        unsafe {
497            ocio_sys::ocio_config_merging_parameters_set_view_transforms(
498                self.handle.as_ptr(),
499                value as i32,
500            )
501        };
502        crate::ocio_call_status()
503    }
504
505    /// Looks via the native merge API.
506    pub fn looks(&self) -> Result<MergeStrategy> {
507        crate::clear_last_error();
508        let value =
509            unsafe { ocio_sys::ocio_config_merging_parameters_get_looks(self.handle.as_ptr()) };
510        crate::ocio_call_status()?;
511        MergeStrategy::from_native(value)
512    }
513
514    /// Set looks via the native merge API.
515    pub fn set_looks(&mut self, value: MergeStrategy) -> Result<()> {
516        crate::clear_last_error();
517        unsafe {
518            ocio_sys::ocio_config_merging_parameters_set_looks(self.handle.as_ptr(), value as i32)
519        };
520        crate::ocio_call_status()
521    }
522
523    /// Color spaces via the native merge API.
524    pub fn color_spaces(&self) -> Result<MergeStrategy> {
525        crate::clear_last_error();
526        let value = unsafe {
527            ocio_sys::ocio_config_merging_parameters_get_color_spaces(self.handle.as_ptr())
528        };
529        crate::ocio_call_status()?;
530        MergeStrategy::from_native(value)
531    }
532
533    /// Set color spaces via the native merge API.
534    pub fn set_color_spaces(&mut self, value: MergeStrategy) -> Result<()> {
535        crate::clear_last_error();
536        unsafe {
537            ocio_sys::ocio_config_merging_parameters_set_color_spaces(
538                self.handle.as_ptr(),
539                value as i32,
540            )
541        };
542        crate::ocio_call_status()
543    }
544
545    /// Named transforms via the native merge API.
546    pub fn named_transforms(&self) -> Result<MergeStrategy> {
547        crate::clear_last_error();
548        let value = unsafe {
549            ocio_sys::ocio_config_merging_parameters_get_named_transforms(self.handle.as_ptr())
550        };
551        crate::ocio_call_status()?;
552        MergeStrategy::from_native(value)
553    }
554
555    /// Set named transforms via the native merge API.
556    pub fn set_named_transforms(&mut self, value: MergeStrategy) -> Result<()> {
557        crate::clear_last_error();
558        unsafe {
559            ocio_sys::ocio_config_merging_parameters_set_named_transforms(
560                self.handle.as_ptr(),
561                value as i32,
562            )
563        };
564        crate::ocio_call_status()
565    }
566
567    /// Add search path via the native merge API.
568    pub fn add_search_path(&mut self, value: &CStr) -> Result<()> {
569        crate::clear_last_error();
570        unsafe {
571            ocio_sys::ocio_config_merging_parameters_add_search_path(
572                self.handle.as_ptr(),
573                value.as_ptr(),
574            )
575        };
576        crate::ocio_call_status()
577    }
578
579    /// Add environment var via the native merge API.
580    pub fn add_environment_var(&mut self, name: &CStr, value: &CStr) -> Result<()> {
581        crate::clear_last_error();
582        unsafe {
583            ocio_sys::ocio_config_merging_parameters_add_environment_var(
584                self.handle.as_ptr(),
585                name.as_ptr(),
586                value.as_ptr(),
587            )
588        };
589        crate::ocio_call_status()
590    }
591
592    /// Num environment vars via the native merge API.
593    pub fn num_environment_vars(&self) -> Result<i32> {
594        crate::clear_last_error();
595        let value = unsafe {
596            ocio_sys::ocio_config_merging_parameters_get_num_environment_vars(self.handle.as_ptr())
597        };
598        crate::ocio_call_status()?;
599        Ok(value)
600    }
601
602    /// Environment variable name as an owned snapshot of the shared override config.
603    pub fn environment_var(&self, index: i32) -> Result<CString> {
604        crate::clear_last_error();
605        let value = unsafe {
606            ocio_sys::ocio_config_merging_parameters_get_environment_var(
607                self.handle.as_ptr(),
608                index,
609            )
610        };
611        crate::ocio_call_status()?;
612        Ok(unsafe { text(value) }.to_owned())
613    }
614
615    /// Environment variable value as an owned snapshot of the shared override config.
616    pub fn environment_var_value(&self, index: i32) -> Result<CString> {
617        crate::clear_last_error();
618        let value = unsafe {
619            ocio_sys::ocio_config_merging_parameters_get_environment_var_value(
620                self.handle.as_ptr(),
621                index,
622            )
623        };
624        crate::ocio_call_status()?;
625        Ok(unsafe { text(value) }.to_owned())
626    }
627
628    /// Merge configs via the native merge API.
629    pub fn merge_configs(&self, base: &Config, input: &Config) -> Result<Config> {
630        crate::clear_last_error();
631        let value = unsafe {
632            ocio_sys::ocio_config_merging_parameters_merge_configs(
633                self.handle.as_ptr(),
634                base.handle.as_ptr(),
635                input.handle.as_ptr(),
636            )
637        };
638        Ok(Config {
639            handle: crate::handle_result(value)?,
640        })
641    }
642
643    /// Merge editable or retained read-only configs. Read-only configs are
644    /// copied to isolate native cache-flag changes during merge heuristics.
645    pub fn merge_configs_ref<'a, 'b>(
646        &self,
647        base: impl Into<crate::ConfigRef<'a>>,
648        input: impl Into<crate::ConfigRef<'b>>,
649    ) -> Result<Config> {
650        let base = base.into();
651        let input = input.into();
652        let base_copy = base.isolated_copy()?;
653        let input_copy = input.isolated_copy()?;
654        let (base, base_const) = base_copy
655            .as_ref()
656            .map_or(base, crate::ConfigRef::Editable)
657            .raw();
658        let (input, input_const) = input_copy
659            .as_ref()
660            .map_or(input, crate::ConfigRef::Editable)
661            .raw();
662        crate::clear_last_error();
663        let value = unsafe {
664            ocio_sys::ocio_config_merging_parameters_merge_config_refs(
665                self.handle.as_ptr(),
666                base,
667                base_const,
668                input,
669                input_const,
670            )
671        };
672        Ok(Config {
673            handle: crate::handle_result(value)?,
674        })
675    }
676
677    /// Merge color space via the native merge API.
678    pub fn merge_color_space(&self, base: &Config, input: &ColorSpace) -> Result<Config> {
679        crate::clear_last_error();
680        let value = unsafe {
681            ocio_sys::ocio_config_merging_parameters_merge_color_space(
682                self.handle.as_ptr(),
683                base.handle.as_ptr(),
684                input.handle.as_ptr(),
685            )
686        };
687        Ok(Config {
688            handle: crate::handle_result(value)?,
689        })
690    }
691
692    /// Merge an editable or retained read-only color space into an editable or
693    /// retained read-only config. A read-only config is copied to isolate native
694    /// cache-flag changes; the color-space handle is forwarded directly.
695    pub fn merge_color_space_ref<'a, 'b>(
696        &self,
697        base: impl Into<crate::ConfigRef<'a>>,
698        input: impl Into<crate::ColorSpaceRef<'b>>,
699    ) -> Result<Config> {
700        let base = base.into();
701        let base_copy = base.isolated_copy()?;
702        let (base, base_const) = base_copy
703            .as_ref()
704            .map_or(base, crate::ConfigRef::Editable)
705            .raw();
706        let (input, input_const) = input.into().raw();
707        crate::clear_last_error();
708        let value = unsafe {
709            ocio_sys::ocio_config_merging_parameters_merge_color_space_refs(
710                self.handle.as_ptr(),
711                base,
712                base_const,
713                input,
714                input_const,
715            )
716        };
717        Ok(Config {
718            handle: crate::handle_result(value)?,
719        })
720    }
721}
722impl Drop for ConfigMergingParameters {
723    fn drop(&mut self) {
724        unsafe { ocio_sys::ocio_config_merging_parameters_destroy(self.handle.as_ptr()) }
725    }
726}
727
728/// An owned OCIOM merge controller. Returned params and configs are editable copies.
729pub struct ConfigMerger {
730    handle: NonNull<c_void>,
731}
732impl ConfigMerger {
733    /// create using native OCIO.
734    pub fn create() -> Result<Self> {
735        crate::clear_last_error();
736        let value = unsafe { ocio_sys::ocio_config_merger_create() };
737        crate::ocio_call_status()?;
738        Ok(Self {
739            handle: crate::handle_result(value)?,
740        })
741    }
742
743    /// from file using native OCIO.
744    pub fn from_file(path: &CStr) -> Result<Self> {
745        crate::clear_last_error();
746        let value = unsafe { ocio_sys::ocio_config_merger_from_file(path.as_ptr()) };
747        crate::ocio_call_status()?;
748        Ok(Self {
749            handle: crate::handle_result(value)?,
750        })
751    }
752
753    /// create editable copy using native OCIO.
754    pub fn create_editable_copy(&self) -> Result<Self> {
755        crate::clear_last_error();
756        let value =
757            unsafe { ocio_sys::ocio_config_merger_create_editable_copy(self.handle.as_ptr()) };
758        crate::ocio_call_status()?;
759        Ok(Self {
760            handle: crate::handle_result(value)?,
761        })
762    }
763
764    /// set search path using native OCIO.
765    pub fn set_search_path(&mut self, v: &CStr) -> Result<()> {
766        crate::clear_last_error();
767        unsafe { ocio_sys::ocio_config_merger_set_search_path(self.handle.as_ptr(), v.as_ptr()) };
768        crate::ocio_call_status()
769    }
770
771    /// add search path using native OCIO.
772    pub fn add_search_path(&mut self, v: &CStr) -> Result<()> {
773        crate::clear_last_error();
774        unsafe { ocio_sys::ocio_config_merger_add_search_path(self.handle.as_ptr(), v.as_ptr()) };
775        crate::ocio_call_status()
776    }
777
778    /// num search paths using native OCIO.
779    pub fn num_search_paths(&self) -> Result<i32> {
780        crate::clear_last_error();
781        let value = unsafe { ocio_sys::ocio_config_merger_num_search_paths(self.handle.as_ptr()) };
782        crate::ocio_call_status()?;
783        Ok(value)
784    }
785
786    /// search path using native OCIO.
787    pub fn search_path(&self, index: i32) -> Result<&CStr> {
788        crate::clear_last_error();
789        let value =
790            unsafe { ocio_sys::ocio_config_merger_search_path(self.handle.as_ptr(), index) };
791        crate::ocio_call_status()?;
792        Ok(unsafe { text(value) })
793    }
794
795    /// set working dir using native OCIO.
796    pub fn set_working_dir(&mut self, v: &CStr) -> Result<()> {
797        crate::clear_last_error();
798        unsafe { ocio_sys::ocio_config_merger_set_working_dir(self.handle.as_ptr(), v.as_ptr()) };
799        crate::ocio_call_status()
800    }
801
802    /// working dir using native OCIO.
803    pub fn working_dir(&self) -> Result<&CStr> {
804        crate::clear_last_error();
805        let value = unsafe { ocio_sys::ocio_config_merger_working_dir(self.handle.as_ptr()) };
806        crate::ocio_call_status()?;
807        Ok(unsafe { text(value) })
808    }
809
810    /// num params using native OCIO.
811    pub fn num_params(&self) -> Result<i32> {
812        crate::clear_last_error();
813        let value = unsafe { ocio_sys::ocio_config_merger_num_params(self.handle.as_ptr()) };
814        crate::ocio_call_status()?;
815        Ok(value)
816    }
817
818    /// Return an editable copy of one set of merge parameters.
819    ///
820    /// As in OCIO, the copy shares its override configuration with the entry.
821    pub fn params(&self, index: i32) -> Result<Option<ConfigMergingParameters>> {
822        crate::clear_last_error();
823        let value = unsafe { ocio_sys::ocio_config_merger_params(self.handle.as_ptr(), index) };
824        crate::ocio_call_status()?;
825        Ok(NonNull::new(value).map(|handle| ConfigMergingParameters { handle }))
826    }
827
828    /// Add parameters by retaining the native handle. Later edits to `params`
829    /// are visible to this merger.
830    pub fn add_params(&mut self, params: &ConfigMergingParameters) -> Result<()> {
831        crate::clear_last_error();
832        unsafe {
833            ocio_sys::ocio_config_merger_add_params(self.handle.as_ptr(), params.handle.as_ptr())
834        };
835        crate::ocio_call_status()
836    }
837
838    /// merge configs using native OCIO.
839    pub fn merge_configs(&self) -> Result<Self> {
840        crate::clear_last_error();
841        let value = unsafe { ocio_sys::ocio_config_merger_merge_configs(self.handle.as_ptr()) };
842        crate::ocio_call_status()?;
843        Ok(Self {
844            handle: crate::handle_result(value)?,
845        })
846    }
847
848    /// Merge and retain OCIO's read-only merger result without copying the
849    /// returned merger or its completed configurations in the binding.
850    pub fn merge_configs_shared(&self) -> Result<ConstConfigMerger> {
851        crate::clear_last_error();
852        let value =
853            unsafe { ocio_sys::ocio_config_merger_merge_configs_shared(self.handle.as_ptr()) };
854        Ok(ConstConfigMerger {
855            handle: crate::handle_result(value)?,
856        })
857    }
858
859    /// num merged configs using native OCIO.
860    pub fn num_merged_configs(&self) -> Result<i32> {
861        crate::clear_last_error();
862        let value =
863            unsafe { ocio_sys::ocio_config_merger_num_merged_configs(self.handle.as_ptr()) };
864        crate::ocio_call_status()?;
865        Ok(value)
866    }
867
868    /// Copy a merged result into an editable configuration.
869    /// Index `-1` selects the final result; other out-of-range indices return `None`.
870    pub fn merged_config(&self, index: i32) -> Result<Option<Config>> {
871        crate::clear_last_error();
872        let value =
873            unsafe { ocio_sys::ocio_config_merger_merged_config(self.handle.as_ptr(), index) };
874        crate::ocio_call_status()?;
875        Ok(NonNull::new(value).map(|handle| Config { handle }))
876    }
877
878    /// Retain a merged result without copying the configuration.
879    /// Index `-1` selects the final result; other out-of-range indices return `None`.
880    pub fn merged_const_config(&self, index: i32) -> Result<Option<ConstConfig>> {
881        crate::clear_last_error();
882        let value = unsafe {
883            ocio_sys::ocio_config_merger_merged_const_config(self.handle.as_ptr(), index)
884        };
885        crate::ocio_call_status()?;
886        Ok(NonNull::new(value).map(|handle| ConstConfig { handle }))
887    }
888
889    /// serialize using native OCIO.
890    pub fn serialize(&self) -> Result<String> {
891        crate::clear_last_error();
892        let value = unsafe { ocio_sys::ocio_config_merger_serialize(self.handle.as_ptr()) };
893        crate::ocio_call_status()?;
894        Ok(unsafe { text(value) }.to_string_lossy().into_owned())
895    }
896
897    /// set version using native OCIO.
898    pub fn set_version(&mut self, major: u32, minor: u32) -> Result<()> {
899        crate::clear_last_error();
900        unsafe { ocio_sys::ocio_config_merger_set_version(self.handle.as_ptr(), major, minor) };
901        crate::ocio_call_status()
902    }
903
904    /// major version using native OCIO.
905    pub fn major_version(&self) -> Result<u32> {
906        crate::clear_last_error();
907        let value = unsafe { ocio_sys::ocio_config_merger_major_version(self.handle.as_ptr()) };
908        crate::ocio_call_status()?;
909        Ok(value)
910    }
911
912    /// minor version using native OCIO.
913    pub fn minor_version(&self) -> Result<u32> {
914        crate::clear_last_error();
915        let value = unsafe { ocio_sys::ocio_config_merger_minor_version(self.handle.as_ptr()) };
916        crate::ocio_call_status()?;
917        Ok(value)
918    }
919}
920impl Drop for ConfigMerger {
921    fn drop(&mut self) {
922        unsafe { ocio_sys::ocio_config_merger_destroy(self.handle.as_ptr()) }
923    }
924}
925
926/// A retained read-only merger returned by native OCIO.
927///
928/// Completed configurations can be retained without copying. Request an
929/// editable copy explicitly when mutation of the merger is needed.
930pub struct ConstConfigMerger {
931    handle: NonNull<c_void>,
932}
933
934impl ConstConfigMerger {
935    fn number(&self, field: i32) -> Result<i64> {
936        crate::clear_last_error();
937        let value =
938            unsafe { ocio_sys::ocio_const_config_merger_number(self.handle.as_ptr(), field) };
939        crate::ocio_call_status()?;
940        Ok(value)
941    }
942
943    fn native_text(&self, field: i32, index: i32) -> Result<&CStr> {
944        crate::clear_last_error();
945        let value =
946            unsafe { ocio_sys::ocio_const_config_merger_text(self.handle.as_ptr(), field, index) };
947        crate::ocio_call_status()?;
948        Ok(unsafe { text(value) })
949    }
950
951    /// Load an OCIOM file without making an editable merger copy.
952    pub fn from_file(path: &CStr) -> Result<Self> {
953        crate::clear_last_error();
954        let value = unsafe { ocio_sys::ocio_const_config_merger_from_file(path.as_ptr()) };
955        Ok(Self {
956            handle: crate::handle_result(value)?,
957        })
958    }
959
960    /// Run the native merger and retain its read-only result.
961    pub fn merge_configs(&self) -> Result<Self> {
962        crate::clear_last_error();
963        let value =
964            unsafe { ocio_sys::ocio_const_config_merger_merge_configs(self.handle.as_ptr()) };
965        Ok(Self {
966            handle: crate::handle_result(value)?,
967        })
968    }
969
970    /// Number of native search paths.
971    pub fn num_search_paths(&self) -> Result<i32> {
972        Ok(self.number(0)? as i32)
973    }
974
975    /// Borrow a native search path; an invalid index returns native empty text.
976    pub fn search_path(&self, index: i32) -> Result<&CStr> {
977        self.native_text(0, index)
978    }
979
980    /// Borrow the native working directory.
981    pub fn working_dir(&self) -> Result<&CStr> {
982        self.native_text(1, 0)
983    }
984
985    /// Number of native merge-parameter entries.
986    pub fn num_params(&self) -> Result<i32> {
987        Ok(self.number(1)? as i32)
988    }
989
990    /// Copy one parameter entry for safe editable access.
991    ///
992    /// As in OCIO, the copy shares its override configuration with the entry.
993    pub fn params(&self, index: i32) -> Result<Option<ConfigMergingParameters>> {
994        crate::clear_last_error();
995        let value = unsafe {
996            ocio_sys::ocio_const_config_merger_params(self.handle.as_ptr(), index, false)
997        };
998        crate::ocio_call_status()?;
999        Ok(NonNull::new(value).map(|handle| ConfigMergingParameters { handle }))
1000    }
1001
1002    /// Serialize the native merger to OCIOM text.
1003    pub fn serialize(&self) -> Result<String> {
1004        Ok(self.native_text(2, 0)?.to_string_lossy().into_owned())
1005    }
1006
1007    /// Major OCIOM format version.
1008    pub fn major_version(&self) -> Result<u32> {
1009        Ok(self.number(2)? as u32)
1010    }
1011
1012    /// Minor OCIOM format version.
1013    pub fn minor_version(&self) -> Result<u32> {
1014        Ok(self.number(3)? as u32)
1015    }
1016
1017    /// Return the number of completed merge steps.
1018    pub fn num_merged_configs(&self) -> Result<i32> {
1019        crate::clear_last_error();
1020        let value =
1021            unsafe { ocio_sys::ocio_const_config_merger_num_merged_configs(self.handle.as_ptr()) };
1022        crate::ocio_call_status()?;
1023        Ok(value)
1024    }
1025
1026    /// Retain a native result. Index `-1` selects the final result.
1027    pub fn merged_const_config(&self, index: i32) -> Result<Option<ConstConfig>> {
1028        crate::clear_last_error();
1029        let value = unsafe {
1030            ocio_sys::ocio_const_config_merger_merged_config(self.handle.as_ptr(), index)
1031        };
1032        crate::ocio_call_status()?;
1033        Ok(NonNull::new(value).map(|handle| ConstConfig { handle }))
1034    }
1035
1036    /// Create an editable copy using OCIO's native copy semantics.
1037    pub fn create_editable_copy(&self) -> Result<ConfigMerger> {
1038        crate::clear_last_error();
1039        let value =
1040            unsafe { ocio_sys::ocio_const_config_merger_editable_copy(self.handle.as_ptr()) };
1041        Ok(ConfigMerger {
1042            handle: crate::handle_result(value)?,
1043        })
1044    }
1045}
1046
1047impl Drop for ConstConfigMerger {
1048    fn drop(&mut self) {
1049        unsafe { ocio_sys::ocio_const_config_merger_destroy(self.handle.as_ptr()) }
1050    }
1051}