|
25 | 25 | OIIO_NAMESPACE_BEGIN |
26 | 26 |
|
27 | 27 |
|
| 28 | +template<class Rtype, class Atype, class Btype> |
| 29 | +static bool |
| 30 | +scale_impl(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi, |
| 31 | + int nthreads) |
| 32 | +{ |
| 33 | + ImageBufAlgo::parallel_image(roi, nthreads, [&](ROI roi) { |
| 34 | + ImageBuf::Iterator<Rtype> r(R, roi); |
| 35 | + ImageBuf::ConstIterator<Atype> a(A, roi); |
| 36 | + ImageBuf::ConstIterator<Btype> b(B, roi); |
| 37 | + for (; !r.done(); ++r, ++a, ++b) |
| 38 | + for (int c = roi.chbegin; c < roi.chend; ++c) |
| 39 | + r[c] = a[c] * b[0]; |
| 40 | + }); |
| 41 | + return true; |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +bool |
| 47 | +ImageBufAlgo::scale(ImageBuf& dst, const ImageBuf& A, const ImageBuf& B, |
| 48 | + KWArgs options, ROI roi, int nthreads) |
| 49 | +{ |
| 50 | + pvt::LoggedTimer logtime("IBA::scale"); |
| 51 | + bool ok = false; |
| 52 | + if (B.nchannels() == 1) { |
| 53 | + if (IBAprep(roi, &dst, &A, &B)) |
| 54 | + OIIO_DISPATCH_COMMON_TYPES3(ok, "scale", scale_impl, |
| 55 | + dst.spec().format, A.spec().format, |
| 56 | + B.spec().format, dst, A, B, roi, |
| 57 | + nthreads); |
| 58 | + } else if (A.nchannels() == 1) { |
| 59 | + if (IBAprep(roi, &dst, &A, &B)) |
| 60 | + OIIO_DISPATCH_COMMON_TYPES3(ok, "scale", scale_impl, |
| 61 | + dst.spec().format, B.spec().format, |
| 62 | + A.spec().format, dst, B, A, roi, |
| 63 | + nthreads); |
| 64 | + } else { |
| 65 | + dst.errorfmt( |
| 66 | + "ImageBufAlgo::scale(): one of the arguments must be a single channel image."); |
| 67 | + } |
| 68 | + |
| 69 | + return ok; |
| 70 | +} |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +ImageBuf |
| 75 | +ImageBufAlgo::scale(const ImageBuf& A, const ImageBuf& B, KWArgs options, |
| 76 | + ROI roi, int nthreads) |
| 77 | +{ |
| 78 | + ImageBuf result; |
| 79 | + bool ok = scale(result, A, B, options, roi, nthreads); |
| 80 | + if (!ok && !result.has_error()) |
| 81 | + result.errorfmt("ImageBufAlgo::scale() error"); |
| 82 | + return result; |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | + |
28 | 87 | template<class Rtype, class Atype, class Btype> |
29 | 88 | static bool |
30 | 89 | mul_impl(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi, |
|
0 commit comments