oiio-sys 0.4.1

Rust sys bindings for OpenImageIO https://github.com/AcademySoftwareFoundation/OpenImageIO
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
pub use ffi::*;

#[repr(i32)]
pub enum IBStorage {
    UNINITIALIZED,
    LOCALBUFFER,
    APPBUFFER,
    IMAGECACHE,
}

unsafe impl cxx::ExternType for IBStorage {
    type Id = cxx::type_id!("oiio::IBStorage");
    type Kind = cxx::kind::Trivial;
}

#[repr(i32)]
pub enum WrapMode {
    WrapDefault,
    WrapBlack,
    WrapClamp,
    WrapPeriodic,
    WrapMirror,
    _WrapLast,
}

unsafe impl cxx::ExternType for WrapMode {
    type Id = cxx::type_id!("oiio::WrapMode");
    type Kind = cxx::kind::Trivial;
}

#[repr(i32)]
pub enum InitializePixels {
    No = 0,
    Yes = 1,
}

unsafe impl cxx::ExternType for InitializePixels {
    type Id = cxx::type_id!("oiio::InitializePixels");
    type Kind = cxx::kind::Trivial;
}

// This is the raw, signature-compatible FFI layer. Safety contracts and
// operation-oriented arguments belong on the public wrappers in `oiio`.
#[allow(clippy::missing_safety_doc, clippy::too_many_arguments)]
#[cxx::bridge(namespace = oiio)]
mod ffi {
    unsafe extern "C++" {
        include!("oiio-sys/src/ffi_imagebuf.h");

        pub type ImageBuf;
        pub type ImageBufIteratorBase;
        pub type DeepData = crate::imageio::DeepData;
        pub type IBStorage = crate::imagebuf::IBStorage;
        pub type ImageCache = crate::imagecache::ImageCache;
        pub type ImageOutput = crate::imageio::ImageOutput;
        pub type ImageSpec = crate::imageio::ImageSpec;
        pub type InitializePixels = crate::imagebuf::InitializePixels;
        pub type IOProxy = crate::filesystem::IOProxy;
        pub type ROI = crate::imageio::ROI;
        pub type TypeDesc = crate::typedesc::TypeDesc;
        pub type WrapMode = crate::imagebuf::WrapMode;

        // ImageBuf
        pub fn imagebuf_default() -> UniquePtr<ImageBuf>;

        pub unsafe fn imagebuf_new_from_file(
            name: &str,
            subimage: i32,
            miplevel: i32,
            imagecache: SharedPtr<ImageCache>,
            config: *const ImageSpec,
            ioproxy: *mut IOProxy,
        ) -> UniquePtr<ImageBuf>;

        pub fn imagebuf_new_from_spec(
            spec: &ImageSpec,
            zero: InitializePixels,
        ) -> UniquePtr<ImageBuf>;

        pub fn imagebuf_new_from_spec_checked(
            spec: &ImageSpec,
            error: &mut String,
        ) -> UniquePtr<ImageBuf>;

        pub unsafe fn imagebuf_new_from_buffer(
            spec: &ImageSpec,
            buffer: *mut u8,
            xstride: i64,
            ystride: i64,
            zstride: i64,
        ) -> UniquePtr<ImageBuf>;

        /// Null with `error` set when the copy's pixels could not be
        /// allocated; the raw copy constructor returns the broken copy with
        /// the source's valid flag still set.
        pub fn imagebuf_clone_checked(
            imagebuf: &ImageBuf,
            error: &mut String,
        ) -> UniquePtr<ImageBuf>;

        pub fn imagebuf_reset(imagebuf: Pin<&mut ImageBuf>);

        pub unsafe fn imagebuf_reset_from_file(
            imagebuf: Pin<&mut ImageBuf>,
            name: &str,
            subimage: i32,
            miplevel: i32,
            imagecache: SharedPtr<ImageCache>,
            config: *const ImageSpec,
            ioproxy: *mut IOProxy,
        );

        pub fn imagebuf_reset_from_spec(
            imagebuf: Pin<&mut ImageBuf>,
            spec: &ImageSpec,
            zero: InitializePixels,
        );

        pub unsafe fn imagebuf_reset_from_buffer(
            imagebuf: Pin<&mut ImageBuf>,
            spec: &ImageSpec,
            buffer: *mut u8,
            xstride: i64,
            ystride: i64,
            zstride: i64,
        );

        pub fn imagebuf_make_writeable(imagebuf: Pin<&mut ImageBuf>, keep_cache_type: bool)
            -> bool;

        pub fn imagebuf_read(
            imagebuf: Pin<&mut ImageBuf>,
            subimage: i32,
            miplevel: i32,
            force: bool,
            convert: TypeDesc,
        ) -> bool;

        pub fn imagebuf_read_subset(
            imagebuf: Pin<&mut ImageBuf>,
            subimage: i32,
            miplevel: i32,
            chbegin: i32,
            chend: i32,
            force: bool,
            convert: TypeDesc,
        ) -> bool;

        pub fn imagebuf_init_spec(
            imagebuf: Pin<&mut ImageBuf>,
            filename: &str,
            subimage: i32,
            miplevel: i32,
        ) -> bool;

        pub fn imagebuf_write(
            imagebuf: Pin<&mut ImageBuf>,
            filename: &str,
            dtype: TypeDesc,
            fileformat: &str,
        ) -> bool;

        pub fn imagebuf_set_write_format(imagebuf: Pin<&mut ImageBuf>, format: TypeDesc);

        pub fn imagebuf_set_write_format_from_channel_names(
            imagebuf: Pin<&mut ImageBuf>,
            format: &[TypeDesc],
        );

        pub fn imagebuf_set_write_tiles(
            imagebuf: Pin<&mut ImageBuf>,
            width: i32,
            height: i32,
            depth: i32,
        );

        pub unsafe fn imagebuf_set_write_ioproxy(
            imagebuf: Pin<&mut ImageBuf>,
            ioproxy: *mut IOProxy,
        );

        pub unsafe fn imagebuf_write_to_imageoutput(
            imagebuf: Pin<&mut ImageBuf>,
            out: *mut ImageOutput,
        ) -> bool;

        pub fn imagebuf_copy_metadata(imagebuf: Pin<&mut ImageBuf>, src: &ImageBuf);

        pub fn imagebuf_copy_pixels(imagebuf: Pin<&mut ImageBuf>, src: &ImageBuf) -> bool;

        pub fn imagebuf_copy(
            imagebuf: Pin<&mut ImageBuf>,
            src: &ImageBuf,
            format: TypeDesc,
        ) -> bool;

        pub fn imagebuf_copy_to_imagebuf(
            imagebuf: &ImageBuf,
            format: TypeDesc,
        ) -> UniquePtr<ImageBuf>;

        pub fn imagebuf_swap(imagebuf: Pin<&mut ImageBuf>, other: Pin<&mut ImageBuf>);

        pub fn imagebuf_getchannel(
            imagebuf: &ImageBuf,
            x: i32,
            y: i32,
            z: i32,
            c: i32,
            wrap: WrapMode,
        ) -> f32;

        pub unsafe fn imagebuf_getpixel(
            imagebuf: &ImageBuf,
            x: i32,
            y: i32,
            z: i32,
            pixel: *mut f32,
            maxchannels: i32,
            wrap: WrapMode,
        );

        pub unsafe fn imagebuf_interppixel(
            imagebuf: &ImageBuf,
            x: f32,
            y: f32,
            pixel: *mut f32,
            wrap: WrapMode,
        );

        pub unsafe fn imagebuf_interppixel_NDC(
            imagebuf: &ImageBuf,
            s: f32,
            t: f32,
            pixel: *mut f32,
            wrap: WrapMode,
        );

        pub unsafe fn imagebuf_interppixel_bicubic(
            imagebuf: &ImageBuf,
            x: f32,
            y: f32,
            pixel: *mut f32,
            wrap: WrapMode,
        );

        pub unsafe fn imagebuf_interppixel_bicubic_NDC(
            imagebuf: &ImageBuf,
            s: f32,
            t: f32,
            pixel: *mut f32,
            wrap: WrapMode,
        );

        pub fn imagebuf_setpixel(
            imagebuf: Pin<&mut ImageBuf>,
            x: i32,
            y: i32,
            z: i32,
            pixel: &[f32],
        );

        pub fn imagebuf_setpixel_i(imagebuf: Pin<&mut ImageBuf>, i: i32, pixel: &[f32]);

        pub unsafe fn imagebuf_setpixel_with_coordinates(
            imagebuf: Pin<&mut ImageBuf>,
            x: i32,
            y: i32,
            z: i32,
            pixel: *const f32,
            maxchannels: i32,
        );

        pub unsafe fn imagebuf_get_pixels(
            imagebuf: &ImageBuf,
            roi: ROI,
            format: TypeDesc,
            result: *mut u8,
            xstride: i64,
            ystride: i64,
            zstride: i64,
        ) -> bool;

        pub unsafe fn imagebuf_set_pixels(
            imagebuf: Pin<&mut ImageBuf>,
            roi: ROI,
            format: TypeDesc,
            data: *const u8,
            xstride: i64,
            ystride: i64,
            zstride: i64,
        ) -> bool;

        /// Safety: the buffer must be writable for its full length.
        pub unsafe fn imagebuf_get_pixels_span(
            imagebuf: &ImageBuf,
            roi: &ROI,
            format: TypeDesc,
            result: &mut [u8],
        ) -> bool;

        /// Safety: the buffer must hold initialized values of `format`.
        pub unsafe fn imagebuf_set_pixels_span(
            imagebuf: Pin<&mut ImageBuf>,
            roi: &ROI,
            format: TypeDesc,
            data: &[u8],
        ) -> bool;

        pub fn imagebuf_initialized(imagebuf: &ImageBuf) -> bool;

        pub fn imagebuf_storage(imagebuf: &ImageBuf) -> IBStorage;

        pub fn imagebuf_spec(imagebuf: &ImageBuf) -> &ImageSpec;

        pub fn imagebuf_specmod(imagebuf: Pin<&mut ImageBuf>) -> Pin<&mut ImageSpec>;

        pub fn imagebuf_nativespec(imagebuf: &ImageBuf) -> &ImageSpec;

        pub fn imagebuf_has_thumbnail(imagebuf: &ImageBuf) -> bool;

        pub fn imagebuf_get_thumbnail(imagebuf: &ImageBuf) -> SharedPtr<ImageBuf>;

        pub fn imagebuf_set_thumbnail(imagebuf: Pin<&mut ImageBuf>, thumb: &ImageBuf);

        pub fn imagebuf_clear_thumbnail(imagebuf: Pin<&mut ImageBuf>);

        pub fn imagebuf_name(imagebuf: &ImageBuf) -> &str;

        pub fn imagebuf_file_format_name(imagebuf: &ImageBuf) -> &str;

        pub fn imagebuf_subimage(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_nsubimages(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_miplevel(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_nmiplevels(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_nchannels(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_xbegin(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_ybegin(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_zbegin(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_xend(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_yend(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_zend(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_xmin(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_ymin(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_zmin(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_xmax(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_ymax(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_zmax(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_orientation(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_set_orientation(imagebuf: Pin<&mut ImageBuf>, orient: i32);

        pub fn imagebuf_oriented_width(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_oriented_height(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_oriented_x(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_oriented_y(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_oriented_full_width(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_oriented_full_height(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_oriented_full_x(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_oriented_full_y(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_set_origin(imagebuf: Pin<&mut ImageBuf>, x: i32, y: i32, z: i32);

        pub fn imagebuf_set_full(
            imagebuf: Pin<&mut ImageBuf>,
            xbegin: i32,
            xend: i32,
            ybegin: i32,
            yend: i32,
            zbegin: i32,
            zend: i32,
        );

        pub fn imagebuf_roi(imagebuf: &ImageBuf) -> ROI;

        pub fn imagebuf_roi_full(imagebuf: &ImageBuf) -> ROI;

        pub fn imagebuf_set_roi_full(imagebuf: Pin<&mut ImageBuf>, newroi: &ROI);

        pub fn imagebuf_contains_roi(imagebuf: &ImageBuf, roi: ROI) -> bool;

        pub fn imagebuf_pixels_valid(imagebuf: &ImageBuf) -> bool;

        pub fn imagebuf_pixeltype(imagebuf: &ImageBuf) -> TypeDesc;

        pub unsafe fn imagebuf_localpixels_mut(imagebuf: Pin<&mut ImageBuf>) -> *mut u8;

        pub unsafe fn imagebuf_localpixels(imagebuf: &ImageBuf) -> *const u8;

        pub fn imagebuf_pixel_stride(imagebuf: &ImageBuf) -> i64;

        pub fn imagebuf_scanline_stride(imagebuf: &ImageBuf) -> i64;

        pub fn imagebuf_z_stride(imagebuf: &ImageBuf) -> i64;

        pub fn imagebuf_contiguous(imagebuf: &ImageBuf) -> bool;

        pub fn imagebuf_cachedpixels(imagebuf: &ImageBuf) -> bool;

        pub fn imagebuf_imagecache(imagebuf: &ImageBuf) -> SharedPtr<ImageCache>;

        pub unsafe fn imagebuf_pixeladdr(
            imagebuf: &ImageBuf,
            x: i32,
            y: i32,
            z: i32,
            ch: i32,
        ) -> *const u8;

        pub unsafe fn imagebuf_pixeladdr_mut(
            imagebuf: &ImageBuf,
            x: i32,
            y: i32,
            z: i32,
            ch: i32,
        ) -> *mut u8;

        pub fn imagebuf_pixelindex(
            imagebuf: &ImageBuf,
            x: i32,
            y: i32,
            z: i32,
            check_range: bool,
        ) -> i32;

        pub fn imagebuf_merge_metadata(
            imagebuf: Pin<&mut ImageBuf>,
            src: &ImageBuf,
            override_existing: bool,
            pattern: &str,
            error: &mut String,
        ) -> bool;

        pub fn imagebuf_threads(imagebuf: &ImageBuf) -> i32;

        pub fn imagebuf_set_threads(imagebuf: Pin<&mut ImageBuf>, count: i32);

        pub fn imagebuf_error(imagebuf: &ImageBuf, message: &str);

        pub fn imagebuf_has_error(imagebuf: &ImageBuf) -> bool;

        pub fn imagebuf_geterror(imagebuf: &ImageBuf, clear: bool) -> String;

        pub fn imagebuf_deep(imagebuf: &ImageBuf) -> bool;

        pub fn imagebuf_deep_samples(imagebuf: &ImageBuf, x: i32, y: i32, z: i32) -> i32;

        pub unsafe fn imagebuf_deep_pixel_ptr(
            imagebuf: &ImageBuf,
            x: i32,
            y: i32,
            z: i32,
            c: i32,
            s: i32,
        ) -> *const u8;

        pub fn imagebuf_deep_value(
            imagebuf: &ImageBuf,
            x: i32,
            y: i32,
            z: i32,
            c: i32,
            s: i32,
        ) -> f32;

        pub fn imagebuf_deep_value_uint(
            imagebuf: &ImageBuf,
            x: i32,
            y: i32,
            z: i32,
            c: i32,
            s: i32,
        ) -> u32;

        /// The deep mutators report `false` with an error message when the
        /// deferred sample allocation cannot be made; see the DeepData
        /// siblings for the mechanism.
        pub fn imagebuf_set_deep_samples(
            imagebuf: Pin<&mut ImageBuf>,
            x: i32,
            y: i32,
            z: i32,
            nsamples: i32,
            error: &mut String,
        ) -> bool;

        pub fn imagebuf_deep_insert_samples(
            imagebuf: Pin<&mut ImageBuf>,
            x: i32,
            y: i32,
            z: i32,
            samplepos: i32,
            nsamples: i32,
            error: &mut String,
        ) -> bool;

        pub fn imagebuf_deep_erase_samples(
            imagebuf: Pin<&mut ImageBuf>,
            x: i32,
            y: i32,
            z: i32,
            samplepos: i32,
            nsamples: i32,
        );

        pub fn imagebuf_set_deep_value(
            imagebuf: Pin<&mut ImageBuf>,
            x: i32,
            y: i32,
            z: i32,
            c: i32,
            s: i32,
            value: f32,
            error: &mut String,
        ) -> bool;

        pub fn imagebuf_set_deep_value_uint(
            imagebuf: Pin<&mut ImageBuf>,
            x: i32,
            y: i32,
            z: i32,
            c: i32,
            s: i32,
            value: u32,
            error: &mut String,
        ) -> bool;

        pub fn imagebuf_copy_deep_pixel(
            imagebuf: Pin<&mut ImageBuf>,
            x: i32,
            y: i32,
            z: i32,
            src: &ImageBuf,
            srcx: i32,
            srcy: i32,
            srcz: i32,
        ) -> bool;

        pub unsafe fn imagebuf_deepdata_mut(imagebuf: Pin<&mut ImageBuf>) -> *mut DeepData;

        pub unsafe fn imagebuf_deepdata(imagebuf: &ImageBuf) -> *const DeepData;

        pub fn imagebuf_lock(imagebuf: &ImageBuf);

        pub fn imagebuf_unlock(imagebuf: &ImageBuf);

        pub fn wrapmode_from_string(name: &str) -> WrapMode;

        // ImageBuf::IteratorBase
        pub fn imagebuf_iterator_x(iterator: &ImageBufIteratorBase) -> i32;

        pub fn imagebuf_iterator_y(iterator: &ImageBufIteratorBase) -> i32;

        pub fn imagebuf_iterator_z(iterator: &ImageBufIteratorBase) -> i32;

        pub fn imagebuf_iterator_valid(iterator: &ImageBufIteratorBase) -> bool;

        pub fn imagebuf_iterator_valid_coordianates(
            iterator: &ImageBufIteratorBase,
            x: i32,
            y: i32,
            z: i32,
        ) -> bool;

        pub fn imagebuf_iterator_exists(iterator: &ImageBufIteratorBase) -> bool;

        pub fn imagebuf_iterator_done(iterator: &ImageBufIteratorBase) -> bool;

        pub fn imagebuf_iterator_deep_samples(iterator: &ImageBufIteratorBase) -> i32;

        pub fn imagebuf_iterator_wrap(iterator: &ImageBufIteratorBase) -> WrapMode;

        pub fn imagebuf_iterator_pos(
            iterator: Pin<&mut ImageBufIteratorBase>,
            x: i32,
            y: i32,
            z: i32,
        );

        pub fn imagebuf_iterator_next(iterator: Pin<&mut ImageBufIteratorBase>);

        pub fn imagebuf_iterator_range(iterator: &ImageBufIteratorBase) -> ROI;

        pub fn imagebuf_iterator_rerange(
            iterator: Pin<&mut ImageBufIteratorBase>,
            xbegin: i32,
            xend: i32,
            ybegin: i32,
            yend: i32,
            zbegin: i32,
            zend: i32,
            wrap: WrapMode,
        );

        pub unsafe fn imagebuf_iterator_rawptr(iterator: &ImageBufIteratorBase) -> *const u8;

        pub fn imagebuf_iterator_deep_value(iterator: &ImageBufIteratorBase, c: i32, s: i32)
            -> f32;

        pub fn imagebuf_iterator_deep_value_uint(
            iterator: &ImageBufIteratorBase,
            c: i32,
            s: i32,
        ) -> u32;

        pub fn imagebuf_iterator_localpixels(iterator: &ImageBufIteratorBase) -> bool;

        pub fn imagebuf_iterator_has_error(iterator: &ImageBufIteratorBase) -> bool;

        pub fn imagebuf_iterator_clear_error(iterator: Pin<&mut ImageBufIteratorBase>);
    }
}