21 using namespace std::placeholders;
22 using std::placeholders::_1;
25 namespace ImageBufAlgo {
53 std::function<
void(
ROI)>
f)
71 int64_t xchunk = 0, ychunk = 0;
75 }
else if (splitdir ==
Split_X) {
85 auto task = [&](
int , int64_t xbegin, int64_t xend,
86 int64_t ybegin, int64_t yend) {
104 template <
class Func>
128 ImageSpec *force_spec=NULL,
int prepflags=0);
132 return IBAprep (roi, dst, A, B, NULL, force_spec, prepflags);
136 return IBAprep (roi, dst, A, B, NULL, NULL, prepflags);
140 return IBAprep (roi, dst, A, NULL, NULL, NULL, prepflags);
180 #define OIIO_DISPATCH_TYPES(ret,name,func,type,R,...) \
181 switch (type.basetype) { \
182 case TypeDesc::FLOAT : \
183 ret = func<float> (R, __VA_ARGS__); break; \
184 case TypeDesc::UINT8 : \
185 ret = func<unsigned char> (R, __VA_ARGS__); break; \
186 case TypeDesc::HALF : \
187 ret = func<half> (R, __VA_ARGS__); break; \
188 case TypeDesc::UINT16: \
189 ret = func<unsigned short> (R, __VA_ARGS__); break; \
190 case TypeDesc::INT8 : \
191 ret = func<char> (R, __VA_ARGS__); break; \
192 case TypeDesc::INT16 : \
193 ret = func<short> (R, __VA_ARGS__); break; \
194 case TypeDesc::UINT : \
195 ret = func<unsigned int> (R, __VA_ARGS__); break; \
196 case TypeDesc::INT : \
197 ret = func<int> (R, __VA_ARGS__); break; \
198 case TypeDesc::DOUBLE: \
199 ret = func<double> (R, __VA_ARGS__); break; \
201 (R).errorfmt("{}: Unsupported pixel data format '{}'", name, type); \
206 #define OIIO_DISPATCH_TYPES2_HELP(ret,name,func,Rtype,Atype,R,...) \
207 switch (Atype.basetype) { \
208 case TypeDesc::FLOAT : \
209 ret = func<Rtype,float> (R, __VA_ARGS__); break; \
210 case TypeDesc::UINT8 : \
211 ret = func<Rtype,unsigned char> (R, __VA_ARGS__); break; \
212 case TypeDesc::HALF : \
213 ret = func<Rtype,half> (R, __VA_ARGS__); break; \
214 case TypeDesc::UINT16: \
215 ret = func<Rtype,unsigned short> (R, __VA_ARGS__); break; \
216 case TypeDesc::INT8 : \
217 ret = func<Rtype,char> (R, __VA_ARGS__); break; \
218 case TypeDesc::INT16 : \
219 ret = func<Rtype,short> (R, __VA_ARGS__); break; \
220 case TypeDesc::UINT : \
221 ret = func<Rtype,unsigned int> (R, __VA_ARGS__); break; \
222 case TypeDesc::INT : \
223 ret = func<Rtype,int> (R, __VA_ARGS__); break; \
224 case TypeDesc::DOUBLE : \
225 ret = func<Rtype,double> (R, __VA_ARGS__); break; \
227 (R).errorfmt("{}: Unsupported pixel data format '{}'", name, Atype); \
232 #define OIIO_DISPATCH_TYPES2(ret,name,func,Rtype,Atype,R,...) \
233 switch (Rtype.basetype) { \
234 case TypeDesc::FLOAT : \
235 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,float,Atype,R,__VA_ARGS__); \
237 case TypeDesc::UINT8 : \
238 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,unsigned char,Atype,R,__VA_ARGS__); \
240 case TypeDesc::HALF : \
241 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,half,Atype,R,__VA_ARGS__); \
243 case TypeDesc::UINT16: \
244 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,unsigned short,Atype,R,__VA_ARGS__); \
246 case TypeDesc::INT8: \
247 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,char,Atype,R,__VA_ARGS__); \
249 case TypeDesc::INT16: \
250 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,short,Atype,R,__VA_ARGS__); \
252 case TypeDesc::UINT: \
253 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,unsigned int,Atype,R,__VA_ARGS__); \
255 case TypeDesc::INT: \
256 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,int,Atype,R,__VA_ARGS__); \
258 case TypeDesc::DOUBLE: \
259 OIIO_DISPATCH_TYPES2_HELP(ret,name,func,double,Atype,R,__VA_ARGS__);\
262 (R).errorfmt("{}: Unsupported pixel data format '{}'", name, Rtype); \
269 #define OIIO_DISPATCH_COMMON_TYPES(ret,name,func,type,R,...) \
270 switch (type.basetype) { \
271 case TypeDesc::FLOAT : \
272 ret = func<float> (R, __VA_ARGS__); break; \
273 case TypeDesc::UINT8 : \
274 ret = func<unsigned char> (R, __VA_ARGS__); break; \
275 case TypeDesc::HALF : \
276 ret = func<half> (R, __VA_ARGS__); break; \
277 case TypeDesc::UINT16: \
278 ret = func<unsigned short> (R, __VA_ARGS__); break; \
282 if ((R).initialized()) \
283 Rtmp.copy (R, TypeDesc::FLOAT); \
284 ret = func<float> (Rtmp, __VA_ARGS__); \
288 (R).errorfmt("{}", Rtmp.geterror()); \
293 #define OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,Rtype,Atype,R,A,...) \
294 switch (Atype.basetype) { \
295 case TypeDesc::FLOAT : \
296 ret = func<Rtype,float> (R, A, __VA_ARGS__); break; \
297 case TypeDesc::UINT8 : \
298 ret = func<Rtype,unsigned char> (R, A, __VA_ARGS__); break; \
299 case TypeDesc::HALF : \
300 ret = func<Rtype,half> (R, A, __VA_ARGS__); break; \
301 case TypeDesc::UINT16: \
302 ret = func<Rtype,unsigned short> (R, A, __VA_ARGS__); break; \
306 Atmp.copy (A, TypeDesc::FLOAT); \
307 ret = func<Rtype,float> (R, Atmp, __VA_ARGS__); \
314 #define OIIO_DISPATCH_COMMON_TYPES2(ret,name,func,Rtype,Atype,R,A,...) \
315 if (Rtype == Atype) { \
317 switch (Atype.basetype) { \
318 case TypeDesc::FLOAT : \
319 ret = func<float,float> (R, A, __VA_ARGS__); break; \
320 case TypeDesc::UINT8 : \
321 ret = func<uint8_t,uint8_t> (R, A, __VA_ARGS__); break; \
322 case TypeDesc::UINT16: \
323 ret = func<uint16_t,uint16_t> (R, A, __VA_ARGS__); break; \
324 case TypeDesc::HALF : \
325 ret = func<half,half> (R, A, __VA_ARGS__); break; \
326 case TypeDesc::INT8 : \
327 ret = func<char,char> (R, A, __VA_ARGS__); break; \
328 case TypeDesc::INT16 : \
329 ret = func<short,short> (R, A, __VA_ARGS__); break; \
330 case TypeDesc::UINT : \
331 ret = func<uint32_t,uint32_t> (R, A, __VA_ARGS__); break; \
332 case TypeDesc::INT : \
333 ret = func<int,int> (R, A, __VA_ARGS__); break; \
334 case TypeDesc::DOUBLE : \
335 ret = func<double,double> (R, A, __VA_ARGS__); break; \
337 (R).errorfmt("{}: Unsupported pixel data format '{}'", name, Atype); \
342 switch (Rtype.basetype) { \
343 case TypeDesc::FLOAT : \
344 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,float,Atype,R,A,__VA_ARGS__); \
346 case TypeDesc::UINT8 : \
347 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,uint8_t,Atype,R,A,__VA_ARGS__); \
349 case TypeDesc::HALF : \
350 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,half,Atype,R,A,__VA_ARGS__); \
352 case TypeDesc::UINT16: \
353 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,uint16_t,Atype,R,A,__VA_ARGS__); \
358 if ((R).initialized()) \
359 Rtmp.copy (R, TypeDesc::FLOAT); \
360 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,float,Atype,Rtmp,A,__VA_ARGS__); \
364 (R).errorfmt("{}", Rtmp.geterror()); \
373 #define OIIO_DISPATCH_COMMON_TYPES2_CONST(ret,name,func,Rtype,Atype,R,A,...) \
374 switch (Rtype.basetype) { \
375 case TypeDesc::FLOAT : \
376 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,float,Atype,R,A,__VA_ARGS__); \
378 case TypeDesc::UINT8 : \
379 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,unsigned char,Atype,R,A,__VA_ARGS__); \
381 case TypeDesc::HALF : \
382 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,half,Atype,R,A,__VA_ARGS__); \
384 case TypeDesc::UINT16: \
385 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,unsigned short,Atype,R,A,__VA_ARGS__); \
390 if ((R).initialized()) \
391 Rtmp.copy (R, TypeDesc::FLOAT); \
392 OIIO_DISPATCH_COMMON_TYPES2_HELP(ret,name,func,float,Atype,Rtmp,A,__VA_ARGS__); \
397 #define OIIO_DISPATCH_COMMON_TYPES3_HELP2(ret,name,func,Rtype,Atype,Btype,R,A,B,...) \
398 switch (Rtype.basetype) { \
399 case TypeDesc::FLOAT : \
400 ret = func<float,Atype,Btype> (R,A,B,__VA_ARGS__); break; \
401 case TypeDesc::UINT8 : \
402 ret = func<unsigned char,Atype,Btype> (R,A,B,__VA_ARGS__); break; \
403 case TypeDesc::HALF : \
404 ret = func<half,Atype,Btype> (R,A,B,__VA_ARGS__); break; \
405 case TypeDesc::UINT16: \
406 ret = func<unsigned short,Atype,Btype> (R,A,B,__VA_ARGS__); break; \
410 if ((R).initialized()) \
411 Rtmp.copy (R, TypeDesc::FLOAT); \
412 ret = func<float,Atype,Btype> (R,A,B,__VA_ARGS__); \
416 (R).errorfmt("{}", Rtmp.geterror()); \
421 #define OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,Atype,Btype,R,A,B,...) \
422 switch (Btype.basetype) { \
423 case TypeDesc::FLOAT : \
424 OIIO_DISPATCH_COMMON_TYPES3_HELP2(ret,name,func,Rtype,Atype,float,R,A,B,__VA_ARGS__); \
426 case TypeDesc::UINT8 : \
427 OIIO_DISPATCH_COMMON_TYPES3_HELP2(ret,name,func,Rtype,Atype,unsigned char,R,A,B,__VA_ARGS__); \
429 case TypeDesc::HALF : \
430 OIIO_DISPATCH_COMMON_TYPES3_HELP2(ret,name,func,Rtype,Atype,half,R,A,B,__VA_ARGS__); \
432 case TypeDesc::UINT16 : \
433 OIIO_DISPATCH_COMMON_TYPES3_HELP2(ret,name,func,Rtype,Atype,unsigned short,R,A,B,__VA_ARGS__); \
438 Btmp.copy (B, TypeDesc::FLOAT); \
439 OIIO_DISPATCH_COMMON_TYPES3_HELP2(ret,name,func,Rtype,Atype,float,R,A,Btmp,__VA_ARGS__); \
446 #define OIIO_DISPATCH_COMMON_TYPES3(ret,name,func,Rtype,Atype,Btype,R,A,B,...) \
447 if (Rtype == Atype && Rtype == Btype) { \
449 switch (Atype.basetype) { \
450 case TypeDesc::FLOAT : \
451 ret = func<float,float,float> (R, A, B, __VA_ARGS__); break;\
452 case TypeDesc::UINT8 : \
453 ret = func<uint8_t,uint8_t,uint8_t> (R, A, B, __VA_ARGS__); break; \
454 case TypeDesc::UINT16: \
455 ret = func<uint16_t,uint16_t,uint16_t> (R, A, B, __VA_ARGS__); break; \
456 case TypeDesc::HALF : \
457 ret = func<half,half,half> (R, A, B, __VA_ARGS__); break; \
458 case TypeDesc::INT8 : \
459 ret = func<char,char,char> (R, A, B, __VA_ARGS__); break; \
460 case TypeDesc::INT16 : \
461 ret = func<int16_t,int16_t,int16_t> (R, A, B, __VA_ARGS__); break; \
462 case TypeDesc::UINT : \
463 ret = func<uint32_t,uint32_t,uint32_t> (R, A, B, __VA_ARGS__); break; \
464 case TypeDesc::INT : \
465 ret = func<int,int,int> (R, A, B, __VA_ARGS__); break; \
466 case TypeDesc::DOUBLE : \
467 ret = func<double,double,double> (R, A, B, __VA_ARGS__); break; \
469 (R).errorfmt("{}: Unsupported pixel data format '{}'", name, Atype); \
473 switch (Atype.basetype) { \
474 case TypeDesc::FLOAT : \
475 OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,float,Btype,R,A,B,__VA_ARGS__); \
477 case TypeDesc::UINT8 : \
478 OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,unsigned char,Btype,R,A,B,__VA_ARGS__); \
480 case TypeDesc::HALF : \
481 OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,half,Btype,R,A,B,__VA_ARGS__); \
483 case TypeDesc::UINT16: \
484 OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,unsigned short,Btype,R,A,B,__VA_ARGS__); \
489 Atmp.copy (A, TypeDesc::FLOAT); \
490 OIIO_DISPATCH_COMMON_TYPES3_HELP(ret,name,func,Rtype,float,Btype,R,Atmp,B,__VA_ARGS__); \
500 #define IBA_FIX_PERCHAN_LEN(av,len,missing,zdef) \
501 if (av.size() < len) { \
503 float *vals = OIIO_ALLOCA(float, nc); \
504 for (int i = 0; i < nc; ++i) \
505 vals[i] = i < av.size() ? av[i] : (i ? vals[i-1] : zdef); \
506 av = cspan<float>(vals, nc); \
511 #define IBA_FIX_PERCHAN_LEN_DEF(av,len) \
512 IBA_FIX_PERCHAN_LEN (av, len, 0.0f, av.size() ? av.back() : 0.0f);
static BASETYPE basetype_merge(TypeDesc a, TypeDesc b)
constexpr imagesize_t npixels() const noexcept
Total number of pixels in the region.
TypeDesc type_merge(TypeDesc a, TypeDesc b, TypeDesc c)
Encapsulation of options that control parallel_image().
OIIO_API void parallel_for_chunked_2D(int64_t xstart, int64_t xend, int64_t xchunksize, int64_t ystart, int64_t yend, int64_t ychunksize, std::function< void(int id, int64_t, int64_t, int64_t, int64_t)> &&task, parallel_options opt=0)
vfloat4 sqrt(const vfloat4 &a)
GLboolean GLboolean GLboolean GLboolean a
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool singlethread() const
constexpr int height() const noexcept
Width.
bool IBAprep(ROI &roi, ImageBuf *dst, const ImageBuf *A, int prepflags)
GLboolean GLboolean GLboolean b
SplitDir
Split strategies.
constexpr int width() const noexcept
Height.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define OIIO_NAMESPACE_END
void parallel_image(Func f, ROI roi, int nthreads=0, SplitDir splitdir=Split_Y)
#define OIIO_NAMESPACE_BEGIN