From: Vladislav Vinogradov Date: Wed, 18 May 2011 06:51:05 +0000 (+0000) Subject: GpuMat::setTo optimization (call cudaMemcpy2D if possible) X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~7332 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f3b45af8767f269f62081b20236b2bacf57393f7;p=platform%2Fupstream%2Fopencv.git GpuMat::setTo optimization (call cudaMemcpy2D if possible) --- diff --git a/modules/gpu/src/matrix_operations.cpp b/modules/gpu/src/matrix_operations.cpp index e1c34dd..e4d5059 100644 --- a/modules/gpu/src/matrix_operations.cpp +++ b/modules/gpu/src/matrix_operations.cpp @@ -442,6 +442,22 @@ GpuMat& GpuMat::setTo(const Scalar& s, const GpuMat& mask) if (mask.empty()) { + if (s[0] == 0.0 && s[1] == 0.0 && s[2] == 0.0 && s[3] == 0.0) + { + cudaSafeCall( cudaMemset2D(data, step, 0, cols * elemSize(), rows) ); + return *this; + } + if (depth() == CV_8U) + { + int cn = channels(); + + if (cn == 1 || (cn == 2 && s[0] == s[1]) || (cn == 3 && s[0] == s[1] && s[0] == s[2]) || (cn == 4 && s[0] == s[1] && s[0] == s[2] && s[0] == s[3])) + { + int val = saturate_cast(s[0]); + cudaSafeCall( cudaMemset2D(data, step, val, cols, rows) ); + return *this; + } + } typedef void (*set_caller_t)(GpuMat& src, const Scalar& s); static const set_caller_t set_callers[8][4] = {