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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
#pragma once

#include <OpenImageIO/deepdata.h>
#include <OpenImageIO/filesystem.h>
#include <OpenImageIO/imageio.h>
#include <OpenImageIO/typedesc.h>
#include <memory>
#include <rust/cxx.h>
#include <string>
#include <vector>

namespace oiio {
enum class Aggregate : uint8_t;
enum class BaseType : uint8_t;
enum class VecSemantics : uint8_t;
using DeepData    = OIIO::DeepData;
using ImageBuf    = OIIO::ImageBuf;
using ImageInput  = OIIO::ImageInput;
using ImageOutput = OIIO::ImageOutput;
using ImageSpec   = OIIO::ImageSpec;
using IOProxy     = OIIO::Filesystem::IOProxy;
using OpenMode    = OIIO::ImageOutput::OpenMode;
using ROI         = OIIO::ROI;
using TypeDesc    = OIIO::TypeDesc;

struct ExtensionMapItem;

#pragma region ROI

ROI
roi_default() noexcept;

ROI
roi_new(int xbegin, int xend, int ybegin, int yend, int zbegin, int zend,
        int chbegin, int chend) noexcept;

ROI
roi_new_all() noexcept;

bool
roi_defined(const ROI& roi) noexcept;

int
roi_width(const ROI& roi) noexcept;

int
roi_height(const ROI& roi) noexcept;

int
roi_depth(const ROI& roi) noexcept;

int
roi_nchannels(const ROI& roi) noexcept;

uint64_t
roi_npixels(const ROI& roi) noexcept;

bool
roi_eq_roi(const ROI& roi, const ROI& other) noexcept;

bool
roi_ne_roi(const ROI& roi, const ROI& other) noexcept;

bool
roi_contains(const ROI& roi, int x, int y, int z, int ch) noexcept;

bool
roi_contains_roi(const ROI& roi, const ROI& other) noexcept;

ROI
roi_union(const ROI& roi, const ROI& other) noexcept;

ROI
roi_intersection(const ROI& roi, const ROI& other) noexcept;
#pragma endregion

#pragma region ImageSpec
std::unique_ptr<ImageSpec>
imagespec_from_resolution(int xres, int yres, int nchans);

std::unique_ptr<ImageSpec>
imagespec_new(int xres, int yres, int nchans, TypeDesc format);

std::unique_ptr<ImageSpec>
imagespec_copy(const ImageSpec& spec);

TypeDesc
imagespec_format(const ImageSpec& spec);

void
imagespec_set_format(ImageSpec& spec, TypeDesc format);

void
imagespec_set_origin(ImageSpec& spec, int x, int y, int z);

void
imagespec_set_dimensions(ImageSpec& spec, int width, int height, int depth);

void
imagespec_set_full(ImageSpec& spec, int full_x, int full_y, int full_z,
                   int full_width, int full_height, int full_depth);

void
imagespec_set_tile_size(ImageSpec& spec, int width, int height, int depth);

void
imagespec_set_channel_names(ImageSpec& spec,
                            const rust::Vec<rust::String>& names);

void
imagespec_set_channelformats(ImageSpec& spec,
                             rust::Slice<const TypeDesc> formats);

void
imagespec_set_alpha_channel(ImageSpec& spec, int index);

void
imagespec_set_z_channel(ImageSpec& spec, int index);

void
imagespec_set_deep(ImageSpec& spec, bool deep);

void
imagespec_attribute_int(ImageSpec& spec, const rust::Str name, int value);

void
imagespec_attribute_float(ImageSpec& spec, const rust::Str name, float value);

void
imagespec_attribute_string(ImageSpec& spec, const rust::Str name,
                           const rust::Str value);

bool
imagespec_erase_attribute(ImageSpec& spec, const rust::Str name);

bool
imagespec_has_attribute(const ImageSpec& spec, const rust::Str name);

TypeDesc
imagespec_attribute_type(const ImageSpec& spec, const rust::Str name);

int
imagespec_get_int_attribute(const ImageSpec& spec, const rust::Str name,
                            int defaultval);

float
imagespec_get_float_attribute(const ImageSpec& spec, const rust::Str name,
                              float defaultval);

rust::String
imagespec_get_string_attribute(const ImageSpec& spec, const rust::Str name,
                               const rust::Str defaultval);

rust::String
imagespec_attribute_to_string(const ImageSpec& spec, const rust::Str name);

// Verbatim access to an attribute's stored value, so a type this crate does
// not model can still be carried from one specification to another without
// going through its printed form, which rounds floats.
rust::Vec<uint8_t>
imagespec_attribute_bytes(const ImageSpec& spec, const rust::Str name);

bool
attribute_bytes_are_writable(const rust::Str type_name, size_t length);

bool
imagespec_attribute_set_bytes(ImageSpec& spec, const rust::Str name,
                              const rust::Str type_name,
                              rust::Slice<const uint8_t> bytes);

// String-typed attributes hold pointers rather than characters, so they are
// read and written as strings instead of as bytes.
rust::Vec<rust::String>
imagespec_attribute_strings(const ImageSpec& spec, const rust::Str name);

bool
imagespec_attribute_set_strings(ImageSpec& spec, const rust::Str name,
                                const rust::Str type_name,
                                const rust::Vec<rust::String>& values);

std::unique_ptr<std::vector<ImageSpec>>
imagespec_vector_new();

void
imagespec_vector_push(std::vector<ImageSpec>& specs, const ImageSpec& spec);

rust::Vec<rust::String>
imagespec_attribute_names(const ImageSpec& spec);

int
imagespec_x(const ImageSpec& spec);

int
imagespec_y(const ImageSpec& spec);

int
imagespec_z(const ImageSpec& spec);

int
imagespec_width(const ImageSpec& spec);

int
imagespec_height(const ImageSpec& spec);

int
imagespec_depth(const ImageSpec& spec);

int
imagespec_full_x(const ImageSpec& spec);

int
imagespec_full_y(const ImageSpec& spec);

int
imagespec_full_z(const ImageSpec& spec);

int
imagespec_full_width(const ImageSpec& spec);

int
imagespec_full_height(const ImageSpec& spec);

int
imagespec_full_depth(const ImageSpec& spec);

int
imagespec_tile_width(const ImageSpec& spec);

int
imagespec_tile_height(const ImageSpec& spec);

int
imagespec_tile_depth(const ImageSpec& spec);

int
imagespec_nchannels(const ImageSpec& spec);

int
imagespec_alpha_channel(const ImageSpec& spec);

int
imagespec_z_channel(const ImageSpec& spec);

bool
imagespec_deep(const ImageSpec& spec);

bool
imagespec_valid(const ImageSpec& spec);

std::unique_ptr<std::vector<std::string>>
imagespec_channel_names(const ImageSpec& spec);

rust::Slice<const TypeDesc>
imagespec_channelformats(const ImageSpec& spec);
#pragma endregion

#pragma region ImageInput

std::unique_ptr<ImageInput>
imageinput_open_with_config(const rust::Str filename, const ImageSpec& config);

std::unique_ptr<ImageInput>
imageinput_open_without_config(const rust::Str filename);

std::unique_ptr<ImageInput>
imageinput_create_with_config(const rust::Str filename, bool do_open,
                              const ImageSpec& config,
                              const rust::Str plugin_searchpath);

std::unique_ptr<ImageInput>
imageinput_create_without_config(const rust::Str filename, bool do_open,
                                 const rust::Str plugin_searchpath);

rust::Str
imageinput_format_name(const ImageInput& imageinput);

bool
imageinput_supports(const ImageInput& imageinput, const rust::Str feature);

bool
imageinput_valid_file(const ImageInput& imageinput, const rust::Str filename);

rust::String
imageinput_geterror(ImageInput& imageinput);

const ImageSpec&
imageinput_spec(const ImageInput& imageinput);

std::unique_ptr<ImageSpec>
imageinput_spec_subimage_miplevel(ImageInput& imageinput, int32_t subimage,
                                  int32_t miplevel);

std::unique_ptr<ImageSpec>
imageinput_spec_dimensions(ImageInput& imageinput, int32_t subimage,
                           int32_t miplevel);

// Open an image through an IOProxy rather than the filesystem. The file name
// only selects the reader; it is never opened.
std::unique_ptr<ImageInput>
imageinput_open_with_ioproxy(const rust::Str filename, IOProxy* ioproxy);

bool
imageinput_close(ImageInput& imageinput);

int
imageinput_current_subimage(const ImageInput& imageinput);

int
imageinput_current_miplevel(const ImageInput& imageinput);

bool
imageinput_seek_subimage(ImageInput& imageinput, int subimage, int miplevel);

bool
imageinput_read_scanline(ImageInput& imageinput, int y, int z, TypeDesc format,
                         rust::Slice<uint8_t> data, int64_t xstride);

bool
imageinput_read_scanlines(ImageInput& imageinput, int subimage, int miplevel,
                          int ybegin, int yend, int z, int chbegin, int chend,
                          TypeDesc format, rust::Slice<uint8_t> data,
                          int64_t xstride, int64_t ystride);

bool
imageinput_read_tile(ImageInput& imageinput, int x, int y, int z,
                     TypeDesc format, rust::Slice<uint8_t> data,
                     int64_t xstride, int64_t ystride, int64_t zstride);

bool
imageinput_read_scanlines(ImageInput& imageinput, int subimage, int miplevel,
                          int ybegin, int yend, int zbegin, int zend,
                          int chbegin, int chend, TypeDesc format,
                          rust::Slice<uint8_t> data, int64_t xstride,
                          int64_t ystride, int64_t zstride);

bool
imageinput_read_image(ImageInput& imageinput, int subimage, int miplevel,
                      int chbegin, int chend, TypeDesc format,
                      rust::Slice<uint8_t> data, int64_t xstride,
                      int64_t ystride, int64_t zstride);

bool
imageinput_read_image_span(ImageInput& imageinput, int subimage, int miplevel,
                           int chbegin, int chend, TypeDesc format,
                           rust::Slice<uint8_t> data);

// Bounded partial reads. Each validates the requested region and the
// destination buffer against the subimage and MIP level's own dimensions
// before entering OpenImageIO, and reports failures through the ImageInput's
// error channel.
bool
imageinput_read_scanlines_span(ImageInput& imageinput, int subimage,
                               int miplevel, int ybegin, int yend, int z,
                               int chbegin, int chend, TypeDesc format,
                               rust::Slice<uint8_t> data);

bool
imageinput_read_tiles_span(ImageInput& imageinput, int subimage, int miplevel,
                           int xbegin, int xend, int ybegin, int yend,
                           int zbegin, int zend, int chbegin, int chend,
                           TypeDesc format, rust::Slice<uint8_t> data);

bool
imageinput_read_native_deep_scanlines(ImageInput& imageinput, int subimage,
                                      int miplevel, int ybegin, int yend, int z,
                                      int chbegin, int chend, DeepData& data,
                                      rust::String& error);

bool
imageinput_read_native_deep_tiles(ImageInput& imageinput, int subimage,
                                  int miplevel, int xbegin, int xend,
                                  int ybegin, int yend, int zbegin, int zend,
                                  int chbegin, int chend, DeepData& data,
                                  rust::String& error);

bool
imageinput_read_native_deep_image(ImageInput& imageinput, int subimage,
                                  int miplevel, DeepData& data,
                                  rust::String& error);

bool
imageinput_read_native_scanline(ImageInput& imageinput, int subimage,
                                int miplevel, int y, int z,
                                rust::Slice<uint8_t> data);

bool
imageinput_read_native_scanlines(ImageInput& imageinput, int subimage,
                                 int miplevel, int ybegin, int yend, int z,
                                 int chbegin, int chend,
                                 rust::Slice<uint8_t> data);

bool
imageinput_read_native_tile(ImageInput& imageinput, int subimage, int miplevel,
                            int x, int y, int z, rust::Slice<uint8_t> data);

bool
imageinput_read_native_tiles(ImageInput& imageinput, int xbegin, int xend,
                             int ybegin, int yend, int zbegin, int zend,
                             int chbegin, int chend, rust::Slice<uint8_t> data);

bool
imageinput_set_ioproxy(ImageInput& imageinput, IOProxy* ioproxy);

bool
imageinput_has_error(const ImageInput& imageinput);

void
imageinput_seterror(ImageInput& imageinput, const rust::Str message);

void
imageinput_set_threads(ImageInput& imageinput, int n);

int
imageinput_threads(const ImageInput& imageinput);
#pragma endregion

#pragma region ImageOutput
std::unique_ptr<ImageOutput>
imageoutput_create(const rust::Str filename, IOProxy* ioproxy,
                   const rust::Str plugin_searchpath);

rust::Str
imageoutput_format_name(const ImageOutput& imageoutput);

int
imageoutput_supports(const ImageOutput& imageoutput, const rust::Str feature);

bool
imageoutput_open(ImageOutput& imageoutput, const rust::Str filename,
                 const ImageSpec& newspec, OpenMode mode);

bool
imageoutput_open_multi_subimage(ImageOutput& imageoutput,
                                const rust::Str filename, int subimages,
                                const ImageSpec* specs);

// Open every subimage of a multi-part file at once. Formats such as OpenEXR
// require all subimage specifications up front and reject `AppendSubimage`.
bool
imageoutput_open_specs(ImageOutput& imageoutput, const rust::Str filename,
                       const std::vector<ImageSpec>& specs);

const ImageSpec&
imageoutput_spec(const ImageOutput& imageoutput);

bool
imageoutput_close(ImageOutput& imageoutput);

bool
imageoutput_write_scanline(ImageOutput& imageoutput, int y, int z,
                           TypeDesc format, const rust::Slice<uint8_t> data,
                           int64_t xstride);

bool
imageoutput_write_scanlines(ImageOutput& imageoutput, int ybegin, int yend,
                            int z, TypeDesc format,
                            const rust::Slice<uint8_t> data, int64_t xstride,
                            int64_t ystride);

bool
imageoutput_write_tile(ImageOutput& imageoutput, int x, int y, int z,
                       TypeDesc format, const rust::Slice<uint8_t> data,
                       int64_t xstride, int64_t ystride, int64_t zstride);

bool
imageoutput_write_tiles(ImageOutput& imageoutput, int xbegin, int xend,
                        int ybegin, int yend, int zbegin, int zend,
                        TypeDesc format, const rust::Slice<uint8_t> data,
                        int64_t xstride, int64_t ystride, int64_t zstride);

bool
imageoutput_write_rectangle(ImageOutput& imageoutput, int xbegin, int xend,
                            int ybegin, int yend, int zbegin, int zend,
                            TypeDesc format, const rust::Slice<uint8_t> data,
                            int64_t xstride, int64_t ystride, int64_t zstride);

bool
imageoutput_write_image(ImageOutput& imageoutput, TypeDesc format,
                        const rust::Slice<uint8_t> data, int64_t xstride,
                        int64_t ystride, int64_t zstride);

// Bounded, contiguous span writes. Each validates the buffer against the
// currently open specification before entering OpenImageIO, and reports the
// failure through the ImageOutput's own error channel.
bool
imageoutput_write_image_span(ImageOutput& imageoutput, TypeDesc format,
                             const rust::Slice<const uint8_t> data);

bool
imageoutput_write_scanlines_span(ImageOutput& imageoutput, int ybegin, int yend,
                                 TypeDesc format,
                                 const rust::Slice<const uint8_t> data);

bool
imageoutput_write_tiles_span(ImageOutput& imageoutput, int xbegin, int xend,
                             int ybegin, int yend, int zbegin, int zend,
                             TypeDesc format,
                             const rust::Slice<const uint8_t> data);

bool
imageoutput_write_rectangle_span(ImageOutput& imageoutput, int xbegin, int xend,
                                 int ybegin, int yend, int zbegin, int zend,
                                 TypeDesc format,
                                 const rust::Slice<const uint8_t> data);

// Read a whole subimage exactly as the file stores it, each channel in its
// own native format packed per pixel. The buffer must hold exactly
// image_pixels * pixel_bytes(native); validated here against the file's own
// specification before OpenImageIO sees the pointer.
bool
imageinput_read_native_image_bytes(ImageInput& imageinput, int subimage,
                                   int miplevel, rust::Slice<uint8_t> data,
                                   rust::String& error);

bool
imageoutput_write_deep_scanlines(ImageOutput& imageoutput, int ybegin, int yend,
                                 int z, const DeepData& deepdata);

bool
imageoutput_write_deep_tiles(ImageOutput& imageoutput, int xbegin, int xend,
                             int ybegin, int yend, int zbegin, int zend,
                             const DeepData& deepdata);

bool
imageoutput_write_deep_image(ImageOutput& imageoutput,
                             const DeepData& deepdata);

bool
imageoutput_set_thumbnail(ImageOutput& imageoutput, const ImageBuf& thumb);

bool
imageoutput_copy_image(ImageOutput& imageoutput, ImageInput* imageinput);

bool
imageoutput_set_ioproxy(ImageOutput& imageoutput, IOProxy* ioproxy);

bool
imageoutput_has_error(const ImageOutput& imageoutput);

rust::String
imageoutput_geterror(const ImageOutput& imageoutput, bool clear);

void
imageoutput_seterror(ImageOutput& imageoutput, const rust::Str message);

void
imageoutput_set_threads(ImageOutput& imageoutput, int n);

int
imageoutput_threads(const ImageOutput& imageoutput);
#pragma endregion

#pragma region Utility Functions
void
shutdown();

int
openimageio_version();

int
openimageio_build_version();

bool
has_error();

rust::String
get_error(bool clear);

bool
attribute(const rust::Str name, TypeDesc type, rust::Slice<uint8_t> value);

bool
attribute_float(const rust::Str name, float value);

bool
attribute_int(const rust::Str name, int value);

bool
attribute_string(const rust::Str name, rust::Str value);

bool
getattribute(const rust::Str name, TypeDesc type, rust::Slice<uint8_t> value);

bool
getattribute_int(const rust::Str name, int& value);

bool
getattribute_float(const rust::Str name, float& value);

bool
getattribute_string(const rust::Str name, rust::String& value);

int
get_int_attribute(const rust::Str name, int defaultval);

float
get_float_attribute(const rust::Str name, float defaultval);

rust::String
get_string_attribute(const rust::Str name, const rust::Str defaultval);

// void
// declare_imageio_format(const rust::Str name,
//                        rust::Fn<ImageInput*(ImageInput*)> input_creator,
//                        const rust::Slice<const rust::Str> input_extensions,
//                        rust::Fn<ImageOutput*(ImageOutput*)> output_creator,
//                        const rust::Slice<const rust::Str> output_extensions,
//                        const rust::Str lib_version);

bool
is_imageio_format_name(const rust::Str name);

rust::Vec<ExtensionMapItem>
get_extension_map();

bool
convert_pixel_values(TypeDesc src_type, rust::Slice<const uint8_t> src,
                     TypeDesc dst_type, rust::Slice<uint8_t> dst);

bool
convert_image(int nchannels, int width, int height, int depth,
              rust::Slice<const uint8_t> src, TypeDesc src_type,
              int64_t src_xstride, int64_t src_ystride, int64_t src_zstride,
              rust::Slice<uint8_t> dst, TypeDesc dst_type, int64_t dst_xstride,
              int64_t dst_ystride, int64_t dst_zstride);

bool
parallel_convert_image(int nchannels, int width, int height, int depth,
                       rust::Slice<const uint8_t> src, TypeDesc src_type,
                       int64_t src_xstride, int64_t src_ystride,
                       int64_t src_zstride, rust::Slice<uint8_t> dst,
                       TypeDesc dst_type, int64_t dst_xstride,
                       int64_t dst_ystride, int64_t dst_zstride, int nthreads);

void
add_dither(int nchannels, int width, int height, int depth, float* data,
           int64_t xstride, int64_t ystride, int64_t zstride,
           float ditheramplitude, int alpha_channel, int z_channel,
           unsigned int ditherseed, int chorigin, int xorigin, int yorigin,
           int zorigin);

void
premult(int nchannels, int width, int height, int depth, int chbegin, int chend,
        TypeDesc datatype, rust::Slice<uint8_t> data, int64_t xstride,
        int64_t ystride, int64_t zstride, int alpha_channel, int z_channel);

bool
copy_image(int nchannels, int width, int height, int depth,
           rust::Slice<const uint8_t> src, int64_t pixelsize,
           int64_t src_xstride, int64_t src_ystride, int64_t src_zstride,
           rust::Slice<uint8_t> dst, int64_t dst_xstride, int64_t dst_ystride,
           int64_t dst_zstride);

bool
wrap_black(int& coord, int origin, int width);

bool
wrap_clamp(int& coord, int origin, int width);

bool
wrap_periodic(int& coord, int origin, int width);

bool
wrap_periodic_pow2(int& coord, int origin, int width);

bool
wrap_mirror(int& coord, int origin, int width);

void
debug(const rust::Str message);
#pragma endregion
}  // namespace oiio