Merge pull request #2755 from vbystricky:oclopt_LUT

This commit is contained in:
Alexander Alekhin
2014-06-06 18:52:39 +04:00
committed by OpenCV Buildbot
2 changed files with 114 additions and 19 deletions

View File

@@ -1559,17 +1559,22 @@ static bool ocl_LUT(InputArray _src, InputArray _lut, OutputArray _dst)
UMat src = _src.getUMat(), lut = _lut.getUMat();
_dst.create(src.size(), CV_MAKETYPE(ddepth, dcn));
UMat dst = _dst.getUMat();
bool bAligned = (1 == lcn) && (0 == (src.offset % 4)) && (0 == ((dcn * src.cols) % 4));
// dst.cols == src.cols by params of dst.create
ocl::Kernel k("LUT", ocl::core::lut_oclsrc,
format("-D dcn=%d -D lcn=%d -D srcT=%s -D dstT=%s", dcn, lcn,
ocl::typeToStr(src.depth()), ocl::memopTypeToStr(ddepth)));
format("-D dcn=%d -D lcn=%d -D srcT=%s -D dstT=%s", bAligned ? 4 : dcn, lcn,
ocl::typeToStr(src.depth()), ocl::memopTypeToStr(ddepth)
));
if (k.empty())
return false;
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::ReadOnlyNoSize(lut),
ocl::KernelArg::WriteOnly(dst));
int cols = bAligned ? dcn * dst.cols / 4 : dst.cols;
size_t globalSize[2] = { dst.cols, dst.rows };
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::ReadOnlyNoSize(lut),
ocl::KernelArg::WriteOnlyNoSize(dst), dst.rows, cols);
size_t globalSize[2] = { cols, (dst.rows + 3) / 4 };
return k.run(2, globalSize, NULL, false);
}