 //////////////////////////////////////////////////////////////////////////////
 /// bitwise_not
 
-namespace
-{
-    template <typename T>
-    void bitMatNot(const GpuMat& src, GpuMat& dst, const GpuMat& mask, Stream& stream)
-    {
-        GlobPtrSz<T> vsrc = globPtr((T*) src.data, src.step, src.rows, src.cols * src.channels());
-        GlobPtrSz<T> vdst = globPtr((T*) dst.data, dst.step, src.rows, src.cols * src.channels());
-
-        if (mask.data)
-            gridTransformUnary(vsrc, vdst, bit_not<T>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
-        else
-            gridTransformUnary(vsrc, vdst, bit_not<T>(), stream);
-    }
-}
-
 void cv::cuda::bitwise_not(InputArray _src, OutputArray _dst, InputArray _mask, Stream& stream)
 {
     GpuMat src = _src.getGpuMat();

    CV_DbgAssert( depth <= CV_32F );
    CV_DbgAssert( op >= 0 && op < 3 );

    if (depth == CV_32F || depth == CV_32S)
    {
        funcs32[op](src1, src2, dst, mask, stream);
    }
    else if (depth == CV_16S || depth == CV_16U)
    {
        funcs16[op](src1, src2, dst, mask, stream);
    }
    else
    {
        funcs8[op](src1, src2, dst, mask, stream);
    }
}


    _dst.create(src.size(), src.type());
    GpuMat dst = _dst.getGpuMat();

    if (mask.empty())
    {
        const int bcols = (int) (src.cols * src.elemSize());

        if ((bcols & 3) == 0)
        {
            const int vcols = bcols >> 2;

            GlobPtrSz<uint> vsrc = globPtr((uint*) src.data, src.step, src.rows, vcols);
            GlobPtrSz<uint> vdst = globPtr((uint*) dst.data, dst.step, src.rows, vcols);

            gridTransformUnary(vsrc, vdst, bit_not<uint>(), stream);
        }
        else if ((bcols & 1) == 0)
        {
            const int vcols = bcols >> 1;

            GlobPtrSz<ushort> vsrc = globPtr((ushort*) src.data, src.step, src.rows, vcols);
            GlobPtrSz<ushort> vdst = globPtr((ushort*) dst.data, dst.step, src.rows, vcols);

            gridTransformUnary(vsrc, vdst, bit_not<ushort>(), stream);
        }
        else
        {
            GlobPtrSz<uchar> vsrc = globPtr((uchar*) src.data, src.step, src.rows, bcols);
            GlobPtrSz<uchar> vdst = globPtr((uchar*) dst.data, dst.step, src.rows, bcols);

            gridTransformUnary(vsrc, vdst, bit_not<uchar>(), stream);
        }
    }
    else
    {
        if (depth == CV_32F || depth == CV_32S)
        {
            GlobPtrSz<uint> vsrc = globPtr((uint*) src.data, src.step, src.rows, src.cols * src.channels());
            GlobPtrSz<uint> vdst = globPtr((uint*) dst.data, dst.step, src.rows, src.cols * src.channels());

            gridTransformUnary(vsrc, vdst, bit_not<uint>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
        }
        else if (depth == CV_16S || depth == CV_16U)
        {
            GlobPtrSz<ushort> vsrc = globPtr((ushort*) src.data, src.step, src.rows, src.cols * src.channels());
            GlobPtrSz<ushort> vdst = globPtr((ushort*) dst.data, dst.step, src.rows, src.cols * src.channels());

            gridTransformUnary(vsrc, vdst, bit_not<ushort>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
        }
        else
        {
            GlobPtrSz<uchar> vsrc = globPtr((uchar*) src.data, src.step, src.rows, src.cols * src.channels());
            GlobPtrSz<uchar> vdst = globPtr((uchar*) dst.data, dst.step, src.rows, src.cols * src.channels());

            gridTransformUnary(vsrc, vdst, bit_not<uchar>(), singleMaskChannels(globPtr<uchar>(mask), src.channels()), stream);
        }
    }
}

