本文整理汇总了C++中imagebuf::ConstIterator::pos方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstIterator::pos方法的具体用法?C++ ConstIterator::pos怎么用?C++ ConstIterator::pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagebuf::ConstIterator
的用法示例。
在下文中一共展示了ConstIterator::pos方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: B
static int
action_sub (int argc, const char *argv[])
{
if (ot.postpone_callback (2, action_sub, argc, argv))
return 0;
ImageRecRef B (ot.pop());
ImageRecRef A (ot.pop());
ot.read (A);
ot.read (B);
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));
const ImageBuf &Bib ((*B)(s,m));
if (! same_size (Aib, Bib)) {
// FIXME: some day, there should be options of combining
// differing images somehow.
std::cerr << "oiiotool: " << argv[0] << " could not combine images of differing sizes\n";
continue;
}
ImageBuf &Rib ((*ot.curimg)(s,m));
ImageBuf::ConstIterator<float> a (Aib);
ImageBuf::ConstIterator<float> b (Bib);
ImageBuf::Iterator<float> r (Rib);
int nchans = Rib.nchannels();
for ( ; ! r.done(); ++r) {
a.pos (r.x(), r.y());
b.pos (r.x(), r.y());
for (int c = 0; c < nchans; ++c)
r[c] = a[c] - b[c];
}
}
}
return 0;
}
示例3: s
static bool
flop_ (ImageBuf &dst, const ImageBuf &src, ROI roi, int nthreads)
{
ImageBuf::ConstIterator<S, D> s (src, roi);
ImageBuf::Iterator<D, D> d (dst, roi);
for ( ; ! d.done(); ++d) {
s.pos (roi.xend-1 - (d.x() - roi.xbegin), d.y(), d.z());
for (int c = roi.chbegin; c < roi.chend; ++c)
d[c] = s[c];
}
return true;
}
示例4: s
static bool
flip_ (ImageBuf &dst, const ImageBuf &src, ROI dst_roi, int nthreads)
{
ROI src_roi_full = src.roi_full();
ROI dst_roi_full = dst.roi_full();
ImageBuf::ConstIterator<S, D> s (src);
ImageBuf::Iterator<D, D> d (dst, dst_roi);
for ( ; ! d.done(); ++d) {
int yy = d.y() - dst_roi_full.ybegin;
s.pos (d.x(), src_roi_full.yend-1 - yy, d.z());
for (int c = dst_roi.chbegin; c < dst_roi.chend; ++c)
d[c] = s[c];
}
return true;
}
示例5: ALLOCA
static bool
convolve_ (ImageBuf &dst, const ImageBuf &src, const ImageBuf &kernel,
bool normalize, ROI roi, int nthreads)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Lots of pixels and request for multi threads? Parallelize.
ImageBufAlgo::parallel_image (
boost::bind(convolve_<DSTTYPE,SRCTYPE>, boost::ref(dst),
boost::cref(src), boost::cref(kernel), normalize,
_1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
float scale = 1.0f;
if (normalize) {
scale = 0.0f;
for (ImageBuf::ConstIterator<float> k (kernel); ! k.done(); ++k)
scale += k[0];
scale = 1.0f / scale;
}
float *sum = ALLOCA (float, roi.chend);
ROI kroi = get_roi (kernel.spec());
ImageBuf::Iterator<DSTTYPE> d (dst, roi);
ImageBuf::ConstIterator<SRCTYPE> s (src, roi, ImageBuf::WrapClamp);
for ( ; ! d.done(); ++d) {
for (int c = roi.chbegin; c < roi.chend; ++c)
sum[c] = 0.0f;
for (ImageBuf::ConstIterator<float> k (kernel, kroi); !k.done(); ++k) {
float kval = k[0];
s.pos (d.x() + k.x(), d.y() + k.y(), d.z() + k.z());
for (int c = roi.chbegin; c < roi.chend; ++c)
sum[c] += kval * s[c];
}
for (int c = roi.chbegin; c < roi.chend; ++c)
d[c] = scale * sum[c];
}
return true;
}
示例6: zero
// DEPRECATED version
bool
ImageBufAlgo::add (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
int options)
{
// Sanity checks
// dst must be distinct from A and B
if ((const void *)&A == (const void *)&dst ||
(const void *)&B == (const void *)&dst) {
dst.error ("destination image must be distinct from source");
return false;
}
// all three images must have the same number of channels
if (A.spec().nchannels != B.spec().nchannels) {
dst.error ("channel number mismatch: %d vs. %d",
A.spec().nchannels, B.spec().nchannels);
return false;
}
// If dst has not already been allocated, set it to the right size,
// make it unconditinally float
if (! dst.pixels_valid()) {
ImageSpec dstspec = A.spec();
dstspec.set_format (TypeDesc::TypeFloat);
dst.alloc (dstspec);
}
// Clear dst pixels if instructed to do so
if (options & ADD_CLEAR_DST) {
zero (dst);
}
ASSERT (A.spec().format == TypeDesc::FLOAT &&
B.spec().format == TypeDesc::FLOAT &&
dst.spec().format == TypeDesc::FLOAT);
ImageBuf::ConstIterator<float,float> a (A);
ImageBuf::ConstIterator<float,float> b (B);
ImageBuf::Iterator<float> d (dst);
int nchannels = A.nchannels();
// Loop over all pixels in A
for ( ; a.valid(); ++a) {
// Point the iterators for B and dst to the corresponding pixel
if (options & ADD_RETAIN_WINDOWS) {
b.pos (a.x(), a.y());
} else {
// ADD_ALIGN_WINDOWS: make B line up with A
b.pos (a.x()-A.xbegin()+B.xbegin(), a.y()-A.ybegin()+B.ybegin());
}
d.pos (a.x(), b.y());
if (! b.valid() || ! d.valid())
continue; // Skip pixels that don't align
// Add the pixel
for (int c = 0; c < nchannels; ++c)
d[c] = a[c] + b[c];
}
return true;
}
示例7: ALLOCA
static bool
resample_ (ImageBuf &dst, const ImageBuf &src, bool interpolate,
ROI roi, int nthreads)
{
if (nthreads != 1 && roi.npixels() >= 1000) {
// Lots of pixels and request for multi threads? Parallelize.
ImageBufAlgo::parallel_image (
boost::bind(resample_<DSTTYPE,SRCTYPE>, boost::ref(dst),
boost::cref(src), interpolate,
_1 /*roi*/, 1 /*nthreads*/),
roi, nthreads);
return true;
}
// Serial case
const ImageSpec &srcspec (src.spec());
const ImageSpec &dstspec (dst.spec());
int nchannels = src.nchannels();
// Local copies of the source image window, converted to float
float srcfx = srcspec.full_x;
float srcfy = srcspec.full_y;
float srcfw = srcspec.full_width;
float srcfh = srcspec.full_height;
float dstfx = dstspec.full_x;
float dstfy = dstspec.full_y;
float dstfw = dstspec.full_width;
float dstfh = dstspec.full_height;
float dstpixelwidth = 1.0f / dstfw;
float dstpixelheight = 1.0f / dstfh;
float *pel = ALLOCA (float, nchannels);
ImageBuf::Iterator<DSTTYPE> out (dst, roi);
ImageBuf::ConstIterator<SRCTYPE> srcpel (src);
for (int y = roi.ybegin; y < roi.yend; ++y) {
// s,t are NDC space
float t = (y-dstfy+0.5f)*dstpixelheight;
// src_xf, src_xf are image space float coordinates
float src_yf = srcfy + t * srcfh - 0.5f;
// src_x, src_y are image space integer coordinates of the floor
int src_y;
(void) floorfrac (src_yf, &src_y);
for (int x = roi.xbegin; x < roi.xend; ++x) {
float s = (x-dstfx+0.5f)*dstpixelwidth;
float src_xf = srcfx + s * srcfw - 0.5f;
int src_x;
(void) floorfrac (src_xf, &src_x);
if (interpolate) {
src.interppixel (src_xf, src_yf, pel);
for (int c = roi.chbegin; c < roi.chend; ++c)
out[c] = pel[c];
} else {
srcpel.pos (src_x, src_y, 0);
for (int c = roi.chbegin; c < roi.chend; ++c)
out[c] = srcpel[c];
}
++out;
}
}
return true;
}
示例8: float
//.........这里部分代码省略.........
// If using separable filters, our vertical set of filter tap
// weights will be the same for the whole scanline we're on. Just
// compute and normalize them once.
float totalweight_y = 0.0f;
if (separable) {
for (int j = 0; j < ytaps; ++j) {
float w = filter->yfilt (yratio * (j-radj-(src_yf_frac-0.5f)));
yfiltval[j] = w;
totalweight_y += w;
}
for (int i = 0; i <= ytaps; ++i)
yfiltval[i] /= totalweight_y;
}
for (int x = roi.xbegin; x < roi.xend; ++x) {
float s = (x-dstfx+0.5f)*dstpixelwidth;
float src_xf = srcfx + s * srcfw;
int src_x;
float src_xf_frac = floorfrac (src_xf, &src_x);
for (int c = 0; c < nchannels; ++c)
pel[c] = 0.0f;
if (separable) {
// Cache and normalize the horizontal filter tap weights
// just once for this (x,y) position, reuse for all vertical
// taps.
float totalweight_x = 0.0f;
for (int i = 0; i < xtaps; ++i) {
float w = filter->xfilt (xratio * (i-radi-(src_xf_frac-0.5f)));
xfiltval[i] = w;
totalweight_x += w;
}
if (totalweight_x != 0.0f) {
for (int i = 0; i < xtaps; ++i) // normalize x filter
xfiltval[i] /= totalweight_x; // weights
ImageBuf::ConstIterator<SRCTYPE> srcpel (src, src_x-radi, src_x+radi+1,
src_y-radj, src_y+radj+1,
0, 1, ImageBuf::WrapClamp);
for (int j = -radj; j <= radj; ++j) {
float wy = yfiltval[j+radj];
if (wy == 0.0f) {
// 0 weight for this y tap -- move to next line
srcpel.pos (srcpel.x(), srcpel.y()+1, srcpel.z());
continue;
}
for (int i = 0; i < xtaps; ++i, ++srcpel) {
float w = wy * xfiltval[i];
for (int c = 0; c < nchannels; ++c)
pel[c] += w * srcpel[c];
}
}
}
// Copy the pixel value (already normalized) to the output.
DASSERT (out.x() == x && out.y() == y);
if (totalweight_y == 0.0f) {
// zero it out
for (int c = 0; c < nchannels; ++c)
out[c] = 0.0f;
} else {
for (int c = 0; c < nchannels; ++c)
out[c] = pel[c];
}
} else {
// Non-separable
float totalweight = 0.0f;
ImageBuf::ConstIterator<SRCTYPE> srcpel (src, src_x-radi, src_x+radi+1,
src_y-radi, src_y+radi+1,
0, 1, ImageBuf::WrapClamp);
for (int j = -radj; j <= radj; ++j) {
for (int i = -radi; i <= radi; ++i, ++srcpel) {
float w = (*filter)(xratio * (i-(src_xf_frac-0.5f)),
yratio * (j-(src_yf_frac-0.5f)));
totalweight += w;
if (w == 0.0f)
continue;
DASSERT (! srcpel.done());
for (int c = 0; c < nchannels; ++c)
pel[c] += w * srcpel[c];
}
}
DASSERT (srcpel.done());
// Rescale pel to normalize the filter and write it to the
// output image.
DASSERT (out.x() == x && out.y() == y);
if (totalweight == 0.0f) {
// zero it out
for (int c = 0; c < nchannels; ++c)
out[c] = 0.0f;
} else {
for (int c = 0; c < nchannels; ++c)
out[c] = pel[c] / totalweight;
}
}
++out;
}
}
return true;
}