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::mul (ImageBuf &dst, const float *val, ROI roi, int nthreads) { IBAprep (roi, &dst); OIIO_DISPATCH_TYPES ("mul", mul_impl, dst.spec().format, dst, val, roi, nthreads); return true; }
bool ImageBufAlgo::add (ImageBuf &dst, const float *val, ROI roi, int nthreads) { IBAprep (roi, &dst); OIIO_DISPATCH_TYPES ("add", add_inplace, dst.spec().format, dst, val, roi, nthreads); return true; }
bool ImageBufAlgo::fill (ImageBuf &dst, const float *pixel, ROI roi, int nthreads) { ASSERT (pixel && "fill must have a non-NULL pixel value pointer"); if (! IBAprep (roi, &dst)) return false; OIIO_DISPATCH_TYPES ("fill", fill_, dst.spec().format, dst, pixel, roi, nthreads); return true; }
bool ImageBufAlgo::premult (ImageBuf &dst, ROI roi, int nthreads) { if (dst.spec().alpha_channel < 0) return true; IBAprep (roi, &dst); OIIO_DISPATCH_TYPES ("premult", premult_, dst.spec().format, dst, roi, nthreads); return true; }
bool ImageBufAlgo::clamp (ImageBuf &dst, float min, float max, bool clampalpha01, ROI roi, int nthreads) { IBAprep (roi, &dst); std::vector<float> minvec (dst.nchannels(), min); std::vector<float> maxvec (dst.nchannels(), max); OIIO_DISPATCH_TYPES ("clamp", clamp_, dst.spec().format, dst, &minvec[0], &maxvec[0], clampalpha01, roi, nthreads); return false; }
bool ImageBufAlgo::checker (ImageBuf &dst, int width, int height, int depth, const float *color1, const float *color2, int xoffset, int yoffset, int zoffset, ROI roi, int nthreads) { if (! IBAprep (roi, &dst)) return false; OIIO_DISPATCH_TYPES ("checker", checker_, dst.spec().format, dst, Dim3(width, height, depth), color1, color2, Dim3(xoffset, yoffset, zoffset), roi, nthreads); return true; }
bool ImageBufAlgo::isMonochrome (const ImageBuf &src, ROI roi, int nthreads) { // If no ROI is defined, use the data window of src. if (! roi.defined()) roi = get_roi(src.spec()); roi.chend = std::min (roi.chend, src.nchannels()); if (roi.nchannels() < 2) return true; // 1 or fewer channels are always "monochrome" OIIO_DISPATCH_TYPES ("isMonochrome", isMonochrome_, src.spec().format, src, roi, nthreads); // FIXME - The nthreads argument is for symmetry with the rest of // ImageBufAlgo and for future expansion. But for right now, we // don't actually split by threads. Maybe later. };
bool ImageBufAlgo::isConstantChannel (const ImageBuf &src, int channel, float val, ROI roi, int nthreads) { // If no ROI is defined, use the data window of src. if (! roi.defined()) roi = get_roi(src.spec()); if (channel < 0 || channel >= src.nchannels()) return false; // that channel doesn't exist in the image OIIO_DISPATCH_TYPES ("isConstantChannel", isConstantChannel_, src.spec().format, src, channel, val, roi, nthreads); // FIXME - The nthreads argument is for symmetry with the rest of // ImageBufAlgo and for future expansion. But for right now, we // don't actually split by threads. Maybe later. };
bool ImageBufAlgo::clamp (ImageBuf &dst, const float *min, const float *max, bool clampalpha01, ROI roi, int nthreads) { IBAprep (roi, &dst); std::vector<float> minvec, maxvec; if (! min) { minvec.resize (dst.nchannels(), -std::numeric_limits<float>::max()); min = &minvec[0]; } if (! max) { maxvec.resize (dst.nchannels(), std::numeric_limits<float>::max()); max = &maxvec[0]; } OIIO_DISPATCH_TYPES ("clamp", clamp_, dst.spec().format, dst, min, max, clampalpha01, roi, nthreads); return false; }
bool ImageBufAlgo::isConstantColor (const ImageBuf &src, float *color, ROI roi, int nthreads) { // If no ROI is defined, use the data window of src. if (! roi.defined()) roi = get_roi(src.spec()); roi.chend = std::min (roi.chend, src.nchannels()); if (roi.nchannels() == 0) return true; OIIO_DISPATCH_TYPES ("isConstantColor", isConstantColor_, src.spec().format, src, color, roi, nthreads); // FIXME - The nthreads argument is for symmetry with the rest of // ImageBufAlgo and for future expansion. But for right now, we // don't actually split by threads. Maybe later. };
bool ImageBufAlgo::computePixelStats (PixelStats &stats, const ImageBuf &src, ROI roi, int nthreads) { if (! roi.defined()) roi = get_roi (src.spec()); else roi.chend = std::min (roi.chend, src.nchannels()); int nchannels = src.spec().nchannels; if (nchannels == 0) { src.error ("%d-channel images not supported", nchannels); return false; } OIIO_DISPATCH_TYPES ("computePixelStats", computePixelStats_, src.spec().format, src, stats, roi, nthreads); return false; }
bool ImageBufAlgo::flatten (ImageBuf &dst, const ImageBuf &src, ROI roi, int nthreads) { if (! src.deep()) { // For some reason, we were asked to flatten an already-flat image. // So just copy it. return dst.copy (src); } // Construct an ideal spec for dst, which is like src but not deep. ImageSpec force_spec = src.spec(); force_spec.deep = false; force_spec.channelformats.clear(); if (! IBAprep (roi, &dst, &src, NULL, &force_spec, IBAprep_SUPPORT_DEEP)) return false; if (dst.spec().deep) { dst.error ("Cannot flatten to a deep image"); return false; } const ImageSpec &srcspec (src.spec()); int alpha_channel, RA_channel, GA_channel, BA_channel; int R_channel, G_channel, B_channel, Z_channel, Zback_channel; if (! find_deep_channels (srcspec, alpha_channel, RA_channel, GA_channel, BA_channel, R_channel, G_channel, B_channel, Z_channel, Zback_channel)) { dst.error ("No alpha channel could be identified"); return false; } bool ok; OIIO_DISPATCH_TYPES (ok, "flatten", flatten_, dst.spec().format, dst, src, roi, nthreads); return ok; }