Skip to content

Commit b8d525a

Browse files
committed
try to speed up more
1 parent e8a93d8 commit b8d525a

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/libOpenImageIO/imagebufalgo_xform.cpp

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,9 @@ resample_ (ImageBuf &dst, const ImageBuf &src, bool interpolate,
502502
ROI roi, int nthreads)
503503
{
504504
ASSERT (!src.deep() && !dst.deep());
505-
ImageBufAlgo::parallel_image (roi, nthreads, [&](ROI roi){
505+
ImageBufAlgo::parallel_image (roi, nthreads, [&,interpolate](ROI roi){
506506
const ImageSpec &srcspec (src.spec());
507507
const ImageSpec &dstspec (dst.spec());
508-
int nchannels = src.nchannels();
509508

510509
// Local copies of the source image window, converted to float
511510
float srcfx = srcspec.full_x;
@@ -519,27 +518,40 @@ resample_ (ImageBuf &dst, const ImageBuf &src, bool interpolate,
519518
float dstfh = dstspec.full_height;
520519
float dstpixelwidth = 1.0f / dstfw;
521520
float dstpixelheight = 1.0f / dstfh;
522-
float *pel = ALLOCA (float, nchannels);
523521

524-
ImageBuf::Iterator<DSTTYPE> out (dst, roi);
525-
ImageBuf::ConstIterator<SRCTYPE> srcpel (src);
526-
for (int y = roi.ybegin; y < roi.yend; ++y) {
527-
// s,t are NDC space
528-
float t = (y-dstfy+0.5f)*dstpixelheight;
529-
// src_xf, src_xf are image space float coordinates
530-
float src_yf = srcfy + t * srcfh;
531-
// src_x, src_y are image space integer coordinates of the floor
532-
int src_y = ifloor (src_yf);
533-
for (int x = roi.xbegin; x < roi.xend; ++x, ++out) {
534-
float s = (x-dstfx+0.5f)*dstpixelwidth;
535-
float src_xf = srcfx + s * srcfw;
536-
int src_x = ifloor (src_xf);
537-
if (interpolate) {
522+
if (interpolate) {
523+
int nchannels = src.nchannels();
524+
float *pel = ALLOCA (float, nchannels);
525+
ImageBuf::Iterator<DSTTYPE> out (dst, roi);
526+
for (int y = roi.ybegin; y < roi.yend; ++y) {
527+
// s,t are NDC space
528+
float t = (y-dstfy+0.5f)*dstpixelheight;
529+
// src_xf, src_xf are image space float coordinates
530+
float src_yf = srcfy + t * srcfh;
531+
for (int x = roi.xbegin; x < roi.xend; ++x, ++out) {
532+
float s = (x-dstfx+0.5f)*dstpixelwidth;
533+
float src_xf = srcfx + s * srcfw;
538534
// Non-deep image, bilinearly interpolate
539535
src.interppixel (src_xf, src_yf, pel);
540536
for (int c = roi.chbegin; c < roi.chend; ++c)
541537
out[c] = pel[c];
542-
} else {
538+
}
539+
}
540+
541+
} else { // vvv NO interpolate case
542+
ImageBuf::Iterator<DSTTYPE,DSTTYPE> out (dst, roi);
543+
ImageBuf::ConstIterator<SRCTYPE,DSTTYPE> srcpel (src);
544+
for (int y = roi.ybegin; y < roi.yend; ++y) {
545+
// s,t are NDC space
546+
float t = (y-dstfy+0.5f)*dstpixelheight;
547+
// src_xf, src_xf are image space float coordinates
548+
float src_yf = srcfy + t * srcfh;
549+
// src_x, src_y are image space integer coordinates of the floor
550+
int src_y = ifloor (src_yf);
551+
for (int x = roi.xbegin; x < roi.xend; ++x, ++out) {
552+
float s = (x-dstfx+0.5f)*dstpixelwidth;
553+
float src_xf = srcfx + s * srcfw;
554+
int src_x = ifloor (src_xf);
543555
// Non-deep image, just copy closest pixel
544556
srcpel.pos (src_x, src_y, 0);
545557
for (int c = roi.chbegin; c < roi.chend; ++c)

0 commit comments

Comments
 (0)