本文整理汇总了C++中imagebuf::Iterator类的典型用法代码示例。如果您正苦于以下问题:C++ Iterator类的具体用法?C++ Iterator怎么用?C++ Iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s
static bool
circular_shift_ (ImageBuf &dst, const ImageBuf &src,
int xshift, int yshift, int zshift,
ROI dstroi, ROI roi, int nthreads)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Possible multiple thread case -- recurse via parallel_image
ImageBufAlgo::parallel_image (
boost::bind(circular_shift_<DSTTYPE,SRCTYPE>,
boost::ref(dst), boost::cref(src),
xshift, yshift, zshift,
dstroi, _1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
int width = dstroi.width(), height = dstroi.height(), depth = dstroi.depth();
ImageBuf::ConstIterator<SRCTYPE,DSTTYPE> s (src, roi);
ImageBuf::Iterator<DSTTYPE,DSTTYPE> d (dst);
for ( ; ! s.done(); ++s) {
int dx = s.x() + xshift; OIIO::wrap_periodic (dx, dstroi.xbegin, width);
int dy = s.y() + yshift; OIIO::wrap_periodic (dy, dstroi.ybegin, height);
int dz = s.z() + zshift; OIIO::wrap_periodic (dz, dstroi.zbegin, depth);
d.pos (dx, dy, dz);
if (! d.exists())
continue;
for (int c = roi.chbegin; c < roi.chend; ++c)
d[c] = s[c];
}
return true;
}
示例2: bilerp
static bool
fill_corners_ (ImageBuf &dst, const float *topleft, const float *topright,
const float *bottomleft, const float *bottomright,
ROI origroi, ROI roi=ROI(), int nthreads=1)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Lots of pixels and request for multi threads? Parallelize.
ImageBufAlgo::parallel_image (
OIIO::bind(fill_corners_<T>, OIIO::ref(dst), topleft, topright,
bottomleft, bottomright,
origroi, _1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
float w = std::max (1, origroi.width() - 1);
float h = std::max (1, origroi.height() - 1);
for (ImageBuf::Iterator<T> p (dst, roi); !p.done(); ++p) {
float u = (p.x() - origroi.xbegin) / w;
float v = (p.y() - origroi.ybegin) / h;
for (int c = roi.chbegin; c < roi.chend; ++c)
p[c] = bilerp (topleft[c], topright[c],
bottomleft[c], bottomright[c], u, v);
}
return true;
}
示例3:
static bool
clamp_ (ImageBuf &dst, const float *min, const float *max,
bool clampalpha01, ROI roi, int nthreads)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Lots of pixels and request for multi threads? Parallelize.
ImageBufAlgo::parallel_image (
boost::bind(clamp_<D>, boost::ref(dst), min, max, clampalpha01,
_1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
for (ImageBuf::Iterator<D> d (dst, roi); ! d.done(); ++d) {
for (int c = roi.chbegin; c < roi.chend; ++c)
d[c] = OIIO::clamp<float> (d[c], min[c], max[c]);
}
int a = dst.spec().alpha_channel;
if (clampalpha01 && a >= roi.chbegin && a < roi.chend) {
for (ImageBuf::Iterator<D> d (dst, roi); ! d.done(); ++d) {
d[a] = OIIO::clamp<float> (d[a], 0.0f, 1.0f);
}
}
return true;
}
示例4: hashnormal
static bool
noise_gaussian_ (ImageBuf &dst, float mean, float stddev, bool mono,
int seed, ROI roi, int nthreads)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Lots of pixels and request for multi threads? Parallelize.
ImageBufAlgo::parallel_image (
OIIO::bind(noise_gaussian_<T>, OIIO::ref(dst),
mean, stddev, mono, seed,
_1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
for (ImageBuf::Iterator<T> p (dst, roi); !p.done(); ++p) {
int x = p.x(), y = p.y(), z = p.z();
float n = 0.0;
for (int c = roi.chbegin; c < roi.chend; ++c) {
if (c == roi.chbegin || !mono)
n = mean + stddev * hashnormal (x, y, z, c, seed);
p[c] = p[c] + n;
}
}
return true;
}
示例5: s
static bool
paste_ (ImageBuf &dst, ROI dstroi,
const ImageBuf &src, ROI srcroi, int nthreads)
{
// N.B. Punt on parallelizing because of the subtle interplay
// between srcroi and dstroi, the parallel_image idiom doesn't
// handle that especially well. And it's not worth customizing for
// this function which is inexpensive and not commonly used, and so
// would benefit little from parallelizing. We can always revisit
// this later. But in the mean time, we maintain the 'nthreads'
// parameter for uniformity with the rest of IBA.
int src_nchans = src.nchannels ();
int dst_nchans = dst.nchannels ();
ImageBuf::ConstIterator<S,D> s (src, srcroi);
ImageBuf::Iterator<D,D> d (dst, dstroi);
for ( ; ! s.done(); ++s, ++d) {
if (! d.exists())
continue; // Skip paste-into pixels that don't overlap dst's data
for (int c = srcroi.chbegin, c_dst = dstroi.chbegin;
c < srcroi.chend; ++c, ++c_dst) {
if (c_dst >= 0 && c_dst < dst_nchans)
d[c_dst] = c < src_nchans ? s[c] : D(0);
}
}
return true;
}
示例6: r
static bool
div_impl (ImageBuf &R, const ImageBuf &A, const ImageBuf &B,
ROI roi, int nthreads)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Possible multiple thread case -- recurse via parallel_image
ImageBufAlgo::parallel_image (
boost::bind(div_impl<Rtype,Atype,Btype>,
boost::ref(R), boost::cref(A), boost::cref(B),
_1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
ImageBuf::Iterator<Rtype> r (R, roi);
ImageBuf::ConstIterator<Atype> a (A, roi);
ImageBuf::ConstIterator<Btype> b (B, roi);
for ( ; !r.done(); ++r, ++a, ++b)
for (int c = roi.chbegin; c < roi.chend; ++c) {
float v = b[c];
r[c] = (v == 0.0f) ? 0.0f : (a[c] / v);
}
return true;
}
示例7: hashrand
static bool
noise_salt_ (ImageBuf &dst, float saltval, float saltportion, bool mono,
int seed, ROI roi, int nthreads)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Lots of pixels and request for multi threads? Parallelize.
ImageBufAlgo::parallel_image (
OIIO::bind(noise_salt_<T>, OIIO::ref(dst),
saltval, saltportion, mono, seed,
_1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
for (ImageBuf::Iterator<T> p (dst, roi); !p.done(); ++p) {
int x = p.x(), y = p.y(), z = p.z();
float n = 0.0;
for (int c = roi.chbegin; c < roi.chend; ++c) {
if (c == roi.chbegin || !mono)
n = hashrand (x, y, z, c, seed);
if (n < saltportion)
p[c] = saltval;
}
}
return true;
}
示例8: ImageRec
static int
action_flip (int argc, const char *argv[])
{
if (ot.postpone_callback (1, action_flip, argc, argv))
return 0;
ot.read ();
ImageRecRef A = ot.pop();
ot.push (new ImageRec (*A, ot.allsubimages ? -1 : 0,
ot.allsubimages ? -1 : 0, true, false));
int subimages = ot.curimg->subimages();
for (int s = 0; s < subimages; ++s) {
int miplevels = ot.curimg->miplevels(s);
for (int m = 0; m < miplevels; ++m) {
const ImageBuf &Aib ((*A)(s,m));
ImageBuf &Rib ((*ot.curimg)(s,m));
ImageBuf::ConstIterator<float> a (Aib);
ImageBuf::Iterator<float> r (Rib);
int nchans = Rib.nchannels();
int firstscanline = Rib.ymin();
int lastscanline = Rib.ymax();
for ( ; ! r.done(); ++r) {
a.pos (r.x(), lastscanline - (r.y() - firstscanline));
for (int c = 0; c < nchans; ++c)
r[c] = a[c];
}
}
}
return 0;
}
示例9: if
static bool
render_box_ (ImageBuf &dst, array_view<const float> color,
ROI roi=ROI(), int nthreads=1)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Lots of pixels and request for multi threads? Parallelize.
ImageBufAlgo::parallel_image (
OIIO::bind(render_box_<T>, OIIO::ref(dst), color,
_1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
float alpha = 1.0f;
if (dst.spec().alpha_channel >= 0 && dst.spec().alpha_channel < int(color.size()))
alpha = color[dst.spec().alpha_channel];
else if (int(color.size()) == roi.chend+1)
alpha = color[roi.chend];
if (alpha == 1.0f) {
for (ImageBuf::Iterator<T> r (dst, roi); !r.done(); ++r)
for (int c = roi.chbegin; c < roi.chend; ++c)
r[c] = color[c];
} else {
for (ImageBuf::Iterator<T> r (dst, roi); !r.done(); ++r)
for (int c = roi.chbegin; c < roi.chend; ++c)
r[c] = color[c] + r[c] * (1.0f-alpha); // "over"
}
return true;
}
示例10:
static inline void
zero_ (ImageBuf &buf)
{
int chans = buf.nchannels();
for (ImageBuf::Iterator<T> pixel (buf); pixel.valid(); ++pixel)
for (int i = 0; i < chans; ++i)
pixel[i] = 0;
}
示例11: pixel
static inline void
setpixel_ (ImageBuf &buf, int x, int y, int z, const float *data, int chans)
{
ImageBuf::Iterator<T> pixel (buf, x, y, z);
if (pixel.valid()) {
for (int i = 0; i < chans; ++i)
pixel[i] = data[i];
}
}
示例12:
static inline void
transfer_pixels_ (ImageBuf &buf, ColorTransfer *tfunc)
{
for (ImageBuf::Iterator<T> pixel (buf); pixel.valid(); ++pixel) {
convert_types (buf.spec().format, pixel.rawptr(),
buf.spec().format, pixel.rawptr(),
buf.nchannels(), tfunc,
buf.spec().alpha_channel, buf.spec().z_channel);
}
}
示例13: a
static bool
pow_impl (ImageBuf &R, const ImageBuf &A, const float *b,
ROI roi, int nthreads)
{
ImageBufAlgo::parallel_image (roi, nthreads, [&](ROI roi){
ImageBuf::ConstIterator<Atype> a (A, roi);
for (ImageBuf::Iterator<Rtype> r (R, roi); !r.done(); ++r, ++a)
for (int c = roi.chbegin; c < roi.chend; ++c)
r[c] = pow (a[c], b[c]);
});
return true;
}
示例14: r
static bool
absdiff_impl (ImageBuf &R, const ImageBuf &A, const ImageBuf &B,
ROI roi, int nthreads)
{
ImageBufAlgo::parallel_image (roi, nthreads, [&](ROI roi){
ImageBuf::Iterator<Rtype> r (R, roi);
ImageBuf::ConstIterator<Atype> a (A, roi);
ImageBuf::ConstIterator<Btype> b (B, roi);
for ( ; !r.done(); ++r, ++a, ++b)
for (int c = roi.chbegin; c < roi.chend; ++c)
r[c] = std::abs (a[c] - b[c]);
});
return true;
}
示例15:
static bool
checker_ (ImageBuf &dst, Dim3 size,
const float *color1, const float *color2,
Dim3 offset,
ROI roi, int nthreads=1)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Lots of pixels and request for multi threads? Parallelize.
ImageBufAlgo::parallel_image (
OIIO::bind(checker_<T>, OIIO::ref(dst),
size, color1, color2, offset,
_1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
for (ImageBuf::Iterator<T> p (dst, roi); !p.done(); ++p) {
int xtile = (p.x()-offset.x)/size.x; xtile += (p.x()<offset.x);
int ytile = (p.y()-offset.y)/size.y; ytile += (p.y()<offset.y);
int ztile = (p.z()-offset.z)/size.z; ztile += (p.z()<offset.z);
int v = xtile + ytile + ztile;
if (v & 1)
for (int c = roi.chbegin; c < roi.chend; ++c)
p[c] = color2[c];
else
for (int c = roi.chbegin; c < roi.chend; ++c)
p[c] = color1[c];
}
return true;
}