-
Notifications
You must be signed in to change notification settings - Fork 5
/
imagebuf.cpp
364 lines (280 loc) · 10.8 KB
/
imagebuf.cpp
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
#include <OpenImageIO/imagebuf.h>
#include "oiio.h"
#include "imagespec.h"
OIIO::ImageBuf::IBStorage fromIBStorage(IBStorage s) {
switch (s) {
case IBSTORAGE_LOCALBUFFER: return OIIO::ImageBuf::LOCALBUFFER;
case IBSTORAGE_APPBUFFER: return OIIO::ImageBuf::APPBUFFER;
case IBSTORAGE_IMAGECACHE: return OIIO::ImageBuf::IMAGECACHE;
case IBSTORAGE_UNINITIALIZED: return OIIO::ImageBuf::UNINITIALIZED;
}
}
IBStorage toIBStorage(OIIO::ImageBuf::IBStorage s) {
if (s == OIIO::ImageBuf::LOCALBUFFER) return IBSTORAGE_LOCALBUFFER;
if (s == OIIO::ImageBuf::APPBUFFER) return IBSTORAGE_APPBUFFER;
if (s == OIIO::ImageBuf::IMAGECACHE) return IBSTORAGE_IMAGECACHE;
return IBSTORAGE_UNINITIALIZED;
}
extern "C" {
char* ImageBuf_geterror(ImageBuf* buf) {
if (!static_cast<OIIO::ImageBuf*>(buf)->has_error()) {
return NULL;
}
std::string err = static_cast<OIIO::ImageBuf*>(buf)->geterror();
return strdup(err.c_str());
}
void deleteImageBuf(ImageBuf *buf) {
delete static_cast<OIIO::ImageBuf*>(buf);
}
ImageBuf* ImageBuf_New() {
return (ImageBuf*) new OIIO::ImageBuf();
}
ImageBuf* ImageBuf_New_WithCache(const char* name, ImageCache *imagecache) {
std::string s_name(name);
return (ImageBuf*) new OIIO::ImageBuf(s_name, static_cast<OIIO::ImageCache*>(imagecache));
}
ImageBuf* ImageBuf_New_Spec(const ImageSpec* spec) {
return (ImageBuf*) new OIIO::ImageBuf(*(static_cast<const OIIO::ImageSpec*>(spec)));
}
ImageBuf* ImageBuf_New_WithBuffer(const char* name, const ImageSpec* spec, void *buffer) {
std::string s_name(name);
return (ImageBuf*) new OIIO::ImageBuf(s_name, *(static_cast<const OIIO::ImageSpec*>(spec)), buffer);
}
ImageBuf* ImageBuf_New_SubImage(const char* name, int subimage, int miplevel, ImageCache* imagecache) {
std::string s_name(name);
return (ImageBuf*) new OIIO::ImageBuf(s_name, subimage, miplevel,
static_cast<OIIO::ImageCache*>(imagecache));
}
void ImageBuf_clear(ImageBuf* buf) {
static_cast<OIIO::ImageBuf*>(buf)->clear();
}
void ImageBuf_reset_subimage(ImageBuf* buf, const char* name, int subimage, int miplevel,
ImageCache *imagecache, const ImageSpec* spec) {
std::string s_name(name);
static_cast<OIIO::ImageBuf*>(buf)->reset(s_name, subimage, miplevel,
static_cast<OIIO::ImageCache*>(imagecache),
static_cast<const OIIO::ImageSpec*>(spec));
}
void ImageBuf_reset_name_cache(ImageBuf* buf, const char* name, ImageCache *imagecache) {
std::string s_name(name);
static_cast<OIIO::ImageBuf*>(buf)->reset(s_name, static_cast<OIIO::ImageCache*>(imagecache));
}
void ImageBuf_reset_name_spec(ImageBuf* buf, const char* name, const ImageSpec* spec) {
std::string s_name(name);
static_cast<OIIO::ImageBuf*>(buf)->reset(s_name, *(static_cast<const OIIO::ImageSpec*>(spec)));
}
void ImageBuf_reset_spec(ImageBuf* buf, ImageSpec* spec) {
static_cast<OIIO::ImageBuf*>(buf)->reset(*(static_cast<const OIIO::ImageSpec*>(spec)));
}
IBStorage ImageBuf_storage(ImageBuf* buf) {
return toIBStorage(static_cast<OIIO::ImageBuf*>(buf)->storage());
}
bool ImageBuf_initialized(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->initialized();
}
bool ImageBuf_init_spec(ImageBuf* buf, const char* filename, int subimage, int miplevel) {
return static_cast<OIIO::ImageBuf*>(buf)->init_spec(filename, subimage, miplevel);
}
bool ImageBuf_read(ImageBuf* buf, int subimage, int miplevel, bool force, TypeDesc convert, void *cbk_data) {
ProgressCallback cbk = NULL;
if (cbk_data != NULL) {
cbk = &image_progress_callback;
}
return static_cast<OIIO::ImageBuf*>(buf)->read(subimage,
miplevel,
force,
fromTypeDesc(convert),
cbk,
cbk_data);
}
bool ImageBuf_write_file(ImageBuf* buf, const char* filename, const char* fileformat, void *cbk_data) {
ProgressCallback cbk = NULL;
if (cbk_data != NULL) {
cbk = &image_progress_callback;
}
return static_cast<OIIO::ImageBuf*>(buf)->write(filename, fileformat, cbk, cbk_data);
}
bool ImageBuf_write_output(ImageBuf* buf, ImageOutput *out, void *cbk_data) {
OIIO::ImageOutput *out_ptr = static_cast<OIIO::ImageOutput*>(out);
ProgressCallback cbk = NULL;
if (cbk_data != NULL) {
cbk = &image_progress_callback;
}
return static_cast<OIIO::ImageBuf*>(buf)->write(out_ptr, cbk, cbk_data);
}
void ImageBuf_set_write_format(ImageBuf* buf, TypeDesc format) {
static_cast<OIIO::ImageBuf*>(buf)->set_write_format(fromTypeDesc(format));
}
void ImageBuf_set_write_tiles(ImageBuf* buf, int width, int height, int depth) {
static_cast<OIIO::ImageBuf*>(buf)->set_write_tiles(width, height, depth);
}
void ImageBuf_copy_metadata(ImageBuf* dst, const ImageBuf* src) {
const OIIO::ImageBuf *src_ptr = static_cast<const OIIO::ImageBuf*>(src);
static_cast<OIIO::ImageBuf*>(dst)->copy_metadata(*src_ptr);
}
bool ImageBuf_copy_pixels(ImageBuf* dst, const ImageBuf* src) {
const OIIO::ImageBuf *src_ptr = static_cast<const OIIO::ImageBuf*>(src);
return static_cast<OIIO::ImageBuf*>(dst)->copy_pixels(*src_ptr);
}
bool ImageBuf_copy(ImageBuf* dst, const ImageBuf* src) {
const OIIO::ImageBuf *src_ptr = static_cast<const OIIO::ImageBuf*>(src);
return static_cast<OIIO::ImageBuf*>(dst)->copy(*src_ptr);
}
void ImageBuf_swap(ImageBuf* buf, ImageBuf* other) {
OIIO::ImageBuf *other_ptr = static_cast<OIIO::ImageBuf*>(other);
static_cast<OIIO::ImageBuf*>(buf)->swap(*other_ptr);
}
const ImageSpec* ImageBuf_spec(ImageBuf* buf) {
OIIO::ImageSpec *spec = new OIIO::ImageSpec(static_cast<OIIO::ImageBuf*>(buf)->spec());
return static_cast<const ImageSpec*>(spec);
}
ImageSpec* ImageBuf_specmod(ImageBuf* buf) {
OIIO::ImageSpec *spec = &(static_cast<OIIO::ImageBuf*>(buf)->specmod());
return static_cast<ImageSpec*>(spec);
}
const ImageSpec* ImageBuf_nativespec(ImageBuf* buf) {
OIIO::ImageSpec *spec = new OIIO::ImageSpec(static_cast<OIIO::ImageBuf*>(buf)->nativespec());
return static_cast<const ImageSpec*>(spec);
}
const char* ImageBuf_name(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->name().c_str();
}
const char* ImageBuf_file_format_name(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->file_format_name().c_str();
}
int ImageBuf_subimage(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->subimage();
}
int ImageBuf_nsubimages(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->nsubimages();
}
int ImageBuf_miplevel(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->miplevel();
}
int ImageBuf_nmiplevels(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->nmiplevels();
}
int ImageBuf_nchannels(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->nchannels();
}
bool ImageBuf_get_pixel_channels(ImageBuf* buf,
int xbegin, int xend,
int ybegin, int yend,
int zbegin, int zend,
int chbegin, int chend,
TypeDesc format,
void *result)
{
return static_cast<OIIO::ImageBuf*>(buf)->get_pixel_channels(xbegin, xend,
ybegin, yend,
zbegin, zend,
chbegin, chend,
fromTypeDesc(format),
result );
}
int ImageBuf_orientation(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->orientation();
}
int ImageBuf_oriented_width(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->oriented_width();
}
int ImageBuf_oriented_height(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->oriented_height();
}
int ImageBuf_oriented_x(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->oriented_x();
}
int ImageBuf_oriented_y(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->oriented_y();
}
int ImageBuf_oriented_full_width(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->oriented_full_width();
}
int ImageBuf_oriented_full_height(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->oriented_full_height();
}
int ImageBuf_oriented_full_x(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->oriented_full_x();
}
int ImageBuf_oriented_full_y(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->oriented_full_y();
}
int ImageBuf_xbegin(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->xbegin();
}
int ImageBuf_xend(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->xend();
}
int ImageBuf_ybegin(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->ybegin();
}
int ImageBuf_yend(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->yend();
}
int ImageBuf_zbegin(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->zbegin();
}
int ImageBuf_zend(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->zend();
}
int ImageBuf_xmin(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->xmin();
}
int ImageBuf_xmax(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->xmax();
}
int ImageBuf_ymin(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->ymin();
}
int ImageBuf_ymax(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->ymax();
}
int ImageBuf_zmin(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->zmin();
}
int ImageBuf_zmax(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->zmax();
}
void ImageBuf_set_full(ImageBuf* buf, int xbegin, int xend, int ybegin, int yend, int zbegin, int zend) {
static_cast<OIIO::ImageBuf*>(buf)->set_full(xbegin, xend, ybegin, yend, zbegin, zend);
}
ROI* ImageBuf_roi(ImageBuf* buf) {
OIIO::ROI roi(static_cast<OIIO::ImageBuf*>(buf)->roi());
OIIO::ROI *ptr = new OIIO::ROI();
*ptr = roi;
return static_cast<ROI*>(ptr);
}
ROI* ImageBuf_roi_full(ImageBuf* buf) {
OIIO::ROI roi(static_cast<OIIO::ImageBuf*>(buf)->roi_full());
OIIO::ROI *ptr = new OIIO::ROI();
*ptr = roi;
return static_cast<ROI*>(ptr);
}
void ImageBuf_set_roi_full(ImageBuf* buf, ROI* newroi) {
static_cast<OIIO::ImageBuf*>(buf)->set_roi_full(*(static_cast<OIIO::ROI*>(newroi)));
}
bool ImageBuf_pixels_valid(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->pixels_valid();
}
TypeDesc ImageBuf_pixeltype(ImageBuf* buf) {
return toTypeDesc(static_cast<OIIO::ImageBuf*>(buf)->pixeltype());
}
// void* ImageBuf_localpixels(ImageBuf* buf);
// const void* ImageBuf_localpixels(ImageBuf* buf);
bool ImageBuf_cachedpixels(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->cachedpixels();
}
ImageCache* ImageBuf_imagecache(ImageBuf* buf) {
OIIO::ImageCache *cache = static_cast<OIIO::ImageBuf*>(buf)->imagecache();
return static_cast<ImageCache*>(cache);
}
// void* ImageBuf_pixeladdr(ImageBuf* buf, int x, int y);
// void* ImageBuf_pixeladdr_z(ImageBuf* buf, int x, int y, int z);
bool ImageBuf_deep(ImageBuf* buf) {
return static_cast<OIIO::ImageBuf*>(buf)->deep();
}
// int ImageBuf_deep_samples(ImageBuf* buf, int x, int y, int z);
// const void* ImageBuf_deep_pixel_ptr(ImageBuf* buf, int x, int y, int z, int c);
// float ImageBuf_deep_value(ImageBuf* buf, int x, int y, int z, int c, int s);
// DeepData* ImageBuf_deepdata(ImageBuf* buf);
} // extern "C"