bool ImageBufAlgo::transpose (ImageBuf &dst, const ImageBuf &src, ROI roi, int nthreads) { pvt::LoggedTimer logtime("IBA::transpose"); if (! roi.defined()) roi = get_roi (src.spec()); roi.chend = std::min (roi.chend, src.nchannels()); ROI dst_roi (roi.ybegin, roi.yend, roi.xbegin, roi.xend, roi.zbegin, roi.zend, roi.chbegin, roi.chend); bool dst_initialized = dst.initialized(); if (! IBAprep (dst_roi, &dst)) return false; if (! dst_initialized) { ROI r = src.roi_full(); ROI dst_roi_full (r.ybegin, r.yend, r.xbegin, r.xend, r.zbegin, r.zend, r.chbegin, r.chend); dst.set_roi_full (dst_roi_full); } bool ok; if (dst.spec().format == src.spec().format) { OIIO_DISPATCH_TYPES (ok, "transpose", transpose_, dst.spec().format, dst, src, roi, nthreads); } else { OIIO_DISPATCH_COMMON_TYPES2 (ok, "transpose", transpose_, dst.spec().format, src.spec().format, dst, src, roi, nthreads); } return ok; }
bool ImageBufAlgo::cut (ImageBuf &dst, const ImageBuf &src, ROI roi, int nthreads) { bool ok = crop (dst, src, roi, nthreads); ASSERT(ok); if (! ok) return false; // Crop did the heavy lifting of copying the roi of pixels from src to // dst, but now we need to make it look like we cut that rectangle out // and repositioned it at the origin. dst.specmod().x = 0; dst.specmod().y = 0; dst.specmod().z = 0; dst.set_roi_full (dst.roi()); return true; }
bool ImageBufAlgo::rotate270 (ImageBuf &dst, const ImageBuf &src, ROI roi, int nthreads) { if (&dst == &src) { // Handle in-place operation ImageBuf tmp; tmp.swap (const_cast<ImageBuf&>(src)); return rotate270 (dst, tmp, roi, nthreads); } pvt::LoggedTimer logtime("IBA::rotate270"); ROI src_roi = roi.defined() ? roi : src.roi(); ROI src_roi_full = src.roi_full(); // Rotated full ROI swaps width and height, and keeps its origin // where the original origin was. ROI dst_roi_full (src_roi_full.xbegin, src_roi_full.xbegin+src_roi_full.height(), src_roi_full.ybegin, src_roi_full.ybegin+src_roi_full.width(), src_roi_full.zbegin, src_roi_full.zend, src_roi_full.chbegin, src_roi_full.chend); ROI dst_roi (src_roi.ybegin, src_roi.yend, src_roi_full.xend-src_roi.xend, src_roi_full.xend-src_roi.xbegin, src_roi.zbegin, src_roi.zend, src_roi.chbegin, src_roi.chend); ASSERT (dst_roi.width() == src_roi.height() && dst_roi.height() == src_roi.width()); bool dst_initialized = dst.initialized(); if (! IBAprep (dst_roi, &dst, &src)) return false; if (! dst_initialized) dst.set_roi_full (dst_roi_full); bool ok; OIIO_DISPATCH_COMMON_TYPES2 (ok, "rotate270", rotate270_, dst.spec().format, src.spec().format, dst, src, dst_roi, nthreads); return ok; }
bool ImageBufAlgo::transpose (ImageBuf &dst, const ImageBuf &src, ROI roi, int nthreads) { if (! roi.defined()) roi = get_roi (src.spec()); roi.chend = std::min (roi.chend, src.nchannels()); ROI dst_roi (roi.ybegin, roi.yend, roi.xbegin, roi.xend, roi.zbegin, roi.zend, roi.chbegin, roi.chend); bool dst_initialized = dst.initialized(); IBAprep (dst_roi, &dst); if (! dst_initialized) { ROI r = src.roi_full(); ROI dst_roi_full (r.ybegin, r.yend, r.xbegin, r.xend, r.zbegin, r.zend, r.chbegin, r.chend); dst.set_roi_full (dst_roi_full); } bool ok; OIIO_DISPATCH_TYPES2 (ok, "transpose", transpose_, dst.spec().format, src.spec().format, dst, src, roi, nthreads); return ok; }